]>
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 | |
c767b14c | 15 | APPFILES += $(APPDIR)/customizable_types $(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 | |
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)" | |
68 | ifneq ($(PV),$(KV)) | |
69 | @echo | |
70 | @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?" | |
71 | @echo | |
72 | endif | |
73 | $(QUIET) $(CHECKPOLICY) $^ -o $@ | |
74 | ||
75 | ######################################## | |
76 | # | |
77 | # Load the binary policy | |
78 | # | |
c767b14c | 79 | reload 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 | # | |
88 | policy.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 | ||
98 | tmp/pre_te_files.conf: $(PRE_TE_FILES) | |
99 | @test -d tmp || mkdir -p tmp | |
100 | $(QUIET) cat $^ > $@ | |
101 | ||
102 | tmp/generated_definitions.conf: $(ALL_LAYERS) $(ALL_TE_FILES) | |
103 | # per-userdomain templates: | |
104 | @test -d tmp || mkdir -p tmp | |
105 | $(QUIET) echo "define(\`per_userdomain_templates',\`" > $@ | |
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 | |
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 | |
122 | $(QUIET) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@ | |
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 | |
129 | $(QUIET) cat $^ > $@ | |
130 | ||
131 | tmp/post_te_files.conf: $(POST_TE_FILES) | |
132 | @test -d tmp || mkdir -p tmp | |
133 | $(QUIET) cat $^ > $@ | |
134 | ||
135 | # extract attributes and put them first. extract post te stuff | |
136 | # like genfscon and put last. portcon, nodecon, and netifcon | |
137 | # is delayed since they are generated by m4 | |
138 | tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf | |
139 | $(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true | |
140 | $(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf | |
141 | $(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf | |
142 | $(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true | |
143 | $(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true | |
144 | $(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true | |
145 | $(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \ | |
146 | -e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \ | |
147 | < tmp/all_te_files.conf > tmp/only_te_rules.conf | |
148 | ||
149 | ######################################## | |
150 | # | |
151 | # Remove the dontaudit rules from the policy.conf | |
152 | # | |
153 | enableaudit: policy.conf | |
154 | @test -d tmp || mkdir -p tmp | |
155 | @echo "Removing dontaudit rules from policy.conf" | |
156 | $(QUIET) grep -v dontaudit policy.conf > tmp/policy.audit | |
157 | $(QUIET) mv tmp/policy.audit policy.conf | |
158 | ||
159 | ######################################## | |
160 | # | |
161 | # Construct file_contexts | |
162 | # | |
c767b14c CP |
163 | $(FC): tmp/$(FC).tmp $(FCSORT) |
164 | $(QUIET) $(FCSORT) $< $@ | |
165 | $(QUIET) grep -e HOME -e ROLE $@ > $(HOMEDIR_TEMPLATE) | |
166 | $(QUIET) sed -i -e /HOME/d -e /ROLE/d $@ | |
167 | ||
168 | tmp/$(FC).tmp: $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES) | |
fb0a3a98 CP |
169 | ifeq ($(ALL_FC_FILES),) |
170 | $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") | |
171 | endif | |
172 | @echo "Creating $(NAME) file_contexts." | |
173 | @test -d tmp || mkdir -p tmp | |
c767b14c | 174 | $(QUIET) m4 $(M4PARAM) $^ > $@ |
fb0a3a98 CP |
175 | |
176 | ######################################## | |
177 | # | |
178 | # Install file_contexts | |
179 | # | |
180 | $(FCPATH): $(FC) $(LOADPATH) $(USERPATH)/system.users | |
181 | @echo "Validating $(NAME) file_contexts." | |
182 | $(QUIET) $(SETFILES) -q -c $(LOADPATH) $(FC) | |
183 | @echo "Installing file_contexts." | |
184 | @mkdir -p $(CONTEXTPATH)/files | |
185 | $(QUIET) install -m 644 $(FC) $(FCPATH) | |
186 | $(QUIET) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH) | |
187 | $(QUIET) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(NAME) $(USEPWD) | |
188 | ||
189 | ######################################## | |
190 | # | |
191 | # Filesystem labeling | |
192 | # | |
193 | FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';` | |
194 | ||
c767b14c CP |
195 | checklabels: $(FCPATH) $(SETFILES) |
196 | @echo "Checking labels on filesystem types: ext2 ext3 xfs jfs" | |
fb0a3a98 CP |
197 | @if test -z "$(FILESYSTEMS)"; then \ |
198 | echo "No filesystems with extended attributes found!" ;\ | |
199 | false ;\ | |
200 | fi | |
c767b14c | 201 | $(QUIET) $(SETFILES) -v -n $(FCPATH) $(FILESYSTEMS) |
fb0a3a98 | 202 | |
c767b14c CP |
203 | restorelabels: $(FCPATH) $(SETFILES) |
204 | @echo "Restoring labels on filesystem types: ext2 ext3 xfs jfs" | |
fb0a3a98 CP |
205 | @if test -z "$(FILESYSTEMS)"; then \ |
206 | echo "No filesystems with extended attributes found!" ;\ | |
207 | false ;\ | |
208 | fi | |
c767b14c | 209 | $(QUIET) $(SETFILES) -v $(FCPATH) $(FILESYSTEMS) |
fb0a3a98 | 210 | |
c767b14c CP |
211 | relabel: $(FCPATH) $(SETFILES) |
212 | @echo "Relabeling filesystem types: ext2 ext3 xfs jfs" | |
fb0a3a98 CP |
213 | @if test -z "$(FILESYSTEMS)"; then \ |
214 | echo "No filesystems with extended attributes found!" ;\ | |
215 | false ;\ | |
216 | fi | |
c767b14c | 217 | $(QUIET) $(SETFILES) $(FCPATH) $(FILESYSTEMS) |
fb0a3a98 | 218 | |
8df65f13 CP |
219 | ######################################## |
220 | # | |
221 | # Run policy source checks | |
222 | # | |
223 | check: policy.conf $(FC) | |
224 | $(SECHECK) -s --profile=development --policy=policy.conf --fcfile=$(FC) > $@.res | |
225 | ||
226 | longcheck: policy.conf $(FC) | |
227 | $(SECHECK) -s --profile=all --policy=policy.conf --fcfile=$(FC) > $@.res | |
228 | ||
fb0a3a98 CP |
229 | ######################################## |
230 | # | |
231 | # Clean the sources | |
232 | # | |
233 | clean: | |
fb0a3a98 CP |
234 | rm -f policy.conf |
235 | rm -f policy.$(PV) | |
236 | rm -f $(FC) | |
c767b14c | 237 | rm -f $(HOMEDIR_TEMPLATE) |
8df65f13 | 238 | rm -f *.res |
c767b14c | 239 | rm -fR tmp |
fb0a3a98 | 240 | |
8df65f13 | 241 | .PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean |