X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Fpam-module.c;h=e76fef8001586cc02d7673b08d4ae752be3f2011;hb=ea18a4b57e2bb94af7b3ecb7abdaec40e9f485f0;hp=45428a090f40e767bbd500350cc20f50efeab309;hpb=92bd5ff3a062c3f9475b9d9d39b9335bfeb7705e;p=elogind.git diff --git a/src/login/pam-module.c b/src/login/pam-module.c index 45428a090..e76fef800 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,30 @@ 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) { + +#ifdef ENABLE_KDBUS + _cleanup_free_ char *s = NULL; + int r; + + 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; + } + + 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; + } +#endif + return PAM_SUCCESS; +} + _public_ PAM_EXTERN int pam_sm_open_session( pam_handle_t *handle, int flags, @@ -234,6 +256,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; @@ -388,6 +414,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)) {