From 46597f23621d2e45d5e1aae050c756b24977bc24 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index a031059..9586e22 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 + size_t cmsgsize = sizeof (struct cmsgcred); + union { struct cmsghdr hdr; char cred[CMSG_SPACE (sizeof (struct cmsgcred))]; } cmsg; #elif defined(LOCAL_CREDS) + size_t cmsgsize = sizeof (struct sockcred); + struct { struct cmsghdr hdr; struct sockcred cred; @@ -1713,7 +1717,7 @@ _dbus_read_credentials_socket (int client_fd, #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 = CMSG_SPACE (cmsgsize); #endif again: @@ -1751,7 +1755,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 < CMSG_LEN (cmsgsize) || cmsg.hdr.cmsg_type != SCM_CREDS) { dbus_set_error (error, DBUS_ERROR_FAILED, -- 1.8.0.msysgit.0