]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Fixes a bug that prevents session locking if the session was unlocked after changing...
authorJesús González <jgonzalez@gdr-sistemas.com>
Wed, 11 Feb 2015 23:30:00 +0000 (12:30 +1300)
committerRobert Ancell <robert.ancell@canonical.com>
Wed, 11 Feb 2015 23:30:00 +0000 (12:30 +1300)
src/lightdm.c
src/seat.c
src/seat.h
src/session.c
src/session.h
tests/Makefile.am
tests/scripts/lock-seat-after-vt-switch.conf [new file with mode: 0644]
tests/src/test-runner.c
tests/test-lock-seat-after-vt-switch [new file with mode: 0755]

index 48a44ab57ff5f834a50cb8d4438ccf62e9a154b2..8c52d1e194189acd8318c0934ea980825abb16d5 100644 (file)
@@ -1081,6 +1081,31 @@ static void
 login1_active_session_changed_cb (Login1Seat *login1_seat, const gchar *login1_session_id)
 {
     g_debug ("Seat %s changes active session to %s", login1_seat_get_id (login1_seat), login1_session_id);
+
+    Seat *seat;
+    seat = display_manager_get_seat (display_manager, login1_seat_get_id (login1_seat));
+
+    if (seat)
+    {
+        Session *active_session;
+        active_session = seat_get_expected_active_session (seat);
+
+        if (g_strcmp0 (login1_session_id, session_get_login1_session_id (active_session)) == 0)
+        {
+            // Session is already active
+            g_debug ("Session %s is already active", login1_session_id);
+            return;
+        }
+
+        active_session = seat_find_session_by_login1_id (seat, login1_session_id);
+        if (active_session != NULL)
+        {
+            g_debug ("Activating session %s", login1_session_id);
+            seat_set_externally_activated_session (seat, active_session);
+            return;
+
+        }
+    }
 }
 
 static gboolean
index 9a56baf26075af40b67db7ae7e7be05a96f8416a..b847332739fc78c7800060efe699b649ef72c779 100644 (file)
@@ -269,6 +269,54 @@ seat_get_next_session (Seat *seat)
     return seat->priv->next_session;
 }
 
+/**
+ * Obtains the active session which lightdm expects to be active.
+ *
+ * This function is different from seat_get_active_session() in that the
+ * later (in the case of xlocal seats) dynamically finds the session that is
+ * really active (based on the active VT), whereas this function returns the
+ * session that lightdm activated last by itself, which may not be the actual
+ * active session (i.e. VT changes).
+ */
+Session *
+seat_get_expected_active_session (Seat *seat)
+{
+    g_return_val_if_fail (seat != NULL, NULL);
+    return seat->priv->active_session;
+}
+
+/**
+ * Sets the active session which lightdm expects to be active.
+ *
+ * This function is different from seat_set_active_session() in that the
+ * later performs an actual session activation, whereas this function just
+ * updates the active session after the session has been activated by some
+ * means external to lightdm (i.e. VT changes).
+ */
+void
+seat_set_externally_activated_session (Seat *seat, Session *session)
+{
+    g_return_if_fail (seat != NULL);
+    if (seat->priv->active_session)
+        g_object_unref (seat->priv->active_session);
+    seat->priv->active_session = g_object_ref (session);
+}
+
+Session *
+seat_find_session_by_login1_id (Seat *seat, const gchar *login1_session_id)
+{
+    GList *session_link;
+
+    for (session_link = seat->priv->sessions; session_link; session_link = session_link->next)
+    {
+        Session *session = session_link->data;
+        if (g_strcmp0 (login1_session_id, session_get_login1_session_id (session)) == 0)
+            return session;
+    }
+
+    return NULL;
+}
+
 gboolean
 seat_get_can_switch (Seat *seat)
 {
index f8781ef551dbb3fd6dd7db26632865f7439e31a9..e8d2bc6fe8ace70469fdc9f7920ac5ac74999c0c 100644 (file)
@@ -93,6 +93,12 @@ Session *seat_get_active_session (Seat *seat);
 
 Session *seat_get_next_session (Seat *seat);
 
+void seat_set_externally_activated_session (Seat *seat, Session *session);
+
+Session *seat_get_expected_active_session (Seat *seat);
+
+Session *seat_find_session_by_login1_id (Seat *seat, const gchar *login1_session_id);
+
 gboolean seat_get_can_switch (Seat *seat);
 
 gboolean seat_get_allow_guest (Seat *seat);
index 66d138d863dee895203e2676a994e5c87e8d316b..26d0ce9752f9993760fa761d55efdeb96a97e501 100644 (file)
@@ -652,6 +652,13 @@ session_get_username (Session *session)
     return session->priv->username;
 }
 
