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 <withnall@endlessm.com>

https://phabricator.endlessm.com/T24302
This commit is contained in:
Philip Withnall 2018-11-02 09:17:56 +00:00
parent 60c58fcba3
commit fa11d103d2
1 changed files with 52 additions and 2 deletions

View File

@ -302,6 +302,47 @@ bus_error_to_app_filter_error (const GError *bus_error,
return g_error_copy (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: * epc_get_app_filter:
* @connection: (nullable): a #GDBusConnection to the system bus, or %NULL to * @connection: (nullable): a #GDBusConnection to the system bus, or %NULL to
@ -344,7 +385,12 @@ epc_get_app_filter (GDBusConnection *connection,
if (connection == NULL) if (connection == NULL)
return 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 = result_variant =
g_dbus_connection_call_sync (connection, g_dbus_connection_call_sync (connection,
"org.freedesktop.Accounts", "org.freedesktop.Accounts",
@ -567,7 +613,11 @@ epc_set_app_filter (GDBusConnection *connection,
if (connection == NULL) if (connection == NULL)
return FALSE; 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); app_filter_variant = _epc_app_filter_build_app_filter_variant (app_filter);
oars_filter_variant = g_variant_new ("(s@a{ss})", "oars-1.1", oars_filter_variant = g_variant_new ("(s@a{ss})", "oars-1.1",