aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/platform/posix/posix_ipcconn.c13
2 files changed, 13 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9ac25aa7..adcd039d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -447,6 +447,7 @@ else ()
nng_check_sym (epoll_create1 sys/epoll.h NNG_HAVE_EPOLL_CREATE1)
nng_check_sym (getpeereid unistd.h NNG_HAVE_GETPEEREID)
nng_check_sym (SO_PEERCRED sys/socket.h NNG_HAVE_SOPEERCRED)
+ nng_check_struct_member (sockpeercred uid sys/socket.h NNG_HAVE_SOCKPEERCRED)
nng_check_sym (LOCAL_PEERCRED sys/un.h NNG_HAVE_LOCALPEERCRED)
nng_check_sym (getpeerucred ucred.h NNG_HAVE_GETPEERUCRED)
nng_check_sym (atomic_flag_test_and_set stdatomic.h NNG_HAVE_STDATOMIC)
diff --git a/src/platform/posix/posix_ipcconn.c b/src/platform/posix/posix_ipcconn.c
index 2b46fb12..5a56d23e 100644
--- a/src/platform/posix/posix_ipcconn.c
+++ b/src/platform/posix/posix_ipcconn.c
@@ -26,7 +26,7 @@
#include <unistd.h>
#if defined(NNG_HAVE_GETPEERUCRED)
#include <ucred.h>
-#elif defined(NNG_HAVE_LOCALPEERCRED)
+#elif defined(NNG_HAVE_LOCALPEERCRED) || defined(NNG_HAVE_SOCKPEERCRED)
#include <sys/ucred.h>
#endif
@@ -350,6 +350,17 @@ ipc_conn_peerid(nni_ipc_conn *c, uint64_t *euid, uint64_t *egid,
*znid = ucred_getzoneid(ucp);
ucred_free(ucp);
return (0);
+#elif defined(NNG_HAVE_SOCKPEERCRED)
+ struct sockpeercred uc;
+ socklen_t len = sizeof(uc);
+ if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &uc, &len) != 0) {
+ return (nni_plat_errno(errno));
+ }
+ *euid = uc.uid;
+ *egid = uc.gid;
+ *prid = uc.pid;
+ *znid = (uint64_t) -1;
+ return (0);
#elif defined(NNG_HAVE_SOPEERCRED)
struct ucred uc;
socklen_t len = sizeof(uc);