diff options
author | Andreas Schneider <asn@samba.org> | 2015-10-28 08:19:43 +0100 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2015-10-28 10:24:59 +0100 |
commit | b9c3fc40cd946c7807cf5afb9c14de8289639c73 (patch) | |
tree | e4ccf188f6ce6c7cced7a3c765c0df6f8aa2adb0 | |
parent | 78cc57fb564738e8e0df11719a60de3b6ebe0c6c (diff) | |
download | uid_wrapper-b9c3fc40cd946c7807cf5afb9c14de8289639c73.tar.gz uid_wrapper-b9c3fc40cd946c7807cf5afb9c14de8289639c73.tar.xz uid_wrapper-b9c3fc40cd946c7807cf5afb9c14de8289639c73.zip |
tests: Move syscall setreuid32 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_setreuid32.c | 106 | ||||
-rw-r--r-- | tests/test_syscall_uid32.c | 24 |
3 files changed, 107 insertions, 24 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6092fe2..68c1e43 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -69,6 +69,7 @@ if (HAVE_LINUX_32BIT_SYSCALLS) set(UWRAP_TESTS ${UWRAP_TESTS} test_syscall_setuid32 + test_syscall_setreuid32 test_syscall_uid32 test_syscall_gid32) endif (HAVE_LINUX_32BIT_SYSCALLS) diff --git a/tests/test_syscall_setreuid32.c b/tests/test_syscall_setreuid32.c new file mode 100644 index 0000000..4cbf16f --- /dev/null +++ b/tests/test_syscall_setreuid32.c @@ -0,0 +1,106 @@ +#include "config.h" + +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +#include <errno.h> +#include <sys/types.h> +#include <unistd.h> + +#include <pwd.h> + +#ifdef HAVE_SYS_SYSCALL_H +#include <sys/syscall.h> +#endif +#ifdef HAVE_SYSCALL_H +#include <syscall.h> +#endif + +static void test_uwrap_syscall_setreuid32(void **state) +{ + long int rc; + uid_t u; +#ifdef HAVE_GETRESUID + uid_t cp_ruid, cp_euid, cp_suid; +#endif + + (void) state; /* unused */ + +#ifdef HAVE_GETRESUID + cp_ruid = cp_euid = cp_suid = -1; + rc = getresuid(&cp_ruid, &cp_euid, &cp_suid); + assert_return_code(rc, errno); + assert_int_equal(cp_ruid, 0); + assert_int_equal(cp_euid, 0); + assert_int_equal(cp_suid, 0); +#endif + u = geteuid(); + assert_int_equal(u, 0x0); + + rc = syscall(SYS_setreuid32, -1, -1); + assert_int_equal(rc, 0); + + rc = setreuid(0x4444, 0x5555); + assert_int_equal(rc, 0); + +#ifdef HAVE_GETRESUID + cp_ruid = cp_euid = cp_suid = -1; + rc = getresuid(&cp_ruid, &cp_euid, &cp_suid); + assert_return_code(rc, errno); + assert_int_equal(cp_ruid, 0x4444); + assert_int_equal(cp_euid, 0x5555); + assert_int_equal(cp_suid, 0x5555); +#endif + + u = getuid(); + assert_int_equal(u, 0x4444); + + u = geteuid(); + assert_int_equal(u, 0x5555); + + rc = syscall(SYS_setreuid32, 0, -1); + assert_int_equal(rc, -1); + assert_int_equal(errno, EPERM); + +#ifdef HAVE_GETRESUID + cp_ruid = cp_euid = cp_suid = -1; + rc = getresuid(&cp_ruid, &cp_euid, &cp_suid); + assert_return_code(rc, errno); + assert_int_equal(cp_ruid, 0x4444); + assert_int_equal(cp_euid, 0x5555); + assert_int_equal(cp_suid, 0x5555); +#endif + u = getuid(); + assert_int_equal(u, 0x4444); + + u = geteuid(); + assert_int_equal(u, 0x5555); + + rc = syscall(SYS_setreuid32, -1, 0); + assert_int_equal(rc, -1); + assert_int_equal(errno, EPERM); + +#ifdef HAVE_GETRESUID + cp_ruid = cp_euid = cp_suid = -1; + rc = getresuid(&cp_ruid, &cp_euid, &cp_suid); + assert_return_code(rc, errno); + assert_int_equal(cp_ruid, 0x4444); + assert_int_equal(cp_euid, 0x5555); + assert_int_equal(cp_suid, 0x5555); +#endif +} + +int main(void) { + int rc; + + const struct CMUnitTest uwrap_tests[] = { + cmocka_unit_test(test_uwrap_syscall_setreuid32), + }; + + rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL); + + return rc; +} + diff --git a/tests/test_syscall_uid32.c b/tests/test_syscall_uid32.c index dd64a25..6136429 100644 --- a/tests/test_syscall_uid32.c +++ b/tests/test_syscall_uid32.c @@ -18,29 +18,6 @@ #include <syscall.h> #endif -static void test_uwrap_syscall_setreuid32(void **state) -{ - long int rc; - uid_t u; - - (void) state; /* unused */ - - rc = syscall(SYS_setreuid32, 2, 0); - assert_int_equal(rc, 0); - - u = geteuid(); - assert_int_equal(u, syscall(SYS_geteuid32)); - - rc = syscall(SYS_setreuid32, -1, 42); - assert_int_equal(rc, 0); - - u = geteuid(); - assert_int_equal(u, 42); - - u = getuid(); - assert_int_equal(u, 2); -} - static void test_uwrap_syscall_setresuid32(void **state) { long int rc; @@ -75,7 +52,6 @@ int main(void) { int rc; const struct CMUnitTest uwrap_tests[] = { - cmocka_unit_test(test_uwrap_syscall_setreuid32), cmocka_unit_test(test_uwrap_syscall_setresuid32), }; |