[gdm/wip/rancell/autologin-accountsservice] Pull automatic login configuration from AccountsService
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdm/wip/rancell/autologin-accountsservice] Pull automatic login configuration from AccountsService
- Date: Thu, 21 Dec 2017 23:19:53 +0000 (UTC)
commit c0d5a24a5fb4fae64ef0ea3a5bcd4d3346bb6544
Author: Robert Ancell <robert ancell canonical com>
Date: Fri Dec 22 12:11:53 2017 +1300
Pull automatic login configuration from AccountsService
daemon/gdm-manager.c | 100 ++++++++++++++++++++++++++------------------------
1 files changed, 52 insertions(+), 48 deletions(-)
---
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
index 9f06196..1da042f 100644
--- a/daemon/gdm-manager.c
+++ b/daemon/gdm-manager.c
@@ -1242,46 +1242,57 @@ get_timed_login_details (GdmManager *manager,
return enabled;
}
-static gboolean
-get_automatic_login_details (GdmManager *manager,
- char **usernamep)
-{
- gboolean res;
- gboolean enabled;
- char *username = NULL;
-
- enabled = FALSE;
- username = NULL;
-
- res = gdm_settings_direct_get_boolean (GDM_KEY_AUTO_LOGIN_ENABLE, &enabled);
- if (res && enabled) {
- res = gdm_settings_direct_get_string (GDM_KEY_AUTO_LOGIN_USER, &username);
+static gchar *
+get_automatic_login_user (GdmManager *manager)
+{
+ g_autoptr(GVariant) result = NULL;
+ g_autoptr(GVariantIter) iter = NULL;
+ const gchar *path;
+ g_autoptr(GError) error = NULL;
+
+ result = g_dbus_connection_call_sync (manager->priv->connection,
+ "org.freedesktop.Accounts",
+ "/org/freedesktop/Accounts",
+ "org.freedesktop.Accounts",
+ "ListCachedUsers",
+ g_variant_new ("()"),
+ G_VARIANT_TYPE ("(ao)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (result == NULL) {
+ g_warning ("Failed to get automatic login details from AccountsService: %s", error->message);
+ return NULL;
}
- if (enabled && res && username != NULL && username[0] != '\0') {
- goto out;
- }
+ g_variant_get (result, "(ao)", &iter);
+ while (g_variant_iter_next (iter, "&o", &path)) {
+ g_autoptr(GDBusProxy) proxy = NULL;
+ g_autoptr(GVariant) username = NULL;
+ g_autoptr(GVariant) automatic_login = NULL;
+ g_autoptr(GError) user_error = NULL;
+
+ proxy = g_dbus_proxy_new_sync (manager->priv->connection,
+ 0, NULL,
+ "org.freedesktop.Accounts",
+ path,
+ "org.freedesktop.Accounts.User",
+ NULL,
+ &user_error);
+ if (proxy == NULL) {
+ g_warning ("Failed to get automatic login details from AccountsService for user %s:
%s", path, user_error->message);
+ continue;
+ }
- g_free (username);
- username = NULL;
- enabled = FALSE;
+ username = g_dbus_proxy_get_cached_property (proxy, "UserName");
+ automatic_login = g_dbus_proxy_get_cached_property (proxy, "AutomaticLogin");
- out:
- if (enabled) {
- g_debug ("GdmDisplay: Got automatic login details for display: %d %s",
- enabled,
- username);
- } else {
- g_debug ("GdmDisplay: Got automatic login details for display: 0");
+ if (g_variant_get_boolean (automatic_login))
+ return g_strdup (g_variant_get_string (username, NULL));
}
- if (usernamep != NULL) {
- *usernamep = username;
- } else {
- g_free (username);
- }
-
- return enabled;
+ return NULL;
}
static void
@@ -1579,17 +1590,14 @@ set_up_session (GdmManager *manager,
ActUser *user;
gboolean loaded;
gboolean is_initial_display = FALSE;
- gboolean autologin_enabled = FALSE;
- char *username = NULL;
+ g_autofree gchar *username = NULL;
g_object_get (G_OBJECT (display), "is-initial", &is_initial_display, NULL);
if (!manager->priv->ran_once && is_initial_display)
- autologin_enabled = get_automatic_login_details (manager, &username);
-
- if (!autologin_enabled) {
- g_free (username);
+ username = get_automatic_login_user (manager);
+ if (username == NULL) {
#ifdef HAVE_LIBXDMCP
if (GDM_IS_XDMCP_CHOOSER_DISPLAY (display)) {
set_up_chooser_session (manager, display);
@@ -1614,7 +1622,7 @@ set_up_session (GdmManager *manager,
operation = g_new (UsernameLookupOperation, 1);
operation->manager = g_object_ref (manager);
operation->display = g_object_ref (display);
- operation->username = username;
+ operation->username = g_steal_pointer (&username);
g_signal_connect (user,
"notify::is-loaded",
@@ -2216,8 +2224,7 @@ on_session_conversation_started (GdmSession *session,
GdmManager *manager)
{
GdmDisplay *display;
- gboolean enabled;
- char *username;
+ g_autofree gchar *username = NULL;
g_debug ("GdmManager: session conversation started for service %s", service_name);
@@ -2236,9 +2243,8 @@ on_session_conversation_started (GdmSession *session,
return;
}
- enabled = get_automatic_login_details (manager, &username);
-
- if (! enabled) {
+ username = get_automatic_login_user (manager);
+ if (username == NULL) {
return;
}
@@ -2247,8 +2253,6 @@ on_session_conversation_started (GdmSession *session,
/* service_name will be "gdm-autologin"
*/
gdm_session_setup_for_user (session, service_name, username);
-
- g_free (username);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]