diff --git a/recipes/wip/ssh/openssh/recipe.toml b/recipes/wip/ssh/openssh/recipe.toml index 4d7261da..26ed0f91 100644 --- a/recipes/wip/ssh/openssh/recipe.toml +++ b/recipes/wip/ssh/openssh/recipe.toml @@ -1,13 +1,20 @@ -#TODO update the patch to match the current version -#TODO does the patch is still needed? +#TODO compiled but not tested +#TODO lack of utmpx.h and resolv.h, expect dns not working +#TODO maybe actually implement utmpx.h in relibc? [source] tar = "https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.8p1.tar.gz" patches = [ "redox.patch", ] [build] -template = "configure" +template = "custom" dependencies = [ "openssl1", "zlib", ] +script = """ +DYNAMIC_INIT +cookbook_configure +mv "${COOKBOOK_STAGE}"/usr/sbin/sshd "${COOKBOOK_STAGE}"/usr/bin/sshd +rmdir "${COOKBOOK_STAGE}"/usr/sbin +""" diff --git a/recipes/wip/ssh/openssh/redox.patch b/recipes/wip/ssh/openssh/redox.patch index f19001f7..e1b43cae 100644 --- a/recipes/wip/ssh/openssh/redox.patch +++ b/recipes/wip/ssh/openssh/redox.patch @@ -1,138 +1,405 @@ -diff -ruwN source/channels.c source-new/channels.c ---- source/channels.c 2018-10-16 18:01:20.000000000 -0600 -+++ source-new/channels.c 2019-01-15 21:01:12.203686148 -0700 -@@ -1865,10 +1865,10 @@ - fatal(":%s: channel %d: no remote id", __func__, c->self); - /* for rdynamic the OPEN_CONFIRMATION has been sent already */ - isopen = (c->type == SSH_CHANNEL_RDYNAMIC_FINISH); -- if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, &err, &sz) < 0) { -- err = errno; -- error("getsockopt SO_ERROR failed"); -- } -+ // if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, &err, &sz) < 0) { -+ // err = errno; -+ // error("getsockopt SO_ERROR failed"); -+ // } - if (err == 0) { - debug("channel %d: connected to %s port %d", - c->self, c->connect_ctx.host, c->connect_ctx.port); -diff -ruwN source/config.sub source-new/config.sub ---- source/config.sub 2018-10-16 18:01:20.000000000 -0600 -+++ source-new/config.sub 2019-01-15 19:39:26.234492329 -0700 -@@ -1407,7 +1407,7 @@ - | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ - | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \ -- | -onefs* | -tirtos* | -phoenix*) -+ | -onefs* | -tirtos* | -phoenix* | -redox*) - # Remember, each alternative MUST END IN *, to match a version number. - ;; - -qnx*) -diff -ruwN source/openbsd-compat/bindresvport.c source-new/openbsd-compat/bindresvport.c ---- source/openbsd-compat/bindresvport.c 2018-10-16 18:01:20.000000000 -0600 -+++ source-new/openbsd-compat/bindresvport.c 2019-01-15 20:46:06.879804135 -0700 -@@ -42,6 +42,10 @@ - #include - #include +diff -ruwN source/defines.h source-new/defines.h +--- source/defines.h 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/defines.h 2025-08-20 13:37:45.820728226 +0700 +@@ -52,6 +52,18 @@ + #define IPPORT_RESERVED 0 + #endif +#ifndef IPPORT_RESERVED +#define IPPORT_RESERVED 1024 +#endif + - #define STARTPORT 600 - #define ENDPORT (IPPORT_RESERVED - 1) - #define NPORTS (ENDPORT - STARTPORT + 1) -diff -ruwN source/openbsd-compat/bsd-getpeereid.c source-new/openbsd-compat/bsd-getpeereid.c ---- source/openbsd-compat/bsd-getpeereid.c 2018-10-16 18:01:20.000000000 -0600 -+++ source-new/openbsd-compat/bsd-getpeereid.c 2019-01-15 20:43:12.410583244 -0700 -@@ -23,7 +23,7 @@ - - #include - --#if defined(SO_PEERCRED) -+#if defined(SO_PEERCRED) && !defined(__redox__) - int - getpeereid(int s, uid_t *euid, gid_t *gid) - { -diff -ruwN source/openbsd-compat/bsd-misc.c source-new/openbsd-compat/bsd-misc.c ---- source/openbsd-compat/bsd-misc.c 2018-10-16 18:01:20.000000000 -0600 -+++ source-new/openbsd-compat/bsd-misc.c 2019-01-15 20:28:46.619332501 -0700 -@@ -25,6 +25,9 @@ - # include ++#ifndef IN_LOOPBACKNET ++#define IN_LOOPBACKNET 127 ++#endif ++ ++#ifndef MAXDNAME ++#define MAXDNAME 256 ++#endif ++ + /* + * Definitions for IP type of service (ip_tos) + */ +@@ -454,19 +466,21 @@ + # define _PATH_DEVNULL "/dev/null" #endif -+#if defined(__redox__) -+#include +-/* user may have set a different path */ +-#if defined(_PATH_MAILDIR) && defined(MAIL_DIRECTORY) +-# undef _PATH_MAILDIR +-#endif /* defined(_PATH_MAILDIR) && defined(MAIL_DIRECTORY) */ +- +-#ifdef MAIL_DIRECTORY +-# define _PATH_MAILDIR MAIL_DIRECTORY ++#ifndef _PATH_MAILDIR ++# define _PATH_MAILDIR "/var/mail" + #endif + + #ifndef _PATH_NOLOGIN + # define _PATH_NOLOGIN "/etc/nologin" + #endif + ++#ifndef ST_RDONLY ++#define ST_RDONLY 1 +#endif - #include - #include ++#ifndef ST_NOSUID ++#define ST_NOSUID 2 ++#endif ++ + /* Define this to be the path of the xauth program. */ + #ifdef XAUTH_PATH + #define _PATH_XAUTH XAUTH_PATH +diff -ruwN source/hostfile.c source-new/hostfile.c +--- source/hostfile.c 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/hostfile.c 2025-08-20 11:51:28.964103232 +0700 +@@ -44,7 +44,9 @@ + #include + + #include ++#ifndef __redox__ + #include ++#endif + #include + #include #include +diff -ruwN source/loginrec.c source-new/loginrec.c +--- source/loginrec.c 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/loginrec.c 2025-08-20 13:43:02.970560664 +0700 +@@ -1033,7 +1033,7 @@ + return (0); + } + # else +- if (!utmpx_write_direct(li, &ut)) { ++ if (!utmpx_write_direct(li, &utx)) { + logit("%s: utmp_write_direct() failed", __func__); + return (0); + } +diff -ruwN source/loginrec.h source-new/loginrec.h +--- source/loginrec.h 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/loginrec.h 2025-08-20 13:39:08.570682776 +0700 +@@ -30,6 +30,7 @@ + **/ + + #include "includes.h" ++#include "openbsd-compat/utmpx.h" + + struct ssh; + +diff -ruwN source/openbsd-compat/bsd-statvfs.h source-new/openbsd-compat/bsd-statvfs.h +--- source/openbsd-compat/bsd-statvfs.h 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/openbsd-compat/bsd-statvfs.h 2025-08-20 13:37:42.000730245 +0700 +@@ -37,13 +37,6 @@ + typedef unsigned long fsfilcnt_t; + #endif + +-#ifndef ST_RDONLY +-#define ST_RDONLY 1 +-#endif +-#ifndef ST_NOSUID +-#define ST_NOSUID 2 +-#endif +- + /* as defined in IEEE Std 1003.1, 2004 Edition */ + struct statvfs { + unsigned long f_bsize; /* File system block size. */ diff -ruwN source/openbsd-compat/getrrsetbyname.c source-new/openbsd-compat/getrrsetbyname.c ---- source/openbsd-compat/getrrsetbyname.c 2018-10-16 18:01:20.000000000 -0600 -+++ source-new/openbsd-compat/getrrsetbyname.c 2019-01-15 20:57:20.248721738 -0700 -@@ -47,7 +47,7 @@ +--- source/openbsd-compat/getrrsetbyname.c 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/openbsd-compat/getrrsetbyname.c 2025-08-20 13:51:15.020299084 +0700 +@@ -67,6 +67,52 @@ + #endif + #define _THREAD_PRIVATE(a,b,c) (c) - #include "includes.h" ++#ifdef __redox__ ++ ++#include ++#include ++ ++/* ++ * Minimalist replacement for for systems that lack it, ++ * such as Redox OS. This provides the basic structures needed by ++ * the OpenSSH compatibility layer. ++ */ ++ ++// Define necessary constants ++#define MAXNS 3 /* max # name servers we'll track */ ++#define MAXDNSRCH 6 /* max # domains in search path */ ++#define MAXRESOLVSORT 10 /* number of nets to sort on */ ++#define MAXDNAME 256 /* max length of a domain name */ ++ ++/* ++ * A simplified, portable version of the resolver state structure. ++ * Glibc-specific fields, hooks, and complex unions have been removed. ++ */ ++struct __res_state { ++ int retrans; /* retransmission time interval */ ++ int retry; /* number of times to retransmit */ ++ unsigned long options; /* option flags */ ++ int nscount; /* number of name servers */ ++ struct sockaddr_in nsaddr_list[MAXNS]; /* address of name servers */ ++ unsigned short id; /* current message id */ ++ char *dnsrch[MAXDNSRCH + 1]; /* components of domain to search */ ++ char defdname[MAXDNAME]; /* default domain name */ ++ ++ struct { ++ struct in_addr addr; ++ uint32_t mask; ++ } sort_list[MAXRESOLVSORT]; ++ ++ int res_h_errno; /* last error code for this context */ ++ ++ // Simplified bitfields, removing glibc internals ++ unsigned ndots : 4; /* threshold for initial abs. query */ ++ unsigned nsort : 4; /* number of elements in sort_list[] */ ++}; ++ ++typedef struct __res_state *res_state; ++#endif /* __redox */ ++ + #ifndef HAVE__RES_EXTERN + struct __res_state _res; + #endif +@@ -167,6 +213,24 @@ + struct dns_rr *next; + }; --#if !defined (HAVE_GETRRSETBYNAME) && !defined (HAVE_LDNS) -+#if !defined (HAVE_GETRRSETBYNAME) && !defined (HAVE_LDNS) && !defined(__redox__) ++#ifdef __redox__ ++typedef struct { ++ uint16_t id; ++ uint8_t rd : 1; ++ uint8_t tc : 1; ++ uint8_t aa : 1; ++ uint8_t opcode : 4; ++ uint8_t qr : 1; ++ uint8_t rcode : 4; ++ uint8_t z : 3; ++ uint8_t ra : 1; ++ uint16_t qdcount; ++ uint16_t ancount; ++ uint16_t nscount; ++ uint16_t arcount; ++} HEADER; ++#endif ++ + struct dns_response { + HEADER header; + struct dns_query *query; +@@ -221,10 +285,10 @@ + } - #include - #include + /* initialize resolver */ +- if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { ++ // if (res_init() == -1) { + result = ERRSET_FAIL; + goto fail; +- } ++ // } + + #ifdef DEBUG + _resp->options |= RES_DEBUG; +@@ -482,12 +546,12 @@ + prev->next = curr; + + /* name */ +- length = dn_expand(answer, answer + size, *cp, name, +- sizeof(name)); +- if (length < 0) { ++ // length = dn_expand(answer, answer + size, *cp, name, ++ // sizeof(name)); ++ // if (length < 0) { + free_dns_query(head); + return (NULL); +- } ++ // } + curr->name = strdup(name); + if (curr->name == NULL) { + free_dns_query(head); +@@ -542,12 +606,12 @@ + prev->next = curr; + + /* name */ +- length = dn_expand(answer, answer + size, *cp, name, +- sizeof(name)); +- if (length < 0) { ++ // length = dn_expand(answer, answer + size, *cp, name, ++ // sizeof(name)); ++ // if (length < 0) { + free_dns_rr(head); + return (NULL); +- } ++ // } + curr->name = strdup(name); + if (curr->name == NULL) { + free_dns_rr(head); diff -ruwN source/openbsd-compat/getrrsetbyname.h source-new/openbsd-compat/getrrsetbyname.h ---- source/openbsd-compat/getrrsetbyname.h 2018-10-16 18:01:20.000000000 -0600 -+++ source-new/openbsd-compat/getrrsetbyname.h 2019-01-15 19:54:39.564320719 -0700 -@@ -50,7 +50,7 @@ - - #include "includes.h" - --#ifndef HAVE_GETRRSETBYNAME -+#if !defined(HAVE_GETRRSETBYNAME) && !defined(__redox__) +--- source/openbsd-compat/getrrsetbyname.h 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/openbsd-compat/getrrsetbyname.h 2025-08-20 11:51:00.744118526 +0700 +@@ -54,9 +54,13 @@ #include #include ++#ifndef __redox__ + #include ++#endif + #include ++#ifndef __redox__ + #include ++#endif + + #ifndef HFIXEDSZ + #define HFIXEDSZ 12 +diff -ruwN source/openbsd-compat/inet_ntop.c source-new/openbsd-compat/inet_ntop.c +--- source/openbsd-compat/inet_ntop.c 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/openbsd-compat/inet_ntop.c 2025-08-20 11:39:15.244488902 +0700 +@@ -26,7 +26,9 @@ + #include + #include + #include ++#ifndef __redox__ + #include ++#endif + #include + #include + #include diff -ruwN source/openbsd-compat/openbsd-compat.h source-new/openbsd-compat/openbsd-compat.h ---- source/openbsd-compat/openbsd-compat.h 2018-10-16 18:01:20.000000000 -0600 -+++ source-new/openbsd-compat/openbsd-compat.h 2019-01-15 20:14:24.316498869 -0700 -@@ -36,6 +36,10 @@ +--- source/openbsd-compat/openbsd-compat.h 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/openbsd-compat/openbsd-compat.h 2025-08-20 13:15:22.721439992 +0700 +@@ -36,6 +36,8 @@ #include /* for wchar_t */ -+#if defined(__redox__) -+#include -+#endif ++#include "getopt.h" + /* OpenBSD function replacements */ #include "base64.h" #include "sigact.h" +diff -ruwN source/openbsd-compat/utmpx.c source-new/openbsd-compat/utmpx.c +--- source/openbsd-compat/utmpx.c 1970-01-01 07:00:00.000000000 +0700 ++++ source-new/openbsd-compat/utmpx.c 2025-08-20 13:13:54.971486065 +0700 +@@ -0,0 +1,13 @@ ++#include "utmpx.h" ++#include // For NULL ++ ++#ifdef __redox__ ++ ++void endutxent(void) { /* Do nothing */ } ++struct utmpx *getutxent(void) { return NULL; } ++struct utmpx *getutxid(const struct utmpx *ut) { return NULL; } ++struct utmpx *getutxline(const struct utmpx *ut) { return NULL; } ++struct utmpx *pututxline(const struct utmpx *ut) { return NULL; } ++void setutxent(void) { /* Do nothing */ } ++ ++#endif +\ No newline at end of file +diff -ruwN source/openbsd-compat/utmpx.h source-new/openbsd-compat/utmpx.h +--- source/openbsd-compat/utmpx.h 1970-01-01 07:00:00.000000000 +0700 ++++ source-new/openbsd-compat/utmpx.h 2025-08-20 13:13:07.201511825 +0700 +@@ -0,0 +1,69 @@ ++#ifndef _COMPAT_UTMPX_H ++#define _COMPAT_UTMPX_H ++#ifdef __redox__ ++#include ++#include ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++/* ++ * This header provides a POSIX-compliant definition of the utmpx structure ++ * and related functions for systems that lack a native , such as Redox OS. ++ */ ++ ++// Define standard sizes for character arrays, based on common practice (e.g., Linux) ++#define UT_LINESIZE 32 ++#define UT_NAMESIZE 32 ++#define UT_HOSTSIZE 256 ++#define UT_IDSIZE 4 ++ ++/* ++ * The utmpx structure, containing user accounting information. ++ */ ++struct utmpx { ++ char ut_user[UT_NAMESIZE]; /* User login name */ ++ char ut_id[UT_IDSIZE]; /* Unspecified terminal id */ ++ char ut_line[UT_LINESIZE]; /* Device name of tty */ ++ pid_t ut_pid; /* Process ID */ ++ short ut_type; /* Type of entry */ ++ struct timeval ut_tv; /* Time entry was made */ ++ // Non-standard but very common fields, often needed for compatibility ++ char ut_host[UT_HOSTSIZE]; /* Host name for remote login */ ++ // Padding to align the structure, if necessary ++ char __padding[16]; ++}; ++ ++/* ++ * Symbolic constants for the ut_type field. ++ */ ++#define EMPTY 0 /* No valid user accounting information */ ++#define BOOT_TIME 1 /* Time of system boot */ ++#define OLD_TIME 2 /* Time when system clock changed */ ++#define NEW_TIME 3 /* Time after system clock changed */ ++#define USER_PROCESS 4 /* A user process */ ++#define INIT_PROCESS 5 /* A process spawned by the init process */ ++#define LOGIN_PROCESS 6 /* The session leader of a logged-in user */ ++#define DEAD_PROCESS 7 /* A session leader who has exited */ ++ ++/* ++ * Function prototypes for utmpx database manipulation. ++ * ++ * NOTE: These are stubs. Since Redox OS does not have a utmp/utmpx ++ * database, these functions won't have a real implementation. They ++ * are declared here to satisfy the linker. ++ */ ++void endutxent(void); ++struct utmpx *getutxent(void); ++struct utmpx *getutxid(const struct utmpx *); ++struct utmpx *getutxline(const struct utmpx *); ++struct utmpx *pututxline(const struct utmpx *); ++void setutxent(void); ++ ++#ifdef __cplusplus ++} ++#endif ++ ++#endif /* __redox__ */ ++#endif /* _COMPAT_UTMPX_H */ +\ No newline at end of file +diff -ruwN source/regress/netcat.c source-new/regress/netcat.c +--- source/regress/netcat.c 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/regress/netcat.c 2025-08-20 11:50:49.164126484 +0700 +@@ -1384,7 +1384,9 @@ + #include + #include + #include ++#ifndef __redox__ + #include ++#endif + + #define SOCKS_PORT "1080" + #define HTTP_PROXY_PORT "3128" diff -ruwN source/sshbuf-misc.c source-new/sshbuf-misc.c ---- source/sshbuf-misc.c 2018-10-16 18:01:20.000000000 -0600 -+++ source-new/sshbuf-misc.c 2019-01-15 20:45:08.969783102 -0700 +--- source/sshbuf-misc.c 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/sshbuf-misc.c 2025-08-20 11:51:17.444108963 +0700 @@ -28,7 +28,9 @@ #include #include #include -+#if !defined(__redox__) ++#ifndef __redox__ #include +#endif #include + #include - #include "ssherr.h" -@@ -158,4 +160,3 @@ - r[l] = '\0'; - return r; - } -- diff -ruwN source/sshkey.c source-new/sshkey.c ---- source/sshkey.c 2018-10-16 18:01:20.000000000 -0600 -+++ source-new/sshkey.c 2019-01-15 20:13:21.629829281 -0700 -@@ -42,7 +42,9 @@ - #include +--- source/sshkey.c 2024-07-01 11:36:28.000000000 +0700 ++++ source-new/sshkey.c 2025-08-20 11:50:36.114133643 +0700 +@@ -43,7 +43,9 @@ #include + #include #include -+#if !defined(__redox__) ++#ifndef __redox__ #include +#endif + #include #ifdef HAVE_UTIL_H #include - #endif /* HAVE_UTIL_H */