From: Hasso Tepper Date: Mon, 13 Jul 2009 18:23:40 +0000 (-0400) Subject: Bug 19432 - Fix handling of HAVE_CMSGCRED case (FreeBSD) X-Git-Tag: dbus-1.2.16~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5abb8aeb5e315df997cbaccfbc8865ef2b70bcf1;p=platform%2Fupstream%2Fdbus.git Bug 19432 - Fix handling of HAVE_CMSGCRED case (FreeBSD) Fixes dbus on FreeBSD and DragonFly systems. The patch is obtained from FreeBSD ports tree. Signed-off-by: Colin Walters (cherry picked from commit 7bf132c7d15c1d8214b11442f053f7d53bca9a8f) --- diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index a26f02d..573e7a2 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1041,9 +1041,9 @@ write_credentials_byte (int server_fd, int bytes_written; char buf[1] = { '\0' }; #if defined(HAVE_CMSGCRED) - struct { + union { struct cmsghdr hdr; - struct cmsgcred cred; + char cred[CMSG_SPACE (sizeof (struct cmsgcred))]; } cmsg; struct iovec iov; struct msghdr msg; @@ -1054,10 +1054,10 @@ write_credentials_byte (int server_fd, msg.msg_iov = &iov; msg.msg_iovlen = 1; - msg.msg_control = &cmsg; - msg.msg_controllen = sizeof (cmsg); + msg.msg_control = (caddr_t) &cmsg; + msg.msg_controllen = CMSG_SPACE (sizeof (struct cmsgcred)); memset (&cmsg, 0, sizeof (cmsg)); - cmsg.hdr.cmsg_len = sizeof (cmsg); + cmsg.hdr.cmsg_len = CMSG_LEN (sizeof (struct cmsgcred)); cmsg.hdr.cmsg_level = SOL_SOCKET; cmsg.hdr.cmsg_type = SCM_CREDS; #endif @@ -1129,13 +1129,10 @@ _dbus_read_credentials_socket (int client_fd, dbus_pid_t pid_read; int bytes_read; - uid_read = DBUS_UID_UNSET; - pid_read = DBUS_PID_UNSET; - #ifdef HAVE_CMSGCRED - struct { + union { struct cmsghdr hdr; - struct cmsgcred cred; + char cred[CMSG_SPACE (sizeof (struct cmsgcred))]; } cmsg; #elif defined(LOCAL_CREDS) @@ -1145,6 +1142,9 @@ _dbus_read_credentials_socket (int client_fd, } cmsg; #endif + uid_read = DBUS_UID_UNSET; + pid_read = DBUS_PID_UNSET; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); /* The POSIX spec certainly doesn't promise this, but @@ -1172,8 +1172,8 @@ _dbus_read_credentials_socket (int client_fd, #if defined(HAVE_CMSGCRED) || defined(LOCAL_CREDS) memset (&cmsg, 0, sizeof (cmsg)); - msg.msg_control = &cmsg; - msg.msg_controllen = sizeof (cmsg); + msg.msg_control = (caddr_t) &cmsg; + msg.msg_controllen = CMSG_SPACE (sizeof (struct cmsgcred)); #endif again: @@ -1211,7 +1211,8 @@ _dbus_read_credentials_socket (int client_fd, } #if defined(HAVE_CMSGCRED) || defined(LOCAL_CREDS) - if (cmsg.hdr.cmsg_len < sizeof (cmsg) || cmsg.hdr.cmsg_type != SCM_CREDS) + if (cmsg.hdr.cmsg_len < CMSG_LEN (sizeof (struct cmsgcred)) + || cmsg.hdr.cmsg_type != SCM_CREDS) { dbus_set_error (error, DBUS_ERROR_FAILED, "Message from recvmsg() was not SCM_CREDS"); @@ -1238,8 +1239,11 @@ _dbus_read_credentials_socket (int client_fd, cr_len, (int) sizeof (cr), _dbus_strerror (errno)); } #elif defined(HAVE_CMSGCRED) - pid_read = cmsg.cred.cmcred_pid; - uid_read = cmsg.cred.cmcred_euid; + struct cmsgcred *cred; + + cred = (struct cmsgcred *) CMSG_DATA (&cmsg); + pid_read = cred->cmcred_pid; + uid_read = cred->cmcred_euid; #elif defined(LOCAL_CREDS) pid_read = DBUS_PID_UNSET; uid_read = cmsg.cred.sc_uid;