]>
Commit | Line | Data |
---|---|---|
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 |
26 | include build.conf |
27 | ||
b4cd1533 CP |
28 | # executable paths |
29 | PREFIX := /usr | |
30 | BINDIR := $(PREFIX)/bin | |
31 | SBINDIR := $(PREFIX)/sbin | |
40a1f3db | 32 | CHECKPOLICY := $(BINDIR)/checkpolicy |
fb0a3a98 | 33 | CHECKMODULE := $(BINDIR)/checkmodule |
c767b14c | 34 | SEMODULE := $(SBINDIR)/semodule |
fb0a3a98 | 35 | SEMOD_PKG := $(BINDIR)/semodule_package |
547283e2 | 36 | LOADPOLICY := $(SBINDIR)/load_policy |
b4cd1533 | 37 | SETFILES := $(SBINDIR)/setfiles |
1beba1c6 | 38 | GENHOMEDIRCON := $(SBINDIR)/genhomedircon |
fb0a3a98 | 39 | XMLLINT := $(BINDIR)/xmllint |
8df65f13 | 40 | SECHECK := $(BINDIR)/sechecker |
0447352a | 41 | |
c7b41e95 CP |
42 | CFLAGS := -Wall |
43 | ||
fb0a3a98 | 44 | # policy source layout |
c04f2abe CP |
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 | |
fb0a3a98 CP |
51 | |
52 | # policy building support tools | |
3a80ec29 | 53 | SUPPORT := support |
95db4228 | 54 | GENXML := $(SUPPORT)/segenxml.py |
3a80ec29 | 55 | GENDOC := $(SUPPORT)/sedoctool.py |
c04f2abe | 56 | GENPERM := $(SUPPORT)/genclassperms.py |
254bbc7b | 57 | FCSORT := $(SUPPORT)/fc_sort |
84eb353c | 58 | SETTUN := $(SUPPORT)/set_tunables |
3a80ec29 | 59 | |
fb0a3a98 CP |
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 | |
4f9f30c8 | 70 | GLOBALBOOL := $(POLDIR)/global_booleans |
fb0a3a98 CP |
71 | MOD_CONF := $(POLDIR)/modules.conf |
72 | TUNABLES := $(POLDIR)/tunables.conf | |
4f9f30c8 | 73 | BOOLEANS := $(POLDIR)/booleans.conf |
fb0a3a98 CP |
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 | |
c767b14c CP |
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 | |
b4cd1533 | 92 | |
134191be | 93 | # enable MLS if requested. |
a0824843 | 94 | ifneq ($(findstring -mls,$(TYPE)),) |
134191be | 95 | override M4PARAM += -D enable_mls |
c767b14c CP |
96 | override CHECKPOLICY += -M |
97 | override CHECKMODULE += -M | |
134191be CP |
98 | endif |
99 | ||
a0824843 CP |
100 | # enable MLS if MCS requested. |
101 | ifneq ($(findstring -mcs,$(TYPE)),) | |
102 | override M4PARAM += -D enable_mcs | |
c767b14c CP |
103 | override CHECKPOLICY += -M |
104 | override CHECKMODULE += -M | |
b67488e3 CP |
105 | endif |
106 | ||
25a0c61f CP |
107 | # enable distribution-specific policy |
108 | ifneq ($(DISTRO),) | |
109 | override M4PARAM += -D distro_$(DISTRO) | |
110 | endif | |
111 | ||
b07eaef9 CP |
112 | # enable polyinstantiation |
113 | ifeq ($(POLY),y) | |
114 | override M4PARAM += -D enable_polyinstantiation | |
115 | endif | |
116 | ||
b67488e3 | 117 | ifneq ($(OUTPUT_POLICY),) |
c767b14c | 118 | override CHECKPOLICY += -c $(OUTPUT_POLICY) |
b67488e3 CP |
119 | endif |
120 | ||
121 | ifeq ($(NAME),) | |
122 | NAME := $(TYPE) | |
134191be CP |
123 | endif |
124 | ||
142e9f40 CP |
125 | ifeq ($(DIRECT_INITRC),y) |
126 | override M4PARAM += -D direct_sysadm_daemon | |
127 | endif | |
128 | ||
ee7f66b0 CP |
129 | override M4PARAM += -D hide_broken_symptoms |
130 | ||
b4cd1533 | 131 | # determine the policy version and current kernel version if possible |
134191be | 132 | PV := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ') |
b4cd1533 CP |
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),) | |
134191be | 138 | KV := $(PV) |
b4cd1533 CP |
139 | endif |
140 | ||
fb0a3a98 | 141 | M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt) |
0fbe15dc | 142 | |
c0e4fe2c | 143 | APPCONF := config/appconfig-$(TYPE) |
c9a26b3e | 144 | APPDIR := $(CONTEXTPATH) |
049e11af | 145 | APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts customizable_types) $(CONTEXTPATH)/files/media |
2926f9c7 | 146 | CONTEXTFILES += $(wildcard $(APPCONF)/*_context*) $(APPCONF)/media |
bdb2fac0 | 147 | USER_FILES := $(POLDIR)/users |
c9a26b3e | 148 | |
57869a68 | 149 | ALL_LAYERS := $(filter-out $(MODDIR)/CVS,$(shell find $(wildcard $(MODDIR)/*) -maxdepth 0 -type d)) |
e12e5738 CP |
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 | ||
8ae194f6 CP |
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)) | |
19db6ba5 | 158 | |
fb0a3a98 | 159 | # modules.conf setting for base module |
e8b3e30a | 160 | MODBASE := base |
fb0a3a98 | 161 | |
e0a9001b | 162 | # modules.conf setting for loadable module |
e8b3e30a | 163 | MODMOD := module |
fb0a3a98 | 164 | |
e0a9001b CP |
165 | # modules.conf setting for unused module |
166 | MODUNUSED := off | |
167 | ||
fb0a3a98 | 168 | # extract settings from modules.conf |
c767b14c CP |
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)) | |
e0a9001b | 171 | OFF_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 |
178 | ifeq ($(MONOLITHIC),y) |
179 | include Rules.monolithic | |
180 | else | |
181 | include Rules.modular | |
b4cd1533 | 182 | endif |
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 | 210 | conf: $(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 | 235 | html: $(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 | |
1fb83a76 | 253 | $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ | \ |
fb2817da CP |
254 | egrep -v "^[[:blank:]]*($$|#)" | \ |
255 | sed -r -e 's/^[[:blank:]]+//' >> tmp/system.users | |
c9a26b3e CP |
256 | $(QUIET) install -m 644 tmp/system.users $@ |
257 | ||
1beba1c6 | 258 | $(USERPATH)/local.users: config/local.users |
c9a26b3e CP |
259 | @mkdir -p $(USERPATH) |
260 | @echo "Installing local.users" | |
c7b41e95 | 261 | $(QUIET) install -b -m 644 $< $@ |
c9a26b3e CP |
262 | |
263 | ######################################## | |
264 | # | |
265 | # Appconfig files | |
266 | # | |
267 | install-appconfig: $(APPFILES) | |
268 | ||
4f9f30c8 | 269 | $(INSTALLDIR)/booleans: $(BOOLEANS) |
1beba1c6 | 270 | @mkdir -p $(INSTALLDIR) |
4f9f30c8 | 271 | $(QUIET) egrep '^[[:blank:]]*[[:alpha:]]' $(BOOLEANS) \ |
1beba1c6 CP |
272 | | sed -e 's/false/0/g' -e 's/true/1/g' > tmp/booleans |
273 | $(QUIET) install -m 644 tmp/booleans $@ | |
274 | ||
2926f9c7 | 275 | $(CONTEXTPATH)/files/media: $(APPCONF)/media |
1beba1c6 CP |
276 | @mkdir -p $(CONTEXTPATH)/files/ |
277 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 278 | |
2926f9c7 | 279 | $(APPDIR)/default_contexts: $(APPCONF)/default_contexts |
1beba1c6 CP |
280 | @mkdir -p $(APPDIR) |
281 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 282 | |
2926f9c7 | 283 | $(APPDIR)/removable_context: $(APPCONF)/removable_context |
1beba1c6 CP |
284 | @mkdir -p $(APPDIR) |
285 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 286 | |
2926f9c7 | 287 | $(APPDIR)/default_type: $(APPCONF)/default_type |
1beba1c6 CP |
288 | @mkdir -p $(APPDIR) |
289 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 290 | |
2926f9c7 | 291 | $(APPDIR)/userhelper_context: $(APPCONF)/userhelper_context |
1beba1c6 CP |
292 | @mkdir -p $(APPDIR) |
293 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 294 | |
2926f9c7 | 295 | $(APPDIR)/initrc_context: $(APPCONF)/initrc_context |
1beba1c6 CP |
296 | @mkdir -p $(APPDIR) |
297 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 298 | |
2926f9c7 | 299 | $(APPDIR)/failsafe_context: $(APPCONF)/failsafe_context |
1beba1c6 CP |
300 | @mkdir -p $(APPDIR) |
301 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 302 | |
2926f9c7 | 303 | $(APPDIR)/dbus_contexts: $(APPCONF)/dbus_contexts |
1beba1c6 CP |
304 | @mkdir -p $(APPDIR) |
305 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 306 | |
2926f9c7 | 307 | $(APPDIR)/users/root: $(APPCONF)/root_default_contexts |
1beba1c6 CP |
308 | @mkdir -p $(APPDIR)/users |
309 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 310 | |
c592e52e CP |
311 | ######################################## |
312 | # | |
313 | # Install policy sources | |
314 | # | |
315 | install-src: | |
316 | rm -rf $(SRCPATH)/policy.old | |
317 | -mv $(SRCPATH)/policy $(SRCPATH)/policy.old | |
318 | mkdir -p $(SRCPATH)/policy | |
319 | cp -R . $(SRCPATH)/policy | |
320 | ||
102a59ba CP |
321 | ######################################## |
322 | # | |
323 | # Clean everything | |
324 | # | |
0fbe15dc | 325 | bare: clean |
12b559a4 | 326 | rm -f $(POLXML) |
254bbc7b CP |
327 | rm -f $(SUPPORT)/*.pyc |
328 | rm -f $(FCSORT) | |
19db6ba5 | 329 | rm -f $(MOD_CONF) |
4f9f30c8 | 330 | rm -f $(BOOLEANS) |
20030ef5 | 331 | rm -fR $(HTMLDIR) |
c767b14c CP |
332 | ifneq ($(GENERATED_TE),) |
333 | rm -f $(GENERATED_TE) | |
334 | endif | |
335 | ifneq ($(GENERATED_IF),) | |
336 | rm -f $(GENERATED_IF) | |
337 | endif | |
338 | ifneq ($(GENERATED_FC),) | |
339 | rm -f $(GENERATED_FC) | |
340 | endif | |
0fbe15dc | 341 | |
fb0a3a98 | 342 | .PHONY: install-src install-appconfig conf html bare |
b8c79823 CP |
343 | .SUFFIXES: |
344 | .SUFFIXES: .c |