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
77 /*
78 * Don't forget to remove USE_LEGACY_COMPAT_16_H from Makefile after
79 * rewriting all tests to the new API.
80 */
81 #include "compat_16.h"
82
83 char *TCID = "getresgid01";
84 int TST_TOTAL = 1;
85 GID_T pr_gid, pe_gid, ps_gid; /* calling process real/effective/saved gid */
86
87 void setup(); /* Main setup function of test */
88 void cleanup(); /* cleanup function for the test */
89
main(int ac,char ** av)90 int main(int ac, char **av)
91 {
92 int lc;
93 GID_T real_gid, /* real/eff./saved user id from getresgid() */
94 eff_gid, sav_gid;
95
96 tst_parse_opts(ac, av, NULL, NULL);
97
98 setup();
99
100 for (lc = 0; TEST_LOOPING(lc); lc++) {
101
102 tst_count = 0;
103
104 /*
105 * Call getresgid() to get the real/effective/saved
106 * user id's of the calling process.
107 */
108 TEST(GETRESGID(cleanup, &real_gid, &eff_gid, &sav_gid));
109
110 if (TEST_RETURN == -1) {
111 tst_resm(TFAIL, "getresgid() Failed, errno=%d : %s",
112 TEST_ERRNO, strerror(TEST_ERRNO));
113 continue;
114 }
115 /*
116 * Verify the real/effective/saved gid values returned
117 * by getresgid with the expected values.
118 */
119 if ((real_gid != pr_gid) || (eff_gid != pe_gid) ||
120 (sav_gid != ps_gid)) {
121 tst_resm(TFAIL, "real:%d, effective:%d, "
122 "saved-user:%d ids differ",
123 real_gid, eff_gid, sav_gid);
124 } else {
125 tst_resm(TPASS, "Functionality of getresgid() "
126 "successful");
127 }
128 }
129
130 cleanup();
131 tst_exit();
132 }
133
134 /*
135 * setup() - performs all ONE TIME setup for this test.
136 * Get the real/effective/saved user id of the calling process.
137 */
setup(void)138 void setup(void)
139 {
140
141 tst_sig(NOFORK, DEF_HANDLER, cleanup);
142
143 TEST_PAUSE;
144
145 /* Real user-id of the calling process */
146 pr_gid = getgid();
147
148 /* Effective user-id of the calling process */
149 pe_gid = getegid();
150
151 /* Saved user-id of the calling process */
152 ps_gid = getegid();
153
154 }
155
156 /*
157 * cleanup() - performs all ONE TIME cleanup for this test at
158 * completion or premature exit.
159 */
cleanup(void)160 void cleanup(void)
161 {
162
163 }
164