b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | --- a/tirpc/reentrant.h |
| 2 | +++ b/tirpc/reentrant.h |
| 3 | @@ -36,7 +36,7 @@ |
| 4 | * These definitions are only guaranteed to be valid on Linux. |
| 5 | */ |
| 6 | |
| 7 | -#if defined(__linux__) |
| 8 | +#if defined(__linux__) || defined(__MACH__) |
| 9 | |
| 10 | #include <pthread.h> |
| 11 | |
| 12 | --- a/tirpc/rpc/rpcent.h |
| 13 | +++ b/tirpc/rpc/rpcent.h |
| 14 | @@ -50,7 +50,7 @@ extern "C" { |
| 15 | |
| 16 | /* These are defined in /usr/include/rpc/netdb.h, unless we are using |
| 17 | the C library without RPC support. */ |
| 18 | -#if defined(__UCLIBC__) && !defined(__UCLIBC_HAS_RPC__) || !defined(__GLIBC__) |
| 19 | +#if (defined(__UCLIBC__) && !defined(__UCLIBC_HAS_RPC__) || !defined(__GLIBC__)) && !defined(__MACH__) |
| 20 | struct rpcent { |
| 21 | char *r_name; /* name of server for this rpc program */ |
| 22 | char **r_aliases; /* alias list */ |
| 23 | --- a/src/rpc_com.h |
| 24 | +++ b/src/rpc_com.h |
| 25 | @@ -63,6 +63,14 @@ void __xprt_set_raddr(SVCXPRT *, const s |
| 26 | |
| 27 | extern int __svc_maxrec; |
| 28 | |
| 29 | +#ifndef SOL_IP |
| 30 | +#define SOL_IP IPPROTO_IP |
| 31 | +#endif |
| 32 | + |
| 33 | +#ifndef SOL_IPV6 |
| 34 | +#define SOL_IPV6 IPPROTO_IPV6 |
| 35 | +#endif |
| 36 | + |
| 37 | #ifdef __cplusplus |
| 38 | } |
| 39 | #endif |
| 40 | --- a/src/svc_dg.c |
| 41 | +++ b/src/svc_dg.c |
| 42 | @@ -37,6 +37,11 @@ |
| 43 | * |
| 44 | * Does some caching in the hopes of achieving execute-at-most-once semantics. |
| 45 | */ |
| 46 | + |
| 47 | +#ifdef __APPLE__ |
| 48 | +#define __APPLE_USE_RFC_3542 |
| 49 | +#endif |
| 50 | + |
| 51 | #include <pthread.h> |
| 52 | #include <reentrant.h> |
| 53 | #include <sys/types.h> |
| 54 | --- a/src/svc_raw.c |
| 55 | +++ b/src/svc_raw.c |
| 56 | @@ -43,6 +43,7 @@ |
| 57 | #include <sys/types.h> |
| 58 | #include <rpc/raw.h> |
| 59 | #include <stdlib.h> |
| 60 | +#include <string.h> |
| 61 | |
| 62 | #ifndef UDPMSGSIZE |
| 63 | #define UDPMSGSIZE 8800 |
| 64 | --- a/src/getpeereid.c |
| 65 | +++ b/src/getpeereid.c |
| 66 | @@ -29,12 +29,17 @@ |
| 67 | #include <sys/socket.h> |
| 68 | #include <sys/un.h> |
| 69 | |
| 70 | +#if __APPLE__ || __FreeBSD__ |
| 71 | +#include <sys/ucred.h> |
| 72 | +#endif |
| 73 | + |
| 74 | #include <errno.h> |
| 75 | #include <unistd.h> |
| 76 | |
| 77 | int |
| 78 | getpeereid(int s, uid_t *euid, gid_t *egid) |
| 79 | { |
| 80 | +#if defined(SO_PEERCRED) |
| 81 | struct ucred uc; |
| 82 | socklen_t uclen; |
| 83 | int error; |
| 84 | @@ -48,4 +53,19 @@ getpeereid(int s, uid_t *euid, gid_t *eg |
| 85 | *euid = uc.uid; |
| 86 | *egid = uc.gid; |
| 87 | return (0); |
| 88 | +#elif defined(LOCAL_PEERCRED) |
| 89 | + struct xucred uc; |
| 90 | + socklen_t uclen; |
| 91 | + int error; |
| 92 | + |
| 93 | + uclen = sizeof(uc); |
| 94 | + error = getsockopt(s, SOL_LOCAL, LOCAL_PEERCRED, &uc, &uclen); /* SCM_CREDENTIALS */ |
| 95 | + if (error != 0) |
| 96 | + return (error); |
| 97 | + *euid = uc.cr_uid; |
| 98 | + *egid = uc.cr_gid; |
| 99 | + return (0); |
| 100 | +#else |
| 101 | + return (ENOTSUP); |
| 102 | +#endif |
| 103 | } |