plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
Cyril Hrubis | 089e030 | 2014-06-03 14:37:32 +0200 | [diff] [blame] | 3 | * AUTHOR : William Roske |
| 4 | * CO-PILOT : Dave Fenner |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 5 | * |
| 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 Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 22 | * with this program; if not, write the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 24 | * |
| 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 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 35 | #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 Hrubis | 089e030 | 2014-06-03 14:37:32 +0200 | [diff] [blame] | 43 | #include "safe_macros.h" |
Han Pingtian | 75fb057 | 2014-11-28 16:33:41 +0800 | [diff] [blame] | 44 | #include "compat_16.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 45 | |
Cyril Hrubis | 089e030 | 2014-06-03 14:37:32 +0200 | [diff] [blame] | 46 | static void setup(void); |
| 47 | static void cleanup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | |
Han Pingtian | 75fb057 | 2014-11-28 16:33:41 +0800 | [diff] [blame] | 49 | TCID_DEFINE(fchown01); |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 50 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | |
Cyril Hrubis | 089e030 | 2014-06-03 14:37:32 +0200 | [diff] [blame] | 52 | static int fd; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 53 | |
vapier | 37cf54a | 2007-04-13 20:58:17 +0000 | [diff] [blame] | 54 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 55 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 56 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 57 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 59 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 60 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 61 | |
vapier | 37cf54a | 2007-04-13 20:58:17 +0000 | [diff] [blame] | 62 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 63 | |
vapier | 37cf54a | 2007-04-13 20:58:17 +0000 | [diff] [blame] | 64 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 66 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | |
Han Pingtian | 75fb057 | 2014-11-28 16:33:41 +0800 | [diff] [blame] | 68 | UID16_CHECK(geteuid(), "fchown", cleanup) |
| 69 | GID16_CHECK(getegid(), "fchown", cleanup) |
| 70 | |
| 71 | TEST(FCHOWN(cleanup, fd, geteuid(), getegid())); |
vapier | 37cf54a | 2007-04-13 20:58:17 +0000 | [diff] [blame] | 72 | |
Cyril Hrubis | 089e030 | 2014-06-03 14:37:32 +0200 | [diff] [blame] | 73 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 74 | tst_resm(TFAIL | TTERRNO, "fchown failed"); |
Cyril Hrubis | 089e030 | 2014-06-03 14:37:32 +0200 | [diff] [blame] | 75 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 76 | tst_resm(TPASS, |
| 77 | "fchown(fd, geteuid(), getegid()) " |
| 78 | "returned %ld", TEST_RETURN); |
Cyril Hrubis | 089e030 | 2014-06-03 14:37:32 +0200 | [diff] [blame] | 79 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 80 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | |
vapier | 37cf54a | 2007-04-13 20:58:17 +0000 | [diff] [blame] | 82 | cleanup(); |
Garrett Cooper | 1569799 | 2010-12-18 06:31:28 -0800 | [diff] [blame] | 83 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 84 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 85 | |
Cyril Hrubis | 089e030 | 2014-06-03 14:37:32 +0200 | [diff] [blame] | 86 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | { |
vapier | 37cf54a | 2007-04-13 20:58:17 +0000 | [diff] [blame] | 88 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 89 | |
vapier | 37cf54a | 2007-04-13 20:58:17 +0000 | [diff] [blame] | 90 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | |
vapier | 37cf54a | 2007-04-13 20:58:17 +0000 | [diff] [blame] | 92 | tst_tmpdir(); |
Cyril Hrubis | 089e030 | 2014-06-03 14:37:32 +0200 | [diff] [blame] | 93 | fd = SAFE_OPEN(cleanup, "tempfile", O_RDWR | O_CREAT, 0700); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 94 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 95 | |
Cyril Hrubis | 089e030 | 2014-06-03 14:37:32 +0200 | [diff] [blame] | 96 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | { |
Cyril Hrubis | 089e030 | 2014-06-03 14:37:32 +0200 | [diff] [blame] | 98 | if (fd > 0 && close(fd)) |
| 99 | tst_resm(TWARN | TERRNO, "Failed to close fd"); |
| 100 | |
vapier | 37cf54a | 2007-04-13 20:58:17 +0000 | [diff] [blame] | 101 | tst_rmdir(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 102 | } |