• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) International Business Machines  Corp., 2001
3  *
4  * This program is free software;  you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12  * the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program;  if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /* DESCRIPTION
19  *	This test will verify that setuid(2) syscall basic functionality.
20  *	setuid(2) returns a value of 0 and uid has been set successfully
21  *	as a normal or super user.
22  */
23 
24 #include <errno.h>
25 #include <unistd.h>
26 #include <sys/types.h>
27 #include "tst_test.h"
28 #include "compat_tst_16.h"
29 
verify_setuid(void)30 static void verify_setuid(void)
31 {
32 	uid_t uid;
33 
34 	/* Set the effective user ID to the current real uid */
35 	uid = getuid();
36 	UID16_CHECK(uid, setuid);
37 
38 	TEST(SETUID(uid));
39 	if (TST_RET == -1)
40 		tst_res(TFAIL | TTERRNO, "setuid(%d) failed", uid);
41 	else
42 		tst_res(TPASS, "setuid(%d) successfully", uid);
43 }
44 
45 static struct tst_test test = {
46 	.test_all = verify_setuid,
47 };
48