• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /*
21  * Test Name: getresgid01
22  *
23  * Test Description:
24  *  Verify that getresgid() will be successful to get the real, effective
25  *  and saved user id of the calling process.
26  *
27  * Expected Result:
28  *  getresgid() should return with 0 value and the real/effective/saved
29  *  user ids should be equal to that of calling process.
30  *
31  * Algorithm:
32  *  Setup:
33  *   Setup signal handling.
34  *   Pause for SIGUSR1 if option specified.
35  *
36  *  Test:
37  *   Loop if the proper options are given.
38  *   Execute system call
39  *   Check return code, if system call failed (return=-1)
40  *	Log the errno and Issue a FAIL message.
41  *   Otherwise,
42  *	Verify the Functionality of system call
43  *      if successful,
44  *		Issue Functionality-Pass message.
45  *      Otherwise,
46  *		Issue Functionality-Fail message.
47  *  Cleanup:
48  *   Print errno log and/or timing stats if options given
49  *
50  * Usage:  <for command-line>
51  *  getresgid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
52  *     where,  -c n : Run n copies concurrently.
53  *             -f   : Turn off functionality Testing.
54  *	       -i n : Execute test n times.
55  *	       -I x : Execute test for x seconds.
56  *	       -P x : Pause for x seconds between iterations.
57  *	       -t   : Turn on syscall timing.
58  *
59  * HISTORY
60  *	07/2001 Ported by Wayne Boyer
61  *
62  * RESTRICTIONS:
63  *  None.
64  *
65  */
66 
67 #include <stdio.h>
68 #include <unistd.h>
69 #include <sys/types.h>
70 #include <errno.h>
71 #include <fcntl.h>
72 #include <string.h>
73 #include <signal.h>
74 
75 #include "test.h"
76 #include "compat_16.h"
77 
78 char *TCID = "getresgid01";
79 int TST_TOTAL = 1;
80 GID_T pr_gid, pe_gid, ps_gid;	/* calling process real/effective/saved gid */
81 
82 void setup();			/* Main setup function of test */
83 void cleanup();			/* cleanup function for the test */
84 
main(int ac,char ** av)85 int main(int ac, char **av)
86 {
87 	int lc;
88 	GID_T real_gid,		/* real/eff./saved user id from getresgid() */
89 	 eff_gid, sav_gid;
90 
91 	tst_parse_opts(ac, av, NULL, NULL);
92 
93 	setup();
94 
95 	for (lc = 0; TEST_LOOPING(lc); lc++) {
96 
97 		tst_count = 0;
98 
99 		/*
100 		 * Call getresgid() to get the real/effective/saved
101 		 * user id's of the calling process.
102 		 */
103 		TEST(GETRESGID(cleanup, &real_gid, &eff_gid, &sav_gid));
104 
105 		if (TEST_RETURN == -1) {
106 			tst_resm(TFAIL, "getresgid() Failed, errno=%d : %s",
107 				 TEST_ERRNO, strerror(TEST_ERRNO));
108 			continue;
109 		}
110 		/*
111 		 * Verify the real/effective/saved gid values returned
112 		 * by getresgid with the expected values.
113 		 */
114 		if ((real_gid != pr_gid) || (eff_gid != pe_gid) ||
115 		    (sav_gid != ps_gid)) {
116 			tst_resm(TFAIL, "real:%d, effective:%d, "
117 				 "saved-user:%d ids differ",
118 				 real_gid, eff_gid, sav_gid);
119 		} else {
120 			tst_resm(TPASS, "Functionality of getresgid() "
121 				 "successful");
122 		}
123 	}
124 
125 	cleanup();
126 	tst_exit();
127 }
128 
129 /*
130  * setup() - performs all ONE TIME setup for this test.
131  *	     Get the real/effective/saved user id of the calling process.
132  */
setup(void)133 void setup(void)
134 {
135 
136 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
137 
138 	TEST_PAUSE;
139 
140 	/* Real user-id of the calling process */
141 	pr_gid = getgid();
142 
143 	/* Effective user-id of the calling process */
144 	pe_gid = getegid();
145 
146 	/* Saved user-id of the calling process */
147 	ps_gid = getegid();
148 
149 }
150 
151 /*
152  * cleanup() - performs all ONE TIME cleanup for this test at
153  *             completion or premature exit.
154  */
cleanup(void)155 void cleanup(void)
156 {
157 
158 }
159