]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/Makefile
cleanup for corenetwork interface generation
[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
23# Build compatibility policies
24POLICYCOMPAT = -c 18
25
26# set distribution
27#override M4PARAM += -D distro_redhat
28
29# Uncomment this to disable command echoing
30#QUIET:=@
31
32########################################
33#
34# Invariant portions of the Makefile
35#
36
37# executable paths
38PREFIX := /usr
39BINDIR := $(PREFIX)/bin
40SBINDIR := $(PREFIX)/sbin
41CHECKPOLICY := $(BINDIR)/checkpolicy
42SETFILES := $(SBINDIR)/setfiles
43
44# determine the policy version and current kernel version if possible
45PV := $(shell $(CHECKPOLICY) $(POLICYCOMPAT) -V |cut -f 1 -d ' ')
46KV := $(shell cat /selinux/policyvers)
47
48# dont print version warnings if we are unable to determine
49# the currently running kernel's policy version
50ifeq ($(KV),)
51KV := $(PV)
52endif
53
54FC := file_contexts
55POLVER := policy.$(PV)
56TYPE := strict
57
58# install paths
59TOPDIR = $(DESTDIR)/etc/selinux
60INSTALLDIR = $(TOPDIR)/$(TYPE)
61POLICYPATH = $(INSTALLDIR)/policy
62SRCPATH = $(INSTALLDIR)/src
63USERPATH = $(INSTALLDIR)/users
64CONTEXTPATH = $(INSTALLDIR)/contexts
65LOADPATH = $(POLICYPATH)/$(POLVER)
66FCPATH = $(CONTEXTPATH)/files/file_contexts
67HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
68
69BASE_MODULE = kernel
70FLASKDIR = $(BASE_MODULE)/flask/
71MISCDIR = $(BASE_MODULE)/misc/
72
73DETECTED_DIRS := $(shell find $(wildcard *) -maxdepth 0 -type d)
74ALL_MODULES := $(filter-out tmp,$(DETECTED_DIRS))
75
76PRE_TE_FILES := $(addprefix $(FLASKDIR),security_classes initial_sids access_vectors)
77ALL_INTERFACES := $(foreach dir,$(ALL_MODULES),$(wildcard $(dir)/*.if))
78ALL_TE_FILES := $(foreach dir,$(ALL_MODULES),$(wildcard $(dir)/*.te))
099c8b24 79POST_TE_FILES := $(addprefix $(MISCDIR),users constraints mls initial_sid_contexts fs_use)
b4cd1533
CP
80
81ALL_FC_FILES := $(foreach dir,$(ALL_MODULES),$(wildcard $(dir)/*.fc))
82
f66a1af9 83POLICY_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf
b4cd1533
CP
84
85override M4PARAM += -D monolithic_policy
86
87########################################
88#
89# default action: build policy locally
90#
91default: policy
92
93policy: $(POLVER)
94
95install: $(LOADPATH)
96
97########################################
98#
99# Build a binary policy locally
100#
101$(POLVER): policy.conf
88c72f44 102 @echo "Compiling $(POLVER)"
b4cd1533
CP
103ifneq ($(PV),$(KV))
104 @echo
105 @echo "WARNING: Policy version mismatch! Is your POLICYCOMPAT set correctly?"
106 @echo
107endif
88c72f44 108 $(QUIET) $(CHECKPOLICY) $(POLICYCOMPAT) $^ -o $@
b4cd1533
CP
109
110########################################
111#
112# Install a binary policy
113#
114$(LOADPATH): policy.conf
115 @mkdir -p $(POLICYPATH)
88c72f44 116 @echo "Compiling and installing $(LOADPATH)"
b4cd1533
CP
117ifneq ($(PV),$(KV))
118 @echo
119 @echo "WARNING: Policy version mismatch! Is your POLICYCOMPAT set correctly?"
120 @echo
121endif
88c72f44 122 $(QUIET) $(CHECKPOLICY) $(POLICYCOMPAT) $^ -o $@
b4cd1533 123
88d14a22
CP
124########################################
125#
126# Load the binary policy
127#
128reload tmp/load: $(LOADPATH) $(FCPATH)
88c72f44 129 @echo "Loading $(LOADPATH)"
88d14a22
CP
130 $(QUIET) $(LOADPOLICY) -q $(LOADPATH)
131 @touch tmp/load
132
133load: tmp/load
134
b4cd1533
CP
135########################################
136#
137# Construct a monolithic policy.conf
138#
139policy.conf: $(POLICY_SECTIONS)
88c72f44
CP
140 @echo "Creating policy.conf"
141# checkpolicy can use the #line directives provided by -s for error reporting:
bd202fe1 142 $(QUIET) m4 $(M4PARAM) -s $^ > tmp/$@.tmp
b4cd1533 143 $(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
88c72f44 144# the ordering of these ocontexts matters:
b4cd1533
CP
145 $(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true
146 $(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true
147 $(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true
148
149tmp/pre_te_files.conf: $(PRE_TE_FILES)
150 @test -d tmp || mkdir -p tmp
151 $(QUIET) cat $^ > $@
152
153tmp/generated_definitions.conf: $(ALL_MODULES) $(ALL_TE_FILES) $(BASE_MODULE)/corenetwork.if $(BASE_MODULE)/corenetwork.te
154 @test -d tmp || mkdir -p tmp
155 $(QUIET) echo "define(\`per_userdomain_templates',\`" > $@
0634b6e7 156 $(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_TE_FILES))); do \
b4cd1533
CP
157 echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$1'")')" \
158 >> $@ ;\
159 done
160 $(QUIET) echo "')" >> $@
161 $(QUIET) for i in $(notdir $(ALL_TE_FILES)); do \
162 echo "define(\`$$i')" >> $@ ;\
163 done
6276f101
CP
164 $(QUIET) grep -E "^network_(interface|node|port)\(.*\)" $(BASE_MODULE)/corenetwork.te \
165 | m4 $(M4PARAM) -D interface_pass $(BASE_MODULE)/global.if $(BASE_MODULE)/corenetwork.if - \
bd202fe1 166 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
88c72f44
CP
167# this is so the xml works:
168 $(QUIET) echo "## </module>" >> $@
b4cd1533
CP
169
170tmp/all_interfaces.conf: $(ALL_INTERFACES)
171 @test -d tmp || mkdir -p tmp
172 $(QUIET) cat $^ > $@
173
174tmp/all_te_files.conf: $(ALL_TE_FILES)
175 @test -d tmp || mkdir -p tmp
176 $(QUIET) cat $^ > $@
177
178tmp/post_te_files.conf: $(POST_TE_FILES)
179 @test -d tmp || mkdir -p tmp
180 $(QUIET) cat $^ > $@
181
182# extract attributes and put them first. extract post te stuff
183# like genfscon and put last. portcon, nodecon, and netifcon
184# is delayed since they are generated by m4
f66a1af9
CP
185tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf
186 $(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true
187 $(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf
b4cd1533
CP
188 $(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf
189 $(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
f66a1af9 190 $(QUIET) sed -e /^attribute/d -e '/^type /d' -e /^genfscon/d < tmp/all_te_files.conf > tmp/only_te_rules.conf
b4cd1533 191
88d14a22
CP
192########################################
193#
194# Remove the dontaudit rules from the policy.conf
195#
196enableaudit: policy.conf
197 @test -d tmp || mkdir -p tmp
198 @echo "Removing dontaudit rules from policy.conf"
199 $(QUIET) grep -v dontaudit policy.conf > tmp/policy.audit
200 $(QUIET) mv tmp/policy.audit policy.conf
201
6d314fd3
CP
202########################################
203#
204# Construct file_contexts
205#
206$(FC): kernel/global.if $(ALL_FC_FILES)
207 @test -d tmp || mkdir -p tmp
208 $(QUIET) m4 $(M4PARAM) $^ > $@
209
b4cd1533
CP
210########################################
211#
212# Filesystem labeling
213#
88d14a22 214FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';`
b4cd1533 215
88d14a22
CP
216checklabels: $(FC) $(SETFILES)
217 @if test -z "$(FILESYSTEMS)"; then \
218 echo "No filesystems with extended attributes found!" ;\
219 false ;\
220 fi
b4cd1533
CP
221 $(QUIET) $(SETFILES) -v -n $(FC) $(FILESYSTEMS)
222
88d14a22
CP
223restorelabels: $(FC) $(SETFILES)
224 @if test -z "$(FILESYSTEMS)"; then \
225 echo "No filesystems with extended attributes found!" ;\
226 false ;\
227 fi
b4cd1533
CP
228 $(QUIET) $(SETFILES) -v $(FC) $(FILESYSTEMS)
229
230relabel: $(FC) $(SETFILES)
88d14a22
CP
231 @if test -z "$(FILESYSTEMS)"; then \
232 echo "No filesystems with extended attributes found!" ;\
233 false ;\
234 fi
b4cd1533
CP
235 $(QUIET) $(SETFILES) $(FC) $(FILESYSTEMS)
236
6d314fd3
CP
237########################################
238#
239# Documentation generation
240#
241
242xml: policy.xml
243
244policy.xml: $(ALL_INTERFACES) tmp/generated_definitions.conf
88c72f44
CP
245 @echo "Creating $@"
246 $(QUIET) echo "<policy>" > $@
247 $(QUIET) grep -h -E "^##[[:space:]]" $^ | sed -e 's/^##[[:space:]]//g' >> $@
248 $(QUIET) echo "</policy>" >> $@
6d314fd3 249
b4cd1533
CP
250clean:
251 rm -fR tmp
6d314fd3 252 rm -f policy.xml
b4cd1533
CP
253 rm -f policy.conf
254 rm -f policy.$(PV)
255 rm -f $(FC)
256
88c72f44 257.PHONY: default policy install reload enableaudit checklabels restorelabels relabel xml clean