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