]>
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 | # | |
17 | ||
b4cd1533 CP |
18 | ######################################## |
19 | # | |
20 | # Configurable portions of the Makefile | |
21 | # | |
22 | ||
25a0c61f CP |
23 | # Policy version |
24 | # By default, checkpolicy will create the highest | |
25 | # version policy it supports. Setting this will | |
26 | # override the version. | |
ebb884de | 27 | #OUTPUT_POLICY = 18 |
134191be | 28 | |
b67488e3 | 29 | # Policy Type |
142e9f40 CP |
30 | # strict, targeted, |
31 | # strict-mls, targeted-mls, | |
32 | # strict-mcs, targeted-mcs | |
a3754ffe | 33 | TYPE = targeted-mcs |
b4cd1533 | 34 | |
25a0c61f | 35 | # Policy Name |
b67488e3 CP |
36 | # If set, this will be used as the policy |
37 | # name. Otherwise the policy type will be | |
38 | # used for the name. | |
ebb884de | 39 | NAME = refpolicy |
b67488e3 | 40 | |
25a0c61f CP |
41 | # Distribution |
42 | # Some distributions have portions of policy | |
43 | # for programs or configurations specific to the | |
44 | # distribution. Setting this will enable options | |
45 | # for the distribution. | |
46 | # redhat, gentoo, debian, and suse are current options. | |
47 | # Fedora users should enable redhat. | |
a3754ffe | 48 | DISTRO = redhat |
25a0c61f | 49 | |
142e9f40 CP |
50 | # Direct admin init |
51 | # Setting this will allow sysadm to directly | |
52 | # run init scripts, instead of requring run_init. | |
53 | # This is a build option, as role transitions do | |
54 | # not work in conditional policy. | |
2b01ae7e | 55 | # This option will be impled as y for redhat policies. |
a3754ffe | 56 | DIRECT_INITRC=y |
142e9f40 | 57 | |
b67488e3 CP |
58 | # Build monolithic policy. Putting n here |
59 | # will build a loadable module policy. | |
b67488e3 | 60 | MONOLITHIC=y |
b4cd1533 CP |
61 | |
62 | # Uncomment this to disable command echoing | |
63 | #QUIET:=@ | |
64 | ||
65 | ######################################## | |
66 | # | |
b67488e3 | 67 | # NO OPTIONS BELOW HERE |
b4cd1533 CP |
68 | # |
69 | ||
70 | # executable paths | |
71 | PREFIX := /usr | |
72 | BINDIR := $(PREFIX)/bin | |
73 | SBINDIR := $(PREFIX)/sbin | |
40a1f3db | 74 | CHECKPOLICY := $(BINDIR)/checkpolicy |
fb0a3a98 CP |
75 | CHECKMODULE := $(BINDIR)/checkmodule |
76 | SEMOD_PKG := $(BINDIR)/semodule_package | |
547283e2 | 77 | LOADPOLICY := $(SBINDIR)/load_policy |
b4cd1533 | 78 | SETFILES := $(SBINDIR)/setfiles |
1beba1c6 | 79 | GENHOMEDIRCON := $(SBINDIR)/genhomedircon |
fb0a3a98 | 80 | XMLLINT := $(BINDIR)/xmllint |
8df65f13 | 81 | SECHECK := $(BINDIR)/sechecker |
0447352a | 82 | |
c7b41e95 CP |
83 | CFLAGS := -Wall |
84 | ||
fb0a3a98 | 85 | # policy source layout |
c04f2abe CP |
86 | POLDIR := policy |
87 | MODDIR := $(POLDIR)/modules | |
88 | FLASKDIR := $(POLDIR)/flask | |
89 | SECCLASS := $(FLASKDIR)/security_classes | |
90 | ISIDS := $(FLASKDIR)/initial_sids | |
91 | AVS := $(FLASKDIR)/access_vectors | |
fb0a3a98 CP |
92 | |
93 | # policy building support tools | |
3a80ec29 | 94 | SUPPORT := support |
95db4228 | 95 | GENXML := $(SUPPORT)/segenxml.py |
3a80ec29 | 96 | GENDOC := $(SUPPORT)/sedoctool.py |
c04f2abe | 97 | GENPERM := $(SUPPORT)/genclassperms.py |
254bbc7b | 98 | FCSORT := $(SUPPORT)/fc_sort |
84eb353c | 99 | SETTUN := $(SUPPORT)/set_tunables |
3a80ec29 | 100 | |
fb0a3a98 CP |
101 | # documentation paths |
102 | DOCS = doc | |
103 | POLXML = $(DOCS)/policy.xml | |
104 | XMLDTD = $(DOCS)/policy.dtd | |
105 | LAYERXML = metadata.xml | |
106 | HTMLDIR = $(DOCS)/html | |
107 | DOCTEMPLATE = $(DOCS)/templates | |
108 | ||
109 | # config file paths | |
110 | GLOBALTUN := $(POLDIR)/global_tunables | |
4f9f30c8 | 111 | GLOBALBOOL := $(POLDIR)/global_booleans |
fb0a3a98 CP |
112 | MOD_CONF := $(POLDIR)/modules.conf |
113 | TUNABLES := $(POLDIR)/tunables.conf | |
4f9f30c8 | 114 | BOOLEANS := $(POLDIR)/booleans.conf |
fb0a3a98 CP |
115 | |
116 | # install paths | |
117 | TOPDIR = $(DESTDIR)/etc/selinux | |
118 | INSTALLDIR = $(TOPDIR)/$(NAME) | |
119 | SRCPATH = $(INSTALLDIR)/src | |
120 | USERPATH = $(INSTALLDIR)/users | |
121 | CONTEXTPATH = $(INSTALLDIR)/contexts | |
b4cd1533 | 122 | |
134191be | 123 | # enable MLS if requested. |
a0824843 | 124 | ifneq ($(findstring -mls,$(TYPE)),) |
134191be CP |
125 | override M4PARAM += -D enable_mls |
126 | CHECKPOLICY += -M | |
fb0a3a98 | 127 | CHECKMODULE += -M |
134191be CP |
128 | endif |
129 | ||
a0824843 CP |
130 | # enable MLS if MCS requested. |
131 | ifneq ($(findstring -mcs,$(TYPE)),) | |
132 | override M4PARAM += -D enable_mcs | |
133 | CHECKPOLICY += -M | |
134 | CHECKMODULE += -M | |
135 | endif | |
136 | ||
b67488e3 CP |
137 | # compile targeted policy if requested. |
138 | ifneq ($(findstring targeted,$(TYPE)),) | |
139 | override M4PARAM += -D targeted_policy | |
140 | endif | |
141 | ||
25a0c61f CP |
142 | # enable distribution-specific policy |
143 | ifneq ($(DISTRO),) | |
144 | override M4PARAM += -D distro_$(DISTRO) | |
2b01ae7e CP |
145 | ifeq ($(DISTRO),redhat) |
146 | override DIRECT_INITRC := y | |
147 | endif | |
25a0c61f CP |
148 | endif |
149 | ||
b67488e3 CP |
150 | ifneq ($(OUTPUT_POLICY),) |
151 | CHECKPOLICY += -c $(OUTPUT_POLICY) | |
152 | endif | |
153 | ||
154 | ifeq ($(NAME),) | |
155 | NAME := $(TYPE) | |
134191be CP |
156 | endif |
157 | ||
142e9f40 CP |
158 | ifeq ($(DIRECT_INITRC),y) |
159 | override M4PARAM += -D direct_sysadm_daemon | |
160 | endif | |
161 | ||
b4cd1533 | 162 | # determine the policy version and current kernel version if possible |
134191be | 163 | PV := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ') |
b4cd1533 CP |
164 | KV := $(shell cat /selinux/policyvers) |
165 | ||
166 | # dont print version warnings if we are unable to determine | |
167 | # the currently running kernel's policy version | |
168 | ifeq ($(KV),) | |
134191be | 169 | KV := $(PV) |
b4cd1533 CP |
170 | endif |
171 | ||
172 | FC := file_contexts | |
173 | POLVER := policy.$(PV) | |
b4cd1533 | 174 | |
fb0a3a98 | 175 | M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt) |
0fbe15dc | 176 | |
c0e4fe2c | 177 | APPCONF := config/appconfig-$(TYPE) |
c9a26b3e | 178 | APPDIR := $(CONTEXTPATH) |
1beba1c6 | 179 | APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts customizable_types) $(CONTEXTPATH)/files/media $(INSTALLDIR)/booleans |
2926f9c7 | 180 | CONTEXTFILES += $(wildcard $(APPCONF)/*_context*) $(APPCONF)/media |
712566ee | 181 | USER_FILES := $(POLDIR)/systemuser $(POLDIR)/users |
c9a26b3e | 182 | |
57869a68 | 183 | ALL_LAYERS := $(filter-out $(MODDIR)/CVS,$(shell find $(wildcard $(MODDIR)/*) -maxdepth 0 -type d)) |
e12e5738 CP |
184 | |
185 | GENERATED_TE := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te.in))) | |
186 | GENERATED_IF := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.if.in))) | |
187 | GENERATED_FC := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.fc.in))) | |
188 | ||
8ae194f6 CP |
189 | # sort here since it removes duplicates, which can happen |
190 | # when a generated file is already generated | |
191 | DETECTED_MODS := $(sort $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te)) $(GENERATED_TE)) | |
19db6ba5 | 192 | |
fb0a3a98 | 193 | # modules.conf setting for base module |
e8b3e30a | 194 | MODBASE := base |
fb0a3a98 CP |
195 | |
196 | # modules.conf setting for module | |
e8b3e30a | 197 | MODMOD := module |
fb0a3a98 CP |
198 | |
199 | # extract settings from modules.conf | |
a3fdcebc CP |
200 | BASE_MODS := $(foreach mod,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODBASE)") print $$1 }' $(MOD_CONF) 2> /dev/null),$(subst ./,,$(shell find -iname $(mod).te))) |
201 | MOD_MODS := $(foreach mod,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODMOD)") print $$1 }' $(MOD_CONF) 2> /dev/null),$(subst ./,,$(shell find -iname $(mod).te))) | |
e8b3e30a | 202 | |
712566ee CP |
203 | HOMEDIR_TEMPLATE = tmp/homedir_template |
204 | ||
b4cd1533 CP |
205 | ######################################## |
206 | # | |
fb0a3a98 | 207 | # Load appropriate rules |
b4cd1533 | 208 | # |
b4cd1533 | 209 | |
fb0a3a98 CP |
210 | ifeq ($(MONOLITHIC),y) |
211 | include Rules.monolithic | |
212 | else | |
213 | include Rules.modular | |
b4cd1533 | 214 | endif |
b4cd1533 | 215 | |
88d14a22 CP |
216 | ######################################## |
217 | # | |
fb0a3a98 | 218 | # Generated files |
b4cd1533 | 219 | # |
f2e4ab3a | 220 | $(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/kernel/corenetwork.if.in |
61bbe531 CP |
221 | @echo "#" > $@ |
222 | @echo "# This is a generated file! Instead of modifying this file, the" >> $@ | |
223 | @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@ | |
224 | @echo "#" >> $@ | |
225 | $(QUIET) cat $(MODDIR)/kernel/corenetwork.if.in >> $@ | |
f2e4ab3a | 226 | $(QUIET) egrep "^[[:blank:]]*network_(interface|node|port)\(.*\)" $(@:.if=.te).in \ |
cf6141a7 | 227 | | m4 -D self_contained_policy $(M4PARAM) $(MODDIR)/kernel/corenetwork.if.m4 - \ |
f2e4ab3a | 228 | | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@ |
f2e4ab3a CP |
229 | |
230 | $(MODDIR)/kernel/corenetwork.te: $(MODDIR)/kernel/corenetwork.te.m4 $(MODDIR)/kernel/corenetwork.te.in | |
61bbe531 CP |
231 | @echo "#" > $@ |
232 | @echo "# This is a generated file! Instead of modifying this file, the" >> $@ | |
233 | @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@ | |
234 | @echo "#" >> $@ | |
cf6141a7 | 235 | $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ \ |
61bbe531 | 236 | | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@ |
f2e4ab3a | 237 | |
84eb353c CP |
238 | ######################################## |
239 | # | |
240 | # Create config files | |
241 | # | |
4f9f30c8 | 242 | conf: $(MOD_CONF) $(BOOLEANS) $(GENERATED_TE) $(GENERATED_IF) $(GENERATED_FC) |
d2d6c8ce | 243 | |
4f9f30c8 CP |
244 | $(MOD_CONF) $(BOOLEANS): $(POLXML) |
245 | @echo "Updating $(MOD_CONF) and $(BOOLEANS)" | |
246 | $(QUIET) cd $(DOCS) && ../$(GENDOC) -t ../$(BOOLEANS) -m ../$(MOD_CONF) -x ../$(POLXML) | |
84eb353c | 247 | |
6d314fd3 CP |
248 | ######################################## |
249 | # | |
250 | # Documentation generation | |
251 | # | |
252 | ||
d2d6c8ce | 253 | # minimal dependencies here, because we don't want to rebuild |
84eb353c | 254 | # this and its dependents every time the dependencies |
19db6ba5 CP |
255 | # change. Also use all .if files here, rather then just the |
256 | # enabled modules. | |
d233bfce | 257 | $(POLXML): $(DETECTED_MODS:.te=.if) $(foreach dir,$(ALL_LAYERS),$(dir)/$(LAYERXML)) |
88c72f44 | 258 | @echo "Creating $@" |
84eb353c | 259 | @mkdir -p tmp |
004db90d | 260 | $(QUIET) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@ |
95db4228 | 261 | $(QUIET) echo '<!DOCTYPE policy SYSTEM "$(notdir $(XMLDTD))">' >> $@ |
4f9f30c8 | 262 | $(QUIET) $(GENXML) -w -m $(LAYERXML) -t $(GLOBALTUN) -b $(GLOBALBOOL) $(ALL_LAYERS) >> $@ |
0447352a CP |
263 | $(QUIET) if test -x $(XMLLINT) && test -f $(XMLDTD); then \ |
264 | $(XMLLINT) --noout --dtdvalid $(XMLDTD) $@ ;\ | |
004db90d | 265 | fi |
6d314fd3 | 266 | |
12b559a4 | 267 | html: $(POLXML) |
20030ef5 | 268 | @mkdir -p $(HTMLDIR) |
12b559a4 | 269 | $(QUIET) cd $(DOCS) && ../$(GENDOC) -d ../$(HTMLDIR) -T ../$(DOCTEMPLATE) -x ../$(POLXML) |
20030ef5 CP |
270 | $(QUIET) cp $(DOCTEMPLATE)/*.css $(HTMLDIR) |
271 | ||
c9a26b3e CP |
272 | ######################################## |
273 | # | |
274 | # Runtime binary policy patching of users | |
275 | # | |
1fb83a76 | 276 | $(USERPATH)/system.users: $(M4SUPPORT) tmp/generated_definitions.conf $(USER_FILES) |
c9a26b3e CP |
277 | @mkdir -p $(USERPATH) |
278 | @echo "Installing system.users" | |
279 | @echo "# " > tmp/system.users | |
280 | @echo "# Do not edit this file. " >> tmp/system.users | |
281 | @echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users | |
282 | @echo "# Please edit local.users to make local changes." >> tmp/system.users | |
283 | @echo "#" >> tmp/system.users | |
1fb83a76 | 284 | $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ | \ |
fb2817da CP |
285 | egrep -v "^[[:blank:]]*($$|#)" | \ |
286 | sed -r -e 's/^[[:blank:]]+//' >> tmp/system.users | |
c9a26b3e CP |
287 | $(QUIET) install -m 644 tmp/system.users $@ |
288 | ||
1beba1c6 | 289 | $(USERPATH)/local.users: config/local.users |
c9a26b3e CP |
290 | @mkdir -p $(USERPATH) |
291 | @echo "Installing local.users" | |
c7b41e95 | 292 | $(QUIET) install -b -m 644 $< $@ |
c9a26b3e CP |
293 | |
294 | ######################################## | |
295 | # | |
296 | # Appconfig files | |
297 | # | |
298 | install-appconfig: $(APPFILES) | |
299 | ||
4f9f30c8 | 300 | $(INSTALLDIR)/booleans: $(BOOLEANS) |
1beba1c6 | 301 | @mkdir -p $(INSTALLDIR) |
4f9f30c8 | 302 | $(QUIET) egrep '^[[:blank:]]*[[:alpha:]]' $(BOOLEANS) \ |
1beba1c6 CP |
303 | | sed -e 's/false/0/g' -e 's/true/1/g' > tmp/booleans |
304 | $(QUIET) install -m 644 tmp/booleans $@ | |
305 | ||
2926f9c7 | 306 | $(CONTEXTPATH)/files/media: $(APPCONF)/media |
1beba1c6 CP |
307 | @mkdir -p $(CONTEXTPATH)/files/ |
308 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 309 | |
2926f9c7 | 310 | $(APPDIR)/default_contexts: $(APPCONF)/default_contexts |
1beba1c6 CP |
311 | @mkdir -p $(APPDIR) |
312 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 313 | |
2926f9c7 | 314 | $(APPDIR)/removable_context: $(APPCONF)/removable_context |
1beba1c6 CP |
315 | @mkdir -p $(APPDIR) |
316 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e CP |
317 | |
318 | $(APPDIR)/customizable_types: policy.conf | |
1beba1c6 CP |
319 | @mkdir -p $(APPDIR) |
320 | $(QUIET) grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > tmp/customizable_types | |
321 | $(QUIET) install -m 644 tmp/customizable_types $@ | |
c9a26b3e | 322 | |
2926f9c7 | 323 | $(APPDIR)/default_type: $(APPCONF)/default_type |
1beba1c6 CP |
324 | @mkdir -p $(APPDIR) |
325 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 326 | |
2926f9c7 | 327 | $(APPDIR)/userhelper_context: $(APPCONF)/userhelper_context |
1beba1c6 CP |
328 | @mkdir -p $(APPDIR) |
329 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 330 | |
2926f9c7 | 331 | $(APPDIR)/initrc_context: $(APPCONF)/initrc_context |
1beba1c6 CP |
332 | @mkdir -p $(APPDIR) |
333 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 334 | |
2926f9c7 | 335 | $(APPDIR)/failsafe_context: $(APPCONF)/failsafe_context |
1beba1c6 CP |
336 | @mkdir -p $(APPDIR) |
337 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 338 | |
2926f9c7 | 339 | $(APPDIR)/dbus_contexts: $(APPCONF)/dbus_contexts |
1beba1c6 CP |
340 | @mkdir -p $(APPDIR) |
341 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 342 | |
2926f9c7 | 343 | $(APPDIR)/users/root: $(APPCONF)/root_default_contexts |
1beba1c6 CP |
344 | @mkdir -p $(APPDIR)/users |
345 | $(QUIET) install -m 644 $< $@ | |
c9a26b3e | 346 | |
c592e52e CP |
347 | ######################################## |
348 | # | |
349 | # Install policy sources | |
350 | # | |
351 | install-src: | |
352 | rm -rf $(SRCPATH)/policy.old | |
353 | -mv $(SRCPATH)/policy $(SRCPATH)/policy.old | |
354 | mkdir -p $(SRCPATH)/policy | |
355 | cp -R . $(SRCPATH)/policy | |
356 | ||
102a59ba CP |
357 | ######################################## |
358 | # | |
359 | # Clean everything | |
360 | # | |
0fbe15dc | 361 | bare: clean |
12b559a4 | 362 | rm -f $(POLXML) |
254bbc7b CP |
363 | rm -f $(SUPPORT)/*.pyc |
364 | rm -f $(FCSORT) | |
19db6ba5 | 365 | rm -f $(MOD_CONF) |
4f9f30c8 | 366 | rm -f $(BOOLEANS) |
20030ef5 | 367 | rm -fR $(HTMLDIR) |
e12e5738 CP |
368 | ifneq ($(GENERATED_TE),) |
369 | rm -f $(GENERATED_TE) | |
370 | endif | |
371 | ifneq ($(GENERATED_IF),) | |
372 | rm -f $(GENERATED_IF) | |
373 | endif | |
374 | ifneq ($(GENERATED_FC),) | |
375 | rm -f $(GENERATED_FC) | |
376 | endif | |
0fbe15dc | 377 | |
fb0a3a98 | 378 | .PHONY: install-src install-appconfig conf html bare |