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