From d2ac1d35ec0079fee17df425a429e4361704d5a0 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sun, 7 Oct 2012 10:55:50 -0500 Subject: [PATCH 1/2] Add DBusGMethodInvocation accessor for the DBusGConnection If you're using two connections, say a shared connection and a private connection that uses DBusServer, there's no way to figure out which DBusConnection a method invocation originates from, and thus no way to do access control based on that. Private bus setup done with eg: void new_conn_func(DBusServer *s, DBusConnection *conn, gpointer to_export) { DBusGConnection *gconn; /* set access control, eg with dbus_connection_set_unix_user_function() */ dbus_connection_setup_with_g_main(conn, NULL); gconn = dbus_connection_get_g_connection(conn); dbus_g_connection_register_object(gconn, "/foo", G_OBJECT (to_export)); } void start_server(GObject *to_export) { DBusServer *s; s = dbus_server_listen("unix:path=/var/foo", NULL); dbus_server_setup_with_g_main (s, NULL); dbus_server_set_new_connection_function (s, new_conn_func, to_export); } --- dbus/dbus-glib.h | 2 ++ dbus/dbus-gobject.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/dbus/dbus-glib.h b/dbus/dbus-glib.h index 9a2076f..addccdd 100644 --- a/dbus/dbus-glib.h +++ b/dbus/dbus-glib.h @@ -326,6 +326,8 @@ void dbus_g_method_return (DBusGMethodInvocation *con void dbus_g_method_return_error (DBusGMethodInvocation *context, const GError *error); +DBusGConnection * dbus_g_method_invocation_get_g_connection (DBusGMethodInvocation *context); + /* Probably possible to replace this with a closure */ typedef struct { GCallback cb; diff --git a/dbus/dbus-gobject.c b/dbus/dbus-gobject.c index bac91be..9889836 100644 --- a/dbus/dbus-gobject.c +++ b/dbus/dbus-gobject.c @@ -3276,6 +3276,22 @@ out: g_free (context); } +/** + * dbus_g_method_invocation_get_g_connection: + * @context: the method context + * + * + * + * Returns: (transfer none): the @DBusGConnection from which the method was called. + */ +DBusGConnection * +dbus_g_method_invocation_get_g_connection (DBusGMethodInvocation *context) +{ + g_return_val_if_fail (context != NULL, NULL); + + return context->connection; +} + const char * _dbus_gobject_get_path (GObject *obj) { -- 1.7.11.4