1#!/bin/sh - 2# 3 4# FLASK 5 6set -e 7 8awk=$1 9shift 10 11# output files 12av_permissions="include/av_permissions.h" 13av_perm_to_string="include/av_perm_to_string.h" 14 15cat $* | $awk " 16BEGIN { 17 outfile = \"$av_permissions\" 18 avpermfile = \"$av_perm_to_string\" 19 "' 20 nextstate = "COMMON_OR_AV"; 21 printf("/* This file is automatically generated. Do not edit. */\n") > outfile; 22 printf("/* This file is automatically generated. Do not edit. */\n") > avpermfile; 23; 24 } 25/^[ \t]*#/ { 26 next; 27 } 28$1 == "class" { 29 if (nextstate != "COMMON_OR_AV" && 30 nextstate != "CLASS_OR_CLASS-OPENBRACKET") 31 { 32 printf("Parse error: Unexpected class definition on line %d\n", NR); 33 next; 34 } 35 36 tclass = $2; 37 38 if (tclass in av_defined) 39 { 40 printf("Duplicate access vector definition for %s on line %d\n", tclass, NR); 41 next; 42 } 43 av_defined[tclass] = 1; 44 45 permission = 0; 46 47 nextstate = "INHERITS_OR_CLASS-OPENBRACKET"; 48 next; 49 } 50$1 == "{" { 51 if (nextstate != "INHERITS_OR_CLASS-OPENBRACKET" && 52 nextstate != "CLASS_OR_CLASS-OPENBRACKET" && 53 nextstate != "COMMON-OPENBRACKET") 54 { 55 printf("Parse error: Unexpected { on line %d\n", NR); 56 next; 57 } 58 59 if (nextstate == "INHERITS_OR_CLASS-OPENBRACKET") 60 nextstate = "CLASS-CLOSEBRACKET"; 61 62 if (nextstate == "CLASS_OR_CLASS-OPENBRACKET") 63 nextstate = "CLASS-CLOSEBRACKET"; 64 65 if (nextstate == "COMMON-OPENBRACKET") 66 nextstate = "COMMON-CLOSEBRACKET"; 67 } 68/[a-z][a-z_]*/ { 69 if (nextstate != "COMMON-CLOSEBRACKET" && 70 nextstate != "CLASS-CLOSEBRACKET") 71 { 72 printf("Parse error: Unexpected symbol %s on line %d\n", $1, NR); 73 next; 74 } 75 76 if (nextstate == "COMMON-CLOSEBRACKET") 77 { 78 if ((common_name,$1) in common_perms) 79 { 80 printf("Duplicate permission %s for common %s on line %d.\n", $1, common_name, NR); 81 next; 82 } 83 84 common_perms[common_name,$1] = permission; 85 86 printf("#define COMMON_%s__%s", toupper(common_name), toupper($1)) > outfile; 87 88 printf(" S_(\"%s\")\n", $1) > cpermfile; 89 } 90 else 91 { 92 if ((tclass,$1) in av_perms) 93 { 94 printf("Duplicate permission %s for %s on line %d.\n", $1, tclass, NR); 95 next; 96 } 97 98 av_perms[tclass,$1] = permission; 99 100 printf("#define %s__%s", toupper(tclass), toupper($1)) > outfile; 101 102 printf(" S_(SECCLASS_%s, %s__%s, \"%s\")\n", toupper(tclass), toupper(tclass), toupper($1), $1) > avpermfile; 103 } 104 105 spaces = 40 - (length($1) + length(tclass)); 106 if (spaces < 1) 107 spaces = 1; 108 109 for (i = 0; i < spaces; i++) 110 printf(" ") > outfile; 111 printf("(1UL << %u)\n", permission) > outfile; 112 permission = permission + 1; 113 } 114$1 == "}" { 115 if (nextstate != "CLASS-CLOSEBRACKET" && 116 nextstate != "COMMON-CLOSEBRACKET") 117 { 118 printf("Parse error: Unexpected } on line %d\n", NR); 119 next; 120 } 121 122 if (nextstate == "COMMON-CLOSEBRACKET") 123 { 124 common_base[common_name] = permission; 125 printf("TE_(common_%s_perm_to_string)\n\n", common_name) > cpermfile; 126 } 127 128 printf("\n") > outfile; 129 130 nextstate = "COMMON_OR_AV"; 131 } 132END { 133 if (nextstate != "COMMON_OR_AV" && nextstate != "CLASS_OR_CLASS-OPENBRACKET") 134 printf("Parse error: Unexpected end of file\n"); 135 136 }' 137 138# FLASK 139