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