uwrap: Always enable logging
[uid_wrapper.git] / tests / test_syscall_setgroups32.c
1 #include "config.h"
2
3 #include <stdarg.h>
4 #include <stddef.h>
5 #include <setjmp.h>
6 #include <cmocka.h>
7
8 #include <errno.h>
9 #include <string.h>
10 #include <sys/types.h>
11 #include <unistd.h>
12
13 #include <grp.h>
14
15 #ifdef HAVE_SYS_SYSCALL_H
16 #include <sys/syscall.h>
17 #endif
18 #ifdef HAVE_SYSCALL_H
19 #include <syscall.h>
20 #endif
21
22 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
23
24 static void test_uwrap_syscall_setgroups32(void **state)
25 {
26         gid_t glist[] = { 100, 200, 300, 400, 500 };
27         gid_t rlist[16];
28         int rc = -1;
29
30         (void) state; /* unused */
31
32         rc = syscall(SYS_setgroups32, ARRAY_SIZE(glist), glist);
33         assert_int_equal(rc, 0);
34
35         rc = getgroups(ARRAY_SIZE(rlist), rlist);
36         assert_int_equal(rc, 5);
37
38         assert_memory_equal(glist, rlist, sizeof(glist));
39
40         /* Drop all supplementary groups. This is often done by daemons */
41         memset(rlist, 0, sizeof(rlist));
42         rc = syscall(SYS_setgroups32, 0, NULL);
43         assert_int_equal(rc, 0);
44
45         rc = getgroups(ARRAY_SIZE(rlist), rlist);
46         assert_int_equal(rc, 0);
47
48         assert_int_equal(rlist[0], 0);
49 }
50
51 int main(void) {
52         int rc;
53
54         const struct CMUnitTest uwrap_tests[] = {
55                 cmocka_unit_test(test_uwrap_syscall_setgroups32),
56         };
57
58         rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL);
59
60         return rc;
61 }