From fa11d103d27a21a6d95799eadfae14dd56d3ad58 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 2 Nov 2018 09:17:56 +0000 Subject: [PATCH] libeos-parental-controls: Use FindUserById for accountsservice objects Instead of manually constructing the D-Bus object path representing a user, call FindUserById to have accountsservice do it for us. For normal users, this makes no difference. For system users (UID < 1000) or other users which accountsservice considers uninteresting (see user_classify_is_human() in user-classify.c in accountsservice), no D-Bus objects are created for them automatically. Calling FindUserById ensures that the object is created before its path is returned to us. Signed-off-by: Philip Withnall https://phabricator.endlessm.com/T24302 --- libeos-parental-controls/app-filter.c | 54 ++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/libeos-parental-controls/app-filter.c b/libeos-parental-controls/app-filter.c index 4843f83..ce3c927 100644 --- a/libeos-parental-controls/app-filter.c +++ b/libeos-parental-controls/app-filter.c @@ -302,6 +302,47 @@ bus_error_to_app_filter_error (const GError *bus_error, return g_error_copy (bus_error); } +/* Find the object path for the given @user_id on the accountsservice D-Bus + * interface, by calling its FindUserById() method. This is a synchronous, + * blocking function. */ +static gchar * +accounts_find_user_by_id (GDBusConnection *connection, + uid_t user_id, + gboolean allow_interactive_authorization, + GCancellable *cancellable, + GError **error) +{ + g_autofree gchar *object_path = NULL; + g_autoptr(GVariant) result_variant = NULL; + g_autoptr(GError) local_error = NULL; + + result_variant = + g_dbus_connection_call_sync (connection, + "org.freedesktop.Accounts", + "/org/freedesktop/Accounts", + "org.freedesktop.Accounts", + "FindUserById", + g_variant_new ("(x)", user_id), + G_VARIANT_TYPE ("(o)"), + allow_interactive_authorization + ? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION + : G_DBUS_CALL_FLAGS_NONE, + -1, /* timeout, ms */ + cancellable, + &local_error); + if (local_error != NULL) + { + g_autoptr(GError) app_filter_error = bus_error_to_app_filter_error (local_error, + user_id); + g_propagate_error (error, g_steal_pointer (&app_filter_error)); + return NULL; + } + + g_variant_get (result_variant, "(o)", &object_path); + + return g_steal_pointer (&object_path); +} + /** * epc_get_app_filter: * @connection: (nullable): a #GDBusConnection to the system bus, or %NULL to @@ -344,7 +385,12 @@ epc_get_app_filter (GDBusConnection *connection, if (connection == NULL) return NULL; - object_path = g_strdup_printf ("/org/freedesktop/Accounts/User%u", user_id); + object_path = accounts_find_user_by_id (connection, user_id, + allow_interactive_authorization, + cancellable, error); + if (object_path == NULL) + return NULL; + result_variant = g_dbus_connection_call_sync (connection, "org.freedesktop.Accounts", @@ -567,7 +613,11 @@ epc_set_app_filter (GDBusConnection *connection, if (connection == NULL) return FALSE; - object_path = g_strdup_printf ("/org/freedesktop/Accounts/User%u", user_id); + object_path = accounts_find_user_by_id (connection, user_id, + allow_interactive_authorization, + cancellable, error); + if (object_path == NULL) + return FALSE; app_filter_variant = _epc_app_filter_build_app_filter_variant (app_filter); oars_filter_variant = g_variant_new ("(s@a{ss})", "oars-1.1",