|
Chris PeBenito |
ab58ad |
#!/bin/sh -
|
|
Chris PeBenito |
ab58ad |
#
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
# FLASK
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
set -e
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
awk=$1
|
|
Chris PeBenito |
ab58ad |
shift
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
# output files
|
|
Chris PeBenito |
ab58ad |
av_permissions="av_permissions.h"
|
|
Chris PeBenito |
ab58ad |
av_inherit="av_inherit.h"
|
|
Chris PeBenito |
ab58ad |
common_perm_to_string="common_perm_to_string.h"
|
|
Chris PeBenito |
ab58ad |
av_perm_to_string="av_perm_to_string.h"
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
cat $* | $awk "
|
|
Chris PeBenito |
ab58ad |
BEGIN {
|
|
Chris PeBenito |
ab58ad |
outfile = \"$av_permissions\"
|
|
Chris PeBenito |
ab58ad |
inheritfile = \"$av_inherit\"
|
|
Chris PeBenito |
ab58ad |
cpermfile = \"$common_perm_to_string\"
|
|
Chris PeBenito |
ab58ad |
avpermfile = \"$av_perm_to_string\"
|
|
Chris PeBenito |
ab58ad |
"'
|
|
Chris PeBenito |
ab58ad |
nextstate = "COMMON_OR_AV";
|
|
Chris PeBenito |
ab58ad |
printf("/* This file is automatically generated. Do not edit. */\n") > outfile;
|
|
Chris PeBenito |
ab58ad |
printf("/* This file is automatically generated. Do not edit. */\n") > inheritfile;
|
|
Chris PeBenito |
ab58ad |
printf("/* This file is automatically generated. Do not edit. */\n") > cpermfile;
|
|
Chris PeBenito |
ab58ad |
printf("/* This file is automatically generated. Do not edit. */\n") > avpermfile;
|
|
Chris PeBenito |
ab58ad |
;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
/^[ \t]*#/ {
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
$1 == "common" {
|
|
Chris PeBenito |
ab58ad |
if (nextstate != "COMMON_OR_AV")
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("Parse error: Unexpected COMMON definition on line %d\n", NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
if ($2 in common_defined)
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("Duplicate COMMON definition for %s on line %d.\n", $2, NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
common_defined[$2] = 1;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
tclass = $2;
|
|
Chris PeBenito |
ab58ad |
common_name = $2;
|
|
Chris PeBenito |
ab58ad |
permission = 1;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
printf("TB_(common_%s_perm_to_string)\n", $2) > cpermfile;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
nextstate = "COMMON-OPENBRACKET";
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
$1 == "class" {
|
|
Chris PeBenito |
ab58ad |
if (nextstate != "COMMON_OR_AV" &&
|
|
Chris PeBenito |
ab58ad |
nextstate != "CLASS_OR_CLASS-OPENBRACKET")
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("Parse error: Unexpected class definition on line %d\n", NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
tclass = $2;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
if (tclass in av_defined)
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("Duplicate access vector definition for %s on line %d\n", tclass, NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
av_defined[tclass] = 1;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
inherits = "";
|
|
Chris PeBenito |
ab58ad |
permission = 1;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
nextstate = "INHERITS_OR_CLASS-OPENBRACKET";
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
$1 == "inherits" {
|
|
Chris PeBenito |
ab58ad |
if (nextstate != "INHERITS_OR_CLASS-OPENBRACKET")
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("Parse error: Unexpected INHERITS definition on line %d\n", NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
if (!($2 in common_defined))
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("COMMON %s is not defined (line %d).\n", $2, NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
inherits = $2;
|
|
Chris PeBenito |
ab58ad |
permission = common_base[$2];
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
for (combined in common_perms)
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
split(combined,separate, SUBSEP);
|
|
Chris PeBenito |
ab58ad |
if (separate[1] == inherits)
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
inherited_perms[common_perms[combined]] = separate[2];
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
j = 1;
|
|
Chris PeBenito |
ab58ad |
for (i in inherited_perms) {
|
|
Chris PeBenito |
ab58ad |
ind[j] = i + 0;
|
|
Chris PeBenito |
ab58ad |
j++;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
n = asort(ind);
|
|
Chris PeBenito |
ab58ad |
for (i = 1; i <= n; i++) {
|
|
Chris PeBenito |
ab58ad |
perm = inherited_perms[ind[i]];
|
|
Chris PeBenito |
ab58ad |
printf("#define %s__%s", toupper(tclass), toupper(perm)) > outfile;
|
|
Chris PeBenito |
ab58ad |
spaces = 40 - (length(perm) + length(tclass));
|
|
Chris PeBenito |
ab58ad |
if (spaces < 1)
|
|
Chris PeBenito |
ab58ad |
spaces = 1;
|
|
Chris PeBenito |
ab58ad |
for (j = 0; j < spaces; j++)
|
|
Chris PeBenito |
ab58ad |
printf(" ") > outfile;
|
|
Chris PeBenito |
ab58ad |
printf("0x%08xUL\n", ind[i]) > outfile;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
printf("\n") > outfile;
|
|
Chris PeBenito |
ab58ad |
for (i in ind) delete ind[i];
|
|
Chris PeBenito |
ab58ad |
for (i in inherited_perms) delete inherited_perms[i];
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
printf(" S_(SECCLASS_%s, %s, 0x%08xUL)\n", toupper(tclass), inherits, permission) > inheritfile;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
nextstate = "CLASS_OR_CLASS-OPENBRACKET";
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
$1 == "{" {
|
|
Chris PeBenito |
ab58ad |
if (nextstate != "INHERITS_OR_CLASS-OPENBRACKET" &&
|
|
Chris PeBenito |
ab58ad |
nextstate != "CLASS_OR_CLASS-OPENBRACKET" &&
|
|
Chris PeBenito |
ab58ad |
nextstate != "COMMON-OPENBRACKET")
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("Parse error: Unexpected { on line %d\n", NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
if (nextstate == "INHERITS_OR_CLASS-OPENBRACKET")
|
|
Chris PeBenito |
ab58ad |
nextstate = "CLASS-CLOSEBRACKET";
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
if (nextstate == "CLASS_OR_CLASS-OPENBRACKET")
|
|
Chris PeBenito |
ab58ad |
nextstate = "CLASS-CLOSEBRACKET";
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
if (nextstate == "COMMON-OPENBRACKET")
|
|
Chris PeBenito |
ab58ad |
nextstate = "COMMON-CLOSEBRACKET";
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
/[a-z][a-z_]*/ {
|
|
Chris PeBenito |
ab58ad |
if (nextstate != "COMMON-CLOSEBRACKET" &&
|
|
Chris PeBenito |
ab58ad |
nextstate != "CLASS-CLOSEBRACKET")
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("Parse error: Unexpected symbol %s on line %d\n", $1, NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
if (nextstate == "COMMON-CLOSEBRACKET")
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
if ((common_name,$1) in common_perms)
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("Duplicate permission %s for common %s on line %d.\n", $1, common_name, NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
common_perms[common_name,$1] = permission;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
printf("#define COMMON_%s__%s", toupper(common_name), toupper($1)) > outfile;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
printf(" S_(\"%s\")\n", $1) > cpermfile;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
else
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
if ((tclass,$1) in av_perms)
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("Duplicate permission %s for %s on line %d.\n", $1, tclass, NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
av_perms[tclass,$1] = permission;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
if (inherits != "")
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
if ((inherits,$1) in common_perms)
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("Permission %s in %s on line %d conflicts with common permission.\n", $1, tclass, inherits, NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
printf("#define %s__%s", toupper(tclass), toupper($1)) > outfile;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
printf(" S_(SECCLASS_%s, %s__%s, \"%s\")\n", toupper(tclass), toupper(tclass), toupper($1), $1) > avpermfile;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
spaces = 40 - (length($1) + length(tclass));
|
|
Chris PeBenito |
ab58ad |
if (spaces < 1)
|
|
Chris PeBenito |
ab58ad |
spaces = 1;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
for (i = 0; i < spaces; i++)
|
|
Chris PeBenito |
ab58ad |
printf(" ") > outfile;
|
|
Chris PeBenito |
ab58ad |
printf("0x%08xUL\n", permission) > outfile;
|
|
Chris PeBenito |
ab58ad |
permission = permission * 2;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
$1 == "}" {
|
|
Chris PeBenito |
ab58ad |
if (nextstate != "CLASS-CLOSEBRACKET" &&
|
|
Chris PeBenito |
ab58ad |
nextstate != "COMMON-CLOSEBRACKET")
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
printf("Parse error: Unexpected } on line %d\n", NR);
|
|
Chris PeBenito |
ab58ad |
next;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
if (nextstate == "COMMON-CLOSEBRACKET")
|
|
Chris PeBenito |
ab58ad |
{
|
|
Chris PeBenito |
ab58ad |
common_base[common_name] = permission;
|
|
Chris PeBenito |
ab58ad |
printf("TE_(common_%s_perm_to_string)\n\n", common_name) > cpermfile;
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
printf("\n") > outfile;
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
nextstate = "COMMON_OR_AV";
|
|
Chris PeBenito |
ab58ad |
}
|
|
Chris PeBenito |
ab58ad |
END {
|
|
Chris PeBenito |
ab58ad |
if (nextstate != "COMMON_OR_AV" && nextstate != "CLASS_OR_CLASS-OPENBRACKET")
|
|
Chris PeBenito |
ab58ad |
printf("Parse error: Unexpected end of file\n");
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
}'
|
|
Chris PeBenito |
ab58ad |
|
|
Chris PeBenito |
ab58ad |
# FLASK
|