]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
su: use full tty path for PAM_TTY
authorKarel Zak <kzak@redhat.com>
Wed, 3 Feb 2021 13:45:15 +0000 (14:45 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 3 Feb 2021 13:45:15 +0000 (14:45 +0100)
pam_set_item() man page:
 PAM_TTY
   The terminal name: prefixed by /dev/ if it is a device file;
   for graphical, X-based, applications the value for this item
   should be the $DISPLAY variable.

It seems for example pam_timestamp module is not robust enough to
differentiate between /dev/ and pty/0 and it assumes that '/' in the
path always means '/dev/' prefix ...

Fixes: https://github.com/karelzak/util-linux/issues/1242
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/su-common.c

index a544c1b8758fe12653fd8d592551f8e250c641d6..caf20adc569aa66f601cda267d36efac70e5446f 100644 (file)
@@ -128,6 +128,7 @@ struct su_context {
        struct passwd   *pwd;                   /* new user info */
        char            *pwdbuf;                /* pwd strings */
 
+       const char      *tty_path;              /* tty device path */
        const char      *tty_name;              /* tty_path without /dev prefix */
        const char      *tty_number;            /* end of the tty_path */
 
@@ -178,7 +179,7 @@ static void init_tty(struct su_context *su)
        su->isterm = isatty(STDIN_FILENO) ? 1 : 0;
        DBG(TTY, ul_debug("initialize [is-term=%s]", su->isterm ? "true" : "false"));
        if (su->isterm)
-               get_terminal_name(NULL, &su->tty_name, &su->tty_number);
+               get_terminal_name(&su->tty_path, &su->tty_name, &su->tty_number);
 }
 
 /*
@@ -366,8 +367,8 @@ static void supam_authenticate(struct su_context *su)
        if (is_pam_failure(rc))
                goto done;
 
-       if (su->tty_name) {
-               rc = pam_set_item(su->pamh, PAM_TTY, su->tty_name);
+       if (su->tty_path) {
+               rc = pam_set_item(su->pamh, PAM_TTY, su->tty_path);
                if (is_pam_failure(rc))
                        goto done;
        }