blob: c9fe7f129775457a3ecbac9ed1455dbf907d0715 [file] [log] [blame]
vapierd13d74b2006-02-11 07:24:00 +00001/*
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +04002 * Copyright (C) International Business Machines Corp., 2001
3 * Ported by Wayne Boyer
4 * Adapted by Dustin Kirkland (k1rkland@us.ibm.com)
vapierd13d74b2006-02-11 07:24:00 +00005 *
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +04006 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
vapierd13d74b2006-02-11 07:24:00 +000010 *
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040011 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
vapierd13d74b2006-02-11 07:24:00 +000015 *
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040016 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
vapierd13d74b2006-02-11 07:24:00 +000019 */
20
21/*
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040022 * Testcase to test the basic functionality of the setfsuid(2) system
23 * call to fail on invalid uid.
vapierd13d74b2006-02-11 07:24:00 +000024 */
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040025
vapierd13d74b2006-02-11 07:24:00 +000026#include <stdio.h>
27#include <unistd.h>
28#include <pwd.h>
vapierd13d74b2006-02-11 07:24:00 +000029#include <sys/types.h>
30#include <errno.h>
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040031
vapierd13d74b2006-02-11 07:24:00 +000032#include "test.h"
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040033#include "compat_16.h"
vapierd13d74b2006-02-11 07:24:00 +000034
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040035static void setup(void);
36static void cleanup(void);
vapierd13d74b2006-02-11 07:24:00 +000037
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040038TCID_DEFINE(setfsuid02);
vapierd13d74b2006-02-11 07:24:00 +000039int TST_TOTAL = 1;
vapierd13d74b2006-02-11 07:24:00 +000040
41int main(int ac, char **av)
42{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020043 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020044 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000045
46 uid_t uid;
subrata_modakbdbaec52009-02-26 12:14:51 +000047
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040048 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080049 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000050
51 setup();
52
subrata_modak56207ce2009-03-23 13:35:39 +000053 uid = 1;
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040054 while (getpwuid(uid))
subrata_modak56207ce2009-03-23 13:35:39 +000055 uid++;
vapierd13d74b2006-02-11 07:24:00 +000056
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040057 UID16_CHECK(uid, setfsuid, cleanup);
58
vapierd13d74b2006-02-11 07:24:00 +000059 for (lc = 0; TEST_LOOPING(lc); lc++) {
60
Caspar Zhangd59a6592013-03-07 14:59:12 +080061 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +000062
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040063 TEST(SETFSUID(cleanup, uid));
vapierd13d74b2006-02-11 07:24:00 +000064
65 if (TEST_RETURN == -1) {
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040066 tst_resm(TFAIL | TTERRNO,
67 "setfsuid() failed unexpectedly");
vapierd13d74b2006-02-11 07:24:00 +000068 continue;
69 }
70
vapierd13d74b2006-02-11 07:24:00 +000071 if (TEST_RETURN == uid) {
subrata_modak923b23f2009-11-02 13:57:16 +000072 tst_resm(TFAIL, "setfsuid() returned %ld, expected %d",
vapierd13d74b2006-02-11 07:24:00 +000073 TEST_RETURN, uid);
74 } else {
75 tst_resm(TPASS, "setfsuid() returned expected value : "
subrata_modak923b23f2009-11-02 13:57:16 +000076 "%ld", TEST_RETURN);
vapierd13d74b2006-02-11 07:24:00 +000077 }
78 }
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040079
vapierd13d74b2006-02-11 07:24:00 +000080 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080081 tst_exit();
Wanlong Gao354ebb42012-12-07 10:10:04 +080082}
vapierd13d74b2006-02-11 07:24:00 +000083
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040084static void setup(void)
vapierd13d74b2006-02-11 07:24:00 +000085{
vapierd13d74b2006-02-11 07:24:00 +000086 tst_sig(NOFORK, DEF_HANDLER, cleanup);
87
vapierd13d74b2006-02-11 07:24:00 +000088 TEST_PAUSE;
89}
90
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040091static void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +000092{
Chris Dearmanec6edca2012-10-17 19:54:01 -070093}