| 1 | This is a combination of three patches:
|
| 2 |
|
| 3 | 1) Taken from https://salsa.debian.org/debian/libtirpc/-/raw/master/debian/patches/03-kfreebsd.diff
|
| 4 |
|
| 5 | Description: Fix build on non Linux architectures
|
| 6 | Author: Andreas Beckmann <[email protected]>
|
| 7 | Last-Update: 2025-03-17
|
| 8 |
|
| 9 | 2) Taken from https://salsa.debian.org/debian/libtirpc/-/raw/master/debian/patches/05-hurd-port.diff
|
| 10 |
|
| 11 | Description: Get source building on Hurd
|
| 12 | - Look for <sys/user.h> before using it.
|
| 13 | - Define MAXHOSTNAMELEN to 64 if missing.
|
| 14 | - Bind sockets on Hurd like on Linux.
|
| 15 | Author: Petter Reinholdtsen <[email protected]>
|
| 16 | Last-Update: 2025-03-17
|
| 17 |
|
| 18 | 3) Taken from https://salsa.debian.org/debian/libtirpc/-/raw/master/debian/patches/06-hurd-client-port.diff
|
| 19 | Description: Fix client code for hurd, avoiding malloc overflow
|
| 20 | When trying to setup a inet connection, it happens the following:
|
| 21 | - in libtirp, src/clnt_vc.c, clnt_vc_create gets called
|
| 22 | - when trying to allocate vc_fd_locks, __rpc_dtbsize() is used as size
|
| 23 | for that array of fd locks
|
| 24 | - __rpc_dtbsize(), in src/rpc_generic.c, queries using rlimit the
|
| 25 | maximum (rlim_max) number of file descriptors (RLIMIT_NOFILE):
|
| 26 | - on Linux, the default is { rlim_cur = 1024, rlim_max = 4096 }
|
| 27 | - on kFreeBSD, the default is { rlim_cur = 1024, rlim_max = 1024 }
|
| 28 | - on Hurd, the default is { rlim_cur = 1024, rlim_max = RLIM_INFINITY }
|
| 29 | meaning that on Hurd the memory allocation fails (as
|
| 30 | __rpc_dtbsize() * sizeof(int) overflows and is negative)
|
| 31 |
|
| 32 | Change libtiprc so __rpc_dtbsize falls back on rlim_cur if rlim_max
|
| 33 | is unlimited.
|
| 34 |
|
| 35 | This patch fixes the client connection using inet sockets; local unix
|
| 36 | sockets are not working, for two reasons so far:
|
| 37 | - getpeername on them gives EOPNOTSUPP
|
| 38 | - SO_REUSEADDR is not implemented for them
|
| 39 | Author: Pino Toscano <[email protected]>
|
| 40 |
|
| 41 | Bug-Debian: http://bugs.debian.org/739674
|
| 42 | Last-Update: 2020-03-03
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 | |
| 47 | |
| 48 | @@ -650,6 +650,7 @@
|
| 49 | void
|
| 50 | svc_dg_enable_pktinfo(int fd, const struct __rpc_sockinfo *si)
|
| 51 | {
|
| 52 | +#ifdef __linux__
|
| 53 | int val = 1;
|
| 54 |
|
| 55 | switch (si->si_af) {
|
| 56 | @@ -662,6 +663,7 @@
|
| 57 | break;
|
| 58 | #endif
|
| 59 | }
|
| 60 | +#endif
|
| 61 | }
|
| 62 |
|
| 63 | /*
|
| 64 | @@ -672,6 +674,7 @@
|
| 65 | int
|
| 66 | svc_dg_valid_pktinfo(struct msghdr *msg)
|
| 67 | {
|
| 68 | +#ifdef __linux__
|
| 69 | struct cmsghdr *cmsg;
|
| 70 |
|
| 71 | if (!msg->msg_name)
|
| 72 | @@ -718,4 +721,7 @@
|
| 73 | }
|
| 74 |
|
| 75 | return 1;
|
| 76 | +#else
|
| 77 | + return 0;
|
| 78 | +#endif
|
| 79 | }
|
| 80 | |
| 81 | |
| 82 | @@ -76,10 +76,12 @@
|
| 83 | #define MCALL_MSG_SIZE 24
|
| 84 |
|
| 85 | #define CMGROUP_MAX 16
|
| 86 | -#define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
|
| 87 |
|
| 88 | #undef rpc_createerr /* make it clear it is a thread safe variable */
|
| 89 |
|
| 90 | +#ifndef SCM_CREDS
|
| 91 | +#define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
|
| 92 | +
|
| 93 | /*
|
| 94 | * Credentials structure, used to verify the identity of a peer
|
| 95 | * process that has sent us a message. This is allocated by the
|
| 96 | @@ -95,6 +97,7 @@
|
| 97 | short cmcred_ngroups; /* number or groups */
|
| 98 | gid_t cmcred_groups[CMGROUP_MAX]; /* groups */
|
| 99 | };
|
| 100 | +#endif
|
| 101 |
|
| 102 | struct cmessage {
|
| 103 | struct cmsghdr cmsg;
|
| 104 | |
| 105 | |
| 106 | @@ -31,6 +31,7 @@
|
| 107 | #include <sys/param.h>
|
| 108 | #include <sys/socket.h>
|
| 109 | #include <sys/un.h>
|
| 110 | +#include <sys/user.h>
|
| 111 |
|
| 112 | #include <errno.h>
|
| 113 | #include <unistd.h>
|
| 114 | @@ -40,12 +41,22 @@
|
| 115 | int
|
| 116 | getpeereid(int s, uid_t *euid, gid_t *egid)
|
| 117 | {
|
| 118 | +#ifdef XUCRED_VERSION
|
| 119 | + struct xucred uc;
|
| 120 | +#define uid cr_uid
|
| 121 | +#define gid cr_gid
|
| 122 | +#else
|
| 123 | struct ucred uc;
|
| 124 | +#endif
|
| 125 | socklen_t uclen;
|
| 126 | int error;
|
| 127 |
|
| 128 | uclen = sizeof(uc);
|
| 129 | +#ifdef XUCRED_VERSION
|
| 130 | + error = getsockopt(s, 0, LOCAL_PEERCRED, &uc, &uclen);
|
| 131 | +#else
|
| 132 | error = getsockopt(s, SOL_SOCKET, SO_PEERCRED, &uc, &uclen); /* SCM_CREDENTIALS */
|
| 133 | +#endif
|
| 134 | if (error != 0)
|
| 135 | return (error);
|
| 136 | // if (uc.cr_version != XUCRED_VERSION)
|
| 137 | |
| 138 | |
| 139 | @@ -36,6 +36,6 @@
|
| 140 | * These definitions are only guaranteed to be valid on Linux.
|
| 141 | */
|
| 142 |
|
| 143 | -#if defined(__linux__) || defined(__APPLE__)
|
| 144 | +#if defined(__linux__) || defined(__GLIBC__)
|
| 145 |
|
| 146 | #include <pthread.h>
|
| 147 |
|
| 148 | |
| 149 | |
| 150 | @@ -56,6 +56,11 @@
|
| 151 | #include <rpc/auth.h>
|
| 152 | #include <rpc/auth_unix.h>
|
| 153 |
|
| 154 | +/* Workaround for Hurd */
|
| 155 | +#ifndef MAXHOSTNAMELEN
|
| 156 | +# define MAXHOSTNAMELEN 64
|
| 157 | +#endif
|
| 158 | +
|
| 159 | /* auth_unix.c */
|
| 160 | static void authunix_nextverf (AUTH *);
|
| 161 | static bool_t authunix_marshal (AUTH *, XDR *);
|
| 162 | |
| 163 | |
| 164 | @@ -64,7 +64,7 @@
|
| 165 | return bindresvport_sa(sd, (struct sockaddr *)sin);
|
| 166 | }
|
| 167 |
|
| 168 | -#ifdef __linux__
|
| 169 | +#if defined(__linux__) || defined(__GNU__)
|
| 170 |
|
| 171 | #define STARTPORT 600
|
| 172 | #define LOWPORT 512
|
| 173 | |
| 174 | |
| 175 | @@ -28,10 +28,14 @@
|
| 176 | #include "config.h"
|
| 177 | #endif
|
| 178 |
|
| 179 | +#include "config.h"
|
| 180 | +
|
| 181 | #include <sys/param.h>
|
| 182 | #include <sys/socket.h>
|
| 183 | #include <sys/un.h>
|
| 184 | -#include <sys/user.h>
|
| 185 | +#ifdef HAVE_SYS_USER_H
|
| 186 | +# include <sys/user.h>
|
| 187 | +#endif /* HAVE_SYS_USER_H */
|
| 188 |
|
| 189 | #include <errno.h>
|
| 190 | #include <unistd.h>
|
| 191 | @@ -41,6 +45,9 @@
|
| 192 | int
|
| 193 | getpeereid(int s, uid_t *euid, gid_t *egid)
|
| 194 | {
|
| 195 | +#ifndef HAVE_SYS_USER_H
|
| 196 | + return(-1);
|
| 197 | +#else
|
| 198 | #ifdef XUCRED_VERSION
|
| 199 | struct xucred uc;
|
| 200 | #define uid cr_uid
|
| 201 | @@ -64,6 +71,7 @@
|
| 202 | *euid = uc.uid;
|
| 203 | *egid = uc.gid;
|
| 204 | return (0);
|
| 205 | +#endif /* HAVE_SYS_USER_H */
|
| 206 | }
|
| 207 |
|
| 208 | #endif
|
| 209 | |
| 210 | |
| 211 | @@ -200,7 +200,7 @@
|
| 212 | AC_CHECK_HEADERS([arpa/inet.h fcntl.h libintl.h limits.h locale.h
|
| 213 | netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h
|
| 214 | sys/param.h sys/socket.h sys/time.h syslog.h unistd.h features.h
|
| 215 | -gssapi/gssapi_ext.h endian.h machine/endian.h])
|
| 216 | +gssapi/gssapi_ext.h endian.h machine/endian.h sys/user.h])
|
| 217 | AX_PTHREAD
|
| 218 | AC_CHECK_FUNCS([getpeereid getrpcbyname getrpcbynumber setrpcent endrpcent getrpcent])
|
| 219 |
|
| 220 | |
| 221 | |
| 222 | @@ -107,12 +107,17 @@
|
| 223 | {
|
| 224 | static int tbsize;
|
| 225 | struct rlimit rl;
|
| 226 | + rlim_t lim;
|
| 227 |
|
| 228 | if (tbsize) {
|
| 229 | return (tbsize);
|
| 230 | }
|
| 231 | if (getrlimit(RLIMIT_NOFILE, &rl) == 0) {
|
| 232 | - return (tbsize = (int)rl.rlim_cur);
|
| 233 | + lim = rl.rlim_max;
|
| 234 | + if (lim == RLIM_INFINITY) {
|
| 235 | + lim = rl.rlim_cur;
|
| 236 | + }
|
| 237 | + return (tbsize = (int)lim);
|
| 238 | }
|
| 239 | /*
|
| 240 | * Something wrong. I'll try to save face by returning a
|