Merge pull request #14079 from poettering/pam-systemd-fixlets

trivial pam_systemd fixlets
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-11-19 20:45:15 +01:00 committed by GitHub
commit 321c911fc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -50,28 +50,30 @@ static int parse_argv(
assert(argc == 0 || argv);
for (i = 0; i < (unsigned) argc; i++) {
if (startswith(argv[i], "class=")) {
const char *p;
if ((p = startswith(argv[i], "class="))) {
if (class)
*class = argv[i] + 6;
*class = p;
} else if (startswith(argv[i], "type=")) {
} else if ((p = startswith(argv[i], "type="))) {
if (type)
*type = argv[i] + 5;
*type = p;
} else if (startswith(argv[i], "desktop=")) {
} else if ((p = startswith(argv[i], "desktop="))) {
if (desktop)
*desktop = argv[i] + 8;
*desktop = p;
} else if (streq(argv[i], "debug")) {
if (debug)
*debug = true;
} else if (startswith(argv[i], "debug=")) {
} else if ((p = startswith(argv[i], "debug="))) {
int k;
k = parse_boolean(argv[i] + 6);
k = parse_boolean(p);
if (k < 0)
pam_syslog(handle, LOG_WARNING, "Failed to parse debug= argument, ignoring.");
pam_syslog(handle, LOG_WARNING, "Failed to parse debug= argument, ignoring: %s", p);
else if (debug)
*debug = k;
@ -97,7 +99,7 @@ static int get_user_data(
r = pam_get_user(handle, &username, NULL);
if (r != PAM_SUCCESS) {
pam_syslog(handle, LOG_ERR, "Failed to get user name.");
pam_syslog(handle, LOG_ERR, "Failed to get user name: %s", pam_strerror(handle, r));
return r;
}
@ -383,7 +385,7 @@ static int update_environment(pam_handle_t *handle, const char *key, const char
r = pam_misc_setenv(handle, key, value, 0);
if (r != PAM_SUCCESS)
pam_syslog(handle, LOG_ERR, "Failed to set environment variable %s.", key);
pam_syslog(handle, LOG_ERR, "Failed to set environment variable %s: %s", key, pam_strerror(handle, r));
return r;
}
@ -391,6 +393,7 @@ static int update_environment(pam_handle_t *handle, const char *key, const char
static bool validate_runtime_directory(pam_handle_t *handle, const char *path, uid_t uid) {
struct stat st;
assert(handle);
assert(path);
/* Just some extra paranoia: let's not set $XDG_RUNTIME_DIR if the directory we'd set it to isn't actually set
@ -459,10 +462,8 @@ _public_ PAM_EXTERN int pam_sm_open_session(
pam_syslog(handle, LOG_DEBUG, "pam-systemd initializing");
r = get_user_data(handle, &username, &pw);
if (r != PAM_SUCCESS) {
pam_syslog(handle, LOG_ERR, "Failed to get user data.");
if (r != PAM_SUCCESS)
return r;
}
/* Make sure we don't enter a loop by talking to
* systemd-logind when it is actually waiting for the
@ -470,7 +471,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
* "systemd-user" we simply set XDG_RUNTIME_DIR and
* leave. */
pam_get_item(handle, PAM_SERVICE, (const void**) &service);
(void) pam_get_item(handle, PAM_SERVICE, (const void**) &service);
if (streq_ptr(service, "systemd-user")) {
char rt[STRLEN("/run/user/") + DECIMAL_STR_MAX(uid_t)];
@ -478,7 +479,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
if (validate_runtime_directory(handle, rt, pw->pw_uid)) {
r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", rt, 0);
if (r != PAM_SUCCESS) {
pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
pam_syslog(handle, LOG_ERR, "Failed to set runtime dir: %s", pam_strerror(handle, r));
return r;
}
}
@ -492,10 +493,10 @@ _public_ PAM_EXTERN int pam_sm_open_session(
/* Otherwise, we ask logind to create a session for us */
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);
(void) pam_get_item(handle, PAM_XDISPLAY, (const void**) &display);
(void) pam_get_item(handle, PAM_TTY, (const void**) &tty);
(void) pam_get_item(handle, PAM_RUSER, (const void**) &remote_user);
(void) pam_get_item(handle, PAM_RHOST, (const void**) &remote_host);
seat = getenv_harder(handle, "XDG_SEAT", NULL);
cvtnr = getenv_harder(handle, "XDG_VTNR", NULL);
@ -660,7 +661,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
return PAM_SUCCESS;
} else {
pam_syslog(handle, LOG_ERR, "Failed to create session: %s", bus_error_message(&error, r));
return PAM_SYSTEM_ERR;
return PAM_SESSION_ERR;
}
}
@ -737,7 +738,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
r = pam_set_data(handle, "systemd.existing", INT_TO_PTR(!!existing), NULL);
if (r != PAM_SUCCESS) {
pam_syslog(handle, LOG_ERR, "Failed to install existing flag.");
pam_syslog(handle, LOG_ERR, "Failed to install existing flag: %s", pam_strerror(handle, r));
return r;
}
@ -750,7 +751,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
r = pam_set_data(handle, "systemd.session-fd", FD_TO_PTR(session_fd), NULL);
if (r != PAM_SUCCESS) {
pam_syslog(handle, LOG_ERR, "Failed to install session fd.");
pam_syslog(handle, LOG_ERR, "Failed to install session fd: %s", pam_strerror(handle, r));
safe_close(session_fd);
return r;
}