Blame SOURCES/0039-manager-do-initial-setup-post-work-in-manager-code.patch

400dab
From c08afca0807d8820030c19a40e7590f72878c788 Mon Sep 17 00:00:00 2001
400dab
From: Ray Strode <rstrode@redhat.com>
400dab
Date: Thu, 6 Sep 2018 19:31:50 -0400
400dab
Subject: [PATCH 39/51] manager: do initial-setup post work in manager code
400dab
400dab
Right now we do the initial-setup related post work
400dab
when stopping the greeter, but the problem is we delay
400dab
stopping the greeter now until after the user session
400dab
is started.
400dab
400dab
That post-work needs to be done before the user session
400dab
is started.
400dab
400dab
This commit moves the code to a more logical place.
400dab
---
400dab
 daemon/gdm-display.c | 132 -------------------------------------------
400dab
 daemon/gdm-manager.c | 132 +++++++++++++++++++++++++++++++++++++++++++
400dab
 2 files changed, 132 insertions(+), 132 deletions(-)
400dab
400dab
diff --git a/daemon/gdm-display.c b/daemon/gdm-display.c
400dab
index 875534272..1cef8c7c1 100644
400dab
--- a/daemon/gdm-display.c
400dab
+++ b/daemon/gdm-display.c
400dab
@@ -22,61 +22,60 @@
400dab
 
400dab
 #include <stdlib.h>
400dab
 #include <stdio.h>
400dab
 #include <stdint.h>
400dab
 #include <fcntl.h>
400dab
 #include <unistd.h>
400dab
 #include <string.h>
400dab
 #include <signal.h>
400dab
 #include <sys/stat.h>
400dab
 #include <sys/types.h>
400dab
 
400dab
 #include <glib.h>
400dab
 #include <glib/gi18n.h>
400dab
 #include <glib-object.h>
400dab
 
400dab
 #include <xcb/xcb.h>
400dab
 #include <X11/Xlib.h>
400dab
 
400dab
 #include "gdm-common.h"
400dab
 #include "gdm-display.h"
400dab
 #include "gdm-display-glue.h"
400dab
 #include "gdm-display-access-file.h"
400dab
 #include "gdm-launch-environment.h"
400dab
 
400dab
 #include "gdm-settings-direct.h"
400dab
 #include "gdm-settings-keys.h"
400dab
 
400dab
 #include "gdm-launch-environment.h"
400dab
 #include "gdm-dbus-util.h"
400dab
 
400dab
-#define INITIAL_SETUP_USERNAME "gnome-initial-setup"
400dab
 #define GNOME_SESSION_SESSIONS_PATH DATADIR "/gnome-session/sessions"
400dab
 
400dab
 #define GDM_DISPLAY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_DISPLAY, GdmDisplayPrivate))
400dab
 
400dab
 struct GdmDisplayPrivate
