dbus_bus_get_unix_user() incorrect type and other possible issue

Havoc Pennington hp at redhat.com
Fri May 18 07:57:04 PDT 2007


Doug Goldstein wrote:
> dbus_bus_get_unix_user() is suppose to return the uid of the user. A uid
> on a Linux/BSD platform is defined as a uid_t, which is always an
> unsigned 32 bit integer. Internally the function uses a dbus_uint32_t
> and does it's processing with that. However it returns an unsigned long,
> which on x86 is fine. However if you go to other platforms it can and is
> a different size (most notably amd64 where it's 64 bits). So obviously
> the type is wrong. It should return either uid_t, which might not be
> defined everywhere or just a dbus_uint32_t.

The reason for unsigned long is to avoid introducing dbus_uid_t that 
varies in size by platform. If you know your platform has 
sizeof(uid_t)==4 then just cast the unsigned long.

I can see your point, but it is kind of an academic argument now since 
the ABI is frozen on that function.

> dbus-send --system --dest=org.freedesktop.DBus --type=method_call
> --print-reply / org.freedesktop.DBus.GetConnectionUnixUser
> string:"org.freedesktop.DBus"
> And that returns:
> Error org.freedesktop.DBus.Error.NameHasNoOwner: Could not get UID of
> name 'org.freedesktop.DBus': no such name
> So it appears to always fail..

The error message could be better, but basically the issue is that 
org.freedesktop.DBus is a "special" bus name owned by the bus itself, so 
there is no connection to get the user from. It should work on any other 
name (as long as that name is owned by some app, of course).

You can get the user of the bus itself with 
dbus_connection_get_unix_user() which gets the user from the process you 
are connected to (the bus) while dbus_bus_get_unix_user() is asking the 
bus to report the user of a connection to the bus.


More information about the dbus mailing list