X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Fpam-module.c;h=ea606b7fc9447a89b6b365f49704144489df6b5a;hb=a2cc4a6c960c26f62c33c995bc648357d939bd68;hp=be5901fd77355e4040b2921bd0f7c1953a28994f;hpb=baae0358f349870544884e405e82e4be7d8add9f;p=elogind.git diff --git a/src/login/pam-module.c b/src/login/pam-module.c index be5901fd7..ea606b7fc 100644 --- a/src/login/pam-module.c +++ b/src/login/pam-module.c @@ -120,7 +120,6 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_ _cleanup_free_ char *p = NULL, *tty = NULL; _cleanup_close_ int fd = -1; struct ucred ucred; - socklen_t l; int v, r; assert(display); @@ -144,10 +143,9 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_ 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); + r = getpeercred(fd, &ucred); if (r < 0) - return -errno; + return r; r = get_ctty(ucred.pid, NULL, &tty); if (r < 0) @@ -166,6 +164,36 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_ return 0; } +static int export_legacy_dbus_address( + pam_handle_t *handle, + uid_t uid, + const char *runtime) { + + _cleanup_free_ char *s = NULL; + int r; + +#ifdef ENABLE_KDBUS + if (asprintf(&s, KERNEL_USER_BUS_FMT ";" UNIX_USER_BUS_FMT, + (unsigned long) uid, runtime) < 0) { + pam_syslog(handle, LOG_ERR, "Failed to set bus variable."); + return PAM_BUF_ERR; + } +#else + if (asprintf(&s, UNIX_USER_BUS_FMT, runtime) < 0) { + pam_syslog(handle, LOG_ERR, "Failed to set bus variable."); + return PAM_BUF_ERR; + } +#endif + + 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; + } + + return PAM_SUCCESS; +} + _public_ PAM_EXTERN int pam_sm_open_session( pam_handle_t *handle, int flags, @@ -234,6 +262,10 @@ _public_ PAM_EXTERN int pam_sm_open_session( pam_syslog(handle, LOG_ERR, "Failed to set runtime dir."); return r; } + + r = export_legacy_dbus_address(handle, pw->pw_uid, rt); + if (r != PAM_SUCCESS) + return r; } return PAM_SUCCESS; @@ -284,7 +316,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( if (!isempty(cvtnr)) safe_atou32(cvtnr, &vtnr); - if (!isempty(display) && vtnr <= 0) { + if (!isempty(display) && !vtnr) { if (isempty(seat)) get_seat_from_display(display, &seat, &vtnr); else if (streq(seat, "seat0")) @@ -388,6 +420,10 @@ _public_ PAM_EXTERN int pam_sm_open_session( pam_syslog(handle, LOG_ERR, "Failed to set runtime dir."); return r; } + + r = export_legacy_dbus_address(handle, pw->pw_uid, runtime_path); + if (r != PAM_SUCCESS) + return r; } if (!isempty(seat)) {