[gdm/gnome-3-6] daemon: user marker file for tracking autologin instead of static variable.



commit 9a77cb7f43bfde2d6d8238b59ccbe8d5ccf4989b
Author: Ray Strode <rstrode redhat com>
Date:   Thu Oct 4 18:13:56 2012 -0400

    daemon: user marker file for tracking autologin instead of static variable.
    
    We currently decide whether or not to skip autologin by a first_login
    state variable in the static display object.
    
    These days we can have multiple static display objects, so storing the
    state variable doesn't make much sense.  We could make the variable
    static, but instead this commit switches to using a marker file in
    /var/run/gdm.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682467
    (cherry picked from commit 11d4b97bfda92a254d2ef55b4795456367a3cfbb)

 configure.ac                |   20 ++++++++++++++++++++
 daemon/gdm-simple-slave.c   |   27 +++++++++++++++++++++++++++
 daemon/gdm-static-display.c |   23 -----------------------
 daemon/main.c               |   14 ++++++++++++++
 4 files changed, 61 insertions(+), 23 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0531d19..b09c6f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1333,6 +1333,26 @@ AC_SUBST(GDM_PID_FILE)
 AC_DEFINE_UNQUOTED(GDM_PID_FILE, "$GDM_PID_FILE", [pid file])
 
 dnl ---------------------------------------------------------------------------
+dnl - ran once marker
+dnl ---------------------------------------------------------------------------
+
+AC_ARG_WITH(ran-once-marker-directory,
+            AS_HELP_STRING([--with-ran-once-marker-directory=<dir>],
+                           [ran once marker directory]))
+
+if ! test -z "$with_ran_once_marker_directory"; then
+   GDM_RAN_ONCE_MARKER_DIR=$with_ran_once_marker_directory
+else
+   GDM_RAN_ONCE_MARKER_DIR=${localstatedir}/run/gdm
+fi
+AC_SUBST(GDM_RAN_ONCE_MARKER_DIR)
+AC_DEFINE_UNQUOTED(GDM_RAN_ONCE_MARKER_DIR, "$GDM_RAN_ONCE_MARKER_DIR", [ran once marker dir])
+
+GDM_RAN_ONCE_MARKER_FILE="$GDM_RAN_ONCE_MARKER_DIR/ran-once-marker"
+AC_SUBST(GDM_RAN_ONCE_MARKER_FILE)
+AC_DEFINE_UNQUOTED(GDM_RAN_ONCE_MARKER_FILE, "$GDM_RAN_ONCE_MARKER_FILE", [ran once marker file])
+
+dnl ---------------------------------------------------------------------------
 dnl - GREETER WORKING DIRECTORY
 dnl ---------------------------------------------------------------------------
 
diff --git a/daemon/gdm-simple-slave.c b/daemon/gdm-simple-slave.c
index 9bc8522..8f5f0c6 100644
--- a/daemon/gdm-simple-slave.c
+++ b/daemon/gdm-simple-slave.c
@@ -517,6 +517,10 @@ start_autologin_conversation_if_necessary (GdmSimpleSlave  *slave)
 {
         gboolean enabled;
 
+        if (g_file_test (GDM_RAN_ONCE_MARKER_FILE, G_FILE_TEST_EXISTS)) {
+                return;
+        }
+
         gdm_slave_get_timed_login_details (GDM_SLAVE (slave), &enabled, NULL, NULL);
 
         if (!enabled) {
@@ -730,6 +734,23 @@ on_session_cancelled (GdmSession      *session,
 }
 
 static void
+touch_marker_file (GdmSimpleSlave *slave)
+{
+        int fd;
+
+        fd = g_creat (GDM_RAN_ONCE_MARKER_FILE, 0644);
+
+        if (fd < 0 && errno != EEXIST) {
+                g_warning ("could not create %s to mark run, this may cause auto login "
+                           "to repeat: %m", GDM_RAN_ONCE_MARKER_FILE);
+                return;
+        }
+
+        fsync (fd);
+        close (fd);
+}
+
+static void
 create_new_session (GdmSimpleSlave  *slave)
 {
         gboolean       display_is_local;
@@ -830,6 +851,8 @@ create_new_session (GdmSimpleSlave  *slave)
                           slave);
 
         start_autologin_conversation_if_necessary (slave);
+
+        touch_marker_file (slave);
 }
 
 static void
@@ -1245,6 +1268,10 @@ wants_autologin (GdmSimpleSlave *slave)
         int delay = 0;
         /* FIXME: handle wait-for-go */
 
+        if (g_file_test (GDM_RAN_ONCE_MARKER_FILE, G_FILE_TEST_EXISTS)) {
+                return FALSE;
+        }
+
         gdm_slave_get_timed_login_details (GDM_SLAVE (slave), &enabled, NULL, &delay);
         return enabled && delay == 0;
 }
