summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHasso Tepper <hasso@estpak.ee>2009-07-13 14:23:40 -0400
committerColin Walters <walters@verbum.org>2009-07-13 14:26:05 -0400
commit7bf132c7d15c1d8214b11442f053f7d53bca9a8f (patch)
tree19a165c6b58f9f29178c37142a64850a5a0638a3
parente4b271e2425a36884b5e3e70e6a32d440b41d145 (diff)
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 <walters@verbum.org>
-rw-r--r--dbus/dbus-sysdeps-unix.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index 87aafcfb..f2ea7fd9 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -1047,9 +1047,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;
@@ -1060,10 +1060,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
@@ -1135,13 +1135,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)
@@ -1151,6 +1148,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
@@ -1178,8 +1178,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:
@@ -1217,7 +1217,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");
@@ -1244,8 +1245,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;