diff --git a/README.md b/README.md index 2469c73..6cb41b2 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Pass it a sandbox profile file in SBPL format. A sample run is shown below: ``` -$ ./convertToProlog.sh test-cases/containerManualPruning.sb +$ ./convertToProlog.sh test-cases/containerBetterGraphProcess.sb * Removing old output files in outputFromQueries ... * Generating Prolog facts in facts.pl ... * Merging Prolog facts (facts.pl) and Prolog rules (rules.pl) in factsAndRules.pl ... diff --git a/convertToProlog.sh b/convertToProlog.sh index 04319c7..be752e1 100755 --- a/convertToProlog.sh +++ b/convertToProlog.sh @@ -4,7 +4,7 @@ if test $# -ne 1; then echo "Usage: $0 " 1>&2 echo "" 1>&2 echo "Sample usage:" 1>&2 - echo " $0 test_cases/containerManualPruning.sb" 1>&2 + echo " $0 test-cases/containerBetterGraphProcess.sb" 1>&2 exit 1 fi @@ -26,7 +26,7 @@ echo "* Merging Prolog facts (facts.pl) and Prolog rules (rules.pl) in factsAndR cat facts.pl rules.pl > factsAndRules.pl echo "* Using script.pl to execute Prolog queries ..." -swi-prolog.swipl -s script.pl --quiet +swipl -s script.pl --quiet echo "" echo "See output of Prolog queries in outputFromQueries/ folder." diff --git a/profile_compilation/parser.out b/profile_compilation/parser.out new file mode 100644 index 0000000..2f60ddc --- /dev/null +++ b/profile_compilation/parser.out @@ -0,0 +1,947 @@ +Created by PLY version 3.11 (http://www.dabeaz.com/ply) + +Unused terminals: + + TK_BOOL + +Grammar + +Rule 0 S' -> profile +Rule 1 profile -> version default ruleList +Rule 2 version -> TK_LPAREN TK_VERSION TK_OTHERTYPE TK_RPAREN +Rule 3 default -> TK_LPAREN decision TK_DEFAULT TK_RPAREN +Rule 4 decision -> TK_ALLOW +Rule 5 decision -> TK_DENY +Rule 6 ruleList -> rule ruleList +Rule 7 ruleList -> +Rule 8 rule -> TK_LPAREN decision action objectList TK_RPAREN +Rule 9 rule -> TK_LPAREN decision action TK_RPAREN +Rule 10 action -> TK_OTHERTYPE +Rule 11 objectList -> TK_LPAREN object TK_RPAREN objectList +Rule 12 objectList -> TK_LPAREN object TK_RPAREN +Rule 13 objectList -> requireAny objectList +Rule 14 objectList -> requireAll objectList +Rule 15 objectList -> requireAny +Rule 16 objectList -> requireAll +Rule 17 requireAny -> TK_LPAREN TK_REQANY objectList TK_RPAREN +Rule 18 requireAll -> TK_LPAREN TK_REQALL objectList TK_RPAREN +Rule 19 requireAll -> reqEnt objectList TK_RPAREN +Rule 20 requireAll -> reqEnt TK_RPAREN +Rule 21 reqEnt -> TK_LPAREN TK_REQENT TK_FILTER +Rule 22 object -> otherType TK_FILTER +Rule 23 object -> regexFilter +Rule 24 object -> otherType otherType +Rule 25 object -> otherType otherType TK_FILTER +Rule 26 object -> subpath +Rule 27 object -> prefix +Rule 28 object -> filemode +Rule 29 object -> TK_REQNOT TK_LPAREN object TK_RPAREN +Rule 30 object -> TK_REQNOT TK_LPAREN simpleEntValObject TK_RPAREN +Rule 31 object -> TK_VNODETYPE otherType +Rule 32 object -> otherType TK_LPAREN otherType TK_FILTER otherType TK_RPAREN +Rule 33 object -> TK_DEBUGMODE +Rule 34 filemode -> TK_FILEMODETYPE TK_MODENUMBER +Rule 35 subpath -> TK_SUBPATH TK_FILTER +Rule 36 prefix -> TK_LPREFIX TK_FILTER +Rule 37 prefix -> TK_SPREFIX TK_FILTER +Rule 38 prefix -> TK_RPREFIX TK_FILTER +Rule 39 simpleEntValObject -> TK_REQENT TK_FILTER +Rule 40 otherType -> TK_OTHERTYPE +Rule 41 regexFilter -> TK_OTHERTYPE regexList +Rule 42 regexList -> TK_REGEXPRESSION regexList +Rule 43 regexList -> TK_REGEXPRESSION + +Terminals, with rules where they appear + +TK_ALLOW : 4 +TK_BOOL : +TK_DEBUGMODE : 33 +TK_DEFAULT : 3 +TK_DENY : 5 +TK_FILEMODETYPE : 34 +TK_FILTER : 21 22 25 32 35 36 37 38 39 +TK_LPAREN : 2 3 8 9 11 12 17 18 21 29 30 32 +TK_LPREFIX : 36 +TK_MODENUMBER : 34 +TK_OTHERTYPE : 2 10 40 41 +TK_REGEXPRESSION : 42 43 +TK_REQALL : 18 +TK_REQANY : 17 +TK_REQENT : 21 39 +TK_REQNOT : 29 30 +TK_RPAREN : 2 3 8 9 11 12 17 18 19 20 29 30 32 +TK_RPREFIX : 38 +TK_SPREFIX : 37 +TK_SUBPATH : 35 +TK_VERSION : 2 +TK_VNODETYPE : 31 +error : + +Nonterminals, with rules where they appear + +action : 8 9 +decision : 3 8 9 +default : 1 +filemode : 28 +object : 11 12 29 +objectList : 8 11 13 14 17 18 19 +otherType : 22 24 24 25 25 31 32 32 32 +prefix : 27 +profile : 0 +regexFilter : 23 +regexList : 41 42 +reqEnt : 19 20 +requireAll : 14 16 +requireAny : 13 15 +rule : 6 +ruleList : 1 6 +simpleEntValObject : 30 +subpath : 26 +version : 1 + +Parsing method: LALR + +state 0 + + (0) S' -> . profile + (1) profile -> . version default ruleList + (2) version -> . TK_LPAREN TK_VERSION TK_OTHERTYPE TK_RPAREN + + TK_LPAREN shift and go to state 3 + + profile shift and go to state 1 + version shift and go to state 2 + +state 1 + + (0) S' -> profile . + + + +state 2 + + (1) profile -> version . default ruleList + (3) default -> . TK_LPAREN decision TK_DEFAULT TK_RPAREN + + TK_LPAREN shift and go to state 5 + + default shift and go to state 4 + +state 3 + + (2) version -> TK_LPAREN . TK_VERSION TK_OTHERTYPE TK_RPAREN + + TK_VERSION shift and go to state 6 + + +state 4 + + (1) profile -> version default . ruleList + (6) ruleList -> . rule ruleList + (7) ruleList -> . + (8) rule -> . TK_LPAREN decision action objectList TK_RPAREN + (9) rule -> . TK_LPAREN decision action TK_RPAREN + + $end reduce using rule 7 (ruleList -> .) + TK_LPAREN shift and go to state 9 + + ruleList shift and go to state 7 + rule shift and go to state 8 + +state 5 + + (3) default -> TK_LPAREN . decision TK_DEFAULT TK_RPAREN + (4) decision -> . TK_ALLOW + (5) decision -> . TK_DENY + + TK_ALLOW shift and go to state 11 + TK_DENY shift and go to state 12 + + decision shift and go to state 10 + +state 6 + + (2) version -> TK_LPAREN TK_VERSION . TK_OTHERTYPE TK_RPAREN + + TK_OTHERTYPE shift and go to state 13 + + +state 7 + + (1) profile -> version default ruleList . + + $end reduce using rule 1 (profile -> version default ruleList .) + + +state 8 + + (6) ruleList -> rule . ruleList + (6) ruleList -> . rule ruleList + (7) ruleList -> . + (8) rule -> . TK_LPAREN decision action objectList TK_RPAREN + (9) rule -> . TK_LPAREN decision action TK_RPAREN + + $end reduce using rule 7 (ruleList -> .) + TK_LPAREN shift and go to state 9 + + rule shift and go to state 8 + ruleList shift and go to state 14 + +state 9 + + (8) rule -> TK_LPAREN . decision action objectList TK_RPAREN + (9) rule -> TK_LPAREN . decision action TK_RPAREN + (4) decision -> . TK_ALLOW + (5) decision -> . TK_DENY + + TK_ALLOW shift and go to state 11 + TK_DENY shift and go to state 12 + + decision shift and go to state 15 + +state 10 + + (3) default -> TK_LPAREN decision . TK_DEFAULT TK_RPAREN + + TK_DEFAULT shift and go to state 16 + + +state 11 + + (4) decision -> TK_ALLOW . + + TK_DEFAULT reduce using rule 4 (decision -> TK_ALLOW .) + TK_OTHERTYPE reduce using rule 4 (decision -> TK_ALLOW .) + + +state 12 + + (5) decision -> TK_DENY . + + TK_DEFAULT reduce using rule 5 (decision -> TK_DENY .) + TK_OTHERTYPE reduce using rule 5 (decision -> TK_DENY .) + + +state 13 + + (2) version -> TK_LPAREN TK_VERSION TK_OTHERTYPE . TK_RPAREN + + TK_RPAREN shift and go to state 17 + + +state 14 + + (6) ruleList -> rule ruleList . + + $end reduce using rule 6 (ruleList -> rule ruleList .) + + +state 15 + + (8) rule -> TK_LPAREN decision . action objectList TK_RPAREN + (9) rule -> TK_LPAREN decision . action TK_RPAREN + (10) action -> . TK_OTHERTYPE + + TK_OTHERTYPE shift and go to state 19 + + action shift and go to state 18 + +state 16 + + (3) default -> TK_LPAREN decision TK_DEFAULT . TK_RPAREN + + TK_RPAREN shift and go to state 20 + + +state 17 + + (2) version -> TK_LPAREN TK_VERSION TK_OTHERTYPE TK_RPAREN . + + TK_LPAREN reduce using rule 2 (version -> TK_LPAREN TK_VERSION TK_OTHERTYPE TK_RPAREN .) + + +state 18 + + (8) rule -> TK_LPAREN decision action . objectList TK_RPAREN + (9) rule -> TK_LPAREN decision action . TK_RPAREN + (11) objectList -> . TK_LPAREN object TK_RPAREN objectList + (12) objectList -> . TK_LPAREN object TK_RPAREN + (13) objectList -> . requireAny objectList + (14) objectList -> . requireAll objectList + (15) objectList -> . requireAny + (16) objectList -> . requireAll + (17) requireAny -> . TK_LPAREN TK_REQANY objectList TK_RPAREN + (18) requireAll -> . TK_LPAREN TK_REQALL objectList TK_RPAREN + (19) requireAll -> . reqEnt objectList TK_RPAREN + (20) requireAll -> . reqEnt TK_RPAREN + (21) reqEnt -> . TK_LPAREN TK_REQENT TK_FILTER + + TK_RPAREN shift and go to state 23 + TK_LPAREN shift and go to state 21 + + objectList shift and go to state 22 + requireAny shift and go to state 24 + requireAll shift and go to state 25 + reqEnt shift and go to state 26 + +state 19 + + (10) action -> TK_OTHERTYPE . + + TK_RPAREN reduce using rule 10 (action -> TK_OTHERTYPE .) + TK_LPAREN reduce using rule 10 (action -> TK_OTHERTYPE .) + + +state 20 + + (3) default -> TK_LPAREN decision TK_DEFAULT TK_RPAREN . + + TK_LPAREN reduce using rule 3 (default -> TK_LPAREN decision TK_DEFAULT TK_RPAREN .) + $end reduce using rule 3 (default -> TK_LPAREN decision TK_DEFAULT TK_RPAREN .) + + +state 21 + + (11) objectList -> TK_LPAREN . object TK_RPAREN objectList + (12) objectList -> TK_LPAREN . object TK_RPAREN + (17) requireAny -> TK_LPAREN . TK_REQANY objectList TK_RPAREN + (18) requireAll -> TK_LPAREN . TK_REQALL objectList TK_RPAREN + (21) reqEnt -> TK_LPAREN . TK_REQENT TK_FILTER + (22) object -> . otherType TK_FILTER + (23) object -> . regexFilter + (24) object -> . otherType otherType + (25) object -> . otherType otherType TK_FILTER + (26) object -> . subpath + (27) object -> . prefix + (28) object -> . filemode + (29) object -> . TK_REQNOT TK_LPAREN object TK_RPAREN + (30) object -> . TK_REQNOT TK_LPAREN simpleEntValObject TK_RPAREN + (31) object -> . TK_VNODETYPE otherType + (32) object -> . otherType TK_LPAREN otherType TK_FILTER otherType TK_RPAREN + (33) object -> . TK_DEBUGMODE + (40) otherType -> . TK_OTHERTYPE + (41) regexFilter -> . TK_OTHERTYPE regexList + (35) subpath -> . TK_SUBPATH TK_FILTER + (36) prefix -> . TK_LPREFIX TK_FILTER + (37) prefix -> . TK_SPREFIX TK_FILTER + (38) prefix -> . TK_RPREFIX TK_FILTER + (34) filemode -> . TK_FILEMODETYPE TK_MODENUMBER + + TK_REQANY shift and go to state 28 + TK_REQALL shift and go to state 29 + TK_REQENT shift and go to state 30 + TK_REQNOT shift and go to state 36 + TK_VNODETYPE shift and go to state 37 + TK_DEBUGMODE shift and go to state 38 + TK_OTHERTYPE shift and go to state 39 + TK_SUBPATH shift and go to state 40 + TK_LPREFIX shift and go to state 41 + TK_SPREFIX shift and go to state 42 + TK_RPREFIX shift and go to state 43 + TK_FILEMODETYPE shift and go to state 44 + + object shift and go to state 27 + otherType shift and go to state 31 + regexFilter shift and go to state 32 + subpath shift and go to state 33 + prefix shift and go to state 34 + filemode shift and go to state 35 + +state 22 + + (8) rule -> TK_LPAREN decision action objectList . TK_RPAREN + + TK_RPAREN shift and go to state 45 + + +state 23 + + (9) rule -> TK_LPAREN decision action TK_RPAREN . + + TK_LPAREN reduce using rule 9 (rule -> TK_LPAREN decision action TK_RPAREN .) + $end reduce using rule 9 (rule -> TK_LPAREN decision action TK_RPAREN .) + + +state 24 + + (13) objectList -> requireAny . objectList + (15) objectList -> requireAny . + (11) objectList -> . TK_LPAREN object TK_RPAREN objectList + (12) objectList -> . TK_LPAREN object TK_RPAREN + (13) objectList -> . requireAny objectList + (14) objectList -> . requireAll objectList + (15) objectList -> . requireAny + (16) objectList -> . requireAll + (17) requireAny -> . TK_LPAREN TK_REQANY objectList TK_RPAREN + (18) requireAll -> . TK_LPAREN TK_REQALL objectList TK_RPAREN + (19) requireAll -> . reqEnt objectList TK_RPAREN + (20) requireAll -> . reqEnt TK_RPAREN + (21) reqEnt -> . TK_LPAREN TK_REQENT TK_FILTER + + TK_RPAREN reduce using rule 15 (objectList -> requireAny .) + TK_LPAREN shift and go to state 21 + + requireAny shift and go to state 24 + objectList shift and go to state 46 + requireAll shift and go to state 25 + reqEnt shift and go to state 26 + +state 25 + + (14) objectList -> requireAll . objectList + (16) objectList -> requireAll . + (11) objectList -> . TK_LPAREN object TK_RPAREN objectList + (12) objectList -> . TK_LPAREN object TK_RPAREN + (13) objectList -> . requireAny objectList + (14) objectList -> . requireAll objectList + (15) objectList -> . requireAny + (16) objectList -> . requireAll + (17) requireAny -> . TK_LPAREN TK_REQANY objectList TK_RPAREN + (18) requireAll -> . TK_LPAREN TK_REQALL objectList TK_RPAREN + (19) requireAll -> . reqEnt objectList TK_RPAREN + (20) requireAll -> . reqEnt TK_RPAREN + (21) reqEnt -> . TK_LPAREN TK_REQENT TK_FILTER + + TK_RPAREN reduce using rule 16 (objectList -> requireAll .) + TK_LPAREN shift and go to state 21 + + requireAll shift and go to state 25 + objectList shift and go to state 47 + requireAny shift and go to state 24 + reqEnt shift and go to state 26 + +state 26 + + (19) requireAll -> reqEnt . objectList TK_RPAREN + (20) requireAll -> reqEnt . TK_RPAREN + (11) objectList -> . TK_LPAREN object TK_RPAREN objectList + (12) objectList -> . TK_LPAREN object TK_RPAREN + (13) objectList -> . requireAny objectList + (14) objectList -> . requireAll objectList + (15) objectList -> . requireAny + (16) objectList -> . requireAll + (17) requireAny -> . TK_LPAREN TK_REQANY objectList TK_RPAREN + (18) requireAll -> . TK_LPAREN TK_REQALL objectList TK_RPAREN + (19) requireAll -> . reqEnt objectList TK_RPAREN + (20) requireAll -> . reqEnt TK_RPAREN + (21) reqEnt -> . TK_LPAREN TK_REQENT TK_FILTER + + TK_RPAREN shift and go to state 49 + TK_LPAREN shift and go to state 21 + + reqEnt shift and go to state 26 + objectList shift and go to state 48 + requireAny shift and go to state 24 + requireAll shift and go to state 25 + +state 27 + + (11) objectList -> TK_LPAREN object . TK_RPAREN objectList + (12) objectList -> TK_LPAREN object . TK_RPAREN + + TK_RPAREN shift and go to state 50 + + +state 28 + + (17) requireAny -> TK_LPAREN TK_REQANY . objectList TK_RPAREN + (11) objectList -> . TK_LPAREN object TK_RPAREN objectList + (12) objectList -> . TK_LPAREN object TK_RPAREN + (13) objectList -> . requireAny objectList + (14) objectList -> . requireAll objectList + (15) objectList -> . requireAny + (16) objectList -> . requireAll + (17) requireAny -> . TK_LPAREN TK_REQANY objectList TK_RPAREN + (18) requireAll -> . TK_LPAREN TK_REQALL objectList TK_RPAREN + (19) requireAll -> . reqEnt objectList TK_RPAREN + (20) requireAll -> . reqEnt TK_RPAREN + (21) reqEnt -> . TK_LPAREN TK_REQENT TK_FILTER + + TK_LPAREN shift and go to state 21 + + objectList shift and go to state 51 + requireAny shift and go to state 24 + requireAll shift and go to state 25 + reqEnt shift and go to state 26 + +state 29 + + (18) requireAll -> TK_LPAREN TK_REQALL . objectList TK_RPAREN + (11) objectList -> . TK_LPAREN object TK_RPAREN objectList + (12) objectList -> . TK_LPAREN object TK_RPAREN + (13) objectList -> . requireAny objectList + (14) objectList -> . requireAll objectList + (15) objectList -> . requireAny + (16) objectList -> . requireAll + (17) requireAny -> . TK_LPAREN TK_REQANY objectList TK_RPAREN + (18) requireAll -> . TK_LPAREN TK_REQALL objectList TK_RPAREN + (19) requireAll -> . reqEnt objectList TK_RPAREN + (20) requireAll -> . reqEnt TK_RPAREN + (21) reqEnt -> . TK_LPAREN TK_REQENT TK_FILTER + + TK_LPAREN shift and go to state 21 + + objectList shift and go to state 52 + requireAny shift and go to state 24 + requireAll shift and go to state 25 + reqEnt shift and go to state 26 + +state 30 + + (21) reqEnt -> TK_LPAREN TK_REQENT . TK_FILTER + + TK_FILTER shift and go to state 53 + + +state 31 + + (22) object -> otherType . TK_FILTER + (24) object -> otherType . otherType + (25) object -> otherType . otherType TK_FILTER + (32) object -> otherType . TK_LPAREN otherType TK_FILTER otherType TK_RPAREN + (40) otherType -> . TK_OTHERTYPE + + TK_FILTER shift and go to state 55 + TK_LPAREN shift and go to state 56 + TK_OTHERTYPE shift and go to state 57 + + otherType shift and go to state 54 + +state 32 + + (23) object -> regexFilter . + + TK_RPAREN reduce using rule 23 (object -> regexFilter .) + + +state 33 + + (26) object -> subpath . + + TK_RPAREN reduce using rule 26 (object -> subpath .) + + +state 34 + + (27) object -> prefix . + + TK_RPAREN reduce using rule 27 (object -> prefix .) + + +state 35 + + (28) object -> filemode . + + TK_RPAREN reduce using rule 28 (object -> filemode .) + + +state 36 + + (29) object -> TK_REQNOT . TK_LPAREN object TK_RPAREN + (30) object -> TK_REQNOT . TK_LPAREN simpleEntValObject TK_RPAREN + + TK_LPAREN shift and go to state 58 + + +state 37 + + (31) object -> TK_VNODETYPE . otherType + (40) otherType -> . TK_OTHERTYPE + + TK_OTHERTYPE shift and go to state 57 + + otherType shift and go to state 59 + +state 38 + + (33) object -> TK_DEBUGMODE . + + TK_RPAREN reduce using rule 33 (object -> TK_DEBUGMODE .) + + +state 39 + + (40) otherType -> TK_OTHERTYPE . + (41) regexFilter -> TK_OTHERTYPE . regexList + (42) regexList -> . TK_REGEXPRESSION regexList + (43) regexList -> . TK_REGEXPRESSION + + TK_FILTER reduce using rule 40 (otherType -> TK_OTHERTYPE .) + TK_LPAREN reduce using rule 40 (otherType -> TK_OTHERTYPE .) + TK_OTHERTYPE reduce using rule 40 (otherType -> TK_OTHERTYPE .) + TK_REGEXPRESSION shift and go to state 61 + + regexList shift and go to state 60 + +state 40 + + (35) subpath -> TK_SUBPATH . TK_FILTER + + TK_FILTER shift and go to state 62 + + +state 41 + + (36) prefix -> TK_LPREFIX . TK_FILTER + + TK_FILTER shift and go to state 63 + + +state 42 + + (37) prefix -> TK_SPREFIX . TK_FILTER + + TK_FILTER shift and go to state 64 + + +state 43 + + (38) prefix -> TK_RPREFIX . TK_FILTER + + TK_FILTER shift and go to state 65 + + +state 44 + + (34) filemode -> TK_FILEMODETYPE . TK_MODENUMBER + + TK_MODENUMBER shift and go to state 66 + + +state 45 + + (8) rule -> TK_LPAREN decision action objectList TK_RPAREN . + + TK_LPAREN reduce using rule 8 (rule -> TK_LPAREN decision action objectList TK_RPAREN .) + $end reduce using rule 8 (rule -> TK_LPAREN decision action objectList TK_RPAREN .) + + +state 46 + + (13) objectList -> requireAny objectList . + + TK_RPAREN reduce using rule 13 (objectList -> requireAny objectList .) + + +state 47 + + (14) objectList -> requireAll objectList . + + TK_RPAREN reduce using rule 14 (objectList -> requireAll objectList .) + + +state 48 + + (19) requireAll -> reqEnt objectList . TK_RPAREN + + TK_RPAREN shift and go to state 67 + + +state 49 + + (20) requireAll -> reqEnt TK_RPAREN . + + TK_LPAREN reduce using rule 20 (requireAll -> reqEnt TK_RPAREN .) + TK_RPAREN reduce using rule 20 (requireAll -> reqEnt TK_RPAREN .) + + +state 50 + + (11) objectList -> TK_LPAREN object TK_RPAREN . objectList + (12) objectList -> TK_LPAREN object TK_RPAREN . + (11) objectList -> . TK_LPAREN object TK_RPAREN objectList + (12) objectList -> . TK_LPAREN object TK_RPAREN + (13) objectList -> . requireAny objectList + (14) objectList -> . requireAll objectList + (15) objectList -> . requireAny + (16) objectList -> . requireAll + (17) requireAny -> . TK_LPAREN TK_REQANY objectList TK_RPAREN + (18) requireAll -> . TK_LPAREN TK_REQALL objectList TK_RPAREN + (19) requireAll -> . reqEnt objectList TK_RPAREN + (20) requireAll -> . reqEnt TK_RPAREN + (21) reqEnt -> . TK_LPAREN TK_REQENT TK_FILTER + + TK_RPAREN reduce using rule 12 (objectList -> TK_LPAREN object TK_RPAREN .) + TK_LPAREN shift and go to state 21 + + objectList shift and go to state 68 + requireAny shift and go to state 24 + requireAll shift and go to state 25 + reqEnt shift and go to state 26 + +state 51 + + (17) requireAny -> TK_LPAREN TK_REQANY objectList . TK_RPAREN + + TK_RPAREN shift and go to state 69 + + +state 52 + + (18) requireAll -> TK_LPAREN TK_REQALL objectList . TK_RPAREN + + TK_RPAREN shift and go to state 70 + + +state 53 + + (21) reqEnt -> TK_LPAREN TK_REQENT TK_FILTER . + + TK_RPAREN reduce using rule 21 (reqEnt -> TK_LPAREN TK_REQENT TK_FILTER .) + TK_LPAREN reduce using rule 21 (reqEnt -> TK_LPAREN TK_REQENT TK_FILTER .) + + +state 54 + + (24) object -> otherType otherType . + (25) object -> otherType otherType . TK_FILTER + + TK_RPAREN reduce using rule 24 (object -> otherType otherType .) + TK_FILTER shift and go to state 71 + + +state 55 + + (22) object -> otherType TK_FILTER . + + TK_RPAREN reduce using rule 22 (object -> otherType TK_FILTER .) + + +state 56 + + (32) object -> otherType TK_LPAREN . otherType TK_FILTER otherType TK_RPAREN + (40) otherType -> . TK_OTHERTYPE + + TK_OTHERTYPE shift and go to state 57 + + otherType shift and go to state 72 + +state 57 + + (40) otherType -> TK_OTHERTYPE . + + TK_FILTER reduce using rule 40 (otherType -> TK_OTHERTYPE .) + TK_RPAREN reduce using rule 40 (otherType -> TK_OTHERTYPE .) + + +state 58 + + (29) object -> TK_REQNOT TK_LPAREN . object TK_RPAREN + (30) object -> TK_REQNOT TK_LPAREN . simpleEntValObject TK_RPAREN + (22) object -> . otherType TK_FILTER + (23) object -> . regexFilter + (24) object -> . otherType otherType + (25) object -> . otherType otherType TK_FILTER + (26) object -> . subpath + (27) object -> . prefix + (28) object -> . filemode + (29) object -> . TK_REQNOT TK_LPAREN object TK_RPAREN + (30) object -> . TK_REQNOT TK_LPAREN simpleEntValObject TK_RPAREN + (31) object -> . TK_VNODETYPE otherType + (32) object -> . otherType TK_LPAREN otherType TK_FILTER otherType TK_RPAREN + (33) object -> . TK_DEBUGMODE + (39) simpleEntValObject -> . TK_REQENT TK_FILTER + (40) otherType -> . TK_OTHERTYPE + (41) regexFilter -> . TK_OTHERTYPE regexList + (35) subpath -> . TK_SUBPATH TK_FILTER + (36) prefix -> . TK_LPREFIX TK_FILTER + (37) prefix -> . TK_SPREFIX TK_FILTER + (38) prefix -> . TK_RPREFIX TK_FILTER + (34) filemode -> . TK_FILEMODETYPE TK_MODENUMBER + + TK_REQNOT shift and go to state 36 + TK_VNODETYPE shift and go to state 37 + TK_DEBUGMODE shift and go to state 38 + TK_REQENT shift and go to state 75 + TK_OTHERTYPE shift and go to state 39 + TK_SUBPATH shift and go to state 40 + TK_LPREFIX shift and go to state 41 + TK_SPREFIX shift and go to state 42 + TK_RPREFIX shift and go to state 43 + TK_FILEMODETYPE shift and go to state 44 + + object shift and go to state 73 + simpleEntValObject shift and go to state 74 + otherType shift and go to state 31 + regexFilter shift and go to state 32 + subpath shift and go to state 33 + prefix shift and go to state 34 + filemode shift and go to state 35 + +state 59 + + (31) object -> TK_VNODETYPE otherType . + + TK_RPAREN reduce using rule 31 (object -> TK_VNODETYPE otherType .) + + +state 60 + + (41) regexFilter -> TK_OTHERTYPE regexList . + + TK_RPAREN reduce using rule 41 (regexFilter -> TK_OTHERTYPE regexList .) + + +state 61 + + (42) regexList -> TK_REGEXPRESSION . regexList + (43) regexList -> TK_REGEXPRESSION . + (42) regexList -> . TK_REGEXPRESSION regexList + (43) regexList -> . TK_REGEXPRESSION + + TK_RPAREN reduce using rule 43 (regexList -> TK_REGEXPRESSION .) + TK_REGEXPRESSION shift and go to state 61 + + regexList shift and go to state 76 + +state 62 + + (35) subpath -> TK_SUBPATH TK_FILTER . + + TK_RPAREN reduce using rule 35 (subpath -> TK_SUBPATH TK_FILTER .) + + +state 63 + + (36) prefix -> TK_LPREFIX TK_FILTER . + + TK_RPAREN reduce using rule 36 (prefix -> TK_LPREFIX TK_FILTER .) + + +state 64 + + (37) prefix -> TK_SPREFIX TK_FILTER . + + TK_RPAREN reduce using rule 37 (prefix -> TK_SPREFIX TK_FILTER .) + + +state 65 + + (38) prefix -> TK_RPREFIX TK_FILTER . + + TK_RPAREN reduce using rule 38 (prefix -> TK_RPREFIX TK_FILTER .) + + +state 66 + + (34) filemode -> TK_FILEMODETYPE TK_MODENUMBER . + + TK_RPAREN reduce using rule 34 (filemode -> TK_FILEMODETYPE TK_MODENUMBER .) + + +state 67 + + (19) requireAll -> reqEnt objectList TK_RPAREN . + + TK_LPAREN reduce using rule 19 (requireAll -> reqEnt objectList TK_RPAREN .) + TK_RPAREN reduce using rule 19 (requireAll -> reqEnt objectList TK_RPAREN .) + + +state 68 + + (11) objectList -> TK_LPAREN object TK_RPAREN objectList . + + TK_RPAREN reduce using rule 11 (objectList -> TK_LPAREN object TK_RPAREN objectList .) + + +state 69 + + (17) requireAny -> TK_LPAREN TK_REQANY objectList TK_RPAREN . + + TK_LPAREN reduce using rule 17 (requireAny -> TK_LPAREN TK_REQANY objectList TK_RPAREN .) + TK_RPAREN reduce using rule 17 (requireAny -> TK_LPAREN TK_REQANY objectList TK_RPAREN .) + + +state 70 + + (18) requireAll -> TK_LPAREN TK_REQALL objectList TK_RPAREN . + + TK_LPAREN reduce using rule 18 (requireAll -> TK_LPAREN TK_REQALL objectList TK_RPAREN .) + TK_RPAREN reduce using rule 18 (requireAll -> TK_LPAREN TK_REQALL objectList TK_RPAREN .) + + +state 71 + + (25) object -> otherType otherType TK_FILTER . + + TK_RPAREN reduce using rule 25 (object -> otherType otherType TK_FILTER .) + + +state 72 + + (32) object -> otherType TK_LPAREN otherType . TK_FILTER otherType TK_RPAREN + + TK_FILTER shift and go to state 77 + + +state 73 + + (29) object -> TK_REQNOT TK_LPAREN object . TK_RPAREN + + TK_RPAREN shift and go to state 78 + + +state 74 + + (30) object -> TK_REQNOT TK_LPAREN simpleEntValObject . TK_RPAREN + + TK_RPAREN shift and go to state 79 + + +state 75 + + (39) simpleEntValObject -> TK_REQENT . TK_FILTER + + TK_FILTER shift and go to state 80 + + +state 76 + + (42) regexList -> TK_REGEXPRESSION regexList . + + TK_RPAREN reduce using rule 42 (regexList -> TK_REGEXPRESSION regexList .) + + +state 77 + + (32) object -> otherType TK_LPAREN otherType TK_FILTER . otherType TK_RPAREN + (40) otherType -> . TK_OTHERTYPE + + TK_OTHERTYPE shift and go to state 57 + + otherType shift and go to state 81 + +state 78 + + (29) object -> TK_REQNOT TK_LPAREN object TK_RPAREN . + + TK_RPAREN reduce using rule 29 (object -> TK_REQNOT TK_LPAREN object TK_RPAREN .) + + +state 79 + + (30) object -> TK_REQNOT TK_LPAREN simpleEntValObject TK_RPAREN . + + TK_RPAREN reduce using rule 30 (object -> TK_REQNOT TK_LPAREN simpleEntValObject TK_RPAREN .) + + +state 80 + + (39) simpleEntValObject -> TK_REQENT TK_FILTER . + + TK_RPAREN reduce using rule 39 (simpleEntValObject -> TK_REQENT TK_FILTER .) + + +state 81 + + (32) object -> otherType TK_LPAREN otherType TK_FILTER otherType . TK_RPAREN + + TK_RPAREN shift and go to state 82 + + +state 82 + + (32) object -> otherType TK_LPAREN otherType TK_FILTER otherType TK_RPAREN . + + TK_RPAREN reduce using rule 32 (object -> otherType TK_LPAREN otherType TK_FILTER otherType TK_RPAREN .) + diff --git a/profile_compilation/parsetab.py b/profile_compilation/parsetab.py new file mode 100644 index 0000000..af3cc72 --- /dev/null +++ b/profile_compilation/parsetab.py @@ -0,0 +1,73 @@ + +# parsetab.py +# This file is automatically generated. Do not edit. +# pylint: disable=W,C,R +_tabversion = '3.10' + +_lr_method = 'LALR' + +_lr_signature = 'TK_ALLOW TK_BOOL TK_DEBUGMODE TK_DEFAULT TK_DENY TK_FILEMODETYPE TK_FILTER TK_LPAREN TK_LPREFIX TK_MODENUMBER TK_OTHERTYPE TK_REGEXPRESSION TK_REQALL TK_REQANY TK_REQENT TK_REQNOT TK_RPAREN TK_RPREFIX TK_SPREFIX TK_SUBPATH TK_VERSION TK_VNODETYPEprofile : version default ruleListversion : TK_LPAREN TK_VERSION TK_OTHERTYPE TK_RPARENdefault \t: TK_LPAREN decision TK_DEFAULT TK_RPARENdecision \t: TK_ALLOW \n | TK_DENYruleList \t: rule ruleList\n | rule \t: TK_LPAREN decision action objectList TK_RPAREN\n | TK_LPAREN decision action TK_RPARENaction \t: TK_OTHERTYPEobjectList : TK_LPAREN object TK_RPAREN objectList\n | TK_LPAREN object TK_RPAREN \n | requireAny objectList\n | requireAll objectList\n | requireAny\n | requireAll requireAny\t: TK_LPAREN TK_REQANY objectList TK_RPARENrequireAll\t: TK_LPAREN TK_REQALL objectList TK_RPAREN\n | reqEnt objectList TK_RPAREN\n | reqEnt TK_RPARENreqEnt\t: TK_LPAREN TK_REQENT TK_FILTERobject \t: otherType TK_FILTER\n | regexFilter\n | otherType otherType\n | otherType otherType TK_FILTER\n | subpath\n | prefix\n | filemode\n | TK_REQNOT TK_LPAREN object TK_RPAREN\n | TK_REQNOT TK_LPAREN simpleEntValObject TK_RPAREN\n | TK_VNODETYPE otherType\n | otherType TK_LPAREN otherType TK_FILTER otherType TK_RPAREN\n | TK_DEBUGMODEfilemode : TK_FILEMODETYPE TK_MODENUMBERsubpath\t: TK_SUBPATH TK_FILTERprefix : TK_LPREFIX TK_FILTER\n | TK_SPREFIX TK_FILTER\n | TK_RPREFIX TK_FILTERsimpleEntValObject\t: TK_REQENT TK_FILTERotherType : TK_OTHERTYPEregexFilter : TK_OTHERTYPE regexListregexList \t: TK_REGEXPRESSION regexList\n | TK_REGEXPRESSION' + +_lr_action_items = {'TK_LPAREN':([0,2,4,8,17,18,19,20,23,24,25,26,28,29,31,36,39,45,49,50,53,67,69,70,],[3,5,9,9,-2,21,-10,-3,-9,21,21,21,21,21,56,58,-40,-8,-20,21,-21,-19,-17,-18,]),'$end':([1,4,7,8,14,20,23,45,],[0,-7,-1,-7,-6,-3,-9,-8,]),'TK_VERSION':([3,],[6,]),'TK_ALLOW':([5,9,],[11,11,]),'TK_DENY':([5,9,],[12,12,]),'TK_OTHERTYPE':([6,11,12,15,21,31,37,39,56,58,77,],[13,-4,-5,19,39,57,57,-40,57,39,57,]),'TK_DEFAULT':([10,11,12,],[16,-4,-5,]),'TK_RPAREN':([13,16,18,19,22,24,25,26,27,32,33,34,35,38,46,47,48,49,50,51,52,53,54,55,57,59,60,61,62,63,64,65,66,67,68,69,70,71,73,74,76,78,79,80,81,82,],[17,20,23,-10,45,-15,-16,49,50,-23,-26,-27,-28,-33,-13,-14,67,-20,-12,69,70,-21,-24,-22,-40,-31,-41,-43,-35,-36,-37,-38,-34,-19,-11,-17,-18,-25,78,79,-42,-29,-30,-39,82,-32,]),'TK_REQANY':([21,],[28,]),'TK_REQALL':([21,],[29,]),'TK_REQENT':([21,58,],[30,75,]),'TK_REQNOT':([21,58,],[36,36,]),'TK_VNODETYPE':([21,58,],[37,37,]),'TK_DEBUGMODE':([21,58,],[38,38,]),'TK_SUBPATH':([21,58,],[40,40,]),'TK_LPREFIX':([21,58,],[41,41,]),'TK_SPREFIX':([21,58,],[42,42,]),'TK_RPREFIX':([21,58,],[43,43,]),'TK_FILEMODETYPE':([21,58,],[44,44,]),'TK_FILTER':([30,31,39,40,41,42,43,54,57,72,75,],[53,55,-40,62,63,64,65,71,-40,77,80,]),'TK_REGEXPRESSION':([39,61,],[61,61,]),'TK_MODENUMBER':([44,],[66,]),} + +_lr_action = {} +for _k, _v in _lr_action_items.items(): + for _x,_y in zip(_v[0],_v[1]): + if not _x in _lr_action: _lr_action[_x] = {} + _lr_action[_x][_k] = _y +del _lr_action_items + +_lr_goto_items = {'profile':([0,],[1,]),'version':([0,],[2,]),'default':([2,],[4,]),'ruleList':([4,8,],[7,14,]),'rule':([4,8,],[8,8,]),'decision':([5,9,],[10,15,]),'action':([15,],[18,]),'objectList':([18,24,25,26,28,29,50,],[22,46,47,48,51,52,68,]),'requireAny':([18,24,25,26,28,29,50,],[24,24,24,24,24,24,24,]),'requireAll':([18,24,25,26,28,29,50,],[25,25,25,25,25,25,25,]),'reqEnt':([18,24,25,26,28,29,50,],[26,26,26,26,26,26,26,]),'object':([21,58,],[27,73,]),'otherType':([21,31,37,56,58,77,],[31,54,59,72,31,81,]),'regexFilter':([21,58,],[32,32,]),'subpath':([21,58,],[33,33,]),'prefix':([21,58,],[34,34,]),'filemode':([21,58,],[35,35,]),'regexList':([39,61,],[60,76,]),'simpleEntValObject':([58,],[74,]),} + +_lr_goto = {} +for _k, _v in _lr_goto_items.items(): + for _x, _y in zip(_v[0], _v[1]): + if not _x in _lr_goto: _lr_goto[_x] = {} + _lr_goto[_x][_k] = _y +del _lr_goto_items +_lr_productions = [ + ("S' -> profile","S'",1,None,None,None), + ('profile -> version default ruleList','profile',3,'p_profile','sandscout_compiler.py',127), + ('version -> TK_LPAREN TK_VERSION TK_OTHERTYPE TK_RPAREN','version',4,'p_version','sandscout_compiler.py',134), + ('default -> TK_LPAREN decision TK_DEFAULT TK_RPAREN','default',4,'p_default','sandscout_compiler.py',139), + ('decision -> TK_ALLOW','decision',1,'p_decision','sandscout_compiler.py',146), + ('decision -> TK_DENY','decision',1,'p_decision','sandscout_compiler.py',147), + ('ruleList -> rule ruleList','ruleList',2,'p_ruleList','sandscout_compiler.py',152), + ('ruleList -> ','ruleList',0,'p_ruleList','sandscout_compiler.py',153), + ('rule -> TK_LPAREN decision action objectList TK_RPAREN','rule',5,'p_rule','sandscout_compiler.py',162), + ('rule -> TK_LPAREN decision action TK_RPAREN','rule',4,'p_rule','sandscout_compiler.py',163), + ('action -> TK_OTHERTYPE','action',1,'p_action','sandscout_compiler.py',189), + ('objectList -> TK_LPAREN object TK_RPAREN objectList','objectList',4,'p_objectList','sandscout_compiler.py',194), + ('objectList -> TK_LPAREN object TK_RPAREN','objectList',3,'p_objectList','sandscout_compiler.py',195), + ('objectList -> requireAny objectList','objectList',2,'p_objectList','sandscout_compiler.py',196), + ('objectList -> requireAll objectList','objectList',2,'p_objectList','sandscout_compiler.py',197), + ('objectList -> requireAny','objectList',1,'p_objectList','sandscout_compiler.py',198), + ('objectList -> requireAll','objectList',1,'p_objectList','sandscout_compiler.py',199), + ('requireAny -> TK_LPAREN TK_REQANY objectList TK_RPAREN','requireAny',4,'p_requireAny','sandscout_compiler.py',213), + ('requireAll -> TK_LPAREN TK_REQALL objectList TK_RPAREN','requireAll',4,'p_requireAll','sandscout_compiler.py',229), + ('requireAll -> reqEnt objectList TK_RPAREN','requireAll',3,'p_requireAll','sandscout_compiler.py',230), + ('requireAll -> reqEnt TK_RPAREN','requireAll',2,'p_requireAll','sandscout_compiler.py',231), + ('reqEnt -> TK_LPAREN TK_REQENT TK_FILTER','reqEnt',3,'p_reqEnt','sandscout_compiler.py',280), + ('object -> otherType TK_FILTER','object',2,'p_object','sandscout_compiler.py',287), + ('object -> regexFilter','object',1,'p_object','sandscout_compiler.py',288), + ('object -> otherType otherType','object',2,'p_object','sandscout_compiler.py',289), + ('object -> otherType otherType TK_FILTER','object',3,'p_object','sandscout_compiler.py',290), + ('object -> subpath','object',1,'p_object','sandscout_compiler.py',291), + ('object -> prefix','object',1,'p_object','sandscout_compiler.py',292), + ('object -> filemode','object',1,'p_object','sandscout_compiler.py',293), + ('object -> TK_REQNOT TK_LPAREN object TK_RPAREN','object',4,'p_object','sandscout_compiler.py',294), + ('object -> TK_REQNOT TK_LPAREN simpleEntValObject TK_RPAREN','object',4,'p_object','sandscout_compiler.py',295), + ('object -> TK_VNODETYPE otherType','object',2,'p_object','sandscout_compiler.py',296), + ('object -> otherType TK_LPAREN otherType TK_FILTER otherType TK_RPAREN','object',6,'p_object','sandscout_compiler.py',297), + ('object -> TK_DEBUGMODE','object',1,'p_object','sandscout_compiler.py',298), + ('filemode -> TK_FILEMODETYPE TK_MODENUMBER','filemode',2,'p_filemode','sandscout_compiler.py',326), + ('subpath -> TK_SUBPATH TK_FILTER','subpath',2,'p_subpath','sandscout_compiler.py',331), + ('prefix -> TK_LPREFIX TK_FILTER','prefix',2,'p_prefix','sandscout_compiler.py',337), + ('prefix -> TK_SPREFIX TK_FILTER','prefix',2,'p_prefix','sandscout_compiler.py',338), + ('prefix -> TK_RPREFIX TK_FILTER','prefix',2,'p_prefix','sandscout_compiler.py',339), + ('simpleEntValObject -> TK_REQENT TK_FILTER','simpleEntValObject',2,'p_simpleEntValObject','sandscout_compiler.py',358), + ('otherType -> TK_OTHERTYPE','otherType',1,'p_otherType','sandscout_compiler.py',364), + ('regexFilter -> TK_OTHERTYPE regexList','regexFilter',2,'p_regexFilter','sandscout_compiler.py',371), + ('regexList -> TK_REGEXPRESSION regexList','regexList',2,'p_regexList','sandscout_compiler.py',381), + ('regexList -> TK_REGEXPRESSION','regexList',1,'p_regexList','sandscout_compiler.py',382), +] diff --git a/profile_compilation/sandscout_compiler.py b/profile_compilation/sandscout_compiler.py index ca8edf9..7cef26b 100755 --- a/profile_compilation/sandscout_compiler.py +++ b/profile_compilation/sandscout_compiler.py @@ -8,28 +8,28 @@ #################################################### -#begin tokenizer / lex +# begin tokenizer / lex #################################################### reserved = { -'subpath' : 'TK_SUBPATH', -'literal-prefix' : 'TK_LPREFIX', -'subpath-prefix' : 'TK_SPREFIX', -'regex-prefix' : 'TK_RPREFIX', -'allow' : 'TK_ALLOW', -'deny' : 'TK_DENY', -'version' : 'TK_VERSION', -'default' : 'TK_DEFAULT', -'require-all' : 'TK_REQALL', -'require-any' : 'TK_REQANY', -'require-not' : 'TK_REQNOT', -'vnode-type' : 'TK_VNODETYPE', -'file-mode' : 'TK_FILEMODETYPE', -'debug-mode' : 'TK_DEBUGMODE', -'require-entitlement' : 'TK_REQENT'} + 'subpath': 'TK_SUBPATH', + 'literal-prefix': 'TK_LPREFIX', + 'subpath-prefix': 'TK_SPREFIX', + 'regex-prefix': 'TK_RPREFIX', + 'allow': 'TK_ALLOW', + 'deny': 'TK_DENY', + 'version': 'TK_VERSION', + 'default': 'TK_DEFAULT', + 'require-all': 'TK_REQALL', + 'require-any': 'TK_REQANY', + 'require-not': 'TK_REQNOT', + 'vnode-type': 'TK_VNODETYPE', + 'file-mode': 'TK_FILEMODETYPE', + 'debug-mode': 'TK_DEBUGMODE', + 'require-entitlement': 'TK_REQENT'} # List of token names. This is always required -tokens = [ +tokens = [ 'TK_LPAREN', 'TK_RPAREN', 'TK_FILTER', @@ -43,57 +43,67 @@ t_TK_LPAREN = r'\(' t_TK_RPAREN = r'\)' + def t_TK_OTHERTYPE(t): - r'[^\"\n#\ \(\)][^\n\ \(\)]*' - if t.value in reserved: - t.type = reserved.get(t.value,'ID') - else: - t.value = str(t.value) - return t - + r'[^\"\n#\ \(\)][^\n\ \(\)]*' + if t.value in reserved: + t.type = reserved.get(t.value, 'ID') + else: + t.value = str(t.value) + return t + + def t_TK_FILTER(t): - r'"[^"]*"' - t.value = str(t.value) - return t + r'"[^"]*"' + t.value = str(t.value) + return t + def t_TK_REGEXPRESSION(t): - r'\#"[^"]*"' - t.value = str(t.value) - return t + r'\#"[^"]*"' + t.value = str(t.value) + return t + def t_TK_BOOL(t): - r'\#[tf]' - t.value = str(t.value) - return t + r'\#[tf]' + t.value = str(t.value) + return t -#attempting to match file-mode number such as #o0004 -def t_TK_MODENUMBER(t): - r'\#o[0-9][0-9][0-9][0-9]' - t.value = str(t.value) - return t +# attempting to match file-mode number such as #o0004 +def t_TK_MODENUMBER(t): + r'\#o[0-9][0-9][0-9][0-9]' + t.value = str(t.value) + return t + -#Taken from ply example in documentation -#Tracks line numbers +# Taken from ply example in documentation +# Tracks line numbers def t_newline(t): - r'\n+' - t.lexer.lineno += len(t.value) + r'\n+' + t.lexer.lineno += len(t.value) -#Taken from ply example in documentation -#Ignores spaces and tabs + +# Taken from ply example in documentation +# Ignores spaces and tabs t_ignore = ' \t' -#Taken from ply example in documentation -#Handle error +# Taken from ply example in documentation +# Handle error + + def t_error(t): - sys.stderr.write('line '+str(lexer.lineno)+': illegal character ('+str(t.value[0])+')\n') - sys.exit() - t.lexer.skip(1) + sys.stderr.write('line '+str(lexer.lineno) + + ': illegal character ('+str(t.value[0])+')\n') + sys.exit() + t.lexer.skip(1) + lexer = lex.lex() -#get input file +# get input file inputFile = open(sys.argv[1], "r").read() lexer.input(inputFile) @@ -107,267 +117,288 @@ def t_error(t): """ #################################################### -#begin parser / yacc +# begin parser / yacc #################################################### root = "root not set" + def p_profile(p): - 'profile : version default ruleList' - p[0] = p[2] + p[3] - global root - root = p[0] - + 'profile : version default ruleList' + p[0] = p[2] + p[3] + global root + root = p[0] + def p_version(p): - 'version : TK_LPAREN TK_VERSION TK_OTHERTYPE TK_RPAREN' - p[0] = p[2] + p[3] + 'version : TK_LPAREN TK_VERSION TK_OTHERTYPE TK_RPAREN' + p[0] = p[2] + p[3] + def p_default(p): - 'default : TK_LPAREN decision TK_DEFAULT TK_RPAREN' - #p[0] = p[2] + p[3] - p[0] = ["profileDefault(profile(\""+sys.argv[2]+"\"),decision(\""+p[2]+"\"))."] + 'default : TK_LPAREN decision TK_DEFAULT TK_RPAREN' + #p[0] = p[2] + p[3] + p[0] = ["profileDefault(profile(\""+sys.argv[2] + + "\"),decision(\""+p[2]+"\"))."] + def p_decision(p): - '''decision : TK_ALLOW - | TK_DENY''' - p[0] = p[1] + '''decision : TK_ALLOW + | TK_DENY''' + p[0] = p[1] + def p_ruleList(p): - '''ruleList : rule ruleList - | ''' - if len(p) == 3: - #I'm assuming this will be the sum of two lists - p[0] = p[1] + p[2] - else: - p[0] = [] + '''ruleList : rule ruleList + | ''' + if len(p) == 3: + # I'm assuming this will be the sum of two lists + p[0] = p[1] + p[2] + else: + p[0] = [] -def p_rule(p): - '''rule : TK_LPAREN decision action objectList TK_RPAREN - | TK_LPAREN decision action TK_RPAREN''' - #each rule is a list of strings - #this code needs to be adjusted to split objectLists apart into separate strings - #prolog freaks out if I use * outside of a string, so I will replace it. - p[3] = p[3].replace('*','STAR') +def p_rule(p): + '''rule : TK_LPAREN decision action objectList TK_RPAREN + | TK_LPAREN decision action TK_RPAREN''' + # each rule is a list of strings + # this code needs to be adjusted to split objectLists apart into separate strings + + # prolog freaks out if I use * outside of a string, so I will replace it. + p[3] = p[3].replace('*', 'STAR') + + if len(p) == 6: + p[0] = [] + for o in p[4]: + if type(o) is str: + #p[0].append(p[2]+"("+p[3] +", [" + o +"]).") + p[0].append("profileRule(profile(\""+sys.argv[2]+"\"),decision(\"" + + p[2] + "\"),operation(\"" + p[3] + "\"),filters([" + o + "])).") + else: + # Some facts were not getting periods at the end. I suspect this is the code that needs to be fixed. + for anyElement in o: + #p[0].append(p[2]+"("+p[3] +", [" + anyElement +"]).") + p[0].append("profileRule(profile(\""+sys.argv[2]+"\"),decision(\""+p[2] + + "\"),operation(\"" + p[3] + "\"),filters([" + anyElement + "])).") + if len(p) == 5: + p[0] = ["profileRule(profile(\""+sys.argv[2]+"\"),decision(\"" + + p[2] + "\"),operation(\"" + p[3] + "\"),filters([]))."] - if len(p) == 6: - p[0] = [] - for o in p[4]: - if type(o) is str: - #p[0].append(p[2]+"("+p[3] +", [" + o +"]).") - p[0].append("profileRule(profile(\""+sys.argv[2]+"\"),decision(\""+p[2] +"\"),operation(\""+ p[3] +"\"),filters(["+ o +"])).") - else: - #Some facts were not getting periods at the end. I suspect this is the code that needs to be fixed. - for anyElement in o: - #p[0].append(p[2]+"("+p[3] +", [" + anyElement +"]).") - p[0].append("profileRule(profile(\""+sys.argv[2]+"\"),decision(\""+p[2] +"\"),operation(\""+ p[3] +"\"),filters(["+ anyElement +"])).") - if len(p) == 5: - p[0] = ["profileRule(profile(\""+sys.argv[2]+"\"),decision(\""+p[2] +"\"),operation(\""+ p[3] +"\"),filters([]))."] def p_action(p): - 'action : TK_OTHERTYPE' - p[0] = p[1] + 'action : TK_OTHERTYPE' + p[0] = p[1] + def p_objectList(p): - '''objectList : TK_LPAREN object TK_RPAREN objectList - | TK_LPAREN object TK_RPAREN - | requireAny objectList - | requireAll objectList - | requireAny - | requireAll ''' - if len(p) == 5: - #what if p[4] contains more than one element? - #I think that this is where my trouble with back to back requireAlls is coming from... - p[0] = [p[2]] + p[4] - if len(p) == 4: - p[0] = [p[2]] - if len(p) == 3: - p[0] = p[1] + p[2] - if len(p) == 2: - p[0] = p[1] + '''objectList : TK_LPAREN object TK_RPAREN objectList + | TK_LPAREN object TK_RPAREN + | requireAny objectList + | requireAll objectList + | requireAny + | requireAll ''' + if len(p) == 5: + # what if p[4] contains more than one element? + # I think that this is where my trouble with back to back requireAlls is coming from... + p[0] = [p[2]] + p[4] + if len(p) == 4: + p[0] = [p[2]] + if len(p) == 3: + p[0] = p[1] + p[2] + if len(p) == 2: + p[0] = p[1] + def p_requireAny(p): - 'requireAny : TK_LPAREN TK_REQANY objectList TK_RPAREN' - #look for elements that are lists. This would indicate back to back requireAny's which are redundant. - #it should be safe to simply combine these into one list - # (A or B or (C or D)) = (A or B or C or D) - - p[0] = [] - for anyElement in p[3]: - if type(anyElement) is str: - p[0].append(anyElement) - else: - for nestedAny in anyElement: - p[0].append(nestedAny) - p[0] = [p[0]] + 'requireAny : TK_LPAREN TK_REQANY objectList TK_RPAREN' + # look for elements that are lists. This would indicate back to back requireAny's which are redundant. + # it should be safe to simply combine these into one list + # (A or B or (C or D)) = (A or B or C or D) -def p_requireAll(p): - '''requireAll : TK_LPAREN TK_REQALL objectList TK_RPAREN - | reqEnt objectList TK_RPAREN - | reqEnt TK_RPAREN''' - #TODO: add logic to distinguish between the three possibilities. - #Could we use objectList instead of entValList? - - #we will be returning a list of strings at the end of this. - returnedList = [] - p[0] = [""] - if len(p) == 5: - returnedList = p[3] - if len(p) == 4: - returnedList = p[2] - - for allElement in returnedList: - if type(allElement) is str: - for i in range(len(p[0])): - if p[0][i] == "": - p[0][i] = allElement - else: - p[0][i] = p[0][i] +","+ allElement - else: - splitGen = [] - for anyElement in allElement: - iteration = [] - for i in range(len(p[0])): - #TODO: I think this is where the extra commas are coming from - if p[0][i] == "": - iteration.append(anyElement) - else: - iteration.append(p[0][i] +","+ anyElement) - splitGen += iteration - p[0] = splitGen - - #If this was in the context of require-entitlement, - #then I need to wrap all the entitlement values in the list of the proper functor. - if len(p) == 4: - for i in range(len(p[0])): - p[0][i] = "require-entitlement("+ p[1] +",["+ p[0][i] +"])" - #this is a guess for how to solve requireAll( requireEnt ( ...)) - - if len(p) == 3: - #without an entValList, there are no elements to process - p[0] = ["require-entitlement("+ p[1] +",[])"] - - #is it safe to have all requireAlls return a list containing a list of strings? - #TODO : this seems to work, so I will keep it for now and verify later... - p[0] = [p[0]] + p[0] = [] + for anyElement in p[3]: + if type(anyElement) is str: + p[0].append(anyElement) + else: + for nestedAny in anyElement: + p[0].append(nestedAny) + p[0] = [p[0]] -def p_reqEnt(p): - 'reqEnt : TK_LPAREN TK_REQENT TK_FILTER' - p[0] = p[3] +def p_requireAll(p): + '''requireAll : TK_LPAREN TK_REQALL objectList TK_RPAREN + | reqEnt objectList TK_RPAREN + | reqEnt TK_RPAREN''' + # TODO: add logic to distinguish between the three possibilities. + # Could we use objectList instead of entValList? + + # we will be returning a list of strings at the end of this. + returnedList = [] + p[0] = [""] + if len(p) == 5: + returnedList = p[3] + if len(p) == 4: + returnedList = p[2] + + for allElement in returnedList: + if type(allElement) is str: + for i in range(len(p[0])): + if p[0][i] == "": + p[0][i] = allElement + else: + p[0][i] = p[0][i] + "," + allElement + else: + splitGen = [] + for anyElement in allElement: + iteration = [] + for i in range(len(p[0])): + # TODO: I think this is where the extra commas are coming from + if p[0][i] == "": + iteration.append(anyElement) + else: + iteration.append(p[0][i] + "," + anyElement) + splitGen += iteration + p[0] = splitGen + + # If this was in the context of require-entitlement, + # then I need to wrap all the entitlement values in the list of the proper functor. + if len(p) == 4: + for i in range(len(p[0])): + p[0][i] = "require-entitlement(" + p[1] + ",[" + p[0][i] + "])" + # this is a guess for how to solve requireAll( requireEnt ( ...)) + + if len(p) == 3: + # without an entValList, there are no elements to process + p[0] = ["require-entitlement(" + p[1] + ",[])"] + + # is it safe to have all requireAlls return a list containing a list of strings? + # TODO : this seems to work, so I will keep it for now and verify later... + p[0] = [p[0]] +def p_reqEnt(p): + 'reqEnt : TK_LPAREN TK_REQENT TK_FILTER' + p[0] = p[3] -#TODO: the TK_ENTVAL TK_BOOL is a temporary fix and should be removed once we fix our SBPL profiles -#TODO: I need to be more careful about the way we handle requireEntitlement +# TODO: the TK_ENTVAL TK_BOOL is a temporary fix and should be removed once we fix our SBPL profiles +# TODO: I need to be more careful about the way we handle requireEntitlement def p_object(p): - '''object : otherType TK_FILTER - | regexFilter - | otherType otherType - | otherType otherType TK_FILTER - | subpath - | prefix - | filemode - | TK_REQNOT TK_LPAREN object TK_RPAREN - | TK_REQNOT TK_LPAREN simpleEntValObject TK_RPAREN - | TK_VNODETYPE otherType - | otherType TK_LPAREN otherType TK_FILTER otherType TK_RPAREN - | TK_DEBUGMODE''' - if len(p) == 2: - p[0] = p[1] - if len(p) == 3: - p[0] = p[1] +"("+ p[2]+ ")" - if len(p) == 4: - p[0] = p[1] +"("+ p[2] +"("+ p[3] +"))" - if len(p) == 5: - if type(p[3]) is str: - p[0] = p[1] + p[2] + p[3] + p[4] - #requireNot could be wrapped around a bundled regular expression - #In this case, it should be treated like a requireAll by concatenating strings - else: - p[0]="" - for anyElement in p[3]: - if p[0] == "": - p[0] = p[1] + p[2] + anyElement + p[4] - else: - p[0] += "," + p[1] + p[2] + anyElement + p[4] -#this is for the system-fsctl operation which has very complex filters -#TODO: we should make a more generic expression that can match any filter, but not metafilters or implied metafilters. - if len(p) == 7: - temp = '"'+p[3]+'"' - p[3] = temp - p[0] = p[1] +"("+ p[3] +","+ p[4] +","+ p[5] +")" + '''object : otherType TK_FILTER + | regexFilter + | otherType otherType + | otherType otherType TK_FILTER + | subpath + | prefix + | filemode + | TK_REQNOT TK_LPAREN object TK_RPAREN + | TK_REQNOT TK_LPAREN simpleEntValObject TK_RPAREN + | TK_VNODETYPE otherType + | otherType TK_LPAREN otherType TK_FILTER otherType TK_RPAREN + | TK_DEBUGMODE''' + if len(p) == 2: + p[0] = p[1] + if len(p) == 3: + p[0] = p[1] + "(" + p[2] + ")" + if len(p) == 4: + p[0] = p[1] + "(" + p[2] + "(" + p[3] + "))" + if len(p) == 5: + if type(p[3]) is str: + p[0] = p[1] + p[2] + p[3] + p[4] + # requireNot could be wrapped around a bundled regular expression + # In this case, it should be treated like a requireAll by concatenating strings + else: + p[0] = "" + for anyElement in p[3]: + if p[0] == "": + p[0] = p[1] + p[2] + anyElement + p[4] + else: + p[0] += "," + p[1] + p[2] + anyElement + p[4] +# this is for the system-fsctl operation which has very complex filters +# TODO: we should make a more generic expression that can match any filter, but not metafilters or implied metafilters. + if len(p) == 7: + temp = '"'+p[3]+'"' + p[3] = temp + p[0] = p[1] + "(" + p[3] + "," + p[4] + "," + p[5] + ")" + def p_filemode(p): - 'filemode : TK_FILEMODETYPE TK_MODENUMBER' - p[0] = p[1] +"(\""+ p[2]+ "\")" + 'filemode : TK_FILEMODETYPE TK_MODENUMBER' + p[0] = p[1] + "(\"" + p[2] + "\")" + def p_subpath(p): - 'subpath : TK_SUBPATH TK_FILTER' - p[2] = p[2][:-1] + '/"' - p[0] = p[1] +"("+ p[2]+ ")" + 'subpath : TK_SUBPATH TK_FILTER' + p[2] = p[2][:-1] + '/"' + p[0] = p[1] + "(" + p[2] + ")" + def p_prefix(p): - '''prefix : TK_LPREFIX TK_FILTER - | TK_SPREFIX TK_FILTER - | TK_RPREFIX TK_FILTER''' - - #if there is a variable in the prefix - if "{" in p[2]: - #do the ugly regex work here, and just rip out what I need from the filter. This is good enough. - pattern = re.compile('"\${([^}]*)}([^"]*)"') - matches = pattern.match(p[2]) - p[0] = p[1] + "(variable(\"" + matches.group(1) + "\"),path(\"" + matches.group(2) + "\"))" - #if there is not a variable in the prefix then we just treat the filter like a subpath - #this might be too vague, but let's see what happens. - else: - #I am not appending a / since prefixes might state literals in the filter argument. - p[0] = "subpath(" + p[2] + ")" - - -#TODO: this is sort of a hack and I should evaluate it effects carefully -#the issue is that requireNot can now accept entitlement requirements as parameters + '''prefix : TK_LPREFIX TK_FILTER + | TK_SPREFIX TK_FILTER + | TK_RPREFIX TK_FILTER''' + + # if there is a variable in the prefix + if "{" in p[2]: + # do the ugly regex work here, and just rip out what I need from the filter. This is good enough. + pattern = re.compile('"\${([^}]*)}([^"]*)"') + matches = pattern.match(p[2]) + p[0] = p[1] + "(variable(\"" + matches.group(1) + \ + "\"),path(\"" + matches.group(2) + "\"))" + # if there is not a variable in the prefix then we just treat the filter like a subpath + # this might be too vague, but let's see what happens. + else: + # I am not appending a / since prefixes might state literals in the filter argument. + p[0] = "subpath(" + p[2] + ")" + + +# TODO: this is sort of a hack and I should evaluate it effects carefully +# the issue is that requireNot can now accept entitlement requirements as parameters def p_simpleEntValObject(p): - 'simpleEntValObject : TK_REQENT TK_FILTER' - p[0] = p[1] +"("+ p[2] +")" - #p[0] = "todoFixNegatedEnts" + 'simpleEntValObject : TK_REQENT TK_FILTER' + p[0] = p[1] + "(" + p[2] + ")" + #p[0] = "todoFixNegatedEnts" + def p_otherType(p): - 'otherType : TK_OTHERTYPE' - #Some filter types are capitalized, but this confuses Prolog, so we make them lowercase - p[1] = p[1].lower() - p[0] = p[1] - + 'otherType : TK_OTHERTYPE' + # Some filter types are capitalized, but this confuses Prolog, so we make them lowercase + p[1] = p[1].lower() + p[0] = p[1] + + def p_regexFilter(p): - 'regexFilter : TK_OTHERTYPE regexList' - p[0] = [] - for r in p[2]: - r = r[1:] - r += "/i" - r = r.replace("\\.","[.]") - p[0].append( p[1] + "(" + r + ")" ) + 'regexFilter : TK_OTHERTYPE regexList' + p[0] = [] + for r in p[2]: + r = r[1:] + r += "/i" + r = r.replace("\\.", "[.]") + p[0].append(p[1] + "(" + r + ")") + def p_regexList(p): - '''regexList : TK_REGEXPRESSION regexList - | TK_REGEXPRESSION''' - if len(p) == 2: - p[0] = [p[1]] - if len(p) == 3: - p[0] = [p[1]] + p[2] + '''regexList : TK_REGEXPRESSION regexList + | TK_REGEXPRESSION''' + if len(p) == 2: + p[0] = [p[1]] + if len(p) == 3: + p[0] = [p[1]] + p[2] + def p_error(p): - if p == None: - sys.stderr.write('line '+str(lexer.lineno)+': syntax error at EOF\n') - else: - sys.stderr.write('line '+str(lexer.lineno)+': syntax error near '+str(p.value)+'\n') - sys.exit() + if p == None: + sys.stderr.write('line '+str(lexer.lineno)+': syntax error at EOF\n') + else: + sys.stderr.write('line '+str(lexer.lineno) + + ': syntax error near '+str(p.value)+'\n') + sys.exit() + parser = yacc.yacc() parser.parse(inputFile) -print "\n", +print ("\n"), for r in root: - print r + print (r) diff --git a/rules.pl b/rules.pl index 4cdc2b7..f697a36 100644 --- a/rules.pl +++ b/rules.pl @@ -103,7 +103,7 @@ write(Stream,R1), write(Stream,","), write(Stream,L1), write(Stream,","), write(Stream,W1), write(Stream,","), - write(Stream,L2), nl(Stream), + write(Stream,L2), nl(Stream), close(Stream), fail. diff --git a/smartPly.py b/smartPly.py index 464a17a..76576f1 100755 --- a/smartPly.py +++ b/smartPly.py @@ -2,9 +2,7 @@ import ply.lex as lex import ply.yacc as yacc -import os import sys -import fileinput import re @@ -22,6 +20,7 @@ 'require-any' : 'TK_REQANY', 'require-not' : 'TK_REQNOT', 'vnode-type' : 'TK_VNODETYPE', + 'file-mode': 'TK_FILEMODETYPE', #Fix for the # in files 'debug-mode' : 'TK_DEBUGMODE', 'require-entitlement' : 'TK_REQENT'} @@ -33,6 +32,7 @@ 'TK_OTHERTYPE', 'TK_BOOL', 'TK_REGEXPRESSION', + 'TK_HASH' #Fix for the # in files ] + list(reserved.values()) # Regular expression rules for simple tokens @@ -62,6 +62,13 @@ def t_TK_BOOL(t): t.value = str(t.value) return t +#Fix for the # in files +def t_TK_HASH(t): + r'\#[a-z][0-9][0-9][0-9][0-9]' + r'\#[a-z]' + t.value = str(t.value) + return t + #Taken from ply example in documentation #Tracks line numbers @@ -254,6 +261,7 @@ def p_object(p): | otherType otherType | otherType otherType TK_FILTER | subpath + | filemode | TK_REQNOT TK_LPAREN object TK_RPAREN | TK_REQNOT TK_LPAREN simpleEntValObject TK_RPAREN | TK_VNODETYPE otherType @@ -284,6 +292,10 @@ def p_object(p): p[3] = temp p[0] = p[1] +"("+ p[3] +","+ p[4] +","+ p[5] +")" +def p_filemode(p): #Fix for the # in files + 'filemode : TK_FILEMODETYPE TK_HASH' + p[0] = p[1] + "(\"" + p[2] + "\")" + def p_subpath(p): 'subpath : TK_SUBPATH TK_FILTER' p[2] = p[2][:-1] + '/"' diff --git a/test-cases/ios-sandbox-profiles b/test-cases/ios-sandbox-profiles new file mode 160000 index 0000000..5bae9c6 --- /dev/null +++ b/test-cases/ios-sandbox-profiles @@ -0,0 +1 @@ +Subproject commit 5bae9c66847c86356172fbcda0448539d6792e63