Debian Codegraph @

data/syntax/selinux-fc.xml

raw
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE language
3 [
4 <!-- Identifier with M4 Arg. or variables -->
5 <!ENTITY charIden "(?:\$[@#]|[\w\-\$\*\{\}&#037;])">
6 <!ENTITY simpleIdentifier "(?:\$[@#]|[a-zA-Z\$&#037;])&charIden;*">
7 <!ENTITY identifier "&simpleIdentifier;(?:\.?&charIden;)*">
8 <!ENTITY startIdentifier "(?:\b[a-zA-Z]|\$[@#]|[\$&#037;])&charIden;*(?:\.?&charIden;)*">
9 <!ENTITY mlsLevel "&identifier;(?:\s*\:\s*&identifier;(?:\s*,\s*&identifier;)*)?">
10 ]>
11
12 <!--
13 SELinux File Contexts Syntax Highlighting Definition
14 ===========================================================================
15
16 This file is part of the KDE's KSyntaxHighlighting framework.
17
18 SPDX-FileCopyrightText: 2018-2020 Nibaldo González S. <[email protected]>
19
20 SPDX-License-Identifier: MIT
21
22 ===========================================================================
23
24 SELinux policy files with definitions of file contexts:
25 - Labeling Policy Files: *.fc
26 - Policy Config. Files: file_contexts, file_contexts_*, file_contexts.local,
27 file_contexts.homedirs, file_contexts.template, homedir_template
28 - SE for Android Policy Config. Files: service_contexts, property_contexts,
29 hwservice_contexts
30 - Policy Build Files: initial_sid_contexts, genfs_contexts, fs_use
31
32 Change log:
33 * Version 7 [30-Sep-2020]: Use include-keywods and other minor changes.
34 * Version 5 [03-Oct-2019]: Replace unnecessary WordDetect rules.
35 * Version 4 [02-Apr-2019]: Remove one indentation.
36 * Version 3 [09-Sep-2018]:
37 - Update itemData's style for the new Solarized color schemes.
38 * Version 2 [28-Aug-2018]:
39 - Some improvements. RegExp and some rules are moved to "selinux.xml".
40 - Add statements keywords that use file contexts.
41 * Version 1 [26-Jan-2018, by Nibaldo González]:
42 - Initial version.
43 -->
44
45 <language name="SELinux File Contexts"
46 version="9"
47 kateversion="5.53"
48 section="Other"
49 extensions="*.fc;file_contexts;file_contexts_*;file_contexts.local;file_contexts.homedirs;file_contexts.template;homedir_template;property_contexts;service_contexts;hwservice_contexts;initial_sid_contexts;genfs_contexts;fs_use"
50 priority="3"
51 mimetype=""
52 author="Nibaldo González ([email protected])"
53 license="MIT">
54
55 <highlighting>
56
57 <list name="statements_fc">
58 <include>statements_fc##SELinux Policy</include>
59 </list>
60 <list name="refpolicy_keywords">
61 <include>refpolicy_keywords##SELinux Policy</include>
62 </list>
63
64 <contexts>
65
66 <context name="_normal" attribute="Normal Text" lineEndContext="#stay">
67 <IncludeRules context="_m4_preprocessor##SELinux Policy"/>
68 <IncludeRules context="_find_comments##SELinux Policy"/>
69 <RegExpr context="#stay" attribute="File Type" String="(?:\s|^)\-[bcdpls\-](?=\s|$)"/>
70
71 <DetectChar context="_path_content" attribute="Path" char="/"/>
72 <DetectChar context="_quoted" attribute="Text Quoted" char="&quot;"/>
73
74 <!-- Content Quoted (M4).
75 NOTE: The default quotes (`text') are highlighted,
76 but another type of quotation mark can be used. -->
77 <IncludeRules context="_m4_string_simple##SELinux Policy"/> <!-- `simple text' -->
78 <IncludeRules context="_m4_quotes##SELinux Policy"/>
79
80 <!-- File Contexts: user:role:type:s0:c0 -->
81 <RegExpr context="_fc_user" attribute="User" String="&startIdentifier;(?=(?:\s*\:\s*&identifier;){2}(?:\s*\:\s*&mlsLevel;(?:\s*\-\s*&mlsLevel;)?)?\b)"/>
82 <StringDetect context="#stay" attribute="Other Keywords" String="&lt;&lt;none&gt;&gt;"/>
83
84 <!-- Java-Language-Style Package Name & other Names, for SE Android (this avoid highlighting keywords) -->
85 <RegExpr context="#stay" attribute="Path" String="\.?[a-zA-Z]\w*(?:(?:\.|::)\w+)+(?=[^\(]|$)" firstNonSpace="true"/>
86
87 <!-- Functions -->
88 <DetectChar context="_parentheses_content" attribute="Normal Text" char="(" beginRegion="ParenthesesBlock"/>
89 <keyword context="#stay" attribute="Refpolicy Keywords" String="refpolicy_keywords"/>
90 <IncludeRules context="_m4_builtin_keywords##SELinux Policy"/>
91 <RegExpr context="#stay" attribute="Function" String="\b[a-zA-Z][\w\-]*(?=\()"/>
92
93 <IncludeRules context="_m4_special_arguments##SELinux Policy"/>
94 <IncludeRules context="_common_special_char##SELinux Policy"/>
95 <IncludeRules context="_line_continue_escape##SELinux Policy"/>
96
97 <!-- Default Variables -->
98 <StringDetect context="_path_content" attribute="Variable" String="HOME_DIR"/>
99 <StringDetect context="_path_content" attribute="Variable" String="HOME_ROOT"/>
100
101 <DetectChar context="_path_content" attribute="Path" char="[" lookAhead="true"/>
102 <Detect2Chars context="_path_content" char="%" char1="{" lookAhead="true"/>
103 <RegExpr context="_path_content" attribute="Path" String="\b[\w\[\]\.@\=\*\-\$%\+!\|&amp;\^~\{\}&lt;&gt;\?\\,]+[/\\\*\?\[\{]" lookAhead="true" firstNonSpace="true"/>
104
105 <DetectChar context="#stay" attribute="Symbol" char="{" beginRegion="Bracket"/>
106 <DetectChar context="#stay" attribute="Symbol" char="}" endRegion="Bracket"/>
107 <AnyChar context="#stay" attribute="Symbol" String=",;~[]"/>
108
109 <!-- Highlight only the statements that contain definition of file contexts -->
110 <keyword context="#stay" attribute="Statements" String="statements_fc"/>
111 <RegExpr context="#stay" String="[a-zA-Z](?:\.?[\w\-]+)*"/>
112 <HlCHex context="#pop" attribute="Number"/>
113 <Int context="#pop" attribute="Number"/>
114 </context>
115
116 <context name="_parentheses_content" attribute="Normal Text" lineEndContext="#stay">
117 <DetectChar context="#pop" attribute="Normal Text" char=")" endRegion="ParenthesesBlock"/>
118 <!-- File Contexts: (user:role:type,s0) -->
119 <RegExpr context="_gen_context_fc_user" attribute="User" String="&startIdentifier;(?:\s*\:\s*&identifier;){2}(?:\s*,\s*&identifier;)*\b" lookAhead="true"/>
120 <IncludeRules context="_normal"/>
121 </context>
122
123 <context name="_path_content" attribute="Path" lineEndContext="#pop">
124 <DetectSpaces context="#pop" lookAhead="true"/>
125 <IncludeRules context="_regex##SELinux Policy"/>
126 <IncludeRules context="_variable"/>
127 </context>
128 <context name="_quoted" attribute="Text Quoted" lineEndContext="#pop">
129 <DetectChar context="#pop" attribute="Text Quoted" char="&quot;"/>
130 <IncludeRules context="_m4_special_arguments##SELinux Policy"/>
131 <IncludeRules context="_other_variable"/>
132 <IncludeRules context="_regex_quoted##SELinux Policy"/>
133 <RegExpr context="#stay" attribute="Text Quoted Open" String="[^\s&quot;\[\(\\](?=\s*$)"/>
134 </context>
135
136 <!-- Variables of "file_contexts", M4 & Refpolicy -->
137 <context name="_variable" attribute="Normal Text" lineEndContext="#stay">
138 <WordDetect context="#stay" attribute="Variable" String="HOME_DIR"/>
139 <WordDetect context="#stay" attribute="Variable" String="HOME_ROOT"/>
140 <StringDetect context="#stay" attribute="Variable" String="USER"/>
141 <StringDetect context="#stay" attribute="Variable" String="ROLE"/>
142 <IncludeRules context="_other_variable"/>
143 </context>
144 <context name="_other_variable" attribute="Normal Text" lineEndContext="#stay">
145 <RegExpr context="#stay" attribute="Variable" String="\%\{[a-zA-Z]\w*\}"/>
146 </context>
147 <context name="_fc_variable" attribute="Path" lineEndContext="#pop">
148 <IncludeRules context="_m4_special_arguments##SELinux Policy"/>
149 <IncludeRules context="_other_variable"/>
150 </context>
151
152 <!-- SELinux Security Contexts -->
153
154 <!-- User -->
155 <context name="_fc_user" attribute="User" lineEndContext="#pop">
156 <DetectChar context="#pop!_fc_role" attribute="Normal Text" char=":"/>
157 </context>
158 <!-- Role -->
159 <context name="_fc_role" attribute="Role" lineEndContext="#pop">
160 <DetectChar context="#pop!_fc_type" attribute="Normal Text" char=":"/>
161 </context>
162 <!-- Type Enforcement -->
163 <context name="_fc_type" attribute="Type Enforcement" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop!_after_fc">
164 <RegExpr context="#pop!_fc_mls" attribute="Type Enforcement" String="\s*&identifier;(?=\s*:\s*&mlsLevel;)"/> <!-- Find MLS/MCS -->
165 <RegExpr context="#pop" attribute="Type Enforcement" String="\s*&identifier;"/>
166 </context>
167
168 <!-- Start MLS/MCS -->
169 <context name="_fc_mls" attribute="MLS/MCS Level" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop!_after_fc">
170 <DetectChar context="#pop!_fc_find_level_range" attribute="Normal Text" char=":"/>
171 <DetectSpaces context="#stay" attribute="Normal Text"/>
172 </context>
173 <context name="_fc_find_level_range" attribute="MLS/MCS Level"
174 lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop!_fc_level_range">
175 <DetectSpaces context="#stay" attribute="Normal Text"/>
176 </context>
177 <!-- MLS/MCS Range (Sensitivity:Category - Sensitivity:Category) -->
178 <!-- Sensitivity -->
179 <context name="_fc_level_range" attribute="MLS/MCS Level" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop!_after_fc">
180 <RegExpr context="#pop!_fc_level_range_cat" attribute="Normal Text" String="\s*:\s*(?=&identifier;)"/> <!-- Find Category -->
181 <RegExpr context="#pop!_fc_level" attribute="Normal Text" String="\s*\-\s*(?=&mlsLevel;)"/> <!-- Find Range -->
182 <IncludeRules context="_default_level"/>
183 </context>
184 <!-- Category -->
185 <context name="_fc_level_range_cat" attribute="MLS/MCS Level" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop!_after_fc">
186 <RegExpr context="#pop!_fc_level" attribute="Normal Text" String="\s*\-\s*(?=&mlsLevel;)"/> <!-- Find Range -->
187 <RegExpr context="#stay" attribute="Normal Text" String="\s*,\s*(?=&simpleIdentifier;)"/>
188 <IncludeRules context="_default_level"/>
189 </context>
190 <!-- MLS/MCS Level (Sensitivity:Category) -->
191 <!-- Sensitivity -->
192 <context name="_fc_level" attribute="MLS/MCS Level" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop!_after_fc">
193 <RegExpr context="#pop!_fc_level_cat" attribute="Normal Text" String="\s*:\s*(?=&identifier;)"/> <!-- Find Category -->
194 <IncludeRules context="_default_level"/>
195 </context>
196 <!-- Category -->
197 <context name="_fc_level_cat" attribute="MLS/MCS Level" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop!_after_fc">
198 <RegExpr context="#stay" attribute="Normal Text" String="\s*,\s*(?=&simpleIdentifier;)"/>
199 <IncludeRules context="_default_level"/>
200 </context>
201
202 <context name="_default_level" attribute="Normal Text" lineEndContext="#pop">
203 <RegExpr context="#stay" attribute="Normal Text" String="\s*\.\s*(?=&charIden;)"/>
204 <DetectChar context="_default_level_arg" attribute="MLS/MCS Level" char="$"/>
205 <DetectChar context="_default_level_var" attribute="MLS/MCS Level" char="%"/>
206 <RegExpr context="#stay" attribute="MLS/MCS Level" String="\w+"/>
207 <DetectChar context="#stay" attribute="MLS/MCS Level" char="-"/>
208 </context>
209 <context name="_default_level_arg" attribute="MLS/MCS Level" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop">
210 <!-- M4 Args. It is not exact -->
211 <Int context="#pop" attribute="MLS/MCS Level"/>
212 <AnyChar context="#pop" attribute="MLS/MCS Level" String="#*@"/>
213 <RegExpr context="#pop" attribute="MLS/MCS Level" String="\{\d+\}"/>
214 </context>
215 <context name="_default_level_var" attribute="MLS/MCS Level" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop">
216 <RegExpr context="#pop" attribute="MLS/MCS Level" String="{[A-Za-z]\w*\}"/>
217 </context>
218
219 <context name="_after_fc" attribute="Normal Text" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop">
220 <RegExpr context="#stay" attribute="Normal Text" String="\s*:\s*\w*|[:\.\w]+"/>
221 </context>
222
223 <!-- Within function "gen_context" (highlight variables and M4 args.) -->
224 <!-- User -->
225 <context name="_gen_context_fc_user" attribute="User" lineEndContext="#pop">
226 <DetectChar context="#pop!_gen_context_role" attribute="Normal Text" char=":"/>
227 <IncludeRules context="_fc_variable"/>
228 </context>
229 <!-- Role -->
230 <context name="_gen_context_role" attribute="Role" lineEndContext="#pop">
231 <DetectChar context="#pop!_before_gen_context_type" attribute="Normal Text" char=":"/>
232 <IncludeRules context="_fc_variable"/>
233 </context>
234 <!-- Type Enforcement -->
235 <context name="_before_gen_context_type" attribute="Type Enforcement"
236 lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop!_gen_context_type">
237 <DetectSpaces context="#stay" attribute="Normal Text"/>
238 </context>
239 <context name="_gen_context_type" attribute="Type Enforcement"
240 lineEndContext="#pop!_fc_find_comma" fallthrough="true" fallthroughContext="#pop!_fc_find_comma">
241 <RegExpr context="#pop!_fc_level_range" attribute="Normal Text" String="\s*:\s*(?=&identifier;)"/> <!-- Find MLS/MCS -->
242 <IncludeRules context="_fc_variable"/>
243 <RegExpr context="#stay" attribute="Type Enforcement" String="[\w\-]+"/>
244 </context>
245 <!-- Comma after file contexts -->
246 <context name="_fc_find_comma" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
247 <DetectChar context="#pop!_fc_after_comma" attribute="Normal Text" char=","/>
248 <RegExpr context="#pop" String="\s*[^,\s]" lookAhead="true"/>
249 <DetectSpaces />
250 </context>
251 <context name="_fc_after_comma" attribute="Normal Text"
252 lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop!_gen_context_level">
253 <DetectSpaces context="#stay"/>
254 </context>
255 <!-- MLS/MCS -->
256 <context name="_gen_context_level" attribute="MLS/MCS Level" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
257 <RegExpr context="#stay" attribute="Normal Text" String="\-\s*(?=&simpleIdentifier;)"/>
258 <IncludeRules context="_fc_variable"/>
259 <RegExpr context="#stay" attribute="MLS/MCS Level" String="\w+"/>
260 <DetectChar context="#stay" attribute="MLS/MCS Level" char="-"/>
261 <AnyChar context="#stay" attribute="Normal Text" String=":.,"/>
262 <DetectSpaces />
263 </context>
264
265 </contexts>
266
267 <itemDatas>
268 <itemData name="Normal Text" defStyleNum="dsNormal" spellChecking="false"/>
269 <itemData name="Text Quoted" defStyleNum="dsString" spellChecking="false"/>
270 <itemData name="Path" defStyleNum="dsNormal" spellChecking="false"/>
271 <itemData name="Variable" defStyleNum="dsVariable" spellChecking="false"/>
272 <itemData name="File Type" defStyleNum="dsKeyword" spellChecking="false"/>
273
274 <itemData name="User" defStyleNum="dsPreprocessor" bold="0" italic="0" underline="0" spellChecking="false"/>
275 <itemData name="Role" defStyleNum="dsInformation" bold="0" italic="0" underline="0" spellChecking="false"/>
276 <itemData name="Type Enforcement" defStyleNum="dsAttribute" bold="0" italic="0" underline="0" spellChecking="false"/>
277 <itemData name="MLS/MCS Level" defStyleNum="dsVerbatimString" bold="0" italic="0" underline="0" spellChecking="false"/>
278
279 <itemData name="Other Keywords" defStyleNum="dsNormal" italic="1" spellChecking="false"/>
280 <itemData name="Statements" defStyleNum="dsKeyword" bold="1" spellChecking="false"/>
281 <itemData name="Refpolicy Keywords" defStyleNum="dsNormal" bold="1" spellChecking="false"/>
282 <itemData name="Function" defStyleNum="dsNormal" bold="1" spellChecking="false"/>
283 <itemData name="Symbol" defStyleNum="dsOperator" spellChecking="false"/>
284 <itemData name="Number" defStyleNum="dsComment" bold="0" italic="0" underline="0" spellChecking="false"/>
285 <itemData name="Text Quoted Open" defStyleNum="dsString" underline="1" spellChecking="false"/>
286 </itemDatas>
287
288 </highlighting>
289
290 <general>
291 <keywords casesensitive="true" additionalDeliminator="&quot;&apos;&#096;" weakDeliminator="*?+.-"/>
292 <comments>
293 <comment name="singleLine" start="#"/>
294 </comments>
295 </general>
296
297 </language>
298 <!-- kate: replace-tabs off; tab-width 3; indent-width 3; remove-trailing-spaces mod; dynamic-word-wrap off; -->