diff options
author | Havoc Pennington <hp@redhat.com> | 2003-03-21 02:38:40 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2003-03-21 02:38:40 +0000 |
commit | b6ffea177fccb6cc4e65992da7d8b390054277f7 (patch) | |
tree | 5194ad93d495c110c88b7730f05b9265dd6ce73d /dbus/dbus-connection.c | |
parent | 056d76d809dc341b0dce160d3f79062604565c77 (diff) |
2003-03-20 Havoc Pennington <hp@redhat.com>
* dbus/dbus-connection.c (dbus_connection_set_unix_user_function):
new function
(dbus_connection_get_unix_user): new function
Diffstat (limited to 'dbus/dbus-connection.c')
-rw-r--r-- | dbus/dbus-connection.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index d70ff716..db621405 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -2211,6 +2211,64 @@ dbus_connection_handle_watch (DBusConnection *connection, } /** + * Gets the UNIX user ID of the connection if any. + * Returns #TRUE if the uid is filled in. + * Always returns #FALSE on non-UNIX platforms. + * + * @param connection the connection + * @param uid return location for the user ID + * @returns #TRUE if uid is filled in with a valid user ID + */ +dbus_bool_t +dbus_connection_get_unix_user (DBusConnection *connection, + unsigned long *uid) +{ + dbus_bool_t result; + + dbus_mutex_lock (connection->mutex); + result = _dbus_transport_get_unix_user (connection->transport, + uid); + dbus_mutex_unlock (connection->mutex); + + return result; +} + +/** + * Sets a predicate function used to determine whether a given user ID + * is allowed to connect. When an incoming connection has + * authenticated with a particular user ID, this function is called; + * if it returns #TRUE, the connection is allowed to proceed, + * otherwise the connection is disconnected. + * + * 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. + * + * @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_unix_user_function (DBusConnection *connection, + DBusAllowUnixUserFunction function, + void *data, + DBusFreeFunction free_data_function) +{ + void *old_data = NULL; + DBusFreeFunction old_free_function = NULL; + + dbus_mutex_lock (connection->mutex); + _dbus_transport_set_unix_user_function (connection->transport, + function, data, free_data_function, + &old_data, &old_free_function); + dbus_mutex_unlock (connection->mutex); + + if (old_free_function != NULL) + (* old_free_function) (old_data); +} + +/** * Adds a message filter. Filters are handlers that are run on * all incoming messages, prior to the normal handlers * registered with dbus_connection_register_handler(). |