error.bend

bend-osdev-apparmor@0.1.0.0 · 175 lines · 19 definitions

1# bend-osdev-apparmor: why a policy fails to load. Each failure names the
2# file and line where it was found (line 0 when it belongs to no line).
3import Base
4
5type AaError is Data:
6  # the text cannot be split into tokens (an unterminated quote, an unbalanced parenthesis)
7  AaErrLex{file: List<&2, U32>, line: U32}
8  # a statement or block that does not fit the grammar
9  AaErrSyntax{file: List<&2, U32>, line: U32}
10  # a malformed pattern (glob)
11  AaErrGlob{file: List<&2, U32>, line: U32}
12  # an unknown name: capability, network domain or type, signal, mount option, flag
13  AaErrName{file: List<&2, U32>, line: U32}
14  # an invalid permission string: unknown letters, w with a, two exec modes,
15  # an exec mode in a deny rule, a bare x in an allow rule, a target without an exec mode
16  AaErrPerms{file: List<&2, U32>, line: U32}
17  # a rule kind or condition outside the model (unix, pivot_root, rlimit, link, ...)
18  AaErrUnsupported{file: List<&2, U32>, line: U32}
19  # an included file that is not in the file map (and the include is not "if exists")
20  AaErrInclude{file: List<&2, U32>, line: U32}
21  # includes nested deeper than the options allow
22  AaErrIncludeDepth{file: List<&2, U32>, line: U32}
23  # a variable used but never assigned
24  AaErrVarUndefined{file: List<&2, U32>, line: U32}
25  # a variable assigned with = twice, or extended with += before it is assigned
26  AaErrVarRedefined{file: List<&2, U32>, line: U32}
27  # a variable or alias statement after the first profile, or inside one
28  AaErrPreamble{file: List<&2, U32>, line: U32}
29  # an unknown or conflicting profile flag
30  AaErrFlag{file: List<&2, U32>, line: U32}
31  # two profiles, children or hats with the same name
32  AaErrDuplicate{file: List<&2, U32>, line: U32}
33  # two rules for the same literal path with different exec modes
34  AaErrExecConflict{file: List<&2, U32>, line: U32}
35
36def AaError.line(e: AaError) -> U32:
37  match e:
38    case AaErrLex{f, l}:
39      l
40    case AaErrSyntax{f, l}:
41      l
42    case AaErrGlob{f, l}:
43      l
44    case AaErrName{f, l}:
45      l
46    case AaErrPerms{f, l}:
47      l
48    case AaErrUnsupported{f, l}:
49      l
50    case AaErrInclude{f, l}:
51      l
52    case AaErrIncludeDepth{f, l}:
53      l
54    case AaErrVarUndefined{f, l}:
55      l
56    case AaErrVarRedefined{f, l}:
57      l
58    case AaErrPreamble{f, l}:
59      l
60    case AaErrFlag{f, l}:
61      l
62    case AaErrDuplicate{f, l}:
63      l
64    case AaErrExecConflict{f, l}:
65      l
66
67def AaError.name(e: AaError) -> String:
68  match e:
69    case AaErrLex{f, l}:
70      "lex"
71    case AaErrSyntax{f, l}:
72      "syntax"
73    case AaErrGlob{f, l}:
74      "glob"
75    case AaErrName{f, l}:
76      "name"
77    case AaErrPerms{f, l}:
78      "perms"
79    case AaErrUnsupported{f, l}:
80      "unsupported"
81    case AaErrInclude{f, l}:
82      "include"
83    case AaErrIncludeDepth{f, l}:
84      "include-depth"
85    case AaErrVarUndefined{f, l}:
86      "var-undefined"
87    case AaErrVarRedefined{f, l}:
88      "var-redefined"
89    case AaErrPreamble{f, l}:
90      "preamble"
91    case AaErrFlag{f, l}:
92      "flag"
93    case AaErrDuplicate{f, l}:
94      "duplicate"
95    case AaErrExecConflict{f, l}:
96      "exec-conflict"
97
98# where a statement came from: what rule parsers report errors against
99type AaSrc is Data:
100  AaSrc{file: List<&2, U32>, line: U32}
101
102def AaSrc.line(s: AaSrc) -> U32:
103  match s:
104    case AaSrc{f, l}:
105      l
106
107def AaSrc.lex(s: AaSrc) -> AaError:
108  match s:
109    case AaSrc{f, l}:
110      AaErrLex{f, l}
111
112def AaSrc.syntax(s: AaSrc) -> AaError:
113  match s:
114    case AaSrc{f, l}:
115      AaErrSyntax{f, l}
116
117def AaSrc.glob(s: AaSrc) -> AaError:
118  match s:
119    case AaSrc{f, l}:
120      AaErrGlob{f, l}
121
122def AaSrc.name(s: AaSrc) -> AaError:
123  match s:
124    case AaSrc{f, l}:
125      AaErrName{f, l}
126
127def AaSrc.perms(s: AaSrc) -> AaError:
128  match s:
129    case AaSrc{f, l}:
130      AaErrPerms{f, l}
131
132def AaSrc.unsupported(s: AaSrc) -> AaError:
133  match s:
134    case AaSrc{f, l}:
135      AaErrUnsupported{f, l}
136
137def AaSrc.include(s: AaSrc) -> AaError:
138  match s:
139    case AaSrc{f, l}:
140      AaErrInclude{f, l}
141
142def AaSrc.include_depth(s: AaSrc) -> AaError:
143  match s:
144    case AaSrc{f, l}:
145      AaErrIncludeDepth{f, l}
146
147def AaSrc.var_undefined(s: AaSrc) -> AaError:
148  match s:
149    case AaSrc{f, l}:
150      AaErrVarUndefined{f, l}
151
152def AaSrc.var_redefined(s: AaSrc) -> AaError:
153  match s:
154    case AaSrc{f, l}:
155      AaErrVarRedefined{f, l}
156
157def AaSrc.preamble(s: AaSrc) -> AaError:
158  match s:
159    case AaSrc{f, l}:
160      AaErrPreamble{f, l}
161
162def AaSrc.flag(s: AaSrc) -> AaError:
163  match s:
164    case AaSrc{f, l}:
165      AaErrFlag{f, l}
166
167def AaSrc.duplicate(s: AaSrc) -> AaError:
168  match s:
169    case AaSrc{f, l}:
170      AaErrDuplicate{f, l}
171
172def AaSrc.exec_conflict(s: AaSrc) -> AaError:
173  match s:
174    case AaSrc{f, l}:
175      AaErrExecConflict{f, l}