diff options
author | Fabian Groffen <grobian@gentoo.org> | 2017-06-07 14:36:22 +0200 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2017-06-27 13:10:32 +0200 |
commit | 20b9df53cf07c0693257f5f01fa1ff945b4cae4a (patch) | |
tree | 0516441e8b4de3aeab2d9519fead500a85271c47 /common | |
parent | ca9648c7c1cd38e306d7b3194900e4120eb179a0 (diff) |
p11_get_upeer_id: implement case using ucred.h
Solaris can retrieve this information via getpeerucred().
Diffstat (limited to 'common')
-rw-r--r-- | common/unix-peer.c | 19 |
1 files changed, 19 insertions, 0 deletions
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 <sys/uio.h> #include <sys/errno.h> +#ifdef HAVE_UCRED_H +# include <ucred.h> +#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 |