Merge lp:~lotheac/lightdm/utmpx into lp:lightdm

Proposed by Lauri Tirkkonen
Status: Merged
Merged at revision: 1508
Proposed branch: lp:~lotheac/lightdm/utmpx
Merge into: lp:lightdm
Diff against target: 98 lines (+42/-8)
1 file modified
src/session-child.c (+42/-8)
To merge this branch: bzr merge lp:~lotheac/lightdm/utmpx
Reviewer Review Type Date Requested Status
LightDM Development Team Pending
Robert Ancell Pending
Review via email: mp+107739@code.launchpad.net

This proposal supersedes a proposal from 2012-05-23.

Description of the change

Write utmpx records for user sessions. This fixes bug #870297 in Ubuntu.

To post a comment you must log in.
Revision history for this message
Robert Ancell (robert-ancell) wrote : Posted in a previous version of this proposal

Hi, thanks for that!

40 + is_greeter = (class && 0 == strncmp(class, XDG_SESSION_CLASS_GREETER,
41 + sizeof XDG_SESSION_CLASS_GREETER));
This can be more simply done with:
is_greeter = g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) == 0;

58 + if (!is_greeter) {
59 + /* Open the session */
60 + result = pam_open_session (pam_handle, 0);
You should still open a PAM session for the greeter, why not?

73 - /* Wait for the command to complete (blocks) */
You seem to have accidentally removed a comment :(

76 + if (!is_greeter) {
Braces start on a new line

86 + if (remote_host_name) {
87 + strncpy (ut.ut_host, remote_host_name, sizeof (ut.ut_host));
88 + } else {
89 + memset (ut.ut_host, 0, sizeof (ut.ut_host));
90 + }
Don't need braces for single line branches

review: Needs Fixing
Revision history for this message
Lauri Tirkkonen (lotheac) wrote : Posted in a previous version of this proposal

> 58 + if (!is_greeter) {
> 59 + /* Open the session */
> 60 + result = pam_open_session (pam_handle, 0);
> You should still open a PAM session for the greeter, why not?

Because if we don't, we can stack pam_lastlog as a session module in order to record user sessions to wtmp and lastlog. I could comment that, though.

> 73 - /* Wait for the command to complete (blocks) */
> You seem to have accidentally removed a comment :(

It's actually just been moved closer to the wait call :) line 101 in the diff

I'll try to get around to fixing the rest later today.

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

I've committed the core of this patch with the following changes:
- Don't stop opening PAM sessions for the greeter - the PAM configuration might require to set something up in the session hooks for the greeter so we need to run those (and it is a session, just not a user session). The correct way to solve this is to make the greeter use a different PAM service so it can have different configuration.
- Remove the record when the session exits
- Minor layout changes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/session-child.c'
--- src/session-child.c 2012-05-15 23:56:33 +0000
+++ src/session-child.c 2012-05-29 09:00:34 +0000
@@ -11,6 +11,7 @@
11#include <grp.h>11#include <grp.h>
12#include <glib.h>12#include <glib.h>
13#include <security/pam_appl.h>13#include <security/pam_appl.h>
14#include <utmpx.h>
1415
15#include "session-child.h"16#include "session-child.h"
16#include "session.h"17#include "session.h"
@@ -182,6 +183,7 @@
182 gchar *console_kit_cookie;183 gchar *console_kit_cookie;
183 const gchar *path;184 const gchar *path;
184 GError *error = NULL;185 GError *error = NULL;
186 gboolean is_greeter = FALSE;
185187
186 g_type_init ();188 g_type_init ();
187189
@@ -334,6 +336,8 @@
334 return EXIT_FAILURE;336 return EXIT_FAILURE;
335 }337 }
336338
339 is_greeter = g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) == 0;
340
337 /* Stop if we didn't authenticated */341 /* Stop if we didn't authenticated */
338 if (authentication_result != PAM_SUCCESS)342 if (authentication_result != PAM_SUCCESS)
339 return EXIT_FAILURE;343 return EXIT_FAILURE;
@@ -384,13 +388,18 @@
384 g_printerr ("Failed to establish PAM credentials: %s\n", pam_strerror (pam_handle, result));388 g_printerr ("Failed to establish PAM credentials: %s\n", pam_strerror (pam_handle, result));
385 return EXIT_FAILURE;389 return EXIT_FAILURE;
386 }390 }
387 391
388 /* Open the session */392 /* Don't open a PAM session for greeters. This way we can stack pam_lastlog
389 result = pam_open_session (pam_handle, 0);393 * as a session module to record wtmp and lastlog for user sessions. */
390 if (result != PAM_SUCCESS)394 if (!is_greeter)
391 {395 {
392 g_printerr ("Failed to open PAM session: %s\n", pam_strerror (pam_handle, result));396 /* Open the session */
393 return EXIT_FAILURE;397 result = pam_open_session (pam_handle, 0);
398 if (result != PAM_SUCCESS)
399 {
400 g_printerr ("Failed to open PAM session: %s\n", pam_strerror (pam_handle, result));
401 return EXIT_FAILURE;
402 }
394 }403 }
395404
396 /* Open a connection to the system bus for ConsoleKit - we must keep it open or CK will close the session */405 /* Open a connection to the system bus for ConsoleKit - we must keep it open or CK will close the session */
@@ -524,9 +533,33 @@
524 return_code = EXIT_FAILURE;533 return_code = EXIT_FAILURE;
525 }534 }
526535
527 /* Wait for the command to complete (blocks) */
528 if (child_pid > 0)536 if (child_pid > 0)
529 {537 {
538 if (!is_greeter)
539 {
540 /* This is a user session */
541 struct utmpx ut;
542 struct timeval tv;
543 /* Log to utmp */
544 ut.ut_type = USER_PROCESS;
545 ut.ut_pid = child_pid;
546 strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line));
547 strncpy (ut.ut_user, username, sizeof (ut.ut_user));
548 strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id));
549 if (remote_host_name)
550 strncpy (ut.ut_host, remote_host_name, sizeof (ut.ut_host));
551 else
552 memset (ut.ut_host, 0, sizeof (ut.ut_host));
553 gettimeofday (&tv, NULL);
554 ut.ut_tv.tv_sec = tv.tv_sec;
555 ut.ut_tv.tv_usec = tv.tv_usec;
556 setutxent ();
557 if (NULL == pututxline (&ut))
558 g_printerr ("Failed to write utmpx: %s\n", strerror (errno));
559 endutxent ();
560 }
561
562 /* Wait for the command to complete (blocks) */
530 waitpid (child_pid, &return_code, 0);563 waitpid (child_pid, &return_code, 0);
531 child_pid = 0;564 child_pid = 0;
532 }565 }
@@ -560,7 +593,8 @@
560 ck_close_session (console_kit_cookie);593 ck_close_session (console_kit_cookie);
561594
562 /* Close the session */595 /* Close the session */
563 pam_close_session (pam_handle, 0);596 if (!is_greeter)
597 pam_close_session (pam_handle, 0);
564598
565 /* Remove credentials */599 /* Remove credentials */
566 result = pam_setcred (pam_handle, PAM_DELETE_CRED);600 result = pam_setcred (pam_handle, PAM_DELETE_CRED);

Subscribers

People subscribed via source and target branches