chiark / gitweb /
logind: make session type and class settable via the same ways
authorLennart Poettering <lennart@poettering.net>
Wed, 5 Feb 2014 17:55:18 +0000 (18:55 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 5 Feb 2014 17:55:18 +0000 (18:55 +0100)
If the session type/class is set via environment variables, use that,
and otherwise fallback to something that is set via the PAM module
command line.

man/pam_systemd.xml
man/sd_session_is_active.xml
src/login/pam-module.c

index d3edc32d2ddb0742af38965bcc134925b48e4f4a..f312ef2b99ab4926d193a5f49feab57c4d45d1d2 100644 (file)
                                 <listitem><para>Takes a string
                                 argument which sets the session class.
                                 The XDG_SESSION_CLASS environmental variable
-                                takes precedence.</para></listitem>
+                                takes precedence. One of
+                                <literal>user</literal>,
+                                <literal>greeter</literal>,
+                                <literal>lock-screen</literal> or
+                                <literal>background</literal>. See
+                                <citerefentry><refentrytitle>sd_session_get_class</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+                                for details about the session class.</para></listitem>
+                        </varlistentry>
+
+                        <varlistentry>
+                                <term><option>type=</option></term>
+
+                                <listitem><para>Takes a string
+                                argument which sets the session type.
+                                The XDG_SESSION_TYPE environmental
+                                variable takes precedence. One of
+                                <literal>unspecified</literal>,
+                                <literal>tty</literal>,
+                                <literal>x11</literal> or
+                                <literal>wayland</literal>. See
+                                <citerefentry><refentrytitle>sd_session_get_type</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+                                for details about the session type.</para></listitem>
                         </varlistentry>
 
                         <varlistentry>
index bff6b04eab7a95510f4a824f3ee91f58e9750c3b..4d5e6d113eab9f04cd303a6929360cb0fda1589f 100644 (file)
                 be used to determine the type of the session
                 identified by the specified session identifier. The
                 returned string is one of <literal>x11</literal>,
-                <literal>tty</literal> or
+                <literal>wayland</literal>, <literal>tty</literal> or
                 <literal>unspecified</literal> and needs to be freed
                 with the libc
                 <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
index 18dd4e2e2136482e3a73f1356502ecef269d4bac..9f0f7d186657f52f200c4cea736c6b3a06b8515c 100644 (file)
@@ -46,6 +46,7 @@ static int parse_argv(
                 pam_handle_t *handle,
                 int argc, const char **argv,
                 const char **class,
+                const char **type,
                 bool *debug) {
 
         unsigned i;
@@ -53,11 +54,15 @@ static int parse_argv(
         assert(argc >= 0);
         assert(argc == 0 || argv);
 
-        for (i = 0; i < (unsigned) argc; i++)
+        for (i = 0; i < (unsigned) argc; i++) {
                 if (startswith(argv[i], "class=")) {
                         if (class)
                                 *class = argv[i] + 6;
 
+                } else if (startswith(argv[i], "type=")) {
+                        if (type)
+                                *type = argv[i] + 5;
+
                 } else if (streq(argv[i], "debug")) {
                         if (debug)
                                 *debug = true;
@@ -73,6 +78,7 @@ static int parse_argv(
 
                 } else
                         pam_syslog(handle, LOG_WARNING, "Unknown parameter '%s', ignoring", argv[i]);
+        }
 
         return 0;
 }
@@ -206,7 +212,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                 *remote_user = NULL, *remote_host = NULL,
                 *seat = NULL,
                 *type = NULL, *class = NULL,
-                *class_pam = NULL, *cvtnr = NULL;
+                *class_pam = NULL, *type_pam = NULL, *cvtnr = NULL;
         _cleanup_bus_unref_ sd_bus *bus = NULL;
         int session_fd = -1, existing, r;
         bool debug = false, remote;
@@ -223,6 +229,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
         if (parse_argv(handle,
                        argc, argv,
                        &class_pam,
+                       &type_pam,
                        &debug) < 0)
                 return PAM_SESSION_ERR;
 
@@ -284,6 +291,18 @@ _public_ PAM_EXTERN int pam_sm_open_session(
         if (isempty(cvtnr))
                 cvtnr = getenv("XDG_VTNR");
 
+        type = pam_getenv(handle, "XDG_SESSION_TYPE");
+        if (isempty(type))
+                type = getenv("XDG_SESSION_TYPE");
+        if (isempty(type))
+                type = type_pam;
+
+        class = pam_getenv(handle, "XDG_SESSION_CLASS");
+        if (isempty(class))
+                class = getenv("XDG_SESSION_CLASS");
+        if (isempty(class))
+                class = class_pam;
+
         tty = strempty(tty);
         display = strempty(display);
 
@@ -300,14 +319,16 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                 /* 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";
+                class = "background";
+                tty = "";
         } 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";
+                class = "user";
+                tty = "";
         }
 
         /* If this fails vtnr will be 0, that's intended */
@@ -321,21 +342,15 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                         get_seat_from_display(display, NULL, &vtnr);
         }
 
-        if (seat && !streq(seat, "seat0")) {
-                pam_syslog(handle, LOG_DEBUG,
-                      "Ignoring vtnr %d for %s which is not seat0", vtnr, seat);
+        if (seat && !streq(seat, "seat0") && vtnr != 0) {
+                pam_syslog(handle, LOG_DEBUG, "Ignoring vtnr %d for %s which is not seat0", vtnr, seat);
                 vtnr = 0;
         }
 
-        if (!type)
+        if (isempty(type))
                 type = !isempty(display) ? "x11" :
-                        !isempty(tty) ? "tty" : "unspecified";
+                           !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 = streq(type, "unspecified") ? "background" : "user";