X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fpam-module.c;h=9002f4e06dea1da6ceaf9974d686202ae1b90faa;hp=90da898ff84d50bff3dfc031cdba534492489ea1;hb=ce9593140b127ce782e2fa2f47fc55558b331126;hpb=25d934917d3dd2ab10e8acc9a6bacd8c7f2f1067 diff --git a/src/pam-module.c b/src/pam-module.c index 90da898ff..9002f4e06 100644 --- a/src/pam-module.c +++ b/src/pam-module.c @@ -57,9 +57,9 @@ static int parse_argv(pam_handle_t *handle, for (i = 0; i < (unsigned) argc; i++) { int k; - if (startswith(argv[i], "kill-processes=")) { - if ((k = parse_boolean(argv[i] + 15)) < 0) { - pam_syslog(handle, LOG_ERR, "Failed to parse kill-processes= argument."); + if (startswith(argv[i], "kill-session-processes=")) { + if ((k = parse_boolean(argv[i] + 23)) < 0) { + pam_syslog(handle, LOG_ERR, "Failed to parse kill-session-processes= argument."); return k; } @@ -180,14 +180,14 @@ static int get_user_data( * it probably contains a uid of the host system. */ if (read_one_line_file("/proc/self/loginuid", &s) >= 0) { - uint32_t u; + uid_t uid; - r = safe_atou32(s, &u); + r = parse_uid(s, &uid); free(s); - if (r >= 0 && u != (uint32_t) -1 && u > 0) { + if (r >= 0 && uid != (uint32_t) -1) { have_loginuid = true; - pw = pam_modutil_getpwuid(handle, u); + pw = pam_modutil_getpwuid(handle, uid); } } } @@ -239,10 +239,10 @@ static bool check_user_lists( } STRV_FOREACH(l, kill_exclude_users) { - uint32_t id; + uid_t u; - if (safe_atou32(*l, &id) >= 0) - if ((uid_t) id == uid) + if (parse_uid(*l, &u) >= 0) + if (u == uid) return false; if (name && streq(name, *l)) @@ -253,10 +253,10 @@ static bool check_user_lists( return true; STRV_FOREACH(l, kill_only_users) { - uint32_t id; + uid_t u; - if (safe_atou32(*l, &id) >= 0) - if ((uid_t) id == uid) + if (parse_uid(*l, &u) >= 0) + if (u == uid) return true; if (name && streq(name, *l)) @@ -374,6 +374,46 @@ _public_ PAM_EXTERN int pam_sm_open_session( if (r != PAM_SUCCESS) goto finish; + /* Make sure we don't enter a loop by talking to + * systemd-logind when it is actually waiting for the + * background to finish start-up. If the service is + * "systemd-shared" we simply set XDG_RUNTIME_DIR and + * leave. */ + + pam_get_item(handle, PAM_SERVICE, (const void**) &service); + if (streq_ptr(service, "systemd-shared")) { + char *p, *rt = NULL; + + if (asprintf(&p, "/run/systemd/users/%lu", (unsigned long) pw->pw_uid) < 0) { + r = PAM_BUF_ERR; + goto finish; + } + + r = parse_env_file(p, NEWLINE, + "RUNTIME", &rt, + NULL); + free(p); + + if (r < 0 && r != -ENOENT) { + r = PAM_SESSION_ERR; + free(rt); + goto finish; + } + + if (rt) { + r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", rt, 0); + free(rt); + + if (r != PAM_SUCCESS) { + pam_syslog(handle, LOG_ERR, "Failed to set runtime dir."); + goto finish; + } + } + + r = PAM_SUCCESS; + goto finish; + } + if (kill_processes) kill_processes = check_user_lists(handle, pw->pw_uid, kill_only_users, kill_exclude_users); @@ -401,13 +441,12 @@ _public_ PAM_EXTERN int pam_sm_open_session( uid = pw->pw_uid; pid = getpid(); - pam_get_item(handle, PAM_SERVICE, (const void**) &service); pam_get_item(handle, PAM_XDISPLAY, (const void**) &display); pam_get_item(handle, PAM_TTY, (const void**) &tty); pam_get_item(handle, PAM_RUSER, (const void**) &remote_user); pam_get_item(handle, PAM_RHOST, (const void**) &remote_host); - seat = pam_getenv(handle, "LOGIN_SEAT"); - cvtnr = pam_getenv(handle, "LOGIN_VTNR"); + seat = pam_getenv(handle, "XDG_SEAT"); + cvtnr = pam_getenv(handle, "XDG_VTNR"); service = strempty(service); tty = strempty(tty); @@ -424,6 +463,10 @@ _public_ PAM_EXTERN int pam_sm_open_session( if (isempty(display)) display = tty; tty = ""; + } else if (streq(tty, "cron")) { + /* cron has been setting PAM_TTY to "cron" for a very long time + * and it cannot stop doing that for compatibility reasons. */ + tty = ""; } if (!isempty(cvtnr)) @@ -433,7 +476,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( get_seat_from_display(display, &seat, &vtnr); type = !isempty(display) ? "x11" : - !isempty(tty) ? "tty" : "other"; + !isempty(tty) ? "tty" : "unspecified"; remote = !isempty(remote_host) && !streq(remote_host, "localhost") && !streq(remote_host, "localhost.localdomain"); @@ -478,6 +521,11 @@ _public_ PAM_EXTERN int pam_sm_open_session( goto finish; } + if (debug) + pam_syslog(handle, LOG_DEBUG, "Asking logind to create session: " + "uid=%u pid=%u service=%s type=%s seat=%s vtnr=%u tty=%s display=%s remote=%s remote_user=%s remote_host=%s", + uid, pid, service, type, seat, vtnr, tty, display, yes_no(remote), remote_user, remote_host); + reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error); if (!reply) { pam_syslog(handle, LOG_ERR, "Failed to create session: %s", bus_error_message(&error)); @@ -490,12 +538,19 @@ _public_ PAM_EXTERN int pam_sm_open_session( DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_STRING, &runtime_path, DBUS_TYPE_UNIX_FD, &session_fd, + DBUS_TYPE_STRING, &seat, + DBUS_TYPE_UINT32, &vtnr, DBUS_TYPE_INVALID)) { pam_syslog(handle, LOG_ERR, "Failed to parse message: %s", bus_error_message(&error)); r = PAM_SESSION_ERR; goto finish; } + if (debug) + pam_syslog(handle, LOG_DEBUG, "Reply from logind: " + "id=%s object_path=%s runtime_path=%s session_fd=%d seat=%s vtnr=%u", + id, object_path, runtime_path, session_fd, seat, vtnr); + r = pam_misc_setenv(handle, "XDG_SESSION_ID", id, 0); if (r != PAM_SUCCESS) { pam_syslog(handle, LOG_ERR, "Failed to set session id."); @@ -508,6 +563,26 @@ _public_ PAM_EXTERN int pam_sm_open_session( goto finish; } + if (!isempty(seat)) { + r = pam_misc_setenv(handle, "XDG_SEAT", seat, 0); + if (r != PAM_SUCCESS) { + pam_syslog(handle, LOG_ERR, "Failed to set seat."); + goto finish; + } + } + + if (vtnr > 0) { + char buf[11]; + snprintf(buf, sizeof(buf), "%u", vtnr); + char_array_0(buf); + + r = pam_misc_setenv(handle, "XDG_VTNR", buf, 0); + if (r != PAM_SUCCESS) { + pam_syslog(handle, LOG_ERR, "Failed to set virtual terminal number."); + goto finish; + } + } + if (session_fd >= 0) { r = pam_set_data(handle, "systemd.session-fd", INT_TO_PTR(session_fd+1), NULL); if (r != PAM_SUCCESS) {