Index: dbus/dbus-auth.c =================================================================== --- dbus/dbus-auth.c (revision 615) +++ dbus/dbus-auth.c (working copy) @@ -1085,8 +1085,7 @@ if (!_dbus_string_init (&plaintext)) return FALSE; - if (!_dbus_string_append_uint (&plaintext, - _dbus_getuid ())) + if (!_dbus_append_uid (&plaintext)) goto failed; if (!_dbus_string_hex_encode (&plaintext, 0, Index: dbus/dbus-transport.c =================================================================== --- dbus/dbus-transport.c (revision 615) +++ dbus/dbus-transport.c (working copy) @@ -1108,6 +1108,32 @@ } /** + * See dbus_connection_set_unix_user_function(). + * + * @param transport the transport + * @param function the predicate + * @param data data to pass to the predicate + * @param free_data_function function to free the data + * @param old_data the old user data to be freed + * @param old_free_data_function old free data function to free it with + */ +void +_dbus_transport_set_win_user_function (DBusTransport *transport, + DBusAllowWinUserFunction function, + void *data, + DBusFreeFunction free_data_function, + void **old_data, + DBusFreeFunction *old_free_data_function) +{ + *old_data = transport->win_user_data; + *old_free_data_function = transport->free_win_user_data; + + transport->win_user_function = function; + transport->win_user_data = data; + transport->free_win_user_data = free_data_function; +} + +/** * Sets the SASL authentication mechanisms supported by this transport. * * @param transport the transport Index: dbus/dbus-connection.c =================================================================== --- dbus/dbus-connection.c (revision 615) +++ dbus/dbus-connection.c (working copy) @@ -2517,6 +2517,7 @@ dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL); dbus_connection_set_wakeup_main_function (connection, NULL, NULL, NULL); dbus_connection_set_unix_user_function (connection, NULL, NULL, NULL); + dbus_connection_set_win_user_function (connection, NULL, NULL, NULL); _dbus_watch_list_free (connection->watches); connection->watches = NULL; @@ -4859,14 +4860,7 @@ * If the function is set to #NULL (as it is by default), then * only the same UID as the server process will be allowed to * connect. - * - * On Windows, the function will be set and its free_data_function will - * be invoked when the connection is freed or a new function is set. - * However, the function will never be called, because there are - * no UNIX user ids to pass to it. * - * @todo add a Windows API analogous to dbus_connection_set_unix_user_function() - * * @param connection the connection * @param function the predicate * @param data data to pass to the predicate @@ -4893,8 +4887,46 @@ (* old_free_function) (old_data); } + /** + * see obove * + * On Windows, the function will be set and its free_data_function will + * be invoked when the connection is freed or a new function is set. + * However, the function will never be called, because there are + * no UNIX user ids to pass to it. + * + * @todo add a Windows API analogous to dbus_connection_set_unix_user_function() + * + * @param connection the connection + * @param function the predicate + * @param data data to pass to the predicate + * @param free_data_function function to free the data + */ +void +dbus_connection_set_win_user_function (DBusConnection *connection, + DBusAllowWinUserFunction function, + void *data, + DBusFreeFunction free_data_function) +{ + void *old_data = NULL; + DBusFreeFunction old_free_function = NULL; + + _dbus_return_if_fail (connection != NULL); + + CONNECTION_LOCK (connection); + _dbus_transport_set_win_user_function (connection->transport, + function, data, free_data_function, + &old_data, &old_free_function); + CONNECTION_UNLOCK (connection); + + if (old_free_function != NULL) + (* old_free_function) (old_data); +} + + +/** + * * Normally #DBusConnection automatically handles all messages to the * org.freedesktop.DBus.Peer interface. However, the message bus wants * to be able to route methods on that interface through the bus and Index: dbus/dbus-transport.h =================================================================== --- dbus/dbus-transport.h (revision 615) +++ dbus/dbus-transport.h (working copy) @@ -68,6 +68,12 @@ DBusFreeFunction free_data_function, void **old_data, DBusFreeFunction *old_free_data_function); +void _dbus_transport_set_win_user_function (DBusTransport *transport, + DBusAllowWinUserFunction function, + void *data, + DBusFreeFunction free_data_function, + void **old_data, + DBusFreeFunction *old_free_data_function); dbus_bool_t _dbus_transport_set_auth_mechanisms (DBusTransport *transport, const char **mechanisms); Index: dbus/dbus-connection.h =================================================================== --- dbus/dbus-connection.h (revision 615) +++ dbus/dbus-connection.h (working copy) @@ -31,6 +31,7 @@ #include #include #include +#include DBUS_BEGIN_DECLS @@ -140,6 +141,10 @@ typedef dbus_bool_t (* DBusAllowUnixUserFunction) (DBusConnection *connection, unsigned long uid, void *data); + +typedef dbus_bool_t (* DBusAllowWinUserFunction) (DBusConnection *connection, + DBusString *sid, + void *data); /** * Called when a pending call now has a reply available. Set with * dbus_pending_call_set_notify(). @@ -219,6 +224,10 @@ DBusAllowUnixUserFunction function, void *data, DBusFreeFunction free_data_function); +void dbus_connection_set_win_user_function (DBusConnection *connection, + DBusAllowWinUserFunction function, + void *data, + DBusFreeFunction free_data_function); void dbus_connection_set_route_peer_messages (DBusConnection *connection, dbus_bool_t value); Index: dbus/dbus-transport-protected.h =================================================================== --- dbus/dbus-transport-protected.h (revision 615) +++ dbus/dbus-transport-protected.h (working copy) @@ -102,9 +102,14 @@ DBusAllowUnixUserFunction unix_user_function; /**< Function for checking whether a user is authorized. */ void *unix_user_data; /**< Data for unix_user_function */ - DBusFreeFunction free_unix_user_data; /**< Function to free unix_user_data */ + + DBusAllowWinUserFunction win_user_function; /**< Function for checking whether a user is authorized. */ + void *win_user_data; /**< Data for win_user_function */ + DBusFreeFunction free_win_user_data; /**< Function to free win_user_data */ + + unsigned int disconnected : 1; /**< #TRUE if we are disconnected. */ unsigned int authenticated : 1; /**< Cache of auth state; use _dbus_transport_get_is_authenticated() to query value */ unsigned int send_credentials_pending : 1; /**< #TRUE if we need to send credentials */ Index: dbus/dbus-sysdeps-win.c =================================================================== --- dbus/dbus-sysdeps-win.c (revision 615) +++ dbus/dbus-sysdeps-win.c (working copy) @@ -1920,6 +1920,15 @@ return retval; } + +dbus_bool_t +_dbus_append_uid (DBusString *str) +{ + return _dbus_string_append_uint(str, _dbus_getuid ()); +} + + + #ifdef DBUS_BUILD_TESTS /** Gets our GID * @returns process GID Index: dbus/dbus-sysdeps.h =================================================================== --- dbus/dbus-sysdeps.h (revision 615) +++ dbus/dbus-sysdeps.h (working copy) @@ -225,6 +225,8 @@ dbus_uid_t _dbus_getuid (void); dbus_gid_t _dbus_getgid (void); +dbus_bool_t _dbus_append_uid (DBusString *str); + /** Opaque type representing an atomically-modifiable integer * that can be used from multiple threads. */ Index: dbus/dbus-auth-script.c =================================================================== --- dbus/dbus-auth-script.c (revision 615) +++ dbus/dbus-auth-script.c (working copy) @@ -432,8 +432,7 @@ goto out; } - if (!_dbus_string_append_uint (&username, - _dbus_getuid ())) + if (!_dbus_append_uid (&username)) { _dbus_warn ("no memory for userid\n"); _dbus_string_free (&username); if (_dbus_hash_table_get_n_entries (policy->rules_by_uid) > 0) Index: bus/connection.c =================================================================== --- bus/connection.c (revision 615) +++ bus/connection.c (working copy) @@ -244,6 +244,9 @@ dbus_connection_set_unix_user_function (connection, NULL, NULL, NULL); + dbus_connection_set_win_user_function (connection, + NULL, NULL, NULL); + dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL); @@ -369,10 +372,13 @@ } static dbus_bool_t -allow_user_function (DBusConnection *connection, - unsigned long uid, - void *data) +allow_unix_user_function (DBusConnection *connection, + unsigned long uid, + void *data) { +#ifdef DBUS_WIN + return TRUE; +#else BusConnectionData *d; d = BUS_CONNECTION_DATA (connection); @@ -380,8 +386,18 @@ _dbus_assert (d != NULL); return bus_context_allow_user (d->connections->context, uid); +#endif } +static dbus_bool_t +allow_win_user_function (DBusConnection *connection, + DBusString *sid, + void *data) +{ + /* TODO */ + return TRUE; +} + static void free_connection_data (void *data) { @@ -599,9 +615,13 @@ goto out; dbus_connection_set_unix_user_function (connection, - allow_user_function, + allow_unix_user_function, NULL, NULL); + dbus_connection_set_win_user_function (connection, + allow_win_user_function, + NULL, NULL); + dbus_connection_set_dispatch_status_function (connection, dispatch_status_function, bus_context_get_loop (connections->context), @@ -679,6 +699,9 @@ dbus_connection_set_unix_user_function (connection, NULL, NULL, NULL); + dbus_connection_set_win_user_function (connection, + NULL, NULL, NULL); + dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);