From 20b9df53cf07c0693257f5f01fa1ff945b4cae4a Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Wed, 7 Jun 2017 14:36:22 +0200 Subject: [PATCH] p11_get_upeer_id: implement case using ucred.h Solaris can retrieve this information via getpeerucred(). --- common/unix-peer.c | 19 +++++++++++++++++++ configure.ac | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/common/unix-peer.c b/common/unix-peer.c index f8f20e6..7fe2eea 100644 --- a/common/unix-peer.c +++ b/common/unix-peer.c @@ -43,6 +43,10 @@ #include #include +#ifdef HAVE_UCRED_H +# include +#endif + /* Returns the unix domain socket peer information. * Returns zero on success. */ @@ -87,6 +91,21 @@ p11_get_upeer_id (int cfd, uid_t *uid, uid_t *gid, pid_t *pid) if (pid) *pid = -1; +#elif defined(HAVE_GETPEERUCRED) + /* *Solaris/OpenIndiana */ + ucred_t *ucred = NULL; + + if (getpeerucred(cfd, &ucred) == -1) + return -1; + + ret = ( (uid && (*uid = ucred_geteuid(ucred)) == -1) || + (gid && (*gid = ucred_getrgid(ucred)) == -1) || + (pid && (*pid = ucred_getpid(ucred)) == -1) ); + + ucred_free(ucred); + + if (ret) + return -1; #else #error "Unsupported UNIX variant" #endif diff --git a/configure.ac b/configure.ac index e812efe..89e5f99 100644 --- a/configure.ac +++ b/configure.ac @@ -96,7 +96,7 @@ if test "$os_unix" = "yes"; then ]) # These are thngs we can work around - AC_CHECK_HEADERS([locale.h sys/resource.h]) + AC_CHECK_HEADERS([locale.h sys/resource.h ucred.h]) AC_CHECK_MEMBERS([struct dirent.d_type],,,[#include ]) AC_CHECK_FUNCS([getprogname getexecname basename mkstemp mkdtemp]) AC_CHECK_FUNCS([getauxval issetugid getresuid secure_getenv]) @@ -104,6 +104,7 @@ if test "$os_unix" = "yes"; then AC_CHECK_FUNCS([fdwalk]) AC_CHECK_FUNCS([setenv]) AC_CHECK_FUNCS([getpeereid]) + AC_CHECK_FUNCS([getpeerucred]) # Required functions AC_CHECK_FUNCS([gmtime_r], -- 2.40.0