From 0a3a51ca948406972d281d897c0a283b294c73bb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 13 Sep 2013 19:43:32 +0100 Subject: [PATCH 6/6] Implement NetBSD credentials-passing with LOCAL_PEEREID Now NetBSD can get process IDs too. --- bus/dispatch.c | 3 ++- dbus/dbus-sysdeps-unix.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bus/dispatch.c b/bus/dispatch.c index 5fc0d11..b7336bd 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -1309,7 +1309,8 @@ check_get_connection_unix_process_id (BusContext *context, { #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ defined(__linux__) || \ - defined(__OpenBSD__) + defined(__OpenBSD__) || \ + defined(__NetBSD__) warn_unexpected (connection, message, "not this error"); goto out; diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 099b017..e0135fc 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -22,6 +22,11 @@ * */ +#ifdef __NetBSD__ + /* Not included in AC_USE_SYSTEM_EXTENSIONS, but similar. */ +# define _NETBSD_SOURCE +#endif + #include #include "dbus-internals.h" @@ -1746,6 +1751,24 @@ _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(LOCAL_PEEREID) + /* Supported by NetBSD. + * + * This is similar to Linux/OpenBSD SO_PEERCRED (above), with the same + * advantages. */ + struct unpcbid cr; + socklen_t cr_len = sizeof (cr); + + if (getsockopt (client_fd, 0, LOCAL_PEEREID, &cr, &cr_len) == 0) + { + pid_read = cr.unp_pid; + uid_read = cr.unp_euid; + } + else + { + _dbus_verbose ("Failed to getsockopt() LOCAL_PEEREID: %s\n", + _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.8.4.rc3