X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Fpam-module.c;h=262621d43fd3631eaa14b5d033d7be0f58217ac4;hb=d3cf48f4bd3d69a276f17aa7c910e0b35215caba;hp=3b2966b30cf833fa37d78f13922c19ee3cedeb8c;hpb=a4cd87e9dce6d38846f23d44df9e21f322f946df;p=elogind.git diff --git a/src/login/pam-module.c b/src/login/pam-module.c index 3b2966b30..262621d43 100644 --- a/src/login/pam-module.c +++ b/src/login/pam-module.c @@ -184,7 +184,7 @@ static int export_legacy_dbus_address( return PAM_SUCCESS; if (asprintf(&s, KERNEL_USER_BUS_FMT ";" UNIX_USER_BUS_FMT, - (unsigned long) uid, runtime) < 0) { + uid, runtime) < 0) { pam_syslog(handle, LOG_ERR, "Failed to set bus variable."); return PAM_BUF_ERR; } @@ -234,7 +234,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( return PAM_SESSION_ERR; if (debug) - pam_syslog(handle, LOG_INFO, "pam-systemd initializing"); + pam_syslog(handle, LOG_DEBUG, "pam-systemd initializing"); r = get_user_data(handle, &username, &pw); if (r != PAM_SUCCESS) { @@ -252,7 +252,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( if (streq_ptr(service, "systemd-user")) { _cleanup_free_ char *p = NULL, *rt = NULL; - if (asprintf(&p, "/run/systemd/users/%lu", (unsigned long) pw->pw_uid) < 0) + if (asprintf(&p, "/run/systemd/users/"UID_FMT, pw->pw_uid) < 0) return PAM_BUF_ERR; r = parse_env_file(p, NEWLINE, @@ -374,7 +374,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( "uid=%u pid=%u service=%s type=%s class=%s desktop=%s seat=%s vtnr=%u tty=%s display=%s remote=%s remote_user=%s remote_host=%s", pw->pw_uid, getpid(), strempty(service), - type, class, desktop, + type, class, strempty(desktop), strempty(seat), vtnr, strempty(tty), strempty(display), yes_no(remote), strempty(remote_user), strempty(remote_host)); @@ -475,7 +475,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( } if (session_fd >= 0) { - session_fd = dup(session_fd); + session_fd = fcntl(session_fd, F_DUPFD_CLOEXEC, 3); if (session_fd < 0) { pam_syslog(handle, LOG_ERR, "Failed to dup session fd: %m"); return PAM_SESSION_ERR; @@ -484,7 +484,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( r = pam_set_data(handle, "systemd.session-fd", INT_TO_PTR(session_fd+1), NULL); if (r != PAM_SUCCESS) { pam_syslog(handle, LOG_ERR, "Failed to install session fd."); - close_nointr_nofail(session_fd); + safe_close(session_fd); return r; } } @@ -499,7 +499,7 @@ _public_ PAM_EXTERN int pam_sm_close_session( _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_bus_unref_ sd_bus *bus = NULL; - const void *p = NULL, *existing = NULL; + const void *existing = NULL; const char *id; int r; @@ -519,10 +519,8 @@ _public_ PAM_EXTERN int pam_sm_close_session( r = sd_bus_open_system(&bus); if (r < 0) { - pam_syslog(handle, LOG_ERR, - "Failed to connect to system bus: %s", strerror(-r)); - r = PAM_SESSION_ERR; - goto finish; + pam_syslog(handle, LOG_ERR, "Failed to connect to system bus: %s", strerror(-r)); + return PAM_SESSION_ERR; } r = sd_bus_call_method(bus, @@ -535,20 +533,16 @@ _public_ PAM_EXTERN int pam_sm_close_session( "s", id); if (r < 0) { - pam_syslog(handle, LOG_ERR, - "Failed to release session: %s", bus_error_message(&error, r)); - - r = PAM_SESSION_ERR; - goto finish; + pam_syslog(handle, LOG_ERR, "Failed to release session: %s", bus_error_message(&error, r)); + return PAM_SESSION_ERR; } } - r = PAM_SUCCESS; + /* Note that we are knowingly leaking the FIFO fd here. This + * way, logind can watch us die. If we closed it here it would + * not have any clue when that is completed. Given that one + * cannot really have multiple PAM sessions open from the same + * process this means we will leak one FD at max. */ -finish: - pam_get_data(handle, "systemd.session-fd", &p); - if (p) - close_nointr(PTR_TO_INT(p) - 1); - - return r; + return PAM_SUCCESS; }