]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Add a session lock D-Bus call that makes the greeter select that user
authorRobert Ancell <robert.ancell@canonical.com>
Wed, 15 Feb 2012 04:07:05 +0000 (15:07 +1100)
committerRobert Ancell <robert.ancell@canonical.com>
Wed, 15 Feb 2012 04:07:05 +0000 (15:07 +1100)
src/lightdm.c
src/seat.c
src/seat.h
tests/Makefile.am
tests/scripts/lock-seat.conf
tests/scripts/lock-session.conf [new file with mode: 0644]
tests/src/test-runner.c
tests/src/test-session.c
tests/test-lock-session [new file with mode: 0755]

index bbdf7034991983b2210fe8e529099a45b65c20ba..c853650ae5f7eb53bdd72cdd7a76ba7e3bb637cd 100644 (file)
@@ -420,11 +420,33 @@ handle_seat_call (GDBusConnection       *connection,
     else if (g_strcmp0 (method_name, "Lock") == 0)
     {
         /* FIXME: Should only allow locks if have a session on this seat */
-        seat_lock (seat);
+        seat_lock (seat, NULL);
         g_dbus_method_invocation_return_value (invocation, NULL);
     }
 }
 
+static Seat *
+get_seat_for_session (Session *session)
+{
+    GList *seat_link;
+
+    for (seat_link = display_manager_get_seats (display_manager); seat_link; seat_link = seat_link->next)
+    {
+        Seat *seat = seat_link->data;
+        GList *display_link;
+
+        for (display_link = seat_get_displays (seat); display_link; display_link = display_link->next)
+        {
+            Display *display = display_link->data;
+
+            if (display_get_session (display) == session)
+                return seat;
+        }
+    } 
+
+    return NULL;
+}
+
 static GVariant *
 handle_session_get_property (GDBusConnection       *connection,
                              const gchar           *sender,
@@ -456,6 +478,17 @@ handle_session_call (GDBusConnection       *connection,
                      GDBusMethodInvocation *invocation,
                      gpointer               user_data)
 {
+    Session *session = user_data;
+
+    if (g_strcmp0 (method_name, "Lock") == 0)
+    {
+        Seat *seat;
+
+        seat = get_seat_for_session (session);
+        /* FIXME: Should only allow locks if have a session on this seat */
+        seat_lock (seat, user_get_name (session_get_user (session)));
+        g_dbus_method_invocation_return_value (invocation, NULL);
+    }
 }
 
 static BusEntry *
@@ -680,6 +713,7 @@ bus_acquired_cb (GDBusConnection *connection,
         "  <interface name='org.freedesktop.DisplayManager.Session'>"
         "    <property name='Seat' type='o' access='read'/>"
         "    <property name='UserName' type='s' access='read'/>"
+        "    <method name='Lock'/>"
         "  </interface>"
         "</node>";
     GDBusNodeInfo *display_manager_info;
index fe53e2c3a704e82de8b933ccaca4478cf7320eb1..42b92b23906e430563e214af4cfd988a34acda2f 100644 (file)
@@ -429,16 +429,17 @@ display_stopped_cb (Display *display, Seat *seat)
     g_object_unref (display);
 
     check_stopped (seat);
+
 }
 
 static gboolean
-switch_to_user_or_start_greeter (Seat *seat, const gchar *username, gboolean is_guest, const gchar *session_name, gboolean is_lock, gboolean autologin)
+switch_to_user_or_start_greeter (Seat *seat, const gchar *username, gboolean use_existing, gboolean is_guest, const gchar *session_name, gboolean is_lock, gboolean autologin)
 {
     Display *display;
     DisplayServer *display_server;
 
     /* Switch to existing if it exists */
-    if (switch_to_user (seat, username, FALSE))
+    if (use_existing && switch_to_user (seat, username, FALSE))
         return TRUE;
 
     /* If one don't exist then start a greeter */
@@ -510,7 +511,7 @@ seat_switch_to_greeter (Seat *seat)
         return FALSE;
 
     g_debug ("Switching to greeter");
-    return switch_to_user_or_start_greeter (seat, NULL, FALSE, NULL, FALSE, FALSE);
+    return switch_to_user_or_start_greeter (seat, NULL, TRUE, FALSE, NULL, FALSE, FALSE);
 }
 
 gboolean
@@ -523,7 +524,7 @@ seat_switch_to_user (Seat *seat, const gchar *username, const gchar *session_nam
         return FALSE;
 
     g_debug ("Switching to user %s", username);
-    return switch_to_user_or_start_greeter (seat, username, FALSE, session_name, FALSE, FALSE);
+    return switch_to_user_or_start_greeter (seat, username, TRUE, FALSE, session_name, FALSE, FALSE);
 }
 
 gboolean
@@ -538,11 +539,11 @@ seat_switch_to_guest (Seat *seat, const gchar *session_name)
         g_debug ("Switching to existing guest account %s", seat->priv->guest_username);
     else
         g_debug ("Switching to new guest account");
-    return switch_to_user_or_start_greeter (seat, seat->priv->guest_username, TRUE, session_name, FALSE, TRUE);
+    return switch_to_user_or_start_greeter (seat, seat->priv->guest_username, TRUE, TRUE, session_name, FALSE, TRUE);
 }
 
 gboolean
