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