blob: 1d056f7ab985786bcbcc8b7572e98a85499cacb6 [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 check the basic functionality of setfsgid(2) system
23 * call failures.
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 <grp.h>
29#include <pwd.h>
30#include <sys/types.h>
31#include <errno.h>
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040032
vapierd13d74b2006-02-11 07:24:00 +000033#include "test.h"
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040034#include "compat_16.h"
vapierd13d74b2006-02-11 07:24:00 +000035
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040036TCID_DEFINE(setfsgid02);
vapierd13d74b2006-02-11 07:24:00 +000037int TST_TOTAL = 1;
vapierd13d74b2006-02-11 07:24:00 +000038
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040039static void setup(void);
40static void cleanup(void);
vapierd13d74b2006-02-11 07:24:00 +000041
42int main(int ac, char **av)
43{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020044 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020045 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000046
47 gid_t gid;
subrata_modakbdbaec52009-02-26 12:14:51 +000048
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040049 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080050 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000051
52 setup();
53
vapierd13d74b2006-02-11 07:24:00 +000054 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080055 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +000056
subrata_modak56207ce2009-03-23 13:35:39 +000057 gid = 1;
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040058 while (getgrgid(gid))
subrata_modak56207ce2009-03-23 13:35:39 +000059 gid++;
vapierd13d74b2006-02-11 07:24:00 +000060
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040061 GID16_CHECK(gid, setfsgid, cleanup);
62
63 TEST(SETFSGID(cleanup, gid));
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 "setfsgid() failed unexpectedly");
vapierd13d74b2006-02-11 07:24:00 +000068 continue;
69 }
70
vapierd13d74b2006-02-11 07:24:00 +000071 if (TEST_RETURN == gid) {
subrata_modak923b23f2009-11-02 13:57:16 +000072 tst_resm(TFAIL, "setfsgid() returned %ld, expected %d",
vapierd13d74b2006-02-11 07:24:00 +000073 TEST_RETURN, gid);
74 } else {
75 tst_resm(TPASS, "setfsgid() returned expected value : "
subrata_modak923b23f2009-11-02 13:57:16 +000076 "%ld", TEST_RETURN);
vapierd13d74b2006-02-11 07:24:00 +000077 }
78 }
vapierd13d74b2006-02-11 07:24:00 +000079
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040080 cleanup();
81 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +000082}
83
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}