[SCM] UID Wrapper Repository - branch master updated

Andreas Schneider asn at samba.org
Mon Aug 17 08:45:25 UTC 2015


The branch, master has been updated
       via  319c52b uwrap: Removed double newline
       via  bd88d4f tests: Add 32bit syscall gid tests
       via  677b0da tests: Improve syscall gid tests
       via  ba8c6cf tests: Add 32bit syscall uid tests
       via  9daf8ee tests: Improve syscall uid tests
       via  40c0bc9 tests: Rename testsuite to test_syscall_gid
       via  6e5ed70 tests: Move syscall uid tests to own test
       via  4b8f2f3 tests: Move syscall test to own test
       via  ff30175 tests: Move set(re)gid function to own test
       via  cf86be4 tests: Move set(re)uid function to own test
      from  c023936 cmake: Do not optimize the code by default

https://git.samba.org/?p=uid_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 319c52b80a5186f8f375722c143172867e740e57
Author: Andreas Schneider <asn at samba.org>
Date:   Mon Aug 17 10:43:55 2015 +0200

    uwrap: Removed double newline
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit bd88d4f14a0da022db7062ac8d63475a2fc279e8
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Aug 14 09:04:13 2015 +0200

    tests: Add 32bit syscall gid tests
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 677b0da7efe794213ea94270d9761617173470f7
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Aug 14 09:01:02 2015 +0200

    tests: Improve syscall gid tests
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit ba8c6cf15280f03d60929d0eb89be6cd9957b480
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Aug 14 08:52:08 2015 +0200

    tests: Add 32bit syscall uid tests
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 9daf8ee7f8e5f9cffa1df5714f8d85f648784831
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Aug 14 08:43:55 2015 +0200

    tests: Improve syscall uid tests
    
    The plan is to have a 32bit version compiled dependent on the support
    for it.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 40c0bc993955d6c6b069cbf945db0f2dc8a9a7b5
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Aug 14 08:27:14 2015 +0200

    tests: Rename testsuite to test_syscall_gid
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 6e5ed70966ebd1db0bcfcf7151bc6758404bf9cc
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Aug 14 08:26:17 2015 +0200

    tests: Move syscall uid tests to own test
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 4b8f2f3b28145d266207e3190efcbcf02a7690b2
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Aug 14 08:20:57 2015 +0200

    tests: Move syscall test to own test
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit ff30175461c490ce9329a6fe043c2f59ff51bdb1
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Aug 14 08:17:34 2015 +0200

    tests: Move set(re)gid function to own test
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit cf86be4c1ff0c37b05ff85fa6d5c0560e75c050e
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Aug 14 08:11:58 2015 +0200

    tests: Move set(re)uid function to own test
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 src/uid_wrapper.c          |   2 +-
 tests/CMakeLists.txt       |  62 ++++--
 tests/test_gid.c           | 157 ++++++++++++++
 tests/test_syscall.c       |  62 ++++++
 tests/test_syscall_gid.c   | 135 +++++++++++++
 tests/test_syscall_gid32.c | 127 ++++++++++++
 tests/test_syscall_uid.c   | 106 ++++++++++
 tests/test_syscall_uid32.c | 101 +++++++++
 tests/test_uid.c           | 134 ++++++++++++
 tests/testsuite.c          | 494 ---------------------------------------------
 10 files changed, 866 insertions(+), 514 deletions(-)
 create mode 100644 tests/test_gid.c
 create mode 100644 tests/test_syscall.c
 create mode 100644 tests/test_syscall_gid.c
 create mode 100644 tests/test_syscall_gid32.c
 create mode 100644 tests/test_syscall_uid.c
 create mode 100644 tests/test_syscall_uid32.c
 create mode 100644 tests/test_uid.c
 delete mode 100644 tests/testsuite.c


Changeset truncated at 500 lines:

diff --git a/src/uid_wrapper.c b/src/uid_wrapper.c
index a5e4fe5..2961b87 100644
--- a/src/uid_wrapper.c
+++ b/src/uid_wrapper.c
@@ -1634,7 +1634,7 @@ static long int uwrap_syscall (long int sysno, va_list vp)
 			break;
 		default:
 			UWRAP_LOG(UWRAP_LOG_DEBUG,
-				  "UID_WRAPPER calling non-wrapped syscall %lu\n",
+				  "UID_WRAPPER calling non-wrapped syscall %lu",
 				  sysno);
 
 			rc = libc_vsyscall(sysno, vp);
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6e59940..997d551 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -6,45 +6,69 @@ include_directories(
   ${CMOCKA_INCLUDE_DIR}
 )
 
+set(PRELOAD_LIBS ${UID_WRAPPER_LOCATION})
+
 if (OSX)
