diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index 684ec967e1f..9d96c915395 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -1260,11 +1260,11 @@ _public_ PAM_EXTERN int pam_sm_open_session( SessionContext c = {}; r = pam_get_item_many( handle, - PAM_SERVICE, &c.service, + PAM_SERVICE, &c.service, PAM_XDISPLAY, &c.display, - PAM_TTY, &c.tty, - PAM_RUSER, &c.remote_user, - PAM_RHOST, &c.remote_host); + PAM_TTY, &c.tty, + PAM_RUSER, &c.remote_user, + PAM_RHOST, &c.remote_host); if (r != PAM_SUCCESS) return pam_syslog_pam_error(handle, LOG_ERR, r, "Failed to get PAM items: @PAMERR@"); @@ -1275,21 +1275,15 @@ _public_ PAM_EXTERN int pam_sm_open_session( c.desktop = getenv_harder(handle, "XDG_SESSION_DESKTOP", desktop_pam); c.incomplete = getenv_harder_bool(handle, "XDG_SESSION_INCOMPLETE", false); - r = pam_get_data(handle, "systemd.memory_max", (const void **)&c.memory_max); - if (!IN_SET(r, PAM_SUCCESS, PAM_NO_MODULE_DATA)) - return pam_syslog_pam_error(handle, LOG_ERR, r, "Failed to get PAM systemd.memory_max data: @PAMERR@"); - r = pam_get_data(handle, "systemd.tasks_max", (const void **)&c.tasks_max); - if (!IN_SET(r, PAM_SUCCESS, PAM_NO_MODULE_DATA)) - return pam_syslog_pam_error(handle, LOG_ERR, r, "Failed to get PAM systemd.tasks_max data: @PAMERR@"); - r = pam_get_data(handle, "systemd.cpu_weight", (const void **)&c.cpu_weight); - if (!IN_SET(r, PAM_SUCCESS, PAM_NO_MODULE_DATA)) - return pam_syslog_pam_error(handle, LOG_ERR, r, "Failed to get PAM systemd.cpu_weight data: @PAMERR@"); - r = pam_get_data(handle, "systemd.io_weight", (const void **)&c.io_weight); - if (!IN_SET(r, PAM_SUCCESS, PAM_NO_MODULE_DATA)) - return pam_syslog_pam_error(handle, LOG_ERR, r, "Failed to get PAM systemd.io_weight data: @PAMERR@"); - r = pam_get_data(handle, "systemd.runtime_max_sec", (const void **)&c.runtime_max_sec); - if (!IN_SET(r, PAM_SUCCESS, PAM_NO_MODULE_DATA)) - return pam_syslog_pam_error(handle, LOG_ERR, r, "Failed to get PAM systemd.runtime_max_sec data: @PAMERR@"); + r = pam_get_data_many( + handle, + "systemd.memory_max", &c.memory_max, + "systemd.tasks_max", &c.tasks_max, + "systemd.cpu_weight", &c.cpu_weight, + "systemd.io_weight", &c.io_weight, + "systemd.runtime_max_sec", &c.runtime_max_sec); + if (r != PAM_SUCCESS) + return pam_syslog_pam_error(handle, LOG_ERR, r, "Failed to get PAM data: @PAMERR@"); session_context_mangle(handle, &c, ur, debug); diff --git a/src/shared/pam-util.c b/src/shared/pam-util.c index af97adb2d08..0b97e81ab83 100644 --- a/src/shared/pam-util.c +++ b/src/shared/pam-util.c @@ -253,17 +253,17 @@ int pam_get_item_many_internal(pam_handle_t *handle, ...) { va_list ap; int r; + assert(handle); + va_start(ap, handle); for (;;) { int item_type = va_arg(ap, int); - if (item_type <= 0) { r = PAM_SUCCESS; break; } const void **value = ASSERT_PTR(va_arg(ap, const void **)); - r = pam_get_item(handle, item_type, value); if (!IN_SET(r, PAM_BAD_ITEM, PAM_SUCCESS)) break; @@ -273,6 +273,30 @@ int pam_get_item_many_internal(pam_handle_t *handle, ...) { return r; } +int pam_get_data_many_internal(pam_handle_t *handle, ...) { + va_list ap; + int r; + + assert(handle); + + va_start(ap, handle); + for (;;) { + const char *data_name = va_arg(ap, const char *); + if (!data_name) { + r = PAM_SUCCESS; + break; + } + + const void **value = ASSERT_PTR(va_arg(ap, const void **)); + r = pam_get_data(handle, data_name, value); + if (!IN_SET(r, PAM_NO_MODULE_DATA, PAM_SUCCESS)) + break; + } + va_end(ap); + + return r; +} + int pam_prompt_graceful(pam_handle_t *handle, int style, char **ret_response, const char *fmt, ...) { va_list args; int r; diff --git a/src/shared/pam-util.h b/src/shared/pam-util.h index 34a83294b09..2e19516042b 100644 --- a/src/shared/pam-util.h +++ b/src/shared/pam-util.h @@ -44,7 +44,9 @@ int pam_get_bus_data(pam_handle_t *handle, const char *module_name, PamBusData * void pam_cleanup_free(pam_handle_t *handle, void *data, int error_status); int pam_get_item_many_internal(pam_handle_t *handle, ...); - #define pam_get_item_many(handle, ...) pam_get_item_many_internal(handle, __VA_ARGS__, -1) +int pam_get_data_many_internal(pam_handle_t *handle, ...) _sentinel_; +#define pam_get_data_many(handle, ...) pam_get_data_many_internal(handle, __VA_ARGS__, NULL) + int pam_prompt_graceful(pam_handle_t *handle, int style, char **ret_response, const char *fmt, ...) _printf_(4,5);