dbus/bus selinux.h,1.8,1.9 selinux.c,1.14,1.15 driver.c,1.70,1.71
Colin Walters
walters at freedesktop.org
Fri Jul 15 07:45:44 EST 2005
Update of /cvs/dbus/dbus/bus
In directory gabe:/tmp/cvs-serv30558/bus
Modified Files:
selinux.h selinux.c driver.c
Log Message:
2005-07-14 Colin Walters <walters at 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.
Index: selinux.h
===================================================================
RCS file: /cvs/dbus/dbus/bus/selinux.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- selinux.h 13 Apr 2005 14:27:11 -0000 1.8
+++ selinux.h 14 Jul 2005 21:45:42 -0000 1.9
@@ -45,6 +45,8 @@
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: selinux.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/selinux.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- selinux.c 13 Apr 2005 14:27:11 -0000 1.14
+++ selinux.c 14 Jul 2005 21:45:42 -0000 1.15
@@ -567,6 +567,19 @@
#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: driver.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/driver.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- driver.c 17 Mar 2005 17:11:59 -0000 1.70
+++ driver.c 14 Jul 2005 21:45:42 -0000 1.71
@@ -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 @@
}
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 @@
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",
"",
"",
More information about the dbus-commit
mailing list