]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/Makefile
remove newrole privs from su and sudo
[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#
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
26include build.conf
27
b4cd1533
CP
28# executable paths
29PREFIX := /usr
30BINDIR := $(PREFIX)/bin
31SBINDIR := $(PREFIX)/sbin
40a1f3db 32CHECKPOLICY := $(BINDIR)/checkpolicy
fb0a3a98 33CHECKMODULE := $(BINDIR)/checkmodule
c767b14c 34SEMODULE := $(SBINDIR)/semodule
fb0a3a98 35SEMOD_PKG := $(BINDIR)/semodule_package
547283e2 36LOADPOLICY := $(SBINDIR)/load_policy
b4cd1533 37SETFILES := $(SBINDIR)/setfiles
1beba1c6 38GENHOMEDIRCON := $(SBINDIR)/genhomedircon
fb0a3a98 39XMLLINT := $(BINDIR)/xmllint
8df65f13 40SECHECK := $(BINDIR)/sechecker
0447352a 41
c7b41e95
CP
42CFLAGS := -Wall
43
fb0a3a98 44# policy source layout
c04f2abe
CP
45POLDIR := policy
46MODDIR := $(POLDIR)/modules
47FLASKDIR := $(POLDIR)/flask
48SECCLASS := $(FLASKDIR)/security_classes
49ISIDS := $(FLASKDIR)/initial_sids
50AVS := $(FLASKDIR)/access_vectors
fb0a3a98
CP
51
52# policy building support tools
3a80ec29 53SUPPORT := support
95db4228 54GENXML := $(SUPPORT)/segenxml.py
3a80ec29 55GENDOC := $(SUPPORT)/sedoctool.py
c04f2abe 56GENPERM := $(SUPPORT)/genclassperms.py
254bbc7b 57FCSORT := $(SUPPORT)/fc_sort
84eb353c 58SETTUN := $(SUPPORT)/set_tunables
3a80ec29 59
fb0a3a98
CP
60# documentation paths
61DOCS = doc
62POLXML = $(DOCS)/policy.xml
63XMLDTD = $(DOCS)/policy.dtd
64LAYERXML = metadata.xml
65HTMLDIR = $(DOCS)/html
66DOCTEMPLATE = $(DOCS)/templates
67
68# config file paths
69GLOBALTUN := $(POLDIR)/global_tunables
4f9f30c8 70GLOBALBOOL := $(POLDIR)/global_booleans
fb0a3a98
CP
71MOD_CONF := $(POLDIR)/modules.conf
72TUNABLES := $(POLDIR)/tunables.conf
4f9f30c8 73BOOLEANS := $(POLDIR)/booleans.conf
fb0a3a98
CP
74
75# install paths
76TOPDIR = $(DESTDIR)/etc/selinux
77INSTALLDIR = $(TOPDIR)/$(NAME)
78SRCPATH = $(INSTALLDIR)/src
79USERPATH = $(INSTALLDIR)/users
80CONTEXTPATH = $(INSTALLDIR)/contexts
c767b14c
CP
81MODPKGDIR = $(DESTDIR)/usr/share/selinux/$(NAME)
82
83# compile strict policy if requested.
84ifneq ($(findstring strict,$(TYPE)),)
3f026a90 85 M4PARAM += -D strict_policy
c767b14c
CP
86endif
87
88# compile targeted policy if requested.
89ifneq ($(findstring targeted,$(TYPE)),)
3f026a90 90 M4PARAM += -D targeted_policy
c767b14c 91endif
b4cd1533 92
134191be 93# enable MLS if requested.
a0824843 94ifneq ($(findstring -mls,$(TYPE)),)
3f026a90
CP
95 M4PARAM += -D enable_mls
96 CHECKPOLICY += -M
97 CHECKMODULE += -M
134191be
CP
98endif
99
a0824843
CP
100# enable MLS if MCS requested.
101ifneq ($(findstring -mcs,$(TYPE)),)
3f026a90
CP
102 M4PARAM += -D enable_mcs
103 CHECKPOLICY += -M
104 CHECKMODULE += -M
b67488e3
CP
105endif
106
25a0c61f
CP
107# enable distribution-specific policy
108ifneq ($(DISTRO),)
3f026a90 109 M4PARAM += -D distro_$(DISTRO)
25a0c61f
CP
110endif
111
b07eaef9
CP
112# enable polyinstantiation
113ifeq ($(POLY),y)
3f026a90 114 M4PARAM += -D enable_polyinstantiation
b07eaef9
CP
115endif
116
b67488e3 117ifneq ($(OUTPUT_POLICY),)
3f026a90 118 CHECKPOLICY += -c $(OUTPUT_POLICY)
b67488e3
CP
119endif
120
3f026a90
CP
121# if not set, use the type as the name.
122NAME ?= $(TYPE)
134191be 123
142e9f40 124ifeq ($(DIRECT_INITRC),y)
3f026a90 125 M4PARAM += -D direct_sysadm_daemon
142e9f40
CP
126endif
127
3f026a90 128M4PARAM += -D hide_broken_symptoms
ee7f66b0 129
37227dcd
CP
130# we need exuberant ctags; unfortunately it is named
131# differently on different distros
132ifeq ($(DISTRO),debian)
133 CTAGS := ctags-exuberant
134endif
135
136ifeq ($(DISTRO),gentoo)
137 CTAGS := exuberant-ctags
138endif
139
a4fae7fa 140CTAGS ?= ctags
37227dcd 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
fb0a3a98 152M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt)
0fbe15dc 153
c0e4fe2c 154APPCONF := config/appconfig-$(TYPE)
c9a26b3e 155APPDIR := $(CONTEXTPATH)
049e11af 156APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts customizable_types) $(CONTEXTPATH)/files/media
2926f9c7 157CONTEXTFILES += $(wildcard $(APPCONF)/*_context*) $(APPCONF)/media
bdb2fac0 158USER_FILES := $(POLDIR)/users
c9a26b3e 159
57869a68 160ALL_LAYERS := $(filter-out $(MODDIR)/CVS,$(shell find $(wildcard $(MODDIR)/*) -maxdepth 0 -type d))
e12e5738
CP
161
162GENERATED_TE := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te.in)))
163GENERATED_IF := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.if.in)))
164GENERATED_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
168DETECTED_MODS := $(sort $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te)) $(GENERATED_TE))
19db6ba5 169
fb0a3a98 170# modules.conf setting for base module
e8b3e30a 171MODBASE := base
fb0a3a98 172
e0a9001b 173# modules.conf setting for loadable module
e8b3e30a 174MODMOD := module
fb0a3a98 175
e0a9001b
CP
176# modules.conf setting for unused module
177MODUNUSED := off
178
fb0a3a98 179# extract settings from modules.conf
c767b14c
CP
180BASE_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODBASE)") print $$1 }' $(MOD_CONF) 2> /dev/null))
181MOD_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODMOD)") print $$1 }' $(MOD_CONF) 2> /dev/null))
e0a9001b 182OFF_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
189ifeq ($(MONOLITHIC),y)
190 include Rules.monolithic
191else
192 include Rules.modular
b4cd1533 193endif
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 221conf: $(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 246html: $(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#
277install-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#
325install-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#
335tags:
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 349bare: 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
357ifneq ($(GENERATED_TE),)
358 rm -f $(GENERATED_TE)
359endif
360ifneq ($(GENERATED_IF),)
361 rm -f $(GENERATED_IF)
362endif
363ifneq ($(GENERATED_FC),)
364 rm -f $(GENERATED_FC)
365endif
0fbe15dc 366
37227dcd 367.PHONY: install-src install-appconfig conf html bare tags
b8c79823
CP
368.SUFFIXES:
369.SUFFIXES: .c