blob: 73d8c64eeb0b8d1b448ccdf71eb1d14fd96b3269 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
subrata_modak4bb656a2009-02-26 12:02:09 +00003 *
plars865695b2001-08-27 22:15:12 +00004 * 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.
subrata_modak4bb656a2009-02-26 12:02:09 +00007 *
plars865695b2001-08-27 22:15:12 +00008 * 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.
subrata_modak4bb656a2009-02-26 12:02:09 +000011 *
plars865695b2001-08-27 22:15:12 +000012 * 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.
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
plars865695b2001-08-27 22:15:12 +000019 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080020 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
plars865695b2001-08-27 22:15:12 +000023 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
subrata_modak4bb656a2009-02-26 12:02:09 +000025 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
plars865695b2001-08-27 22:15:12 +000030 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31 */
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020032
33/*
34 * AUTHOR : William Roske
35 * CO-PILOT : Dave Fenner
36 */
plars865695b2001-08-27 22:15:12 +000037
38#include <errno.h>
39#include <string.h>
40#include <signal.h>
plars865695b2001-08-27 22:15:12 +000041#include <sys/types.h>
42
43#include "test.h"
Stanislav Kholmanskikh1c442442013-09-11 13:25:43 +040044#include "compat_16.h"
plars865695b2001-08-27 22:15:12 +000045
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020046static void setup(void);
47static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000048
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020049char *TCID = "setuid01";
50int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000051
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020052static uid_t uid;
plars865695b2001-08-27 22:15:12 +000053
subrata_modak56207ce2009-03-23 13:35:39 +000054int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000055{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020056 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020057 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000058
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020059 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
subrata_modak56207ce2009-03-23 13:35:39 +000060 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080061
subrata_modak56207ce2009-03-23 13:35:39 +000062 setup();
plars865695b2001-08-27 22:15:12 +000063
subrata_modak56207ce2009-03-23 13:35:39 +000064 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080065 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000066
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020067 /* Set the effective user ID to the current real uid */
subrata_modak56207ce2009-03-23 13:35:39 +000068 uid = getuid();
Stanislav Kholmanskikh1c442442013-09-11 13:25:43 +040069 UID16_CHECK(uid, setuid, cleanup);
subrata_modakbdbaec52009-02-26 12:14:51 +000070
Stanislav Kholmanskikh1c442442013-09-11 13:25:43 +040071 TEST(SETUID(cleanup, uid));
subrata_modak56207ce2009-03-23 13:35:39 +000072
subrata_modak56207ce2009-03-23 13:35:39 +000073 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +000074 tst_resm(TFAIL,
75 "setuid - Set the effective user ID to the current real uid failed, errno=%d : %s",
76 TEST_ERRNO, strerror(TEST_ERRNO));
77 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020078 tst_resm(TPASS,
79 "setuid - Set the effective user ID to the current real uid returned %ld",
subrata_modak56207ce2009-03-23 13:35:39 +000080 TEST_RETURN);
subrata_modak56207ce2009-03-23 13:35:39 +000081 }
subrata_modakbdbaec52009-02-26 12:14:51 +000082
Garrett Cooper2c282152010-12-16 00:55:50 -080083 }
plars865695b2001-08-27 22:15:12 +000084
subrata_modak56207ce2009-03-23 13:35:39 +000085 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080086 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080087}
plars865695b2001-08-27 22:15:12 +000088
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020089static void setup(void)
plars865695b2001-08-27 22:15:12 +000090{
subrata_modak56207ce2009-03-23 13:35:39 +000091 tst_sig(NOFORK, DEF_HANDLER, cleanup);
subrata_modak56207ce2009-03-23 13:35:39 +000092 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -080093}
plars865695b2001-08-27 22:15:12 +000094
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020095static void cleanup(void)
plars865695b2001-08-27 22:15:12 +000096{
Chris Dearmanec6edca2012-10-17 19:54:01 -070097}