Merge lp:~robert-ancell/lightdm/wtmp into lp:lightdm

Proposed by Robert Ancell
Status: Merged
Approved by: Robert Ancell
Approved revision: 1921
Merged at revision: 1921
Proposed branch: lp:~robert-ancell/lightdm/wtmp
Merge into: lp:lightdm
Diff against target: 441 lines (+258/-37)
9 files modified
src/session-child.c (+56/-0)
tests/Makefile.am (+6/-2)
tests/scripts/utmp-autologin.conf (+5/-3)
tests/scripts/utmp-login.conf (+75/-0)
tests/scripts/utmp-wrong-password.conf (+38/-0)
tests/src/libsystem.c (+73/-31)
tests/test-utmp-autologin (+1/-1)
tests/test-utmp-login (+2/-0)
tests/test-utmp-wrong-password (+2/-0)
To merge this branch: bzr merge lp:~robert-ancell/lightdm/wtmp
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Robert Ancell Approve
Review via email: mp+210317@code.launchpad.net

Commit message

Log to wtmp and btmp

To post a comment you must log in.
Revision history for this message
Robert Ancell (robert-ancell) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/session-child.c'
2--- src/session-child.c 2014-03-10 04:20:54 +0000
3+++ src/session-child.c 2014-03-10 23:47:02 +0000
4@@ -13,6 +13,7 @@
5 #include <grp.h>
6 #include <glib.h>
7 #include <security/pam_appl.h>
8+#include <utmp.h>
9 #include <utmpx.h>
10 #include <sys/mman.h>
11
12@@ -196,6 +197,29 @@
13 return x_authority_new (x_authority_family, x_authority_address, x_authority_address_length, x_authority_number, x_authority_name, x_authority_data, x_authority_data_length);
14 }
15
16+/* GNU provides this but we can't rely on that so let's make our own version */
17+static void
18+updwtmpx (const gchar *wtmp_file, struct utmpx *ut)
19+{
20+ struct utmp u;
21+
22+ memset (&u, 0, sizeof (u));
23+ u.ut_type = ut->ut_type;
24+ u.ut_pid = ut->ut_pid;
25+ if (ut->ut_line)
26+ strncpy (u.ut_line, ut->ut_line, sizeof (u.ut_line));
27+ if (ut->ut_id)
28+ strncpy (u.ut_id, ut->ut_id, sizeof (u.ut_id));
29+ if (ut->ut_user)
30+ strncpy (u.ut_user, ut->ut_user, sizeof (u.ut_user));
31+ if (ut->ut_host)
32+ strncpy (u.ut_host, ut->ut_host, sizeof (u.ut_host));
33+ u.ut_tv.tv_sec = ut->ut_tv.tv_sec;
34+ u.ut_tv.tv_usec = ut->ut_tv.tv_usec;
35+
36+ updwtmp (wtmp_file, &u);
37+}
38+
39 int
40 session_child_run (int argc, char **argv)
41 {
42@@ -333,6 +357,34 @@
43 g_free (username);
44 username = g_strdup (new_username);
45
46+ /* Write record to btmp database */
47+ if (authentication_result == PAM_AUTH_ERR)
48+ {
49+ struct utmpx ut;
50+ struct timeval tv;
51+
52+ memset (&ut, 0, sizeof (ut));
53+ ut.ut_type = USER_PROCESS;
54+ ut.ut_pid = getpid ();
55+ if (xdisplay)
56+ {
57+ strncpy (ut.ut_line, xdisplay, sizeof (ut.ut_line));
58+ strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id));
59+ }
60+ else if (tty)
61+ strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line));
62+ strncpy (ut.ut_user, username, sizeof (ut.ut_user));
63+ if (xdisplay)
64+ strncpy (ut.ut_host, xdisplay, sizeof (ut.ut_host));
65+ else if (remote_host_name)
66+ strncpy (ut.ut_host, remote_host_name, sizeof (ut.ut_host));
67+ gettimeofday (&tv, NULL);
68+ ut.ut_tv.tv_sec = tv.tv_sec;
69+ ut.ut_tv.tv_usec = tv.tv_usec;
70+
71+ updwtmpx ("/var/log/btmp", &ut);
72+ }
73+
74 /* Check account is valid */
75 if (authentication_result == PAM_SUCCESS)
76 authentication_result = pam_acct_mgmt (pam_handle, 0);
77@@ -617,10 +669,12 @@
78 ut.ut_tv.tv_sec = tv.tv_sec;
79 ut.ut_tv.tv_usec = tv.tv_usec;
80
81+ /* Write records to utmp/wtmp databases */
82 setutxent ();
83 if (!pututxline (&ut))
84 g_printerr ("Failed to write utmpx: %s\n", strerror (errno));
85 endutxent ();
86+ updwtmpx ("/var/log/wtmp", &ut);
87 }
88
89 waitpid (child_pid, &return_code, 0);
90@@ -651,10 +705,12 @@
91 ut.ut_tv.tv_sec = tv.tv_sec;
92 ut.ut_tv.tv_usec = tv.tv_usec;
93
94+ /* Write records to utmp/wtmp databases */
95 setutxent ();
96 if (!pututxline (&ut))
97 g_printerr ("Failed to write utmpx: %s\n", strerror (errno));
98 endutxent ();
99+ updwtmpx ("/var/log/wtmp", &ut);
100 }
101 }
102
103
104=== modified file 'tests/Makefile.am'
105--- tests/Makefile.am 2014-03-10 04:20:54 +0000
106+++ tests/Makefile.am 2014-03-10 23:47:02 +0000
107@@ -144,7 +144,9 @@
108 test-vnc-open-file-descriptors \
109 test-xdmcp-client \
110 test-xdmcp-server-login \
111- test-utmp \
112+ test-utmp-login \
113+ test-utmp-autologin \
114+ test-utmp-wrong-password \
115 test-no-accounts-service \
116 test-console-kit \
117 test-no-console-kit \
118@@ -476,7 +478,9 @@
119 scripts/user-renamed.conf \
120 scripts/user-renamed-invalid.conf \
121 scripts/user-session.conf \
122- scripts/utmp.conf \
123+ scripts/utmp-autologin.conf \
124+ scripts/utmp-login.conf \
125+ scripts/utmp-wrong-password.conf \
126 scripts/vnc-command.conf \
127 scripts/vnc-dimensions.conf \
128 scripts/vnc-login.conf \
129
130=== renamed file 'tests/scripts/utmp.conf' => 'tests/scripts/utmp-autologin.conf'
131--- tests/scripts/utmp.conf 2014-03-10 04:28:41 +0000
132+++ tests/scripts/utmp-autologin.conf 2014-03-10 23:47:02 +0000
133@@ -1,5 +1,5 @@
134 #
135-# Check UTMP records written on login
136+# Check UTMP records written on autologin
137 #
138
139 [test-utmp-config]
140@@ -20,8 +20,9 @@
141 #?XSERVER-0 INDICATE-READY
142 #?XSERVER-0 ACCEPT-CONNECT
143
144-# UTMP record written
145+# UTMP/WTMP record written
146 #?UTMP TYPE=USER_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0
147+#?WTMP FILE=.*/wtmp TYPE=USER_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0
148
149 # Autologin session starts
150 #?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_GREETER_DATA_DIR=.*/have-password1 DESKTOP_SESSION=default USER=have-password1
151@@ -31,8 +32,9 @@
152 # Logout session
153 #?*SESSION-X-0 LOGOUT
154
155-# UTMP record written
156+# UTMP/WTMP record written
157 #?UTMP TYPE=DEAD_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0
158+#?WTMP FILE=.*/wtmp TYPE=DEAD_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0
159
160 # X server stops
161 #?XSERVER-0 TERMINATE SIGNAL=15
162
163=== added file 'tests/scripts/utmp-login.conf'
164--- tests/scripts/utmp-login.conf 1970-01-01 00:00:00 +0000
165+++ tests/scripts/utmp-login.conf 2014-03-10 23:47:02 +0000
166@@ -0,0 +1,75 @@
167+#
168+# Check UTMP records written on login
169+#
170+
171+[test-utmp-config]
172+check-events=true
173+
174+[SeatDefaults]
175+user-session=default
176+
177+#?*START-DAEMON
178+#?RUNNER DAEMON-START
179+
180+# X server starts
181+#?XSERVER-0 START VT=7 SEAT=seat0
182+
183+# Daemon connects when X server is ready
184+#?*XSERVER-0 INDICATE-READY
185+#?XSERVER-0 INDICATE-READY
186+#?XSERVER-0 ACCEPT-CONNECT
187+
188+# Greeter starts
189+#?GREETER-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_SESSION_CLASS=greeter
190+#?XSERVER-0 ACCEPT-CONNECT
191+#?GREETER-X-0 CONNECT-XSERVER
192+#?GREETER-X-0 CONNECT-TO-DAEMON
193+#?GREETER-X-0 CONNECTED-TO-DAEMON
194+
195+# Log into account with a password
196+#?*GREETER-X-0 AUTHENTICATE USERNAME=have-password1
197+#?GREETER-X-0 SHOW-PROMPT TEXT="Password:"
198+#?*GREETER-X-0 RESPOND TEXT="password"
199+#?GREETER-X-0 AUTHENTICATION-COMPLETE USERNAME=have-password1 AUTHENTICATED=TRUE
200+#?*GREETER-X-0 START-SESSION
201+#?GREETER-X-0 TERMINATE SIGNAL=15
202+
203+# UTMP/WTMP record written
204+#?UTMP TYPE=USER_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0
205+#?WTMP FILE=.*/wtmp TYPE=USER_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0
206+
207+# Session starts
208+#?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_GREETER_DATA_DIR=.*/have-password1 DESKTOP_SESSION=default USER=have-password1
209+#?XSERVER-0 ACCEPT-CONNECT
210+#?SESSION-X-0 CONNECT-XSERVER
211+
212+# Logout session
213+#?*SESSION-X-0 LOGOUT
214+
215+# UTMP/WTMP record written
216+#?UTMP TYPE=DEAD_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0
217+#?WTMP FILE=.*/wtmp TYPE=DEAD_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0
218+
219+# X server stops
220+#?XSERVER-0 TERMINATE SIGNAL=15
221+
222+# X server starts
223+#?XSERVER-0 START VT=7 SEAT=seat0
224+
225+# Daemon connects when X server is ready
226+#?*XSERVER-0 INDICATE-READY
227+#?XSERVER-0 INDICATE-READY
228+#?XSERVER-0 ACCEPT-CONNECT
229+
230+# Greeter starts
231+#?GREETER-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_SESSION_CLASS=greeter
232+#?XSERVER-0 ACCEPT-CONNECT
233+#?GREETER-X-0 CONNECT-XSERVER
234+#?GREETER-X-0 CONNECT-TO-DAEMON
235+#?GREETER-X-0 CONNECTED-TO-DAEMON
236+
237+# Cleanup
238+#?*STOP-DAEMON
239+#?GREETER-X-0 TERMINATE SIGNAL=15
240+#?XSERVER-0 TERMINATE SIGNAL=15
241+#?RUNNER DAEMON-EXIT STATUS=0
242
243=== added file 'tests/scripts/utmp-wrong-password.conf'
244--- tests/scripts/utmp-wrong-password.conf 1970-01-01 00:00:00 +0000
245+++ tests/scripts/utmp-wrong-password.conf 2014-03-10 23:47:02 +0000
246@@ -0,0 +1,38 @@
247+#
248+# Check BTMP records written on failed login
249+#
250+
251+[test-utmp-config]
252+check-events=true
253+
254+#?*START-DAEMON
255+#?RUNNER DAEMON-START
256+
257+# X server starts
258+#?XSERVER-0 START VT=7 SEAT=seat0
259+
260+# Daemon connects when X server is ready
261+#?*XSERVER-0 INDICATE-READY
262+#?XSERVER-0 INDICATE-READY
263+#?XSERVER-0 ACCEPT-CONNECT
264+
265+# Greeter starts
266+#?GREETER-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_SESSION_CLASS=greeter
267+#?XSERVER-0 ACCEPT-CONNECT
268+#?GREETER-X-0 CONNECT-XSERVER
269+#?GREETER-X-0 CONNECT-TO-DAEMON
270+#?GREETER-X-0 CONNECTED-TO-DAEMON
271+
272+# Login with invalid password
273+#?*GREETER-X-0 AUTHENTICATE USERNAME=have-password1
274+#?GREETER-X-0 SHOW-PROMPT TEXT="Password:"
275+#?*GREETER-X-0 RESPOND TEXT="rubbish"
276+#?WTMP FILE=.*/btmp TYPE=USER_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0
277+#?GREETER-X-0 AUTHENTICATION-COMPLETE USERNAME=have-password1 AUTHENTICATED=FALSE
278+
279+# Cleanup
280+#?*STOP-DAEMON
281+#?GREETER-X-0 TERMINATE SIGNAL=15
282+#?XSERVER-0 TERMINATE SIGNAL=15
283+#?RUNNER DAEMON-EXIT STATUS=0
284+
285
286=== modified file 'tests/src/libsystem.c'
287--- tests/src/libsystem.c 2014-03-10 04:20:54 +0000
288+++ tests/src/libsystem.c 2014-03-10 23:47:02 +0000
289@@ -15,6 +15,7 @@
290 #include <security/pam_appl.h>
291 #include <fcntl.h>
292 #include <dlfcn.h>
293+#include <utmp.h>
294 #include <utmpx.h>
295 #ifdef __linux__
296 #include <linux/vt.h>
297@@ -1442,43 +1443,44 @@
298 setutxent (void)
299 {
300 }
301-
302+
303 struct utmpx *
304 pututxline (const struct utmpx *ut)
305 {
306- GString *status;
307-
308- status = g_string_new ("UTMP");
309- switch (ut->ut_type)
310- {
311- case INIT_PROCESS:
312- g_string_append_printf (status, " TYPE=INIT_PROCESS");
313- break;
314- case LOGIN_PROCESS:
315- g_string_append_printf (status, " TYPE=LOGIN_PROCESS");
316- break;
317- case USER_PROCESS:
318- g_string_append_printf (status, " TYPE=USER_PROCESS");
319- break;
320- case DEAD_PROCESS:
321- g_string_append_printf (status, " TYPE=DEAD_PROCESS");
322- break;
323- default:
324- g_string_append_printf (status, " TYPE=%d", ut->ut_type);
325- }
326- if (ut->ut_line)
327- g_string_append_printf (status, " LINE=%s", ut->ut_line);
328- if (ut->ut_id)
329- g_string_append_printf (status, " ID=%s", ut->ut_id);
330- if (ut->ut_user)
331- g_string_append_printf (status, " USER=%s", ut->ut_user);
332- if (ut->ut_host)
333- g_string_append_printf (status, " HOST=%s", ut->ut_host);
334-
335 connect_status ();
336 if (g_key_file_get_boolean (config, "test-utmp-config", "check-events", NULL))
337+ {
338+ GString *status;
339+
340+ status = g_string_new ("UTMP");
341+ switch (ut->ut_type)
342+ {
343+ case INIT_PROCESS:
344+ g_string_append_printf (status, " TYPE=INIT_PROCESS");
345+ break;
346+ case LOGIN_PROCESS:
347+ g_string_append_printf (status, " TYPE=LOGIN_PROCESS");
348+ break;
349+ case USER_PROCESS:
350+ g_string_append_printf (status, " TYPE=USER_PROCESS");
351+ break;
352+ case DEAD_PROCESS:
353+ g_string_append_printf (status, " TYPE=DEAD_PROCESS");
354+ break;
355+ default:
356+ g_string_append_printf (status, " TYPE=%d", ut->ut_type);
357+ }
358+ if (ut->ut_line)
359+ g_string_append_printf (status, " LINE=%s", ut->ut_line);
360+ if (ut->ut_id)
361+ g_string_append_printf (status, " ID=%s", ut->ut_id);
362+ if (ut->ut_user)
363+ g_string_append_printf (status, " USER=%s", ut->ut_user);
364+ if (ut->ut_host)
365+ g_string_append_printf (status, " HOST=%s", ut->ut_host);
366 status_notify ("%s", status->str);
367- g_string_free (status, TRUE);
368+ g_string_free (status, TRUE);
369+ }
370
371 return (struct utmpx *)ut;
372 }
373@@ -1488,6 +1490,46 @@
374 {
375 }
376
377+void
378+updwtmp (const char *wtmp_file, const struct utmp *ut)
379+{
380+ connect_status ();
381+ if (g_key_file_get_boolean (config, "test-utmp-config", "check-events", NULL))
382+ {
383+ GString *status;
384+
385+ status = g_string_new ("WTMP");
386+ g_string_append_printf (status, " FILE=%s", wtmp_file);
387+ switch (ut->ut_type)
388+ {
389+ case INIT_PROCESS:
390+ g_string_append_printf (status, " TYPE=INIT_PROCESS");
391+ break;
392+ case LOGIN_PROCESS:
393+ g_string_append_printf (status, " TYPE=LOGIN_PROCESS");
394+ break;
395+ case USER_PROCESS:
396+ g_string_append_printf (status, " TYPE=USER_PROCESS");
397+ break;
398+ case DEAD_PROCESS:
399+ g_string_append_printf (status, " TYPE=DEAD_PROCESS");
400+ break;
401+ default:
402+ g_string_append_printf (status, " TYPE=%d", ut->ut_type);
403+ }
404+ if (ut->ut_line)
405+ g_string_append_printf (status, " LINE=%s", ut->ut_line);
406+ if (ut->ut_id)
407+ g_string_append_printf (status, " ID=%s", ut->ut_id);
408+ if (ut->ut_user)
409+ g_string_append_printf (status, " USER=%s", ut->ut_user);
410+ if (ut->ut_host)
411+ g_string_append_printf (status, " HOST=%s", ut->ut_host);
412+ status_notify ("%s", status->str);
413+ g_string_free (status, TRUE);
414+ }
415+}
416+
417 struct xcb_connection_t
418 {
419 gchar *display;
420
421=== renamed file 'tests/test-utmp' => 'tests/test-utmp-autologin'
422--- tests/test-utmp 2014-03-10 04:20:54 +0000
423+++ tests/test-utmp-autologin 2014-03-10 23:47:02 +0000
424@@ -1,2 +1,2 @@
425 #!/bin/sh
426-./src/dbus-env ./src/test-runner utmp test-gobject-greeter
427+./src/dbus-env ./src/test-runner utmp-autologin test-gobject-greeter
428
429=== added file 'tests/test-utmp-login'
430--- tests/test-utmp-login 1970-01-01 00:00:00 +0000
431+++ tests/test-utmp-login 2014-03-10 23:47:02 +0000
432@@ -0,0 +1,2 @@
433+#!/bin/sh
434+./src/dbus-env ./src/test-runner utmp-login test-gobject-greeter
435
436=== added file 'tests/test-utmp-wrong-password'
437--- tests/test-utmp-wrong-password 1970-01-01 00:00:00 +0000
438+++ tests/test-utmp-wrong-password 2014-03-10 23:47:02 +0000
439@@ -0,0 +1,2 @@
440+#!/bin/sh
441+./src/dbus-env ./src/test-runner utmp-wrong-password test-gobject-greeter

Subscribers

People subscribed via source and target branches