blob: 66d1c60d92292c67657d403b4f74884d423adfb6 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
21 * NAME
22 * setfsuid01.c
23 *
24 * DESCRIPTION
25 * Testcase to test the basic functionality of the setfsuid(2) system
26 * call.
27 *
28 * ALGORITHM
29 * Call setfsuid(2) and test the uid returned by setfsuid(2).
30 * If the returned value doesn't match the uid of the process,
31 * then the testcase fails.
32 *
33 * USAGE: <for command-line>
34 * setfsuid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
35 * where, -c n : Run n copies concurrently.
36 * -f : Turn off functionality Testing.
37 * -i n : Execute test n times.
38 * -I x : Execute test for x seconds.
39 * -P x : Pause for x seconds between iterations.
40 * -t : Turn on syscall timing.
41 *
42 * HISTORY
43 * 07/2001 Ported by Wayne Boyer
44 *
45 * RESTRICTIONS
46 * None
47 */
robbiewda0cc972003-03-28 17:18:51 +000048#include <sys/types.h>
49#include <sys/fsuid.h>
plars865695b2001-08-27 22:15:12 +000050#include <stdio.h>
51#include <unistd.h>
plars865695b2001-08-27 22:15:12 +000052#include <errno.h>
53#include "test.h"
54#include "usctest.h"
55
56void setup(void);
57void cleanup(void);
58
59char *TCID = "setfsuid01";
60int TST_TOTAL = 1;
61extern int Tst_count;
62
robbiewda0cc972003-03-28 17:18:51 +000063int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000064{
65 int lc; /* loop counter */
66 char *msg; /* message returned from parse_opts */
67
68 uid_t uid;
69
70 /* parse standard options */
71 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
72 tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
73 }
74
75 setup();
76
77 uid = geteuid();
78
79 /* Check for looping state if -i option is given */
80 for (lc = 0; TEST_LOOPING(lc); lc++) {
81
82 /* reset Tst_count in case we are looping */
83 Tst_count = 0;
84
85 TEST(setfsuid(uid));
86
87 if (TEST_RETURN == -1) {
88 tst_resm(TFAIL, "call failed unexpectedly - errno %d",
89 TEST_ERRNO);
90 continue;
91 }
92
93 if (!STD_FUNCTIONAL_TEST) {
94 tst_resm(TPASS, "call succeeded");
95 continue;
96 }
97
98 if (TEST_RETURN != uid) {
99 tst_resm(TFAIL, "setfsuid() returned %d, expected %d",
100 TEST_RETURN, uid);
101 } else {
102 tst_resm(TPASS, "setfsuid() returned expected value : "
103 "%d", uid);
104 }
105 }
106 cleanup();
107
108 /*NOTREACHED*/
robbiewda0cc972003-03-28 17:18:51 +0000109 return(0);
plars865695b2001-08-27 22:15:12 +0000110}
111
112/*
113 * setup() - performs all ONE TIME setup for this test.
114 */
115void
116setup()
117{
118 /* capture signals */
119 tst_sig(NOFORK, DEF_HANDLER, cleanup);
120
121 /* Pause if that option was specified */
122 TEST_PAUSE;
123}
124
125/*
126 * cleanup() - performs all ONE TIME cleanup for this test at
127 * completion or premature exit.
128 */
129void
130cleanup()
131{
132 /*
133 * print timing stats if that option was specified.
134 * print errno log if that option was specified.
135 */
136 TEST_CLEANUP;
137}