blob: 2abb3cf7df1ba33559f26e12530615ff9a62cf1d [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * $Copyright: $
3 * Copyright (c) 1984-2000
4 * Sequent Computer Systems, Inc. All rights reserved.
subrata_modak56207ce2009-03-23 13:35:39 +00005 *
plars865695b2001-08-27 22:15:12 +00006 * This software is furnished under a license and may be used
7 * only in accordance with the terms of that license and with the
8 * inclusion of the above copyright notice. This software may not
9 * be provided or otherwise made available to, or used by, any
10 * other person. No title to or ownership of the software is
11 * hereby transferred.
12 */
13
14/*
15 * Test Name: getresgid01
16 *
17 * Test Description:
18 * Verify that getresgid() will be successful to get the real, effective
19 * and saved user id of the calling process.
20 *
21 * Expected Result:
22 * getresgid() should return with 0 value and the real/effective/saved
23 * user ids should be equal to that of calling process.
24 *
25 * Algorithm:
26 * Setup:
27 * Setup signal handling.
28 * Pause for SIGUSR1 if option specified.
29 *
30 * Test:
31 * Loop if the proper options are given.
32 * Execute system call
33 * Check return code, if system call failed (return=-1)
subrata_modak56207ce2009-03-23 13:35:39 +000034 * Log the errno and Issue a FAIL message.
plars865695b2001-08-27 22:15:12 +000035 * Otherwise,
subrata_modak56207ce2009-03-23 13:35:39 +000036 * Verify the Functionality of system call
plars865695b2001-08-27 22:15:12 +000037 * if successful,
subrata_modak56207ce2009-03-23 13:35:39 +000038 * Issue Functionality-Pass message.
plars865695b2001-08-27 22:15:12 +000039 * Otherwise,
40 * Issue Functionality-Fail message.
41 * Cleanup:
42 * Print errno log and/or timing stats if options given
43 *
44 * Usage: <for command-line>
45 * getresgid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
46 * where, -c n : Run n copies concurrently.
47 * -f : Turn off functionality Testing.
48 * -i n : Execute test n times.
49 * -I x : Execute test for x seconds.
50 * -P x : Pause for x seconds between iterations.
51 * -t : Turn on syscall timing.
52 *
53 * HISTORY
54 * 07/2001 Ported by Wayne Boyer
55 *
56 * RESTRICTIONS:
57 * None.
58 *
59 */
robbiew96d23372003-03-26 20:40:04 +000060
plars865695b2001-08-27 22:15:12 +000061#include <stdio.h>
62#include <unistd.h>
63#include <sys/types.h>
64#include <errno.h>
65#include <fcntl.h>
66#include <string.h>
67#include <signal.h>
68
69#include "test.h"
70#include "usctest.h"
71
subrata_modak56207ce2009-03-23 13:35:39 +000072extern int getresgid(gid_t *, gid_t *, gid_t *);
robbiew96d23372003-03-26 20:40:04 +000073
subrata_modak56207ce2009-03-23 13:35:39 +000074char *TCID = "getresgid01"; /* Test program identifier. */
75int TST_TOTAL = 1; /* Total number of test cases. */
plars865695b2001-08-27 22:15:12 +000076extern int Tst_count; /* Test Case counter for tst_* routines */
77gid_t pr_gid, pe_gid, ps_gid; /* calling process real/effective/saved gid */
78
79void setup(); /* Main setup function of test */
80void cleanup(); /* cleanup function for the test */
81
subrata_modak56207ce2009-03-23 13:35:39 +000082int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000083{
84 int lc; /* loop counter */
85 char *msg; /* message returned from parse_opts */
86 gid_t real_gid, /* real/eff./saved user id from getresgid() */
subrata_modak56207ce2009-03-23 13:35:39 +000087 eff_gid, sav_gid;
88
plars865695b2001-08-27 22:15:12 +000089 /* Parse standard options given to run the test. */
Garrett Cooper53740502010-12-16 00:04:01 -080090<<<<<<< HEAD
Garrett Cooper45e285d2010-11-22 12:19:25 -080091 msg = parse_opts(ac, av, NULL, NULL);
Garrett Cooper53740502010-12-16 00:04:01 -080092=======
plars865695b2001-08-27 22:15:12 +000093 msg = parse_opts(ac, av, (option_t *) NULL, NULL);
Garrett Cooper53740502010-12-16 00:04:01 -080094>>>>>>> master
Garrett Cooper45e285d2010-11-22 12:19:25 -080095 if (msg != NULL) {
plars865695b2001-08-27 22:15:12 +000096 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
97 tst_exit();
98 }
99
100 /* Perform global setup for test */
101 setup();
102
103 /* Check looping state if -c option given */
104 for (lc = 0; TEST_LOOPING(lc); lc++) {
105 /* Reset Tst_count in case we are looping. */
subrata_modak56207ce2009-03-23 13:35:39 +0000106 Tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000107
subrata_modak4bb656a2009-02-26 12:02:09 +0000108 /*
plars865695b2001-08-27 22:15:12 +0000109 * Call getresgid() to get the real/effective/saved
110 * user id's of the calling process.
111 */
112 TEST(getresgid(&real_gid, &eff_gid, &sav_gid));
113
114 /* check return code of getresgid(2) */
115 if (TEST_RETURN == -1) {
116 tst_resm(TFAIL, "getresgid() Failed, errno=%d : %s",
117 TEST_ERRNO, strerror(TEST_ERRNO));
118 continue;
119 }
120 /*
121 * Perform functional verification if test
122 * executed without (-f) option.
123 */
124 if (STD_FUNCTIONAL_TEST) {
125 /*
126 * Verify the real/effective/saved gid values returned
127 * by getresgid with the expected values.
128 */
subrata_modak56207ce2009-03-23 13:35:39 +0000129 if ((real_gid != pr_gid) || (eff_gid != pe_gid) ||
plars865695b2001-08-27 22:15:12 +0000130 (sav_gid != ps_gid)) {
131 tst_resm(TFAIL, "real:%d, effective:%d, "
132 "saved-user:%d ids differ",
133 real_gid, eff_gid, sav_gid);
134 } else {
135 tst_resm(TPASS, "Functionality of getresgid() "
136 "successful");
137 }
138 } else {
139 tst_resm(TPASS, "call succeeded");
140 }
subrata_modak56207ce2009-03-23 13:35:39 +0000141 } /* End for TEST_LOOPING */
plars865695b2001-08-27 22:15:12 +0000142
143 /* Call cleanup() to undo setup done for the test. */
144 cleanup();
145
Garrett Cooper53740502010-12-16 00:04:01 -0800146 return 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000147} /* End main */
plars865695b2001-08-27 22:15:12 +0000148
149/*
150 * setup() - performs all ONE TIME setup for this test.
151 * Get the real/effective/saved user id of the calling process.
152 */
subrata_modak56207ce2009-03-23 13:35:39 +0000153void setup()
plars865695b2001-08-27 22:15:12 +0000154{
155 /* capture signals */
156 tst_sig(NOFORK, DEF_HANDLER, cleanup);
157
158 /* Pause if that option was specified */
159 TEST_PAUSE;
160
161 /* Real user-id of the calling process */
162 pr_gid = getgid();
163
164 /* Effective user-id of the calling process */
165 pe_gid = getegid();
166
167 /* Saved user-id of the calling process */
168 ps_gid = getegid();
169
170}
171
plars865695b2001-08-27 22:15:12 +0000172/*
173 * cleanup() - performs all ONE TIME cleanup for this test at
174 * completion or premature exit.
175 */
subrata_modak56207ce2009-03-23 13:35:39 +0000176void cleanup()
plars865695b2001-08-27 22:15:12 +0000177{
178 /*
179 * print timing stats if that option was specified.
180 * print errno log if that option was specified.
181 */
182 TEST_CLEANUP;
183
184 /* exit with return code appropriate for results */
185 tst_exit();
186}