aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2015-10-08 15:23:24 +0200
committerAndreas Schneider <asn@samba.org>2015-10-27 14:55:44 +0100
commitee7795df63783a787e40dd5dfcf41574a0dfc3a7 (patch)
tree3371c1042885c0cc674fdd1a08b1d3efcd601cc6
parenta6eb46785f68934376b103796273ffdaf1f6f5a9 (diff)
downloaduid_wrapper-ee7795df63783a787e40dd5dfcf41574a0dfc3a7.tar.gz
uid_wrapper-ee7795df63783a787e40dd5dfcf41574a0dfc3a7.tar.xz
uid_wrapper-ee7795df63783a787e40dd5dfcf41574a0dfc3a7.zip
tests: Add new test_setuid_euid1 and test_setuid_euid2
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Andreas Schneider <asn@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/test_setuid_euid1.c73
-rw-r--r--tests/test_setuid_euid2.c83
3 files changed, 157 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index cf8b830..a96eff2 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -26,7 +26,7 @@ if (HAVE_SETREUID)
endif (HAVE_SETREUID)
if (HAVE_SETRESUID)
- list(APPEND UWRAP_UID_TESTS test_setresuid)
+ list(APPEND UWRAP_UID_TESTS test_setresuid test_setuid_euid1 test_setuid_euid2)
if (HAVE_GETRESUID)
list(APPEND UWRAP_UID_TESTS test_getresuid)
endif (HAVE_GETRESUID)
diff --git a/tests/test_setuid_euid1.c b/tests/test_setuid_euid1.c
new file mode 100644
index 0000000..b4ceb73
--- /dev/null
+++ b/tests/test_setuid_euid1.c
@@ -0,0 +1,73 @@
+#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>
+
+static void test_uwrap_setuid(void **state)
+{
+ int rc;
+ uid_t u;
+ uid_t cp_ruid, cp_euid, cp_suid;
+
+ (void) state; /* unused */
+
+ 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);
+
+ u = geteuid();
+ assert_int_equal(u, 0x0);
+
+ rc = setresuid(0x4444, 0x5555, 0x6666);
+ assert_int_equal(rc, 0);
+
+ 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, 0x6666);
+
+ u = getuid();
+ assert_int_equal(u, 0x4444);
+
+ u = geteuid();
+ assert_int_equal(u, 0x5555);
+
+ rc = setuid(0x5555);
+ assert_int_equal(rc, -1);
+ assert_int_equal(errno, EPERM);
+
+ rc = setuid(0x4444);
+ assert_return_code(rc, errno);
+
+ 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, 0x4444);
+ assert_int_equal(cp_suid, 0x6666);
+}
+
+int main(void) {
+ int rc;
+
+ const struct CMUnitTest uwrap_tests[] = {
+ cmocka_unit_test(test_uwrap_setuid),
+ };
+
+ rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL);
+
+ return rc;
+}
diff --git a/tests/test_setuid_euid2.c b/tests/test_setuid_euid2.c
new file mode 100644
index 0000000..a722de9
--- /dev/null
+++ b/tests/test_setuid_euid2.c
@@ -0,0 +1,83 @@
+#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>
+
+static void test_uwrap_setuid(void **state)
+{
+ int rc;
+ uid_t u;
+ uid_t cp_ruid, cp_euid, cp_suid;
+
+ (void) state; /* unused */
+
+ 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);
+
+ u = getuid();
+ assert_int_equal(u, 0x0);
+
+ u = geteuid();
+ assert_int_equal(u, 0x0);
+
+ rc = setresuid(0x4444, 0x5555, 0x6666);
+ assert_int_equal(rc, 0);
+
+ 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, 0x6666);
+
+ u = getuid();
+ assert_int_equal(u, 0x4444);
+
+ u = geteuid();
+ assert_int_equal(u, 0x5555);
+
+
+ rc = setuid(0x5555);
+ assert_int_equal(rc, -1);
+ assert_int_equal(errno, EPERM);
+
+ rc = setuid(0x6666);
+ assert_return_code(rc, errno);
+
+ 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, 0x6666);
+ assert_int_equal(cp_suid, 0x6666);
+
+ u = getuid();
+ assert_int_equal(u, 0x4444);
+
+ u = geteuid();
+ assert_int_equal(u, 0x6666);
+}
+
+int main(void) {
+ int rc;
+
+ const struct CMUnitTest uwrap_tests[] = {
+ cmocka_unit_test(test_uwrap_setuid),
+ };
+
+ rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL);
+
+ return rc;
+}