blob: 097a0a6ab4746cc93d0f8f1f68f609f8996a3817 [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 check the basic functionality of setfsgid(2) system call.
plars865695b2001-08-27 22:15:12 +000022 */
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040023
plars865695b2001-08-27 22:15:12 +000024#include <stdio.h>
25#include <unistd.h>
robbiew8541eeb2003-03-27 19:59:32 +000026#include <sys/fsuid.h>
plars865695b2001-08-27 22:15:12 +000027#include <sys/types.h>
28#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 +040033TCID_DEFINE(setfsgid01);
plars865695b2001-08-27 22:15:12 +000034int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000035
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040036static void setup(void);
37static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000038
robbiew8541eeb2003-03-27 19:59:32 +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 gid_t gid;
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
plars865695b2001-08-27 22:15:12 +000051 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080052 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000053
54 gid = getegid();
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040055 GID16_CHECK(gid, setfsgid, cleanup);
plars865695b2001-08-27 22:15:12 +000056
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040057 TEST(SETFSGID(cleanup, gid));
plars865695b2001-08-27 22:15:12 +000058
59 if (TEST_RETURN == -1) {
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040060 tst_resm(TFAIL | TTERRNO,
61 "setfsgid() failed unexpectedly");
plars865695b2001-08-27 22:15:12 +000062 continue;
63 }
64
plars865695b2001-08-27 22:15:12 +000065 if (TEST_RETURN != gid) {
subrata_modak923b23f2009-11-02 13:57:16 +000066 tst_resm(TFAIL, "setfsgid() returned %ld, expected %d",
plars865695b2001-08-27 22:15:12 +000067 TEST_RETURN, gid);
68 } else {
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040069 tst_resm(TPASS,
70 "setfsgid() returned expected value : %ld",
71 TEST_RETURN);
plars865695b2001-08-27 22:15:12 +000072 }
73 }
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040074
plars865695b2001-08-27 22:15:12 +000075 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080076 tst_exit();
plars865695b2001-08-27 22:15:12 +000077}
78
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040079static void setup(void)
plars865695b2001-08-27 22:15:12 +000080{
plars865695b2001-08-27 22:15:12 +000081 tst_sig(NOFORK, DEF_HANDLER, cleanup);
82
plars865695b2001-08-27 22:15:12 +000083 TEST_PAUSE;
84}
85
Stanislav Kholmanskikh0e7a99b2013-09-13 13:59:10 +040086static void cleanup(void)
plars865695b2001-08-27 22:15:12 +000087{
Chris Dearmanec6edca2012-10-17 19:54:01 -070088}