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