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