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
76 /*
77 * Don't forget to remove USE_LEGACY_COMPAT_16_H from Makefile after
78 * rewriting all tests to the new API.
79 */
80 #include "compat_16.h"
81
82 char *TCID = "getresuid01";
83 int TST_TOTAL = 1;
84 UID_T pr_uid, pe_uid, ps_uid; /* calling process real/effective/saved uid */
85
86 void setup(); /* Main setup function of test */
87 void cleanup(); /* cleanup function for the test */
88
main(int ac,char ** av)89 int main(int ac, char **av)
90 {
91 int lc;
92 UID_T real_uid, /* real/eff./saved user id from getresuid() */
93 eff_uid, sav_uid;
94
95 tst_parse_opts(ac, av, NULL, NULL);
96
97 setup();
98
99 for (lc = 0; TEST_LOOPING(lc); lc++) {
100
101 tst_count = 0;
102
103 /*
104 * Call getresuid() to get the real/effective/saved
105 * user id's of the calling process.
106 */
107 TEST(GETRESUID(cleanup, &real_uid, &eff_uid, &sav_uid));
108
109 if (TEST_RETURN == -1) {
110 tst_resm(TFAIL, "getresuid() Failed, errno=%d : %s",
111 TEST_ERRNO, strerror(TEST_ERRNO));
112 continue;
113 }
114
115 if ((real_uid != pr_uid) || (eff_uid != pe_uid) ||
116 (sav_uid != ps_uid)) {
117 tst_resm(TFAIL, "real:%d, effective:%d, "
118 "saved-user:%d ids differ",
119 real_uid, eff_uid, sav_uid);
120 } else {
121 tst_resm(TPASS, "Functionality of getresuid() "
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_uid = getuid();
143
144 /* Effective user-id of the calling process */
145 pe_uid = geteuid();
146
147 /* Saved user-id of the calling process */
148 ps_uid = geteuid();
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