400dab
 {
400dab
         char                 *id;
400dab
         char                 *seat_id;
400dab
         char                 *session_id;
400dab
         char                 *session_class;
400dab
         char                 *session_type;
400dab
 
400dab
         char                 *remote_hostname;
400dab
         int                   x11_display_number;
400dab
         char                 *x11_display_name;
400dab
         int                   status;
400dab
         time_t                creation_time;
400dab
         GTimer               *server_timer;
400dab
 
400dab
         char                 *x11_cookie;
400dab
         gsize                 x11_cookie_size;
400dab
         GdmDisplayAccessFile *access_file;
400dab
 
400dab
         guint                 finish_idle_id;
400dab
 
400dab
         xcb_connection_t     *xcb_connection;
400dab
         int                   xcb_screen_number;
400dab
 
400dab
         GDBusConnection      *connection;
400dab
         GdmDisplayAccessFile *user_access_file;
400dab
@@ -98,131 +97,60 @@ enum {
400dab
         PROP_0,
400dab
         PROP_ID,
400dab
         PROP_STATUS,
400dab
         PROP_SEAT_ID,
400dab
         PROP_SESSION_ID,
400dab
         PROP_SESSION_CLASS,
400dab
         PROP_SESSION_TYPE,
400dab
         PROP_REMOTE_HOSTNAME,
400dab
         PROP_X11_DISPLAY_NUMBER,
400dab
         PROP_X11_DISPLAY_NAME,
400dab
         PROP_X11_COOKIE,
400dab
         PROP_X11_AUTHORITY_FILE,
400dab
         PROP_IS_CONNECTED,
400dab
         PROP_IS_LOCAL,
400dab
         PROP_LAUNCH_ENVIRONMENT,
400dab
         PROP_IS_INITIAL,
400dab
         PROP_ALLOW_TIMED_LOGIN,
400dab
         PROP_HAVE_EXISTING_USER_ACCOUNTS,
400dab
         PROP_DOING_INITIAL_SETUP,
400dab
 };
400dab
 
400dab
 static void     gdm_display_class_init  (GdmDisplayClass *klass);
400dab
 static void     gdm_display_init        (GdmDisplay      *self);
400dab
 static void     gdm_display_finalize    (GObject         *object);
400dab
 static void     queue_finish            (GdmDisplay      *self);
400dab
 static void     _gdm_display_set_status (GdmDisplay *self,
400dab
                                          int         status);
400dab
 static gboolean wants_initial_setup (GdmDisplay *self);
400dab
 G_DEFINE_ABSTRACT_TYPE (GdmDisplay, gdm_display, G_TYPE_OBJECT)
400dab
 
400dab
-static gboolean
400dab
-chown_file (GFile   *file,
400dab
-            uid_t    uid,
400dab
-            gid_t    gid,
400dab
-            GError **error)
400dab
-{
400dab
-        if (!g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_UID, uid,
400dab
-                                          G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
400dab
-                                          NULL, error)) {
400dab
-                return FALSE;
400dab
-        }
400dab
-        if (!g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_GID, gid,
400dab
-                                          G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
400dab
-                                          NULL, error)) {
400dab
-                return FALSE;
400dab
-        }
400dab
-        return TRUE;
400dab
-}
400dab
-
400dab
-static gboolean
400dab
-chown_recursively (GFile   *dir,
400dab
-                   uid_t    uid,
400dab
-                   gid_t    gid,
400dab
-                   GError **error)
400dab
-{
400dab
-        GFile *file = NULL;
400dab
-        GFileInfo *info = NULL;
400dab
-        GFileEnumerator *enumerator = NULL;
400dab
-        gboolean retval = FALSE;
400dab
-
400dab
-        if (chown_file (dir, uid, gid, error) == FALSE) {
400dab
-                goto out;
400dab
-        }
400dab
-
400dab
-        enumerator = g_file_enumerate_children (dir,
400dab
-                                                G_FILE_ATTRIBUTE_STANDARD_TYPE","
400dab
-                                                G_FILE_ATTRIBUTE_STANDARD_NAME,
400dab
-                                                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
400dab
-                                                NULL, error);
400dab
-        if (!enumerator) {
400dab
-                goto out;
400dab
-        }
400dab
-
400dab
-        while ((info = g_file_enumerator_next_file (enumerator, NULL, error)) != NULL) {
400dab
-                file = g_file_get_child (dir, g_file_info_get_name (info));
400dab
-
400dab
-                if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
400dab
-                        if (chown_recursively (file, uid, gid, error) == FALSE) {
400dab
-                                goto out;
400dab
-                        }
400dab
-                } else if (chown_file (file, uid, gid, error) == FALSE) {
400dab
-                        goto out;
400dab
-                }
400dab
-
400dab
-                g_clear_object (&file;;
400dab
-                g_clear_object (&info;;
400dab
-        }
400dab
-
400dab
-        if (*error) {
400dab
-                goto out;
400dab
-        }
400dab
-
400dab
-        retval = TRUE;
400dab
-out:
400dab
-        g_clear_object (&file;;
400dab
-        g_clear_object (&info;;
400dab
-        g_clear_object (&enumerator);
400dab
-
400dab
-        return retval;
400dab
-}
400dab
-
400dab
 GQuark
400dab
 gdm_display_error_quark (void)
400dab
 {
400dab
         static GQuark ret = 0;
400dab
         if (ret == 0) {
400dab
                 ret = g_quark_from_static_string ("gdm_display_error");
400dab
         }
400dab
 
400dab
         return ret;
400dab
 }
400dab
 
400dab
 time_t
400dab
 gdm_display_get_creation_time (GdmDisplay *self)
400dab
 {
400dab
         g_return_val_if_fail (GDM_IS_DISPLAY (self), 0);
400dab
 
400dab
         return self->priv->creation_time;
400dab
 }
400dab
 
400dab
 int
400dab
 gdm_display_get_status (GdmDisplay *self)
400dab
 {
400dab
         g_return_val_if_fail (GDM_IS_DISPLAY (self), 0);
400dab
 
400dab
         return self->priv->status;
400dab
 }
400dab
 
400dab
 const char *
400dab
 gdm_display_get_session_id (GdmDisplay *self)
400dab
 {
400dab
@@ -1649,145 +1577,85 @@ gdm_display_start_greeter_session (GdmDisplay *self)
400dab
                                  G_CALLBACK (on_launch_environment_session_stopped),
400dab
                                  self, 0);
400dab
         g_signal_connect_object (self->priv->launch_environment,
400dab
                                  "exited",
400dab
                                  G_CALLBACK (on_launch_environment_session_exited),
400dab
                                  self, 0);
400dab
         g_signal_connect_object (self->priv->launch_environment,
400dab
                                  "died",
400dab
                                  G_CALLBACK (on_launch_environment_session_died),
400dab
                                  self, 0);
400dab
 
400dab
         if (auth_file != NULL) {
400dab
                 g_object_set (self->priv->launch_environment,
400dab
                               "x11-authority-file", auth_file,
400dab
                               NULL);
400dab
         }
400dab
 
400dab
         gdm_launch_environment_start (self->priv->launch_environment);
400dab
 
400dab
         session = gdm_launch_environment_get_session (self->priv->launch_environment);
400dab
         g_object_set (G_OBJECT (session),
400dab
                       "display-is-initial", self->priv->is_initial,
400dab
                       NULL);
400dab
 
400dab
         g_free (display_name);
400dab
         g_free (seat_id);
400dab
         g_free (hostname);
400dab
         g_free (auth_file);
400dab
 }
400dab
 
400dab
-static void
400dab
-chown_initial_setup_home_dir (void)
400dab
-{
400dab
-        GFile *dir;
400dab
-        GError *error;
400dab
-        char *gis_dir_path;
400dab
-        char *gis_uid_path;
400dab
-        char *gis_uid_contents;
400dab
-        struct passwd *pwe;
400dab
-        uid_t uid;
400dab
-
400dab
-        if (!gdm_get_pwent_for_name (INITIAL_SETUP_USERNAME, &pwe)) {
400dab
-                g_warning ("Unknown user %s", INITIAL_SETUP_USERNAME);
400dab
-                return;
400dab
-        }
400dab
-
400dab
-        gis_dir_path = g_strdup (pwe->pw_dir);
400dab
-
400dab
-        gis_uid_path = g_build_filename (gis_dir_path,
400dab
-                                         "gnome-initial-setup-uid",
400dab
-                                         NULL);
400dab
-        if (!g_file_get_contents (gis_uid_path, &gis_uid_contents, NULL, NULL)) {
400dab
-                g_warning ("Unable to read %s", gis_uid_path);
400dab
-                goto out;
400dab
-        }
400dab
-
400dab
-        uid = (uid_t) atoi (gis_uid_contents);
400dab
-        pwe = getpwuid (uid);
400dab
-        if (uid == 0 || pwe == NULL) {
400dab
-                g_warning ("UID '%s' in %s is not valid", gis_uid_contents, gis_uid_path);
400dab
-                goto out;
400dab
-        }
400dab
-
400dab
-        error = NULL;
400dab
-        dir = g_file_new_for_path (gis_dir_path);
400dab
-        if (!chown_recursively (dir, pwe->pw_uid, pwe->pw_gid, &error)) {
400dab
-                g_warning ("Failed to change ownership for %s: %s", gis_dir_path, error->message);
400dab
-                g_error_free (error);
400dab
-        }
400dab
-        g_object_unref (dir);
400dab
-out:
400dab
-        g_free (gis_uid_contents);
400dab
-        g_free (gis_uid_path);
400dab
-        g_free (gis_dir_path);
400dab
-}
400dab
-
400dab
 void
400dab
 gdm_display_stop_greeter_session (GdmDisplay *self)
400dab
 {
400dab
         GError *error = NULL;
400dab
 
400dab
         if (self->priv->launch_environment != NULL) {
400dab
 
400dab
                 g_signal_handlers_disconnect_by_func (self->priv->launch_environment,
400dab
                                                       G_CALLBACK (on_launch_environment_session_opened),
400dab
                                                       self);
400dab
                 g_signal_handlers_disconnect_by_func (self->priv->launch_environment,
400dab
                                                       G_CALLBACK (on_launch_environment_session_started),
400dab
                                                       self);
400dab
                 g_signal_handlers_disconnect_by_func (self->priv->launch_environment,
400dab
                                                       G_CALLBACK (on_launch_environment_session_stopped),
400dab
                                                       self);
400dab
                 g_signal_handlers_disconnect_by_func (self->priv->launch_environment,
400dab
                                                       G_CALLBACK (on_launch_environment_session_exited),
400dab
                                                       self);
400dab
                 g_signal_handlers_disconnect_by_func (self->priv->launch_environment,
400dab
                                                       G_CALLBACK (on_launch_environment_session_died),
400dab
                                                       self);
400dab
                 gdm_launch_environment_stop (self->priv->launch_environment);
400dab
                 g_clear_object (&self->priv->launch_environment);
400dab
         }
400dab
-
400dab
-        if (self->priv->doing_initial_setup) {
400dab
-                chown_initial_setup_home_dir ();
400dab
-
400dab
-                if (!g_file_set_contents (ALREADY_RAN_INITIAL_SETUP_ON_THIS_BOOT,
400dab
-                                          "1",
400dab
-                                          1,
400dab
-                                          &error)) {
400dab
-                        g_warning ("GdmDisplay: Could not write initial-setup-done marker to %s: %s",
400dab
-                                   ALREADY_RAN_INITIAL_SETUP_ON_THIS_BOOT,
400dab
-                                   error->message);
400dab
-                        g_clear_error (&error);
400dab
-                }
400dab
-        }
400dab
 }
400dab
 
400dab
 static xcb_window_t
400dab
 get_root_window (xcb_connection_t *connection,
400dab
                  int               screen_number)
400dab
 {
400dab
         xcb_screen_t *screen = NULL;
400dab
         xcb_screen_iterator_t iter;
400dab
 
400dab
         iter = xcb_setup_roots_iterator (xcb_get_setup (connection));
400dab
         while (iter.rem) {
400dab
                 if (screen_number == 0)
400dab
                         screen = iter.data;
400dab
                 screen_number--;
400dab
                 xcb_screen_next (&iter);
400dab
         }
400dab
 
400dab
         if (screen != NULL) {
400dab
                 return screen->root;
400dab
         }
400dab
 
400dab
         return XCB_WINDOW_NONE;
400dab
 }
400dab
 
400dab
 static void
400dab
 gdm_display_set_windowpath (GdmDisplay *self)
400dab
 {
400dab
         /* setting WINDOWPATH for clients */
400dab
         xcb_intern_atom_cookie_t atom_cookie;
400dab
         xcb_intern_atom_reply_t *atom_reply = NULL;
400dab
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
400dab
index 0823e8638..cf982870c 100644
400dab
--- a/daemon/gdm-manager.c
400dab
+++ b/daemon/gdm-manager.c
400dab
@@ -35,60 +35,61 @@
400dab
 #include <glib-object.h>
400dab
 
400dab
 #include <act/act-user-manager.h>
400dab
 
400dab
 #include <systemd/sd-login.h>
400dab
 
400dab
 #include "gdm-common.h"
400dab
 
400dab
 #include "gdm-dbus-util.h"
400dab
 #include "gdm-manager.h"
400dab
 #include "gdm-manager-glue.h"
400dab
 #include "gdm-display-store.h"
400dab
 #include "gdm-display-factory.h"
400dab
 #include "gdm-launch-environment.h"
400dab
 #include "gdm-local-display.h"
400dab
 #include "gdm-local-display-factory.h"
400dab
 #include "gdm-session.h"
400dab
 #include "gdm-session-record.h"
400dab
 #include "gdm-settings-direct.h"
400dab
 #include "gdm-settings-keys.h"
400dab
 #include "gdm-xdmcp-display-factory.h"
400dab
 #include "gdm-xdmcp-chooser-display.h"
400dab
 
400dab
 #define GDM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_MANAGER, GdmManagerPrivate))
400dab
 
400dab
 #define GDM_DBUS_PATH             "/org/gnome/DisplayManager"
400dab
 #define GDM_MANAGER_PATH          GDM_DBUS_PATH "/Manager"
400dab
 #define GDM_MANAGER_DISPLAYS_PATH GDM_DBUS_PATH "/Displays"
400dab
 
400dab
 #define INITIAL_SETUP_USERNAME "gnome-initial-setup"
400dab
+#define ALREADY_RAN_INITIAL_SETUP_ON_THIS_BOOT GDM_RUN_DIR "/gdm.ran-initial-setup"
400dab
 
400dab
 typedef struct
400dab
 {
400dab
         GdmManager *manager;
400dab
         GdmSession *session;
400dab
         char *service_name;
400dab
         guint idle_id;
400dab
 } StartUserSessionOperation;
400dab
 
400dab
 struct GdmManagerPrivate
400dab
 {
400dab
         GdmDisplayStore        *display_store;
400dab
         GdmLocalDisplayFactory *local_factory;
400dab
 #ifdef HAVE_LIBXDMCP
400dab
         GdmXdmcpDisplayFactory *xdmcp_factory;
400dab
 #endif
400dab
         GdmDisplay             *automatic_login_display;
400dab
         GList                  *user_sessions;
400dab
         GHashTable             *transient_sessions;
400dab
         GHashTable             *open_reauthentication_requests;
400dab
         gboolean                xdmcp_enabled;
400dab
 
400dab
         gboolean                started;
400dab
         gboolean                show_local_greeter;
400dab
 
400dab
         GDBusConnection          *connection;
400dab
         GDBusObjectManagerServer *object_manager;
400dab
 
400dab
 #ifdef  WITH_PLYMOUTH
400dab
         guint                     plymouth_is_running : 1;
400dab
@@ -1630,130 +1631,261 @@ start_user_session (GdmManager *manager,
400dab
 
400dab
         destroy_start_user_session_operation (operation);
400dab
 }
400dab
 
400dab
 static void
400dab
 create_display_for_user_session (GdmManager *self,
400dab
                                  GdmSession *session,
400dab
                                  const char *session_id)
400dab
 {
400dab
         GdmDisplay *display;
400dab
         /* at the moment we only create GdmLocalDisplay objects on seat0 */
400dab
         const char *seat_id = "seat0";
400dab
 
400dab
         display = gdm_local_display_new ();
400dab
 
400dab
         g_object_set (G_OBJECT (display),
400dab
                       "session-class", "user",
400dab
                       "seat-id", seat_id,
400dab
                       "session-id", session_id,
400dab
                       NULL);
400dab
         gdm_display_store_add (self->priv->display_store,
400dab
                                display);
400dab
         g_object_set_data (G_OBJECT (session), "gdm-display", display);
400dab
         g_object_set_data_full (G_OBJECT (display),
400dab
                                 "gdm-user-session",
400dab
                                 g_object_ref (session),
400dab
                                 (GDestroyNotify)
400dab
                                 clean_user_session);
400dab
 }
400dab
 
400dab
+static gboolean
400dab
+chown_file (GFile   *file,
400dab
+            uid_t    uid,
400dab
+            gid_t    gid,
400dab
+            GError **error)
400dab
+{
400dab
+        if (!g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_UID, uid,
400dab
+                                          G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
400dab
+                                          NULL, error)) {
400dab
+                return FALSE;
400dab
+        }
400dab
+        if (!g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_GID, gid,
400dab
+                                          G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
400dab
+                                          NULL, error)) {
400dab
+                return FALSE;
400dab
+        }
400dab
+        return TRUE;
400dab
+}
400dab
+
400dab
+static gboolean
400dab
+chown_recursively (GFile   *dir,
400dab
+                   uid_t    uid,
400dab
+                   gid_t    gid,
400dab
+                   GError **error)
400dab
+{
400dab
+        GFile *file = NULL;
400dab
+        GFileInfo *info = NULL;
400dab
+        GFileEnumerator *enumerator = NULL;
400dab
+        gboolean retval = FALSE;
400dab
+
400dab
+        if (chown_file (dir, uid, gid, error) == FALSE) {
400dab
+                goto out;
400dab
+        }
400dab
+
400dab
+        enumerator = g_file_enumerate_children (dir,
400dab
+                                                G_FILE_ATTRIBUTE_STANDARD_TYPE","
400dab
+                                                G_FILE_ATTRIBUTE_STANDARD_NAME,
400dab
+                                                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
400dab
+                                                NULL, error);
400dab
+        if (!enumerator) {
400dab
+                goto out;
400dab
+        }
400dab
+
400dab
+        while ((info = g_file_enumerator_next_file (enumerator, NULL, error)) != NULL) {
400dab
+                file = g_file_get_child (dir, g_file_info_get_name (info));
400dab
+
400dab
+                if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
400dab
+                        if (chown_recursively (file, uid, gid, error) == FALSE) {
400dab
+                                goto out;
400dab
+                        }
400dab
+                } else if (chown_file (file, uid, gid, error) == FALSE) {
400dab
+                        goto out;
400dab
+                }
400dab
+
400dab
+                g_clear_object (&file;;
400dab
+                g_clear_object (&info;;
400dab
+        }
400dab
+
400dab
+        if (*error) {
400dab
+                goto out;
400dab
+        }
400dab
+
400dab
+        retval = TRUE;
400dab
+out:
400dab
+        g_clear_object (&file;;
400dab
+        g_clear_object (&info;;
400dab
+        g_clear_object (&enumerator);
400dab
+
400dab
+        return retval;
400dab
+}
400dab
+
400dab
+static void
400dab
+chown_initial_setup_home_dir (void)
400dab
+{
400dab
+        GFile *dir;
400dab
+        GError *error;
400dab
+        char *gis_dir_path;
400dab
+        char *gis_uid_path;
400dab
+        char *gis_uid_contents;
400dab
+        struct passwd *pwe;
400dab
+        uid_t uid;
400dab
+
400dab
+        if (!gdm_get_pwent_for_name (INITIAL_SETUP_USERNAME, &pwe)) {
400dab
+                g_warning ("Unknown user %s", INITIAL_SETUP_USERNAME);
400dab
+                return;
400dab
+        }
400dab
+
400dab
+        gis_dir_path = g_strdup (pwe->pw_dir);
400dab
+
400dab
+        gis_uid_path = g_build_filename (gis_dir_path,
400dab
+                                         "gnome-initial-setup-uid",
400dab
+                                         NULL);
400dab
+        if (!g_file_get_contents (gis_uid_path, &gis_uid_contents, NULL, NULL)) {
400dab
+                g_warning ("Unable to read %s", gis_uid_path);
400dab
+                goto out;
400dab
+        }
400dab
+
400dab
+        uid = (uid_t) atoi (gis_uid_contents);
400dab
+        pwe = getpwuid (uid);
400dab
+        if (uid == 0 || pwe == NULL) {
400dab
+                g_warning ("UID '%s' in %s is not valid", gis_uid_contents, gis_uid_path);
400dab
+                goto out;
400dab
+        }
400dab
+
400dab
+        error = NULL;
400dab
+        dir = g_file_new_for_path (gis_dir_path);
400dab
+        if (!chown_recursively (dir, pwe->pw_uid, pwe->pw_gid, &error)) {
400dab
+                g_warning ("Failed to change ownership for %s: %s", gis_dir_path, error->message);
400dab
+                g_error_free (error);
400dab
+        }
400dab
+        g_object_unref (dir);
400dab
+out:
400dab
+        g_free (gis_uid_contents);
400dab
+        g_free (gis_uid_path);
400dab
+        g_free (gis_dir_path);
400dab
+}
400dab
+
400dab
 static gboolean
400dab
 on_start_user_session (StartUserSessionOperation *operation)
400dab
 {
400dab
         GdmManager *self = operation->manager;
400dab
         gboolean migrated;
400dab
         gboolean fail_if_already_switched = TRUE;
400dab
         gboolean doing_initial_setup = FALSE;
400dab
         GdmDisplay *display;
400dab
         const char *session_id;
400dab
 #if defined(ENABLE_WAYLAND_SUPPORT) && defined(ENABLE_USER_DISPLAY_SERVER)
400dab
         g_autofree char *display_session_type = NULL;
400dab
 #endif
400dab
 
400dab
         g_debug ("GdmManager: start or jump to session");
400dab
 
400dab
         /* If there's already a session running, jump to it.
400dab
          * If the only session running is the one we just opened,
400dab
          * start a session on it.
400dab
          */
400dab
         migrated = switch_to_compatible_user_session (operation->manager, operation->session, fail_if_already_switched);
400dab
 
400dab
         g_debug ("GdmManager: migrated: %d", migrated);
400dab
         if (migrated) {
400dab
                 /* We don't stop the manager here because
400dab
                    when Xorg exits it switches to the VT it was
400dab
                    started from.  That interferes with fast
400dab
                    user switching. */
400dab
                 gdm_session_reset (operation->session);
400dab
                 destroy_start_user_session_operation (operation);
400dab
                 goto out;
400dab
         }
400dab
 
400dab
         display = get_display_for_user_session (operation->session);
400dab
 
400dab
         g_object_get (G_OBJECT (display),
400dab
                       "doing-initial-setup", &doing_initial_setup,
400dab
 #if defined(ENABLE_WAYLAND_SUPPORT) && defined(ENABLE_USER_DISPLAY_SERVER)
400dab
                       "session-type", &display_session_type,
400dab
 #endif
400dab
                       NULL);
400dab
 
400dab
         session_id = gdm_session_get_conversation_session_id (operation->session,
400dab
                                                               operation->service_name);
400dab
 
400dab
         if (gdm_session_get_display_mode (operation->session) == GDM_SESSION_DISPLAY_MODE_REUSE_VT) {
400dab
                 /* In this case, the greeter's display is morphing into
400dab
                  * the user session display. Kill the greeter on this session
400dab
                  * and let the user session follow the same display. */
400dab
                 gdm_display_stop_greeter_session (display);
400dab
                 g_object_set (G_OBJECT (display),
400dab
                                 "session-class", "user",
400dab
                                 "session-id", session_id,
400dab
                                 NULL);
400dab
         } else {
400dab
                 uid_t allowed_uid;
400dab
 
400dab
                 g_object_ref (display);
400dab
                 if (doing_initial_setup) {
400dab
+                        g_autoptr(GError) error = NULL;
400dab
+
400dab
 #if defined(ENABLE_WAYLAND_SUPPORT) && defined(ENABLE_USER_DISPLAY_SERVER)
400dab
                         if (g_strcmp0 (display_session_type, "wayland") == 0) {
400dab
                                 g_debug ("GdmManager: closing down initial setup display in background");
400dab
                                 g_object_set (G_OBJECT (display), "status", GDM_DISPLAY_WAITING_TO_FINISH, NULL);
400dab
                         }
400dab
 #endif
400dab
                         if (gdm_display_get_status (display) == GDM_DISPLAY_MANAGED) {
400dab
                                 g_debug ("GdmManager: closing down initial setup display");
400dab
                                 gdm_display_stop_greeter_session (display);
400dab
                                 gdm_display_unmanage (display);
400dab
                                 gdm_display_finish (display);
400dab
                         }
400dab
+
400dab
+                        chown_initial_setup_home_dir ();
400dab
+
400dab
+                        if (!g_file_set_contents (ALREADY_RAN_INITIAL_SETUP_ON_THIS_BOOT,
400dab
+                                                  "1",
400dab
+                                                  1,
400dab
+                                                  &error)) {
400dab
+                                g_warning ("GdmDisplay: Could not write initial-setup-done marker to %s: %s",
400dab
+                                           ALREADY_RAN_INITIAL_SETUP_ON_THIS_BOOT,
400dab
+                                           error->message);
400dab
+                                g_clear_error (&error);
400dab
+                        }
400dab
                 } else {
400dab
                         g_debug ("GdmManager: session has its display server, reusing our server for another login screen");
400dab
                 }
400dab
 
400dab
                 /* The user session is going to follow the session worker
400dab
                  * into the new display. Untie it from this display and
400dab
                  * create a new session for a future user login. */
400dab
                 allowed_uid = gdm_session_get_allowed_user (operation->session);
400dab
                 g_object_set_data (G_OBJECT (display), "gdm-user-session", NULL);
400dab
                 g_object_set_data (G_OBJECT (operation->session), "gdm-display", NULL);
400dab
                 create_user_session_for_display (operation->manager, display, allowed_uid);
400dab
 
400dab
                 /* Give the user session a new display object for bookkeeping purposes */
400dab
                 create_display_for_user_session (operation->manager,
400dab
                                                  operation->session,
400dab
                                                  session_id);
400dab
 
400dab
                 if ((g_strcmp0 (operation->service_name, "gdm-autologin") == 0) &&
400dab
                     !gdm_session_client_is_connected (operation->session)) {
400dab
                         /* remove the unused prepared greeter display since we're not going
400dab
                          * to have a greeter */
400dab
                         gdm_display_store_remove (self->priv->display_store, display);
400dab
                         g_object_unref (display);
400dab
 
400dab
                         self->priv->automatic_login_display = g_object_get_data (G_OBJECT (operation->session), "gdm-display");
400dab
                         g_object_add_weak_pointer (G_OBJECT (self->priv->automatic_login_display), (gpointer *) &self->priv->automatic_login_display);
400dab
                 }
400dab
         }
400dab
 
400dab
         start_user_session (operation->manager, operation);
400dab
-- 
400dab
2.27.0
400dab