plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +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 | |
| 36 | #include <unistd.h> |
| 37 | #include <errno.h> |
| 38 | #include <string.h> |
| 39 | #include <signal.h> |
| 40 | #include <sys/types.h> |
| 41 | #include <sys/stat.h> |
| 42 | |
| 43 | #include "test.h" |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +0200 | [diff] [blame] | 44 | #include "safe_macros.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 45 | |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +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 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 49 | char *TCID = "mknod01"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 50 | |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +0200 | [diff] [blame] | 51 | #define PATH "test_node" |
| 52 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 53 | int tcases[] = { /* modes to give nodes created (1 per text case) */ |
| 54 | S_IFREG | 0777, /* ordinary file with mode 0777 */ |
| 55 | S_IFIFO | 0777, /* fifo special with mode 0777 */ |
| 56 | S_IFCHR | 0777, /* character special with mode 0777 */ |
| 57 | S_IFBLK | 0777, /* block special with mode 0777 */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 59 | S_IFREG | 04700, /* ordinary file with mode 04700 (suid) */ |
| 60 | S_IFREG | 02700, /* ordinary file with mode 02700 (sgid) */ |
| 61 | S_IFREG | 06700, /* ordinary file with mode 06700 (sgid & suid) */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +0200 | [diff] [blame] | 64 | int TST_TOTAL = ARRAY_SIZE(tcases); |
| 65 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 66 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | { |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +0200 | [diff] [blame] | 68 | int lc, i; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 69 | const char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 70 | |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +0200 | [diff] [blame] | 71 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 72 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 73 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 74 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 75 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 76 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 77 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 79 | for (i = 0; i < TST_TOTAL; i++) { |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +0200 | [diff] [blame] | 80 | TEST(mknod(PATH, tcases[i], 0)); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 81 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 82 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 83 | tst_resm(TFAIL, |
| 84 | "mknod(%s, %#o, 0) failed, errno=%d : %s", |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +0200 | [diff] [blame] | 85 | PATH, tcases[i], TEST_ERRNO, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 86 | strerror(TEST_ERRNO)); |
| 87 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 88 | tst_resm(TPASS, |
| 89 | "mknod(%s, %#o, 0) returned %ld", |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +0200 | [diff] [blame] | 90 | PATH, tcases[i], TEST_RETURN); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 91 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +0200 | [diff] [blame] | 93 | SAFE_UNLINK(cleanup, PATH); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 96 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | cleanup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 99 | tst_exit(); |
| 100 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 102 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | { |
Cyril Hrubis | c183203 | 2014-06-02 18:24:10 +0200 | [diff] [blame] | 104 | tst_require_root(NULL); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 105 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 106 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 107 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 108 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 109 | tst_tmpdir(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 110 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 112 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 113 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 114 | tst_rmdir(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 115 | } |