]>
Commit | Line | Data |
---|---|---|
fb0a3a98 CP |
1 | ######################################## |
2 | # | |
3 | # Rules and Targets for building monolithic policies | |
4 | # | |
5 | ||
5b45ffb0 CP |
6 | POLICY_CONF = $(BUILDDIR)policy.conf |
7 | FC = $(BUILDDIR)file_contexts | |
8 | POLVER = $(BUILDDIR)policy.$(PV) | |
9 | HOMEDIR_TEMPLATE = $(BUILDDIR)homedir_template | |
c9f20d5b | 10 | |
3abd5ee8 CP |
11 | M4PARAM += -D self_contained_policy |
12 | ||
fb0a3a98 CP |
13 | # install paths |
14 | POLICYPATH = $(INSTALLDIR)/policy | |
5b45ffb0 | 15 | LOADPATH = $(POLICYPATH)/$(notdir $(POLVER)) |
fb0a3a98 CP |
16 | HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template |
17 | ||
049e11af | 18 | APPFILES += $(INSTALLDIR)/booleans |
fb0a3a98 | 19 | |
c767b14c | 20 | # for monolithic policy use all base and module to create policy |
cf0ff557 | 21 | ALL_MODULES := $(strip $(BASE_MODS) $(MOD_MODS)) |
ab23bb90 CP |
22 | # off module interfaces included to make sure all interfaces are expanded. |
23 | ALL_INTERFACES := $(ALL_MODULES:.te=.if) $(OFF_MODS:.te=.if) | |
fb0a3a98 CP |
24 | ALL_TE_FILES := $(ALL_MODULES) |
25 | ALL_FC_FILES := $(ALL_MODULES:.te=.fc) | |
26 | ||
a0824843 | 27 | PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs |
ffd04848 | 28 | POST_TE_FILES := $(USER_FILES) $(POLDIR)/constraints |
fb0a3a98 | 29 | |
3abd5ee8 | 30 | POLICY_SECTIONS := $(TMPDIR)/pre_te_files.conf $(TMPDIR)/all_attrs_types.conf $(TMPDIR)/global_bools.conf $(TMPDIR)/only_te_rules.conf $(TMPDIR)/all_post.conf |
c767b14c CP |
31 | |
32 | # search layer dirs for source files | |
e2680fb4 CP |
33 | vpath %.te $(ALL_LAYERS) |
34 | vpath %.if $(ALL_LAYERS) | |
35 | vpath %.fc $(ALL_LAYERS) | |
c767b14c | 36 | |
fb0a3a98 CP |
37 | ######################################## |
38 | # | |
39 | # default action: build policy locally | |
40 | # | |
41 | default: policy | |
42 | ||
43 | policy: $(POLVER) | |
44 | ||
45 | install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users | |
46 | ||
c9f20d5b | 47 | load: $(TMPDIR)/load |
fb0a3a98 | 48 | |
120988c4 CP |
49 | checklabels: $(FCPATH) |
50 | restorelabels: $(FCPATH) | |
51 | relabel: $(FCPATH) | |
52 | resetlabels: $(FCPATH) | |
53 | ||
fb0a3a98 CP |
54 | ######################################## |
55 | # | |
56 | # Build a binary policy locally | |
57 | # | |
c9f20d5b | 58 | $(POLVER): $(POLICY_CONF) |
fb0a3a98 CP |
59 | @echo "Compiling $(NAME) $(POLVER)" |
60 | ifneq ($(PV),$(KV)) | |
61 | @echo | |
62 | @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?" | |
63 | @echo | |
64 | endif | |
5b45ffb0 | 65 | $(verbose) $(CHECKPOLICY) $^ -o $@ |
fb0a3a98 CP |
66 | |
67 | ######################################## | |
68 | # | |
69 | # Install a binary policy | |
70 | # | |
c9f20d5b | 71 | $(LOADPATH): $(POLICY_CONF) |
fb0a3a98 CP |
72 | @mkdir -p $(POLICYPATH) |
73 | @echo "Compiling and installing $(NAME) $(LOADPATH)" | |
74 | ifneq ($(PV),$(KV)) | |
75 | @echo | |
76 | @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?" | |
77 | @echo | |
78 | endif | |
9b3756bf | 79 | $(verbose) $(CHECKPOLICY) $^ -o $@ |
fb0a3a98 CP |
80 | |
81 | ######################################## | |
82 | # | |
83 | # Load the binary policy | |
84 | # | |
c9f20d5b | 85 | reload $(TMPDIR)/load: $(LOADPATH) $(FCPATH) $(APPFILES) |
fb0a3a98 | 86 | @echo "Loading $(NAME) $(LOADPATH)" |
9b3756bf | 87 | $(verbose) $(LOADPOLICY) -q $(LOADPATH) |
c9f20d5b | 88 | @touch $(TMPDIR)/load |
fb0a3a98 CP |
89 | |
90 | ######################################## | |
91 | # | |
92 | # Construct a monolithic policy.conf | |
93 | # | |
c9f20d5b CP |
94 | $(POLICY_CONF): $(POLICY_SECTIONS) |
95 | @echo "Creating $(NAME) $(@F)" | |
3abd5ee8 CP |
96 | @test -d $(@D) || mkdir -p $(@D) |
97 | $(verbose) cat $^ > $@ | |
fb0a3a98 | 98 | |
c9f20d5b CP |
99 | $(TMPDIR)/pre_te_files.conf: $(PRE_TE_FILES) |
100 | @test -d $(TMPDIR) || mkdir -p $(TMPDIR) | |
3abd5ee8 | 101 | $(verbose) $(M4) $(M4PARAM) $^ > $@ |
fb0a3a98 | 102 | |
988a441b | 103 | $(TMPDIR)/generated_definitions.conf: $(ALL_TE_FILES) |
c9f20d5b | 104 | @test -d $(TMPDIR) || mkdir -p $(TMPDIR) |
70131678 CP |
105 | # define all available object classes |
106 | $(verbose) $(GENPERM) $(AVS) $(SECCLASS) > $@ | |
107 | # per-userdomain templates: | |
108 | $(verbose) echo "define(\`base_per_userdomain_template',\`" >> $@ | |
3abd5ee8 CP |
109 | $(verbose) $(foreach mod,$(basename $(notdir $(ALL_MODULES))), \ |
110 | echo "ifdef(\`""$(mod)""_per_userdomain_template',\`""$(mod)""_per_userdomain_template("'$$*'")')" >> $@ ;) | |
9b3756bf | 111 | $(verbose) echo "')" >> $@ |
fb0a3a98 | 112 | # define foo.te |
9b3756bf | 113 | $(verbose) for i in $(notdir $(ALL_MODULES)); do \ |
fb0a3a98 CP |
114 | echo "define(\`$$i')" >> $@ ;\ |
115 | done | |
5b45ffb0 | 116 | $(verbose) test -f $(BOOLEANS) && $(SETBOOLS) $(BOOLEANS) >> $@ || true |
fb0a3a98 | 117 | |
3abd5ee8 CP |
118 | $(TMPDIR)/global_bools.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(GLOBALBOOL) $(GLOBALTUN) |
119 | $(verbose) $(M4) $(M4PARAM) $^ > $@ | |
120 | ||
c9f20d5b | 121 | $(TMPDIR)/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES) |
fb0a3a98 CP |
122 | ifeq ($(ALL_INTERFACES),) |
123 | $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") | |
124 | endif | |
c9f20d5b | 125 | @test -d $(TMPDIR) || mkdir -p $(TMPDIR) |
3abd5ee8 CP |
126 | @echo "divert(-1)" > $@ |
127 | $(verbose) $(M4) $^ | $(SED) -e s/dollarsstar/\$$\*/g >> $@ | |
128 | @echo "divert" >> $@ | |
fb0a3a98 | 129 | |
3abd5ee8 CP |
130 | $(TMPDIR)/rolemap.conf: $(ROLEMAP) |
131 | $(call parse-rolemap,base,$@) | |
132 | ||
133 | $(TMPDIR)/all_te_files.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(TMPDIR)/all_interfaces.conf $(ALL_TE_FILES) $(TMPDIR)/rolemap.conf | |
fb0a3a98 CP |
134 | ifeq ($(ALL_TE_FILES),) |
135 | $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") | |
136 | endif | |
c9f20d5b | 137 | @test -d $(TMPDIR) || mkdir -p $(TMPDIR) |
3abd5ee8 | 138 | $(verbose) $(M4) $(M4PARAM) -s $^ > $@ |
fb0a3a98 | 139 | |
3abd5ee8 | 140 | $(TMPDIR)/post_te_files.conf: $(M4SUPPORT) $(POST_TE_FILES) |
c9f20d5b | 141 | @test -d $(TMPDIR) || mkdir -p $(TMPDIR) |
3abd5ee8 | 142 | $(verbose) $(M4) $(M4PARAM) $^ > $@ |
fb0a3a98 CP |
143 | |
144 | # extract attributes and put them first. extract post te stuff | |
3abd5ee8 | 145 | # like genfscon and put last. |
c9f20d5b | 146 | $(TMPDIR)/all_attrs_types.conf $(TMPDIR)/only_te_rules.conf $(TMPDIR)/all_post.conf: $(TMPDIR)/all_te_files.conf $(TMPDIR)/post_te_files.conf |
f62f4c79 | 147 | $(verbose) $(get_type_attr_decl) $(TMPDIR)/all_te_files.conf | $(SORT) > $(TMPDIR)/all_attrs_types.conf |
c9f20d5b | 148 | $(verbose) cat $(TMPDIR)/post_te_files.conf > $(TMPDIR)/all_post.conf |
3abd5ee8 CP |
149 | # these have to run individually because order matters: |
150 | $(verbose) $(GREP) '^sid ' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true | |
151 | $(verbose) $(GREP) '^fs_use_(xattr|task|trans)' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true | |
152 | $(verbose) $(GREP) ^genfscon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true | |
153 | $(verbose) $(GREP) ^portcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true | |
154 | $(verbose) $(GREP) ^netifcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true | |
155 | $(verbose) $(GREP) ^nodecon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true | |
156 | $(verbose) $(comment_move_decl) $(TMPDIR)/all_te_files.conf > $(TMPDIR)/only_te_rules.conf | |
fb0a3a98 CP |
157 | |
158 | ######################################## | |
159 | # | |
160 | # Remove the dontaudit rules from the policy.conf | |
161 | # | |
c9f20d5b CP |
162 | enableaudit: $(POLICY_CONF) |
163 | @test -d $(TMPDIR) || mkdir -p $(TMPDIR) | |
164 | @echo "Removing dontaudit rules from $(notdir $(POLICY_CONF))" | |
3abd5ee8 | 165 | $(verbose) $(GREP) -v dontaudit @^ > $(TMPDIR)/policy.audit |
c9f20d5b | 166 | $(verbose) mv $(TMPDIR)/policy.audit $(POLICY_CONF) |
fb0a3a98 CP |
167 | |
168 | ######################################## | |
169 | # | |
170 | # Construct file_contexts | |
171 | # | |
c9f20d5b | 172 | $(FC): $(TMPDIR)/$(notdir $(FC)).tmp $(FCSORT) |
9b3756bf | 173 | $(verbose) $(FCSORT) $< $@ |
185ab241 CP |
174 | ifeq "$(DISTRO)" "rhel4" |
175 | # the old genhomedircon used in RHEL4 makes assumptions on | |
176 | # the directory strucure of the policy. need to set up a mini | |
177 | # environment with this structure for correct functioning. | |
a3e785d5 CP |
178 | @ mkdir -p $(TMPDIR)/rhel4 |
179 | @ cp $@ $(TMPDIR)/rhel4 | |
185ab241 | 180 | @ $(M4) $(M4PARAM) $(M4SUPPORT) $(USER_FILES) > $(TMPDIR)/rhel4/users |
a3e785d5 | 181 | $(verbose) $(GREP) -v "^/root" $< > $(TMPDIR)/rhel4/$(@F).root |
185ab241 CP |
182 | $(verbose) ( cd $(TMPDIR)/rhel4/users ; $(GENHOMEDIRCON) . $(@F).root > $@ ) |
183 | $(verbose) $(GREP) "^/root" $< >> $@ | |
184 | else | |
3abd5ee8 CP |
185 | $(verbose) $(GREP) -e HOME -e ROLE $@ > $(HOMEDIR_TEMPLATE) |
186 | $(verbose) $(SED) -i -e /HOME/d -e /ROLE/d $@ | |
185ab241 | 187 | endif |
c767b14c | 188 | |
c9f20d5b | 189 | $(TMPDIR)/$(notdir $(FC)).tmp: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(ALL_FC_FILES) |
fb0a3a98 CP |
190 | ifeq ($(ALL_FC_FILES),) |
191 | $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") | |
192 | endif | |
193 | @echo "Creating $(NAME) file_contexts." | |
c9f20d5b | 194 | @test -d $(TMPDIR) || mkdir -p $(TMPDIR) |
3abd5ee8 | 195 | $(verbose) $(M4) $(M4PARAM) $^ > $@ |
fb0a3a98 CP |
196 | |
197 | ######################################## | |
198 | # | |
199 | # Install file_contexts | |
200 | # | |
201 | $(FCPATH): $(FC) $(LOADPATH) $(USERPATH)/system.users | |
202 | @echo "Validating $(NAME) file_contexts." | |
9b3756bf | 203 | $(verbose) $(SETFILES) -q -c $(LOADPATH) $(FC) |
fb0a3a98 CP |
204 | @echo "Installing file_contexts." |
205 | @mkdir -p $(CONTEXTPATH)/files | |
185ab241 CP |
206 | ifeq "$(DISTRO)" "rhel4" |
207 | $(verbose) install -m $(FC) $@ | |
208 | else | |
9b3756bf CP |
209 | $(verbose) install -m 644 $(FC) $(FCPATH) |
210 | $(verbose) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH) | |
211 | $(verbose) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(NAME) $(USEPWD) | |
185ab241 | 212 | endif |
fb0a3a98 | 213 | |
8df65f13 CP |
214 | ######################################## |
215 | # | |
216 | # Run policy source checks | |
217 | # | |
5b45ffb0 CP |
218 | check: $(BUILDDIR)check.res |
219 | $(BUILDDIR)check.res: $(POLICY_CONF) $(FC) | |
220 | $(SECHECK) -s --profile=development --policy=$(POLICY_CONF) --fcfile=$(FC) > $@ | |
8df65f13 | 221 | |
5b45ffb0 CP |
222 | longcheck: $(BUILDDIR)longcheck.res |
223 | $(BUILDDIR)longcheck.res: $(POLICY_CONF) $(FC) | |
224 | $(SECHECK) -s --profile=all --policy=$(POLICY_CONF) --fcfile=$(FC) > $@ | |
8df65f13 | 225 | |
049e11af CP |
226 | ######################################## |
227 | # | |
228 | # Appconfig files | |
229 | # | |
efc94af8 | 230 | $(APPDIR)/customizable_types: $(POLICY_CONF) |
049e11af | 231 | @mkdir -p $(APPDIR) |
a3cf80d8 | 232 | $(verbose) $(GREP) '^[[:blank:]]*type .*customizable' $< | cut -d',' -f1 | cut -d' ' -f2 | $(SORT) -u > $(TMPDIR)/customizable_types |
4ca6d0d2 | 233 | $(verbose) install -m 644 $(TMPDIR)/customizable_types $@ |
049e11af | 234 | |
fb0a3a98 CP |
235 | ######################################## |
236 | # | |
237 | # Clean the sources | |
238 | # | |
239 | clean: | |
c9f20d5b | 240 | rm -f $(POLICY_CONF) |
5b45ffb0 | 241 | rm -f $(POLVER) |
fb0a3a98 | 242 | rm -f $(FC) |
c767b14c | 243 | rm -f $(HOMEDIR_TEMPLATE) |
8df65f13 | 244 | rm -f *.res |
c9f20d5b | 245 | rm -fR $(TMPDIR) |
fb0a3a98 | 246 | |
8df65f13 | 247 | .PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean |