redox/recipes/wip/ssh/openssh/redox.patch
2025-08-20 06:54:12 -06:00

406 lines
12 KiB
Diff

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
+
+#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
-/* 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
+#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 <netinet/in.h>
#include <errno.h>
+#ifndef __redox__
#include <resolv.h>
+#endif
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
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 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)
+#ifdef __redox__
+
+#include <sys/types.h>
+#include <stdint.h>
+
+/*
+ * Minimalist replacement for <resolv.h> 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;
};
+#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 @@
}
/* 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 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 <sys/types.h>
#include <netinet/in.h>
+#ifndef __redox__
#include <arpa/nameser.h>
+#endif
#include <netdb.h>
+#ifndef __redox__
#include <resolv.h>
+#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 <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#ifndef __redox__
#include <arpa/nameser.h>
+#endif
#include <string.h>
#include <errno.h>
#include <stdio.h>
diff -ruwN source/openbsd-compat/openbsd-compat.h source-new/openbsd-compat/openbsd-compat.h
--- 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 <stddef.h> /* for wchar_t */
+#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 <stddef.h> // 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 <sys/types.h>
+#include <sys/time.h>
+
+#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 <utmpx.h>, 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 <stdlib.h>
#include <string.h>
#include <unistd.h>
+#ifndef __redox__
#include <resolv.h>
+#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 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 <stdio.h>
#include <limits.h>
#include <string.h>
+#ifndef __redox__
#include <resolv.h>
+#endif
#include <ctype.h>
#include <unistd.h>
diff -ruwN source/sshkey.c source-new/sshkey.c
--- 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifndef __redox__
#include <resolv.h>
+#endif
#include <time.h>
#ifdef HAVE_UTIL_H
#include <util.h>