From: Topi Miettinen Date: Sun, 26 Jan 2020 09:58:34 +0000 (+0200) Subject: pam_systemd: resolve the tty of display via /sys instead of /dev X-Git-Tag: v245-rc1~58 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e21d90606afc7d433df738373fab20411c559f74;p=thirdparty%2Fsystemd.git pam_systemd: resolve the tty of display via /sys instead of /dev Rely on information provided by /proc/*/stat and /sys/dev/char for resolving the controlling tty for the display server, instead of trying to access the tty device in /dev (which may not be accessible for example due to PrivateDevices=yes). --- diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index c7fe858b921..8447e1c555f 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -219,10 +220,11 @@ static int socket_from_display(const char *display, char **path) { static int get_seat_from_display(const char *display, const char **seat, uint32_t *vtnr) { union sockaddr_union sa = {}; - _cleanup_free_ char *p = NULL, *tty = NULL; + _cleanup_free_ char *p = NULL, *sys_path = NULL, *tty = NULL; _cleanup_close_ int fd = -1; struct ucred ucred; int v, r, salen; + dev_t display_ctty; assert(display); assert(vtnr); @@ -251,7 +253,13 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_ if (r < 0) return r; - r = get_ctty(ucred.pid, NULL, &tty); + r = get_ctty_devnr(ucred.pid, &display_ctty); + if (r < 0) + return r; + + if (asprintf(&sys_path, "/sys/dev/char/%d:%d", major(display_ctty), minor(display_ctty)) < 0) + return -ENOMEM; + r = readlink_value(sys_path, &tty); if (r < 0) return r;