From 2779cbf9766859d9fa6f693eb75732d226c496cd Mon Sep 17 00:00:00 2001 From: Olivier Andrieu Date: Mon, 28 Jun 2004 21:55:15 +0000 Subject: * bus/driver.c (bus_driver_handle_get_connection_unix_user) * dbus/bus.c (dbus_bus_get_unix_user) * doc/dbus-specification.xml: implement GetConnectionUnixUser method of org.freedesktop.DBus interface. * bus/dispatch.c: test case --- bus/driver.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'bus/driver.c') diff --git a/bus/driver.c b/bus/driver.c index 2b65a4c2..84e1d6b6 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -829,6 +829,83 @@ bus_driver_handle_get_service_owner (DBusConnection *connection, return FALSE; } +static dbus_bool_t +bus_driver_handle_get_connection_unix_user (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + char *service; + DBusString str; + BusRegistry *registry; + BusService *serv; + DBusConnection *conn; + DBusMessage *reply; + unsigned long uid; + const char *base_name; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + registry = bus_connection_get_registry (connection); + + service = NULL; + reply = NULL; + + if (! dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &service, + DBUS_TYPE_INVALID)) + goto failed; + + _dbus_verbose ("asked for UID of connection %s\n", service); + + _dbus_string_init_const (&str, service); + serv = bus_registry_lookup (registry, &str); + if (serv == NULL) + { + dbus_set_error (error, + DBUS_ERROR_SERVICE_HAS_NO_OWNER, + "Could not get owner of service '%s': no such service", service); + goto failed; + } + + conn = bus_service_get_primary_owner (serv); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + if (!dbus_connection_get_unix_user (conn, &uid)) + { + dbus_set_error (error, + DBUS_ERROR_FAILED, + "Could not determine UID for '%s'", service); + goto failed; + } + + if (! dbus_message_append_args (reply, + DBUS_TYPE_UINT32, (dbus_uint32_t) uid, + DBUS_TYPE_INVALID)) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + dbus_free (service); + + return TRUE; + + oom: + BUS_SET_OOM (error); + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (reply) + dbus_message_unref (reply); + dbus_free (service); + return FALSE; +} + static dbus_bool_t bus_driver_handle_reload_config (DBusConnection *connection, BusTransaction *transaction, @@ -875,6 +952,7 @@ struct { "AddMatch", bus_driver_handle_add_match }, { "RemoveMatch", bus_driver_handle_remove_match }, { "GetServiceOwner", bus_driver_handle_get_service_owner }, + { "GetConnectionUnixUser", bus_driver_handle_get_connection_unix_user }, { "ReloadConfig", bus_driver_handle_reload_config } }; -- cgit