diff options
author | Robert Ancell <robert.ancell@canonical.com> | 2017-12-20 17:08:27 +1300 |
---|---|---|
committer | Robert Ancell <robert.ancell@canonical.com> | 2017-12-20 17:08:27 +1300 |
commit | 6015bce25f241e7580c03594d846769f8236232f (patch) | |
tree | 6a0ae48b6c43c6a2e2e5e3eaef4246fc45aae562 | |
parent | ee9f36a21ed661f52758a6d3badfdcac3716119c (diff) | |
download | lightdm-git-6015bce25f241e7580c03594d846769f8236232f.tar.gz |
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.
-rw-r--r-- | common/user-list.c | 58 | ||||
-rw-r--r-- | data/Makefile.am | 13 | ||||
-rw-r--r-- | data/org.freedesktop.DisplayManager.AccountsService.policy.in | 33 | ||||
-rw-r--r-- | data/org.freedesktop.DisplayManager.AccountsService.xml | 26 | ||||
-rw-r--r-- | debian/lightdm.install | 4 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | tests/src/test-runner.c | 44 |
7 files changed, 153 insertions, 26 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<policyconfig> + <action id="org.freedesktop.DisplayManager.AccountsService.ModifyOwn"> + <_description>Set properties of own user</_description> + <_message>Authentication is required to set one's own greeter properties.</_message> + <defaults> + <allow_any>yes</allow_any> + <allow_inactive>yes</allow_inactive> + <allow_active>yes</allow_active> + </defaults> + </action> + + <action id="org.freedesktop.DisplayManager.AccountsService.ReadAny"> + <_description>Set properties of any user</_description> + <_message>Authentication is required to get another user's greeter properties.</_message> + <defaults> + <allow_any>yes</allow_any> + <allow_inactive>yes</allow_inactive> + <allow_active>yes</allow_active> + </defaults> + </action> + + <action id="org.freedesktop.DisplayManager.AccountsService.ModifyAny"> + <_description>Set properties of any user</_description> + <_message>Authentication is required to set another user's greeter properties.</_message> + <defaults> + <allow_any>no</allow_any> + <allow_inactive>no</allow_inactive> + <allow_active>no</allow_active> + </defaults> + </action> +</policyconfig> 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 @@ +<node> + <interface name="org.freedesktop.DisplayManager.AccountsService"> + + <annotation name="org.freedesktop.Accounts.VendorExtension" value="true"/> + + <annotation name="org.freedesktop.Accounts.Authentication.ChangeOwn" + value="org.freedesktop.DisplayManager.AccountsService.ModifyOwn"/> + + <annotation name="org.freedesktop.Accounts.Authentication.ReadAny" + value="org.freedesktop.DisplayManager.AccountsService.ReadAny"/> + + <annotation name="org.freedesktop.Accounts.Authentication.ChangeAny" + value="org.freedesktop.DisplayManager.AccountsService.ModifyAny"/> + + <property name="BackgroundFile" type="s" access="readwrite"> + <annotation name="org.freedesktop.Accounts.DefaultValue" value=""/> + </property> + <property name="HasMessages" type="b" access="readwrite"> + <annotation name="org.freedesktop.Accounts.DefaultValue" value="false"/> + </property> + <property name="BackgroundFile" type="s" access="readwrite"> + <annotation name="org.freedesktop.Accounts.DefaultValue" value=""/> + </property> + + </interface> +</node> 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 " <property name='Shell' type='s' access='read'/>" " <property name='Uid' type='t' access='read'/>" " <property name='XSession' type='s' access='read'/>" - " <property name='XKeyboardLayouts' type='as' access='read'/>" " <signal name='Changed' />" " </interface>" " <interface name='org.freedesktop.DisplayManager.AccountsService'>" " <property name='BackgroundFile' type='s' access='read'/>" " <property name='HasMessages' type='b' access='read'/>" + " <property name='XKeyboardLayouts' type='as' access='read'/>" " </interface>" "</node>"; 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, |