diff options
author | Andreas Schneider <asn@samba.org> | 2015-10-28 08:15:37 +0100 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2015-10-28 10:24:56 +0100 |
commit | 78cc57fb564738e8e0df11719a60de3b6ebe0c6c (patch) | |
tree | 0e368294ca18a4c1d0f24fccaf0e1ce9a15afede | |
parent | 218e64271dc0947721a0592e48f9f59f73565580 (diff) | |
download | uid_wrapper-78cc57fb564738e8e0df11719a60de3b6ebe0c6c.tar.gz uid_wrapper-78cc57fb564738e8e0df11719a60de3b6ebe0c6c.tar.xz uid_wrapper-78cc57fb564738e8e0df11719a60de3b6ebe0c6c.zip |
tests: Move syscall setuid32 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_setuid32.c | 92 | ||||
-rw-r--r-- | tests/test_syscall_uid32.c | 16 |
3 files changed, 93 insertions, 16 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c04d788..6092fe2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -68,6 +68,7 @@ set(UWRAP_TESTS if (HAVE_LINUX_32BIT_SYSCALLS) set(UWRAP_TESTS ${UWRAP_TESTS} + test_syscall_setuid32 test_syscall_uid32 test_syscall_gid32) endif (HAVE_LINUX_32BIT_SYSCALLS) diff --git a/tests/test_syscall_setuid32.c b/tests/test_syscall_setuid32.c new file mode 100644 index 0000000..e7532f7 --- /dev/null +++ b/tests/test_syscall_setuid32.c @@ -0,0 +1,92 @@ +#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_setuid32(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 + +#ifndef BSD + /* BSD sets 0xFFFFFF as the UID number in this case */ + rc = syscall(SYS_setuid32, -1); + assert_int_equal(rc, -1); + assert_int_equal(errno, EINVAL); +#endif + + u = getuid(); + assert_int_equal(u, 0x0); + +#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 + + rc = syscall(SYS_setuid32, 0x5555); + assert_return_code(rc, errno); + +#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, 0x5555); + assert_int_equal(cp_euid, 0x5555); + assert_int_equal(cp_suid, 0x5555); +#endif + + u = getuid(); + assert_int_equal(u, 0x5555); + + u = geteuid(); + assert_int_equal(u, 0x5555); + + rc = syscall(SYS_setuid32, 0x0); + assert_int_equal(rc, -1); + assert_int_equal(errno, EPERM); +} + +int main(void) { + int rc; + + const struct CMUnitTest uwrap_tests[] = { + cmocka_unit_test(test_uwrap_syscall_setuid32), + }; + + 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 0e6a585..dd64a25 100644 --- a/tests/test_syscall_uid32.c +++ b/tests/test_syscall_uid32.c @@ -18,21 +18,6 @@ #include <syscall.h> #endif -static void test_uwrap_syscall_setuid32(void **state) -{ - long int rc; - uid_t u; - - (void) state; /* unused */ - - rc = syscall(SYS_setuid32, 1); - assert_int_equal(rc, 0); - - u = getuid(); - assert_int_equal(u, 1); - assert_int_equal(u, syscall(SYS_getuid32)); -} - static void test_uwrap_syscall_setreuid32(void **state) { long int rc; @@ -90,7 +75,6 @@ int main(void) { int rc; const struct CMUnitTest uwrap_tests[] = { - cmocka_unit_test(test_uwrap_syscall_setuid32), cmocka_unit_test(test_uwrap_syscall_setreuid32), cmocka_unit_test(test_uwrap_syscall_setresuid32), }; |