]> git.ipfire.org Git - people/stevee/selinux-policy.git/blob - refpolicy/Rules.monolithic
add fc mls policy
[people/stevee/selinux-policy.git] / refpolicy / Rules.monolithic
1 ########################################
2 #
3 # Rules and Targets for building monolithic policies
4 #
5
6 # install paths
7 POLICYPATH = $(INSTALLDIR)/policy
8 LOADPATH = $(POLICYPATH)/$(POLVER)
9 FCPATH = $(CONTEXTPATH)/files/file_contexts
10 HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
11
12 # Monolithic still uses booleans file
13 APPFILES += $(INSTALLDIR)/booleans
14
15 # for monolithic policy use all base and module to create policy
16 ENABLEMOD := $(BASE_MODS) $(MOD_MODS)
17
18 ALL_MODULES := $(filter $(ENABLEMOD),$(DETECTED_MODS))
19
20 ALL_INTERFACES := $(ALL_MODULES:.te=.if)
21 ALL_TE_FILES := $(ALL_MODULES)
22 ALL_FC_FILES := $(ALL_MODULES:.te=.fc)
23
24 PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
25 POST_TE_FILES := $(POLDIR)/systemuser $(POLDIR)/users $(POLDIR)/constraints
26
27 POLICY_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
28
29 ########################################
30 #
31 # default action: build policy locally
32 #
33 default: policy
34
35 policy: $(POLVER)
36
37 install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
38
39 load: tmp/load
40
41 ########################################
42 #
43 # Build a binary policy locally
44 #
45 $(POLVER): policy.conf
46 @echo "Compiling $(NAME) $(POLVER)"
47 ifneq ($(PV),$(KV))
48 @echo
49 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
50 @echo
51 endif
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)"
61 ifneq ($(PV),$(KV))
62 @echo
63 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
64 @echo
65 endif
66 $(QUIET) $(CHECKPOLICY) $^ -o $@
67
68 ########################################
69 #
70 # Load the binary policy
71 #
72 reload 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 #
81 policy.conf: $(POLICY_SECTIONS)
82 @echo "Creating $(NAME) policy.conf"
83 # checkpolicy can use the #line directives provided by -s for error reporting:
84 $(QUIET) m4 -D self_contained_policy $(M4PARAM) -s $^ > tmp/$@.tmp
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
91 tmp/pre_te_files.conf: $(PRE_TE_FILES)
92 @test -d tmp || mkdir -p tmp
93 $(QUIET) cat $^ > $@
94
95 tmp/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 \
100 echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$*'")')" \
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
108 $(QUIET) $(SETTUN) $(BOOLEANS) >> $@
109
110 tmp/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES)
111 ifeq ($(ALL_INTERFACES),)
112 $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
113 endif
114 @test -d tmp || mkdir -p tmp
115 $(QUIET) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
116
117 tmp/all_te_files.conf: $(ALL_TE_FILES)
118 ifeq ($(ALL_TE_FILES),)
119 $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
120 endif
121 @test -d tmp || mkdir -p tmp
122 $(QUIET) cat $^ > $@
123
124 tmp/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
131 tmp/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 #
146 enableaudit: 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)
157 ifeq ($(ALL_FC_FILES),)
158 $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
159 endif
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 #
184 FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';`
185
186 checklabels: $(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
193 restorelabels: $(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
200 relabel: $(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
207 ########################################
208 #
209 # Run policy source checks
210 #
211 check: policy.conf $(FC)
212 $(SECHECK) -s --profile=development --policy=policy.conf --fcfile=$(FC) > $@.res
213
214 longcheck: policy.conf $(FC)
215 $(SECHECK) -s --profile=all --policy=policy.conf --fcfile=$(FC) > $@.res
216
217 ########################################
218 #
219 # Clean the sources
220 #
221 clean:
222 rm -fR tmp
223 rm -f policy.conf
224 rm -f policy.$(PV)
225 rm -f $(FC)
226 rm -f *.res
227
228 .PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean