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