diff options
author | Robert Ancell <robert.ancell@canonical.com> | 2011-07-15 23:22:14 +1000 |
---|---|---|
committer | Robert Ancell <robert.ancell@canonical.com> | 2011-07-15 23:22:14 +1000 |
commit | 0d013ee96f81996b5937759d29ab298317018528 (patch) | |
tree | 1c6dac2fd819210dd18392ef39d35958a6bb0324 | |
parent | 41e45603abc32860aecdd357fc3be937c6953cf3 (diff) | |
download | lightdm-0d013ee96f81996b5937759d29ab298317018528.tar.gz |
Fix autologin
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | src/display-manager.c | 11 | ||||
-rw-r--r-- | src/display-manager.xml | 2 | ||||
-rw-r--r-- | src/display.c | 5 | ||||
-rw-r--r-- | src/lightdm.c | 4 | ||||
-rw-r--r-- | src/seat-local.c | 22 | ||||
-rw-r--r-- | src/seat.c | 113 | ||||
-rw-r--r-- | src/seat.h | 9 | ||||
-rw-r--r-- | src/vt.c | 3 | ||||
-rw-r--r-- | tests/Makefile.am | 6 | ||||
-rw-r--r-- | tests/scripts/switch-to-greeter.conf (renamed from tests/scripts/show-greeter.conf) | 0 | ||||
-rw-r--r-- | tests/scripts/switch-to-greeter.script (renamed from tests/scripts/show-greeter.script) | 4 | ||||
-rw-r--r-- | tests/src/test-runner.c | 6 | ||||
-rwxr-xr-x | tests/test-show-greeter | 2 | ||||
-rwxr-xr-x | tests/test-switch-to-greeter | 2 |
15 files changed, 134 insertions, 57 deletions
@@ -3,6 +3,8 @@ Overview of changes in lightdm 0.4.5 * Fix invalid XAUTHORITY variable being set for second X server. * Fix bug where switching users created X servers without VTs * Release a VT when the X server on it stops + * D-Bus API changes: + - Rename ShowGreeter() to SwitchToGreeter() Overview of changes in lightdm 0.4.4 diff --git a/src/display-manager.c b/src/display-manager.c index e5225019..d5310d81 100644 --- a/src/display-manager.c +++ b/src/display-manager.c @@ -60,12 +60,15 @@ add_seat (DisplayManager *manager, Seat *seat) { gboolean result; - manager->priv->seats = g_list_append (manager->priv->seats, seat); + manager->priv->seats = g_list_append (manager->priv->seats, g_object_ref (seat)); result = seat_start (SEAT (seat)); if (!result) + { manager->priv->seats = g_list_remove (manager->priv->seats, seat); - + g_object_unref (seat); + } + return result; } @@ -77,8 +80,7 @@ xdmcp_session_cb (XDMCPServer *server, XDMCPSession *session, DisplayManager *ma seat = seat_xdmcp_session_new (session); result = add_seat (manager, SEAT (seat)); - if (!result) - g_object_unref (seat); + g_object_unref (seat); return result; } @@ -113,6 +115,7 @@ display_manager_start (DisplayManager *manager) if (!add_seat (manager, SEAT (seat))) g_warning ("Failed to start seat %s", seat_name); + g_object_unref (seat); } g_strfreev (tokens); diff --git a/src/display-manager.xml b/src/display-manager.xml index 004eca1f..b1131f75 100644 --- a/src/display-manager.xml +++ b/src/display-manager.xml @@ -3,7 +3,7 @@ <interface name="org.freedesktop.DisplayManager"> <!-- Show greeter to allow new login / switch users --> - <method name="ShowGreeter"/> + <method name="SwitchToGreeter"/> <!-- Switch to a user, starting a new display if required --> <method name="SwitchToUser"> diff --git a/src/display.c b/src/display.c index 04c7d51d..5a039956 100644 --- a/src/display.c +++ b/src/display.c @@ -598,7 +598,7 @@ start_user_session (Display *display, const gchar *session) // FIXME: Copy old error file log_filename = g_build_filename (user_get_home_directory (user), ".xsession-errors", NULL); g_debug ("Logging to %s", log_filename); - child_process_set_log_file (CHILD_PROCESS (session), log_filename); + child_process_set_log_file (CHILD_PROCESS (display->priv->user_session), log_filename); g_free (log_filename); /* Connect using the session bus */ @@ -711,9 +711,10 @@ greeter_start_session_cb (Greeter *greeter, const gchar *session, gboolean is_gu return; } + /* Stop this display if can switch to that user */ if (activate_user (display, pam_session_get_username (display->priv->user_pam_session))) { - display_stop (display); + display_stop (display); return; } diff --git a/src/lightdm.c b/src/lightdm.c index 8c20f50d..50fca3af 100644 --- a/src/lightdm.c +++ b/src/lightdm.c @@ -129,7 +129,7 @@ handle_display_manager_call (GDBusConnection *connection, GDBusMethodInvocation *invocation, gpointer user_data) { - if (g_strcmp0 (method_name, "ShowGreeter") == 0) + if (g_strcmp0 (method_name, "SwitchToGreeter") == 0) { if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()"))) return; @@ -183,7 +183,7 @@ bus_acquired_cb (GDBusConnection *connection, "<node>" " <interface name='org.freedesktop.DisplayManager'>" " <property name='ConfigFile' type='s' access='read'/>" - " <method name='ShowGreeter'/>" + " <method name='SwitchToGreeter'/>" " <method name='SwitchToUser'>" " <arg name='username' direction='in' type='s'/>" " </method>" diff --git a/src/seat-local.c b/src/seat-local.c index 2e40bb4b..0d84b0d4 100644 --- a/src/seat-local.c +++ b/src/seat-local.c @@ -28,17 +28,21 @@ SeatLocal * seat_local_new (const gchar *config_section) { SeatLocal *seat; + gchar *username; + guint timeout; seat = g_object_new (SEAT_LOCAL_TYPE, NULL); seat->priv->config_section = g_strdup (config_section); - return seat; -} + seat_set_can_switch (SEAT (seat), TRUE); + username = config_get_string (config_get_instance (), config_section, "default-user"); + timeout = config_get_integer (config_get_instance (), config_section, "default-user-timeout"); + if (timeout < 0) + timeout = 0; + if (username) + seat_set_autologin_user (SEAT (seat), username, timeout); -static gboolean -seat_local_get_can_switch (Seat *seat) -{ - return TRUE; + return seat; } static Display * @@ -46,12 +50,13 @@ seat_local_add_display (Seat *seat) { XServer *xserver; XAuthorization *authorization = NULL; - gchar *dir, *filename, *path, *command, *xserver_section = NULL; + gchar *xserver_section = NULL; + gchar *command, *dir, *filename, *path; gchar *number; gchar hostname[1024]; Display *display; - g_debug ("Starting new display to switch user"); + g_debug ("Starting display"); xserver = xserver_new (XSERVER_TYPE_LOCAL, NULL, xserver_get_free_display_number ()); number = g_strdup_printf ("%d", xserver_get_display_number (xserver)); @@ -148,7 +153,6 @@ seat_local_class_init (SeatLocalClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); SeatClass *seat_class = SEAT_CLASS (klass); - seat_class->get_can_switch = seat_local_get_can_switch; seat_class->add_display = seat_local_add_display; seat_class->set_active_display = seat_local_set_active_display; object_class->finalize = seat_local_finalize; @@ -27,6 +27,14 @@ static guint signals[LAST_SIGNAL] = { 0 }; struct SeatPrivate { + /* True if able to switch users */ + gboolean can_switch; + + /* User to automatically log in as */ + gchar *autologin_username; + gboolean autologin_guest; + guint autologin_timeout; + /* The displays for this seat */ GList *displays; @@ -36,6 +44,36 @@ struct SeatPrivate G_DEFINE_TYPE (Seat, seat, G_TYPE_OBJECT); +void +seat_set_can_switch (Seat *seat, gboolean can_switch) +{ + g_return_if_fail (seat != NULL); + + seat->priv->can_switch = can_switch; +} + +void +seat_set_autologin_user (Seat *seat, const gchar *username, guint timeout) +{ + g_return_if_fail (seat != NULL); + + g_free (seat->priv->autologin_username); + seat->priv->autologin_username = g_strdup (username); + seat->priv->autologin_timeout = timeout; + seat->priv->autologin_guest = FALSE; +} + +void +seat_set_autologin_guest (Seat *seat, guint timeout) +{ + g_return_if_fail (seat != NULL); + + g_free (seat->priv->autologin_username); + seat->priv->autologin_username = NULL; + seat->priv->autologin_timeout = timeout; + seat->priv->autologin_guest = TRUE; +} + gboolean seat_start (Seat *seat) { @@ -50,25 +88,37 @@ seat_get_displays (Seat *seat) return seat->priv->displays; } -void -seat_remove_display (Seat *seat, Display *display) -{ - g_return_if_fail (seat != NULL); - g_return_if_fail (display != NULL); - seat->priv->displays = g_list_remove (seat->priv->displays, display); -} - gboolean seat_get_can_switch (Seat *seat) { g_return_val_if_fail (seat != NULL, FALSE); - return SEAT_GET_CLASS (seat)->get_can_switch (seat); + return seat->priv->can_switch; } static gboolean display_activate_user_cb (Display *display, const gchar *username, Seat *seat) { - return seat_switch_to_user (seat, username); + GList *link; + + /* Switch to active display if it exists */ + for (link = seat->priv->displays; link; link = link->next) + { + Display *d = link->data; + + if (d == display) + continue; + + /* If already logged in, then switch to that display and stop the greeter display */ + if (g_strcmp0 (display_get_session_user (d), username) == 0) + { + g_debug ("Switching to user %s session on display %s", username, xserver_get_address (display_get_xserver (display))); + SEAT_GET_CLASS (seat)->set_active_display (seat, display); + return TRUE; + } + } + + /* Otherwise start on this display */ + return FALSE; } static gboolean @@ -91,6 +141,19 @@ display_stopped_cb (Display *display, Seat *seat) check_stopped (seat); } +static Display * +add_display (Seat *seat) +{ + Display *display; + + display = SEAT_GET_CLASS (seat)->add_display (seat); + g_signal_connect (display, "activate-user", G_CALLBACK (display_activate_user_cb), seat); + g_signal_connect (display, "stopped", G_CALLBACK (display_stopped_cb), seat); + seat->priv->displays = g_list_append (seat->priv->displays, display); + + return display; +} + static gboolean switch_to_user (Seat *seat, const gchar *username, gboolean is_guest) { @@ -118,11 +181,7 @@ switch_to_user (Seat *seat, const gchar *username, gboolean is_guest) } } - display = SEAT_GET_CLASS (seat)->add_display (seat); - g_signal_connect (display, "activate-user", G_CALLBACK (display_activate_user_cb), seat); - g_signal_connect (display, "stopped", G_CALLBACK (display_stopped_cb), seat); - seat->priv->displays = g_list_append (seat->priv->displays, display); - + display = add_display (seat); if (is_guest) display_set_default_user (display, NULL, TRUE, FALSE, 0); else if (username) @@ -135,8 +194,8 @@ gboolean seat_switch_to_greeter (Seat *seat) { g_return_val_if_fail (seat != NULL, FALSE); - - if (!seat_get_can_switch (seat)) + + if (!seat->priv->can_switch) return FALSE; g_debug ("Showing greeter"); @@ -150,7 +209,7 @@ seat_switch_to_user (Seat *seat, const gchar *username) g_return_val_if_fail (seat != NULL, FALSE); g_return_val_if_fail (username != NULL, FALSE); - if (!seat_get_can_switch (seat)) + if (!seat->priv->can_switch) return FALSE; g_debug ("Switching to user %s", username); @@ -162,7 +221,7 @@ seat_switch_to_guest (Seat *seat) { g_return_val_if_fail (seat != NULL, FALSE); - if (!seat_get_can_switch (seat)) + if (!seat->priv->can_switch) return FALSE; if (!guest_account_get_is_enabled ()) @@ -185,13 +244,16 @@ seat_stop (Seat *seat) static gboolean seat_real_start (Seat *seat) { - return seat_switch_to_greeter (seat); -} + Display *display; -static gboolean -seat_real_get_can_switch (Seat *seat) -{ - return FALSE; + display = add_display (seat); + + if (seat->priv->autologin_username) + display_set_default_user (display, seat->priv->autologin_username, FALSE, FALSE, seat->priv->autologin_timeout); + else if (seat->priv->autologin_guest) + display_set_default_user (display, NULL, TRUE, FALSE, seat->priv->autologin_timeout); + + return display_start (display); } static Display * @@ -247,7 +309,6 @@ seat_class_init (SeatClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); klass->start = seat_real_start; - klass->get_can_switch = seat_real_get_can_switch; klass->add_display = seat_real_add_display; klass->set_active_display = seat_real_set_active_display; klass->stop = seat_real_stop; @@ -35,7 +35,6 @@ typedef struct GObjectClass parent_class; gboolean (*start)(Seat *seat); - gboolean (*get_can_switch)(Seat *seat); // FIXME: Make a construct property Display *(*add_display)(Seat *seat); void (*set_active_display)(Seat *seat, Display *display); void (*stop)(Seat *seat); @@ -46,12 +45,16 @@ typedef struct GType seat_get_type (void); +void seat_set_can_switch (Seat *seat, gboolean can_switch); + +void seat_set_autologin_user (Seat *seat, const gchar *username, guint timeout); + +void seat_set_autologin_guest (Seat *seat, guint timeout); + gboolean seat_start (Seat *seat); GList *seat_get_displays (Seat *seat); -void seat_remove_display (Seat *seat, Display *display); - gboolean seat_get_can_switch (Seat *seat); gboolean seat_switch_to_greeter (Seat *seat); @@ -114,6 +114,9 @@ vt_get_unused (void) { gint number; + if (getuid () != 0) + return -1; + number = vt_get_min (); while (vt_is_used (number)) number++; diff --git a/tests/Makefile.am b/tests/Makefile.am index b24304b7..54ea603b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,7 +3,7 @@ SUBDIRS = src TESTS = \ test-no-config \ test-headless \ - test-show-greeter \ + test-switch-to-greeter \ test-switch-to-guest \ test-switch-to-user \ test-autologin \ @@ -65,8 +65,8 @@ EXTRA_DIST = \ scripts/login-gobject-xserver-crash.conf \ scripts/login-gobject-xserver-crash.script \ scripts/no-config.script \ - scripts/show-greeter.conf \ - scripts/show-greeter.script \ + scripts/switch-to-greeter.conf \ + scripts/switch-to-greeter.script \ scripts/switch-to-guest.conf \ scripts/switch-to-guest.script \ scripts/switch-to-user.conf \ diff --git a/tests/scripts/show-greeter.conf b/tests/scripts/switch-to-greeter.conf index e232614d..e232614d 100644 --- a/tests/scripts/show-greeter.conf +++ b/tests/scripts/switch-to-greeter.conf diff --git a/tests/scripts/show-greeter.script b/tests/scripts/switch-to-greeter.script index 986e9425..4fe6424b 100644 --- a/tests/scripts/show-greeter.script +++ b/tests/scripts/switch-to-greeter.script @@ -29,8 +29,8 @@ XSERVER :50 ACCEPT-CONNECT SESSION CONNECT-XSERVER # Show the greeter -*SHOW-GREETER -RUNNER SHOW-GREETER +*SWITCH-TO-GREETER +RUNNER SWITCH-TO-GREETER # New X server starts XSERVER :51 START diff --git a/tests/src/test-runner.c b/tests/src/test-runner.c index d2f1400b..e107e0c5 100644 --- a/tests/src/test-runner.c +++ b/tests/src/test-runner.c @@ -220,20 +220,20 @@ run_commands () { sleep (1); } - else if (strcmp (name, "SHOW-GREETER") == 0) + else if (strcmp (name, "SWITCH-TO-GREETER") == 0) { g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL), "org.freedesktop.DisplayManager", "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", - "ShowGreeter", + "SwitchToGreeter", g_variant_new ("()"), G_VARIANT_TYPE ("()"), G_DBUS_CALL_FLAGS_NONE, 1000, NULL, NULL); - check_status ("RUNNER SHOW-GREETER"); + check_status ("RUNNER SWITCH-TO-GREETER"); } else if (strcmp (name, "SWITCH-TO-USER") == 0) { diff --git a/tests/test-show-greeter b/tests/test-show-greeter deleted file mode 100755 index b90cc140..00000000 --- a/tests/test-show-greeter +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -./src/test-runner show-greeter diff --git a/tests/test-switch-to-greeter b/tests/test-switch-to-greeter new file mode 100755 index 00000000..4106c304 --- /dev/null +++ b/tests/test-switch-to-greeter @@ -0,0 +1,2 @@ +#!/bin/sh +./src/test-runner switch-to-greeter |