blob: 381d886a0d9f4ac4283cdfe89977765cc6a3578b [file] [log] [blame]
robbiew8da54972002-05-30 18:50:35 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiew8da54972002-05-30 18:50:35 +000018 */
19
subrata_modak4bb656a2009-02-26 12:02:09 +000020/*
robbiew8da54972002-05-30 18:50:35 +000021 * 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 <unistd.h>
66#include <errno.h>
67#include <pwd.h>
68#include <grp.h>
69
70#include "test.h"
robbiew8da54972002-05-30 18:50:35 +000071
subrata_modak34a572a2008-08-27 12:02:42 +000072#include "compat_16.h"
73
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020074TCID_DEFINE(setgroups04);
robbiew8da54972002-05-30 18:50:35 +000075int TST_TOTAL = 1;
robbiew8da54972002-05-30 18:50:35 +000076
Cyril Hrubis605fa332015-02-04 13:11:20 +010077GID_T groups_list[NGROUPS];
robbiew8da54972002-05-30 18:50:35 +000078
79void setup(); /* setup function for the test */
80void cleanup(); /* cleanup function for the test */
81
robbiewd34d5812005-07-11 22:28:09 +000082#if !defined(UCLINUX)
83
subrata_modak56207ce2009-03-23 13:35:39 +000084int main(int ac, char **av)
subrata_modak4bb656a2009-02-26 12:02:09 +000085{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020086 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020087 const char *msg;
robbiew8da54972002-05-30 18:50:35 +000088 int gidsetsize; /* total no. of groups */
subrata_modak56207ce2009-03-23 13:35:39 +000089 char *test_desc; /* test specific error message */
subrata_modakbdbaec52009-02-26 12:14:51 +000090
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080091 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080092 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew8da54972002-05-30 18:50:35 +000093
94 /* Perform setup for test */
95 setup();
96
subrata_modak4bb656a2009-02-26 12:02:09 +000097 for (lc = 0; TEST_LOOPING(lc); lc++) {
robbiew8da54972002-05-30 18:50:35 +000098
Caspar Zhangd59a6592013-03-07 14:59:12 +080099 tst_count = 0;
robbiew8da54972002-05-30 18:50:35 +0000100
101 gidsetsize = NGROUPS;
102 test_desc = "EFAULT";
subrata_modak56207ce2009-03-23 13:35:39 +0000103
robbiew8da54972002-05-30 18:50:35 +0000104 /*
105 * Call setgroups() to test condition
106 * verify that it fails with -1 return value and
107 * sets appropriate errno.
subrata_modak4bb656a2009-02-26 12:02:09 +0000108 */
Stanislav Kholmanskikhce0dffe2013-09-05 11:01:48 +0400109 TEST(SETGROUPS(cleanup, gidsetsize, sbrk(0)));
Garrett Cooper2c282152010-12-16 00:55:50 -0800110
robbiew8da54972002-05-30 18:50:35 +0000111 if (TEST_RETURN != -1) {
subrata_modak923b23f2009-11-02 13:57:16 +0000112 tst_resm(TFAIL, "setgroups() returned %ld, "
robbiew8da54972002-05-30 18:50:35 +0000113 "expected -1, errno=%d", TEST_RETURN,
Cyril Hrubis605fa332015-02-04 13:11:20 +0100114 EFAULT);
subrata_modak56207ce2009-03-23 13:35:39 +0000115 } else {
116
Cyril Hrubis605fa332015-02-04 13:11:20 +0100117 if (TEST_ERRNO == EFAULT) {
subrata_modak56207ce2009-03-23 13:35:39 +0000118 tst_resm(TPASS,
119 "setgroups() fails with expected "
120 "error EFAULT errno:%d", TEST_ERRNO);
robbiew8da54972002-05-30 18:50:35 +0000121 } else {
122 tst_resm(TFAIL, "setgroups() fails, %s, "
123 "errno=%d, expected errno=%d",
Cyril Hrubis605fa332015-02-04 13:11:20 +0100124 test_desc, TEST_ERRNO, EFAULT);
robbiew8da54972002-05-30 18:50:35 +0000125 }
126 }
127
Garrett Cooper2c282152010-12-16 00:55:50 -0800128 }
robbiew8da54972002-05-30 18:50:35 +0000129
robbiew8da54972002-05-30 18:50:35 +0000130 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800131 tst_exit();
robbiew8da54972002-05-30 18:50:35 +0000132
robbiew8da54972002-05-30 18:50:35 +0000133}
134
robbiewd34d5812005-07-11 22:28:09 +0000135#else
136
Mike Frysingerc57fba52014-04-09 18:56:30 -0400137int main(void)
robbiewd34d5812005-07-11 22:28:09 +0000138{
vapier81a63072006-02-27 04:29:21 +0000139 tst_resm(TINFO, "test is not available on uClinux");
Garrett Cooper2c282152010-12-16 00:55:50 -0800140 tst_exit();
robbiewd34d5812005-07-11 22:28:09 +0000141}
142
robbiew61f8e602005-08-02 17:51:41 +0000143#endif /* if !defined(UCLINUX) */
robbiewd34d5812005-07-11 22:28:09 +0000144
robbiew8da54972002-05-30 18:50:35 +0000145/*
146 * setup()
147 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400148void setup(void)
robbiew8da54972002-05-30 18:50:35 +0000149{
Nicolas Jolyd4ceb372014-06-22 17:03:57 +0200150 tst_require_root(NULL);
subrata_modak56207ce2009-03-23 13:35:39 +0000151
robbiew8da54972002-05-30 18:50:35 +0000152 tst_sig(NOFORK, DEF_HANDLER, cleanup);
153
robbiew8da54972002-05-30 18:50:35 +0000154 TEST_PAUSE;
155
156}
subrata_modak56207ce2009-03-23 13:35:39 +0000157
robbiew8da54972002-05-30 18:50:35 +0000158/*
159 * cleanup()
160 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400161void cleanup(void)
robbiew8da54972002-05-30 18:50:35 +0000162{
robbiew8da54972002-05-30 18:50:35 +0000163
Chris Dearmanec6edca2012-10-17 19:54:01 -0700164}