The following patches fix sepolicy python3 issues found by make test in python/sepolicy
PATCH 1/2 sepolicy/interface: Use relative python 3 imports
Fixes:
Verify sepolicy interface -c -i works ... Traceback (most recent call last):
File "/usr/bin/sepolicy", line 699, in <module>
args.func(args)
File "/usr/bin/sepolicy", line 508, in interface
print_interfaces(args.interfaces, args)
File "/usr/bin/sepolicy", line 492, in print_interfaces
interface_compile_test(i)
File "/usr/lib/python3.6/site-packages/sepolicy/interface.py", line 226, in interface_compile_test
fd.write(generate_compile_te(interface, idict))
File "/usr/lib/python3.6/site-packages/sepolicy/interface.py", line 184, in generate_compile_te
from templates import test_module
ModuleNotFoundError: No module named 'templates'
--- python/sepolicy/sepolicy/interface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
python/sepolicy/sepolicy/interface.py +2 -2
@@ -171,7 +171,7 @@ def get_interface_format_text(interface, path="/usr/share/selinux/devel/policy.x def get_interface_compile_format_text(interfaces_dict, interface): - from templates import test_module + from .templates import test_module param_tmp = [] for i in interfaces_dict[interface][0]: param_tmp.append(test_module.dict_values[i])
@@ -181,7 +181,7 @@ def get_interface_compile_format_text(interfaces_dict, interface): def generate_compile_te(interface, idict, name="compiletest"): - from templates import test_module + from .templates import test_module te = "" te += re.sub("TEMPLATETYPE", name, test_module.te_test_module) te += get_interface_compile_format_text(idict, interface)
Signature · 1 line
2.13.0
PATCH 2/2 sepolicy: Fix sorting of port_strings in python 3
In reply to Petr LautrbachFixes:
$ sepolicy network -d httpd_t
httpd_t: tcp name_connect
Traceback (most recent call last):
File /usr/bin/sepolicy, line 699, in <module>
args.func(args)
File /usr/bin/sepolicy, line 319, in network
_print_net(d, tcp, name_connect)
File /usr/bin/sepolicy, line 276, in _print_net
port_strings.sort(numcmp)
TypeError: must use keyword argument for key function
--- python/sepolicy/sepolicy.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
python/sepolicy/sepolicy.py +6 -12
@@ -241,19 +241,13 @@ def generate_custom_usage(usage_text, usage_dict): return usage_text - -def numcmp(val1, val2): +# expects formats: +# "22 (sshd_t)", "80, 8080 (httpd_t)", "all ports (port_type)" +def port_string_to_num(val): try: - v1 = int(val1.split(",")[0].split("-")[0]) - v2 = int(val2.split(",")[0].split("-")[0]) - if v1 > v2: - return 1 - if v1 == v2: - return 0 - if v1 < v2: - return -1 + return int(val.split(" ")[0].split(",")[0].split("-")[0]) except: - return cmp(val1, val2) + return 99999999 def _print_net(src, protocol, perm):
@@ -273,7 +267,7 @@ def _print_net(src, protocol, perm): port_strings.append("%s (%s) %s" % (", ".join(recs), t, boolean_text)) else: port_strings.append("%s (%s)" % (", ".join(recs), t)) - port_strings.sort(numcmp) + port_strings.sort(key=lambda param: port_string_to_num(param)) for p in port_strings: print("\t" + p)
Signature · 1 line
2.13.0
Stephen Smalley
AppliedRe: [PATCH 2/2] sepolicy: Fix sorting of port_strings in python 3
Quoted 13 lines · Petr Lautrbach
Fixes:
$ sepolicy network -d httpd_t
httpd_t: tcpname_connect
Traceback (most recent call last):
File/usr/bin/sepolicy, line 699, in <module>args.func(args)
File/usr/bin/sepolicy, line 319, in network_print_net(d, tcp, name_connect)
File/usr/bin/sepolicy, line 276, in_print_netport_strings.sort(numcmp)
TypeError: must use keyword argument for key function
Quoted 1 line
Signed-off-by Petr Lautrbach <[email protected]>
Thanks, applied both.
Quoted 47 lines
---
python/sepolicy/sepolicy.py | 18 ++++++------------1 file changed, 6 insertions(+), 12 deletions(-)python/sepolicy/sepolicy.py +0
-0@@ -241,19 +241,13 @@ def generate_custom_usage(usage_text,
usage_dict):
returnusage_textpython/sepolicy/sepolicy.py +3
-2- -def numcmp(val1, val2): +# expects formats: +# "22 (sshd_t)", "80, 8080 (httpd_t)", "all ports (port_type)" +def port_string_to_num(val):try:
- v1 = int(val1.split(",")[0].split("-")[0])
- v2 = int(val2.split(",")[0].split("-")[0])
- if v1 > v2:
- return 1
- if v1 == v2:
- return 0
- if v1 < v2:
- return -1
+ returnint(val.split(" ")[0].split(",")[0].split("-")[0])except:
- returncmp(val1, val2)
+ return 99999999
def_print_net(src, protocol, perm):python/sepolicy/sepolicy.py +0
-0@@ -273,7 +267,7 @@ def _print_net(src, protocol, perm): port_strings.append("%s (%s) %s" % (", ".join(recs), t, boolean_text))else:
port_strings.append("%s (%s)" % (", ".join(recs), t))
- port_strings.sort(numcmp)
+ port_strings.sort(key=lambda param:port_string_to_num(param))
for p inport_strings:
print("\t" + p)