-    set(TEST_ENVIRONMENT DYLD_FORCE_FLAT_NAMESPACE=1;DYLD_INSERT_LIBRARIES=${UID_WRAPPER_LOCATION};UID_WRAPPER=1)
+    set(TEST_ENVIRONMENT DYLD_FORCE_FLAT_NAMESPACE=1;DYLD_INSERT_LIBRARIES=${PRELOAD_LIBS};UID_WRAPPER=1)
     add_definitions(-DOSX)
 else ()
-    set(TEST_ENVIRONMENT LD_PRELOAD=${UID_WRAPPER_LOCATION};UID_WRAPPER=1)
+    set(TEST_ENVIRONMENT LD_PRELOAD=${PRELOAD_LIBS})
 endif ()
 
-add_cmocka_test(testsuite testsuite.c ${CMOCKA_LIBRARY})
-set_property(
-    TEST
-        testsuite
-    PROPERTY
-        ENVIRONMENT ${TEST_ENVIRONMENT})
+set(TESTSUITE_LIBRARIES ${UWRAP_REQUIRED_LIBRARIES} ${CMOCKA_LIBRARY})
+
+set(UWRAP_TESTS
+    test_uid
+    test_gid
+    test_syscall
+    test_syscall_uid
+    test_syscall_gid)
 
+if (HAVE_LINUX_32BIT_SYSCALLS)
+    set(UWRAP_TESTS
+        ${UWRAP_TESTS}
+        test_syscall_uid32
+        test_syscall_gid32)
+endif (HAVE_LINUX_32BIT_SYSCALLS)
+
+foreach(_UWRAP_TEST ${UWRAP_TESTS})
+    add_cmocka_test(${_UWRAP_TEST} ${_UWRAP_TEST}.c ${TESTSUITE_LIBRARIES})
+
+    set_property(
+        TEST
+            ${_UWRAP_TEST}
+        PROPERTY
+            ENVIRONMENT ${TEST_ENVIRONMENT};UID_WRAPPER=1)
+endforeach()
+
+# helper library implementing uid_wrapper_enabled()
 add_library(uwrap_enabled SHARED uwrap_enabled.c)
+
 add_cmocka_test(test_uwrap_enabled test_uwrap_enabled.c ${CMOCKA_LIBRARY} uwrap_enabled)
 set_property(
     TEST
         test_uwrap_enabled
     PROPERTY
-        ENVIRONMENT ${TEST_ENVIRONMENT})
+        ENVIRONMENT ${TEST_ENVIRONMENT};UID_WRAPPER=1)
 
-if (LINUX OR OSX)
-add_cmocka_test(test_glibc_thread_support test_glibc_thread_support.c ${CMOCKA_LIBRARY})
-target_link_libraries(test_glibc_thread_support ${CMAKE_THREAD_LIBS_INIT})
+add_cmocka_test(test_uwrap_disabled test_uwrap_disabled.c ${CMOCKA_LIBRARY})
 set_property(
     TEST
-        test_glibc_thread_support
+        test_uwrap_disabled
     PROPERTY
         ENVIRONMENT ${TEST_ENVIRONMENT})
+
+if (LINUX OR OSX)
+    add_cmocka_test(test_glibc_thread_support test_glibc_thread_support.c ${CMOCKA_LIBRARY})
+    target_link_libraries(test_glibc_thread_support ${CMAKE_THREAD_LIBS_INIT})
+    set_property(
+        TEST
+            test_glibc_thread_support
+        PROPERTY
+            ENVIRONMENT ${TEST_ENVIRONMENT};UID_WRAPPER=1)
 endif(LINUX OR OSX)
 
 if (LINUX)
     add_executable(getuids getuids.c)
 endif (LINUX)
 
