aboutsummaryrefslogtreecommitdiffstats
path: root/src/assuan-socket-server.c
diff options
context:
space:
mode:
authorBen Kibbey <[email protected]>2012-11-21 02:53:31 +0000
committerWerner Koch <[email protected]>2012-11-21 12:10:48 +0000
commit76ea68c2a77cafe2424fe6bc97403c9d9a6b1e95 (patch)
tree1dcf1faef19efb42b47a29566ebfc538ca10e370 /src/assuan-socket-server.c
parentImprove parsing of the GIT revision number. (diff)
downloadlibassuan-76ea68c2a77cafe2424fe6bc97403c9d9a6b1e95.tar.gz
libassuan-76ea68c2a77cafe2424fe6bc97403c9d9a6b1e95.zip
Support LOCAL_PEEREID (NetBSD) and getpeereid() (FreeBSD)
* configure.ac: check for LOCAL_PEEREID and getpeereid(). * src/assuan-socket-server.c (accept_connection_bottom): make use of LOCAL_PEEREID and getpeereid(). -- For use with assuan_get_peercred(). Note that getpeereid() does not set the PID member. LOCAL_PEEREID is checked before getpeereid() since NetBSD has both of these. SO_PEERCRED is still checked first. [Second revision] This revision adds support for LOCAL_PEEREID which NetBSD uses. Its tested against NetBSD 6.0 and may work without problems with earlier versions. FreeBSD uses getpeereid() which does not have PID support. Recent OpenBSD versions do support SO_PEERCRED and old versions have getpeereid() but also may have LOCAL_PEEREID (not sure).
Diffstat (limited to 'src/assuan-socket-server.c')
-rw-r--r--src/assuan-socket-server.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/assuan-socket-server.c b/src/assuan-socket-server.c
index 27994a2..1e8e541 100644
--- a/src/assuan-socket-server.c
+++ b/src/assuan-socket-server.c
@@ -74,6 +74,27 @@ accept_connection_bottom (assuan_context_t ctx)
ctx->pid = cr.pid;
}
}
+#elif defined(HAVE_LOCAL_PEEREID)
+ {
+ struct unpcbid unp;
+ socklen_t unpl = sizeof unp;
+
+ if (getsockopt(fd, 0, LOCAL_PEEREID, &unp, &unpl) != -1)
+ {
+ ctx->peercred.pid = unp.unp_pid;
+ ctx->peercred.uid = unp.unp_euid;
+ ctx->peercred.gid = unp.unp_egid;
+ ctx->peercred_valid = 1;
+ }
+ }
+#elif defined(HAVE_GETPEEREID)
+ {
+ if (getpeereid(fd, &ctx->peercred.uid, &ctx->peercred.gid) != -1)
+ {
+ ctx->peercred.pid = ASSUAN_INVALID_PID;
+ ctx->peercred_valid = 1;
+ }
+ }
#endif
ctx->inbound.fd = fd;