]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - Rules.monolithic
fix makefile style so internal variables are lowercase
[people/stevee/selinux-policy.git] / Rules.monolithic
CommitLineData
fb0a3a98
CP
1########################################
2#
3# Rules and Targets for building monolithic policies
4#
5
c634db20
CP
6# determine the policy version and current kernel version if possible
7pv := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ')
8kv := $(shell cat /selinux/policyvers)
9
10# dont print version warnings if we are unable to determine
11# the currently running kernel's policy version
12ifeq "$(kv)" ""
13 kv := $(pv)
14endif
15
16policy_conf = $(builddir)policy.conf
17fc = $(builddir)file_contexts
18polver = $(builddir)policy.$(pv)
19homedir_template = $(builddir)homedir_template
c9f20d5b 20
3abd5ee8
CP
21M4PARAM += -D self_contained_policy
22
fb0a3a98 23# install paths
c634db20
CP
24policypath = $(installdir)/policy
25loadpath = $(policypath)/$(notdir $(polver))
26homedirpath = $(contextpath)/files/homedir_template
fb0a3a98 27
c634db20 28appfiles += $(installdir)/booleans $(userpath)/local.users
fb0a3a98 29
c767b14c 30# for monolithic policy use all base and module to create policy
c634db20 31all_modules := $(strip $(base_mods) $(mod_mods))
ab23bb90 32# off module interfaces included to make sure all interfaces are expanded.
c634db20
CP
33all_interfaces := $(all_modules:.te=.if) $(off_mods:.te=.if)
34all_te_files := $(all_modules)
35all_fc_files := $(all_modules:.te=.fc)
fb0a3a98 36
c634db20
CP
37pre_te_files := $(secclass) $(isids) $(avs) $(m4support) $(poldir)/mls $(poldir)/mcs
38post_te_files := $(user_files) $(poldir)/constraints
fb0a3a98 39
c634db20 40policy_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
41
42# search layer dirs for source files
c634db20
CP
43vpath %.te $(all_layers)
44vpath %.if $(all_layers)
45vpath %.fc $(all_layers)
c767b14c 46
fb0a3a98
CP
47########################################
48#
49# default action: build policy locally
50#
51default: policy
52
c634db20 53policy: $(polver)
fb0a3a98 54
c634db20 55install: $(loadpath) $(fcpath) $(ncpath) $(appfiles)
fb0a3a98 56
c634db20 57load: $(tmpdir)/load
fb0a3a98 58
c634db20
CP
59checklabels: $(fcpath)
60restorelabels: $(fcpath)
61relabel: $(fcpath)
62resetlabels: $(fcpath)
120988c4 63
fb0a3a98
CP
64########################################
65#
66# Build a binary policy locally
67#
c634db20
CP
68$(polver): $(policy_conf)
69 @echo "Compiling $(NAME) $(polver)"
70ifneq ($(pv),$(kv))
fb0a3a98
CP
71 @echo
72 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
73 @echo
74endif
5b45ffb0 75 $(verbose) $(CHECKPOLICY) $^ -o $@
fb0a3a98
CP
76
77########################################
78#
79# Install a binary policy
80#
c634db20
CP
81$(loadpath): $(policy_conf)
82 @mkdir -p $(policypath)
83 @echo "Compiling and installing $(NAME) $(loadpath)"
84ifneq ($(pv),$(kv))
fb0a3a98
CP
85 @echo
86 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
87 @echo
88endif
9b3756bf 89 $(verbose) $(CHECKPOLICY) $^ -o $@
fb0a3a98
CP
90
91########################################
92#
93# Load the binary policy
94#
c634db20
CP
95reload $(tmpdir)/load: $(loadpath) $(fcpath) $(ncpath) $(appfiles)
96 @echo "Loading $(NAME) $(loadpath)"
97 $(verbose) $(LOADPOLICY) -q $(loadpath)
98 @touch $(tmpdir)/load
fb0a3a98
CP
99
100########################################
101#
102# Construct a monolithic policy.conf
103#
c634db20 104$(policy_conf): $(policy_sections)
c9f20d5b 105 @echo "Creating $(NAME) $(@F)"
3abd5ee8
CP
106 @test -d $(@D) || mkdir -p $(@D)
107 $(verbose) cat $^ > $@
fb0a3a98 108
c634db20
CP
109$(tmpdir)/pre_te_files.conf: $(pre_te_files)
110 @test -d $(tmpdir) || mkdir -p $(tmpdir)
3abd5ee8 111 $(verbose) $(M4) $(M4PARAM) $^ > $@
fb0a3a98 112
c634db20
CP
113$(tmpdir)/generated_definitions.conf: $(all_te_files)
114 @test -d $(tmpdir) || mkdir -p $(tmpdir)
70131678 115# define all available object classes
c634db20 116 $(verbose) $(genperm) $(avs) $(secclass) > $@
70131678
CP
117# per-userdomain templates:
118 $(verbose) echo "define(\`base_per_userdomain_template',\`" >> $@
c634db20 119 $(verbose) $(foreach mod,$(basename $(notdir $(all_modules))), \
3abd5ee8 120 echo "ifdef(\`""$(mod)""_per_userdomain_template',\`""$(mod)""_per_userdomain_template("'$$*'")')" >> $@ ;)
9b3756bf 121 $(verbose) echo "')" >> $@
c634db20 122 $(verbose) test -f $(booleans) && $(setbools) $(booleans) >> $@ || true
fb0a3a98 123
c634db20 124$(tmpdir)/global_bools.conf: $(m4support) $(tmpdir)/generated_definitions.conf $(globalbool) $(globaltun)
3abd5ee8
CP
125 $(verbose) $(M4) $(M4PARAM) $^ > $@
126
c634db20
CP
127$(tmpdir)/all_interfaces.conf: $(m4support) $(all_interfaces)
128 @test -d $(tmpdir) || mkdir -p $(tmpdir)
129 @echo "ifdef(\`__if_error',\`m4exit(1)')" > $(tmpdir)/iferror.m4
3abd5ee8 130 @echo "divert(-1)" > $@
c634db20
CP
131 $(verbose) $(M4) $^ $(tmpdir)/iferror.m4 >> $(tmpdir)/$(@F).tmp
132 $(verbose) $(SED) -e s/dollarsstar/\$$\*/g $(tmpdir)/$(@F).tmp >> $@
3abd5ee8 133 @echo "divert" >> $@
fb0a3a98 134
c634db20 135$(tmpdir)/rolemap.conf: $(rolemap)
3abd5ee8
CP
136 $(call parse-rolemap,base,$@)
137
c634db20
CP
138$(tmpdir)/all_te_files.conf: $(m4support) $(tmpdir)/generated_definitions.conf $(tmpdir)/all_interfaces.conf $(all_te_files) $(tmpdir)/rolemap.conf
139ifeq "$(strip $(all_te_files))" ""
140 $(error No enabled modules! $(notdir $(mod_conf)) may need to be generated by using "make conf")
fb0a3a98 141endif
c634db20 142 @test -d $(tmpdir) || mkdir -p $(tmpdir)
3abd5ee8 143 $(verbose) $(M4) $(M4PARAM) -s $^ > $@
fb0a3a98 144
c634db20
CP
145$(tmpdir)/post_te_files.conf: $(m4support) $(post_te_files)
146 @test -d $(tmpdir) || mkdir -p $(tmpdir)
3abd5ee8 147 $(verbose) $(M4) $(M4PARAM) $^ > $@
fb0a3a98
CP
148
149# extract attributes and put them first. extract post te stuff
3abd5ee8 150# like genfscon and put last.
c634db20
CP
151$(tmpdir)/all_attrs_types.conf $(tmpdir)/only_te_rules.conf $(tmpdir)/all_post.conf: $(tmpdir)/all_te_files.conf $(tmpdir)/post_te_files.conf
152 $(verbose) $(get_type_attr_decl) $(tmpdir)/all_te_files.conf | $(SORT) > $(tmpdir)/all_attrs_types.conf
153 $(verbose) cat $(tmpdir)/post_te_files.conf > $(tmpdir)/all_post.conf
3abd5ee8 154# these have to run individually because order matters:
c634db20
CP
155 $(verbose) $(GREP) '^sid ' $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
156 $(verbose) $(GREP) '^fs_use_(xattr|task|trans)' $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
157 $(verbose) $(GREP) ^genfscon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
158 $(verbose) $(GREP) ^portcon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
159 $(verbose) $(GREP) ^netifcon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
160 $(verbose) $(GREP) ^nodecon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
161 $(verbose) $(comment_move_decl) $(tmpdir)/all_te_files.conf > $(tmpdir)/only_te_rules.conf
fb0a3a98
CP
162
163########################################
164#
165# Remove the dontaudit rules from the policy.conf
166#
c634db20
CP
167enableaudit: $(policy_conf)
168 @test -d $(tmpdir) || mkdir -p $(tmpdir)
169 @echo "Removing dontaudit rules from $(notdir $(policy_conf))"
170 $(verbose) $(GREP) -v dontaudit $^ > $(tmpdir)/policy.audit
171 $(verbose) mv $(tmpdir)/policy.audit $(policy_conf)
fb0a3a98
CP
172
173########################################
174#
175# Construct file_contexts
176#
c634db20
CP
177$(fc): $(tmpdir)/$(notdir $(fc)).tmp $(fcsort)
178 $(verbose) $(fcsort) $< $@
179 $(verbose) $(GREP) -e HOME -e ROLE $@ > $(homedir_template)
3abd5ee8 180 $(verbose) $(SED) -i -e /HOME/d -e /ROLE/d $@
c767b14c 181
c634db20
CP
182$(tmpdir)/$(notdir $(fc)).tmp: $(m4support) $(tmpdir)/generated_definitions.conf $(all_fc_files)
183ifeq ($(all_fc_files),)
184 $(error No enabled modules! $(notdir $(mod_conf)) may need to be generated by using "make conf")
fb0a3a98
CP
185endif
186 @echo "Creating $(NAME) file_contexts."
c634db20 187 @test -d $(tmpdir) || mkdir -p $(tmpdir)
3abd5ee8 188 $(verbose) $(M4) $(M4PARAM) $^ > $@
fb0a3a98 189
c634db20 190$(homedir_template): $(fc)
fc47b34c 191
fb0a3a98
CP
192########################################
193#
194# Install file_contexts
195#
c634db20 196$(fcpath): $(fc) $(loadpath) $(userpath)/system.users
fb0a3a98 197 @echo "Validating $(NAME) file_contexts."
c634db20 198 $(verbose) $(SETFILES) -q -c $(loadpath) $(fc)
fb0a3a98 199 @echo "Installing file_contexts."
c634db20
CP
200 @mkdir -p $(contextpath)/files
201 $(verbose) $(INSTALL) -m 644 $(fc) $(fcpath)
202 $(verbose) $(INSTALL) -m 644 $(homedir_template) $(homedirpath)
203 $(verbose) $(genhomedircon) -d $(topdir) -t $(NAME) $(USEPWD)
fc47b34c
CP
204ifeq "$(DISTRO)" "rhel4"
205# Setfiles in RHEL4 does not look at file_contexts.homedirs.
206 $(verbose) cat $@.homedirs >> $@
207# Delete the file_contexts.homedirs in case the toolchain has
208# been updated, to prevent duplicate match errors.
209 $(verbose) rm -f $@.homedirs
185ab241 210endif
fb0a3a98 211
8df65f13 212########################################
5a7c06fd
CP
213#
214# Intall netfilter_contexts
215#
c634db20 216$(ncpath): $(net_contexts)
5a7c06fd 217 @echo "Installing $(NAME) netfilter_contexts."
cfd5c5e1 218 $(verbose) $(INSTALL) -m 0644 $^ $@
5a7c06fd
CP
219
220########################################
8df65f13
CP
221#
222# Run policy source checks
223#
c634db20
CP
224check: $(builddir)check.res
225$(builddir)check.res: $(policy_conf) $(fc)
226 $(SECHECK) -s --profile=development --policy=$(policy_conf) --fcfile=$(fc) > $@
8df65f13 227
c634db20
CP
228longcheck: $(builddir)longcheck.res
229$(builddir)longcheck.res: $(policy_conf) $(fc)
230 $(SECHECK) -s --profile=all --policy=$(policy_conf) --fcfile=$(fc) > $@
8df65f13 231
049e11af
CP
232########################################
233#
234# Appconfig files
235#
c634db20
CP
236$(appdir)/customizable_types: $(policy_conf)
237 @mkdir -p $(appdir)
238 $(verbose) $(GREP) '^[[:blank:]]*type .*customizable' $< | cut -d';' -f1 | cut -d',' -f1 | cut -d' ' -f2 | $(SORT) -u > $(tmpdir)/customizable_types
239 $(verbose) $(INSTALL) -m 644 $(tmpdir)/customizable_types $@
049e11af 240
fb0a3a98
CP
241########################################
242#
243# Clean the sources
244#
245clean:
c634db20
CP
246 rm -f $(policy_conf)
247 rm -f $(polver)
248 rm -f $(fc)
249 rm -f $(homedir_template)
6962bb32 250 rm -f $(net_contexts)
8df65f13 251 rm -f *.res
c634db20 252 rm -fR $(tmpdir)
fb0a3a98 253
8df65f13 254.PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean