X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flogin%2Fpam_elogind.c;h=f66f1ce8428bfcfc6ee135dd940e330e4cd62ae1;hp=f75b8ac2c91aece4029ae3e0cfee83c22cead8fd;hb=c73bfb05cb09992935ede3247a1cc4726e54a44d;hpb=b767c85a403ee56b5f87bc9414638b857dabd18d diff --git a/src/login/pam_elogind.c b/src/login/pam_elogind.c index f75b8ac2c..f66f1ce84 100644 --- a/src/login/pam_elogind.c +++ b/src/login/pam_elogind.c @@ -31,6 +31,7 @@ #include #include +#include "bus-common-errors.h" #include "util.h" #include "audit.h" #include "macro.h" @@ -178,24 +179,37 @@ static int export_legacy_dbus_address( const char *runtime) { _cleanup_free_ char *s = NULL; - int r; - - /* skip export if kdbus is not active */ - if (!is_kdbus_available()) - return PAM_SUCCESS; - - if (asprintf(&s, KERNEL_USER_BUS_ADDRESS_FMT ";" UNIX_USER_BUS_ADDRESS_FMT, uid, runtime) < 0) { - pam_syslog(handle, LOG_ERR, "Failed to set bus variable."); - return PAM_BUF_ERR; + 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. */ + + s = strjoin(runtime, "/bus", NULL); + if (!s) + goto error; + + if (access(s, F_OK) < 0) + return PAM_SUCCESS; + + 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) { - pam_syslog(handle, LOG_ERR, "Failed to set bus variable."); - return r; - } + if (r != PAM_SUCCESS) + goto error; return PAM_SUCCESS; + +error: + pam_syslog(handle, LOG_ERR, "Failed to set bus variable."); + return r; } _public_ PAM_EXTERN int pam_sm_open_session( @@ -243,7 +257,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( } /* Make sure we don't enter a loop by talking to - * logind when it is actually waiting for the + * systemd-logind when it is actually waiting for the * background to finish start-up. If the service is * "systemd-user" we simply set XDG_RUNTIME_DIR and * leave. */ @@ -399,8 +413,13 @@ _public_ PAM_EXTERN int pam_sm_open_session( remote_host, 0); if (r < 0) { - pam_syslog(handle, LOG_ERR, "Failed to create session: %s", bus_error_message(&error, r)); - return PAM_SYSTEM_ERR; + if (sd_bus_error_has_name(&error, BUS_ERROR_SESSION_BUSY)) { + pam_syslog(handle, LOG_DEBUG, "Cannot create session: %s", bus_error_message(&error, r)); + return PAM_SUCCESS; + } else { + pam_syslog(handle, LOG_ERR, "Failed to create session: %s", bus_error_message(&error, r)); + return PAM_SYSTEM_ERR; + } } r = sd_bus_message_read(reply,