+const gchar *
+session_get_login1_session_id (Session *session)
+{
+    g_return_val_if_fail (session != NULL, NULL);
+    return session->priv->login1_session_id;
+}
+
 const gchar *
 session_get_console_kit_cookie (Session *session)
 {
index 513fd12dc7942afb09c01b7bd7cdce78cef5d028..c62303e66b1b20781480b3df8f0696a3ffcea8e7 100644 (file)
@@ -115,6 +115,8 @@ gboolean session_get_is_started (Session *session);
 
 const gchar *session_get_username (Session *session);
 
+const gchar *session_get_login1_session_id (Session *session);
+
 const gchar *session_get_console_kit_cookie (Session *session);
 
 void session_respond (Session *session, struct pam_response *response);
index 8bfd1add07bafc6794de98837b6923d504ad4bfd..70e35bba297f0d9b897dd6d90121536aa5bbe469 100644 (file)
@@ -129,6 +129,7 @@ TESTS = \
        test-upstart-login \
        test-dbus \
        test-lock-seat \
+       test-lock-seat-after-vt-switch \
        test-lock-seat-resettable \
        test-lock-seat-return-session \
        test-lock-session \
diff --git a/tests/scripts/lock-seat-after-vt-switch.conf b/tests/scripts/lock-seat-after-vt-switch.conf
new file mode 100644 (file)
index 0000000..82266db
--- /dev/null
@@ -0,0 +1,86 @@
+#
+# Check that a seat is locked properly when it has been unlocked by switching
+# back to the user session and using the screensaver to unlock it.
+#
+
+[SeatDefaults]
+autologin-user=have-password1
+user-session=default
+
+#?*START-DAEMON
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER-0 START VT=7 SEAT=seat0
+
+# Daemon connects when X server is ready
+#?*XSERVER-0 INDICATE-READY
+#?XSERVER-0 INDICATE-READY
+#?XSERVER-0 ACCEPT-CONNECT
+
+# Session starts
+#?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_GREETER_DATA_DIR=.*/have-password1 XDG_SESSION_TYPE=x11 XDG_SESSION_DESKTOP=default USER=have-password1
+#?LOGIN1 ACTIVATE-SESSION SESSION=c0
+#?XSERVER-0 ACCEPT-CONNECT
+#?SESSION-X-0 CONNECT-XSERVER
+
+# Lock the seat
+#?*SESSION-X-0 LOCK-SEAT
+#?SESSION-X-0 LOCK-SEAT
+
+# New X server starts
+#?XSERVER-1 START VT=8 SEAT=seat0
+
+# Daemon connects when X server is ready
+#?*XSERVER-1 INDICATE-READY
+#?XSERVER-1 INDICATE-READY
+#?XSERVER-1 ACCEPT-CONNECT
+
+# Session is locked
+#?LOGIN1 LOCK-SESSION SESSION=c0
+
+# Greeter starts
+#?GREETER-X-1 START XDG_SEAT=seat0 XDG_VTNR=8 XDG_SESSION_CLASS=greeter
+#?XSERVER-1 ACCEPT-CONNECT
+#?GREETER-X-1 CONNECT-XSERVER
+#?GREETER-X-1 CONNECT-TO-DAEMON
+#?GREETER-X-1 CONNECTED-TO-DAEMON
+#?GREETER-X-1 LOCK-HINT
+
+# Session is switched to greeter
+#?LOGIN1 ACTIVATE-SESSION SESSION=c1
+#?VT ACTIVATE VT=8
+
+# External program switches back to the first session
+#?*UPDATE-SEAT ID=seat0 ACTIVE-SESSION=c0
+
+# Session is unlocked using the screensaver
+#?*UNLOCK-SESSION SESSION=c0
+#?RUNNER UNLOCK-SESSION SESSION=c0
+
+# Lock the seat again
+#?*SESSION-X-0 LOCK-SEAT
+#?SESSION-X-0 LOCK-SEAT
+
+# New X server starts (this is a "bug")
+#?XSERVER-2 START VT=9 SEAT=seat0
+#?*XSERVER-2 INDICATE-READY
+#?XSERVER-2 INDICATE-READY
+#?XSERVER-2 ACCEPT-CONNECT
+
+# Session is locked
+#?LOGIN1 LOCK-SESSION SESSION=c0
+
+# Session is switched to greeter
+#?LOGIN1 ACTIVATE-SESSION SESSION=c1
+
+# The unnecessary X server is killed
+#?XSERVER-2 TERMINATE SIGNAL=15
+
+# Cleanup
+#?*STOP-DAEMON
+#?SESSION-X-0 TERMINATE SIGNAL=15
+#?XSERVER-0 TERMINATE SIGNAL=15
+#?GREETER-X-1 TERMINATE SIGNAL=15
+#?XSERVER-1 TERMINATE SIGNAL=15
+#?RUNNER DAEMON-EXIT STATUS=0
index abad48651f72b15185574d40d89aa39b770244cc..e66dead8f7b8ce1bf2837423b4d7bfaeaf728459 100644 (file)
@@ -110,6 +110,7 @@ typedef struct
     gchar *path;
     gboolean can_graphical;
     gboolean can_multi_session;
+    gchar *active_session;
 } Login1Seat;
 
 static GList *login1_seats = NULL;
