From ddce490e794c0d1b42dbe6ac1ef21a2b14b4e89d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 16 Jun 2005 05:51:46 +0000 Subject: [PATCH] 2005-06-16 Colin Walters * python/dbus_bindings.pyx.in: Import size_t, __int64_t, __uint64_t, and __signed. * dbus/dbus-sysdeps.c (write_credentials_byte): Define cmsg struct, output it. (_dbus_read_credentials_unix_socket): Use cmsg struct. Patch from Joe Markus Clarke for FreeBSD support. --- ChangeLog | 12 +++++++++++ dbus/dbus-sysdeps.c | 52 +++++++++++++++++++++++++++++++++------------ python/dbus_bindings.pyx.in | 8 +++++++ 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5de6eee..51f1b57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2005-06-16 Colin Walters + * python/dbus_bindings.pyx.in: Import size_t, + __int64_t, __uint64_t, and __signed. + + * dbus/dbus-sysdeps.c (write_credentials_byte): + Define cmsg struct, output it. + (_dbus_read_credentials_unix_socket): + Use cmsg struct. + + Patch from Joe Markus Clarke for FreeBSD support. + +2005-06-16 Colin Walters + * tools/dbus-send.c (append_array): Use strtok. (append_dict): New function. (type_from_name): New function, extracted from main. diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index 917a240..1d0a64a 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -742,12 +742,40 @@ write_credentials_byte (int server_fd, { int bytes_written; char buf[1] = { '\0' }; +#if defined(HAVE_CMSGCRED) && !defined(LOCAL_CREDS) + struct { + struct cmsghdr hdr; + struct cmsgcred cred; + } cmsg; + struct iovec iov; + struct msghdr msg; +#endif + +#if defined(HAVE_CMSGCRED) && !defined(LOCAL_CREDS) + iov.iov_base = buf; + iov.iov_len = 1; + + memset (&msg, 0, sizeof (msg)); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + + msg.msg_control = &cmsg; + msg.msg_controllen = sizeof (cmsg); + memset (&cmsg, 0, sizeof (cmsg)); + cmsg.hdr.cmsg_len = sizeof (cmsg); + cmsg.hdr.cmsg_level = SOL_SOCKET; + cmsg.hdr.cmsg_type = SCM_CREDS; +#endif _DBUS_ASSERT_ERROR_IS_CLEAR (error); again: +#if defined(HAVE_CMSGCRED) && !defined(LOCAL_CREDS) + bytes_written = sendmsg (server_fd, &msg, 0); +#else bytes_written = write (server_fd, buf, 1); +#endif if (bytes_written < 0 && errno == EINTR) goto again; @@ -801,8 +829,10 @@ _dbus_read_credentials_unix_socket (int client_fd, char buf; #ifdef HAVE_CMSGCRED - char cmsgmem[CMSG_SPACE (sizeof (struct cmsgcred))]; - struct cmsghdr *cmsg = (struct cmsghdr *) cmsgmem; + struct { + struct cmsghdr hdr; + struct cmsgcred cred; + } cmsg; #endif _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -837,9 +867,9 @@ _dbus_read_credentials_unix_socket (int client_fd, msg.msg_iovlen = 1; #ifdef HAVE_CMSGCRED - memset (cmsgmem, 0, sizeof (cmsgmem)); - msg.msg_control = cmsgmem; - msg.msg_controllen = sizeof (cmsgmem); + memset (&cmsg, 0, sizeof (cmsg)); + msg.msg_control = &cmsg; + msg.msg_controllen = sizeof (cmsg); #endif again: @@ -862,7 +892,7 @@ _dbus_read_credentials_unix_socket (int client_fd, } #ifdef HAVE_CMSGCRED - if (cmsg->cmsg_len < sizeof (cmsgmem) || cmsg->cmsg_type != SCM_CREDS) + if (cmsg->hdr.cmsg_len < sizeof (cmsg) || cmsg.hdr.cmsg_type != SCM_CREDS) { dbus_set_error (error, DBUS_ERROR_FAILED, "Message from recvmsg() was not SCM_CREDS"); @@ -890,13 +920,9 @@ _dbus_read_credentials_unix_socket (int client_fd, cr_len, (int) sizeof (cr), _dbus_strerror (errno)); } #elif defined(HAVE_CMSGCRED) - struct cmsgcred *cred; - - cred = (struct cmsgcred *) CMSG_DATA (cmsg); - - credentials->pid = cred->cmcred_pid; - credentials->uid = cred->cmcred_euid; - credentials->gid = cred->cmcred_groups[0]; + credentials->pid = cmsg.cred.cmcred_pid; + credentials->uid = cmsg.cred.cmcred_euid; + credentials->gid = cmsg.cred.cmcred_groups[0]; #else /* !SO_PEERCRED && !HAVE_CMSGCRED */ _dbus_verbose ("Socket credentials not supported on this OS\n"); #endif diff --git a/python/dbus_bindings.pyx.in b/python/dbus_bindings.pyx.in index 8689d8c..3c81993 100644 --- a/python/dbus_bindings.pyx.in +++ b/python/dbus_bindings.pyx.in @@ -7,6 +7,14 @@ #FIXME: find memory leaks that I am sure exist +cdef extern from "sys/types.h": + ctypedef size_t + ctypedef __int64_t + ctypedef __uint64_t + +cdef extern from "sys/cdefs.h": + ctypedef __signed + #include "dbus_h_wrapper.h" cdef extern from "stdlib.h": -- 2.7.4