blob: 50767ef842d81811b168d03f0fb56bc3c9915241 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +04002 * Copyright (c) International Business Machines Corp., 2001
3 * Ported by Wayne Boyer
plars865695b2001-08-27 22:15:12 +00004 *
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +04005 * 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.
plars865695b2001-08-27 22:15:12 +00009 *
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040010 * 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.
plars865695b2001-08-27 22:15:12 +000014 *
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040015 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040021 * Testcase to test the basic functionality of the setfsuid(2) system call.
plars865695b2001-08-27 22:15:12 +000022 */
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040023
robbiewda0cc972003-03-28 17:18:51 +000024#include <sys/types.h>
25#include <sys/fsuid.h>
plars865695b2001-08-27 22:15:12 +000026#include <stdio.h>
27#include <unistd.h>
plars865695b2001-08-27 22:15:12 +000028#include <errno.h>
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040029
plars865695b2001-08-27 22:15:12 +000030#include "test.h"
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040031#include "compat_16.h"
plars865695b2001-08-27 22:15:12 +000032
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040033static void setup(void);
34static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000035
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040036TCID_DEFINE(setfsuid01);
plars865695b2001-08-27 22:15:12 +000037int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000038
robbiewda0cc972003-03-28 17:18:51 +000039int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000040{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020041 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020042 const char *msg;
plars865695b2001-08-27 22:15:12 +000043
44 uid_t uid;
subrata_modakbdbaec52009-02-26 12:14:51 +000045
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040046 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080047 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000048
49 setup();
50
51 uid = geteuid();
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040052 UID16_CHECK(uid, setfsuid, cleanup);
plars865695b2001-08-27 22:15:12 +000053
plars865695b2001-08-27 22:15:12 +000054 for (lc = 0; TEST_LOOPING(lc); lc++) {
55
Caspar Zhangd59a6592013-03-07 14:59:12 +080056 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000057
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040058 TEST(SETFSUID(cleanup, uid));
plars865695b2001-08-27 22:15:12 +000059
60 if (TEST_RETURN == -1) {
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040061 tst_resm(TFAIL | TTERRNO,
62 "setfsuid() failed unexpectedly");
plars865695b2001-08-27 22:15:12 +000063 continue;
64 }
65
plars865695b2001-08-27 22:15:12 +000066 if (TEST_RETURN != uid) {
subrata_modak923b23f2009-11-02 13:57:16 +000067 tst_resm(TFAIL, "setfsuid() returned %ld, expected %d",
plars865695b2001-08-27 22:15:12 +000068 TEST_RETURN, uid);
69 } else {
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040070 tst_resm(TPASS,
71 "setfsuid() returned expected value : %ld",
72 TEST_RETURN);
plars865695b2001-08-27 22:15:12 +000073 }
74 }
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040075
plars865695b2001-08-27 22:15:12 +000076 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080077 tst_exit();
plars865695b2001-08-27 22:15:12 +000078}
79
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040080static void setup(void)
plars865695b2001-08-27 22:15:12 +000081{
plars865695b2001-08-27 22:15:12 +000082 tst_sig(NOFORK, DEF_HANDLER, cleanup);
83
plars865695b2001-08-27 22:15:12 +000084 TEST_PAUSE;
85}
86
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040087static void cleanup(void)
plars865695b2001-08-27 22:15:12 +000088{
Chris Dearmanec6edca2012-10-17 19:54:01 -070089}