win32 dbus_connection_get_unix_user() problem
Ralf Habacker
ralf.habacker at freenet.de
Thu Mar 8 07:29:43 PST 2007
Havoc Pennington schrieb:
> Ralf Habacker wrote:
>> In dbus/dbus-connection.c (dbus_connection_get_unix_user) there is a
>> hack, which let bus-test fail on win32:
>>
>> #ifdef DBUS_WIN
>> /* FIXME this should be done at a lower level, but it's kind of hard,
>> * just want to be sure we don't ship with this API returning
>> * some weird internal fake uid for 1.0
>> */
>> return FALSE;
>> #endif
>>
>> In http://lists.freedesktop.org/archives/dbus/2006-June/005030.html
>> there is a thread refering to a GetConnectionUnixUser dbus function and
>> a possible replacement. Does this means the same function ?
>> Because dbus_connection_get_unix_user() is usesd several times in the
>> dbus code it looks like a problem to replace this function. How to
>> proceed ?
>>
>
> connection_get_unix_user() makes no sense on Windows. So any code that
> calls it either makes no sense on Windows anyway, or will need
> changing to use a Windows alternative. For example you might add
> dbus_connection_get_windows_user() that returns a Windows username (or
> whatever is appropriate for Windows).
connection_get_unix_user() returns a type of dbus_uid_t which is an
integer type and represent the numeric equivalent of a username. On
windows the equivalent is the sid for example
S-1-5-21-3474614464-2368066142-2094027321-501. SID's are implemented as
strings.
There are 58 places in dbus code where this dbus_uid_t is used.
Following your hint means to implement in every of this 55 places a
different implementation for win32 (string) and unix (int). Tor
Lillqvist has implemented the code in this way and it was very hard to
read and to maintain. Peter Kümmel then has modified this implementation
by using an sid cache using int as hashes, which is used currently in
the win32 uid code and it works very good.
The following functions uses dbus_connection_get_unix_user():
bus_policy_create_client_policy
bus_connection_disconnected
bus_connection_get_groups
bus_connection_complete
bus_connections_check_limits
These functions are core dbus function and cannot be skipped. Replacing
the calls by windows related functions will blow up the code with
several #ifdef DBUS_WIN ... wrappers. What I have learned in the
meantime about dbus plattform related functions is that there should be
different implementations of functions using the same name.
My suggestion is now to let dbus_uid_t as int and implement the
following platform specific functions
dbus_connection_set_user_function
dbus_connection_get_user
in all crossplatform relates places mentioned above.
> IIRC GetConnectionUnixUser is a function on the bus daemon that is
> implemented by calling connection_get_unix_user(). You could add
> GetConnectionWindowsUser implemented by calling
> connection_get_windows_user(), or you could simply not have this
> feature on Windows for now.
Why is there such a different naming required ? When I contact a dbus
server and I like to know the user id of the server, why should I have
to know if this is a windows or a unix dbus server ? What I like to
know is the id of the user under which the server is running to use this
id in further calls to the server, isn't it ?
Ralf
More information about the dbus
mailing list