From e21d90606afc7d433df738373fab20411c559f74 Mon Sep 17 00:00:00 2001 From: Topi Miettinen Date: Sun, 26 Jan 2020 11:58:34 +0200 Subject: [PATCH] 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). --- src/login/pam_systemd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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; -- 2.47.3