-add_cmocka_test(test_uwrap_disabled test_uwrap_disabled.c ${CMOCKA_LIBRARY})
-set_property(
-    TEST
-        test_uwrap_disabled
-    PROPERTY
-        ENVIRONMENT LD_PRELOAD=${CMAKE_BINARY_DIR}/src/libuid_wrapper.so)
diff --git a/tests/test_gid.c b/tests/test_gid.c
new file mode 100644
index 0000000..f5aecf6
--- /dev/null
+++ b/tests/test_gid.c
@@ -0,0 +1,157 @@
+#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>
+
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
+static void test_uwrap_setegid(void **state)
+{
+	int rc;
+	uid_t u;
+
+	(void) state; /* unused */
+
+	rc = setegid(0);
+	assert_int_equal(rc, 0);
+
+	u = getegid();
+#ifdef SYS_getegid /* Not available on Solaris */
+	assert_int_equal(u, syscall(SYS_getegid));
+#endif
+
+	rc = setegid(42);
+	assert_int_equal(rc, 0);
+
+	u = getegid();
+	assert_int_equal(u, 42);
+}
+
+#ifdef HAVE_SETREGID
+static void test_uwrap_setregid(void **state)
+{
+	int rc;
+	uid_t u;
+
+	(void) state; /* unused */
+
+	rc = setregid(1, 2);
+	assert_int_equal(rc, 0);
+
+	u = getgid();
+	assert_int_equal(u, 1);
+
+	u = getegid();
+	assert_int_equal(u, 2);
+}
+#endif
+
+#ifdef HAVE_SETRESGID
+static void test_uwrap_setresgid(void **state)
+{
+	int rc;
+	uid_t u;
+
+	(void) state; /* unused */
+
+	rc = setresgid(1, 2, -1);
+	assert_int_equal(rc, 0);
+
+	u = getgid();
+	assert_int_equal(u, 1);
+
+	u = getegid();
+	assert_int_equal(u, 2);
+}
+#endif
+
+static void test_uwrap_setgid(void **state)
+{
+	int rc;
+	gid_t u;
+
+	(void) state; /* unused */
+
+	rc = setgid(-1);
+	assert_int_equal(rc, -1);
+
+	rc = setgid(42);
+	assert_int_equal(rc, 0);
+
+	u = getgid();
+	assert_int_equal(u, 42);
+}
+
+static void test_uwrap_getgroups(void **state)
+{
+	gid_t rlist[20] = {0};
+	int num_groups;
+	int rc;
+
+	(void) state; /* unused */
+	num_groups = getgroups(0, NULL);
+	assert_int_not_equal(num_groups, -1);
+
+	rc = getgroups(ARRAY_SIZE(rlist), rlist);
+	assert_int_equal(rc, num_groups);
+	assert_int_equal(rlist[0], getegid());
+}
+
+static void test_uwrap_setgroups(void **state)
+{
+	gid_t glist[] = { 100, 200, 300, 400, 500 };
+	gid_t rlist[16];
+	int rc;
+
+	(void) state; /* unused */
+
+	rc = setgroups(ARRAY_SIZE(glist), glist);
+	assert_int_equal(rc, 0);
+
+	rc = getgroups(ARRAY_SIZE(rlist), rlist);
+	assert_int_equal(rc, 5);
+
+	assert_memory_equal(glist, rlist, sizeof(glist));
+
+	/* Drop all supplementary groups. This is often done by daemons */
+	memset(rlist, 0, sizeof(rlist));
+
+	rc = setgroups(0, NULL);
+	assert_int_equal(rc, 0);
+
+	rc = getgroups(ARRAY_SIZE(rlist), rlist);
+	assert_int_equal(rc, 0);
+
+	assert_int_equal(rlist[0], 0);
+}
+
+int main(void) {
+	int rc;
+
+	const struct CMUnitTest uwrap_tests[] = {
+		cmocka_unit_test(test_uwrap_getgroups),
+
+		cmocka_unit_test(test_uwrap_setegid),
+#ifdef HAVE_SETREGID
+		cmocka_unit_test(test_uwrap_setregid),
+#endif
+#ifdef HAVE_SETRESGID
+		cmocka_unit_test(test_uwrap_setresgid),
+#endif
+		cmocka_unit_test(test_uwrap_setgid),
+		cmocka_unit_test(test_uwrap_setgroups),
+	};
+
+	rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL);
+
+	return rc;
+}
diff --git a/tests/test_syscall.c b/tests/test_syscall.c
new file mode 100644
index 0000000..c43f1f9
--- /dev/null
+++ b/tests/test_syscall.c
@@ -0,0 +1,62 @@
+#include "config.h"
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+#ifdef HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
+#ifdef HAVE_SYSCALL_H
+#include <syscall.h>
+#endif
+
+#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
+
+static void test_uwrap_syscall(void **state)
+{
+	long int rc;
+	struct timeval tv1, tv2;
+	struct timezone tz1, tz2;
+
+	(void) state; /* unused */
+
+	rc = syscall(SYS_getpid);
+	assert_int_equal(rc, getpid());
+
+	ZERO_STRUCT(tv1);
+	ZERO_STRUCT(tv2);
+	ZERO_STRUCT(tz1);
+	ZERO_STRUCT(tz2);
+
+	rc = gettimeofday(&tv1, &tz1);
+	assert_int_equal(rc, 0);
+
+#ifdef OSX
+	tv2.tv_sec = syscall(SYS_gettimeofday, &tv2, NULL);
+#else
+	rc = syscall(SYS_gettimeofday, &tv2, &tz2);
+	assert_int_equal(rc, 0);
+	assert_int_equal(tz1.tz_dsttime, tz2.tz_dsttime);
+	assert_int_equal(tz1.tz_minuteswest, tz2.tz_minuteswest);
+#endif
+
+	assert_int_equal(tv1.tv_sec, tv2.tv_sec);
+}
+
+int main(void) {
+	int rc;
+
+	const struct CMUnitTest uwrap_tests[] = {
+		cmocka_unit_test(test_uwrap_syscall),
+	};
+
+	rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL);
+
+	return rc;
+}
diff --git a/tests/test_syscall_gid.c b/tests/test_syscall_gid.c
new file mode 100644
index 0000000..d87bb84
--- /dev/null
+++ b/tests/test_syscall_gid.c
@@ -0,0 +1,135 @@
+#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
+
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
+static void test_uwrap_syscall_setgid(void **state)
+{
+	long int rc;
+	gid_t g;
+
+	(void) state; /* unused */
+
+	rc = syscall(SYS_setgid, 1);
+	assert_int_equal(rc, 0);
+
+	g = getgid();
+	assert_int_equal(g, 1);
+	assert_int_equal(g, syscall(SYS_getgid));
+}
+
+static void test_uwrap_syscall_setregid(void **state)
+{
+	long int rc;
+	gid_t g;
+
+	(void) state; /* unused */
+
+	rc = syscall(SYS_setregid, 2, 0);
+	assert_int_equal(rc, 0);
+
+	g = getegid();
+	assert_int_equal(g, 0);
+	assert_int_equal(g, syscall(SYS_getegid));
+
+	rc = syscall(SYS_setregid, -1, 42);
+	assert_int_equal(rc, 0);
+
+	g = getgid();
+	assert_int_equal(g, 2);
+	g = getegid();
+	assert_int_equal(g, 42);
+}
+
+#if defined(SYS_setresgid) && defined(SYS_getresgid)
+static void test_uwrap_syscall_setresgid(void **state)
+{
+	long int rc;
+	gid_t g;
+	gid_t g_r, g_e, g_s;
+
+	(void) state; /* unused */
+
+	rc = syscall(SYS_setresgid, 42, 0, -1);
+	assert_int_equal(rc, 0);
+
+	g = getegid();
+	rc = syscall(SYS_getresgid, &g_r, &g_e, &g_s);
+	assert_return_code(rc, errno);
+
+	assert_int_equal(g_r, 42);
+	assert_int_equal(g, g_e);
+
+	rc = syscall(SYS_setregid, -1, 42);
+	assert_return_code(rc, errno);
+
+	g = getegid();
+	assert_int_equal(g, 42);
+}
+#endif
+
+#if defined(SYS_setgroups)
+static void test_uwrap_syscall_setgroups(void **state)
+{
+	gid_t glist[] = { 100, 200, 300, 400, 500 };
+	gid_t rlist[16];
+	int rc = -1;
+
+	(void) state; /* unused */
+
+	rc = syscall(SYS_setgroups, ARRAY_SIZE(glist), glist);
+	assert_int_equal(rc, 0);
+
+	rc = getgroups(ARRAY_SIZE(rlist), rlist);
+	assert_int_equal(rc, 5);
+
+	assert_memory_equal(glist, rlist, sizeof(glist));
+
+	/* Drop all supplementary groups. This is often done by daemons */
+	memset(rlist, 0, sizeof(rlist));
+	rc = syscall(SYS_setgroups, 0, NULL);
+	assert_int_equal(rc, 0);
+
+	rc = getgroups(ARRAY_SIZE(rlist), rlist);
+	assert_int_equal(rc, 0);
+
+	assert_int_equal(rlist[0], 0);
+}
+#endif
+
+int main(void) {
+	int rc;
+
+	const struct CMUnitTest uwrap_tests[] = {
+		cmocka_unit_test(test_uwrap_syscall_setgid),
+		cmocka_unit_test(test_uwrap_syscall_setregid),
+#if defined(SYS_setresgid) && defined(SYS_getresgid)
+		cmocka_unit_test(test_uwrap_syscall_setresgid),
+#endif
+#if defined(SYS_setgroups)
+		cmocka_unit_test(test_uwrap_syscall_setgroups),
+#endif
+	};
+
+	rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL);
+
+	return rc;
+}
diff --git a/tests/test_syscall_gid32.c b/tests/test_syscall_gid32.c
new file mode 100644
index 0000000..04b8c9e
--- /dev/null
+++ b/tests/test_syscall_gid32.c
@@ -0,0 +1,127 @@
+#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>


-- 
UID Wrapper Repository



More information about the samba-cvs mailing list