X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fsystemd.git;a=blobdiff_plain;f=src%2Flogin%2Fpam_systemd.c;h=246bbddeee10eca1fa85293efee2b4b4dc71b8e1;hp=95977426d9392cdf05236330c10d18bc548a1bf3;hb=53e1b683907c2f12330f00feb9630150196f064d;hpb=afd806fc480dc8d17b6a7837e474b2caa8a5c850 diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index 95977426d93..246bbddeee1 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -1,5 +1,4 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. @@ -38,15 +37,17 @@ #include "def.h" #include "fd-util.h" #include "fileio.h" -#include "formats-util.h" +#include "format-util.h" #include "hostname-util.h" #include "login-util.h" #include "macro.h" #include "parse-util.h" +#include "process-util.h" #include "socket-util.h" #include "strv.h" #include "terminal-util.h" #include "util.h" +#include "path-util.h" static int parse_argv( pam_handle_t *handle, @@ -152,7 +153,7 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_ if (fd < 0) return -errno; - if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) + if (connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0) return -errno; r = getpeercred(fd, &ucred); @@ -184,25 +185,20 @@ static int export_legacy_dbus_address( _cleanup_free_ char *s = NULL; int r = PAM_BUF_ERR; - if (is_kdbus_available()) { - if (asprintf(&s, KERNEL_USER_BUS_ADDRESS_FMT ";" UNIX_USER_BUS_ADDRESS_FMT, uid, runtime) < 0) - goto error; - } else { - /* FIXME: We *really* should move the access() check into the - * daemons that spawn dbus-daemon, instead of forcing - * DBUS_SESSION_BUS_ADDRESS= here. */ + /* FIXME: We *really* should move the access() check into the + * daemons that spawn dbus-daemon, instead of forcing + * DBUS_SESSION_BUS_ADDRESS= here. */ - s = strjoin(runtime, "/bus", NULL); - if (!s) - goto error; + s = strjoin(runtime, "/bus"); + if (!s) + goto error; - if (access(s, F_OK) < 0) - return PAM_SUCCESS; + if (access(s, F_OK) < 0) + return PAM_SUCCESS; - s = mfree(s); - if (asprintf(&s, UNIX_USER_BUS_ADDRESS_FMT, runtime) < 0) - goto error; - } + s = mfree(s); + if (asprintf(&s, UNIX_USER_BUS_ADDRESS_FMT, runtime) < 0) + goto error; r = pam_misc_setenv(handle, "DBUS_SESSION_BUS_ADDRESS", s, 0); if (r != PAM_SUCCESS) @@ -341,7 +337,9 @@ _public_ PAM_EXTERN int pam_sm_open_session( type ="tty"; class = "user"; tty = NULL; - } + } else + /* Chop off leading /dev prefix that some clients specify, but others do not. */ + tty = skip_dev_prefix(tty); /* If this fails vtnr will be 0, that's intended */ if (!isempty(cvtnr)) @@ -379,7 +377,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( if (debug) pam_syslog(handle, LOG_DEBUG, "Asking logind to create session: " "uid="UID_FMT" pid="PID_FMT" service=%s type=%s class=%s desktop=%s seat=%s vtnr=%"PRIu32" tty=%s display=%s remote=%s remote_user=%s remote_host=%s", - pw->pw_uid, getpid(), + pw->pw_uid, getpid_cached(), strempty(service), type, class, strempty(desktop), strempty(seat), vtnr, strempty(tty), strempty(display), @@ -394,7 +392,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( &reply, "uusssssussbssa(sv)", (uint32_t) pw->pw_uid, - (uint32_t) getpid(), + (uint32_t) getpid_cached(), service, type, class,