1 /*
2  * Copyright (C) International Business Machines  Corp., 2001
3  * Ported by Wayne Boyer
4  * Adapted by Dustin Kirkland (k1rkland@us.ibm.com)
5  *
6  * This program is free software;  you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
14  * the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program;  if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  *     Testcase to check the basic functionality of setfsgid(2) system
23  *     call failures.
24  */
25 
26 #include <stdio.h>
27 #include <unistd.h>
28 #include <grp.h>
29 #include <pwd.h>
30 #include <sys/types.h>
31 #include <errno.h>
32 
33 #include "test.h"
34 #include "compat_16.h"
35 
36 TCID_DEFINE(setfsgid02);
37 int TST_TOTAL = 1;
38 
39 static void setup(void);
40 static void cleanup(void);
41 
main(int ac,char ** av)42 int main(int ac, char **av)
43 {
44 	int lc;
45 
46 	gid_t gid;
47 
48 	tst_parse_opts(ac, av, NULL, NULL);
49 
50 	setup();
51 
52 	for (lc = 0; TEST_LOOPING(lc); lc++) {
53 		tst_count = 0;
54 
55 		gid = 1;
56 		while (getgrgid(gid))
57 			gid++;
58 
59 		GID16_CHECK(gid, setfsgid, cleanup);
60 
61 		TEST(SETFSGID(cleanup, gid));
62 
63 		if (TEST_RETURN == -1) {
64 			tst_resm(TFAIL | TTERRNO,
65 				"setfsgid() failed unexpectedly");
66 			continue;
67 		}
68 
69 		if (TEST_RETURN == gid) {
70 			tst_resm(TFAIL, "setfsgid() returned %ld, expected %d",
71 				 TEST_RETURN, gid);
72 		} else {
73 			tst_resm(TPASS, "setfsgid() returned expected value : "
74 				 "%ld", TEST_RETURN);
75 		}
76 	}
77 
78 	cleanup();
79 	tst_exit();
80 }
81 
setup(void)82 static void setup(void)
83 {
84 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
85 
86 	TEST_PAUSE;
87 }
88 
cleanup(void)89 static void cleanup(void)
90 {
91 }
92