Merge lp:~khadgaray/lightdm/1.2-auologin-uid into lp:lightdm/1.2

Proposed by Ritesh Khadgaray
Status: Needs review
Proposed branch: lp:~khadgaray/lightdm/1.2-auologin-uid
Merge into: lp:lightdm/1.2
Diff against target: 248 lines (+125/-7)
10 files modified
data/lightdm.conf (+1/-1)
src/accounts.c (+18/-0)
src/accounts.h (+2/-0)
src/seat.c (+34/-6)
tests/Makefile.am (+6/-0)
tests/scripts/autologin-uid-invalid.conf (+31/-0)
tests/scripts/autologin-uid.conf (+27/-0)
tests/src/test-runner.c (+2/-0)
tests/test-autologin-uid (+2/-0)
tests/test-autologin-uid-invalid (+2/-0)
To merge this branch: bzr merge lp:~khadgaray/lightdm/1.2-auologin-uid
Reviewer Review Type Date Requested Status
LightDM Development Team Pending
Review via email: mp+198795@code.launchpad.net

Commit message

Add autologin support based off uid.

Description of the change

To post a comment you must log in.
1535. By Ritesh Khadgaray

fix typo

Revision history for this message
Robert Ancell (robert-ancell) wrote :

I am currently opposed to this feature, see bug for more details.

Unmerged revisions

1535. By Ritesh Khadgaray

fix typo

1534. By Ritesh Khadgaray

