From 6015bce25f241e7580c03594d846769f8236232f Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 20 Dec 2017 17:08:27 +1300 Subject: Use AccountsService extension system for extended greeter information (background, messages etc) The support for this never landed upstream in AccountsService and the extension system was added later. This allows OSs to make use of these features without a patched AccountsService. --- common/user-list.c | 58 +++++++++++++++------- data/Makefile.am | 13 ++++- ...esktop.DisplayManager.AccountsService.policy.in | 33 ++++++++++++ ....freedesktop.DisplayManager.AccountsService.xml | 26 ++++++++++ debian/lightdm.install | 4 +- po/POTFILES.in | 1 + tests/src/test-runner.c | 44 ++++++++++++++-- 7 files changed, 153 insertions(+), 26 deletions(-) create mode 100644 data/org.freedesktop.DisplayManager.AccountsService.policy.in create mode 100644 data/org.freedesktop.DisplayManager.AccountsService.xml diff --git a/common/user-list.c b/common/user-list.c index ee4063dd..b8e32826 100644 --- a/common/user-list.c +++ b/common/user-list.c @@ -494,6 +494,7 @@ load_accounts_user (CommonUser *user) { CommonUserPrivate *priv = GET_USER_PRIVATE (user); g_autoptr(GVariant) result = NULL; + g_autoptr(GVariant) extra_result = NULL; GVariant *value; GVariantIter *iter; gchar *name; @@ -572,29 +573,50 @@ load_accounts_user (CommonUser *user) g_free (priv->session); priv->session = g_variant_dup_string (value, NULL); } - else if (strcmp (name, "BackgroundFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) - { - g_free (priv->background); - priv->background = g_variant_dup_string (value, NULL); - if (strcmp (priv->background, "") == 0) - g_clear_pointer (&priv->background, g_free); - } - else if (strcmp (name, "XKeyboardLayouts") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY)) + else if (strcmp (name, "Uid") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_UINT64)) + priv->uid = g_variant_get_uint64 (value); + } + g_variant_iter_free (iter); + + extra_result = g_dbus_connection_call_sync (priv->bus, + "org.freedesktop.Accounts", + priv->path, + "org.freedesktop.DBus.Properties", + "GetAll", + g_variant_new ("(s)", "org.freedesktop.DisplayManager.AccountsService"), + G_VARIANT_TYPE ("(a{sv})"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (error) + g_warning ("Error updating user %s: %s", priv->path, error->message); + if (extra_result) { + g_variant_get (extra_result, "(a{sv})", &iter); + while (g_variant_iter_loop (iter, "{&sv}", &name, &value)) { - g_strfreev (priv->layouts); - priv->layouts = g_variant_dup_strv (value, NULL); - if (!priv->layouts) + if (strcmp (name, "BackgroundFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) + { + g_free (priv->background); + priv->background = g_variant_dup_string (value, NULL); + if (strcmp (priv->background, "") == 0) + g_clear_pointer (&priv->background, g_free); + } + else if (strcmp (name, "HasMessages") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)) + priv->has_messages = g_variant_get_boolean (value); + else if (strcmp (name, "XKeyboardLayouts") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY)) { - priv->layouts = g_malloc (sizeof (gchar *) * 1); - priv->layouts[0] = NULL; + g_strfreev (priv->layouts); + priv->layouts = g_variant_dup_strv (value, NULL); + if (!priv->layouts) + { + priv->layouts = g_malloc (sizeof (gchar *) * 1); + priv->layouts[0] = NULL; + } } } - else if (strcmp (name, "XHasMessages") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)) - priv->has_messages = g_variant_get_boolean (value); - else if (strcmp (name, "Uid") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_UINT64)) - priv->uid = g_variant_get_uint64 (value); + g_variant_iter_free (iter); } - g_variant_iter_free (iter); return !system_account; } diff --git a/data/Makefile.am b/data/Makefile.am index b3dd2f80..32ab5a57 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -27,8 +27,17 @@ dist_apparmor_profile_abstractions_DATA = \ apparmor/abstractions/lightdm \ apparmor/abstractions/lightdm_chromium-browser +accountsservicedir = $(datadir)/accountsservice/interfaces +dist_accountsservice_DATA = \ + org.freedesktop.DisplayManager.AccountsService.xml + +polkitdir = $(datadir)/polkit-1/actions +polkit_in_files = org.freedesktop.DisplayManager.AccountsService.policy +polkit_DATA = $(polkit_in_files:.policy.in=.policy) +@INTLTOOL_POLICY_RULE@ + dist_man1_MANS = dm-tool.1 \ lightdm.1 -EXTRA_DIST = apparmor/lightdm-guest-session.in -CLEANFILES = lightdm-guest-session +EXTRA_DIST = apparmor/lightdm-guest-session.in $(polkit_in_files) +CLEANFILES = lightdm-guest-session $(polkit_DATA) diff --git a/data/org.freedesktop.DisplayManager.AccountsService.policy.in b/data/org.freedesktop.DisplayManager.AccountsService.policy.in new file mode 100644 index 00000000..d9899c20 --- /dev/null +++ b/data/org.freedesktop.DisplayManager.AccountsService.policy.in @@ -0,0 +1,33 @@ + + + + + <_description>Set properties of own user + <_message>Authentication is required to set one's own greeter properties. + + yes + yes + yes + + + + + <_description>Set properties of any user + <_message>Authentication is required to get another user's greeter properties. + + yes + yes + yes + + + + + <_description>Set properties of any user + <_message>Authentication is required to set another user's greeter properties. + + no + no + no + + + diff --git a/data/org.freedesktop.DisplayManager.AccountsService.xml b/data/org.freedesktop.DisplayManager.AccountsService.xml new file mode 100644 index 00000000..07b0dab9 --- /dev/null +++ b/data/org.freedesktop.DisplayManager.AccountsService.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/debian/lightdm.install b/debian/lightdm.install index 14700b6d..cfc1f2de 100644 --- a/debian/lightdm.install +++ b/debian/lightdm.install @@ -1,7 +1,9 @@ usr/sbin/lightdm +usr/share/accountsservice +usr/share/bash-completion usr/share/man usr/share/locale -usr/share/bash-completion +usr/share/polkit-1 usr/lib/lightdm usr/bin etc/dbus-1/ diff --git a/po/POTFILES.in b/po/POTFILES.in index 2668b565..68fb513d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,5 +1,6 @@ # List of source files containing translatable strings. # Please keep this file sorted alphabetically. [encoding: UTF-8] +data/org.freedesktop.DisplayManager.AccountsService.policy.in src/lightdm.c src/dm-tool.c diff --git a/tests/src/test-runner.c b/tests/src/test-runner.c index 7a0dd75e..836e24fa 100644 --- a/tests/src/test-runner.c +++ b/tests/src/test-runner.c @@ -52,6 +52,7 @@ typedef struct gchar *background; gchar *path; guint id; + guint extra_id; gchar *language; gchar *xsession; gchar **layouts; @@ -2122,8 +2123,6 @@ handle_user_get_property (GDBusConnection *connection, return g_variant_new_string (user->home_directory); else if (strcmp (property_name, "SystemAccount") == 0) return g_variant_new_boolean (user->uid < 1000); - else if (strcmp (property_name, "BackgroundFile") == 0) - return g_variant_new_string (user->background ? user->background : ""); else if (strcmp (property_name, "Language") == 0) return g_variant_new_string (user->language ? user->language : ""); else if (strcmp (property_name, "IconFile") == 0) @@ -2134,6 +2133,25 @@ handle_user_get_property (GDBusConnection *connection, return g_variant_new_uint64 (user->uid); else if (strcmp (property_name, "XSession") == 0) return g_variant_new_string (user->xsession ? user->xsession : ""); + + return NULL; +} + +static GVariant * +handle_user_get_extra_property (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error, + gpointer user_data) +{ + AccountsUser *user = user_data; + + if (strcmp (property_name, "BackgroundFile") == 0) + return g_variant_new_string (user->background ? user->background : ""); + else if (strcmp (property_name, "HasMessages") == 0) + return g_variant_new_boolean (user->has_messages); else if (strcmp (property_name, "XKeyboardLayouts") == 0) { if (user->layouts != NULL) @@ -2141,8 +2159,6 @@ handle_user_get_property (GDBusConnection *connection, else return g_variant_new_strv (NULL, 0); } - else if (strcmp (property_name, "XHasMessages") == 0) - return g_variant_new_boolean (user->has_messages); return NULL; } @@ -2157,6 +2173,7 @@ accounts_user_set_hidden (AccountsUser *user, gboolean hidden, gboolean emit_sig g_autoptr(GError) error = NULL; g_dbus_connection_unregister_object (accounts_connection, user->id); + g_dbus_connection_unregister_object (accounts_connection, user->extra_id); if (!g_dbus_connection_emit_signal (accounts_connection, NULL, "/org/freedesktop/Accounts", @@ -2185,12 +2202,12 @@ accounts_user_set_hidden (AccountsUser *user, gboolean hidden, gboolean emit_sig " " " " " " - " " " " " " " " " " " " + " " " " ""; g_autoptr(GDBusNodeInfo) user_info = NULL; @@ -2200,6 +2217,11 @@ accounts_user_set_hidden (AccountsUser *user, gboolean hidden, gboolean emit_sig handle_user_call, handle_user_get_property, }; + static const GDBusInterfaceVTable user_extra_vtable = + { + NULL, + handle_user_get_extra_property, + }; user_info = g_dbus_node_info_new_for_xml (user_interface, &error); if (!user_info) @@ -2219,6 +2241,18 @@ accounts_user_set_hidden (AccountsUser *user, gboolean hidden, gboolean emit_sig g_warning ("Failed to register user: %s", error->message); return; } + user->extra_id = g_dbus_connection_register_object (accounts_connection, + user->path, + user_info->interfaces[1], + &user_extra_vtable, + user, + NULL, + &error); + if (user->extra_id == 0) + { + g_warning ("Failed to register user: %s", error->message); + return; + } if (!g_dbus_connection_emit_signal (accounts_connection, NULL, -- cgit v1.2.1