DBUS_TYPE_LINUX_CRED ?

Simon McVittie simon.mcvittie at collabora.co.uk
Mon Dec 16 03:36:50 PST 2013


On 14/12/13 03:17, Serge Hallyn wrote:
> Quoting Lennart Poettering (mzqohf at 0pointer.de):
>> identity of some process to somebody else, make the sender
>> get itself a AF_UNIX/SOCK_DGRAM socket pair via socketpair(), and send
>> an empty datagram with the SCM_CREDENTIALS of your choice into the
>> writing side, then close that. And send the reading side over the bus as
>> file handler use the dbus "h" type. Then also close the reading
>> side. The receiver can then read the datagram out of it, with the creds
>> translated and then closes it.

This sounds sensible. GIO, part of GLib, has some nicer high-level API
for this.

Or, if you can get new features into the kernel and aren't concerned
about portability (either to other kernels or older kernels), Thiago's
"forkfd" suggestion sounds even better. Everything is a file (descriptor)?

> But a simple
> 
> 	struct ucred cred = { .pid = pid, .uid = uid, .gid = gid};
> 	dbus_message_iter_append(basic (&iter, DBUS_TYPE_LINUX_CRED, &cred)
> 
> would have been much nicer, so I thought it worth asking.

Here is the closest you're going to get to an official answer, since I'm
the one doing most of the D-Bus code review at the moment:

I don't want highly OS-specific types like struct ucred to appear in the
libdbus API: we have enough problems with this stuff in libdbus'
internals (e.g. credentials-passing on NetBSD didn't work for several
years due to lack of testing/bug-reporting, and was only recently
fixed). D-Bus is a building block, not a catch-all utility library. If
you want a general-purpose utility library, good options include GLib
and Qt; or if you're operating at a low level and you only care about
Linux, the systemd libraries and libnih might be good options.

    S



More information about the dbus mailing list