blob: c1fd0f2e04e8b5f36c0fff856fead2b48e98b7a9 [file] [log] [blame]
vapierd13d74b2006-02-11 07:24:00 +00001/*
2 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
21 * NAME
22 * setfsgid02.c
23 *
24 * DESCRIPTION
25 * Testcase to check the basic functionality of setfsgid(2) system
26 * call failures.
27 *
28 * ALGORITHM
29 * Call setfsgid() and test the return value when invalid gid used.
30 *
31 * USAGE: <for command-line>
32 * setfsgid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
33 * where, -c n : Run n copies concurrently.
34 * -f : Turn off functionality Testing.
35 * -i n : Execute test n times.
36 * -I x : Execute test for x seconds.
37 * -P x : Pause for x seconds between iterations.
38 * -t : Turn on syscall timing.
39 *
40 * HISTORY
41 * 07/2001 Ported by Wayne Boyer
42 * 04/2003 Adapted by Dustin Kirkland (k1rkland@us.ibm.com)
43 *
44 * RESTRICTIONS
45 * None
46 */
47#include <stdio.h>
48#include <unistd.h>
49#include <grp.h>
50#include <pwd.h>
51#include <sys/types.h>
52#include <errno.h>
53#ifdef __GLIBC__
54#include <sys/fsuid.h>
55#endif
56#include "test.h"
57#include "usctest.h"
58
59char *TCID = "setfsgid02";
60int TST_TOTAL = 1;
61extern int Tst_count;
62
63void setup(void);
64void cleanup(void);
65
66int main(int ac, char **av)
67{
subrata_modak56207ce2009-03-23 13:35:39 +000068 int lc; /* loop counter */
69 char *msg; /* message returned from parse_opts */
vapierd13d74b2006-02-11 07:24:00 +000070
71 gid_t gid;
subrata_modakbdbaec52009-02-26 12:14:51 +000072
vapierd13d74b2006-02-11 07:24:00 +000073 /* parse standard options */
Garrett Cooper45e285d2010-11-22 12:19:25 -080074 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
vapierd13d74b2006-02-11 07:24:00 +000075 tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
76 }
77
78 setup();
79
80 /* Check for looping state if -i option is given */
81 for (lc = 0; TEST_LOOPING(lc); lc++) {
82 /* reset Tst_count in case we are looping */
83 Tst_count = 0;
84
subrata_modak56207ce2009-03-23 13:35:39 +000085 gid = 1;
86 while (getgrgid(gid)) {
87 gid++;
88 }
vapierd13d74b2006-02-11 07:24:00 +000089
90 TEST(setfsgid(gid));
91
92 if (TEST_RETURN == -1) {
93 tst_resm(TFAIL, "call failed unexpectedly - errno %d",
94 TEST_ERRNO);
95 continue;
96 }
97
98 if (!STD_FUNCTIONAL_TEST) {
99 tst_resm(TPASS, "call succeeded");
100 continue;
101 }
102
103 if (TEST_RETURN == gid) {
subrata_modak923b23f2009-11-02 13:57:16 +0000104 tst_resm(TFAIL, "setfsgid() returned %ld, expected %d",
vapierd13d74b2006-02-11 07:24:00 +0000105 TEST_RETURN, gid);
106 } else {
107 tst_resm(TPASS, "setfsgid() returned expected value : "
subrata_modak923b23f2009-11-02 13:57:16 +0000108 "%ld", TEST_RETURN);
vapierd13d74b2006-02-11 07:24:00 +0000109 }
110 }
111 cleanup();
112
subrata_modak56207ce2009-03-23 13:35:39 +0000113 /*NOTREACHED*/ return EXIT_SUCCESS;
vapierd13d74b2006-02-11 07:24:00 +0000114}
115
116/*
117 * setup() - performs all ONE TIME setup for this test.
118 */
subrata_modak56207ce2009-03-23 13:35:39 +0000119void setup()
vapierd13d74b2006-02-11 07:24:00 +0000120{
121 /* capture signals */
122 tst_sig(NOFORK, DEF_HANDLER, cleanup);
123
124 /* Pause if that option was specified */
125 TEST_PAUSE;
126}
127
128/*
129 * cleanup() - performs all ONE TIME cleanup for this test at
130 * completion or premature exit.
131 */
subrata_modak56207ce2009-03-23 13:35:39 +0000132void cleanup()
vapierd13d74b2006-02-11 07:24:00 +0000133{
134 /*
135 * print timing stats if that option was specified.
136 * print errno log if that option was specified.
137 */
138 TEST_CLEANUP;
139
140 /* exit with return code appropriate for results */
141 tst_exit();
142}