diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-11-14 09:55:26 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2025-01-07 23:55:34 +0100 |
commit | 3d57b6692f0a014df2c8e9a41ac61e5da4275506 (patch) | |
tree | 0a52630483cfd26eeb07a1e30af3a13aec0f48d4 /src/test | |
parent | namespace-util: slightly tweak proc_mounted() handling in namespace_is_init() (diff) | |
download | systemd-3d57b6692f0a014df2c8e9a41ac61e5da4275506.tar.xz systemd-3d57b6692f0a014df2c8e9a41ac61e5da4275506.zip |
namespace-util: add helper to get base UID from userns
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-namespace.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c index 6a0459e1fa..3f9c8b83de 100644 --- a/src/test/test-namespace.c +++ b/src/test/test-namespace.c @@ -252,6 +252,30 @@ TEST(namespace_is_init) { } } +TEST(userns_get_base_uid) { + _cleanup_close_ int fd = -EBADF; + + fd = userns_acquire("0 1 1", "0 2 1"); + if (ERRNO_IS_NEG_NOT_SUPPORTED(fd)) + return (void) log_tests_skipped("userns is not supported"); + if (ERRNO_IS_NEG_PRIVILEGE(fd)) + return (void) log_tests_skipped("lacking userns privileges"); + + uid_t base_uid, base_gid; + ASSERT_OK(userns_get_base_uid(fd, &base_uid, &base_gid)); + ASSERT_EQ(base_uid, 1U); + ASSERT_EQ(base_gid, 2U); + + ASSERT_ERROR(userns_get_base_uid(fd, &base_uid, NULL), EUCLEAN); + + fd = safe_close(fd); + + fd = userns_acquire_empty(); + ASSERT_OK(fd); + + ASSERT_ERROR(userns_get_base_uid(fd, &base_uid, &base_gid), ENOMSG); +} + static int intro(void) { if (!have_namespaces()) return log_tests_skipped("Don't have namespace support or lacking privileges"); |