blob: db0724ebe03dccb0141af11eefed200974842eb2 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
Cyril Hrubis089e0302014-06-03 14:37:32 +02003 * AUTHOR : William Roske
4 * CO-PILOT : Dave Fenner
plars865695b2001-08-27 22:15:12 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it would be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * Further, this software is distributed without any warranty that it is
15 * free of the rightful claim of any third person regarding infringement
16 * or the like. Any license provided herein, whether implied or
17 * otherwise, applies only to this software file. Patent licenses, if
18 * any, provided herein do not apply to combinations of this program with
19 * other software, or any other product whatsoever.
20 *
21 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080022 * with this program; if not, write the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars865695b2001-08-27 22:15:12 +000024 *
25 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 * Mountain View, CA 94043, or:
27 *
28 * http://www.sgi.com
29 *
30 * For further information regarding this notice, see:
31 *
32 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
33 *
34 */
plars865695b2001-08-27 22:15:12 +000035#include <sys/types.h>
36#include <sys/stat.h>
37#include <fcntl.h>
38
39#include <errno.h>
40#include <string.h>
41#include <signal.h>
42#include "test.h"
Cyril Hrubis089e0302014-06-03 14:37:32 +020043#include "safe_macros.h"
Han Pingtian75fb0572014-11-28 16:33:41 +080044#include "compat_16.h"
plars865695b2001-08-27 22:15:12 +000045
Cyril Hrubis089e0302014-06-03 14:37:32 +020046static void setup(void);
47static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000048
Han Pingtian75fb0572014-11-28 16:33:41 +080049TCID_DEFINE(fchown01);
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020050int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000051
Cyril Hrubis089e0302014-06-03 14:37:32 +020052static int fd;
plars865695b2001-08-27 22:15:12 +000053
vapier37cf54a2007-04-13 20:58:17 +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;
plars865695b2001-08-27 22:15:12 +000058
Garrett Cooper45e285d2010-11-22 12:19:25 -080059 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080060 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000061
vapier37cf54a2007-04-13 20:58:17 +000062 setup();
plars865695b2001-08-27 22:15:12 +000063
vapier37cf54a2007-04-13 20:58:17 +000064 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +000065
Caspar Zhangd59a6592013-03-07 14:59:12 +080066 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000067
Han Pingtian75fb0572014-11-28 16:33:41 +080068 UID16_CHECK(geteuid(), "fchown", cleanup)
69 GID16_CHECK(getegid(), "fchown", cleanup)
70
71 TEST(FCHOWN(cleanup, fd, geteuid(), getegid()));
vapier37cf54a2007-04-13 20:58:17 +000072
Cyril Hrubis089e0302014-06-03 14:37:32 +020073 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080074 tst_resm(TFAIL | TTERRNO, "fchown failed");
Cyril Hrubis089e0302014-06-03 14:37:32 +020075 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +080076 tst_resm(TPASS,
77 "fchown(fd, geteuid(), getegid()) "
78 "returned %ld", TEST_RETURN);
Cyril Hrubis089e0302014-06-03 14:37:32 +020079 }
Garrett Cooper2c282152010-12-16 00:55:50 -080080 }
plars865695b2001-08-27 22:15:12 +000081
vapier37cf54a2007-04-13 20:58:17 +000082 cleanup();
Garrett Cooper15697992010-12-18 06:31:28 -080083 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080084}
plars865695b2001-08-27 22:15:12 +000085
Cyril Hrubis089e0302014-06-03 14:37:32 +020086static void setup(void)
plars865695b2001-08-27 22:15:12 +000087{
vapier37cf54a2007-04-13 20:58:17 +000088 tst_sig(FORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +000089
vapier37cf54a2007-04-13 20:58:17 +000090 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +000091
vapier37cf54a2007-04-13 20:58:17 +000092 tst_tmpdir();
Cyril Hrubis089e0302014-06-03 14:37:32 +020093 fd = SAFE_OPEN(cleanup, "tempfile", O_RDWR | O_CREAT, 0700);
Garrett Cooper2c282152010-12-16 00:55:50 -080094}
plars865695b2001-08-27 22:15:12 +000095
Cyril Hrubis089e0302014-06-03 14:37:32 +020096static void cleanup(void)
plars865695b2001-08-27 22:15:12 +000097{
Cyril Hrubis089e0302014-06-03 14:37:32 +020098 if (fd > 0 && close(fd))
99 tst_resm(TWARN | TERRNO, "Failed to close fd");
100
vapier37cf54a2007-04-13 20:58:17 +0000101 tst_rmdir();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700102}