-seat_lock (Seat *seat)
+seat_lock (Seat *seat, const gchar *username)
 {
     g_return_val_if_fail (seat != NULL, FALSE);
 
@@ -550,7 +551,7 @@ seat_lock (Seat *seat)
         return FALSE;
 
     g_debug ("Locking seat");
-    return switch_to_user_or_start_greeter (seat, NULL, FALSE, NULL, TRUE, FALSE);
+    return switch_to_user_or_start_greeter (seat, username, FALSE, FALSE, NULL, TRUE, FALSE);
 }
 
 void
@@ -591,11 +592,11 @@ seat_real_start (Seat *seat)
         autologin_username = NULL;
 
     if (autologin_username)
-        return switch_to_user_or_start_greeter (seat, autologin_username, FALSE, NULL, FALSE, TRUE);
+        return switch_to_user_or_start_greeter (seat, autologin_username, TRUE, FALSE, NULL, FALSE, TRUE);
     else if (seat_get_boolean_property (seat, "autologin-guest"))
-        return switch_to_user_or_start_greeter (seat, NULL, TRUE, NULL, FALSE, TRUE);
+        return switch_to_user_or_start_greeter (seat, NULL, TRUE, TRUE, NULL, FALSE, TRUE);
     else
-        return switch_to_user_or_start_greeter (seat, NULL, FALSE, NULL, FALSE, FALSE);
+        return switch_to_user_or_start_greeter (seat, NULL, TRUE, FALSE, NULL, FALSE, FALSE);
 }
 
 static void
