1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker *
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13*49cdfc7eSAndroid Build Coastguard Worker * the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker * along with this program; if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker */
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker /*
21*49cdfc7eSAndroid Build Coastguard Worker * Test Name: mknod04
22*49cdfc7eSAndroid Build Coastguard Worker *
23*49cdfc7eSAndroid Build Coastguard Worker * Test Description:
24*49cdfc7eSAndroid Build Coastguard Worker * Verify that mknod(2) succeeds when used to create a filesystem
25*49cdfc7eSAndroid Build Coastguard Worker * node on a directory with set group-ID bit set.
26*49cdfc7eSAndroid Build Coastguard Worker * The node created should not have group-ID bit set and its gid should be
27*49cdfc7eSAndroid Build Coastguard Worker * equal to the effective gid of the process.
28*49cdfc7eSAndroid Build Coastguard Worker *
29*49cdfc7eSAndroid Build Coastguard Worker * Expected Result:
30*49cdfc7eSAndroid Build Coastguard Worker * mknod() should return value 0 on success and node created should not
31*49cdfc7eSAndroid Build Coastguard Worker * have set group-ID bit set and its gid should be equal to the effective
32*49cdfc7eSAndroid Build Coastguard Worker * gid of the process.
33*49cdfc7eSAndroid Build Coastguard Worker *
34*49cdfc7eSAndroid Build Coastguard Worker * Algorithm:
35*49cdfc7eSAndroid Build Coastguard Worker * Setup:
36*49cdfc7eSAndroid Build Coastguard Worker * Setup signal handling.
37*49cdfc7eSAndroid Build Coastguard Worker * Create temporary directory.
38*49cdfc7eSAndroid Build Coastguard Worker * Pause for SIGUSR1 if option specified.
39*49cdfc7eSAndroid Build Coastguard Worker *
40*49cdfc7eSAndroid Build Coastguard Worker * Test:
41*49cdfc7eSAndroid Build Coastguard Worker * Loop if the proper options are given.
42*49cdfc7eSAndroid Build Coastguard Worker * Execute system call
43*49cdfc7eSAndroid Build Coastguard Worker * Check return code, if system call failed (return=-1)
44*49cdfc7eSAndroid Build Coastguard Worker * Log the errno and Issue a FAIL message.
45*49cdfc7eSAndroid Build Coastguard Worker * Otherwise,
46*49cdfc7eSAndroid Build Coastguard Worker * Verify the Functionality of system call
47*49cdfc7eSAndroid Build Coastguard Worker * if successful,
48*49cdfc7eSAndroid Build Coastguard Worker * Issue Functionality-Pass message.
49*49cdfc7eSAndroid Build Coastguard Worker * Otherwise,
50*49cdfc7eSAndroid Build Coastguard Worker * Issue Functionality-Fail message.
51*49cdfc7eSAndroid Build Coastguard Worker * Cleanup:
52*49cdfc7eSAndroid Build Coastguard Worker * Print errno log and/or timing stats if options given
53*49cdfc7eSAndroid Build Coastguard Worker * Delete the temporary directory created.
54*49cdfc7eSAndroid Build Coastguard Worker *
55*49cdfc7eSAndroid Build Coastguard Worker * Usage: <for command-line>
56*49cdfc7eSAndroid Build Coastguard Worker * mknod04 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
57*49cdfc7eSAndroid Build Coastguard Worker * where, -c n : Run n copies concurrently.
58*49cdfc7eSAndroid Build Coastguard Worker * -f : Turn off functionality Testing.
59*49cdfc7eSAndroid Build Coastguard Worker * -i n : Execute test n times.
60*49cdfc7eSAndroid Build Coastguard Worker * -I x : Execute test for x seconds.
61*49cdfc7eSAndroid Build Coastguard Worker * -P x : Pause for x seconds between iterations.
62*49cdfc7eSAndroid Build Coastguard Worker * -t : Turn on syscall timing.
63*49cdfc7eSAndroid Build Coastguard Worker *
64*49cdfc7eSAndroid Build Coastguard Worker * HISTORY
65*49cdfc7eSAndroid Build Coastguard Worker * 07/2001 Ported by Wayne Boyer
66*49cdfc7eSAndroid Build Coastguard Worker *
67*49cdfc7eSAndroid Build Coastguard Worker * RESTRICTIONS:
68*49cdfc7eSAndroid Build Coastguard Worker * This test should be run by 'super-user' (root) only.
69*49cdfc7eSAndroid Build Coastguard Worker *
70*49cdfc7eSAndroid Build Coastguard Worker */
71*49cdfc7eSAndroid Build Coastguard Worker
72*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
73*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
74*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
75*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
76*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
77*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
78*49cdfc7eSAndroid Build Coastguard Worker #include <pwd.h>
79*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
80*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
81*49cdfc7eSAndroid Build Coastguard Worker
82*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
83*49cdfc7eSAndroid Build Coastguard Worker #include "safe_macros.h"
84*49cdfc7eSAndroid Build Coastguard Worker
85*49cdfc7eSAndroid Build Coastguard Worker #define LTPUSER "nobody"
86*49cdfc7eSAndroid Build Coastguard Worker #define MODE_RWX S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
87*49cdfc7eSAndroid Build Coastguard Worker #define MODE_SGID S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO
88*49cdfc7eSAndroid Build Coastguard Worker #define DIR_TEMP "testdir_4"
89*49cdfc7eSAndroid Build Coastguard Worker #define TNODE "tnode_%d"
90*49cdfc7eSAndroid Build Coastguard Worker
91*49cdfc7eSAndroid Build Coastguard Worker struct stat buf; /* struct. to hold stat(2) o/p contents */
92*49cdfc7eSAndroid Build Coastguard Worker struct passwd *user1; /* struct. to hold getpwnam(3) o/p contents */
93*49cdfc7eSAndroid Build Coastguard Worker
94*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "mknod04";
95*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
96*49cdfc7eSAndroid Build Coastguard Worker char node_name[PATH_MAX]; /* buffer to hold node name created */
97*49cdfc7eSAndroid Build Coastguard Worker
98*49cdfc7eSAndroid Build Coastguard Worker gid_t group1_gid, group2_gid, mygid; /* user and process group id's */
99*49cdfc7eSAndroid Build Coastguard Worker uid_t save_myuid, user1_uid; /* user and process user id's */
100*49cdfc7eSAndroid Build Coastguard Worker pid_t mypid; /* process id */
101*49cdfc7eSAndroid Build Coastguard Worker
102*49cdfc7eSAndroid Build Coastguard Worker void setup(); /* setup function for the test */
103*49cdfc7eSAndroid Build Coastguard Worker void cleanup(); /* cleanup function for the test */
104*49cdfc7eSAndroid Build Coastguard Worker
main(int ac,char ** av)105*49cdfc7eSAndroid Build Coastguard Worker int main(int ac, char **av)
106*49cdfc7eSAndroid Build Coastguard Worker {
107*49cdfc7eSAndroid Build Coastguard Worker int lc;
108*49cdfc7eSAndroid Build Coastguard Worker int fflag;
109*49cdfc7eSAndroid Build Coastguard Worker
110*49cdfc7eSAndroid Build Coastguard Worker tst_parse_opts(ac, av, NULL, NULL);
111*49cdfc7eSAndroid Build Coastguard Worker
112*49cdfc7eSAndroid Build Coastguard Worker setup();
113*49cdfc7eSAndroid Build Coastguard Worker
114*49cdfc7eSAndroid Build Coastguard Worker for (lc = 0; TEST_LOOPING(lc); lc++) {
115*49cdfc7eSAndroid Build Coastguard Worker
116*49cdfc7eSAndroid Build Coastguard Worker tst_count = 0;
117*49cdfc7eSAndroid Build Coastguard Worker
118*49cdfc7eSAndroid Build Coastguard Worker /*
119*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE CONDITION:
120*49cdfc7eSAndroid Build Coastguard Worker * Attempt to create a filesystem node on a directory
121*49cdfc7eSAndroid Build Coastguard Worker * with group id (sgid) bit set such that,
122*49cdfc7eSAndroid Build Coastguard Worker * the node created by mknod(2) should not have group id
123*49cdfc7eSAndroid Build Coastguard Worker * (sgid) bit set and node's gid should be equal to the
124*49cdfc7eSAndroid Build Coastguard Worker * effective gid of the process.
125*49cdfc7eSAndroid Build Coastguard Worker */
126*49cdfc7eSAndroid Build Coastguard Worker TEST(mknod(node_name, MODE_RWX, 0));
127*49cdfc7eSAndroid Build Coastguard Worker
128*49cdfc7eSAndroid Build Coastguard Worker /* Check return code from mknod(2) */
129*49cdfc7eSAndroid Build Coastguard Worker if (TEST_RETURN == -1) {
130*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "mknod(%s, %#o, 0) failed, errno=%d : "
131*49cdfc7eSAndroid Build Coastguard Worker "%s", node_name, MODE_RWX, TEST_ERRNO,
132*49cdfc7eSAndroid Build Coastguard Worker strerror(TEST_ERRNO));
133*49cdfc7eSAndroid Build Coastguard Worker continue;
134*49cdfc7eSAndroid Build Coastguard Worker }
135*49cdfc7eSAndroid Build Coastguard Worker /* Set the functionality flag */
136*49cdfc7eSAndroid Build Coastguard Worker fflag = 1;
137*49cdfc7eSAndroid Build Coastguard Worker
138*49cdfc7eSAndroid Build Coastguard Worker /* Check for node's creation */
139*49cdfc7eSAndroid Build Coastguard Worker if (stat(node_name, &buf) < 0) {
140*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "stat() of %s failed, errno:%d",
141*49cdfc7eSAndroid Build Coastguard Worker node_name, TEST_ERRNO);
142*49cdfc7eSAndroid Build Coastguard Worker /* unset fflag */
143*49cdfc7eSAndroid Build Coastguard Worker fflag = 0;
144*49cdfc7eSAndroid Build Coastguard Worker }
145*49cdfc7eSAndroid Build Coastguard Worker
146*49cdfc7eSAndroid Build Coastguard Worker /* Verify mode permissions of node */
147*49cdfc7eSAndroid Build Coastguard Worker if (buf.st_mode & S_ISGID) {
148*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s: Incorrect modes, setgid "
149*49cdfc7eSAndroid Build Coastguard Worker "bit set", node_name);
150*49cdfc7eSAndroid Build Coastguard Worker /* unset flag as functionality fails */
151*49cdfc7eSAndroid Build Coastguard Worker fflag = 0;
152*49cdfc7eSAndroid Build Coastguard Worker }
153*49cdfc7eSAndroid Build Coastguard Worker
154*49cdfc7eSAndroid Build Coastguard Worker /* Verify group ID of node */
155*49cdfc7eSAndroid Build Coastguard Worker if (buf.st_gid != group2_gid) {
156*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s: Incorrect group",
157*49cdfc7eSAndroid Build Coastguard Worker node_name);
158*49cdfc7eSAndroid Build Coastguard Worker /* unset flag as functionality fails */
159*49cdfc7eSAndroid Build Coastguard Worker fflag = 0;
160*49cdfc7eSAndroid Build Coastguard Worker }
161*49cdfc7eSAndroid Build Coastguard Worker if (fflag) {
162*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "Functionality of mknod(%s, "
163*49cdfc7eSAndroid Build Coastguard Worker "%#o, 0) successful",
164*49cdfc7eSAndroid Build Coastguard Worker node_name, MODE_RWX);
165*49cdfc7eSAndroid Build Coastguard Worker }
166*49cdfc7eSAndroid Build Coastguard Worker
167*49cdfc7eSAndroid Build Coastguard Worker /* Remove the node for the next go `round */
168*49cdfc7eSAndroid Build Coastguard Worker if (unlink(node_name) == -1) {
169*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TWARN, "unlink(%s) failed, errno:%d %s",
170*49cdfc7eSAndroid Build Coastguard Worker node_name, errno, strerror(errno));
171*49cdfc7eSAndroid Build Coastguard Worker }
172*49cdfc7eSAndroid Build Coastguard Worker }
173*49cdfc7eSAndroid Build Coastguard Worker
174*49cdfc7eSAndroid Build Coastguard Worker /* Change the directory back to temporary directory */
175*49cdfc7eSAndroid Build Coastguard Worker SAFE_CHDIR(cleanup, "..");
176*49cdfc7eSAndroid Build Coastguard Worker
177*49cdfc7eSAndroid Build Coastguard Worker /*
178*49cdfc7eSAndroid Build Coastguard Worker * Invoke cleanup() to delete the test directories created
179*49cdfc7eSAndroid Build Coastguard Worker * in the setup() and exit main().
180*49cdfc7eSAndroid Build Coastguard Worker */
181*49cdfc7eSAndroid Build Coastguard Worker cleanup();
182*49cdfc7eSAndroid Build Coastguard Worker
183*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
184*49cdfc7eSAndroid Build Coastguard Worker }
185*49cdfc7eSAndroid Build Coastguard Worker
186*49cdfc7eSAndroid Build Coastguard Worker /*
187*49cdfc7eSAndroid Build Coastguard Worker * void
188*49cdfc7eSAndroid Build Coastguard Worker * setup(void) - performs all ONE TIME setup for this test.
189*49cdfc7eSAndroid Build Coastguard Worker * Exit the test program on receipt of unexpected signals.
190*49cdfc7eSAndroid Build Coastguard Worker * Create a temporary directory used to hold test directories created
191*49cdfc7eSAndroid Build Coastguard Worker * and change the directory to it.
192*49cdfc7eSAndroid Build Coastguard Worker * Verify that pid of process executing the test is root.
193*49cdfc7eSAndroid Build Coastguard Worker * Create a test directory on temporary directory and set the ownership
194*49cdfc7eSAndroid Build Coastguard Worker * of test directory to guest user and process, change mode permissions
195*49cdfc7eSAndroid Build Coastguard Worker * to set group-id bit on it.
196*49cdfc7eSAndroid Build Coastguard Worker * Set the effective uid/gid of the process to that of guest user.
197*49cdfc7eSAndroid Build Coastguard Worker */
setup(void)198*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
199*49cdfc7eSAndroid Build Coastguard Worker {
200*49cdfc7eSAndroid Build Coastguard Worker tst_require_root();
201*49cdfc7eSAndroid Build Coastguard Worker
202*49cdfc7eSAndroid Build Coastguard Worker /* Capture unexpected signals */
203*49cdfc7eSAndroid Build Coastguard Worker tst_sig(NOFORK, DEF_HANDLER, cleanup);
204*49cdfc7eSAndroid Build Coastguard Worker
205*49cdfc7eSAndroid Build Coastguard Worker TEST_PAUSE;
206*49cdfc7eSAndroid Build Coastguard Worker
207*49cdfc7eSAndroid Build Coastguard Worker /* Make a temp dir and cd to it */
208*49cdfc7eSAndroid Build Coastguard Worker tst_tmpdir();
209*49cdfc7eSAndroid Build Coastguard Worker
210*49cdfc7eSAndroid Build Coastguard Worker /* fix permissions on the tmpdir */
211*49cdfc7eSAndroid Build Coastguard Worker if (chmod(".", 0711) != 0) {
212*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup, "chmod() failed");
213*49cdfc7eSAndroid Build Coastguard Worker }
214*49cdfc7eSAndroid Build Coastguard Worker
215*49cdfc7eSAndroid Build Coastguard Worker /* Save the real user id of the current test process */
216*49cdfc7eSAndroid Build Coastguard Worker save_myuid = getuid();
217*49cdfc7eSAndroid Build Coastguard Worker
218*49cdfc7eSAndroid Build Coastguard Worker /* Save the process id of the current test process */
219*49cdfc7eSAndroid Build Coastguard Worker mypid = getpid();
220*49cdfc7eSAndroid Build Coastguard Worker
221*49cdfc7eSAndroid Build Coastguard Worker /* Get the node name to be created in the test */
222*49cdfc7eSAndroid Build Coastguard Worker sprintf(node_name, TNODE, mypid);
223*49cdfc7eSAndroid Build Coastguard Worker
224*49cdfc7eSAndroid Build Coastguard Worker /* Get the uid/gid of ltp user */
225*49cdfc7eSAndroid Build Coastguard Worker if ((user1 = getpwnam(LTPUSER)) == NULL) {
226*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER);
227*49cdfc7eSAndroid Build Coastguard Worker }
228*49cdfc7eSAndroid Build Coastguard Worker user1_uid = user1->pw_uid;
229*49cdfc7eSAndroid Build Coastguard Worker group1_gid = user1->pw_gid;
230*49cdfc7eSAndroid Build Coastguard Worker
231*49cdfc7eSAndroid Build Coastguard Worker /* Get the effective group id of the test process */
232*49cdfc7eSAndroid Build Coastguard Worker group2_gid = getegid();
233*49cdfc7eSAndroid Build Coastguard Worker
234*49cdfc7eSAndroid Build Coastguard Worker /*
235*49cdfc7eSAndroid Build Coastguard Worker * Create a test directory under temporary directory with the
236*49cdfc7eSAndroid Build Coastguard Worker * specified mode permissions, with uid/gid set to that of guest
237*49cdfc7eSAndroid Build Coastguard Worker * user and the test process.
238*49cdfc7eSAndroid Build Coastguard Worker */
239*49cdfc7eSAndroid Build Coastguard Worker SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
240*49cdfc7eSAndroid Build Coastguard Worker SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid);
241*49cdfc7eSAndroid Build Coastguard Worker SAFE_CHMOD(cleanup, DIR_TEMP, MODE_SGID);
242*49cdfc7eSAndroid Build Coastguard Worker
243*49cdfc7eSAndroid Build Coastguard Worker /*
244*49cdfc7eSAndroid Build Coastguard Worker * Verify that test directory created with expected permission modes
245*49cdfc7eSAndroid Build Coastguard Worker * and ownerships.
246*49cdfc7eSAndroid Build Coastguard Worker */
247*49cdfc7eSAndroid Build Coastguard Worker SAFE_STAT(cleanup, DIR_TEMP, &buf);
248*49cdfc7eSAndroid Build Coastguard Worker
249*49cdfc7eSAndroid Build Coastguard Worker /* Verify modes of test directory */
250*49cdfc7eSAndroid Build Coastguard Worker if (!(buf.st_mode & S_ISGID)) {
251*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup,
252*49cdfc7eSAndroid Build Coastguard Worker "%s: Incorrect modes, setgid bit not set", DIR_TEMP);
253*49cdfc7eSAndroid Build Coastguard Worker }
254*49cdfc7eSAndroid Build Coastguard Worker
255*49cdfc7eSAndroid Build Coastguard Worker /* Verify group ID */
256*49cdfc7eSAndroid Build Coastguard Worker if (buf.st_gid != group2_gid) {
257*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP);
258*49cdfc7eSAndroid Build Coastguard Worker }
259*49cdfc7eSAndroid Build Coastguard Worker
260*49cdfc7eSAndroid Build Coastguard Worker /*
261*49cdfc7eSAndroid Build Coastguard Worker * Set the effective group id and user id of the test process
262*49cdfc7eSAndroid Build Coastguard Worker * to that of guest user (nobody)
263*49cdfc7eSAndroid Build Coastguard Worker */
264*49cdfc7eSAndroid Build Coastguard Worker SAFE_SETGID(cleanup, group1_gid);
265*49cdfc7eSAndroid Build Coastguard Worker if (setreuid(-1, user1_uid) < 0) {
266*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup,
267*49cdfc7eSAndroid Build Coastguard Worker "Unable to set process uid to that of ltp user");
268*49cdfc7eSAndroid Build Coastguard Worker }
269*49cdfc7eSAndroid Build Coastguard Worker
270*49cdfc7eSAndroid Build Coastguard Worker /* Save the real group ID of the current process */
271*49cdfc7eSAndroid Build Coastguard Worker mygid = getgid();
272*49cdfc7eSAndroid Build Coastguard Worker
273*49cdfc7eSAndroid Build Coastguard Worker /* Change directory to DIR_TEMP */
274*49cdfc7eSAndroid Build Coastguard Worker SAFE_CHDIR(cleanup, DIR_TEMP);
275*49cdfc7eSAndroid Build Coastguard Worker }
276*49cdfc7eSAndroid Build Coastguard Worker
277*49cdfc7eSAndroid Build Coastguard Worker /*
278*49cdfc7eSAndroid Build Coastguard Worker * cleanup() - Performs all ONE TIME cleanup for this test at
279*49cdfc7eSAndroid Build Coastguard Worker * completion or premature exit.
280*49cdfc7eSAndroid Build Coastguard Worker * Print test timing stats and errno log if test executed with options.
281*49cdfc7eSAndroid Build Coastguard Worker * Restore the real/effective user id of the process changed during
282*49cdfc7eSAndroid Build Coastguard Worker * setup().
283*49cdfc7eSAndroid Build Coastguard Worker * Remove temporary directory and sub-directories/files under it
284*49cdfc7eSAndroid Build Coastguard Worker * created during setup().
285*49cdfc7eSAndroid Build Coastguard Worker * Exit the test program with normal exit code.
286*49cdfc7eSAndroid Build Coastguard Worker */
cleanup(void)287*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
288*49cdfc7eSAndroid Build Coastguard Worker {
289*49cdfc7eSAndroid Build Coastguard Worker
290*49cdfc7eSAndroid Build Coastguard Worker /*
291*49cdfc7eSAndroid Build Coastguard Worker * Restore the effective uid of the process changed in the
292*49cdfc7eSAndroid Build Coastguard Worker * setup().
293*49cdfc7eSAndroid Build Coastguard Worker */
294*49cdfc7eSAndroid Build Coastguard Worker if (setreuid(-1, save_myuid) < 0) {
295*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup,
296*49cdfc7eSAndroid Build Coastguard Worker "resetting process real/effective uid failed");
297*49cdfc7eSAndroid Build Coastguard Worker }
298*49cdfc7eSAndroid Build Coastguard Worker
299*49cdfc7eSAndroid Build Coastguard Worker tst_rmdir();
300*49cdfc7eSAndroid Build Coastguard Worker
301*49cdfc7eSAndroid Build Coastguard Worker }
302