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