~ubuntu-branches/ubuntu/dapper/selinux-policy-default/dapper

« back to all changes in this revision

Viewing changes to flask/mkflask.sh

  • Committer: Bazaar Package Importer
  • Author(s): Russell Coker
  • Date: 2004-06-10 18:08:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040610180800-gagxr0cdovi7mv2i
Tags: upstream-1.12
ImportĀ upstreamĀ versionĀ 1.12

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("static char *class_to_string[] =\n{\n") > debugfile;
 
32
                printf("    \"null\",\n") > debugfile;
 
33
                printf("/* This file is automatically generated.  Do not edit. */\n") > debugfile2;
 
34
                printf("static char *initial_sid_to_string[] =\n{\n") > debugfile2;
 
35
                printf("    \"null\",\n") > debugfile2;
 
36
        }
 
37
/^[ \t]*#/      { 
 
38
                        next;
 
39
                }
 
40
$1 == "class"   { 
 
41
                        if (nextstate != "CLASS")
 
42
                        {
 
43
                                printf("Parse error:  Unexpected class definition on line %d\n", NR);
 
44
                                next;   
 
45
                        }
 
46
 
 
47
                        if ($2 in class_found)
 
48
                        {
 
49
                                printf("Duplicate class definition for %s on line %d.\n", $2, NR);
 
50
                                next;
 
51
                        }       
 
52
                        class_found[$2] = 1;
 
53
 
 
54
                        class_value++;
 
55
 
 
56
                        printf("#define SECCLASS_%s", toupper($2)) > outfile;
 
57
                        for (i = 0; i < 40 - length($2); i++) 
 
58
                                printf(" ") > outfile; 
 
59
                        printf("%d\n", class_value) > outfile; 
 
60
 
 
61
                        printf("    \"%s\",\n", $2) > debugfile;
 
62
                }
 
63
$1 == "sid"     { 
 
64
                        if (nextstate == "CLASS")
 
65
                        {
 
66
                            nextstate = "SID";
 
67
                            printf("};\n\n") > debugfile;
 
68
                            printf("\n/*\n * Security identifier indices for initial entities\n */\n") > outfile;                           
 
69
                        }
 
70
 
 
71
                        if ($2 in sid_found)
 
72
                        {
 
73
                                printf("Duplicate SID definition for %s on line %d.\n", $2, NR);
 
74
                                next;
 
75
                        }       
 
76
                        sid_found[$2] = 1;
 
77
                        sid_value++;
 
78
 
 
79
                        printf("#define SECINITSID_%s", toupper($2)) > outfile;
 
80
                        for (i = 0; i < 37 - length($2); i++) 
 
81
                                printf(" ") > outfile; 
 
82
                        printf("%d\n", sid_value) > outfile; 
 
83
                        printf("    \"%s\",\n", $2) > debugfile2;
 
84
                }
 
85
END     {
 
86
                if (nextstate != "SID")
 
87
                        printf("Parse error:  Unexpected end of file\n");
 
88
 
 
89
                printf("\n#define SECINITSID_NUM") > outfile;
 
90
                for (i = 0; i < 34; i++) 
 
91
                        printf(" ") > outfile; 
 
92
                printf("%d\n", sid_value) > outfile; 
 
93
                printf("\n#endif\n") > outfile;
 
94
                printf("};\n\n") > debugfile2;
 
95
        }'
 
96
 
 
97
# FLASK