diff options
author | Andreas Schneider <asn@samba.org> | 2015-10-28 09:33:16 +0100 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2015-10-28 10:25:16 +0100 |
commit | 9d6423cc1e33e5444b8e459e515ca889799656e5 (patch) | |
tree | 2423896994fa96319aa364c6516fbd94930b06ec | |
parent | 7927d700b632377d23649c0a325d00047631f345 (diff) | |
download | uid_wrapper-9d6423cc1e33e5444b8e459e515ca889799656e5.tar.gz uid_wrapper-9d6423cc1e33e5444b8e459e515ca889799656e5.tar.xz uid_wrapper-9d6423cc1e33e5444b8e459e515ca889799656e5.zip |
tests: Move syscall setregid32 test to own executable
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/test_syscall_gid32.c | 26 | ||||
-rw-r--r-- | tests/test_syscall_setresgid32.c | 205 |
3 files changed, 206 insertions, 26 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index baa12d4..7558297 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -73,6 +73,7 @@ if (HAVE_LINUX_32BIT_SYSCALLS) test_syscall_setresuid32 test_syscall_setgid32 test_syscall_setregid32 + test_syscall_setresgid32 test_syscall_gid32) endif (HAVE_LINUX_32BIT_SYSCALLS) diff --git a/tests/test_syscall_gid32.c b/tests/test_syscall_gid32.c index 73abe89..3ac482c 100644 --- a/tests/test_syscall_gid32.c +++ b/tests/test_syscall_gid32.c @@ -21,31 +21,6 @@ #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) -static void test_uwrap_syscall_setresgid32(void **state) -{ - long int rc; - gid_t g; - gid_t g_r, g_e, g_s; - - (void) state; /* unused */ - - rc = syscall(SYS_setresgid32, 42, 0, -1); - assert_int_equal(rc, 0); - - g = getegid(); - rc = syscall(SYS_getresgid32, &g_r, &g_e, &g_s); - assert_return_code(rc, errno); - - assert_int_equal(g_r, 42); - assert_int_equal(g, g_e); - - rc = syscall(SYS_setregid32, -1, 42); - assert_return_code(rc, errno); - - g = getegid(); - assert_int_equal(g, 42); -} - static void test_uwrap_syscall_setgroups32(void **state) { gid_t glist[] = { 100, 200, 300, 400, 500 }; @@ -77,7 +52,6 @@ int main(void) { int rc; const struct CMUnitTest uwrap_tests[] = { - cmocka_unit_test(test_uwrap_syscall_setresgid32), cmocka_unit_test(test_uwrap_syscall_setgroups32), }; diff --git a/tests/test_syscall_setresgid32.c b/tests/test_syscall_setresgid32.c new file mode 100644 index 0000000..9c0e789 --- /dev/null +++ b/tests/test_syscall_setresgid32.c @@ -0,0 +1,205 @@ +#include "config.h" + +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +#include <errno.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> + +#include <grp.h> + +#ifdef HAVE_SYS_SYSCALL_H +#include <sys/syscall.h> +#endif +#ifdef HAVE_SYSCALL_H +#include <syscall.h> +#endif + +static void test_uwrap_syscall_setresgid32(void **state) +{ + long int rc; + uid_t u; + gid_t g; +#ifdef HAVE_GETRESGID + gid_t cp_rgid, cp_egid, cp_sgid; +#endif + + (void) state; /* unused */ + + u = getuid(); + assert_int_equal(u, 0x0); + u = geteuid(); + assert_int_equal(u, 0x0); + +#ifdef HAVE_GETRESGID + cp_rgid = cp_egid = cp_sgid = -1; + rc = getresgid(&cp_rgid, &cp_egid, &cp_sgid); + assert_return_code(rc, errno); + assert_int_equal(cp_rgid, 0); + assert_int_equal(cp_egid, 0); + assert_int_equal(cp_sgid, 0); +#endif + + g = getgid(); + assert_int_equal(g, 0x0); + g = getegid(); + assert_int_equal(g, 0x0); + + rc = syscall(SYS_setresgid32, -1, -1, -1); + assert_return_code(rc, errno); + + rc = syscall(SYS_setresgid32, 0x4444, 0x5555, -1); + assert_return_code(rc, errno); + +#ifdef HAVE_GETRESGID + cp_rgid = cp_egid = cp_sgid = -1; + rc = getresgid(&cp_rgid, &cp_egid, &cp_sgid); + assert_return_code(rc, errno); + assert_int_equal(cp_rgid, 0x4444); + assert_int_equal(cp_egid, 0x5555); + assert_int_equal(cp_sgid, 0); +#endif + + g = getgid(); + assert_int_equal(g, 0x4444); + g = getegid(); + assert_int_equal(g, 0x5555); + + /* We can go back cause the sgid is 0 */ + rc = syscall(SYS_setresgid32, 0, -1, -1); + assert_return_code(rc, errno); + +#ifdef HAVE_GETRESGID + cp_rgid = cp_egid = cp_sgid = -1; + rc = getresgid(&cp_rgid, &cp_egid, &cp_sgid); + assert_return_code(rc, errno); + assert_int_equal(cp_rgid, 0); + assert_int_equal(cp_egid, 0x5555); + assert_int_equal(cp_sgid, 0); +#endif + + u = getgid(); + assert_int_equal(u, 0x0); + g = getegid(); + assert_int_equal(g, 0x5555); + + rc = syscall(SYS_setresgid32, -1, 0, -1); + assert_return_code(rc, errno); + +#ifdef HAVE_GETRESGID + cp_rgid = cp_egid = cp_sgid = -1; + rc = getresgid(&cp_rgid, &cp_egid, &cp_sgid); + assert_return_code(rc, errno); + assert_int_equal(cp_rgid, 0x0); + assert_int_equal(cp_egid, 0x0); + assert_int_equal(cp_sgid, 0x0); +#endif + + u = getegid(); + assert_int_equal(u, 0); + + rc = syscall(SYS_setresgid32, 0, 0x5555, 0x6666); + assert_return_code(rc, errno); + +#ifdef HAVE_GETRESGID + cp_rgid = cp_egid = cp_sgid = -1; + rc = getresgid(&cp_rgid, &cp_egid, &cp_sgid); + assert_return_code(rc, errno); + assert_int_equal(cp_rgid, 0); + assert_int_equal(cp_egid, 0x5555); + assert_int_equal(cp_sgid, 0x6666); +#endif + + /* + * The egid needs to be 0 in order to change to an + * unknown value (here 0x4444) + */ + rc = syscall(SYS_setresgid32, 0x5555, 0x6666, 0x4444); + assert_return_code(rc, errno); + +#ifdef HAVE_GETRESGID + cp_rgid = cp_egid = cp_sgid = -1; + rc = getresgid(&cp_rgid, &cp_egid, &cp_sgid); + assert_return_code(rc, errno); + assert_int_equal(cp_rgid, 0x5555); + assert_int_equal(cp_egid, 0x6666); + assert_int_equal(cp_sgid, 0x4444); +#endif + + errno = 0; + rc = syscall(SYS_setresgid32, 0x5555, 0x6666, 0); + assert_return_code(rc, errno); + +#ifdef HAVE_GETRESGID + cp_rgid = cp_egid = cp_sgid = -1; + rc = getresgid(&cp_rgid, &cp_egid, &cp_sgid); + assert_return_code(rc, errno); + assert_int_equal(cp_rgid, 0x5555); + assert_int_equal(cp_egid, 0x6666); + assert_int_equal(cp_sgid, 0); +#endif + + rc = syscall(SYS_setresgid32, 0x5555, 0x6666, 0x4444); + assert_return_code(rc, errno); + +#ifdef HAVE_GETRESGID + cp_rgid = cp_egid = cp_sgid = -1; + rc = getresgid(&cp_rgid, &cp_egid, &cp_sgid); + assert_return_code(rc, errno); + assert_int_equal(cp_rgid, 0x5555); + assert_int_equal(cp_egid, 0x6666); + assert_int_equal(cp_sgid, 0x4444); +#endif + + rc = syscall(SYS_setresgid32, 0x5555, 0, 0x6666); + assert_return_code(rc, errno); + +#ifdef HAVE_GETRESGID + cp_rgid = cp_egid = cp_sgid = -1; + rc = getresgid(&cp_rgid, &cp_egid, &cp_sgid); + assert_return_code(rc, errno); + assert_int_equal(cp_rgid, 0x5555); + assert_int_equal(cp_egid, 0); + assert_int_equal(cp_sgid, 0x6666); +#endif + + rc = syscall(SYS_setresgid32, 0x1111, 0x2222, 0x3333); + assert_return_code(rc, errno); + +#ifdef HAVE_GETRESGID + cp_rgid = cp_egid = cp_sgid = -1; + rc = getresgid(&cp_rgid, &cp_egid, &cp_sgid); + assert_return_code(rc, errno); + assert_int_equal(cp_rgid, 0x1111); + assert_int_equal(cp_egid, 0x2222); + assert_int_equal(cp_sgid, 0x3333); +#endif + + rc = syscall(SYS_setresgid32, 0, -1, -1); + assert_return_code(rc, errno); + +#ifdef HAVE_GETRESGID + cp_rgid = cp_egid = cp_sgid = -1; + rc = getresgid(&cp_rgid, &cp_egid, &cp_sgid); + assert_return_code(rc, errno); + assert_int_equal(cp_rgid, 0x0); + assert_int_equal(cp_egid, 0x2222); + assert_int_equal(cp_sgid, 0x3333); +#endif +} + +int main(void) { + int rc; + + const struct CMUnitTest uwrap_tests[] = { + cmocka_unit_test(test_uwrap_syscall_setresgid32), + }; + + rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL); + + return rc; +} |