X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Fpam-module.c;h=13290fd8ea6de3fcbb621e99dc7d92e7be50a030;hb=7fd1b19bc9e9f5574f2877936b8ac267c7706947;hp=702095e5e677aec9ab3352ec0f808c3c461222bd;hpb=a5c32cff1f56afe6f0c6c70d91a88a7a8238b2d7;p=elogind.git diff --git a/src/login/pam-module.c b/src/login/pam-module.c index 702095e5e..13290fd8e 100644 --- a/src/login/pam-module.c +++ b/src/login/pam-module.c @@ -32,8 +32,6 @@ #include #include -#include - #include "util.h" #include "audit.h" #include "macro.h" @@ -258,13 +256,15 @@ static bool check_user_lists( } static int get_seat_from_display(const char *display, const char **seat, uint32_t *vtnr) { - char *p = NULL; + _cleanup_free_ char *p = NULL; int r; - int fd; - union sockaddr_union sa; + _cleanup_close_ int fd = -1; + union sockaddr_union sa = { + .un.sun_family = AF_UNIX, + }; struct ucred ucred; socklen_t l; - char *tty; + _cleanup_free_ char *tty = NULL; int v; assert(display); @@ -279,27 +279,17 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_ r = socket_from_display(display, &p); if (r < 0) return r; + strncpy(sa.un.sun_path, p, sizeof(sa.un.sun_path)-1); fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); - if (fd < 0) { - free(p); + if (fd < 0) return -errno; - } - zero(sa); - sa.un.sun_family = AF_UNIX; - strncpy(sa.un.sun_path, p, sizeof(sa.un.sun_path)-1); - free(p); - - if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) { - close_nointr_nofail(fd); + if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) return -errno; - } l = sizeof(ucred); r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &l); - close_nointr_nofail(fd); - if (r < 0) return -errno; @@ -308,8 +298,6 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_ return r; v = vtnr_from_tty(tty); - free(tty); - if (v < 0) return v; else if (v == 0) @@ -348,8 +336,8 @@ _public_ PAM_EXTERN int pam_sm_open_session( /* pam_syslog(handle, LOG_INFO, "pam-systemd initializing"); */ - /* Make this a NOP on non-systemd systems */ - if (sd_booted() <= 0) + /* Make this a NOP on non-logind systems */ + if (!logind_running()) return PAM_SUCCESS; if (parse_argv(handle, @@ -452,9 +440,10 @@ _public_ PAM_EXTERN int pam_sm_open_session( seat = strempty(seat); if (strchr(tty, ':')) { - /* A tty with a colon is usually an X11 display, place - * there to show up in utmp. We rearrange things and - * don't pretend that an X display was a tty */ + /* A tty with a colon is usually an X11 display, + * placed there to show up in utmp. We rearrange + * things and don't pretend that an X display was a + * tty. */ if (isempty(display)) display = tty; @@ -494,7 +483,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( if (isempty(class)) class = class_pam; if (isempty(class)) - class = "user"; + class = streq(type, "unspecified") ? "background" : "user"; remote = !isempty(remote_host) && !streq(remote_host, "localhost") &&