diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-11-28 09:29:58 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-01-04 12:26:40 +0100 |
commit | f47d75de51212dfa36f0e6b555052edbf55acdff (patch) | |
tree | ebe80765e25254cfe4f15eedecceb12d9025d3e5 /src | |
parent | Merge pull request #30513 from rpigott/resolved-ede (diff) | |
download | systemd-f47d75de51212dfa36f0e6b555052edbf55acdff.tar.xz systemd-f47d75de51212dfa36f0e6b555052edbf55acdff.zip |
pam-util: add pam_get_item_many() helper that gets many PAM items at once
Just to shorten a bit of code.
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/pam-util.c | 24 | ||||
-rw-r--r-- | src/shared/pam-util.h | 4 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/shared/pam-util.c b/src/shared/pam-util.c index 1057104194..59437ae0bb 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 5a05fb71f1..9c40ba2dde 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) |