From a13f6d0f9d938d4ce2274fd37d54dd9b16c6bae4 Mon Sep 17 00:00:00 2001 From: Patrick Welche Date: Sat, 12 Apr 2014 08:24:38 +0100 Subject: [PATCH] Implement NetBSD credentials-passing with LOCAL_PEEREID --- configure.ac | 5 +++++ dbus/dbus-sysdeps-unix.c | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/configure.ac b/configure.ac index 13d1c87..85f8001 100644 --- a/configure.ac +++ b/configure.ac @@ -811,6 +811,11 @@ if test x$dbus_have_struct_cmsgcred = xyes; then AC_DEFINE(HAVE_CMSGCRED,1,[Have cmsgcred structure]) fi +AC_CHECK_MEMBER([struct unpcbid.unp_pid], + [AC_DEFINE([HAVE_UNPCBID], 1, [Have unpcbid structure])], + [], + [[#include ]]) + AC_CHECK_FUNCS(getpeerucred getpeereid) AC_CHECK_FUNCS(pipe2 accept4) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index fcf5df6..b639e36 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -73,6 +73,9 @@ #ifdef HAVE_GETPEERUCRED #include #endif +#ifdef HAVE_UNPCBID +#include +#endif #ifdef HAVE_ALLOCA_H #include #endif @@ -1752,6 +1755,23 @@ _dbus_read_credentials_socket (int client_fd, _dbus_verbose ("Failed to getsockopt() credentials, returned len %d/%d: %s\n", cr_len, (int) sizeof (cr), _dbus_strerror (errno)); } +#elif defined(HAVE_UNPCBID) + /* Another variant of the above - used on NetBSD + */ + struct unpcbid cr; + socklen_t cr_len = sizeof (cr); + + if (getsockopt (client_fd, 0, LOCAL_PEEREID, &cr, &cr_len) == 0 && + cr_len == sizeof (cr)) + { + pid_read = cr.unp_pid; + uid_read = cr.unp_euid; + } + else + { + _dbus_verbose ("Failed to getsockopt() credentials, returned len %d/%d: %s\n", + cr_len, (int) sizeof (cr), _dbus_strerror (errno)); + } #elif defined(HAVE_CMSGCRED) /* We only check for HAVE_CMSGCRED, but we're really assuming that the * presence of that struct implies SCM_CREDS. Supported by at least -- 1.9.0