diff --git a/src/shared/pam-util.c b/src/shared/pam-util.c index 1057104194e..59437ae0bb9 100644 --- a/src/shared/pam-util.c +++ b/src/shared/pam-util.c @@ -202,3 +202,27 @@ void pam_cleanup_free(pam_handle_t *handle, void *data, int error_status) { /* A generic destructor for pam_set_data() that just frees the specified data */ free(data); } + +int pam_get_item_many_internal(pam_handle_t *handle, ...) { + va_list ap; + int r; + + 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; + } + va_end(ap); + + return r; +} diff --git a/src/shared/pam-util.h b/src/shared/pam-util.h index 5a05fb71f11..9c40ba2dded 100644 --- a/src/shared/pam-util.h +++ b/src/shared/pam-util.h @@ -39,3 +39,7 @@ int pam_acquire_bus_connection(pam_handle_t *handle, const char *module_name, sd int pam_release_bus_connection(pam_handle_t *handle, const char *module_name); 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)