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: getresuid01
22 *
23 * Test Description:
24 * Verify that getresuid() will be successful to get the real, effective
25 * and saved user id of the calling process.
26 *
27 * Expected Result:
28 * getresuid() 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 * getresuid01 [-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 #include <stdio.h>
67 #include <unistd.h>
68 #include <sys/types.h>
69 #include <errno.h>
70 #include <fcntl.h>
71 #include <string.h>
72 #include <signal.h>
73
74 #include "test.h"
75 #include "compat_16.h"
76
77 char *TCID = "getresuid01";
78 int TST_TOTAL = 1;
79 UID_T pr_uid, pe_uid, ps_uid; /* calling process real/effective/saved uid */
80
81 void setup(); /* Main setup function of test */
82 void cleanup(); /* cleanup function for the test */
83
main(int ac,char ** av)84 int main(int ac, char **av)
85 {
86 int lc;
87 UID_T real_uid, /* real/eff./saved user id from getresuid() */
88 eff_uid, sav_uid;
89
90 tst_parse_opts(ac, av, NULL, NULL);
91
92 setup();
93
94 for (lc = 0; TEST_LOOPING(lc); lc++) {
95
96 tst_count = 0;
97
98 /*
99 * Call getresuid() to get the real/effective/saved
100 * user id's of the calling process.
101 */
102 TEST(GETRESUID(cleanup, &real_uid, &eff_uid, &sav_uid));
103
104 if (TEST_RETURN == -1) {
105 tst_resm(TFAIL, "getresuid() Failed, errno=%d : %s",
106 TEST_ERRNO, strerror(TEST_ERRNO));
107 continue;
108 }
109
110 if ((real_uid != pr_uid) || (eff_uid != pe_uid) ||
111 (sav_uid != ps_uid)) {
112 tst_resm(TFAIL, "real:%d, effective:%d, "
113 "saved-user:%d ids differ",
114 real_uid, eff_uid, sav_uid);
115 } else {
116 tst_resm(TPASS, "Functionality of getresuid() "
117 "successful");
118 }
119 }
120
121 cleanup();
122 tst_exit();
123 }
124
125 /*
126 * setup() - performs all ONE TIME setup for this test.
127 * Get the real/effective/saved user id of the calling process.
128 */
setup(void)129 void setup(void)
130 {
131
132 tst_sig(NOFORK, DEF_HANDLER, cleanup);
133
134 TEST_PAUSE;
135
136 /* Real user-id of the calling process */
137 pr_uid = getuid();
138
139 /* Effective user-id of the calling process */
140 pe_uid = geteuid();
141
142 /* Saved user-id of the calling process */
143 ps_uid = geteuid();
144
145 }
146
147 /*
148 * cleanup() - performs all ONE TIME cleanup for this test at
149 * completion or premature exit.
150 */
cleanup(void)151 void cleanup(void)
152 {
153
154 }
155