@@ -142,6 +143,7 @@ static void check_status (const gchar *status);
 static AccountsUser *get_accounts_user_by_uid (guint uid);
 static AccountsUser *get_accounts_user_by_name (const gchar *username);
 static void accounts_user_set_hidden (AccountsUser *user, gboolean hidden, gboolean emit_signal);
+static Login1Session *find_login1_session (const gchar *id);
 
 static gboolean
 kill_timeout_cb (gpointer data)
@@ -567,6 +569,13 @@ handle_command (const gchar *command)
                 seat->can_multi_session = strcmp (v, "TRUE") == 0;
                 g_variant_builder_add (&invalidated_properties, "s", "CanMultiSession");
             }
+            v = g_hash_table_lookup (params, "ACTIVE-SESSION");
+            if (v)
+            {
+                g_free (seat->active_session);
+                seat->active_session = g_strdup (v);
+                g_variant_builder_add (&invalidated_properties, "s", "ActiveSession");
+            }
 
             g_dbus_connection_emit_signal (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
                                            NULL,
@@ -917,6 +926,26 @@ handle_command (const gchar *command)
         check_status (status_text);
         g_free (status_text);
     }
+    else if (strcmp (name, "UNLOCK-SESSION") == 0)
+    {
+        gchar *status_text, *id;
+        Login1Session *session;
+        
+        id = g_hash_table_lookup (params, "SESSION");
+        session = find_login1_session (id);
+        if (session)
+        {
+            if (!session->locked)
+                g_warning ("Session %s is not locked", id);
+            session->locked = FALSE;
+        }
+        else
+            g_warning ("Unknown session %s", id);
+
+        status_text = g_strdup_printf ("RUNNER UNLOCK-SESSION SESSION=%s", id);
+        check_status (status_text);
+        g_free (status_text);
+    }
     /* Forward to external processes */
     else if (g_str_has_prefix (name, "SESSION-") ||
              g_str_has_prefix (name, "GREETER-") ||
@@ -1481,6 +1510,22 @@ handle_login1_seat_get_property (GDBusConnection       *connection,
         return g_variant_new_boolean (seat->can_multi_session);
     else if (strcmp (property_name, "Id") == 0)
         return g_variant_new_string (seat->id);
+    else if (strcmp (property_name, "ActiveSession") == 0)
+    {
+        if (seat->active_session)
+        {
+            gchar *path;
+            GVariant *ret;
+            
+            path = g_strdup_printf ("/org/freedesktop/login1/session/%s", seat->active_session);
+            ret = g_variant_new ("(so)", seat->active_session, path);
+            g_free (path);
+
+            return ret;
+        }
+        else 
+            return NULL;
+    }
     else
         return NULL;
 }
@@ -1497,6 +1542,7 @@ add_login1_seat (GDBusConnection *connection, const gchar *id, gboolean emit_sig
         "  <interface name='org.freedesktop.login1.Seat'>"
         "    <property name='CanGraphical' type='b' access='read'/>"
         "    <property name='CanMultiSession' type='b' access='read'/>"
+        "    <property name='ActiveSession' type='(so)' access='read'/>"
         "    <property name='Id' type='s' access='read'/>"
         "  </interface>"
         "</node>";
@@ -1512,6 +1558,7 @@ add_login1_seat (GDBusConnection *connection, const gchar *id, gboolean emit_sig
     seat->path = g_strdup_printf ("/org/freedesktop/login1/seat/%s", seat->id);
     seat->can_graphical = TRUE;
     seat->can_multi_session = TRUE;
+    seat->active_session = NULL;
 
     login1_seat_info = g_dbus_node_info_new_for_xml (login1_seat_interface, &error);
     if (error)
@@ -1589,6 +1636,7 @@ remove_login1_seat (GDBusConnection *connection, const gchar *id)
     login1_seats = g_list_remove (login1_seats, seat);
     g_free (seat->id);
     g_free (seat->path);
+    g_free (seat->active_session);
     g_free (seat);
 }
 
diff --git a/tests/test-lock-seat-after-vt-switch b/tests/test-lock-seat-after-vt-switch
new file mode 100755 (executable)
index 0000000..1689fe3
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner lock-seat-after-vt-switch test-gobject-greeter