1 /*
2 * Copyright (C) Bull S.A. 2001
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /*
21 * Test Name: setgroups04
22 *
23 * Test Description:
24 * Verify that, setgroups() fails with -1 and sets errno to EFAULT if the list has an invalid address.
25 *
26 * Expected Result:
27 * setgroups() should fail with return value -1 and set expected errno.
28 *
29 * Algorithm:
30 * Setup:
31 * Setup signal handling.
32 * Pause for SIGUSR1 if option specified.
33 *
34 * Test:
35 * Loop if the proper options are given.
36 * Execute system call
37 * Check return code, if system call failed (return=-1)
38 * if errno set == expected errno
39 * Issue sys call fails with expected return value and errno.
40 * Otherwise,
41 * Issue sys call fails with unexpected errno.
42 * Otherwise,
43 * Issue sys call returns unexpected value.
44 *
45 * Cleanup:
46 * Print errno log and/or timing stats if options given
47 *
48 * Usage: <for command-line>
49 * setgroups04 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
50 * where, -c n : Run n copies concurrently.
51 * -f : Turn off functionality Testing.
52 * -i n : Execute test n times.
53 * -I x : Execute test for x seconds.
54 * -P x : Pause for x seconds between iterations.
55 * -t : Turn on syscall timing.
56 *
57 * HISTORY
58 * 05/2002 Ported by Andr� Merlier
59 *
60 * RESTRICTIONS:
61 * none.
62 *
63 */
64 #include <sys/types.h>
65 #include <sys/param.h>
66 #include <unistd.h>
67 #include <errno.h>
68 #include <pwd.h>
69 #include <grp.h>
70
71 #include "test.h"
72
73 /*
74 * Don't forget to remove USE_LEGACY_COMPAT_16_H from Makefile after
75 * rewriting this test to the new API.
76 */
77 #include "compat_16.h"
78
79 TCID_DEFINE(setgroups04);
80 int TST_TOTAL = 1;
81
82 GID_T groups_list[NGROUPS];
83
84 void setup(); /* setup function for the test */
85 void cleanup(); /* cleanup function for the test */
86
87 #if !defined(UCLINUX)
88
main(int ac,char ** av)89 int main(int ac, char **av)
90 {
91 int lc;
92 int gidsetsize; /* total no. of groups */
93 char *test_desc; /* test specific error message */
94
95 tst_parse_opts(ac, av, NULL, NULL);
96
97 /* Perform setup for test */
98 setup();
99
100 for (lc = 0; TEST_LOOPING(lc); lc++) {
101
102 tst_count = 0;
103
104 gidsetsize = NGROUPS;
105 test_desc = "EFAULT";
106
107 /*
108 * Call setgroups() to test condition
109 * verify that it fails with -1 return value and
110 * sets appropriate errno.
111 */
112 TEST(SETGROUPS(cleanup, gidsetsize, sbrk(0)));
113
114 if (TEST_RETURN != -1) {
115 tst_resm(TFAIL, "setgroups() returned %ld, "
116 "expected -1, errno=%d", TEST_RETURN,
117 EFAULT);
118 } else {
119
120 if (TEST_ERRNO == EFAULT) {
121 tst_resm(TPASS,
122 "setgroups() fails with expected "
123 "error EFAULT errno:%d", TEST_ERRNO);
124 } else {
125 tst_resm(TFAIL, "setgroups() fails, %s, "
126 "errno=%d, expected errno=%d",
127 test_desc, TEST_ERRNO, EFAULT);
128 }
129 }
130
131 }
132
133 cleanup();
134 tst_exit();
135
136 }
137
138 #else
139
main(void)140 int main(void)
141 {
142 tst_resm(TINFO, "test is not available on uClinux");
143 tst_exit();
144 }
145
146 #endif /* if !defined(UCLINUX) */
147
148 /*
149 * setup()
150 */
setup(void)151 void setup(void)
152 {
153 tst_require_root();
154
155 tst_sig(NOFORK, DEF_HANDLER, cleanup);
156
157 TEST_PAUSE;
158
159 }
160
161 /*
162 * cleanup()
163 */
cleanup(void)164 void cleanup(void)
165 {
166
167 }
168