]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/Makefile
make corenetwork generation explicit, rather then on-the-fly
[people/stevee/selinux-policy.git] / refpolicy / Makefile
CommitLineData
88d14a22
CP
1#
2# Makefile for the security policy.
3#
4# Targets:
5#
6# install - compile and install the policy configuration, and context files.
7# load - compile, install, and load the policy configuration.
8# reload - compile, install, and load/reload the policy configuration.
9# relabel - relabel filesystems based on the file contexts configuration.
10# checklabels - check filesystems against the file context configuration
11# restorelabels - check filesystems against the file context configuration
12# and restore the label of files with incorrect labels
13# policy - compile the policy configuration locally for testing/development.
14#
15# The default target is 'policy'.
16#
17
b4cd1533
CP
18########################################
19#
20# Configurable portions of the Makefile
21#
22
b67488e3
CP
23# Override default policy version
24OUTPUT_POLICY = 18
134191be 25
b67488e3
CP
26# Policy Type
27# strict, targeted, strict-mls, targeted-mls
28# strict and strict-mls are currently supported.
29TYPE = strict
b4cd1533 30
b67488e3
CP
31# If set, this will be used as the policy
32# name. Otherwise the policy type will be
33# used for the name.
34NAME =
35
36# Build monolithic policy. Putting n here
37# will build a loadable module policy.
38# Only monolithic policies are currently supported.
39MONOLITHIC=y
b4cd1533
CP
40
41# Uncomment this to disable command echoing
42#QUIET:=@
43
44########################################
45#
b67488e3 46# NO OPTIONS BELOW HERE
b4cd1533
CP
47#
48
49# executable paths
50PREFIX := /usr
51BINDIR := $(PREFIX)/bin
52SBINDIR := $(PREFIX)/sbin
53CHECKPOLICY := $(BINDIR)/checkpolicy
547283e2 54LOADPOLICY := $(SBINDIR)/load_policy
b4cd1533 55SETFILES := $(SBINDIR)/setfiles
0447352a 56
3a80ec29
CP
57SUPPORT := support
58GENDOC := $(SUPPORT)/sedoctool.py
254bbc7b 59FCSORT := $(SUPPORT)/fc_sort
84eb353c 60SETTUN := $(SUPPORT)/set_tunables
3a80ec29 61
004db90d 62XMLLINT := $(BINDIR)/xmllint
b4cd1533 63
134191be 64# enable MLS if requested.
b67488e3 65ifneq ($(findstring mls,$(TYPE)),)
134191be
CP
66 override M4PARAM += -D enable_mls
67 CHECKPOLICY += -M
68endif
69
b67488e3
CP
70# compile targeted policy if requested.
71ifneq ($(findstring targeted,$(TYPE)),)
72 override M4PARAM += -D targeted_policy
73endif
74
75ifeq ($(MONOLITHIC),y)
76 override M4PARAM += -D monolithic_policy
77endif
78
79ifneq ($(OUTPUT_POLICY),)
80 CHECKPOLICY += -c $(OUTPUT_POLICY)
81endif
82
83ifeq ($(NAME),)
84 NAME := $(TYPE)
134191be
CP
85endif
86
b4cd1533 87# determine the policy version and current kernel version if possible
134191be 88PV := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ')
b4cd1533
CP
89KV := $(shell cat /selinux/policyvers)
90
91# dont print version warnings if we are unable to determine
92# the currently running kernel's policy version
93ifeq ($(KV),)
134191be 94 KV := $(PV)
b4cd1533
CP
95endif
96
97FC := file_contexts
98POLVER := policy.$(PV)
b4cd1533
CP
99
100# install paths
101TOPDIR = $(DESTDIR)/etc/selinux
b67488e3 102INSTALLDIR = $(TOPDIR)/$(NAME)
b4cd1533
CP
103POLICYPATH = $(INSTALLDIR)/policy
104SRCPATH = $(INSTALLDIR)/src
105USERPATH = $(INSTALLDIR)/users
106CONTEXTPATH = $(INSTALLDIR)/contexts
107LOADPATH = $(POLICYPATH)/$(POLVER)
108FCPATH = $(CONTEXTPATH)/files/file_contexts
109HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
110
b67488e3
CP
111POLDIR = policy
112MODDIR = $(POLDIR)/modules
113
114BASE_MODULE = $(MODDIR)/kernel
115FLASKDIR = $(POLDIR)/flask
09693356 116APPCONF = config/appconfig
0350b1dc 117M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt)
b4cd1533 118
84eb353c 119GLOBALTUN := $(POLDIR)/global_tunables
0350b1dc 120MOD_DISABLE := $(POLDIR)/modules.conf
84eb353c 121TUNABLES := $(POLDIR)/tunables.conf
0fbe15dc 122
c9a26b3e
CP
123APPDIR := $(CONTEXTPATH)
124APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts customizable_types) $(CONTEXTPATH)/files/media
2926f9c7 125CONTEXTFILES += $(wildcard $(APPCONF)/*_context*) $(APPCONF)/media
b67488e3 126USER_FILES := $(POLDIR)/users
c9a26b3e 127
0fbe15dc 128DISABLEMOD := $(foreach mod,$(shell egrep -v '^[[:blank:]]*\#' $(MOD_DISABLE)),$(shell find -iname $(mod).te))
b67488e3
CP
129DETECTED_DIRS := $(shell find $(wildcard policy/modules/*) -maxdepth 0 -type d)
130ALL_LAYERS := $(filter-out CVS,$(DETECTED_DIRS))
0fbe15dc 131DETECTED_MODS := $(foreach dir,$(ALL_LAYERS),$(wildcard ./$(dir)/*.te))
f2e4ab3a
CP
132GENERATED_MOD := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard ./$(dir)/*.te.in)))
133DETECTED_MODS += $(GENERATED_MOD)
0fbe15dc 134ALL_MODULES := $(filter-out $(DISABLEMOD),$(DETECTED_MODS))
b4cd1533 135
b67488e3 136PRE_TE_FILES := $(addprefix $(FLASKDIR)/,security_classes initial_sids access_vectors) $(M4SUPPORT) $(POLDIR)/mls
0fbe15dc
CP
137ALL_INTERFACES := $(ALL_MODULES:.te=.if)
138ALL_TE_FILES := $(ALL_MODULES)
b67488e3 139POST_TE_FILES := $(POLDIR)/users $(POLDIR)/constraints
b4cd1533 140
0fbe15dc 141ALL_FC_FILES := $(ALL_MODULES:.te=.fc)
b4cd1533 142
84eb353c 143POLICY_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attrs_types.conf $(GLOBALTUN) tmp/only_te_rules.conf tmp/all_post.conf
b4cd1533 144
3a80ec29 145DOCTOOLS = doc
36e54b81
CP
146XMLDTD = $(DOCTOOLS)/policy.dtd
147HTMLHEAD = $(DOCTOOLS)/header.html
148HTMLFOOT = $(DOCTOOLS)/footer.html
149HTMLCSS = $(DOCTOOLS)/style.css
150HTMLOUT = $(DOCTOOLS)/html
36e54b81 151
b4cd1533
CP
152########################################
153#
154# default action: build policy locally
155#
156default: policy
157
158policy: $(POLVER)
159
44cda51b 160install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
c9a26b3e
CP
161
162load: tmp/load
b4cd1533
CP
163
164########################################
165#
166# Build a binary policy locally
167#
168$(POLVER): policy.conf
b67488e3 169 @echo "Compiling $(NAME) $(POLVER)"
b4cd1533
CP
170ifneq ($(PV),$(KV))
171 @echo
b67488e3 172 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
b4cd1533
CP
173 @echo
174endif
134191be 175 $(QUIET) $(CHECKPOLICY) $^ -o $@
b4cd1533
CP
176
177########################################
178#
179# Install a binary policy
180#
181$(LOADPATH): policy.conf
182 @mkdir -p $(POLICYPATH)
b67488e3 183 @echo "Compiling and installing $(NAME) $(LOADPATH)"
b4cd1533
CP
184ifneq ($(PV),$(KV))
185 @echo
b67488e3 186 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
b4cd1533
CP
187 @echo
188endif
134191be 189 $(QUIET) $(CHECKPOLICY) $^ -o $@
b4cd1533 190
88d14a22
CP
191########################################
192#
193# Load the binary policy
194#
195reload tmp/load: $(LOADPATH) $(FCPATH)
b67488e3 196 @echo "Loading $(NAME) $(LOADPATH)"
88d14a22
CP
197 $(QUIET) $(LOADPOLICY) -q $(LOADPATH)
198 @touch tmp/load
199
b4cd1533
CP
200########################################
201#
202# Construct a monolithic policy.conf
203#
204policy.conf: $(POLICY_SECTIONS)
b67488e3 205 @echo "Creating $(NAME) policy.conf"
84eb353c 206 # checkpolicy can use the #line directives provided by -s for error reporting:
b67488e3 207 $(QUIET) m4 $(M4PARAM) -s $^ > tmp/$@.tmp
b4cd1533 208 $(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
84eb353c 209 # the ordering of these ocontexts matters:
b4cd1533
CP
210 $(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true
211 $(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true
212 $(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true
213
214tmp/pre_te_files.conf: $(PRE_TE_FILES)
215 @test -d tmp || mkdir -p tmp
216 $(QUIET) cat $^ > $@
217
84eb353c
CP
218tmp/generated_definitions.conf: $(ALL_LAYERS) $(ALL_TE_FILES) $(BASE_MODULE)/corenetwork.if $(BASE_MODULE)/corenetwork.te $(TUNABLES)
219 # per-userdomain templates:
b4cd1533
CP
220 @test -d tmp || mkdir -p tmp
221 $(QUIET) echo "define(\`per_userdomain_templates',\`" > $@
0fbe15dc 222 $(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \
b4cd1533
CP
223 echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$1'")')" \
224 >> $@ ;\
225 done
226 $(QUIET) echo "')" >> $@
84eb353c 227 # define foo.te
0fbe15dc 228 $(QUIET) for i in $(notdir $(ALL_MODULES)); do \
b4cd1533
CP
229 echo "define(\`$$i')" >> $@ ;\
230 done
84eb353c 231 $(QUIET) $(SETTUN) $(TUNABLES) >> $@
b4cd1533 232
3a80ec29 233tmp/all_interfaces.conf: $(ALL_INTERFACES)
b4cd1533 234 @test -d tmp || mkdir -p tmp
3a80ec29 235 $(QUIET) cat $^ > $@
b4cd1533 236
3a80ec29 237tmp/all_te_files.conf: $(ALL_TE_FILES)
b4cd1533 238 @test -d tmp || mkdir -p tmp
3a80ec29 239 $(QUIET) cat $^ > $@
b4cd1533
CP
240
241tmp/post_te_files.conf: $(POST_TE_FILES)
242 @test -d tmp || mkdir -p tmp
243 $(QUIET) cat $^ > $@
244
245# extract attributes and put them first. extract post te stuff
246# like genfscon and put last. portcon, nodecon, and netifcon
247# is delayed since they are generated by m4
f66a1af9
CP
248tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf
249 $(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true
250 $(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf
b4cd1533 251 $(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf
cabfa520
CP
252 $(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true
253 $(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true
b4cd1533 254 $(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
cabfa520
CP
255 $(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \
256 -e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \
257 < tmp/all_te_files.conf > tmp/only_te_rules.conf
b4cd1533 258
f2e4ab3a
CP
259$(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/kernel/corenetwork.if.in
260 $(QUIET) cat $(MODDIR)/kernel/corenetwork.if.in > $@
261 $(QUIET) egrep "^[[:blank:]]*network_(interface|node|port)\(.*\)" $(@:.if=.te).in \
262 | m4 $(M4PARAM) -D monolithic_policy $(M4SUPPORT) $(MODDIR)/kernel/corenetwork.if.m4 - \
263 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
264 $(QUIET) echo "## </module>" >> $@
265
266$(MODDIR)/kernel/corenetwork.te: $(MODDIR)/kernel/corenetwork.te.m4 $(MODDIR)/kernel/corenetwork.te.in
267 $(QUIET) m4 $(M4PARAM) -D monolithic_policy $(M4SUPPORT) $^ \
268 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
269
88d14a22
CP
270########################################
271#
272# Remove the dontaudit rules from the policy.conf
273#
274enableaudit: policy.conf
275 @test -d tmp || mkdir -p tmp
276 @echo "Removing dontaudit rules from policy.conf"
277 $(QUIET) grep -v dontaudit policy.conf > tmp/policy.audit
278 $(QUIET) mv tmp/policy.audit policy.conf
279
6d314fd3
CP
280########################################
281#
282# Construct file_contexts
283#
de96491b 284$(FC): $(M4SUPPORT) $(ALL_FC_FILES)
6d314fd3
CP
285 @test -d tmp || mkdir -p tmp
286 $(QUIET) m4 $(M4PARAM) $^ > $@
287
547283e2
CP
288########################################
289#
290# Install file_contexts
291#
3a80ec29 292$(FCPATH): $(FC) $(USERPATH)/system.users
547283e2
CP
293 @mkdir -p $(CONTEXTPATH)/files
294 $(QUIET) install -m 644 $(FC) $(FCPATH)
295# $(QUIET) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH)
296# $(QUIET) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(TYPE) $(USEPWD)
254bbc7b 297 $(QUIET) $(FCSORT) $(FCPATH) $(FCPATH)
547283e2 298
b4cd1533
CP
299########################################
300#
301# Filesystem labeling
302#
88d14a22 303FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';`
b4cd1533 304
88d14a22
CP
305checklabels: $(FC) $(SETFILES)
306 @if test -z "$(FILESYSTEMS)"; then \
307 echo "No filesystems with extended attributes found!" ;\
308 false ;\
309 fi
b4cd1533
CP
310 $(QUIET) $(SETFILES) -v -n $(FC) $(FILESYSTEMS)
311
88d14a22
CP
312restorelabels: $(FC) $(SETFILES)
313 @if test -z "$(FILESYSTEMS)"; then \
314 echo "No filesystems with extended attributes found!" ;\
315 false ;\
316 fi
b4cd1533
CP
317 $(QUIET) $(SETFILES) -v $(FC) $(FILESYSTEMS)
318
319relabel: $(FC) $(SETFILES)
88d14a22
CP
320 @if test -z "$(FILESYSTEMS)"; then \
321 echo "No filesystems with extended attributes found!" ;\
322 false ;\
323 fi
b4cd1533
CP
324 $(QUIET) $(SETFILES) $(FC) $(FILESYSTEMS)
325
84eb353c
CP
326########################################
327#
328# Create config files
329#
330conf $(MOD_DISABLE) $(TUNABLES): tmp/policy.xml
331 @echo "Creating $(MOD_DISABLE) and $(TUNABLES)"
332 $(QUIET) cd tmp && ../$(GENDOC) -t ../$(TUNABLES) -m ../$(MOD_DISABLE) -x ../tmp/policy.xml
333
6d314fd3
CP
334########################################
335#
336# Documentation generation
337#
338
84eb353c
CP
339# no dependencies here, because we don't want to rebuild
340# this and its dependents every time the dependencies
341# change
342tmp/policy.xml:
88c72f44 343 @echo "Creating $@"
84eb353c 344 @mkdir -p tmp
004db90d
CP
345 $(QUIET) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@
346 $(QUIET) echo '<!DOCTYPE policy SYSTEM "policy.dtd">' >> $@
347 $(QUIET) echo "<policy>" >> $@
44cda51b 348# process this through m4 to eliminate the generated definitions templates.
3c62aa31 349# currently these are only in corenetwork.if
84eb353c 350 $(QUIET) m4 $(ALL_INTERFACES) $(GLOBALTUN) | egrep -h "^##[[:blank:]]" | sed -e 's/^##[[:blank:]]//g' >> $@
88c72f44 351 $(QUIET) echo "</policy>" >> $@
0447352a 352 $(QUIET) if test -x $(XMLLINT) && test -f $(XMLDTD); then \
3a80ec29 353 cp $(XMLDTD) tmp ;\
0447352a 354 $(XMLLINT) --noout --dtdvalid $(XMLDTD) $@ ;\
004db90d 355 fi
6d314fd3 356
c9a26b3e
CP
357########################################
358#
359# Runtime binary policy patching of users
360#
361$(USERPATH)/system.users: $(USER_FILES) tmp/generated_definitions.conf
362 @mkdir -p $(USERPATH)
363 @echo "Installing system.users"
364 @echo "# " > tmp/system.users
365 @echo "# Do not edit this file. " >> tmp/system.users
366 @echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users
367 @echo "# Please edit local.users to make local changes." >> tmp/system.users
368 @echo "#" >> tmp/system.users
369 $(QUIET) m4 $(M4PARAM) tmp/generated_definitions.conf $(USER_FILES) | \
370 egrep -v "^[[:space:]]*($$|#)" >> tmp/system.users
371 $(QUIET) install -m 644 tmp/system.users $@
372
373$(USERPATH)/local.users: local.users
374 @mkdir -p $(USERPATH)
375 @echo "Installing local.users"
376 $(QUIET) install -C -b -m 644 $< $@
377
378########################################
379#
380# Appconfig files
381#
382install-appconfig: $(APPFILES)
383
2926f9c7 384$(CONTEXTPATH)/files/media: $(APPCONF)/media
c9a26b3e
CP
385 mkdir -p $(CONTEXTPATH)/files/
386 install -m 644 $< $@
387
2926f9c7 388$(APPDIR)/default_contexts: $(APPCONF)/default_contexts
c9a26b3e
CP
389 mkdir -p $(APPDIR)
390 install -m 644 $< $@
391
2926f9c7 392$(APPDIR)/removable_context: $(APPCONF)/removable_context
c9a26b3e
CP
393 mkdir -p $(APPDIR)
394 install -m 644 $< $@
395
396$(APPDIR)/customizable_types: policy.conf
397 mkdir -p $(APPDIR)
398 @grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > tmp/customizable_types
399 install -m 644 tmp/customizable_types $@
400
2926f9c7 401$(APPDIR)/default_type: $(APPCONF)/default_type
c9a26b3e
CP
402 mkdir -p $(APPDIR)
403 install -m 644 $< $@
404
2926f9c7 405$(APPDIR)/userhelper_context: $(APPCONF)/userhelper_context
c9a26b3e
CP
406 mkdir -p $(APPDIR)
407 install -m 644 $< $@
408
2926f9c7 409$(APPDIR)/initrc_context: $(APPCONF)/initrc_context
c9a26b3e
CP
410 mkdir -p $(APPDIR)
411 install -m 644 $< $@
412
2926f9c7 413$(APPDIR)/failsafe_context: $(APPCONF)/failsafe_context
c9a26b3e
CP
414 mkdir -p $(APPDIR)
415 install -m 644 $< $@
416
2926f9c7 417$(APPDIR)/dbus_contexts: $(APPCONF)/dbus_contexts
c9a26b3e
CP
418 mkdir -p $(APPDIR)
419 install -m 644 $< $@
420
2926f9c7 421$(APPDIR)/users/root: $(APPCONF)/root_default_contexts
c9a26b3e
CP
422 mkdir -p $(APPDIR)/users
423 install -m 644 $< $@
424
b4cd1533
CP
425clean:
426 rm -fR tmp
6d314fd3 427 rm -f policy.xml
b4cd1533
CP
428 rm -f policy.conf
429 rm -f policy.$(PV)
430 rm -f $(FC)
431
0fbe15dc 432bare: clean
254bbc7b
CP
433 rm -f $(SUPPORT)/*.pyc
434 rm -f $(FCSORT)
0fbe15dc
CP
435 rm -f $(MOD_DISABLE)
436 rm -f $(TUNABLES)
437
438.PHONY: default policy install reload enableaudit checklabels restorelabels relabel conf clean bare