: seobject.py must skip comments while reading external configuration files (was Re: [refpolicy] [PATCH]: clarify the file_contexts.subs_dist configuration file usage)
PATCH 1/1 : seobject.py must skip comments while reading external configuration files (was Re: [refpolicy] [PATCH]: clarify the file_contexts.subs_dist configuration file usage)
Hello.
Apparently semanage does not work properly when the external configuration file "file_contexts.subs_dist" (from the policy) contains #-comments.
The patch attached below aims to fix this: seobject.py must skip comments while reading the external configuration file "file_contexts.subs_dist".
Quoted 39 lines · Christopher J. PeBenito
Quoted 29 lines · Guido Trentalancia
Quoted 28 lines
Add a comment at the top of the configuration file file_contexts.subs_dist to clarify that it performs aliasing and not substitutions in the strict sense of the word.
A name change might be considered too, if it proves to lead to further confusion.
There might be pieces of documentation that could benefit from similar considerations.
Also note that a specific manual page is missing.
Signed-off-by Guido Trentalancia <[email protected]>--- config/file_contexts.subs_dist | 10 ++++++++++ 1 file changed, 10 insertions(+)diff -pruN refpolicy-08092012/config/file_contexts.subs_dist refpolicy-08092012-file_contexts.subs_dist-comment/config/file_contexts.subs_dist
config/file_contexts.subs_dist 2012-08-10 17:01:36.045451839 +0200 renamed from config/file_contexts.subs_dist 2012-06-21 20:10:29.011803405 +0200 +7
-0@@ -1,3 +1,13 @@ +# This file can is used to configure base path aliases as in: +# +# /aliased_path /original_path_as_configured_in_file_contexts +# +# where original_path_as_configured_in_file_contexts is a base +# path being used in the main file_contexts configuration file. +#Quoted 8 lines
config/file_contexts.subs_dist 2012-08-10 17:01:36.045451839 +0200 line 13
Quoted 6 lines
config/file_contexts.subs_dist 2012-08-10 17:01:36.045451839 +0200 renamed from config/file_contexts.subs_dist 2012-06-21 20:10:29.011803405 +0200 +3
-0+# It does not perform substitutions as done by sed(1), for +# example, but aliasing. +# /lib32 /lib /lib64 /lib /run /var/runMerged.
Quoted 6 lines
This seems to break policycoreutils:
# semanage fcontext -l /usr/sbin/semanage: too many values to unpack (expected 2)Undoing the comment change fixes things again.
All is needed is something like this for selinux-userspace (policycoreutils):
Fix fcontextRecords() in policycoreutils/semanage/seobject.py so that semanage does not produce an error in fcontext mode when the file_contexts.subs_dist file contains comments (prefixed by #).
--- policycoreutils/semanage/seobject.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
policycoreutils/semanage/seobject.py +14 -4
@@ -1627,16 +1627,26 @@ class fcontextRecords(semanageRecords): self.equal_ind = False try: fd = open(selinux.selinux_file_context_subs_path(), "r") - for i in fd.readlines(): - target, substitute = i.split() + for i in fd.read().split("n"): + i = i.strip() + if len(i) == 0: + continue + if i.startswith("#"): + continue + target, substitute = i.split(" ") self.equiv[target] = substitute fd.close() except IOError: pass try: fd = open(selinux.selinux_file_context_subs_dist_path(), "r") - for i in fd.readlines(): - target, substitute = i.split() + for i in fd.read().split("n"): + i = i.strip() + if len(i) == 0: + continue + if i.startswith("#"): + continue + target, substitute = i.split(" ") self.equiv_dist[target] = substitute fd.close() except IOError: