From 60d3d4ea3a70877a8ab0986f5a9d4b01c18fe5f2 Mon Sep 17 00:00:00 2001 From: Matt Fischer Date: Mon, 4 Feb 2013 18:17:18 -0600 Subject: [PATCH] Fixed LOCAL_CREDS code in Unix backend The Unix port supports credential passing using either cmsgcred or sockcred, however in a couple of places, the latter accidentally included some cmsgcred references. This patch changes the code so that it works properly when only LOCAL_CREDS support is present. --- dbus/dbus-sysdeps-unix.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index a031059..8cce4e7 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1670,12 +1670,16 @@ _dbus_read_credentials_socket (int client_fd, int bytes_read; #ifdef HAVE_CMSGCRED + int controllen; + union { struct cmsghdr hdr; char cred[CMSG_SPACE (sizeof (struct cmsgcred))]; } cmsg; #elif defined(LOCAL_CREDS) + int controllen; + struct { struct cmsghdr hdr; struct sockcred cred; @@ -1710,10 +1714,16 @@ _dbus_read_credentials_socket (int client_fd, msg.msg_iov = &iov; msg.msg_iovlen = 1; +#if defined(HAVE_CMSGCRED) + controllen = CMSG_SPACE (sizeof (struct cmsgcred)); +#elif defined(LOCAL_CREDS) + controllen = sizeof (struct sockcred); +#endif + #if defined(HAVE_CMSGCRED) || defined(LOCAL_CREDS) _DBUS_ZERO(cmsg); msg.msg_control = (caddr_t) &cmsg; - msg.msg_controllen = CMSG_SPACE (sizeof (struct cmsgcred)); + msg.msg_controllen = controllen; #endif again: @@ -1751,7 +1761,7 @@ _dbus_read_credentials_socket (int client_fd, } #if defined(HAVE_CMSGCRED) || defined(LOCAL_CREDS) - if (cmsg.hdr.cmsg_len < CMSG_LEN (sizeof (struct cmsgcred)) + if (cmsg.hdr.cmsg_len < controllen || cmsg.hdr.cmsg_type != SCM_CREDS) { dbus_set_error (error, DBUS_ERROR_FAILED, -- 1.8.0.msysgit.0