chiark / gitweb /
pam_systemd: new option for the session class
[elogind.git] / src / login / pam-module.c
index 08a9328b651e1a4f6d8b72dfd89d0a14081fa42a..88b0ef9e4503448565a40012cef1cb80e70ce89e 100644 (file)
@@ -49,6 +49,7 @@ static int parse_argv(pam_handle_t *handle,
                       bool *kill_processes,
                       char ***kill_only_users,
                       char ***kill_exclude_users,
+                      const char **class,
                       bool *debug) {
 
         unsigned i;
@@ -135,6 +136,11 @@ static int parse_argv(pam_handle_t *handle,
                                 *kill_exclude_users = l;
                         }
 
+                } else if (startswith(argv[i], "class=")) {
+
+                        if (class)
+                                *class = argv[i] + 6;
+
                 } else if (startswith(argv[i], "debug=")) {
                         if ((k = parse_boolean(argv[i] + 6)) < 0) {
                                 pam_syslog(handle, LOG_ERR, "Failed to parse debug= argument.");
@@ -322,7 +328,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, *class, *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 = NULL, *class = NULL, *class_pam = NULL, *cvtnr = NULL;
         char **controllers = NULL, **reset_controllers = NULL, **kill_only_users = NULL, **kill_exclude_users = NULL;
         DBusError error;
         uint32_t uid, pid;
@@ -349,7 +355,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                        argc, argv,
                        &controllers, &reset_controllers,
                        &kill_processes, &kill_only_users, &kill_exclude_users,
-                       &debug) < 0) {
+                       &class_pam, &debug) < 0) {
                 r = PAM_SESSION_ERR;
                 goto finish;
         }
@@ -453,9 +459,17 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                         display = tty;
                 tty = "";
         } else if (streq(tty, "cron")) {
-                /* cron has been setting PAM_TTY to "cron" for a very long time
-                 * and it cannot stop doing that for compatibility reasons. */
+                /* cron has been setting PAM_TTY to "cron" for a very
+                 * long time and it probably shouldn't stop doing that
+                 * for compatibility reasons. */
                 tty = "";
+                type = "unspecified";
+        } else if (streq(tty, "ssh")) {
+                /* ssh has been setting PAM_TTY to "ssh" for a very
+                 * long time and probably shouldn't stop doing that
+                 * for compatibility reasons. */
+                tty = "";
+                type ="tty";
         }
 
         /* If this fails vtnr will be 0, that's intended */
@@ -469,12 +483,15 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                         get_seat_from_display(display, NULL, &vtnr);
         }
 
-        type = !isempty(display) ? "x11" :
-                   !isempty(tty) ? "tty" : "unspecified";
+        if (!type)
+                type = !isempty(display) ? "x11" :
+                        !isempty(tty) ? "tty" : "unspecified";
 
         class = pam_getenv(handle, "XDG_SESSION_CLASS");
         if (isempty(class))
                 class = getenv("XDG_SESSION_CLASS");
+        if (isempty(class))
+                class = class_pam;
         if (isempty(class))
                 class = "user";