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