Chris PeBenito 31b7c0
#!/bin/sh -
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# FLASK
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
set -e
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
awk=$1
Chris PeBenito 31b7c0
shift 1
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# output file
Chris PeBenito 31b7c0
output_file="flask.h"
Chris PeBenito 31b7c0
debug_file="class_to_string.h"
Chris PeBenito 31b7c0
debug_file2="initial_sid_to_string.h"
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
cat $* | $awk "
Chris PeBenito 31b7c0
BEGIN	{
Chris PeBenito 31b7c0
		outfile = \"$output_file\"
Chris PeBenito 31b7c0
		debugfile = \"$debug_file\"
Chris PeBenito 31b7c0
		debugfile2 = \"$debug_file2\"
Chris PeBenito 31b7c0
		"'
Chris PeBenito 31b7c0
		nextstate = "CLASS";
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
		printf("/* This file is automatically generated.  Do not edit. */\n") > outfile;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
		printf("#ifndef _SELINUX_FLASK_H_\n") > outfile;
Chris PeBenito 31b7c0
		printf("#define _SELINUX_FLASK_H_\n") > outfile;
Chris PeBenito 31b7c0
		printf("\n/*\n * Security object class definitions\n */\n") > outfile;
Chris PeBenito 31b7c0
		printf("/* This file is automatically generated.  Do not edit. */\n") > debugfile;
Chris PeBenito 31b7c0
		printf("/*\n * Security object class definitions\n */\n") > debugfile;
Chris PeBenito 31b7c0
		printf("    S_(\"null\")\n") > debugfile;
Chris PeBenito 31b7c0
		printf("/* This file is automatically generated.  Do not edit. */\n") > debugfile2;
Chris PeBenito 31b7c0
		printf("static char *initial_sid_to_string[] =\n{\n") > debugfile2;
Chris PeBenito 31b7c0
		printf("    \"null\",\n") > debugfile2;
Chris PeBenito 31b7c0
	}
Chris PeBenito 31b7c0
/^[ \t]*#/	{ 
Chris PeBenito 31b7c0
			next;
Chris PeBenito 31b7c0
		}
Chris PeBenito 31b7c0
$1 == "class"	{ 
Chris PeBenito 31b7c0
			if (nextstate != "CLASS")
Chris PeBenito 31b7c0
			{
Chris PeBenito 31b7c0
				printf("Parse error:  Unexpected class definition on line %d\n", NR);
Chris PeBenito 31b7c0
				next;	
Chris PeBenito 31b7c0
			}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
			if ($2 in class_found)
Chris PeBenito 31b7c0
			{
Chris PeBenito 31b7c0
				printf("Duplicate class definition for %s on line %d.\n", $2, NR);
Chris PeBenito 31b7c0
				next;
Chris PeBenito 31b7c0
			}	
Chris PeBenito 31b7c0
			class_found[$2] = 1;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
			class_value++;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
			printf("#define SECCLASS_%s", toupper($2)) > outfile;
Chris PeBenito 31b7c0
			for (i = 0; i < 40 - length($2); i++) 
Chris PeBenito 31b7c0
				printf(" ") > outfile; 
Chris PeBenito 31b7c0
			printf("%d\n", class_value) > outfile; 
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
			printf("    S_(\"%s\")\n", $2) > debugfile;
Chris PeBenito 31b7c0
		}
Chris PeBenito 31b7c0
$1 == "sid"	{ 
Chris PeBenito 31b7c0
			if (nextstate == "CLASS")
Chris PeBenito 31b7c0
			{
Chris PeBenito 31b7c0
			    nextstate = "SID";
Chris PeBenito 31b7c0
			    printf("\n/*\n * Security identifier indices for initial entities\n */\n") > outfile;			    
Chris PeBenito 31b7c0
			}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
			if ($2 in sid_found)
Chris PeBenito 31b7c0
			{
Chris PeBenito 31b7c0
				printf("Duplicate SID definition for %s on line %d.\n", $2, NR);
Chris PeBenito 31b7c0
				next;
Chris PeBenito 31b7c0
			}	
Chris PeBenito 31b7c0
			sid_found[$2] = 1;
Chris PeBenito 31b7c0
			sid_value++;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
			printf("#define SECINITSID_%s", toupper($2)) > outfile;
Chris PeBenito 31b7c0
			for (i = 0; i < 37 - length($2); i++) 
Chris PeBenito 31b7c0
				printf(" ") > outfile; 
Chris PeBenito 31b7c0
			printf("%d\n", sid_value) > outfile; 
Chris PeBenito 31b7c0
			printf("    \"%s\",\n", $2) > debugfile2;
Chris PeBenito 31b7c0
		}
Chris PeBenito 31b7c0
END	{
Chris PeBenito 31b7c0
		if (nextstate != "SID")
Chris PeBenito 31b7c0
			printf("Parse error:  Unexpected end of file\n");
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
		printf("\n#define SECINITSID_NUM") > outfile;
Chris PeBenito 31b7c0
		for (i = 0; i < 34; i++) 
Chris PeBenito 31b7c0
			printf(" ") > outfile; 
Chris PeBenito 31b7c0
		printf("%d\n", sid_value) > outfile; 
Chris PeBenito 31b7c0
		printf("\n#endif\n") > outfile;
Chris PeBenito 31b7c0
		printf("};\n\n") > debugfile2;
Chris PeBenito 31b7c0
	}'
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# FLASK