summaryrefslogtreecommitdiff
path: root/src/login/pam_systemd.c
diff options
context:
space:
mode:
authorTopi Miettinen <toiwoton@gmail.com>2020-01-26 11:58:34 +0200
committerLennart Poettering <lennart@poettering.net>2020-01-29 16:06:48 +0100
commite21d90606afc7d433df738373fab20411c559f74 (patch)
treeda74c1d976770d9b20df0ea6a7f0c6dce51938e9 /src/login/pam_systemd.c
parent72d43d09ccb55b70d65494ad8cfea5af6f3ef52f (diff)
downloadsystemd-e21d90606afc7d433df738373fab20411c559f74.tar.gz
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).
Diffstat (limited to 'src/login/pam_systemd.c')
-rw-r--r--src/login/pam_systemd.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c
index c7fe858b92..8447e1c555 100644
--- a/src/login/pam_systemd.c
+++ b/src/login/pam_systemd.c
@@ -11,6 +11,7 @@
#include <security/pam_modutil.h>
#include <sys/file.h>
#include <sys/stat.h>
+#include <sys/sysmacros.h>
#include <sys/types.h>
#include <unistd.h>
@@ -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;