blob: f2abd2c2c7bd4a9042fcb0cb2359305ff063d9e3 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
Cyril Hrubisc1832032014-06-02 18:24:10 +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
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 Hrubisc1832032014-06-02 18:24:10 +020044#include "safe_macros.h"
plars865695b2001-08-27 22:15:12 +000045
Cyril Hrubisc1832032014-06-02 18:24:10 +020046static void setup(void);
47static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000048
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020049char *TCID = "mknod01";
plars865695b2001-08-27 22:15:12 +000050
Cyril Hrubisc1832032014-06-02 18:24:10 +020051#define PATH "test_node"
52
subrata_modak56207ce2009-03-23 13:35:39 +000053int 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 */
plars865695b2001-08-27 22:15:12 +000058
subrata_modak56207ce2009-03-23 13:35:39 +000059 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) */
plars865695b2001-08-27 22:15:12 +000062};
63
Cyril Hrubisc1832032014-06-02 18:24:10 +020064int TST_TOTAL = ARRAY_SIZE(tcases);
65
subrata_modak56207ce2009-03-23 13:35:39 +000066int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000067{
Cyril Hrubisc1832032014-06-02 18:24:10 +020068 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020069 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000070
Cyril Hrubisc1832032014-06-02 18:24:10 +020071 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
subrata_modak56207ce2009-03-23 13:35:39 +000072 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000073
subrata_modak56207ce2009-03-23 13:35:39 +000074 setup();
plars865695b2001-08-27 22:15:12 +000075
subrata_modak56207ce2009-03-23 13:35:39 +000076 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080077 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000078
subrata_modak56207ce2009-03-23 13:35:39 +000079 for (i = 0; i < TST_TOTAL; i++) {
Cyril Hrubisc1832032014-06-02 18:24:10 +020080 TEST(mknod(PATH, tcases[i], 0));
subrata_modak56207ce2009-03-23 13:35:39 +000081
subrata_modak56207ce2009-03-23 13:35:39 +000082 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +000083 tst_resm(TFAIL,
84 "mknod(%s, %#o, 0) failed, errno=%d : %s",
Cyril Hrubisc1832032014-06-02 18:24:10 +020085 PATH, tcases[i], TEST_ERRNO,
subrata_modak56207ce2009-03-23 13:35:39 +000086 strerror(TEST_ERRNO));
87 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020088 tst_resm(TPASS,
89 "mknod(%s, %#o, 0) returned %ld",
Cyril Hrubisc1832032014-06-02 18:24:10 +020090 PATH, tcases[i], TEST_RETURN);
subrata_modak56207ce2009-03-23 13:35:39 +000091 }
plars865695b2001-08-27 22:15:12 +000092
Cyril Hrubisc1832032014-06-02 18:24:10 +020093 SAFE_UNLINK(cleanup, PATH);
subrata_modak56207ce2009-03-23 13:35:39 +000094 }
95
Garrett Cooper2c282152010-12-16 00:55:50 -080096 }
plars865695b2001-08-27 22:15:12 +000097
subrata_modak56207ce2009-03-23 13:35:39 +000098 cleanup();
Garrett Cooper2c282152010-12-16 00:55:50 -080099 tst_exit();
100}
plars865695b2001-08-27 22:15:12 +0000101
Mike Frysingerc57fba52014-04-09 18:56:30 -0400102void setup(void)
plars865695b2001-08-27 22:15:12 +0000103{
Cyril Hrubisc1832032014-06-02 18:24:10 +0200104 tst_require_root(NULL);
subrata_modak56207ce2009-03-23 13:35:39 +0000105 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000106
subrata_modak56207ce2009-03-23 13:35:39 +0000107 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000108
subrata_modak56207ce2009-03-23 13:35:39 +0000109 tst_tmpdir();
Garrett Cooper2c282152010-12-16 00:55:50 -0800110}
plars865695b2001-08-27 22:15:12 +0000111
Mike Frysingerc57fba52014-04-09 18:56:30 -0400112void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000113{
subrata_modak56207ce2009-03-23 13:35:39 +0000114 tst_rmdir();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700115}