diff --git a/daemon/gdm-static-display.c b/daemon/gdm-static-display.c
index 1806be9..8e7254d 100644
--- a/daemon/gdm-static-display.c
+++ b/daemon/gdm-static-display.c
@@ -46,7 +46,6 @@
 struct GdmStaticDisplayPrivate
 {
         GdmDBusStaticDisplay *skeleton;
-        gboolean first_login;
 };
 
 static void     gdm_static_display_class_init   (GdmStaticDisplayClass *klass);
@@ -117,30 +116,11 @@ gdm_static_display_unmanage (GdmDisplay *display)
 {
         g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE);
 
-        GDM_STATIC_DISPLAY (display)->priv->first_login = FALSE;
-
         GDM_DISPLAY_CLASS (gdm_static_display_parent_class)->unmanage (display);
 
         return TRUE;
 }
 
-static void
-gdm_static_display_get_timed_login_details (GdmDisplay *display,
-                                            gboolean   *enabledp,
-                                            char      **usernamep,
-                                            int        *delayp)
-{
-        GDM_DISPLAY_CLASS (gdm_static_display_parent_class)->get_timed_login_details (display, enabledp, usernamep, delayp);
-
-        if (!GDM_STATIC_DISPLAY (display)->priv->first_login) {
-                /* if this is autologin but not timed login, then disable
-                 * autologin after the first one */
-                if (*enabledp && *delayp == 0) {
-                        *enabledp = FALSE;
-                }
-        }
-}
-
 static GObject *
 gdm_static_display_constructor (GType                  type,
                                    guint                  n_construct_properties,
@@ -185,7 +165,6 @@ gdm_static_display_class_init (GdmStaticDisplayClass *klass)
         display_class->manage = gdm_static_display_manage;
         display_class->finish = gdm_static_display_finish;
         display_class->unmanage = gdm_static_display_unmanage;
-        display_class->get_timed_login_details = gdm_static_display_get_timed_login_details;
 
         g_type_class_add_private (klass, sizeof (GdmStaticDisplayPrivate));
 }
@@ -195,8 +174,6 @@ gdm_static_display_init (GdmStaticDisplay *static_display)
 {
 
         static_display->priv = GDM_STATIC_DISPLAY_GET_PRIVATE (static_display);
-
-        static_display->priv->first_login = TRUE;
 }
 
 GdmDisplay *
diff --git a/daemon/main.c b/daemon/main.c
index 6d02ad3..834976b 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -146,6 +146,12 @@ write_pid (void)
 }
 
 static void
+delete_first_run_marker (void)
+{
+        g_unlink (GDM_RAN_ONCE_MARKER_FILE);
+}
+
+static void
 check_logdir (void)
 {
         struct stat     statbuf;
@@ -162,6 +168,7 @@ check_logdir (void)
                 }
                 g_chmod (log_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
         }
+
 }
 
 static void
@@ -486,6 +493,10 @@ main (int    argc,
         set_effective_user_group (0, 0);
         check_logdir ();
 
+        /* Set up /var/run/gdm */
+        g_mkdir_with_parents (GDM_RAN_ONCE_MARKER_DIR, 0755);
+        g_chmod (GDM_RAN_ONCE_MARKER_DIR, S_IRWXU | S_IRWXG);
+
         /* XDM compliant error message */
         if (getuid () != 0) {
                 /* make sure the pid file doesn't get wiped */
@@ -500,6 +511,9 @@ main (int    argc,
         delete_pid ();
         write_pid ();
 
+        /* clean up any stale ran once marker file that may be lingering */
+        delete_first_run_marker ();
+
         g_chdir (AUTHDIR);
 
         main_loop = g_main_loop_new (NULL, FALSE);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]