summaryrefslogtreecommitdiffstats
path: root/bus/driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'bus/driver.c')
-rw-r--r--bus/driver.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/bus/driver.c b/bus/driver.c
index 2a58d807..8e8a5366 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -27,6 +27,7 @@
#include "driver.h"
#include "dispatch.h"
#include "services.h"
+#include "selinux.h"
#include "signals.h"
#include "utils.h"
#include <dbus/dbus-string.h>
@@ -1014,6 +1015,79 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
}
static dbus_bool_t
+bus_driver_handle_get_connection_unix_security_context (DBusConnection *connection,
+ BusTransaction *transaction,
+ DBusMessage *message,
+ DBusError *error)
+{
+ const char *service;
+ DBusString str;
+ BusRegistry *registry;
+ BusService *serv;
+ DBusConnection *conn;
+ DBusMessage *reply;
+ BusSELinuxID *context;
+
+ _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 security context 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_NAME_HAS_NO_OWNER,
+ "Could not get security context of name '%s': no such name", service);
+ goto failed;
+ }
+
+ conn = bus_service_get_primary_owner (serv);
+
+ reply = dbus_message_new_method_return (message);
+ if (reply == NULL)
+ goto oom;
+
+ context = bus_connection_get_selinux_id (conn);
+ if (!context)
+ {
+ dbus_set_error (error,
+ DBUS_ERROR_UNIX_SECURITY_CONTEXT_UNKNOWN,
+ "Could not determine security context for '%s'", service);
+ goto failed;
+ }
+
+ if (! bus_selinux_append_context (reply, context))
+ goto oom;
+
+ if (! bus_transaction_send_from_driver (transaction, connection, reply))
+ goto oom;
+
+ dbus_message_unref (reply);
+
+ return TRUE;
+
+ oom:
+ BUS_SET_OOM (error);
+
+ failed:
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ if (reply)
+ dbus_message_unref (reply);
+ return FALSE;
+}
+
+static dbus_bool_t
bus_driver_handle_reload_config (DBusConnection *connection,
BusTransaction *transaction,
DBusMessage *message,
@@ -1093,6 +1167,10 @@ struct
DBUS_TYPE_STRING_AS_STRING,
DBUS_TYPE_UINT32_AS_STRING,
bus_driver_handle_get_connection_unix_process_id },
+ { "GetConnectionUnixSecurityContext",
+ DBUS_TYPE_STRING_AS_STRING,
+ DBUS_TYPE_STRING_AS_STRING,
+ bus_driver_handle_get_connection_unix_security_context },
{ "ReloadConfig",
"",
"",