tests: Move syscall setuid32 test to own executable
authorAndreas Schneider <asn@samba.org>
Wed, 28 Oct 2015 07:15:37 +0000 (08:15 +0100)
committerAndreas Schneider <asn@samba.org>
Wed, 28 Oct 2015 09:24:56 +0000 (10:24 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
tests/CMakeLists.txt
tests/test_syscall_setuid32.c [new file with mode: 0644]
tests/test_syscall_uid32.c

index c04d7883b28ff5e58f4bf39c0aca82473d1f9e90..6092fe26098a1947285973d709e859ebac39a694 100644 (file)
@@ -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 (file)
index 0000000..e7532f7
--- /dev/null
@@ -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;
+}
index 0e6a585ab793472aa19a66e0b1373e84bbe58c92..dd64a25a2dce2db09ff8ca02e7499965d2b61455 100644 (file)
 #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),
        };