chiark / gitweb /
login: track login class (i.e. one of "user", "greeter", "lock-screen") for each...
[elogind.git] / src / login / pam-module.c
index 14e706b37430a52c2f03953f48fc36a159d2793e..8544413a0834ff15dec3e9108a602e6a98439bc2 100644 (file)
 #include <security/pam_ext.h>
 #include <security/pam_misc.h>
 
+#include <systemd/sd-daemon.h>
+
 #include "util.h"
 #include "macro.h"
-#include "sd-daemon.h"
 #include "strv.h"
 #include "dbus-common.h"
 #include "def.h"
@@ -259,7 +260,6 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_
         int v;
 
         assert(display);
-        assert(seat);
         assert(vtnr);
 
         /* We deduce the X11 socket from the display name, then use
@@ -307,7 +307,8 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_
         else if (v == 0)
                 return -ENOENT;
 
-        *seat = "seat0";
+        if (seat)
+                *seat = "seat0";
         *vtnr = (uint32_t) v;
 
         return 0;
@@ -320,7 +321,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
 
         struct passwd *pw;
         bool kill_processes = false, debug = false;
-        const char *username, *id, *object_path, *runtime_path, *service = NULL, *tty = NULL, *display = NULL, *remote_user = NULL, *remote_host = NULL, *seat = NULL, *type, *cvtnr = NULL;
+        const char *username, *id, *object_path, *runtime_path, *service = NULL, *tty = NULL, *display = NULL, *remote_user = NULL, *remote_host = NULL, *seat = NULL, *type, *class, *cvtnr = NULL;
         char **controllers = NULL, **reset_controllers = NULL, **kill_only_users = NULL, **kill_exclude_users = NULL;
         DBusError error;
         uint32_t uid, pid;
@@ -454,19 +455,30 @@ _public_ PAM_EXTERN int pam_sm_open_session(
         if (!isempty(cvtnr))
                 safe_atou32(cvtnr, &vtnr);
 
-        if (!isempty(display) && isempty(seat) && vtnr <= 0)
-                get_seat_from_display(display, &seat, &vtnr);
+        if (!isempty(display) && vtnr <= 0) {
+                if (isempty(seat))
+                        get_seat_from_display(display, &seat, &vtnr);
+                else if (streq(seat, "seat0"))
+                        get_seat_from_display(display, NULL, &vtnr);
+        }
 
         type = !isempty(display) ? "x11" :
                    !isempty(tty) ? "tty" : "unspecified";
 
-        remote = !isempty(remote_host) && !streq(remote_host, "localhost") && !streq(remote_host, "localhost.localdomain");
+        class = pam_getenv(handle, "XDG_SESSION_CLASS");
+        if (isempty(class))
+                class = "user";
+
+        remote = !isempty(remote_host) &&
+                !streq(remote_host, "localhost") &&
+                !streq(remote_host, "localhost.localdomain");
 
         if (!dbus_message_append_args(m,
                                       DBUS_TYPE_UINT32, &uid,
                                       DBUS_TYPE_UINT32, &pid,
                                       DBUS_TYPE_STRING, &service,
                                       DBUS_TYPE_STRING, &type,
+                                      DBUS_TYPE_STRING, &class,
                                       DBUS_TYPE_STRING, &seat,
                                       DBUS_TYPE_UINT32, &vtnr,
                                       DBUS_TYPE_STRING, &tty,