1 ########################################
3 # Rules and Targets for building monolithic policies
7 POLICYPATH = $(INSTALLDIR)/policy
8 LOADPATH = $(POLICYPATH)/$(POLVER)
9 FCPATH = $(CONTEXTPATH)/files/file_contexts
10 HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
12 # Monolithic still uses booleans file
13 APPFILES += $(INSTALLDIR)/booleans
15 # for monolithic policy use all base and module to create policy
16 ENABLEMOD := $(BASE_MODS) $(MOD_MODS)
18 ALL_MODULES := $(filter $(ENABLEMOD),$(DETECTED_MODS))
20 ALL_INTERFACES := $(ALL_MODULES:.te=.if)
21 ALL_TE_FILES := $(ALL_MODULES)
22 ALL_FC_FILES := $(ALL_MODULES:.te=.fc)
24 PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
25 POST_TE_FILES := $(POLDIR)/systemuser $(POLDIR)/users $(POLDIR)/constraints
27 POLICY_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
29 ########################################
31 # default action: build policy locally
37 install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
41 ########################################
43 # Build a binary policy locally
45 $(POLVER): policy.conf
46 @echo "Compiling $(NAME) $(POLVER)"
49 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
52 $(QUIET) $(CHECKPOLICY) $^ -o $@
54 ########################################
56 # Install a binary policy
58 $(LOADPATH): policy.conf
59 @mkdir -p $(POLICYPATH)
60 @echo "Compiling and installing $(NAME) $(LOADPATH)"
63 @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
66 $(QUIET) $(CHECKPOLICY) $^ -o $@
68 ########################################
70 # Load the binary policy
72 reload tmp/load: $(LOADPATH) $(FCPATH)
73 @echo "Loading $(NAME) $(LOADPATH)"
74 $(QUIET) $(LOADPOLICY) -q $(LOADPATH)
77 ########################################
79 # Construct a monolithic policy.conf
81 policy.conf: $(POLICY_SECTIONS)
82 @echo "Creating $(NAME) policy.conf"
83 # checkpolicy can use the #line directives provided by -s for error reporting:
84 $(QUIET) m4 -D self_contained_policy $(M4PARAM) -s $^ > tmp/$@.tmp
85 $(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
86 # the ordering of these ocontexts matters:
87 $(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true
88 $(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true
89 $(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true
91 tmp/pre_te_files.conf: $(PRE_TE_FILES)
92 @test -d tmp || mkdir -p tmp
95 tmp/generated_definitions.conf: $(ALL_LAYERS) $(ALL_TE_FILES)
96 # per-userdomain templates:
97 @test -d tmp || mkdir -p tmp
98 $(QUIET) echo "define(\`per_userdomain_templates',\`" > $@
99 $(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \
100 echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$*'")')" \
103 $(QUIET) echo "')" >> $@
105 $(QUIET) for i in $(notdir $(ALL_MODULES)); do \
106 echo "define(\`$$i')" >> $@ ;\
108 $(QUIET) $(SETTUN) $(BOOLEANS) >> $@
110 tmp/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES)
111 ifeq ($(ALL_INTERFACES),)
112 $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
114 @test -d tmp || mkdir -p tmp
115 $(QUIET) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
117 tmp/all_te_files.conf: $(ALL_TE_FILES)
118 ifeq ($(ALL_TE_FILES),)
119 $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
121 @test -d tmp || mkdir -p tmp
124 tmp/post_te_files.conf: $(POST_TE_FILES)
125 @test -d tmp || mkdir -p tmp
128 # extract attributes and put them first. extract post te stuff
129 # like genfscon and put last. portcon, nodecon, and netifcon
130 # is delayed since they are generated by m4
131 tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf
132 $(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true
133 $(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf
134 $(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf
135 $(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true
136 $(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true
137 $(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
138 $(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \
139 -e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \
140 < tmp/all_te_files.conf > tmp/only_te_rules.conf
142 ########################################
144 # Remove the dontaudit rules from the policy.conf
146 enableaudit: policy.conf
147 @test -d tmp || mkdir -p tmp
148 @echo "Removing dontaudit rules from policy.conf"
149 $(QUIET) grep -v dontaudit policy.conf > tmp/policy.audit
150 $(QUIET) mv tmp/policy.audit policy.conf
152 ########################################
154 # Construct file_contexts
156 $(FC): $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES) $(FCSORT)
157 ifeq ($(ALL_FC_FILES),)
158 $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
160 @echo "Creating $(NAME) file_contexts."
161 @test -d tmp || mkdir -p tmp
162 $(QUIET) m4 $(M4PARAM) $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES) > tmp/$@.tmp
163 $(QUIET) grep -e HOME -e ROLE tmp/$@.tmp > $(HOMEDIR_TEMPLATE)
164 $(QUIET) sed -i -e /HOME/d -e /ROLE/d tmp/$@.tmp
165 $(QUIET) $(FCSORT) tmp/$@.tmp $@
167 ########################################
169 # Install file_contexts
171 $(FCPATH): $(FC) $(LOADPATH) $(USERPATH)/system.users
172 @echo "Validating $(NAME) file_contexts."
173 $(QUIET) $(SETFILES) -q -c $(LOADPATH) $(FC)
174 @echo "Installing file_contexts."
175 @mkdir -p $(CONTEXTPATH)/files
176 $(QUIET) install -m 644 $(FC) $(FCPATH)
177 $(QUIET) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH)
178 $(QUIET) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(NAME) $(USEPWD)
180 ########################################
182 # Filesystem labeling
184 FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';`
186 checklabels: $(FC) $(SETFILES)
187 @if test -z "$(FILESYSTEMS)"; then \
188 echo "No filesystems with extended attributes found!" ;\
191 $(QUIET) $(SETFILES) -v -n $(FC) $(FILESYSTEMS)
193 restorelabels: $(FC) $(SETFILES)
194 @if test -z "$(FILESYSTEMS)"; then \
195 echo "No filesystems with extended attributes found!" ;\
198 $(QUIET) $(SETFILES) -v $(FC) $(FILESYSTEMS)
200 relabel: $(FC) $(SETFILES)
201 @if test -z "$(FILESYSTEMS)"; then \
202 echo "No filesystems with extended attributes found!" ;\
205 $(QUIET) $(SETFILES) $(FC) $(FILESYSTEMS)
207 ########################################
209 # Run policy source checks
211 check: policy.conf $(FC)
212 $(SECHECK) -s --profile=development --policy=policy.conf --fcfile=$(FC) > $@.res
214 longcheck: policy.conf $(FC)
215 $(SECHECK) -s --profile=all --policy=policy.conf --fcfile=$(FC) > $@.res
217 ########################################
228 .PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean