1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) Linux Test Project, 2003-2023
5*49cdfc7eSAndroid Build Coastguard Worker * 07/2001 Ported by Wayne Boyer
6*49cdfc7eSAndroid Build Coastguard Worker */
7*49cdfc7eSAndroid Build Coastguard Worker
8*49cdfc7eSAndroid Build Coastguard Worker /*\
9*49cdfc7eSAndroid Build Coastguard Worker * [Description]
10*49cdfc7eSAndroid Build Coastguard Worker *
11*49cdfc7eSAndroid Build Coastguard Worker * Check that root process can setgroups() supplementary group ID and verify
12*49cdfc7eSAndroid Build Coastguard Worker * that getgroups() returns the previously set ID.
13*49cdfc7eSAndroid Build Coastguard Worker */
14*49cdfc7eSAndroid Build Coastguard Worker
15*49cdfc7eSAndroid Build Coastguard Worker #include <pwd.h>
16*49cdfc7eSAndroid Build Coastguard Worker
17*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
18*49cdfc7eSAndroid Build Coastguard Worker #include "compat_tst_16.h"
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker static GID_T *groups_get, *groups_set;
21*49cdfc7eSAndroid Build Coastguard Worker
verify_setgroups(void)22*49cdfc7eSAndroid Build Coastguard Worker static void verify_setgroups(void)
23*49cdfc7eSAndroid Build Coastguard Worker {
24*49cdfc7eSAndroid Build Coastguard Worker groups_set[0] = 42;
25*49cdfc7eSAndroid Build Coastguard Worker
26*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_PASS(SETGROUPS(1, groups_set));
27*49cdfc7eSAndroid Build Coastguard Worker
28*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_VAL(GETGROUPS(1, groups_get), 1);
29*49cdfc7eSAndroid Build Coastguard Worker
30*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_EQ_LI(groups_get[0], groups_set[0]);
31*49cdfc7eSAndroid Build Coastguard Worker
32*49cdfc7eSAndroid Build Coastguard Worker groups_get[0] = 0;
33*49cdfc7eSAndroid Build Coastguard Worker }
34*49cdfc7eSAndroid Build Coastguard Worker
35*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
36*49cdfc7eSAndroid Build Coastguard Worker .test_all = verify_setgroups,
37*49cdfc7eSAndroid Build Coastguard Worker .bufs = (struct tst_buffers []) {
38*49cdfc7eSAndroid Build Coastguard Worker {&groups_get, .size = sizeof(GID_T)},
39*49cdfc7eSAndroid Build Coastguard Worker {&groups_set, .size = sizeof(GID_T)},
40*49cdfc7eSAndroid Build Coastguard Worker {},
41*49cdfc7eSAndroid Build Coastguard Worker },
42*49cdfc7eSAndroid Build Coastguard Worker .needs_root = 1,
43*49cdfc7eSAndroid Build Coastguard Worker };
44