index dadbd0ee9a05d2f931a32d95e2f2035494b0cb41..c525450514746802657a55567639dca8b1c08037 100644 (file)
@@ -83,7 +83,7 @@ gboolean seat_switch_to_user (Seat *seat, const gchar *username, const gchar *se
 
 gboolean seat_switch_to_guest (Seat *seat, const gchar *session_name);
 
-gboolean seat_lock (Seat *seat);
+gboolean seat_lock (Seat *seat, const gchar *username);
 
 void seat_stop (Seat *seat);
 
index 331868cca41cd84eed13e48921636cf313943e7b..4157a826e81fb7282ac2f66f5b26a8e9ff1e3da8 100644 (file)
@@ -67,6 +67,7 @@ TESTS = \
        test-script-hook-fail-greeter-setup \
        test-script-hook-fail-session-setup \
     test-lock-seat \
+    test-lock-session \
        test-switch-to-greeter \
        test-switch-to-guest \
        test-switch-to-user \
@@ -132,6 +133,7 @@ EXTRA_DIST = \
        scripts/language.conf \
        scripts/language-no-accounts-service.conf \
        scripts/lock-seat.conf \
+       scripts/lock-session.conf \
        scripts/login.conf \
        scripts/login-guest.conf \
        scripts/login-guest-disabled.conf \
index 9549d9889ab47a23f9d939c7f46f5dceee500852..a231cca795bbc2fbe6c8b4d81598176034889745 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Use D-Bus interface to show the greeter
+# Check can lock a seat from D-Bus
 #
 
 [LightDM]
@@ -35,8 +35,8 @@ minimum-display-number=50
 #?SESSION :50 CONNECT-XSERVER
 
 # Lock the seat
-#?*LOCK-SEAT
-#?RUNNER LOCK-SEAT
+#?*SESSION :50 LOCK-SEAT
+#?SESSION :50 LOCK-SEAT
 
 # New X server starts
 #?XSERVER :51 START
diff --git a/tests/scripts/lock-session.conf b/tests/scripts/lock-session.conf
new file mode 100644 (file)
index 0000000..2753c57
--- /dev/null
@@ -0,0 +1,64 @@
+#
+# Check can lock a session from D-Bus
+#
+
+[LightDM]
+minimum-display-number=50
+
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER :50 START
+#?XSERVER :50 INDICATE-READY
+
+# LightDM connects to X server
+#?XSERVER :50 ACCEPT-CONNECT
+
+# Greeter starts
+#?GREETER :50 START
+#?XSERVER :50 ACCEPT-CONNECT
+#?GREETER :50 CONNECT-XSERVER
+#?GREETER :50 CONNECT-TO-DAEMON
+#?GREETER :50 CONNECTED-TO-DAEMON
+
+# Login
+#?*GREETER :50 AUTHENTICATE USERNAME=alice
+#?GREETER :50 SHOW-PROMPT TEXT="Password:"
+#?*GREETER :50 RESPOND TEXT="password"
+#?GREETER :50 AUTHENTICATION-COMPLETE USERNAME=alice AUTHENTICATED=TRUE
+#?*GREETER :50 START-SESSION
+#?GREETER :50 TERMINATE SIGNAL=15
+
+# Session starts
+#?SESSION :50 START USER=alice
+#?XSERVER :50 ACCEPT-CONNECT
+#?SESSION :50 CONNECT-XSERVER
+
+# Lock the session
+#?*SESSION :50 LOCK-SESSION
+#?SESSION :50 LOCK-SESSION
+
+# New X server starts
+#?XSERVER :51 START
+#?XSERVER :51 INDICATE-READY
+
+# LightDM connects to X server
+#?XSERVER :51 ACCEPT-CONNECT
+
+# Greeter starts with session user selected
+#?GREETER :51 START
+#?XSERVER :51 ACCEPT-CONNECT
+#?GREETER :51 CONNECT-XSERVER
+#?GREETER :51 CONNECT-TO-DAEMON
+#?GREETER :51 CONNECTED-TO-DAEMON
+#?GREETER :51 SELECT-USER-HINT USERNAME=alice    
+#?GREETER :51 LOCK-HINT
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(SESSION :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15|GREETER :51 TERMINATE SIGNAL=15|XSERVER :51 TERMINATE SIGNAL=15)
+#?(SESSION :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15|GREETER :51 TERMINATE SIGNAL=15|XSERVER :51 TERMINATE SIGNAL=15)
+#?(SESSION :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15|GREETER :51 TERMINATE SIGNAL=15|XSERVER :51 TERMINATE SIGNAL=15)
+#?(SESSION :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15|GREETER :51 TERMINATE SIGNAL=15|XSERVER :51 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0
index 2fa1db7570760d578b4ab1a9d926d6d6be945e1c..354d321d61948292ef4fb0930cad1cdc80b8ede7 100644 (file)
@@ -318,21 +318,6 @@ handle_command (const gchar *command)
     {
         sleep (1);
     }
-    else if (strcmp (name, "LOCK-SEAT") == 0)
-    {
-        g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
-                                     "org.freedesktop.DisplayManager",
-                                     "/org/freedesktop/DisplayManager/Seat0",
-                                     "org.freedesktop.DisplayManager.Seat",
-                                     "Lock",
-                                     g_variant_new ("()"),
-                                     G_VARIANT_TYPE ("()"),
-                                     G_DBUS_CALL_FLAGS_NONE,
-                                     1000,
-                                     NULL,
-                                     NULL);
-        check_status ("RUNNER LOCK-SEAT");
-    }
     else if (strcmp (name, "SWITCH-TO-GREETER") == 0)
     {
         g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
index 97bfe99a319f743121e99a1f4ec9a5456db605af..36dc7f85b566f3c97497328dd4a5e8e771cf4f7f 100644 (file)
@@ -7,6 +7,7 @@
 #include <xcb/xcb.h>
 #include <glib.h>
 #include <glib-object.h>
+#include <gio/gio.h>
 
 #include "status.h"
 
@@ -33,6 +34,42 @@ request_cb (const gchar *request)
     if (strcmp (request, r) == 0)
         kill (getpid (), SIGSEGV);
     g_free (r);
+
+    r = g_strdup_printf ("SESSION %s LOCK-SEAT", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
+                                     "org.freedesktop.DisplayManager",
+                                     getenv ("XDG_SEAT_PATH"),
+                                     "org.freedesktop.DisplayManager.Seat",
+                                     "Lock",
+                                     g_variant_new ("()"),
+                                     G_VARIANT_TYPE ("()"),
+                                     G_DBUS_CALL_FLAGS_NONE,
+                                     1000,
+                                     NULL,
+                                     NULL);
+        status_notify ("SESSION %s LOCK-SEAT", getenv ("DISPLAY"));
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("SESSION %s LOCK-SESSION", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
+                                     "org.freedesktop.DisplayManager",
+                                     getenv ("XDG_SESSION_PATH"),
+                                     "org.freedesktop.DisplayManager.Session",
+                                     "Lock",
+                                     g_variant_new ("()"),
+                                     G_VARIANT_TYPE ("()"),
+                                     G_DBUS_CALL_FLAGS_NONE,
+                                     1000,
+                                     NULL,
+                                     NULL);
+        status_notify ("SESSION %s LOCK-SESSION", getenv ("DISPLAY"));
+    }
+    g_free (r);
 }
 
 int
diff --git a/tests/test-lock-session b/tests/test-lock-session
new file mode 100755 (executable)
index 0000000..30deb7b
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner lock-session test-gobject-greeter