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