DBus connection peer PID
hp at pobox.com
Sun Oct 3 11:09:29 PDT 2010
On Sun, Oct 3, 2010 at 12:32 PM, Valentin Rusu <kde at rusu.info> wrote:
> I have the task to implement an ACL handling system and I'm trying to figure
> out how one can say what PID is sending messages to our daemon via DBus.
> Looking into documentation and 1.2 version sources I found out that DBus
> provides dbus_connection_get_unix_process_id among other functions.
> I tryed this function, but it returns false. When stepping into the code, I
> can saw that the credential/PID is not filled-in.
dbus_connection_get_unix_process_id() returns the pid of the process
on the other side of the connection. If you're using the session or
system bus (or any bus) then this process will be the bus daemon, not
the client you are talking to. The reasons I know of it would fail are
1) the connection is TCP rather than UNIX sockets or 2) the connection
is not authenticated yet (wait for the Hello message, or check
dbus_connection_get_is_authenticated) or 3) you are not on a unix
To get the pid of a client you would use the
GetConnectionUnixProcessID method on the bus. There doesn't seem to be
a convenience wrapper in dbus-bus.h but you can call it by hand with
whatever dbus binding you are using or by building a DBusMessage. Copy
the code from dbus_bus_get_unix_user() and just change the name of the
Note that you MUST use the unique bus name (starts with ":") anytime
you care about pid or user or something, otherwise there's a race
condition where the name owner can change between getting credentials
and using them.
More information about the dbus