Skip to content

Commit 6015bce

Browse files
committed
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.
1 parent ee9f36a commit 6015bce

File tree

7 files changed

+153
-26
lines changed

7 files changed

+153
-26
lines changed

common/user-list.c

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ load_accounts_user (CommonUser *user)
494494
{
495495
CommonUserPrivate *priv = GET_USER_PRIVATE (user);
496496
g_autoptr(GVariant) result = NULL;
497+
g_autoptr(GVariant) extra_result = NULL;
497498
GVariant *value;
498499
GVariantIter *iter;
499500
gchar *name;
@@ -572,29 +573,50 @@ load_accounts_user (CommonUser *user)
572573
g_free (priv->session);
573574
priv->session = g_variant_dup_string (value, NULL);
574575
}
575-
else if (strcmp (name, "BackgroundFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
576-
{
577-
g_free (priv->background);
578-
priv->background = g_variant_dup_string (value, NULL);
579-
if (strcmp (priv->background, "") == 0)
580-
g_clear_pointer (&priv->background, g_free);
581-
}
582-
else if (strcmp (name, "XKeyboardLayouts") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY))
576+
else if (strcmp (name, "Uid") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_UINT64))
577+
priv->uid = g_variant_get_uint64 (value);
578+
}
579+
g_variant_iter_free (iter);
580+
581+
extra_result = g_dbus_connection_call_sync (priv->bus,
582+
"org.freedesktop.Accounts",
583+
priv->path,
584+
"org.freedesktop.DBus.Properties",
585+
"GetAll",
586+
g_variant_new ("(s)", "org.freedesktop.DisplayManager.AccountsService"),
587+
G_VARIANT_TYPE ("(a{sv})"),
588+
G_DBUS_CALL_FLAGS_NONE,
589+
-1,
590+
NULL,
591+
&error);
592+
if (error)
593+
g_warning ("Error updating user %s: %s", priv->path, error->message);
594+
if (extra_result) {
595+
g_variant_get (extra_result, "(a{sv})", &iter);
596+
while (g_variant_iter_loop (iter, "{&sv}", &name, &value))
583597
{
584-
g_strfreev (priv->layouts);
585-
priv->layouts = g_variant_dup_strv (value, NULL);
586-
if (!priv->layouts)
598+
if (strcmp (name, "BackgroundFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
599+
{
600+
g_free (priv->background);
601+
priv->background = g_variant_dup_string (value, NULL);
602+
if (strcmp (priv->background, "") == 0)
603+
g_clear_pointer (&priv->background, g_free);
604+
}
605+
else if (strcmp (name, "HasMessages") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
606+
priv->has_messages = g_variant_get_boolean (value);
607+
else if (strcmp (name, "XKeyboardLayouts") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY))
587608
{
588-
priv->layouts = g_malloc (sizeof (gchar *) * 1);
589-
priv->layouts[0] = NULL;
609+
g_strfreev (priv->layouts);
610+
priv->layouts = g_variant_dup_strv (value, NULL);
611+
if (!priv->layouts)
612+
{
613+
priv->layouts = g_malloc (sizeof (gchar *) * 1);
614+
priv->layouts[0] = NULL;
615+
}
590616
}
591617
}
592-
else if (strcmp (name, "XHasMessages") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
593-
priv->has_messages = g_variant_get_boolean (value);
594-
else if (strcmp (name, "Uid") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_UINT64))
595-
priv->uid = g_variant_get_uint64 (value);
618+
g_variant_iter_free (iter);
596619
}
597-
g_variant_iter_free (iter);
598620

599621
return !system_account;
600622
}

data/Makefile.am

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,17 @@ dist_apparmor_profile_abstractions_DATA = \
2727
apparmor/abstractions/lightdm \
2828
apparmor/abstractions/lightdm_chromium-browser
2929

30+
accountsservicedir = $(datadir)/accountsservice/interfaces
31+
dist_accountsservice_DATA = \
32+
org.freedesktop.DisplayManager.AccountsService.xml
33+
34+
polkitdir = $(datadir)/polkit-1/actions
35+
polkit_in_files = org.freedesktop.DisplayManager.AccountsService.policy
36+
polkit_DATA = $(polkit_in_files:.policy.in=.policy)
37+
@INTLTOOL_POLICY_RULE@
38+
3039
dist_man1_MANS = dm-tool.1 \
3140
lightdm.1
3241

33-
EXTRA_DIST = apparmor/lightdm-guest-session.in
34-
CLEANFILES = lightdm-guest-session
42+
EXTRA_DIST = apparmor/lightdm-guest-session.in $(polkit_in_files)
43+
CLEANFILES = lightdm-guest-session $(polkit_DATA)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<policyconfig>
4+
<action id="org.freedesktop.DisplayManager.AccountsService.ModifyOwn">
5+
<_description>Set properties of own user</_description>
6+
<_message>Authentication is required to set one's own greeter properties.</_message>
7+
<defaults>
8+
<allow_any>yes</allow_any>
9+
<allow_inactive>yes</allow_inactive>
10+
<allow_active>yes</allow_active>
11+
</defaults>
12+
</action>
13+
14+
<action id="org.freedesktop.DisplayManager.AccountsService.ReadAny">
15+
<_description>Set properties of any user</_description>
16+
<_message>Authentication is required to get another user's greeter properties.</_message>
17+
<defaults>
18+
<allow_any>yes</allow_any>
19+
<allow_inactive>yes</allow_inactive>
20+
<allow_active>yes</allow_active>
21+
</defaults>
22+
</action>
23+
24+
<action id="org.freedesktop.DisplayManager.AccountsService.ModifyAny">
25+
<_description>Set properties of any user</_description>
26+
<_message>Authentication is required to set another user's greeter properties.</_message>
27+
<defaults>
28+
<allow_any>no</allow_any>
29+
<allow_inactive>no</allow_inactive>
30+
<allow_active>no</allow_active>
31+
</defaults>
32+
</action>
33+
</policyconfig>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<node>
2+
<interface name="org.freedesktop.DisplayManager.AccountsService">
3+
4+
<annotation name="org.freedesktop.Accounts.VendorExtension" value="true"/>
5+
6+
<annotation name="org.freedesktop.Accounts.Authentication.ChangeOwn"
7+
value="org.freedesktop.DisplayManager.AccountsService.ModifyOwn"/>
8+
9+
<annotation name="org.freedesktop.Accounts.Authentication.ReadAny"
10+
value="org.freedesktop.DisplayManager.AccountsService.ReadAny"/>
11+
12+
<annotation name="org.freedesktop.Accounts.Authentication.ChangeAny"
13+
value="org.freedesktop.DisplayManager.AccountsService.ModifyAny"/>
14+
15+
<property name="BackgroundFile" type="s" access="readwrite">
16+
<annotation name="org.freedesktop.Accounts.DefaultValue" value=""/>
17+
</property>
18+
<property name="HasMessages" type="b" access="readwrite">
19+
<annotation name="org.freedesktop.Accounts.DefaultValue" value="false"/>
20+
</property>
21+
<property name="BackgroundFile" type="s" access="readwrite">
22+
<annotation name="org.freedesktop.Accounts.DefaultValue" value=""/>
23+
</property>
24+
25+
</interface>
26+
</node>

debian/lightdm.install

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
usr/sbin/lightdm
2+
usr/share/accountsservice
3+
usr/share/bash-completion
24
usr/share/man
35
usr/share/locale
4-
usr/share/bash-completion
6+
usr/share/polkit-1
57
usr/lib/lightdm
68
usr/bin
79
etc/dbus-1/

po/POTFILES.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# List of source files containing translatable strings.
22
# Please keep this file sorted alphabetically.
33
[encoding: UTF-8]
4+
data/org.freedesktop.DisplayManager.AccountsService.policy.in
45
src/lightdm.c
56
src/dm-tool.c

tests/src/test-runner.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typedef struct
5252
gchar *background;
5353
gchar *path;
5454
guint id;
55+
guint extra_id;
5556
gchar *language;
5657
gchar *xsession;
5758
gchar **layouts;
@@ -2122,8 +2123,6 @@ handle_user_get_property (GDBusConnection *connection,
21222123
return g_variant_new_string (user->home_directory);
21232124
else if (strcmp (property_name, "SystemAccount") == 0)
21242125
return g_variant_new_boolean (user->uid < 1000);
2125-
else if (strcmp (property_name, "BackgroundFile") == 0)
2126-
return g_variant_new_string (user->background ? user->background : "");
21272126
else if (strcmp (property_name, "Language") == 0)
21282127
return g_variant_new_string (user->language ? user->language : "");
21292128
else if (strcmp (property_name, "IconFile") == 0)
@@ -2134,15 +2133,32 @@ handle_user_get_property (GDBusConnection *connection,
21342133
return g_variant_new_uint64 (user->uid);
21352134
else if (strcmp (property_name, "XSession") == 0)
21362135
return g_variant_new_string (user->xsession ? user->xsession : "");
2136+
2137+
return NULL;
2138+
}
2139+
2140+
static GVariant *
2141+
handle_user_get_extra_property (GDBusConnection *connection,
2142+
const gchar *sender,
2143+
const gchar *object_path,
2144+
const gchar *interface_name,
2145+
const gchar *property_name,
2146+
GError **error,
2147+
gpointer user_data)
2148+
{
2149+
AccountsUser *user = user_data;
2150+
2151+
if (strcmp (property_name, "BackgroundFile") == 0)
2152+
return g_variant_new_string (user->background ? user->background : "");
2153+
else if (strcmp (property_name, "HasMessages") == 0)
2154+
return g_variant_new_boolean (user->has_messages);
21372155
else if (strcmp (property_name, "XKeyboardLayouts") == 0)
21382156
{
21392157
if (user->layouts != NULL)
21402158
return g_variant_new_strv ((const gchar * const *) user->layouts, -1);
21412159
else
21422160
return g_variant_new_strv (NULL, 0);
21432161
}
2144-
else if (strcmp (property_name, "XHasMessages") == 0)
2145-
return g_variant_new_boolean (user->has_messages);
21462162

21472163
return NULL;
21482164
}
@@ -2157,6 +2173,7 @@ accounts_user_set_hidden (AccountsUser *user, gboolean hidden, gboolean emit_sig
21572173
g_autoptr(GError) error = NULL;
21582174

21592175
g_dbus_connection_unregister_object (accounts_connection, user->id);
2176+
g_dbus_connection_unregister_object (accounts_connection, user->extra_id);
21602177
if (!g_dbus_connection_emit_signal (accounts_connection,
21612178
NULL,
21622179
"/org/freedesktop/Accounts",
@@ -2185,12 +2202,12 @@ accounts_user_set_hidden (AccountsUser *user, gboolean hidden, gboolean emit_sig
21852202
" <property name='Shell' type='s' access='read'/>"
21862203
" <property name='Uid' type='t' access='read'/>"
21872204
" <property name='XSession' type='s' access='read'/>"
2188-
" <property name='XKeyboardLayouts' type='as' access='read'/>"
21892205
" <signal name='Changed' />"
21902206
" </interface>"
21912207
" <interface name='org.freedesktop.DisplayManager.AccountsService'>"
21922208
" <property name='BackgroundFile' type='s' access='read'/>"
21932209
" <property name='HasMessages' type='b' access='read'/>"
2210+
" <property name='XKeyboardLayouts' type='as' access='read'/>"
21942211
" </interface>"
21952212
"</node>";
21962213
g_autoptr(GDBusNodeInfo) user_info = NULL;
@@ -2200,6 +2217,11 @@ accounts_user_set_hidden (AccountsUser *user, gboolean hidden, gboolean emit_sig
22002217
handle_user_call,
22012218
handle_user_get_property,
22022219
};
2220+
static const GDBusInterfaceVTable user_extra_vtable =
2221+
{
2222+
NULL,
2223+
handle_user_get_extra_property,
2224+
};
22032225

22042226
user_info = g_dbus_node_info_new_for_xml (user_interface, &error);
22052227
if (!user_info)
@@ -2219,6 +2241,18 @@ accounts_user_set_hidden (AccountsUser *user, gboolean hidden, gboolean emit_sig
22192241
g_warning ("Failed to register user: %s", error->message);
22202242
return;
22212243
}
2244+
user->extra_id = g_dbus_connection_register_object (accounts_connection,
2245+
user->path,
2246+
user_info->interfaces[1],
2247+
&user_extra_vtable,
2248+
user,
2249+
NULL,
2250+
&error);
2251+
if (user->extra_id == 0)
2252+
{
2253+
g_warning ("Failed to register user: %s", error->message);
2254+
return;
2255+
}
22222256

22232257
if (!g_dbus_connection_emit_signal (accounts_connection,
22242258
NULL,

0 commit comments

Comments
 (0)