diff options
| author | Garrett D'Amore <garrett@damore.org> | 2025-01-03 08:02:22 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2025-01-03 08:38:19 -0800 |
| commit | 960e96723f6cfe64c370b7c1168c664f4c49deae (patch) | |
| tree | b342ee0f9888daf0783d8b8c7663a7b3a8cf266d | |
| parent | 86d073f3a7511b3045f5b183954eb6cd633fe930 (diff) | |
| download | nng-960e96723f6cfe64c370b7c1168c664f4c49deae.tar.gz nng-960e96723f6cfe64c370b7c1168c664f4c49deae.tar.bz2 nng-960e96723f6cfe64c370b7c1168c664f4c49deae.zip | |
fixes #2061 Move IPC parameters from uint64 to int
| -rw-r--r-- | docs/ref/tran/ipc.md | 8 | ||||
| -rw-r--r-- | docs/ref/tran/socket.md | 14 | ||||
| -rw-r--r-- | src/platform/posix/posix_ipcconn.c | 30 | ||||
| -rw-r--r-- | src/platform/posix/posix_peerid.c | 30 | ||||
| -rw-r--r-- | src/platform/posix/posix_peerid.h | 7 | ||||
| -rw-r--r-- | src/platform/posix/posix_sockfd.c | 28 | ||||
| -rw-r--r-- | src/platform/windows/win_ipcconn.c | 7 | ||||
| -rw-r--r-- | src/sp/transport/ipc/ipc_test.c | 23 | ||||
| -rw-r--r-- | src/sp/transport/socket/sockfd_test.c | 23 |
9 files changed, 82 insertions, 88 deletions
diff --git a/docs/ref/tran/ipc.md b/docs/ref/tran/ipc.md index 6c5cb104..3d046ee5 100644 --- a/docs/ref/tran/ipc.md +++ b/docs/ref/tran/ipc.md @@ -81,10 +81,10 @@ where supported by the underlying platform. | `NNG_OPT_IPC_PERMISSIONS` | `int` | Settable on listeners before they start, this is the UNIX file mode used when creating the socket. | | `NNG_OPT_LOCADDR` | [`nng_sockaddr`] | Local socket address, either [`nng_sockaddr_ipc`] or [`nng_sockaddr_abstract`]. | | `NNG_OPT_REMADDR` | [`nng_sockaddr`] | Remote socket address, either [`nng_sockaddr_ipc`] or [`nng_sockaddr_abstract`]. | -| `NNG_OPT_PEER_GID` | `uint64_t` | Read only option, returns the group ID of the process at the other end of the socket, if platform supports it. | -| `NNG_OPT_PEER_PID` | `uint64_t` | Read only option, returns the processed ID of the process at the other end of the socket, if platform supports it. | -| `NNG_OPT_PEER_UID` | `uint64_t` | Read only option, returns the user ID of the process at the other end of the socket, if platform supports it. | -| `NNG_OPT_PEER_ZONEID` | `uint64_t` | Read only option, returns the zone ID of the process at the other end of the socket, if platform supports it. | +| `NNG_OPT_PEER_GID` | `int` | Read only option, returns the group ID of the process at the other end of the socket, if platform supports it. | +| `NNG_OPT_PEER_PID` | `int` | Read only option, returns the processed ID of the process at the other end of the socket, if platform supports it. | +| `NNG_OPT_PEER_UID` | `int` | Read only option, returns the user ID of the process at the other end of the socket, if platform supports it. | +| `NNG_OPT_PEER_ZONEID` | `int` | Read only option, returns the zone ID of the process at the other end of the socket, if platform supports it. | | [`NNG_OPT_LISTEN_FD`] | `int` | Write only for listeners before they start, use the named socket for accepting (for use with socket activation). | ### Other Configuration Parameters diff --git a/docs/ref/tran/socket.md b/docs/ref/tran/socket.md index cba55a4b..45a0a621 100644 --- a/docs/ref/tran/socket.md +++ b/docs/ref/tran/socket.md @@ -37,13 +37,13 @@ There are no further socket details available. The following transport options are supported by this transport. -| Option | Type | Description | -| --------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `NNG_OPT_SOCKET_FD` | `int` | Write-only option, that may be set multiple times on a listener. Each time this is set, the listener will create a [pipe] backed by the given file descriptor passed as an argument. | -| `NNG_OPT_PEER_GID` | `uint64_t` | Read only option, returns the group ID of the process at the other end of the socket, if platform supports it. | -| `NNG_OPT_PEER_PID` | `uint64_t` | Read only option, returns the processed ID of the process at the other end of the socket, if platform supports it. | -| `NNG_OPT_PEER_UID` | `uint64_t` | Read only option, returns the user ID of the process at the other end of the socket, if platform supports it. | -| `NNG_OPT_PEER_ZONEID` | `uint64_t` | Read only option, returns the zone ID of the process at the other end of the socket, if platform supports it. | +| Option | Type | Description | +| --------------------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `NNG_OPT_SOCKET_FD` | `int` | Write-only option, that may be set multiple times on a listener. Each time this is set, the listener will create a [pipe] backed by the given file descriptor passed as an argument. | +| `NNG_OPT_PEER_GID` | `int` | Read only option, returns the group ID of the process at the other end of the socket, if platform supports it. | +| `NNG_OPT_PEER_PID` | `int` | Read only option, returns the processed ID of the process at the other end of the socket, if platform supports it. | +| `NNG_OPT_PEER_UID` | `int` | Read only option, returns the user ID of the process at the other end of the socket, if platform supports it. | +| `NNG_OPT_PEER_ZONEID` | `int` | Read only option, returns the zone ID of the process at the other end of the socket, if platform supports it. | > [!NOTE] > The `NNG_OPT_PEER_GID`, `NNG_OPT_PEER_PID`, `NNG_OPT_PEER_UID`, and `NNG_OPT_PEER_ZONEID` options depend on platform support. diff --git a/src/platform/posix/posix_ipcconn.c b/src/platform/posix/posix_ipcconn.c index b3376815..41676340 100644 --- a/src/platform/posix/posix_ipcconn.c +++ b/src/platform/posix/posix_ipcconn.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2019 Devolutions <info@devolutions.net> // @@ -304,14 +304,14 @@ ipc_get_peer_uid(void *arg, void *buf, size_t *szp, nni_type t) { ipc_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; if ((rv = nni_posix_peerid(nni_posix_pfd_fd(&c->pfd), &id, &ignore, &ignore, &ignore)) != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -319,14 +319,14 @@ ipc_get_peer_gid(void *arg, void *buf, size_t *szp, nni_type t) { ipc_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; if ((rv = nni_posix_peerid(nni_posix_pfd_fd(&c->pfd), &ignore, &id, &ignore, &ignore)) != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -334,18 +334,18 @@ ipc_get_peer_zoneid(void *arg, void *buf, size_t *szp, nni_type t) { ipc_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; if ((rv = nni_posix_peerid(nni_posix_pfd_fd(&c->pfd), &ignore, &ignore, &ignore, &id)) != 0) { return (rv); } - if (id == (uint64_t) -1) { + if (id == -1) { // NB: -1 is not a legal zone id (illumos/Solaris) return (NNG_ENOTSUP); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -353,18 +353,18 @@ ipc_get_peer_pid(void *arg, void *buf, size_t *szp, nni_type t) { ipc_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; if ((rv = nni_posix_peerid(nni_posix_pfd_fd(&c->pfd), &ignore, &ignore, &id, &ignore)) != 0) { return (rv); } - if (id == (uint64_t) -1) { + if (id == -1) { // NB: -1 is not a legal process id return (NNG_ENOTSUP); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int diff --git a/src/platform/posix/posix_peerid.c b/src/platform/posix/posix_peerid.c index e0020150..0ce9d6bc 100644 --- a/src/platform/posix/posix_peerid.c +++ b/src/platform/posix/posix_peerid.c @@ -1,5 +1,5 @@ // -// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2019 Devolutions <info@devolutions.net> // @@ -38,10 +38,8 @@ #define SOL_LOCAL 0 #endif - int -nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, - uint64_t *znid) +nni_posix_peerid(int fd, int *euid, int *egid, int *prid, int *znid) { #if defined(NNG_HAVE_GETPEEREID) && !defined(NNG_HAVE_LOCALPEERCRED) uid_t uid; @@ -52,8 +50,8 @@ nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, } *euid = uid; *egid = gid; - *prid = (uint64_t) -1; - *znid = (uint64_t) -1; + *prid = -1; + *znid = -1; return (0); #elif defined(NNG_HAVE_GETPEERUCRED) ucred_t *ucp = NULL; @@ -75,7 +73,7 @@ nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, *euid = uc.uid; *egid = uc.gid; *prid = uc.pid; - *znid = (uint64_t) -1; + *znid = -1; return (0); #elif defined(NNG_HAVE_SOPEERCRED) struct ucred uc; @@ -86,7 +84,7 @@ nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, *euid = uc.uid; *egid = uc.gid; *prid = uc.pid; - *znid = (uint64_t) -1; + *znid = -1; return (0); #elif defined(NNG_HAVE_LOCALPEERCRED) struct xucred xu; @@ -96,17 +94,14 @@ nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, } *euid = xu.cr_uid; *egid = xu.cr_gid; - *prid = (uint64_t) -1; - *znid = (uint64_t) -1; + *prid = -1; + *znid = -1; #if defined(NNG_HAVE_LOCALPEERPID) // documented on macOS since 10.8 - { - pid_t pid; - if (getsockopt(fd, SOL_LOCAL, LOCAL_PEERPID, &pid, &len) == - 0) { - *prid = (uint64_t) pid; - } + pid_t pid; + if (getsockopt(fd, SOL_LOCAL, LOCAL_PEERPID, &pid, &len) == 0) { + *prid = pid; } -#endif // NNG_HAVE_LOCALPEERPID +#endif // NNG_HAVE_LOCALPEERPID return (0); #else if (fd < 0) { @@ -119,4 +114,3 @@ nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, return (NNG_ENOTSUP); #endif } - diff --git a/src/platform/posix/posix_peerid.h b/src/platform/posix/posix_peerid.h index 57e9abff..be3d67de 100644 --- a/src/platform/posix/posix_peerid.h +++ b/src/platform/posix/posix_peerid.h @@ -1,5 +1,5 @@ // -// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -19,7 +19,6 @@ #include "core/nng_impl.h" #include <sys/types.h> -int nni_posix_peerid( - int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, uint64_t *znid); +int nni_posix_peerid(int fd, int *euid, int *egid, int *prid, int *znid); -#endif // PLATFORM_POSIX_PEERID_H
\ No newline at end of file +#endif // PLATFORM_POSIX_PEERID_H diff --git a/src/platform/posix/posix_sockfd.c b/src/platform/posix/posix_sockfd.c index 96782c04..0bdee2d6 100644 --- a/src/platform/posix/posix_sockfd.c +++ b/src/platform/posix/posix_sockfd.c @@ -339,14 +339,14 @@ sfd_get_peer_uid(void *arg, void *buf, size_t *szp, nni_type t) { nni_sfd_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; rv = nni_posix_peerid(c->fd, &id, &ignore, &ignore, &ignore); if (rv != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -354,14 +354,14 @@ sfd_get_peer_gid(void *arg, void *buf, size_t *szp, nni_type t) { nni_sfd_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; rv = nni_posix_peerid(c->fd, &ignore, &id, &ignore, &ignore); if (rv != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -369,18 +369,18 @@ sfd_get_peer_zoneid(void *arg, void *buf, size_t *szp, nni_type t) { nni_sfd_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; rv = nni_posix_peerid(c->fd, &ignore, &ignore, &ignore, &id); if (rv != 0) { return (rv); } - if (id == (uint64_t) -1) { + if (id == -1) { // NB: -1 is not a legal zone id (illumos/Solaris) return (NNG_ENOTSUP); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -388,18 +388,18 @@ sfd_get_peer_pid(void *arg, void *buf, size_t *szp, nni_type t) { nni_sfd_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; rv = nni_posix_peerid(c->fd, &ignore, &ignore, &id, &ignore); if (rv != 0) { return (rv); } - if (id == (uint64_t) -1) { + if (id == -1) { // NB: -1 is not a legal process id return (NNG_ENOTSUP); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static const nni_option sfd_options[] = { diff --git a/src/platform/windows/win_ipcconn.c b/src/platform/windows/win_ipcconn.c index f6c1b2a4..353d703f 100644 --- a/src/platform/windows/win_ipcconn.c +++ b/src/platform/windows/win_ipcconn.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2019 Devolutions <info@devolutions.net> // @@ -407,7 +407,10 @@ ipc_conn_get_peer_pid(void *c, void *buf, size_t *szp, nni_opt_type t) return (nni_win_error(GetLastError())); } } - return (nni_copyout_u64(id, buf, szp, t)); + // While the above APIs take ULONG, the actual process IDs in + // Windows are DWORD (i.e. int). See GetProcessId() that returns an + // int. + return (nni_copyout_int((int) id, buf, szp, t)); } static const nni_option ipc_conn_options[] = { diff --git a/src/sp/transport/ipc/ipc_test.c b/src/sp/transport/ipc/ipc_test.c index 1c758125..4d8f3ab7 100644 --- a/src/sp/transport/ipc/ipc_test.c +++ b/src/sp/transport/ipc/ipc_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Cody Piersall <cody.piersall@gmail.com> // // This software is supplied under the terms of the MIT License, a @@ -620,7 +620,7 @@ test_ipc_pipe_peer(void) nng_socket s0, s1; nng_msg *msg; nng_pipe p; - uint64_t id; + int id; char *addr; NUTS_ADDR(addr, "ipc"); @@ -639,23 +639,22 @@ test_ipc_pipe_peer(void) p = nng_msg_get_pipe(msg); NUTS_ASSERT(nng_pipe_id(p) != -1); #if defined(NNG_PLATFORM_DARWIN) || defined(NNG_PLATFORM_LINUX) - NUTS_PASS(nng_pipe_get_uint64(p, NNG_OPT_PEER_PID, &id)); - NUTS_ASSERT(id == (uint64_t) getpid()); + NUTS_PASS(nng_pipe_get_int(p, NNG_OPT_PEER_PID, &id)); + NUTS_ASSERT(id == (int) getpid()); #endif #if defined(NNG_PLATFORM_DARWIN) || defined(NNG_PLATFORM_LINUX) - NUTS_PASS(nng_pipe_get_uint64(p, NNG_OPT_PEER_UID, &id)); - NUTS_ASSERT(id == (uint64_t) getuid()); + NUTS_PASS(nng_pipe_get_int(p, NNG_OPT_PEER_UID, &id)); + NUTS_ASSERT(id == (int) getuid()); #endif #if defined(NNG_PLATFORM_DARWIN) || defined(NNG_PLATFORM_LINUX) - NUTS_PASS(nng_pipe_get_uint64(p, NNG_OPT_PEER_GID, &id)); - NUTS_ASSERT(id == (uint64_t) getgid()); + NUTS_PASS(nng_pipe_get_int(p, NNG_OPT_PEER_GID, &id)); + NUTS_ASSERT(id == (int) getgid()); #endif #if defined(NNG_PLATFORM_SUNOS) - NUTS_PASS(nng_pipe_get_uint64(p, NNG_OPT_PEER_ZONEID, &id)); - NUTS_ASSERT(id == (uint64_t) getzoneid()); + NUTS_PASS(nng_pipe_get_int(p, NNG_OPT_PEER_ZONEID, &id)); + NUTS_ASSERT(id == (int) getzoneid()); #else - NUTS_FAIL( - nng_pipe_get_uint64(p, NNG_OPT_PEER_ZONEID, &id), NNG_ENOTSUP); + NUTS_FAIL(nng_pipe_get_int(p, NNG_OPT_PEER_ZONEID, &id), NNG_ENOTSUP); #endif nng_msg_free(msg); diff --git a/src/sp/transport/socket/sockfd_test.c b/src/sp/transport/socket/sockfd_test.c index 5a6035a6..e5d62f5d 100644 --- a/src/sp/transport/socket/sockfd_test.c +++ b/src/sp/transport/socket/sockfd_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2018 Devolutions <info@devolutions.net> // Copyright 2018 Cody Piersall <cody.piersall@gmail.com> @@ -425,7 +425,7 @@ test_sockfd_pipe_peer(void) nng_listener l; nng_msg *msg; nng_pipe p; - uint64_t id; + int id; NUTS_PASS(nng_socket_pair(fds)); NUTS_OPEN(s0); @@ -444,23 +444,22 @@ test_sockfd_pipe_peer(void) p = nng_msg_get_pipe(msg); NUTS_ASSERT(nng_pipe_id(p) != -1); #if defined(NNG_PLATFORM_DARWIN) || defined(NNG_PLATFORM_LINUX) - NUTS_PASS(nng_pipe_get_uint64(p, NNG_OPT_PEER_PID, &id)); - NUTS_ASSERT(id == (uint64_t) getpid()); + NUTS_PASS(nng_pipe_get_int(p, NNG_OPT_PEER_PID, &id)); + NUTS_ASSERT(id == (int) getpid()); #endif #if defined(NNG_PLATFORM_DARWIN) || defined(NNG_PLATFORM_LINUX) - NUTS_PASS(nng_pipe_get_uint64(p, NNG_OPT_PEER_UID, &id)); - NUTS_ASSERT(id == (uint64_t) getuid()); + NUTS_PASS(nng_pipe_get_int(p, NNG_OPT_PEER_UID, &id)); + NUTS_ASSERT(id == (int) getuid()); #endif #if defined(NNG_PLATFORM_DARWIN) || defined(NNG_PLATFORM_LINUX) - NUTS_PASS(nng_pipe_get_uint64(p, NNG_OPT_PEER_GID, &id)); - NUTS_ASSERT(id == (uint64_t) getgid()); + NUTS_PASS(nng_pipe_get_int(p, NNG_OPT_PEER_GID, &id)); + NUTS_ASSERT(id == (int) getgid()); #endif #if defined(NNG_PLATFORM_SUNOS) - NUTS_PASS(nng_pipe_get_uint64(p, NNG_OPT_PEER_ZONEID, &id)); - NUTS_ASSERT(id == (uint64_t) getzoneid()); + NUTS_PASS(nng_pipe_get_int(p, NNG_OPT_PEER_ZONEID, &id)); + NUTS_ASSERT(id == (int) getzoneid()); #else - NUTS_FAIL( - nng_pipe_get_uint64(p, NNG_OPT_PEER_ZONEID, &id), NNG_ENOTSUP); + NUTS_FAIL(nng_pipe_get_int(p, NNG_OPT_PEER_ZONEID, &id), NNG_ENOTSUP); #endif nng_msg_free(msg); |
