gdbus: Add g_dbus_pending_property_get_sender
authorArkadiusz Bokowy <arkadiusz.bokowy@gmail.com>
Tue, 29 Oct 2024 20:41:30 +0000 (21:41 +0100)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 20 Feb 2025 07:43:24 +0000 (16:43 +0900)
This function allows to retrieve D-Bus message sender name in a property
setter callback. Message sender name might be required to limit write
access to authorized clients only.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
gdbus/gdbus.h
gdbus/object.c

index 334a28c77f4e4465de9c6ae2efadbc3f01ae2e08..1281103dca29e7c5b7cc788f8e078151c81b7fed 100755 (executable)
@@ -314,6 +314,7 @@ guint g_dbus_add_properties_watch(DBusConnection *connection,
 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
 void g_dbus_remove_all_watches(DBusConnection *connection);
 
+const char *g_dbus_pending_property_get_sender(GDBusPendingPropertySet id);
 void g_dbus_pending_property_success(GDBusPendingPropertySet id);
 void g_dbus_pending_property_error_valist(GDBusPendingReply id,
                        const char *name, const char *format, va_list args);
index efc1c15329f57d631a756fe896f16d7ae087949c..a303a7a9dcef5b9eb7f61b667834a969c02f187f 100755 (executable)
@@ -453,28 +453,45 @@ static gboolean check_privilege(DBusConnection *conn, DBusMessage *msg,
 static GDBusPendingPropertySet next_pending_property = 1;
 static GSList *pending_property_set;
 
+static int pending_property_data_compare_id(const void *data,
+                                               const void *user_data)
+{
+       const struct property_data *propdata = data;
+       const GDBusPendingPropertySet *id = user_data;
+       return propdata->id - *id;
+}
+
 static struct property_data *remove_pending_property_data(
                                                GDBusPendingPropertySet id)
 {
        struct property_data *propdata;
        GSList *l;
 
-       for (l = pending_property_set; l != NULL; l = l->next) {
-               propdata = l->data;
-               if (propdata->id != id)
-                       continue;
-
-               break;
-       }
-
+       l = g_slist_find_custom(pending_property_set, &id,
+                               pending_property_data_compare_id);
        if (l == NULL)
                return NULL;
 
+       propdata = l->data;
        pending_property_set = g_slist_delete_link(pending_property_set, l);
 
        return propdata;
 }
 
+const char *g_dbus_pending_property_get_sender(GDBusPendingPropertySet id)
+{
+       struct property_data *propdata;
+       GSList *l;
+
+       l = g_slist_find_custom(pending_property_set, &id,
+                                       pending_property_data_compare_id);
+       if (l == NULL)
+               return NULL;
+
+       propdata = l->data;
+       return dbus_message_get_sender(propdata->message);
+}
+
 void g_dbus_pending_property_success(GDBusPendingPropertySet id)
 {
        struct property_data *propdata;