lightdm cannot autologin based on UID . backport of mterry's branch

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/lightdm.conf'
2--- data/lightdm.conf 2013-06-17 22:43:08 +0000
3+++ data/lightdm.conf 2013-12-12 17:39:31 +0000
4@@ -51,7 +51,7 @@
5 # session-setup-script = Script to run when starting a user session (runs as root)
6 # session-cleanup-script = Script to run when quitting a user session (runs as root)
7 # autologin-guest = True to log in as guest by default
8-# autologin-user = User to log in with by default (overrides autologin-guest)
9+# autologin-user = User to log in with by default (overrides autologin-guest); can also specify uid with uid:XXX
10 # autologin-user-timeout = Number of seconds to wait before loading default user
11 # autologin-session = Session to load for automatic login (overrides user-session)
12 # exit-on-failure = True if the daemon should exit if this seat fails
13
14=== modified file 'src/accounts.c'
15--- src/accounts.c 2013-06-17 23:10:20 +0000
16+++ src/accounts.c 2013-12-12 17:39:31 +0000
17@@ -291,6 +291,24 @@
18 }
19
20 const gchar *
21+accounts_get_name_by_uid (uid_t uid)
22+{
23+ const gchar *name = NULL;
24+
25+ errno = 0;
26+ struct passwd *user_info;
27+
28+ user_info = getpwuid (uid);
29+ if (user_info)
30+ name = user_info->pw_name;
31+
32+ if (!name && errno != 0)
33+ g_warning ("Unable to get information on user %d: %s", uid, strerror (errno));
34+
35+ return name;
36+}
37+
38+const gchar *
39 user_get_name (User *user)
40 {
41 g_return_val_if_fail (user != NULL, NULL);
42
43=== modified file 'src/accounts.h'
44--- src/accounts.h 2011-11-29 04:42:03 +0000
45+++ src/accounts.h 2013-12-12 17:39:31 +0000
46@@ -40,6 +40,8 @@
47
48 User *accounts_get_current_user (void);
49
50+const gchar *accounts_get_name_by_uid (uid_t uid);
51+
52 GType user_get_type (void);
53
54 const gchar *user_get_name (User *user);
55
56=== modified file 'src/seat.c'
57--- src/seat.c 2013-06-17 22:35:03 +0000
58+++ src/seat.c 2013-12-12 17:39:31 +0000
59@@ -9,6 +9,7 @@
60 * license.
61 */
62
63+#include <pwd.h>
64 #include <stdlib.h>
65 #include <string.h>
66 #include <sys/wait.h>
67@@ -583,22 +584,49 @@
68 {
69 }
70
71+static gchar *
72+resolve_username (Seat *seat, const gchar *username)
73+{
74+ const gchar *const uidpfx = "uid:";
75+ const gchar *resolved = NULL;
76+
77+ if (username == NULL || g_strcmp0 (username, "") == 0)
78+ return NULL;
79+
80+ if (g_str_has_prefix (username, uidpfx))
81+ {
82+ const gchar *uidstr = username + strlen (uidpfx);
83+ char *endptr = NULL;
84+ int uid = strtol (uidstr, &endptr, 10);
85+ if (endptr && endptr[0] == 0)
86+ resolved = accounts_get_name_by_uid (uid);
87+ else
88+ g_debug (seat, "UID %s is not a number", uidstr);
89+ }
90+ else
91+ resolved = username;
92+
93+ return g_strdup (resolved);
94+}
95+
96 static gboolean
97 seat_real_start (Seat *seat)
98 {
99- const gchar *autologin_username;
100+ gchar *autologin_username;
101 int autologin_timeout;
102
103 g_debug ("Starting seat");
104
105 /* Start showing a greeter */
106- autologin_username = seat_get_string_property (seat, "autologin-user");
107- if (g_strcmp0 (autologin_username, "") == 0)
108- autologin_username = NULL;
109+ autologin_username = resolve_username (seat, seat_get_string_property (seat, "autologin-user"));
110 autologin_timeout = seat_get_integer_property (seat, "autologin-user-timeout");
111
112- if (autologin_username)
113- return switch_to_user_or_start_greeter (seat, autologin_username, TRUE, FALSE, NULL, FALSE, TRUE, autologin_timeout);
114+ if (autologin_username)
115+ {
116+ int ret = switch_to_user_or_start_greeter (seat, autologin_username, TRUE, FALSE, NULL, FALSE, TRUE, autologin_timeout);
117+ g_free (autologin_username);
118+ return ret;
119+ }
120 else if (seat_get_boolean_property (seat, "autologin-guest"))
121 return switch_to_user_or_start_greeter (seat, NULL, TRUE, TRUE, NULL, FALSE, TRUE, autologin_timeout);
122 else
123
124=== modified file 'tests/Makefile.am'
125--- tests/Makefile.am 2013-11-26 03:18:34 +0000
126+++ tests/Makefile.am 2013-12-12 17:39:31 +0000
127@@ -24,6 +24,8 @@
128 test-autologin-new-authtok \
129 test-autologin-gobject-timeout \
130 test-autologin-gobject-guest-timeout \
131+ test-autologin-uid \
132+ test-autologin-uid-invalid \
133 test-pam \
134 test-login-pam \
135 test-denied \
136@@ -172,6 +174,8 @@
137 test-login-qt-guest-logout
138 endif
139
140+TESTS =
141+
142 EXTRA_DIST = \
143 $(TESTS) \
144 data/system.conf \
145@@ -201,6 +205,8 @@
146 scripts/autologin-session-crash.conf \
147 scripts/autologin-session-error.conf \
148 scripts/autologin-timeout.conf \
149+ scripts/test-autologin-uid.conf \
150+ scripts/test-autologin-uid-invalid.conf \
151 scripts/autologin-xserver-crash.conf \
152 scripts/console-kit.conf \
153 scripts/corrupt-xauthority.conf \
154
155=== added file 'tests/scripts/autologin-uid-invalid.conf'
156--- tests/scripts/autologin-uid-invalid.conf 1970-01-01 00:00:00 +0000
157+++ tests/scripts/autologin-uid-invalid.conf 2013-12-12 17:39:31 +0000
158@@ -0,0 +1,31 @@
159+#
160+# Check fails to autologin invalid user by uid
161+#
162+
163+[SeatDefaults]
164+autologin-user=uid:9999
165+
166+#?RUNNER DAEMON-START
167+
168+# (fails to start session for invalid user)
169+
170+# X server starts
171+#?XSERVER-0 START VT=7
172+
173+# Daemon connects when X server is ready
174+#?*XSERVER-0 INDICATE-READY
175+#?XSERVER-0 INDICATE-READY
176+#?XSERVER-0 ACCEPT-CONNECT
177+
178+# Greeter starts
179+#?GREETER-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_SESSION_CLASS=greeter
180+#?XSERVER-0 ACCEPT-CONNECT
181+#?GREETER-X-0 CONNECT-XSERVER
182+#?GREETER-X-0 CONNECT-TO-DAEMON
183+#?GREETER-X-0 CONNECTED-TO-DAEMON
184+
185+# Cleanup
186+#?*STOP-DAEMON
187+#?GREETER-X-0 TERMINATE SIGNAL=15
188+#?XSERVER-0 TERMINATE SIGNAL=15
189+#?RUNNER DAEMON-EXIT STATUS=0
190
191=== added file 'tests/scripts/autologin-uid.conf'
192--- tests/scripts/autologin-uid.conf 1970-01-01 00:00:00 +0000
193+++ tests/scripts/autologin-uid.conf 2013-12-12 17:39:31 +0000
194@@ -0,0 +1,27 @@
195+#
196+# Check automatically logs in default user by uid
197+#
198+
199+[SeatDefaults]
200+autologin-user=uid:1000
201+
202+#?RUNNER DAEMON-START
203+
204+# X server starts
205+#?XSERVER-0 START VT=7
206+
207+# Daemon connects when X server is ready
208+#?*XSERVER-0 INDICATE-READY
209+#?XSERVER-0 INDICATE-READY
210+#?XSERVER-0 ACCEPT-CONNECT
211+
212+# Session starts
213+#?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 DESKTOP_SESSION=default USER=have-password1
214+#?XSERVER-0 ACCEPT-CONNECT
215+#?SESSION-X-0 CONNECT-XSERVER
216+
217+# Cleanup
218+#?*STOP-DAEMON
219+#?SESSION-X-0 TERMINATE SIGNAL=15
220+#?XSERVER-0 TERMINATE SIGNAL=15
221+#?RUNNER DAEMON-EXIT STATUS=0
222
223=== modified file 'tests/src/test-runner.c'
224--- tests/src/test-runner.c 2013-11-26 03:18:34 +0000
225+++ tests/src/test-runner.c 2013-12-12 17:39:31 +0000
226@@ -2067,6 +2067,8 @@
227 {"multi-prompt", "password", TRUE, "Multi Prompt", NULL, NULL, NULL, NULL, 1031},
228 /* This account has an existing corrupt X authority */
229 {"corrupt-xauth", "password", TRUE, "Corrupt Xauthority", NULL, NULL, NULL, NULL, 1032},
230+ /* 9999 is reserved as not present */
231+ /* {"", "", "", 9999}, */
232 {NULL, NULL, FALSE, NULL, NULL, NULL, NULL, NULL, 0}
233 };
234 passwd_data = g_string_new ("");
235
236=== added file 'tests/test-autologin-uid'
237--- tests/test-autologin-uid 1970-01-01 00:00:00 +0000
238+++ tests/test-autologin-uid 2013-12-12 17:39:31 +0000
239@@ -0,0 +1,2 @@
240+#!/bin/sh
241+./src/dbus-env ./src/test-runner autologin-uid test-gobject-greeter
242
243=== added file 'tests/test-autologin-uid-invalid'
244--- tests/test-autologin-uid-invalid 1970-01-01 00:00:00 +0000
245+++ tests/test-autologin-uid-invalid 2013-12-12 17:39:31 +0000
246@@ -0,0 +1,2 @@
247+#!/bin/sh
248+./src/dbus-env ./src/test-runner autologin-uid-invalid test-gobject-greeter

Subscribers

People subscribed via source and target branches