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