~apparmor-dev/apparmor/master

« back to all changes in this revision

Viewing changes to tests/regression/apparmor/syscall_mknod.c

  • Committer: Steve Beattie
  • Date: 2019-02-19 09:38:13 UTC
  • Revision ID: sbeattie@ubuntu.com-20190219093813-ud526ee6hwn8nljz
The AppArmor project has been converted to git and is now hosted on
gitlab.

To get the converted repository, please do
  git clone https://gitlab.com/apparmor/apparmor

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *      Copyright (C) 2002-2005 Novell/SUSE
3
 
 *
4
 
 *      This program is free software; you can redistribute it and/or
5
 
 *      modify it under the terms of the GNU General Public License as
6
 
 *      published by the Free Software Foundation, version 2 of the
7
 
 *      License.
8
 
 */
9
 
 
10
 
#include <stdio.h>
11
 
#include <unistd.h>
12
 
#include <errno.h>
13
 
#include <sys/types.h>
14
 
#include <sys/stat.h>
15
 
#include <fcntl.h>
16
 
#include <string.h>
17
 
 
18
 
int main(int argc, char *argv[])
19
 
{
20
 
        int mode;
21
 
 
22
 
        if (argc != 3){
23
 
                fprintf(stderr, "usage: %s b|c|f|s|r file\n",
24
 
                        argv[0]);
25
 
                return 1;
26
 
        }
27
 
 
28
 
        if (strcmp(argv[1], "b") == 0){
29
 
                mode=S_IFBLK;
30
 
        }else if (strcmp(argv[1], "c") == 0){
31
 
                mode=S_IFCHR;
32
 
        }else if (strcmp(argv[1], "f") == 0){
33
 
                mode=S_IFIFO;
34
 
        }else if (strcmp(argv[1], "s") == 0){
35
 
                mode=S_IFSOCK;
36
 
        }else if (strcmp(argv[1], "r") == 0){
37
 
                mode=S_IFREG;
38
 
        }else{
39
 
                fprintf(stderr, "FAIL: type must be b|c|f|s|r\n");
40
 
                return 1;
41
 
        }
42
 
 
43
 
        if (mknod(argv[2], mode, 1) == -1){
44
 
                fprintf(stderr, "FAIL: mknod %s failed - %s\n",
45
 
                        argv[1],
46
 
                        strerror(errno));
47
 
                return 1;
48
 
        }
49
 
 
50
 
        printf("PASS\n");
51
 
 
52
 
        return 0;
53
 
}