~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/flask/policy/policy/flask/mkflask.sh

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh -
 
2
#
 
3
 
 
4
# FLASK
 
5
 
 
6
set -e
 
7
 
 
8
awk=$1
 
9
shift 1
 
10
 
 
11
# output file
 
12
output_file="flask.h"
 
13
debug_file="class_to_string.h"
 
14
debug_file2="initial_sid_to_string.h"
 
15
 
 
16
cat $* | $awk "
 
17
BEGIN   {
 
18
                outfile = \"$output_file\"
 
19
                debugfile = \"$debug_file\"
 
20
                debugfile2 = \"$debug_file2\"
 
21
                "'
 
22
                nextstate = "CLASS";
 
23
 
 
24
                printf("/* This file is automatically generated.  Do not edit. */\n") > outfile;
 
25
 
 
26
                printf("#ifndef _SELINUX_FLASK_H_\n") > outfile;
 
27
                printf("#define _SELINUX_FLASK_H_\n") > outfile;
 
28
                printf("\n/*\n * Security object class definitions\n */\n") > outfile;
 
29
                printf("/* This file is automatically generated.  Do not edit. */\n") > debugfile;
 
30
                printf("/*\n * Security object class definitions\n */\n") > debugfile;
 
31
                printf("    S_(\"null\")\n") > debugfile;
 
32
                printf("/* This file is automatically generated.  Do not edit. */\n") > debugfile2;
 
33
                printf("static char *initial_sid_to_string[] =\n{\n") > debugfile2;
 
34
                printf("    \"null\",\n") > debugfile2;
 
35
        }
 
36
/^[ \t]*#/      { 
 
37
                        next;
 
38
                }
 
39
$1 == "class"   { 
 
40
                        if (nextstate != "CLASS")
 
41
                        {
 
42
                                printf("Parse error:  Unexpected class definition on line %d\n", NR);
 
43
                                next;   
 
44
                        }
 
45
 
 
46
                        if ($2 in class_found)
 
47
                        {
 
48
                                printf("Duplicate class definition for %s on line %d.\n", $2, NR);
 
49
                                next;
 
50
                        }       
 
51
                        class_found[$2] = 1;
 
52
 
 
53
                        class_value++;
 
54
 
 
55
                        printf("#define SECCLASS_%s", toupper($2)) > outfile;
 
56
                        for (i = 0; i < 40 - length($2); i++) 
 
57
                                printf(" ") > outfile; 
 
58
                        printf("%d\n", class_value) > outfile; 
 
59
 
 
60
                        printf("    S_(\"%s\")\n", $2) > debugfile;
 
61
                }
 
62
$1 == "sid"     { 
 
63
                        if (nextstate == "CLASS")
 
64
                        {
 
65
                            nextstate = "SID";
 
66
                            printf("\n/*\n * Security identifier indices for initial entities\n */\n") > outfile;                           
 
67
                        }
 
68
 
 
69
                        if ($2 in sid_found)
 
70
                        {
 
71
                                printf("Duplicate SID definition for %s on line %d.\n", $2, NR);
 
72
                                next;
 
73
                        }       
 
74
                        sid_found[$2] = 1;
 
75
                        sid_value++;
 
76
 
 
77
                        printf("#define SECINITSID_%s", toupper($2)) > outfile;
 
78
                        for (i = 0; i < 37 - length($2); i++) 
 
79
                                printf(" ") > outfile; 
 
80
                        printf("%d\n", sid_value) > outfile; 
 
81
                        printf("    \"%s\",\n", $2) > debugfile2;
 
82
                }
 
83
END     {
 
84
                if (nextstate != "SID")
 
85
                        printf("Parse error:  Unexpected end of file\n");
 
86
 
 
87
                printf("\n#define SECINITSID_NUM") > outfile;
 
88
                for (i = 0; i < 34; i++) 
 
89
                        printf(" ") > outfile; 
 
90
                printf("%d\n", sid_value) > outfile; 
 
91
                printf("\n#endif\n") > outfile;
 
92
                printf("};\n\n") > debugfile2;
 
93
        }'
 
94
 
 
95
# FLASK