]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/Makefile
fixes and remove debug code
[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
e12e5738
CP
128DISABLEMOD := $(foreach mod,$(shell egrep -v '^[[:blank:]]*\#' $(MOD_DISABLE)),$(subst ./,,$(shell find -iname $(mod).te)))
129ALL_LAYERS := $(shell find $(wildcard policy/modules/*) -maxdepth 0 -type d)
130
131GENERATED_TE := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te.in)))
132GENERATED_IF := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.if.in)))
133GENERATED_FC := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.fc.in)))
134
135DETECTED_MODS := $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te)) $(GENERATED_TE)
0fbe15dc 136ALL_MODULES := $(filter-out $(DISABLEMOD),$(DETECTED_MODS))
b4cd1533 137
b67488e3 138PRE_TE_FILES := $(addprefix $(FLASKDIR)/,security_classes initial_sids access_vectors) $(M4SUPPORT) $(POLDIR)/mls
0fbe15dc
CP
139ALL_INTERFACES := $(ALL_MODULES:.te=.if)
140ALL_TE_FILES := $(ALL_MODULES)
b67488e3 141POST_TE_FILES := $(POLDIR)/users $(POLDIR)/constraints
b4cd1533 142
0fbe15dc 143ALL_FC_FILES := $(ALL_MODULES:.te=.fc)
b4cd1533 144
84eb353c 145POLICY_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 146
3a80ec29 147DOCTOOLS = doc
36e54b81
CP
148XMLDTD = $(DOCTOOLS)/policy.dtd
149HTMLHEAD = $(DOCTOOLS)/header.html
150HTMLFOOT = $(DOCTOOLS)/footer.html
151HTMLCSS = $(DOCTOOLS)/style.css
152HTMLOUT = $(DOCTOOLS)/html
36e54b81 153
b4cd1533
CP
154########################################
155#
156# default action: build policy locally
157#
158default: policy
159
160policy: $(POLVER)
161
44cda51b 162install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
c9a26b3e
CP
163
164load: tmp/load
b4cd1533
CP
165
166########################################
167#
168# Build a binary policy locally
169#
170$(POLVER): policy.conf
b67488e3 171 @echo "Compiling $(NAME) $(POLVER)"
b4cd1533
CP
172ifneq ($(PV),$(KV))
173 @echo
b67488e3 174 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
b4cd1533
CP
175 @echo
176endif
134191be 177 $(QUIET) $(CHECKPOLICY) $^ -o $@
b4cd1533
CP
178
179########################################
180#
181# Install a binary policy
182#
183$(LOADPATH): policy.conf
184 @mkdir -p $(POLICYPATH)
b67488e3 185 @echo "Compiling and installing $(NAME) $(LOADPATH)"
b4cd1533
CP
186ifneq ($(PV),$(KV))
187 @echo
b67488e3 188 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
b4cd1533
CP
189 @echo
190endif
134191be 191 $(QUIET) $(CHECKPOLICY) $^ -o $@
b4cd1533 192
88d14a22
CP
193########################################
194#
195# Load the binary policy
196#
197reload tmp/load: $(LOADPATH) $(FCPATH)
b67488e3 198 @echo "Loading $(NAME) $(LOADPATH)"
88d14a22
CP
199 $(QUIET) $(LOADPOLICY) -q $(LOADPATH)
200 @touch tmp/load
201
b4cd1533
CP
202########################################
203#
204# Construct a monolithic policy.conf
205#
206policy.conf: $(POLICY_SECTIONS)
b67488e3 207 @echo "Creating $(NAME) policy.conf"
84eb353c 208 # checkpolicy can use the #line directives provided by -s for error reporting:
b67488e3 209 $(QUIET) m4 $(M4PARAM) -s $^ > tmp/$@.tmp
b4cd1533 210 $(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
84eb353c 211 # the ordering of these ocontexts matters:
b4cd1533
CP
212 $(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true
213 $(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true
214 $(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true
215
216tmp/pre_te_files.conf: $(PRE_TE_FILES)
217 @test -d tmp || mkdir -p tmp
218 $(QUIET) cat $^ > $@
219
e12e5738 220tmp/generated_definitions.conf: $(ALL_LAYERS) $(ALL_TE_FILES) $(TUNABLES)
84eb353c 221 # per-userdomain templates:
b4cd1533
CP
222 @test -d tmp || mkdir -p tmp
223 $(QUIET) echo "define(\`per_userdomain_templates',\`" > $@
0fbe15dc 224 $(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \
b4cd1533
CP
225 echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$1'")')" \
226 >> $@ ;\
227 done
228 $(QUIET) echo "')" >> $@
84eb353c 229 # define foo.te
0fbe15dc 230 $(QUIET) for i in $(notdir $(ALL_MODULES)); do \
b4cd1533
CP
231 echo "define(\`$$i')" >> $@ ;\
232 done
84eb353c 233 $(QUIET) $(SETTUN) $(TUNABLES) >> $@
b4cd1533 234
3a80ec29 235tmp/all_interfaces.conf: $(ALL_INTERFACES)
b4cd1533 236 @test -d tmp || mkdir -p tmp
3a80ec29 237 $(QUIET) cat $^ > $@
b4cd1533 238
3a80ec29 239tmp/all_te_files.conf: $(ALL_TE_FILES)
b4cd1533 240 @test -d tmp || mkdir -p tmp
3a80ec29 241 $(QUIET) cat $^ > $@
b4cd1533
CP
242
243tmp/post_te_files.conf: $(POST_TE_FILES)
244 @test -d tmp || mkdir -p tmp
245 $(QUIET) cat $^ > $@
246
247# extract attributes and put them first. extract post te stuff
248# like genfscon and put last. portcon, nodecon, and netifcon
249# is delayed since they are generated by m4
f66a1af9
CP
250tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf
251 $(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true
252 $(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf
b4cd1533 253 $(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf
cabfa520
CP
254 $(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true
255 $(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true
b4cd1533 256 $(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
cabfa520
CP
257 $(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \
258 -e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \
259 < tmp/all_te_files.conf > tmp/only_te_rules.conf
b4cd1533 260
f2e4ab3a
CP
261$(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/kernel/corenetwork.if.in
262 $(QUIET) cat $(MODDIR)/kernel/corenetwork.if.in > $@
263 $(QUIET) egrep "^[[:blank:]]*network_(interface|node|port)\(.*\)" $(@:.if=.te).in \
264 | m4 $(M4PARAM) -D monolithic_policy $(M4SUPPORT) $(MODDIR)/kernel/corenetwork.if.m4 - \
265 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
266 $(QUIET) echo "## </module>" >> $@
267
268$(MODDIR)/kernel/corenetwork.te: $(MODDIR)/kernel/corenetwork.te.m4 $(MODDIR)/kernel/corenetwork.te.in
269 $(QUIET) m4 $(M4PARAM) -D monolithic_policy $(M4SUPPORT) $^ \
270 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
271
88d14a22
CP
272########################################
273#
274# Remove the dontaudit rules from the policy.conf
275#
276enableaudit: policy.conf
277 @test -d tmp || mkdir -p tmp
278 @echo "Removing dontaudit rules from policy.conf"
279 $(QUIET) grep -v dontaudit policy.conf > tmp/policy.audit
280 $(QUIET) mv tmp/policy.audit policy.conf
281
6d314fd3
CP
282########################################
283#
284# Construct file_contexts
285#
de96491b 286$(FC): $(M4SUPPORT) $(ALL_FC_FILES)
6d314fd3
CP
287 @test -d tmp || mkdir -p tmp
288 $(QUIET) m4 $(M4PARAM) $^ > $@
289
547283e2
CP
290########################################
291#
292# Install file_contexts
293#
3a80ec29 294$(FCPATH): $(FC) $(USERPATH)/system.users
547283e2
CP
295 @mkdir -p $(CONTEXTPATH)/files
296 $(QUIET) install -m 644 $(FC) $(FCPATH)
297# $(QUIET) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH)
298# $(QUIET) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(TYPE) $(USEPWD)
254bbc7b 299 $(QUIET) $(FCSORT) $(FCPATH) $(FCPATH)
547283e2 300
b4cd1533
CP
301########################################
302#
303# Filesystem labeling
304#
88d14a22 305FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';`
b4cd1533 306
88d14a22
CP
307checklabels: $(FC) $(SETFILES)
308 @if test -z "$(FILESYSTEMS)"; then \
309 echo "No filesystems with extended attributes found!" ;\
310 false ;\
311 fi
b4cd1533
CP
312 $(QUIET) $(SETFILES) -v -n $(FC) $(FILESYSTEMS)
313
88d14a22
CP
314restorelabels: $(FC) $(SETFILES)
315 @if test -z "$(FILESYSTEMS)"; then \
316 echo "No filesystems with extended attributes found!" ;\
317 false ;\
318 fi
b4cd1533
CP
319 $(QUIET) $(SETFILES) -v $(FC) $(FILESYSTEMS)
320
321relabel: $(FC) $(SETFILES)
88d14a22
CP
322 @if test -z "$(FILESYSTEMS)"; then \
323 echo "No filesystems with extended attributes found!" ;\
324 false ;\
325 fi
b4cd1533
CP
326 $(QUIET) $(SETFILES) $(FC) $(FILESYSTEMS)
327
84eb353c
CP
328########################################
329#
330# Create config files
331#
332conf $(MOD_DISABLE) $(TUNABLES): tmp/policy.xml
333 @echo "Creating $(MOD_DISABLE) and $(TUNABLES)"
334 $(QUIET) cd tmp && ../$(GENDOC) -t ../$(TUNABLES) -m ../$(MOD_DISABLE) -x ../tmp/policy.xml
335
6d314fd3
CP
336########################################
337#
338# Documentation generation
339#
340
84eb353c
CP
341# no dependencies here, because we don't want to rebuild
342# this and its dependents every time the dependencies
343# change
16e1cf48 344tmp/policy.xml: $(GENERATED_IF)
88c72f44 345 @echo "Creating $@"
84eb353c 346 @mkdir -p tmp
004db90d
CP
347 $(QUIET) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@
348 $(QUIET) echo '<!DOCTYPE policy SYSTEM "policy.dtd">' >> $@
349 $(QUIET) echo "<policy>" >> $@
44cda51b 350# process this through m4 to eliminate the generated definitions templates.
3c62aa31 351# currently these are only in corenetwork.if
84eb353c 352 $(QUIET) m4 $(ALL_INTERFACES) $(GLOBALTUN) | egrep -h "^##[[:blank:]]" | sed -e 's/^##[[:blank:]]//g' >> $@
88c72f44 353 $(QUIET) echo "</policy>" >> $@
0447352a 354 $(QUIET) if test -x $(XMLLINT) && test -f $(XMLDTD); then \
3a80ec29 355 cp $(XMLDTD) tmp ;\
0447352a 356 $(XMLLINT) --noout --dtdvalid $(XMLDTD) $@ ;\
004db90d 357 fi
6d314fd3 358
c9a26b3e
CP
359########################################
360#
361# Runtime binary policy patching of users
362#
363$(USERPATH)/system.users: $(USER_FILES) tmp/generated_definitions.conf
364 @mkdir -p $(USERPATH)
365 @echo "Installing system.users"
366 @echo "# " > tmp/system.users
367 @echo "# Do not edit this file. " >> tmp/system.users
368 @echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users
369 @echo "# Please edit local.users to make local changes." >> tmp/system.users
370 @echo "#" >> tmp/system.users
371 $(QUIET) m4 $(M4PARAM) tmp/generated_definitions.conf $(USER_FILES) | \
372 egrep -v "^[[:space:]]*($$|#)" >> tmp/system.users
373 $(QUIET) install -m 644 tmp/system.users $@
374
375$(USERPATH)/local.users: local.users
376 @mkdir -p $(USERPATH)
377 @echo "Installing local.users"
378 $(QUIET) install -C -b -m 644 $< $@
379
380########################################
381#
382# Appconfig files
383#
384install-appconfig: $(APPFILES)
385
2926f9c7 386$(CONTEXTPATH)/files/media: $(APPCONF)/media
c9a26b3e
CP
387 mkdir -p $(CONTEXTPATH)/files/
388 install -m 644 $< $@
389
2926f9c7 390$(APPDIR)/default_contexts: $(APPCONF)/default_contexts
c9a26b3e
CP
391 mkdir -p $(APPDIR)
392 install -m 644 $< $@
393
2926f9c7 394$(APPDIR)/removable_context: $(APPCONF)/removable_context
c9a26b3e
CP
395 mkdir -p $(APPDIR)
396 install -m 644 $< $@
397
398$(APPDIR)/customizable_types: policy.conf
399 mkdir -p $(APPDIR)
400 @grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > tmp/customizable_types
401 install -m 644 tmp/customizable_types $@
402
2926f9c7 403$(APPDIR)/default_type: $(APPCONF)/default_type
c9a26b3e
CP
404 mkdir -p $(APPDIR)
405 install -m 644 $< $@
406
2926f9c7 407$(APPDIR)/userhelper_context: $(APPCONF)/userhelper_context
c9a26b3e
CP
408 mkdir -p $(APPDIR)
409 install -m 644 $< $@
410
2926f9c7 411$(APPDIR)/initrc_context: $(APPCONF)/initrc_context
c9a26b3e
CP
412 mkdir -p $(APPDIR)
413 install -m 644 $< $@
414
2926f9c7 415$(APPDIR)/failsafe_context: $(APPCONF)/failsafe_context
c9a26b3e
CP
416 mkdir -p $(APPDIR)
417 install -m 644 $< $@
418
2926f9c7 419$(APPDIR)/dbus_contexts: $(APPCONF)/dbus_contexts
c9a26b3e
CP
420 mkdir -p $(APPDIR)
421 install -m 644 $< $@
422
2926f9c7 423$(APPDIR)/users/root: $(APPCONF)/root_default_contexts
c9a26b3e
CP
424 mkdir -p $(APPDIR)/users
425 install -m 644 $< $@
426
b4cd1533
CP
427clean:
428 rm -fR tmp
6d314fd3 429 rm -f policy.xml
b4cd1533
CP
430 rm -f policy.conf
431 rm -f policy.$(PV)
432 rm -f $(FC)
433
0fbe15dc 434bare: clean
254bbc7b
CP
435 rm -f $(SUPPORT)/*.pyc
436 rm -f $(FCSORT)
0fbe15dc
CP
437 rm -f $(MOD_DISABLE)
438 rm -f $(TUNABLES)
e12e5738
CP
439ifneq ($(GENERATED_TE),)
440 rm -f $(GENERATED_TE)
441endif
442ifneq ($(GENERATED_IF),)
443 rm -f $(GENERATED_IF)
444endif
445ifneq ($(GENERATED_FC),)
446 rm -f $(GENERATED_FC)
447endif
0fbe15dc
CP
448
449.PHONY: default policy install reload enableaudit checklabels restorelabels relabel conf clean bare