1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31 *
32 * Author: William Roske
33 * Co-pilot: Dave Fenner
34 */
35
36 /*
37 * Testcase to test the basic functionality of setreuid(2) system call.
38 */
39
40 #include <errno.h>
41 #include <string.h>
42 #include <signal.h>
43 #include <sys/types.h>
44
45 #include "test.h"
46 #include "compat_16.h"
47
48 static void setup(void);
49 static void cleanup(void);
50
51 TCID_DEFINE(setreuid01);
52 int TST_TOTAL = 5;
53
54 static uid_t ruid, euid; /* real and effective user ids */
55
main(int ac,char ** av)56 int main(int ac, char **av)
57 {
58 int lc;
59
60 tst_parse_opts(ac, av, NULL, NULL);
61
62 setup();
63
64 for (lc = 0; TEST_LOOPING(lc); lc++) {
65
66 tst_count = 0;
67
68 /*
69 * TEST CASE:
70 * Don't change either real or effective uid
71 */
72 ruid = getuid(); /* get real uid */
73 UID16_CHECK(ruid, setreuid, cleanup);
74
75 euid = geteuid(); /* get effective uid */
76 UID16_CHECK(euid, setreuid, cleanup);
77
78 TEST(SETREUID(cleanup, -1, -1));
79
80 if (TEST_RETURN == -1) {
81 tst_resm(TFAIL,
82 "setreuid - Don't change either real or effective uid failed, errno=%d : %s",
83 TEST_ERRNO, strerror(TEST_ERRNO));
84 } else {
85 tst_resm(TPASS,
86 "setreuid - Don't change either real or effective uid returned %ld",
87 TEST_RETURN);
88 }
89
90 /*
91 * TEST CASE:
92 * change effective to effective uid
93 */
94
95 TEST(SETREUID(cleanup, -1, euid));
96
97 if (TEST_RETURN == -1) {
98 tst_resm(TFAIL,
99 "setreuid - change effective to effective uid failed, errno=%d : %s",
100 TEST_ERRNO, strerror(TEST_ERRNO));
101 } else {
102 tst_resm(TPASS,
103 "setreuid - change effective to effective uid returned %ld",
104 TEST_RETURN);
105 }
106
107 /*
108 * TEST CASE:
109 * change real to real uid
110 */
111
112 TEST(SETREUID(cleanup, ruid, -1));
113
114 if (TEST_RETURN == -1) {
115 tst_resm(TFAIL,
116 "setreuid - change real to real uid failed, errno=%d : %s",
117 TEST_ERRNO, strerror(TEST_ERRNO));
118 } else {
119 tst_resm(TPASS,
120 "setreuid - change real to real uid returned %ld",
121 TEST_RETURN);
122 }
123
124 /*
125 * TEST CASE:
126 * change effective to real uid
127 */
128
129 TEST(SETREUID(cleanup, -1, ruid));
130
131 if (TEST_RETURN == -1) {
132 tst_resm(TFAIL,
133 "setreuid - change effective to real uid failed, errno=%d : %s",
134 TEST_ERRNO, strerror(TEST_ERRNO));
135 } else {
136 tst_resm(TPASS,
137 "setreuid - change effective to real uid returned %ld",
138 TEST_RETURN);
139 }
140
141 /*
142 * TEST CASE:
143 * try to change real to current real
144 */
145
146 TEST(SETREUID(cleanup, ruid, ruid));
147
148 if (TEST_RETURN == -1) {
149 tst_resm(TFAIL,
150 "setreuid - try to change real to current real failed, errno=%d : %s",
151 TEST_ERRNO, strerror(TEST_ERRNO));
152 } else {
153 tst_resm(TPASS,
154 "setreuid - try to change real to current real returned %ld",
155 TEST_RETURN);
156 }
157
158 }
159
160 cleanup();
161 tst_exit();
162 }
163
setup(void)164 static void setup(void)
165 {
166 tst_sig(NOFORK, DEF_HANDLER, cleanup);
167
168 TEST_PAUSE;
169
170 tst_tmpdir();
171 }
172
cleanup(void)173 static void cleanup(void)
174 {
175 tst_rmdir();
176 }
177