diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-12 14:25:56 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-23 14:14:08 +0100 |
commit | f0d1266821771724b09a00764f4e20478c77f0a2 (patch) | |
tree | 7af2216618df1db81f57891855c9cb4cb992891c /src/test/nss-test-util.c | |
parent | 3f9721fef0f2e4da181eab9b20bac127f30efa08 (diff) | |
download | systemd-f0d1266821771724b09a00764f4e20478c77f0a2.tar.gz |
test-nss-users: add new nss test that resolves users and groups
Inspired by https://bugzilla.redhat.com/show_bug.cgi?id=1929936.
This is similar to test-nss-hosts, but does users, groups, uid, gids.
Functions tested are:
_nss_*_getpwnam_r
_nss_*_getgrnam_r
_nss_*_getpwgid_r
_nss_*_getgrgid_r
Other entry points should be tested too, but it's not relevant to the bug
I was investigating, so I'm leaving that for later ;)
Diffstat (limited to 'src/test/nss-test-util.c')
-rw-r--r-- | src/test/nss-test-util.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/test/nss-test-util.c b/src/test/nss-test-util.c new file mode 100644 index 0000000000..fc1d724a2f --- /dev/null +++ b/src/test/nss-test-util.c @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include <dlfcn.h> +#include <stdio.h> +#include <unistd.h> + +#include "nss-test-util.h" +#include "string-util.h" + +const char* nss_status_to_string(enum nss_status status, char *buf, size_t buf_len) { + switch (status) { + case NSS_STATUS_TRYAGAIN: + return "NSS_STATUS_TRYAGAIN"; + case NSS_STATUS_UNAVAIL: + return "NSS_STATUS_UNAVAIL"; + case NSS_STATUS_NOTFOUND: + return "NSS_STATUS_NOTFOUND"; + case NSS_STATUS_SUCCESS: + return "NSS_STATUS_SUCCESS"; + case NSS_STATUS_RETURN: + return "NSS_STATUS_RETURN"; + default: + snprintf(buf, buf_len, "%i", status); + return buf; + } +}; + +void* nss_open_handle(const char *dir, const char *module, int flags) { + const char *path = NULL; + void *handle; + + if (dir) + path = strjoina(dir, "/libnss_", module, ".so.2"); + if (!path || access(path, F_OK) < 0) + path = strjoina("libnss_", module, ".so.2"); + + log_debug("Using %s", path); + handle = dlopen(path, flags); + if (!handle) + log_error("Failed to load module %s: %s", module, dlerror()); + return handle; +} |