]>
Commit | Line | Data |
---|---|---|
fb0a3a98 CP |
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 | ||
c767b14c CP |
12 | FC := file_contexts |
13 | POLVER := policy.$(PV) | |
2ed0d184 | 14 | |
049e11af | 15 | APPFILES += $(INSTALLDIR)/booleans |
fb0a3a98 | 16 | |
c767b14c | 17 | # for monolithic policy use all base and module to create policy |
cf0ff557 | 18 | ALL_MODULES := $(strip $(BASE_MODS) $(MOD_MODS)) |
fb0a3a98 CP |
19 | |
20 | ALL_INTERFACES := $(ALL_MODULES:.te=.if) | |
21 | ALL_TE_FILES := $(ALL_MODULES) | |
22 | ALL_FC_FILES := $(ALL_MODULES:.te=.fc) | |
23 | ||
a0824843 | 24 | PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs |
ffd04848 | 25 | POST_TE_FILES := $(USER_FILES) $(POLDIR)/constraints |
fb0a3a98 | 26 | |
4f9f30c8 | 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 |
fb0a3a98 | 28 | |
c767b14c CP |
29 | HOMEDIR_TEMPLATE = homedir_template |
30 | ||
31 | # search layer dirs for source files | |
32 | vpath %.te $(ALL_LAYERS) | |
33 | vpath %.if $(ALL_LAYERS) | |
34 | vpath %.fc $(ALL_LAYERS) | |
35 | ||
fb0a3a98 CP |
36 | ######################################## |
37 | # | |
38 | # default action: build policy locally | |
39 | # | |
40 | default: policy | |
41 | ||
42 | policy: $(POLVER) | |
43 | ||
44 | install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users | |
45 | ||
46 | load: tmp/load | |
47 | ||
48 | ######################################## | |
49 | # | |
50 | # Build a binary policy locally | |
51 | # | |
52 | $(POLVER): policy.conf | |
53 | @echo "Compiling $(NAME) $(POLVER)" | |
54 | ifneq ($(PV),$(KV)) | |
55 | @echo | |
56 | @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?" | |
57 | @echo | |
58 | endif | |
9b3756bf | 59 | $(verbose) $(CHECKPOLICY) $^ -o $@ |
fb0a3a98 CP |
60 | |
61 | ######################################## | |
62 | # | |
63 | # Install a binary policy | |
64 | # | |
65 | $(LOADPATH): policy.conf | |
66 | @mkdir -p $(POLICYPATH) | |
67 | @echo "Compiling and installing $(NAME) $(LOADPATH)" | |
68 | ifneq ($(PV),$(KV)) | |
69 | @echo | |
70 | @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?" | |
71 | @echo | |
72 | endif | |
9b3756bf | 73 | $(verbose) $(CHECKPOLICY) $^ -o $@ |
fb0a3a98 CP |
74 | |
75 | ######################################## | |
76 | # | |
77 | # Load the binary policy | |
78 | # | |
c767b14c | 79 | reload tmp/load: $(LOADPATH) $(FCPATH) $(APPFILES) |
fb0a3a98 | 80 | @echo "Loading $(NAME) $(LOADPATH)" |
9b3756bf | 81 | $(verbose) $(LOADPOLICY) -q $(LOADPATH) |
fb0a3a98 CP |
82 | @touch tmp/load |
83 | ||
84 | ######################################## | |
85 | # | |
86 | # Construct a monolithic policy.conf | |
87 | # | |
88 | policy.conf: $(POLICY_SECTIONS) | |
89 | @echo "Creating $(NAME) policy.conf" | |
90 | # checkpolicy can use the #line directives provided by -s for error reporting: | |
9b3756bf CP |
91 | $(verbose) m4 -D self_contained_policy $(M4PARAM) -s $^ > tmp/$@.tmp |
92 | $(verbose) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@ | |
fb0a3a98 | 93 | # the ordering of these ocontexts matters: |
9b3756bf CP |
94 | $(verbose) grep ^portcon tmp/$@.tmp >> $@ || true |
95 | $(verbose) grep ^netifcon tmp/$@.tmp >> $@ || true | |
96 | $(verbose) grep ^nodecon tmp/$@.tmp >> $@ || true | |
fb0a3a98 CP |
97 | |
98 | tmp/pre_te_files.conf: $(PRE_TE_FILES) | |
99 | @test -d tmp || mkdir -p tmp | |
9b3756bf | 100 | $(verbose) cat $^ > $@ |
fb0a3a98 | 101 | |
6b1c8ee3 | 102 | tmp/generated_definitions.conf: $(ALL_TE_FILES) |
fb0a3a98 CP |
103 | # per-userdomain templates: |
104 | @test -d tmp || mkdir -p tmp | |
9b3756bf CP |
105 | $(verbose) echo "define(\`base_per_userdomain_template',\`" > $@ |
106 | $(verbose) 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 | |
9b3756bf | 110 | $(verbose) echo "')" >> $@ |
fb0a3a98 | 111 | # define foo.te |
9b3756bf | 112 | $(verbose) for i in $(notdir $(ALL_MODULES)); do \ |
fb0a3a98 CP |
113 | echo "define(\`$$i')" >> $@ ;\ |
114 | done | |
9b3756bf | 115 | $(verbose) $(SETTUN) $(BOOLEANS) >> $@ |
fb0a3a98 CP |
116 | |
117 | tmp/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES) | |
118 | ifeq ($(ALL_INTERFACES),) | |
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 | |
9b3756bf | 122 | $(verbose) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@ |
fb0a3a98 CP |
123 | |
124 | tmp/all_te_files.conf: $(ALL_TE_FILES) | |
125 | ifeq ($(ALL_TE_FILES),) | |
126 | $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") | |
127 | endif | |
128 | @test -d tmp || mkdir -p tmp | |
9b3756bf | 129 | $(verbose) cat $^ > $@ |
4ace0fa5 | 130 | $(call parse-rolemap,base,$@) |
fb0a3a98 CP |
131 | |
132 | tmp/post_te_files.conf: $(POST_TE_FILES) | |
133 | @test -d tmp || mkdir -p tmp | |
9b3756bf | 134 | $(verbose) cat $^ > $@ |
fb0a3a98 CP |
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 | |
139 | tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf | |
9b3756bf CP |
140 | $(verbose) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true |
141 | $(verbose) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf | |
142 | $(verbose) cat tmp/post_te_files.conf > tmp/all_post.conf | |
143 | $(verbose) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true | |
144 | $(verbose) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true | |
145 | $(verbose) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true | |
146 | $(verbose) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \ | |
fb0a3a98 CP |
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 | # | |
154 | enableaudit: policy.conf | |
155 | @test -d tmp || mkdir -p tmp | |
156 | @echo "Removing dontaudit rules from policy.conf" | |
9b3756bf CP |
157 | $(verbose) grep -v dontaudit policy.conf > tmp/policy.audit |
158 | $(verbose) mv tmp/policy.audit policy.conf | |
fb0a3a98 CP |
159 | |
160 | ######################################## | |
161 | # | |
162 | # Construct file_contexts | |
163 | # | |
c767b14c | 164 | $(FC): tmp/$(FC).tmp $(FCSORT) |
9b3756bf CP |
165 | $(verbose) $(FCSORT) $< $@ |
166 | $(verbose) grep -e HOME -e ROLE $@ > $(HOMEDIR_TEMPLATE) | |
167 | $(verbose) sed -i -e /HOME/d -e /ROLE/d $@ | |
c767b14c CP |
168 | |
169 | tmp/$(FC).tmp: $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES) | |
fb0a3a98 CP |
170 | ifeq ($(ALL_FC_FILES),) |
171 | $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") | |
172 | endif | |
173 | @echo "Creating $(NAME) file_contexts." | |
174 | @test -d tmp || mkdir -p tmp | |
9b3756bf | 175 | $(verbose) 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." | |
9b3756bf | 183 | $(verbose) $(SETFILES) -q -c $(LOADPATH) $(FC) |
fb0a3a98 CP |
184 | @echo "Installing file_contexts." |
185 | @mkdir -p $(CONTEXTPATH)/files | |
9b3756bf CP |
186 | $(verbose) install -m 644 $(FC) $(FCPATH) |
187 | $(verbose) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH) | |
188 | $(verbose) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(NAME) $(USEPWD) | |
fb0a3a98 CP |
189 | |
190 | ######################################## | |
191 | # | |
192 | # Filesystem labeling | |
193 | # | |
194 | FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';` | |
195 | ||
c767b14c CP |
196 | checklabels: $(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 | |
9b3756bf | 202 | $(verbose) $(SETFILES) -v -n $(FCPATH) $(FILESYSTEMS) |
fb0a3a98 | 203 | |
c767b14c CP |
204 | restorelabels: $(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 | |
9b3756bf | 210 | $(verbose) $(SETFILES) -v $(FCPATH) $(FILESYSTEMS) |
fb0a3a98 | 211 | |
c767b14c CP |
212 | relabel: $(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 | |
9b3756bf | 218 | $(verbose) $(SETFILES) $(FCPATH) $(FILESYSTEMS) |
fb0a3a98 | 219 | |
8df65f13 CP |
220 | ######################################## |
221 | # | |
222 | # Run policy source checks | |
223 | # | |
224 | check: policy.conf $(FC) | |
225 | $(SECHECK) -s --profile=development --policy=policy.conf --fcfile=$(FC) > $@.res | |
226 | ||
227 | longcheck: 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) | |
9b3756bf CP |
236 | $(verbose) grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > tmp/customizable_types |
237 | $(verbose) install -m 644 tmp/customizable_types $@ | |
049e11af | 238 | |
fb0a3a98 CP |
239 | ######################################## |
240 | # | |
241 | # Clean the sources | |
242 | # | |
243 | clean: | |
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 |