diff options
author | Andreas Schneider <asn@samba.org> | 2015-10-28 08:36:53 +0100 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2015-10-28 10:25:05 +0100 |
commit | 1a90764f7effea83b54f3e85bfdf2579ef796218 (patch) | |
tree | 3e0da5dbdce2ad8ebfdb6523e5f385a092429c43 | |
parent | 5ebd9cd421eda784ecf095e945860631ebbb1a33 (diff) | |
download | uid_wrapper-1a90764f7effea83b54f3e85bfdf2579ef796218.tar.gz uid_wrapper-1a90764f7effea83b54f3e85bfdf2579ef796218.tar.xz uid_wrapper-1a90764f7effea83b54f3e85bfdf2579ef796218.zip |
tests: Move syscall setgid32 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 | 16 | ||||
-rw-r--r-- | tests/test_syscall_setgid32.c | 158 |
3 files changed, 159 insertions, 16 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 41b1ce2..82b4eab 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -71,6 +71,7 @@ if (HAVE_LINUX_32BIT_SYSCALLS) test_syscall_setuid32 test_syscall_setreuid32 test_syscall_setresuid32 + test_syscall_setgid32 test_syscall_gid32) endif (HAVE_LINUX_32BIT_SYSCALLS) diff --git a/tests/test_syscall_gid32.c b/tests/test_syscall_gid32.c index 04b8c9e..a810cb0 100644 --- a/tests/test_syscall_gid32.c +++ b/tests/test_syscall_gid32.c @@ -21,21 +21,6 @@ #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) -static void test_uwrap_syscall_setgid32(void **state) -{ - long int rc; - gid_t g; - - (void) state; /* unused */ - - rc = syscall(SYS_setgid32, 1); - assert_int_equal(rc, 0); - - g = getgid(); - assert_int_equal(g, 1); - assert_int_equal(g, syscall(SYS_getgid32)); -} - static void test_uwrap_syscall_setregid32(void **state) { long int rc; @@ -115,7 +100,6 @@ int main(void) { int rc; const struct CMUnitTest uwrap_tests[] = { - cmocka_unit_test(test_uwrap_syscall_setgid32), cmocka_unit_test(test_uwrap_syscall_setregid32), cmocka_unit_test(test_uwrap_syscall_setresgid32), cmocka_unit_test(test_uwrap_syscall_setgroups32), diff --git a/tests/test_syscall_setgid32.c b/tests/test_syscall_setgid32.c new file mode 100644 index 0000000..e01a2b4 --- /dev/null +++ b/tests/test_syscall_setgid32.c @@ -0,0 +1,158 @@ +#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_setgid32_root(void **state) +{ + 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_setgid32, -1); + assert_int_equal(rc, -1); + assert_int_equal(errno, EINVAL); + +#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 + + rc = syscall(SYS_setgid32, 0x5555); + 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, 0x5555); + assert_int_equal(cp_sgid, 0x5555); +#endif + + g = getgid(); + assert_int_equal(g, 0x5555); + + g = getegid(); + assert_int_equal(g, 0x5555); + + rc = setgid(0); + assert_return_code(rc, errno); +} + +static void test_uwrap_syscall_setgid32_user(void **state) +{ + int rc; + uid_t u; +#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 + + setuid(0x5555); + assert_return_code(rc, errno); + + u = getuid(); + assert_int_equal(u, 0x5555); + u = geteuid(); + assert_int_equal(u, 0x5555); + +#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 + + rc = syscall(SYS_setgid32, 0x5555); + assert_int_equal(rc, -1); + assert_int_equal(errno, EPERM); + +#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 + + rc = syscall(SYS_setgid32, 0x0); + assert_return_code(rc, errno); +} + +int main(void) { + int rc; + + const struct CMUnitTest uwrap_tests[] = { + cmocka_unit_test(test_uwrap_syscall_setgid32_root), + cmocka_unit_test(test_uwrap_syscall_setgid32_user), + }; + + rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL); + + return rc; +} + |