aboutsummaryrefslogtreecommitdiffstats
path: root/src/assuan-socket-server.c
diff options
context:
space:
mode:
authorBen Kibbey <[email protected]>2012-11-22 22:17:54 +0000
committerWerner Koch <[email protected]>2012-11-26 13:35:34 +0000
commitcd96daf5a4ddb4a7e9e373220a7aaead0a97c8cf (patch)
treea541ca3543597c70828ed2899472589973168562 /src/assuan-socket-server.c
parentSupport LOCAL_PEEREID (NetBSD) and getpeereid() (FreeBSD) (diff)
downloadlibassuan-cd96daf5a4ddb4a7e9e373220a7aaead0a97c8cf.tar.gz
libassuan-cd96daf5a4ddb4a7e9e373220a7aaead0a97c8cf.zip
Check for getpeerucred().
* configure.ac: check for getpeerucred() which (Open)Solaris/SunOS uses. * src/assuan-socket-server.c (accept_connection_bottom): make use of getpeerucred().
Diffstat (limited to 'src/assuan-socket-server.c')
-rw-r--r--src/assuan-socket-server.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/assuan-socket-server.c b/src/assuan-socket-server.c
index 1e8e541..964720b 100644
--- a/src/assuan-socket-server.c
+++ b/src/assuan-socket-server.c
@@ -30,6 +30,9 @@
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
+#ifdef HAVE_UCRED_H
+#include <ucred.h>
+#endif
#ifdef HAVE_W32_SYSTEM
# ifdef HAVE_WINSOCK2_H
# include <winsock2.h>
@@ -58,7 +61,7 @@ accept_connection_bottom (assuan_context_t ctx)
ctx->peercred_valid = 0;
#ifdef HAVE_SO_PEERCRED
{
- struct ucred cr;
+ struct ucred cr;
socklen_t cl = sizeof cr;
if ( !getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl))
@@ -70,16 +73,29 @@ accept_connection_bottom (assuan_context_t ctx)
/* This overrides any already set PID if the function returns
a valid one. */
- if (cr.pid != ASSUAN_INVALID_PID && cr.pid)
+ if (cr.pid != ASSUAN_INVALID_PID && cr.pid)
ctx->pid = cr.pid;
}
}
-#elif defined(HAVE_LOCAL_PEEREID)
+#elif defined (HAVE_GETPEERUCRED)
+ {
+ ucred_t *ucred = NULL;
+
+ if (getpeerucred (fd, &ucred) != -1)
+ {
+ ctx->peercred.uid = ucred_geteuid (ucred);
+ ctx->peercred.gid = ucred_getegid (ucred);
+ ctx->peercred.pid = ucred_getpid (ucred);
+ ctx->peercred_valid = 1;
+ ucred_free (ucred);
+ }
+ }
+#elif defined (HAVE_LOCAL_PEEREID)
{
struct unpcbid unp;
socklen_t unpl = sizeof unp;
- if (getsockopt(fd, 0, LOCAL_PEEREID, &unp, &unpl) != -1)
+ if (getsockopt (fd, 0, LOCAL_PEEREID, &unp, &unpl) != -1)
{
ctx->peercred.pid = unp.unp_pid;
ctx->peercred.uid = unp.unp_euid;
@@ -89,7 +105,7 @@ accept_connection_bottom (assuan_context_t ctx)
}
#elif defined(HAVE_GETPEEREID)
{
- if (getpeereid(fd, &ctx->peercred.uid, &ctx->peercred.gid) != -1)
+ if (getpeereid (fd, &ctx->peercred.uid, &ctx->peercred.gid) != -1)
{
ctx->peercred.pid = ASSUAN_INVALID_PID;
ctx->peercred_valid = 1;