• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "compat_16.h"
74 
75 TCID_DEFINE(setgroups04);
76 int TST_TOTAL = 1;
77 
78 GID_T groups_list[NGROUPS];
79 
80 void setup();			/* setup function for the test */
81 void cleanup();			/* cleanup function for the test */
82 
83 #if !defined(UCLINUX)
84 
main(int ac,char ** av)85 int main(int ac, char **av)
86 {
87 	int lc;
88 	int gidsetsize;		/* total no. of groups */
89 	char *test_desc;	/* test specific error message */
90 
91 	tst_parse_opts(ac, av, NULL, NULL);
92 
93 	/* Perform setup for test */
94 	setup();
95 
96 	for (lc = 0; TEST_LOOPING(lc); lc++) {
97 
98 		tst_count = 0;
99 
100 		gidsetsize = NGROUPS;
101 		test_desc = "EFAULT";
102 
103 		/*
104 		 * Call setgroups() to test condition
105 		 * verify that it fails with -1 return value and
106 		 * sets appropriate errno.
107 		 */
108 		TEST(SETGROUPS(cleanup, gidsetsize, sbrk(0)));
109 
110 		if (TEST_RETURN != -1) {
111 			tst_resm(TFAIL, "setgroups() returned %ld, "
112 				 "expected -1, errno=%d", TEST_RETURN,
113 				 EFAULT);
114 		} else {
115 
116 			if (TEST_ERRNO == EFAULT) {
117 				tst_resm(TPASS,
118 					 "setgroups() fails with expected "
119 					 "error EFAULT errno:%d", TEST_ERRNO);
120 			} else {
121 				tst_resm(TFAIL, "setgroups() fails, %s, "
122 					 "errno=%d, expected errno=%d",
123 					 test_desc, TEST_ERRNO, EFAULT);
124 			}
125 		}
126 
127 	}
128 
129 	cleanup();
130 	tst_exit();
131 
132 }
133 
134 #else
135 
main(void)136 int main(void)
137 {
138 	tst_resm(TINFO, "test is not available on uClinux");
139 	tst_exit();
140 }
141 
142 #endif /* if !defined(UCLINUX) */
143 
144 /*
145  * setup()
146  */
setup(void)147 void setup(void)
148 {
149 	tst_require_root();
150 
151 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
152 
153 	TEST_PAUSE;
154 
155 }
156 
157 /*
158  * cleanup()
159  */
cleanup(void)160 void cleanup(void)
161 {
162 
163 }
164