setuid01.c revision fdce7d5e2a219d201a2b0e3bab6b61b01ec1d716
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/* $Id: setuid01.c,v 1.5 2009/11/02 13:57:18 subrata_modak Exp $ */
33/**********************************************************
34 *
35 *    OS Test - Silicon Graphics, Inc.
36 *
37 *    TEST IDENTIFIER	: setuid01
38 *
39 *    EXECUTED BY	: anyone
40 *
41 *    TEST TITLE	: Basic test for setuid(2)
42 *
43 *    PARENT DOCUMENT	: usctpl01
44 *
45 *    TEST CASE TOTAL	: 1
46 *
47 *    WALL CLOCK TIME	: 1
48 *
49 *    CPU TYPES		: ALL
50 *
51 *    AUTHOR		: William Roske
52 *
53 *    CO-PILOT		: Dave Fenner
54 *
55 *    DATE STARTED	: 05/14/92
56 *
57 *    INITIAL RELEASE	: UNICOS 7.0
58 *
59 *    TEST CASES
60 *
61 * 	1.) setuid(2) returns...(See Description)
62 *
63 *    INPUT SPECIFICATIONS
64 * 	The standard options for system call tests are accepted.
65 *	(See the parse_opts(3) man page).
66 *
67 *    OUTPUT SPECIFICATIONS
68 *$
69 *    DURATION
70 * 	Terminates - with frequency and infinite modes.
71 *
72 *    SIGNALS
73 * 	Uses SIGUSR1 to pause before test if option set.
74 * 	(See the parse_opts(3) man page).
75 *
76 *    RESOURCES
77 * 	None
78 *
79 *    ENVIRONMENTAL NEEDS
80 * 	The libcuts.a and libsys.a libraries must be included in
81 *	the compilation of this test.
82 *
83 *    SPECIAL PROCEDURAL REQUIREMENTS
84 * 	None
85 *
86 *    INTERCASE DEPENDENCIES
87 * 	None
88 *
89 *    DETAILED DESCRIPTION
90 *	This is a Phase I test for the setuid(2) system call.  It is intended
91 *	to provide a limited exposure of the system call, for now.  It
92 *	should/will be extended when full functional tests are written for
93 *	setuid(2).
94 *
95 * 	Setup:
96 * 	  Setup signal handling.
97 *	  Pause for SIGUSR1 if option specified.
98 *
99 * 	Test:
100 *	 Loop if the proper options are given.
101 * 	  Execute system call
102 *	  Check return code, if system call failed (return=-1)
103 *		Log the errno and Issue a FAIL message.
104 *	  Otherwise, Issue a PASS message.
105 *
106 * 	Cleanup:
107 * 	  Print errno log and/or timing stats if options given
108 *
109 *
110 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
111
112#include <errno.h>
113#include <string.h>
114#include <signal.h>
115
116#include <sys/types.h>
117
118#include "test.h"
119#include "usctest.h"
120
121void setup();
122void cleanup();
123
124char *TCID = "setuid01";
125int TST_TOTAL = 1;
126
127int uid;			/* current user id */
128
129int main(int ac, char **av)
130{
131	int lc;
132	char *msg;
133
134    /***************************************************************
135     * parse standard options
136     ***************************************************************/
137	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
138		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
139
140	}
141
142    /***************************************************************
143     * perform global setup for test
144     ***************************************************************/
145	setup();
146
147    /***************************************************************
148     * check looping state if -c option given
149     ***************************************************************/
150	for (lc = 0; TEST_LOOPING(lc); lc++) {
151
152		tst_count = 0;
153
154		/*
155		 * TEST CASE:
156		 *  Set the effective user ID to the current real uid
157		 */
158		uid = getuid();
159
160		/* Call setuid(2) */
161		TEST(setuid(uid));
162
163		/* check return code */
164		if (TEST_RETURN == -1) {
165			TEST_ERROR_LOG(TEST_ERRNO);
166			tst_resm(TFAIL,
167				 "setuid -  Set the effective user ID to the current real uid failed, errno=%d : %s",
168				 TEST_ERRNO, strerror(TEST_ERRNO));
169		} else {
170	    /***************************************************************
171	     * only perform functional verification if flag set (-f not given)
172	     ***************************************************************/
173			if (STD_FUNCTIONAL_TEST) {
174				/* No Verification test, yet... */
175				tst_resm(TPASS,
176					 "setuid -  Set the effective user ID to the current real uid returned %ld",
177					 TEST_RETURN);
178			}
179		}
180
181	}
182
183    /***************************************************************
184     * cleanup and exit
185     ***************************************************************/
186	cleanup();
187	tst_exit();
188	tst_exit();
189
190}
191
192/***************************************************************
193 * setup() - performs all ONE TIME setup for this test.
194 ***************************************************************/
195void setup()
196{
197
198	tst_sig(NOFORK, DEF_HANDLER, cleanup);
199
200	TEST_PAUSE;
201}
202
203/***************************************************************
204 * cleanup() - performs all ONE TIME cleanup for this test at
205 *		completion or premature exit.
206 ***************************************************************/
207void cleanup()
208{
209	/*
210	 * print timing stats if that option was specified.
211	 * print errno log if that option was specified.
212	 */
213	TEST_CLEANUP;
214
215}
216