]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
2005-07-14 Colin Walters <walters@verbum.org>
authorColin Walters <walters@verbum.org>
Thu, 14 Jul 2005 21:45:42 +0000 (21:45 +0000)
committerColin Walters <walters@verbum.org>
Thu, 14 Jul 2005 21:45:42 +0000 (21:45 +0000)
* bus/driver.c
(bus_driver_handle_get_connection_unix_security_context): New function.
(message_handlers): Add.

* bus/selinux.c (bus_selinux_append_context): New function; appends
security context to message.

* bus/selinux.h: Prototype.

* dbus/dbus-protocol.h (DBUS_ERROR_UNIX_SECURITY_CONTEXT_UNKNOWN): New.

ChangeLog
bus/driver.c
bus/selinux.c
bus/selinux.h
dbus/dbus-protocol.h

index 45640f71898d96a87796cfd634c21313be2bba66..39d38e20aac32eb17c0dfc8b28bc03f7558db0c4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-07-14  Colin Walters  <walters@verbum.org>
+
+       * bus/driver.c
+       (bus_driver_handle_get_connection_unix_security_context): New function.
+       (message_handlers): Add.
+
+       * bus/selinux.c (bus_selinux_append_context): New function; appends
+       security context to message.
+
+       * bus/selinux.h: Prototype.
+
+       * dbus/dbus-protocol.h (DBUS_ERROR_UNIX_SECURITY_CONTEXT_UNKNOWN): New.
+
 2005-07-14  John (J5) Palmieri  <johnp@redhat.com>
 
        * bus/activation.c: clean up all tabs to be 8 spaces 
index 2a58d807f087a584331d4ac02ec0993d34a9b639..8e8a53664f022dc330f2fb7da35eb09ffbddd400 100644 (file)
@@ -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>
@@ -1013,6 +1014,79 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
   return FALSE;
 }
 
+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,
@@ -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",
     "",
     "",
index c647a77b6ce484b23d540773023b9214f4b6726c..9e73cc63e702c62ee82f61319d8b310c6b3e1d48 100644 (file)
@@ -567,6 +567,19 @@ bus_selinux_allows_send (DBusConnection     *sender,
 #endif /* HAVE_SELINUX */
 }
 
+dbus_bool_t
+bus_selinux_append_context (DBusMessage    *message,
+                           BusSELinuxID   *context)
+{
+  /* Note if you change how the context is marshalled (e.g. to ay),
+   * you also need to change driver.c for the appropriate return value.
+   */
+  return dbus_message_append_args (message,
+                                  DBUS_TYPE_STRING,
+                                  SELINUX_SID_FROM_BUS (context),
+                                  DBUS_TYPE_INVALID);
+}
+
 /**
  * Gets the security context of a connection to the bus. It is up to
  * the caller to freecon() when they are done. 
index 4424fa8254a304f857493236057ade8593e36732..22339bc15eae7511cf023c282bfcedd6388ed061 100644 (file)
@@ -45,6 +45,8 @@ dbus_bool_t    bus_selinux_id_table_insert (DBusHashTable    *service_table,
 void           bus_selinux_id_table_print  (DBusHashTable    *service_table);
 const char*    bus_selinux_get_policy_root (void);
 
+dbus_bool_t    bus_selinux_append_context      (DBusMessage    *message,
+                                               BusSELinuxID   *context);
 
 dbus_bool_t bus_selinux_allows_acquire_service (DBusConnection *connection,
                                                 BusSELinuxID   *service_sid,
index 7f471b3dfad8603460263bade777e1439c6f7bbf..d9ac24344fd3c074cc83399142e4864d69390cae 100644 (file)
@@ -237,6 +237,7 @@ extern "C" {
 #define DBUS_ERROR_SPAWN_FAILED               "org.freedesktop.DBus.Error.Spawn.Failed"
 #define DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN    "org.freedesktop.DBus.Error.UnixProcessIdUnknown"
 #define DBUS_ERROR_INVALID_SIGNATURE          "org.freedesktop.DBus.Error.InvalidSignature"
+#define DBUS_ERROR_UNIX_SECURITY_CONTEXT_UNKNOWN    "org.freedesktop.DBus.Error.UnixSecurityContextUnknown"
 
 #define DBUS_INTROSPECT_1_0_XML_NAMESPACE         "http://www.freedesktop.org/standards/dbus"
 #define DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"