]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/Rules.monolithic
add text for rolemap
[people/stevee/selinux-policy.git] / refpolicy / Rules.monolithic
CommitLineData
fb0a3a98
CP
1########################################
2#
3# Rules and Targets for building monolithic policies
4#
5
6# install paths
7POLICYPATH = $(INSTALLDIR)/policy
8LOADPATH = $(POLICYPATH)/$(POLVER)
9FCPATH = $(CONTEXTPATH)/files/file_contexts
10HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
11
c767b14c
CP
12FC := file_contexts
13POLVER := policy.$(PV)
2ed0d184 14
049e11af 15APPFILES += $(INSTALLDIR)/booleans
fb0a3a98 16
c767b14c 17# for monolithic policy use all base and module to create policy
cf0ff557 18ALL_MODULES := $(strip $(BASE_MODS) $(MOD_MODS))
fb0a3a98
CP
19
20ALL_INTERFACES := $(ALL_MODULES:.te=.if)
21ALL_TE_FILES := $(ALL_MODULES)
22ALL_FC_FILES := $(ALL_MODULES:.te=.fc)
23
a0824843 24PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
ffd04848 25POST_TE_FILES := $(USER_FILES) $(POLDIR)/constraints
fb0a3a98 26
4f9f30c8 27POLICY_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attrs_types.conf $(GLOBALBOOL) $(GLOBALTUN) tmp/only_te_rules.conf tmp/all_post.conf
fb0a3a98 28
c767b14c
CP
29HOMEDIR_TEMPLATE = homedir_template
30
31# search layer dirs for source files
32vpath %.te $(ALL_LAYERS)
33vpath %.if $(ALL_LAYERS)
34vpath %.fc $(ALL_LAYERS)
35
fb0a3a98
CP
36########################################
37#
38# default action: build policy locally
39#
40default: policy
41
42policy: $(POLVER)
43
44install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
45
46load: tmp/load
47
48########################################
49#
50# Build a binary policy locally
51#
52$(POLVER): policy.conf
53 @echo "Compiling $(NAME) $(POLVER)"
54ifneq ($(PV),$(KV))
55 @echo
56 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
57 @echo
58endif
59 $(QUIET) $(CHECKPOLICY) $^ -o $@
60
61########################################
62#
63# Install a binary policy
64#
65$(LOADPATH): policy.conf
66 @mkdir -p $(POLICYPATH)
67 @echo "Compiling and installing $(NAME) $(LOADPATH)"
68ifneq ($(PV),$(KV))
69 @echo
70 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
71 @echo
72endif
73 $(QUIET) $(CHECKPOLICY) $^ -o $@
74
75########################################
76#
77# Load the binary policy
78#
c767b14c 79reload tmp/load: $(LOADPATH) $(FCPATH) $(APPFILES)
fb0a3a98
CP
80 @echo "Loading $(NAME) $(LOADPATH)"
81 $(QUIET) $(LOADPOLICY) -q $(LOADPATH)
82 @touch tmp/load
83
84########################################
85#
86# Construct a monolithic policy.conf
87#
88policy.conf: $(POLICY_SECTIONS)
89 @echo "Creating $(NAME) policy.conf"
90# checkpolicy can use the #line directives provided by -s for error reporting:
0e15cdfb 91 $(QUIET) m4 -D self_contained_policy $(M4PARAM) -s $^ > tmp/$@.tmp
fb0a3a98
CP
92 $(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
93# the ordering of these ocontexts matters:
94 $(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true
95 $(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true
96 $(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true
97
98tmp/pre_te_files.conf: $(PRE_TE_FILES)
99 @test -d tmp || mkdir -p tmp
100 $(QUIET) cat $^ > $@
101
6b1c8ee3 102tmp/generated_definitions.conf: $(ALL_TE_FILES)
fb0a3a98
CP
103# per-userdomain templates:
104 @test -d tmp || mkdir -p tmp
4ace0fa5 105 $(QUIET) echo "define(\`base_per_userdomain_template',\`" > $@
fb0a3a98 106 $(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \
2a94561a 107 echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$*'")')" \
fb0a3a98
CP
108 >> $@ ;\
109 done
110 $(QUIET) echo "')" >> $@
111# define foo.te
112 $(QUIET) for i in $(notdir $(ALL_MODULES)); do \
113 echo "define(\`$$i')" >> $@ ;\
114 done
4f9f30c8 115 $(QUIET) $(SETTUN) $(BOOLEANS) >> $@
fb0a3a98
CP
116
117tmp/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES)
118ifeq ($(ALL_INTERFACES),)
119 $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
120endif
121 @test -d tmp || mkdir -p tmp
122 $(QUIET) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
123
124tmp/all_te_files.conf: $(ALL_TE_FILES)
125ifeq ($(ALL_TE_FILES),)
126 $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
127endif
128 @test -d tmp || mkdir -p tmp
129 $(QUIET) cat $^ > $@
4ace0fa5 130 $(call parse-rolemap,base,$@)
fb0a3a98
CP
131
132tmp/post_te_files.conf: $(POST_TE_FILES)
133 @test -d tmp || mkdir -p tmp
134 $(QUIET) cat $^ > $@
135
136# extract attributes and put them first. extract post te stuff
137# like genfscon and put last. portcon, nodecon, and netifcon
138# is delayed since they are generated by m4
139tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf
140 $(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true
141 $(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf
142 $(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf
143 $(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true
144 $(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true
145 $(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
146 $(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \
147 -e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \
148 < tmp/all_te_files.conf > tmp/only_te_rules.conf
149
150########################################
151#
152# Remove the dontaudit rules from the policy.conf
153#
154enableaudit: policy.conf
155 @test -d tmp || mkdir -p tmp
156 @echo "Removing dontaudit rules from policy.conf"
157 $(QUIET) grep -v dontaudit policy.conf > tmp/policy.audit
158 $(QUIET) mv tmp/policy.audit policy.conf
159
160########################################
161#
162# Construct file_contexts
163#
c767b14c
CP
164$(FC): tmp/$(FC).tmp $(FCSORT)
165 $(QUIET) $(FCSORT) $< $@
166 $(QUIET) grep -e HOME -e ROLE $@ > $(HOMEDIR_TEMPLATE)
167 $(QUIET) sed -i -e /HOME/d -e /ROLE/d $@
168
169tmp/$(FC).tmp: $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES)
fb0a3a98
CP
170ifeq ($(ALL_FC_FILES),)
171 $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
172endif
173 @echo "Creating $(NAME) file_contexts."
174 @test -d tmp || mkdir -p tmp
c767b14c 175 $(QUIET) m4 $(M4PARAM) $^ > $@
fb0a3a98
CP
176
177########################################
178#
179# Install file_contexts
180#
181$(FCPATH): $(FC) $(LOADPATH) $(USERPATH)/system.users
182 @echo "Validating $(NAME) file_contexts."
183 $(QUIET) $(SETFILES) -q -c $(LOADPATH) $(FC)
184 @echo "Installing file_contexts."
185 @mkdir -p $(CONTEXTPATH)/files
186 $(QUIET) install -m 644 $(FC) $(FCPATH)
187 $(QUIET) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH)
188 $(QUIET) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(NAME) $(USEPWD)
189
190########################################
191#
192# Filesystem labeling
193#
194FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';`
195
c767b14c
CP
196checklabels: $(FCPATH) $(SETFILES)
197 @echo "Checking labels on filesystem types: ext2 ext3 xfs jfs"
fb0a3a98
CP
198 @if test -z "$(FILESYSTEMS)"; then \
199 echo "No filesystems with extended attributes found!" ;\
200 false ;\
201 fi
c767b14c 202 $(QUIET) $(SETFILES) -v -n $(FCPATH) $(FILESYSTEMS)
fb0a3a98 203
c767b14c
CP
204restorelabels: $(FCPATH) $(SETFILES)
205 @echo "Restoring labels on filesystem types: ext2 ext3 xfs jfs"
fb0a3a98
CP
206 @if test -z "$(FILESYSTEMS)"; then \
207 echo "No filesystems with extended attributes found!" ;\
208 false ;\
209 fi
c767b14c 210 $(QUIET) $(SETFILES) -v $(FCPATH) $(FILESYSTEMS)
fb0a3a98 211
c767b14c
CP
212relabel: $(FCPATH) $(SETFILES)
213 @echo "Relabeling filesystem types: ext2 ext3 xfs jfs"
fb0a3a98
CP
214 @if test -z "$(FILESYSTEMS)"; then \
215 echo "No filesystems with extended attributes found!" ;\
216 false ;\
217 fi
c767b14c 218 $(QUIET) $(SETFILES) $(FCPATH) $(FILESYSTEMS)
fb0a3a98 219
8df65f13
CP
220########################################
221#
222# Run policy source checks
223#
224check: policy.conf $(FC)
225 $(SECHECK) -s --profile=development --policy=policy.conf --fcfile=$(FC) > $@.res
226
227longcheck: policy.conf $(FC)
228 $(SECHECK) -s --profile=all --policy=policy.conf --fcfile=$(FC) > $@.res
229
049e11af
CP
230########################################
231#
232# Appconfig files
233#
234$(APPDIR)/customizable_types: policy.conf
235 @mkdir -p $(APPDIR)
236 $(QUIET) grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > tmp/customizable_types
237 $(QUIET) install -m 644 tmp/customizable_types $@
238
fb0a3a98
CP
239########################################
240#
241# Clean the sources
242#
243clean:
fb0a3a98
CP
244 rm -f policy.conf
245 rm -f policy.$(PV)
246 rm -f $(FC)
c767b14c 247 rm -f $(HOMEDIR_TEMPLATE)
8df65f13 248 rm -f *.res
c767b14c 249 rm -fR tmp
fb0a3a98 250
8df65f13 251.PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean