]>
Commit | Line | Data |
---|---|---|
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 | # determine the policy version and current kernel version if possible | |
132 | PV := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ') | |
133 | KV := $(shell cat /selinux/policyvers) | |
134 | ||
135 | # dont print version warnings if we are unable to determine | |
136 | # the currently running kernel's policy version | |
137 | ifeq ($(KV),) | |
138 | KV := $(PV) | |
139 | endif | |
140 | ||
141 | M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt) | |
142 | ||
143 | APPCONF := config/appconfig-$(TYPE) | |
144 | APPDIR := $(CONTEXTPATH) | |
145 | APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts customizable_types) $(CONTEXTPATH)/files/media | |
146 | CONTEXTFILES += $(wildcard $(APPCONF)/*_context*) $(APPCONF)/media | |
147 | USER_FILES := $(POLDIR)/users | |
148 | ||
149 | ALL_LAYERS := $(filter-out $(MODDIR)/CVS,$(shell find $(wildcard $(MODDIR)/*) -maxdepth 0 -type d)) | |
150 | ||
151 | GENERATED_TE := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te.in))) | |
152 | GENERATED_IF := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.if.in))) | |
153 | GENERATED_FC := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.fc.in))) | |
154 | ||
155 | # sort here since it removes duplicates, which can happen | |
156 | # when a generated file is already generated | |
157 | DETECTED_MODS := $(sort $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te)) $(GENERATED_TE)) | |
158 | ||
159 | # modules.conf setting for base module | |
160 | MODBASE := base | |
161 | ||
162 | # modules.conf setting for loadable module | |
163 | MODMOD := module | |
164 | ||
165 | # modules.conf setting for unused module | |
166 | MODUNUSED := off | |
167 | ||
168 | # extract settings from modules.conf | |
169 | BASE_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODBASE)") print $$1 }' $(MOD_CONF) 2> /dev/null)) | |
170 | MOD_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODMOD)") print $$1 }' $(MOD_CONF) 2> /dev/null)) | |
171 | OFF_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODUNUSED)") print $$1 }' $(MOD_CONF) 2> /dev/null)) | |
172 | ||
173 | ######################################## | |
174 | # | |
175 | # Load appropriate rules | |
176 | # | |
177 | ||
178 | ifeq ($(MONOLITHIC),y) | |
179 | include Rules.monolithic | |
180 | else | |
181 | include Rules.modular | |
182 | endif | |
183 | ||
184 | ######################################## | |
185 | # | |
186 | # Generated files | |
187 | # | |
188 | $(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/kernel/corenetwork.if.in | |
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 >> $@ | |
194 | $(QUIET) egrep "^[[:blank:]]*network_(interface|node|port)\(.*\)" $(@:.if=.te).in \ | |
195 | | m4 -D self_contained_policy $(M4PARAM) $(MODDIR)/kernel/corenetwork.if.m4 - \ | |
196 | | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@ | |
197 | ||
198 | $(MODDIR)/kernel/corenetwork.te: $(MODDIR)/kernel/corenetwork.te.m4 $(MODDIR)/kernel/corenetwork.te.in | |
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 "#" >> $@ | |
203 | $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ \ | |
204 | | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@ | |
205 | ||
206 | ######################################## | |
207 | # | |
208 | # Create config files | |
209 | # | |
210 | conf: $(MOD_CONF) $(BOOLEANS) $(GENERATED_TE) $(GENERATED_IF) $(GENERATED_FC) | |
211 | ||
212 | $(MOD_CONF) $(BOOLEANS): $(POLXML) | |
213 | @echo "Updating $(MOD_CONF) and $(BOOLEANS)" | |
214 | $(QUIET) cd $(DOCS) && ../$(GENDOC) -t ../$(BOOLEANS) -m ../$(MOD_CONF) -x ../$(POLXML) | |
215 | ||
216 | ######################################## | |
217 | # | |
218 | # Documentation generation | |
219 | # | |
220 | ||
221 | # minimal dependencies here, because we don't want to rebuild | |
222 | # this and its dependents every time the dependencies | |
223 | # change. Also use all .if files here, rather then just the | |
224 | # enabled modules. | |
225 | $(POLXML): $(DETECTED_MODS:.te=.if) $(foreach dir,$(ALL_LAYERS),$(dir)/$(LAYERXML)) | |
226 | @echo "Creating $@" | |
227 | @mkdir -p tmp | |
228 | $(QUIET) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@ | |
229 | $(QUIET) echo '<!DOCTYPE policy SYSTEM "$(notdir $(XMLDTD))">' >> $@ | |
230 | $(QUIET) $(GENXML) -w -m $(LAYERXML) -t $(GLOBALTUN) -b $(GLOBALBOOL) $(ALL_LAYERS) >> $@ | |
231 | $(QUIET) if test -x $(XMLLINT) && test -f $(XMLDTD); then \ | |
232 | $(XMLLINT) --noout --dtdvalid $(XMLDTD) $@ ;\ | |
233 | fi | |
234 | ||
235 | html: $(POLXML) | |
236 | @mkdir -p $(HTMLDIR) | |
237 | $(QUIET) cd $(DOCS) && ../$(GENDOC) -d ../$(HTMLDIR) -T ../$(DOCTEMPLATE) -x ../$(POLXML) | |
238 | $(QUIET) cp $(DOCTEMPLATE)/*.css $(HTMLDIR) | |
239 | ||
240 | ######################################## | |
241 | # | |
242 | # Runtime binary policy patching of users | |
243 | # | |
244 | $(USERPATH)/system.users: $(M4SUPPORT) tmp/generated_definitions.conf $(USER_FILES) | |
245 | @mkdir -p $(USERPATH) | |
246 | @echo "Installing system.users" | |
247 | @echo "# " > tmp/system.users | |
248 | @echo "# Do not edit this file. " >> tmp/system.users | |
249 | @echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users | |
250 | @echo "# Please edit local.users to make local changes." >> tmp/system.users | |
251 | @echo "#" >> tmp/system.users | |
252 | $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ | \ | |
253 | egrep -v "^[[:blank:]]*($$|#)" | \ | |
254 | sed -r -e 's/^[[:blank:]]+//' >> tmp/system.users | |
255 | $(QUIET) install -m 644 tmp/system.users $@ | |
256 | ||
257 | $(USERPATH)/local.users: config/local.users | |
258 | @mkdir -p $(USERPATH) | |
259 | @echo "Installing local.users" | |
260 | $(QUIET) install -b -m 644 $< $@ | |
261 | ||
262 | ######################################## | |
263 | # | |
264 | # Appconfig files | |
265 | # | |
266 | install-appconfig: $(APPFILES) | |
267 | ||
268 | $(INSTALLDIR)/booleans: $(BOOLEANS) | |
269 | @mkdir -p $(INSTALLDIR) | |
270 | $(QUIET) egrep '^[[:blank:]]*[[:alpha:]]' $(BOOLEANS) \ | |
271 | | sed -e 's/false/0/g' -e 's/true/1/g' > tmp/booleans | |
272 | $(QUIET) install -m 644 tmp/booleans $@ | |
273 | ||
274 | $(CONTEXTPATH)/files/media: $(APPCONF)/media | |
275 | @mkdir -p $(CONTEXTPATH)/files/ | |
276 | $(QUIET) install -m 644 $< $@ | |
277 | ||
278 | $(APPDIR)/default_contexts: $(APPCONF)/default_contexts | |
279 | @mkdir -p $(APPDIR) | |
280 | $(QUIET) install -m 644 $< $@ | |
281 | ||
282 | $(APPDIR)/removable_context: $(APPCONF)/removable_context | |
283 | @mkdir -p $(APPDIR) | |
284 | $(QUIET) install -m 644 $< $@ | |
285 | ||
286 | $(APPDIR)/default_type: $(APPCONF)/default_type | |
287 | @mkdir -p $(APPDIR) | |
288 | $(QUIET) install -m 644 $< $@ | |
289 | ||
290 | $(APPDIR)/userhelper_context: $(APPCONF)/userhelper_context | |
291 | @mkdir -p $(APPDIR) | |
292 | $(QUIET) install -m 644 $< $@ | |
293 | ||
294 | $(APPDIR)/initrc_context: $(APPCONF)/initrc_context | |
295 | @mkdir -p $(APPDIR) | |
296 | $(QUIET) install -m 644 $< $@ | |
297 | ||
298 | $(APPDIR)/failsafe_context: $(APPCONF)/failsafe_context | |
299 | @mkdir -p $(APPDIR) | |
300 | $(QUIET) install -m 644 $< $@ | |
301 | ||
302 | $(APPDIR)/dbus_contexts: $(APPCONF)/dbus_contexts | |
303 | @mkdir -p $(APPDIR) | |
304 | $(QUIET) install -m 644 $< $@ | |
305 | ||
306 | $(APPDIR)/users/root: $(APPCONF)/root_default_contexts | |
307 | @mkdir -p $(APPDIR)/users | |
308 | $(QUIET) install -m 644 $< $@ | |
309 | ||
310 | ######################################## | |
311 | # | |
312 | # Install policy sources | |
313 | # | |
314 | install-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 | ||
320 | ######################################## | |
321 | # | |
322 | # Clean everything | |
323 | # | |
324 | bare: clean | |
325 | rm -f $(POLXML) | |
326 | rm -f $(SUPPORT)/*.pyc | |
327 | rm -f $(FCSORT) | |
328 | rm -f $(MOD_CONF) | |
329 | rm -f $(BOOLEANS) | |
330 | rm -fR $(HTMLDIR) | |
331 | ifneq ($(GENERATED_TE),) | |
332 | rm -f $(GENERATED_TE) | |
333 | endif | |
334 | ifneq ($(GENERATED_IF),) | |
335 | rm -f $(GENERATED_IF) | |
336 | endif | |
337 | ifneq ($(GENERATED_FC),) | |
338 | rm -f $(GENERATED_FC) | |
339 | endif | |
340 | ||
341 | .PHONY: install-src install-appconfig conf html bare | |
342 | .SUFFIXES: | |
343 | .SUFFIXES: .c |