]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/Makefile
patch from dan
[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
b07eaef9
CP
112# enable polyinstantiation
113ifeq ($(POLY),y)
114 override M4PARAM += -D enable_polyinstantiation
115endif
116
b67488e3 117ifneq ($(OUTPUT_POLICY),)
c767b14c 118 override CHECKPOLICY += -c $(OUTPUT_POLICY)
b67488e3
CP
119endif
120
121ifeq ($(NAME),)
122 NAME := $(TYPE)
134191be
CP
123endif
124
142e9f40
CP
125ifeq ($(DIRECT_INITRC),y)
126 override M4PARAM += -D direct_sysadm_daemon
127endif
128
ee7f66b0
CP
129override M4PARAM += -D hide_broken_symptoms
130
b4cd1533 131# determine the policy version and current kernel version if possible
134191be 132PV := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ')
b4cd1533
CP
133KV := $(shell cat /selinux/policyvers)
134
135# dont print version warnings if we are unable to determine
136# the currently running kernel's policy version
137ifeq ($(KV),)
134191be 138 KV := $(PV)
b4cd1533
CP
139endif
140
fb0a3a98 141M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt)
0fbe15dc 142
c0e4fe2c 143APPCONF := config/appconfig-$(TYPE)
c9a26b3e 144APPDIR := $(CONTEXTPATH)
049e11af 145APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts customizable_types) $(CONTEXTPATH)/files/media
2926f9c7 146CONTEXTFILES += $(wildcard $(APPCONF)/*_context*) $(APPCONF)/media
bdb2fac0 147USER_FILES := $(POLDIR)/users
c9a26b3e 148
57869a68 149ALL_LAYERS := $(filter-out $(MODDIR)/CVS,$(shell find $(wildcard $(MODDIR)/*) -maxdepth 0 -type d))
e12e5738
CP
150
151GENERATED_TE := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te.in)))
152GENERATED_IF := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.if.in)))
153GENERATED_FC := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.fc.in)))
154
8ae194f6
CP
155# sort here since it removes duplicates, which can happen
156# when a generated file is already generated
157DETECTED_MODS := $(sort $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te)) $(GENERATED_TE))
19db6ba5 158
fb0a3a98 159# modules.conf setting for base module
e8b3e30a 160MODBASE := base
fb0a3a98 161
e0a9001b 162# modules.conf setting for loadable module
e8b3e30a 163MODMOD := module
fb0a3a98 164
e0a9001b
CP
165# modules.conf setting for unused module
166MODUNUSED := off
167
fb0a3a98 168# extract settings from modules.conf
c767b14c
CP
169BASE_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODBASE)") print $$1 }' $(MOD_CONF) 2> /dev/null))
170MOD_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODMOD)") print $$1 }' $(MOD_CONF) 2> /dev/null))
e0a9001b 171OFF_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODUNUSED)") print $$1 }' $(MOD_CONF) 2> /dev/null))
712566ee 172
b4cd1533
CP
173########################################
174#
fb0a3a98 175# Load appropriate rules
b4cd1533 176#
b4cd1533 177
fb0a3a98
CP
178ifeq ($(MONOLITHIC),y)
179 include Rules.monolithic
180else
181 include Rules.modular
b4cd1533 182endif
b4cd1533 183
88d14a22
CP
184########################################
185#
fb0a3a98 186# Generated files
b4cd1533 187#
f2e4ab3a 188$(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/kernel/corenetwork.if.in
61bbe531
CP
189 @echo "#" > $@
190 @echo "# This is a generated file! Instead of modifying this file, the" >> $@
191 @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
192 @echo "#" >> $@
193 $(QUIET) cat $(MODDIR)/kernel/corenetwork.if.in >> $@
f2e4ab3a 194 $(QUIET) egrep "^[[:blank:]]*network_(interface|node|port)\(.*\)" $(@:.if=.te).in \
cf6141a7 195 | m4 -D self_contained_policy $(M4PARAM) $(MODDIR)/kernel/corenetwork.if.m4 - \
f2e4ab3a 196 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
f2e4ab3a
CP
197
198$(MODDIR)/kernel/corenetwork.te: $(MODDIR)/kernel/corenetwork.te.m4 $(MODDIR)/kernel/corenetwork.te.in
61bbe531
CP
199 @echo "#" > $@
200 @echo "# This is a generated file! Instead of modifying this file, the" >> $@
201 @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
202 @echo "#" >> $@
cf6141a7 203 $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ \
61bbe531 204 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
f2e4ab3a 205
84eb353c
CP
206########################################
207#
208# Create config files
209#
4f9f30c8 210conf: $(MOD_CONF) $(BOOLEANS) $(GENERATED_TE) $(GENERATED_IF) $(GENERATED_FC)
d2d6c8ce 211
4f9f30c8
CP
212$(MOD_CONF) $(BOOLEANS): $(POLXML)
213 @echo "Updating $(MOD_CONF) and $(BOOLEANS)"
214 $(QUIET) cd $(DOCS) && ../$(GENDOC) -t ../$(BOOLEANS) -m ../$(MOD_CONF) -x ../$(POLXML)
84eb353c 215
6d314fd3
CP
216########################################
217#
218# Documentation generation
219#
220
d2d6c8ce 221# minimal dependencies here, because we don't want to rebuild
84eb353c 222# this and its dependents every time the dependencies
19db6ba5
CP
223# change. Also use all .if files here, rather then just the
224# enabled modules.
d233bfce 225$(POLXML): $(DETECTED_MODS:.te=.if) $(foreach dir,$(ALL_LAYERS),$(dir)/$(LAYERXML))
88c72f44 226 @echo "Creating $@"
84eb353c 227 @mkdir -p tmp
004db90d 228 $(QUIET) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@
95db4228 229 $(QUIET) echo '<!DOCTYPE policy SYSTEM "$(notdir $(XMLDTD))">' >> $@
4f9f30c8 230 $(QUIET) $(GENXML) -w -m $(LAYERXML) -t $(GLOBALTUN) -b $(GLOBALBOOL) $(ALL_LAYERS) >> $@
0447352a
CP
231 $(QUIET) if test -x $(XMLLINT) && test -f $(XMLDTD); then \
232 $(XMLLINT) --noout --dtdvalid $(XMLDTD) $@ ;\
004db90d 233 fi
6d314fd3 234
12b559a4 235html: $(POLXML)
2de03f30 236 @echo "Building html interface reference documentation in $(HTMLDIR)"
20030ef5 237 @mkdir -p $(HTMLDIR)
12b559a4 238 $(QUIET) cd $(DOCS) && ../$(GENDOC) -d ../$(HTMLDIR) -T ../$(DOCTEMPLATE) -x ../$(POLXML)
20030ef5
CP
239 $(QUIET) cp $(DOCTEMPLATE)/*.css $(HTMLDIR)
240
c9a26b3e
CP
241########################################
242#
243# Runtime binary policy patching of users
244#
1fb83a76 245$(USERPATH)/system.users: $(M4SUPPORT) tmp/generated_definitions.conf $(USER_FILES)
c9a26b3e
CP
246 @mkdir -p $(USERPATH)
247 @echo "Installing system.users"
248 @echo "# " > tmp/system.users
249 @echo "# Do not edit this file. " >> tmp/system.users
250 @echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users
251 @echo "# Please edit local.users to make local changes." >> tmp/system.users
252 @echo "#" >> tmp/system.users
7dca64fa
CP
253 $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ | sed -r -e 's/^[[:blank:]]+//' \
254 -e '/^[[:blank:]]*($$|#)/d' >> tmp/system.users
c9a26b3e
CP
255 $(QUIET) install -m 644 tmp/system.users $@
256
1beba1c6 257$(USERPATH)/local.users: config/local.users
c9a26b3e
CP
258 @mkdir -p $(USERPATH)
259 @echo "Installing local.users"
c7b41e95 260 $(QUIET) install -b -m 644 $< $@
c9a26b3e
CP
261
262########################################
263#
264# Appconfig files
265#
266install-appconfig: $(APPFILES)
267
4f9f30c8 268$(INSTALLDIR)/booleans: $(BOOLEANS)
1beba1c6 269 @mkdir -p $(INSTALLDIR)
c43ecfc3 270 $(QUIET) sed -r -e 's/false/0/g' -e 's/true/1/g' \
7dca64fa 271 -e '/^[[:blank:]]*($$|#)/d' $(BOOLEANS) | sort > tmp/booleans
1beba1c6
CP
272 $(QUIET) install -m 644 tmp/booleans $@
273
2926f9c7 274$(CONTEXTPATH)/files/media: $(APPCONF)/media
1beba1c6
CP
275 @mkdir -p $(CONTEXTPATH)/files/
276 $(QUIET) install -m 644 $< $@
c9a26b3e 277
2926f9c7 278$(APPDIR)/default_contexts: $(APPCONF)/default_contexts
1beba1c6
CP
279 @mkdir -p $(APPDIR)
280 $(QUIET) install -m 644 $< $@
c9a26b3e 281
2926f9c7 282$(APPDIR)/removable_context: $(APPCONF)/removable_context
1beba1c6
CP
283 @mkdir -p $(APPDIR)
284 $(QUIET) install -m 644 $< $@
c9a26b3e 285
2926f9c7 286$(APPDIR)/default_type: $(APPCONF)/default_type
1beba1c6
CP
287 @mkdir -p $(APPDIR)
288 $(QUIET) install -m 644 $< $@
c9a26b3e 289
2926f9c7 290$(APPDIR)/userhelper_context: $(APPCONF)/userhelper_context
1beba1c6
CP
291 @mkdir -p $(APPDIR)
292 $(QUIET) install -m 644 $< $@
c9a26b3e 293
2926f9c7 294$(APPDIR)/initrc_context: $(APPCONF)/initrc_context
1beba1c6
CP
295 @mkdir -p $(APPDIR)
296 $(QUIET) install -m 644 $< $@
c9a26b3e 297
2926f9c7 298$(APPDIR)/failsafe_context: $(APPCONF)/failsafe_context
1beba1c6
CP
299 @mkdir -p $(APPDIR)
300 $(QUIET) install -m 644 $< $@
c9a26b3e 301
2926f9c7 302$(APPDIR)/dbus_contexts: $(APPCONF)/dbus_contexts
1beba1c6
CP
303 @mkdir -p $(APPDIR)
304 $(QUIET) install -m 644 $< $@
c9a26b3e 305
2926f9c7 306$(APPDIR)/users/root: $(APPCONF)/root_default_contexts
1beba1c6
CP
307 @mkdir -p $(APPDIR)/users
308 $(QUIET) install -m 644 $< $@
c9a26b3e 309
c592e52e
CP
310########################################
311#
312# Install policy sources
313#
314install-src:
315 rm -rf $(SRCPATH)/policy.old
316 -mv $(SRCPATH)/policy $(SRCPATH)/policy.old
317 mkdir -p $(SRCPATH)/policy
318 cp -R . $(SRCPATH)/policy
319
102a59ba
CP
320########################################
321#
322# Clean everything
323#
0fbe15dc 324bare: clean
12b559a4 325 rm -f $(POLXML)
254bbc7b
CP
326 rm -f $(SUPPORT)/*.pyc
327 rm -f $(FCSORT)
19db6ba5 328 rm -f $(MOD_CONF)
4f9f30c8 329 rm -f $(BOOLEANS)
20030ef5 330 rm -fR $(HTMLDIR)
c767b14c
CP
331ifneq ($(GENERATED_TE),)
332 rm -f $(GENERATED_TE)
333endif
334ifneq ($(GENERATED_IF),)
335 rm -f $(GENERATED_IF)
336endif
337ifneq ($(GENERATED_FC),)
338 rm -f $(GENERATED_FC)
339endif
0fbe15dc 340
fb0a3a98 341.PHONY: install-src install-appconfig conf html bare
b8c79823
CP
342.SUFFIXES:
343.SUFFIXES: .c