]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/Makefile
credit dan for patches
[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#
b4cd1533 17#
8e0ef1f9 18# Please see build.conf for policy build options.
b4cd1533
CP
19#
20
b4cd1533
CP
21########################################
22#
b67488e3 23# NO OPTIONS BELOW HERE
b4cd1533
CP
24#
25
8e0ef1f9
CP
26include build.conf
27
b4cd1533
CP
28# executable paths
29PREFIX := /usr
30BINDIR := $(PREFIX)/bin
31SBINDIR := $(PREFIX)/sbin
40a1f3db 32CHECKPOLICY := $(BINDIR)/checkpolicy
fb0a3a98 33CHECKMODULE := $(BINDIR)/checkmodule
c767b14c 34SEMODULE := $(SBINDIR)/semodule
fb0a3a98 35SEMOD_PKG := $(BINDIR)/semodule_package
547283e2 36LOADPOLICY := $(SBINDIR)/load_policy
b4cd1533 37SETFILES := $(SBINDIR)/setfiles
1beba1c6 38GENHOMEDIRCON := $(SBINDIR)/genhomedircon
fb0a3a98 39XMLLINT := $(BINDIR)/xmllint
8df65f13 40SECHECK := $(BINDIR)/sechecker
0447352a 41
c7b41e95
CP
42CFLAGS := -Wall
43
fb0a3a98 44# policy source layout
c04f2abe
CP
45POLDIR := policy
46MODDIR := $(POLDIR)/modules
47FLASKDIR := $(POLDIR)/flask
48SECCLASS := $(FLASKDIR)/security_classes
49ISIDS := $(FLASKDIR)/initial_sids
50AVS := $(FLASKDIR)/access_vectors
fb0a3a98
CP
51
52# policy building support tools
3a80ec29 53SUPPORT := support
95db4228 54GENXML := $(SUPPORT)/segenxml.py
3a80ec29 55GENDOC := $(SUPPORT)/sedoctool.py
c04f2abe 56GENPERM := $(SUPPORT)/genclassperms.py
254bbc7b 57FCSORT := $(SUPPORT)/fc_sort
84eb353c 58SETTUN := $(SUPPORT)/set_tunables
3a80ec29 59
fb0a3a98
CP
60# documentation paths
61DOCS = doc
62POLXML = $(DOCS)/policy.xml
63XMLDTD = $(DOCS)/policy.dtd
64LAYERXML = metadata.xml
65HTMLDIR = $(DOCS)/html
66DOCTEMPLATE = $(DOCS)/templates
67
68# config file paths
69GLOBALTUN := $(POLDIR)/global_tunables
4f9f30c8 70GLOBALBOOL := $(POLDIR)/global_booleans
fb0a3a98
CP
71MOD_CONF := $(POLDIR)/modules.conf
72TUNABLES := $(POLDIR)/tunables.conf
4f9f30c8 73BOOLEANS := $(POLDIR)/booleans.conf
fb0a3a98
CP
74
75# install paths
76TOPDIR = $(DESTDIR)/etc/selinux
77INSTALLDIR = $(TOPDIR)/$(NAME)
78SRCPATH = $(INSTALLDIR)/src
79USERPATH = $(INSTALLDIR)/users
80CONTEXTPATH = $(INSTALLDIR)/contexts
c767b14c
CP
81MODPKGDIR = $(DESTDIR)/usr/share/selinux/$(NAME)
82
83# compile strict policy if requested.
84ifneq ($(findstring strict,$(TYPE)),)
85 override M4PARAM += -D strict_policy
86endif
87
88# compile targeted policy if requested.
89ifneq ($(findstring targeted,$(TYPE)),)
90 override M4PARAM += -D targeted_policy
91endif
b4cd1533 92
134191be 93# enable MLS if requested.
a0824843 94ifneq ($(findstring -mls,$(TYPE)),)
134191be 95 override M4PARAM += -D enable_mls
c767b14c
CP
96 override CHECKPOLICY += -M
97 override CHECKMODULE += -M
134191be
CP
98endif
99
a0824843
CP
100# enable MLS if MCS requested.
101ifneq ($(findstring -mcs,$(TYPE)),)
102 override M4PARAM += -D enable_mcs
c767b14c
CP
103 override CHECKPOLICY += -M
104 override CHECKMODULE += -M
b67488e3
CP
105endif
106
25a0c61f
CP
107# enable distribution-specific policy
108ifneq ($(DISTRO),)
109 override M4PARAM += -D distro_$(DISTRO)
110endif
111
b67488e3 112ifneq ($(OUTPUT_POLICY),)
c767b14c 113 override CHECKPOLICY += -c $(OUTPUT_POLICY)
b67488e3
CP
114endif
115
116ifeq ($(NAME),)
117 NAME := $(TYPE)
134191be
CP
118endif
119
142e9f40
CP
120ifeq ($(DIRECT_INITRC),y)
121 override M4PARAM += -D direct_sysadm_daemon
122endif
123
ee7f66b0
CP
124override M4PARAM += -D hide_broken_symptoms
125
b4cd1533 126# determine the policy version and current kernel version if possible
134191be 127PV := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ')
b4cd1533
CP
128KV := $(shell cat /selinux/policyvers)
129
130# dont print version warnings if we are unable to determine
131# the currently running kernel's policy version
132ifeq ($(KV),)
134191be 133 KV := $(PV)
b4cd1533
CP
134endif
135
fb0a3a98 136M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt)
0fbe15dc 137
c0e4fe2c 138APPCONF := config/appconfig-$(TYPE)
c9a26b3e 139APPDIR := $(CONTEXTPATH)
c767b14c 140APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts) $(CONTEXTPATH)/files/media
2926f9c7 141CONTEXTFILES += $(wildcard $(APPCONF)/*_context*) $(APPCONF)/media
bdb2fac0 142USER_FILES := $(POLDIR)/users
c9a26b3e 143
57869a68 144ALL_LAYERS := $(filter-out $(MODDIR)/CVS,$(shell find $(wildcard $(MODDIR)/*) -maxdepth 0 -type d))
e12e5738
CP
145
146GENERATED_TE := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te.in)))
147GENERATED_IF := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.if.in)))
148GENERATED_FC := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.fc.in)))
149
8ae194f6
CP
150# sort here since it removes duplicates, which can happen
151# when a generated file is already generated
152DETECTED_MODS := $(sort $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te)) $(GENERATED_TE))
19db6ba5 153
fb0a3a98 154# modules.conf setting for base module
e8b3e30a 155MODBASE := base
fb0a3a98
CP
156
157# modules.conf setting for module
e8b3e30a 158MODMOD := module
fb0a3a98
CP
159
160# extract settings from modules.conf
c767b14c
CP
161BASE_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODBASE)") print $$1 }' $(MOD_CONF) 2> /dev/null))
162MOD_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODMOD)") print $$1 }' $(MOD_CONF) 2> /dev/null))
712566ee 163
b4cd1533
CP
164########################################
165#
fb0a3a98 166# Load appropriate rules
b4cd1533 167#
b4cd1533 168
fb0a3a98
CP
169ifeq ($(MONOLITHIC),y)
170 include Rules.monolithic
171else
172 include Rules.modular
b4cd1533 173endif
b4cd1533 174
88d14a22
CP
175########################################
176#
fb0a3a98 177# Generated files
b4cd1533 178#
f2e4ab3a 179$(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/kernel/corenetwork.if.in
61bbe531
CP
180 @echo "#" > $@
181 @echo "# This is a generated file! Instead of modifying this file, the" >> $@
182 @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
183 @echo "#" >> $@
184 $(QUIET) cat $(MODDIR)/kernel/corenetwork.if.in >> $@
f2e4ab3a 185 $(QUIET) egrep "^[[:blank:]]*network_(interface|node|port)\(.*\)" $(@:.if=.te).in \
cf6141a7 186 | m4 -D self_contained_policy $(M4PARAM) $(MODDIR)/kernel/corenetwork.if.m4 - \
f2e4ab3a 187 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
f2e4ab3a
CP
188
189$(MODDIR)/kernel/corenetwork.te: $(MODDIR)/kernel/corenetwork.te.m4 $(MODDIR)/kernel/corenetwork.te.in
61bbe531
CP
190 @echo "#" > $@
191 @echo "# This is a generated file! Instead of modifying this file, the" >> $@
192 @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
193 @echo "#" >> $@
cf6141a7 194 $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ \
61bbe531 195 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
f2e4ab3a 196
84eb353c
CP
197########################################
198#
199# Create config files
200#
4f9f30c8 201conf: $(MOD_CONF) $(BOOLEANS) $(GENERATED_TE) $(GENERATED_IF) $(GENERATED_FC)
d2d6c8ce 202
4f9f30c8
CP
203$(MOD_CONF) $(BOOLEANS): $(POLXML)
204 @echo "Updating $(MOD_CONF) and $(BOOLEANS)"
205 $(QUIET) cd $(DOCS) && ../$(GENDOC) -t ../$(BOOLEANS) -m ../$(MOD_CONF) -x ../$(POLXML)
84eb353c 206
6d314fd3
CP
207########################################
208#
209# Documentation generation
210#
211
d2d6c8ce 212# minimal dependencies here, because we don't want to rebuild
84eb353c 213# this and its dependents every time the dependencies
19db6ba5
CP
214# change. Also use all .if files here, rather then just the
215# enabled modules.
d233bfce 216$(POLXML): $(DETECTED_MODS:.te=.if) $(foreach dir,$(ALL_LAYERS),$(dir)/$(LAYERXML))
88c72f44 217 @echo "Creating $@"
84eb353c 218 @mkdir -p tmp
004db90d 219 $(QUIET) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@
95db4228 220 $(QUIET) echo '<!DOCTYPE policy SYSTEM "$(notdir $(XMLDTD))">' >> $@
4f9f30c8 221 $(QUIET) $(GENXML) -w -m $(LAYERXML) -t $(GLOBALTUN) -b $(GLOBALBOOL) $(ALL_LAYERS) >> $@
0447352a
CP
222 $(QUIET) if test -x $(XMLLINT) && test -f $(XMLDTD); then \
223 $(XMLLINT) --noout --dtdvalid $(XMLDTD) $@ ;\
004db90d 224 fi
6d314fd3 225
12b559a4 226html: $(POLXML)
20030ef5 227 @mkdir -p $(HTMLDIR)
12b559a4 228 $(QUIET) cd $(DOCS) && ../$(GENDOC) -d ../$(HTMLDIR) -T ../$(DOCTEMPLATE) -x ../$(POLXML)
20030ef5
CP
229 $(QUIET) cp $(DOCTEMPLATE)/*.css $(HTMLDIR)
230
c9a26b3e
CP
231########################################
232#
233# Runtime binary policy patching of users
234#
1fb83a76 235$(USERPATH)/system.users: $(M4SUPPORT) tmp/generated_definitions.conf $(USER_FILES)
c9a26b3e
CP
236 @mkdir -p $(USERPATH)
237 @echo "Installing system.users"
238 @echo "# " > tmp/system.users
239 @echo "# Do not edit this file. " >> tmp/system.users
240 @echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users
241 @echo "# Please edit local.users to make local changes." >> tmp/system.users
242 @echo "#" >> tmp/system.users
1fb83a76 243 $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ | \
fb2817da
CP
244 egrep -v "^[[:blank:]]*($$|#)" | \
245 sed -r -e 's/^[[:blank:]]+//' >> tmp/system.users
c9a26b3e
CP
246 $(QUIET) install -m 644 tmp/system.users $@
247
1beba1c6 248$(USERPATH)/local.users: config/local.users
c9a26b3e
CP
249 @mkdir -p $(USERPATH)
250 @echo "Installing local.users"
c7b41e95 251 $(QUIET) install -b -m 644 $< $@
c9a26b3e
CP
252
253########################################
254#
255# Appconfig files
256#
257install-appconfig: $(APPFILES)
258
4f9f30c8 259$(INSTALLDIR)/booleans: $(BOOLEANS)
1beba1c6 260 @mkdir -p $(INSTALLDIR)
4f9f30c8 261 $(QUIET) egrep '^[[:blank:]]*[[:alpha:]]' $(BOOLEANS) \
1beba1c6
CP
262 | sed -e 's/false/0/g' -e 's/true/1/g' > tmp/booleans
263 $(QUIET) install -m 644 tmp/booleans $@
264
2926f9c7 265$(CONTEXTPATH)/files/media: $(APPCONF)/media
1beba1c6
CP
266 @mkdir -p $(CONTEXTPATH)/files/
267 $(QUIET) install -m 644 $< $@
c9a26b3e 268
2926f9c7 269$(APPDIR)/default_contexts: $(APPCONF)/default_contexts
1beba1c6
CP
270 @mkdir -p $(APPDIR)
271 $(QUIET) install -m 644 $< $@
c9a26b3e 272
2926f9c7 273$(APPDIR)/removable_context: $(APPCONF)/removable_context
1beba1c6
CP
274 @mkdir -p $(APPDIR)
275 $(QUIET) install -m 644 $< $@
c9a26b3e
CP
276
277$(APPDIR)/customizable_types: policy.conf
1beba1c6
CP
278 @mkdir -p $(APPDIR)
279 $(QUIET) grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > tmp/customizable_types
280 $(QUIET) install -m 644 tmp/customizable_types $@
c9a26b3e 281
2926f9c7 282$(APPDIR)/default_type: $(APPCONF)/default_type
1beba1c6
CP
283 @mkdir -p $(APPDIR)
284 $(QUIET) install -m 644 $< $@
c9a26b3e 285
2926f9c7 286$(APPDIR)/userhelper_context: $(APPCONF)/userhelper_context
1beba1c6
CP
287 @mkdir -p $(APPDIR)
288 $(QUIET) install -m 644 $< $@
c9a26b3e 289
2926f9c7 290$(APPDIR)/initrc_context: $(APPCONF)/initrc_context
1beba1c6
CP
291 @mkdir -p $(APPDIR)
292 $(QUIET) install -m 644 $< $@
c9a26b3e 293
2926f9c7 294$(APPDIR)/failsafe_context: $(APPCONF)/failsafe_context
1beba1c6
CP
295 @mkdir -p $(APPDIR)
296 $(QUIET) install -m 644 $< $@
c9a26b3e 297
2926f9c7 298$(APPDIR)/dbus_contexts: $(APPCONF)/dbus_contexts
1beba1c6
CP
299 @mkdir -p $(APPDIR)
300 $(QUIET) install -m 644 $< $@
c9a26b3e 301
2926f9c7 302$(APPDIR)/users/root: $(APPCONF)/root_default_contexts
1beba1c6
CP
303 @mkdir -p $(APPDIR)/users
304 $(QUIET) install -m 644 $< $@
c9a26b3e 305
c592e52e
CP
306########################################
307#
308# Install policy sources
309#
310install-src:
311 rm -rf $(SRCPATH)/policy.old
312 -mv $(SRCPATH)/policy $(SRCPATH)/policy.old
313 mkdir -p $(SRCPATH)/policy
314 cp -R . $(SRCPATH)/policy
315
102a59ba
CP
316########################################
317#
318# Clean everything
319#
0fbe15dc 320bare: clean
12b559a4 321 rm -f $(POLXML)
254bbc7b
CP
322 rm -f $(SUPPORT)/*.pyc
323 rm -f $(FCSORT)
19db6ba5 324 rm -f $(MOD_CONF)
4f9f30c8 325 rm -f $(BOOLEANS)
20030ef5 326 rm -fR $(HTMLDIR)
c767b14c
CP
327ifneq ($(GENERATED_TE),)
328 rm -f $(GENERATED_TE)
329endif
330ifneq ($(GENERATED_IF),)
331 rm -f $(GENERATED_IF)
332endif
333ifneq ($(GENERATED_FC),)
334 rm -f $(GENERATED_FC)
335endif
0fbe15dc 336
fb0a3a98 337.PHONY: install-src install-appconfig conf html bare