Skip to contentSkip to conversation

python/sepolicy: Support non-MLS policy

PATCH New Nicolas Iooss 1 participant 3 messages Feb 14, 2018 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 python/sepolicy: Support non-MLS policy

When using sepolgen GUI on a system with a non-MLS policy, sepolicy.info(sepolicy.PORT) does not define "range" attributes (since commit 908340e8e7a9 ("sepolicy: support non-MLS policy in manpage")). Replace them with None in get_all_ports() result.

---
 python/sepolicy/sepolicy/generate.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
python/sepolicy/sepolicy/generate.py +1 -1
index d68f96ef5ca5..35623a01acfe 100644
@@ -105,7 +105,7 @@ def get_all_ports():
                 p['type'] == "port_t" or \
                 p['type'] == "hi_reserved_port_t":
             continue
-        dict[(p['low'], p['high'], p['protocol'])] = (p['type'], p['range'])
+        dict[(p['low'], p['high'], p['protocol'])] = (p['type'], p.get('range'))
     return dict
 
 
Signature · 1 line
2.16.0
#1 lore raw

PATCH 2/3 python/sepolicy: Initialize policy.ports as a dict in generate.py

in class policy, ports is usually initialized with the result of get_all_ports(), which is a dict. If this function failed, the error was not fatal but ports was left initialized as a list, which would trigger other errors when accessing it.

Initialize ports as an empty dict in order to fix this issue.

---
 python/sepolicy/sepolicy/generate.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
python/sepolicy/sepolicy/generate.py +1 -1
index 35623a01acfe..f885425806f1 100644
@@ -198,7 +198,7 @@ class policy:
 
     def __init__(self, name, type):
         self.rpms = []
-        self.ports = []
+        self.ports = {}
         self.all_roles = get_all_roles()
         self.types = []
 
Signature · 1 line
2.16.0
#2 lore raw

PATCH 3/3 python/sepolicy: Fix translated strings with parameters

In reply to Nicolas Iooss

When a translated string takes parameters with %, the % and the parameters need to be after the call to the underline function in order to work properly.

---
 python/sepolicy/sepolicy/generate.py  |  2 +-
 python/sepolicy/sepolicy/gui.py       | 28 ++++++++++++++--------------
 python/sepolicy/sepolicy/interface.py |  4 ++--
 3 files changed, 17 insertions(+), 17 deletions(-)
python/sepolicy/sepolicy/generate.py +1 -1
index f885425806f1..325a3888be2b 100644
@@ -191,7 +191,7 @@ def verify_ports(ports):
                 temp.append(p)
         return temp
     except ValueError:
-        raise ValueError(_("Ports must be numbers or ranges of numbers from 1 to %d " % max_port))
+        raise ValueError(_("Ports must be numbers or ranges of numbers from 1 to %d ") % max_port)
 
 
 class policy:
python/sepolicy/sepolicy/gui.py +14 -14
index 6562aa850c98..537d5168a536 100644
@@ -500,7 +500,7 @@ class SELinuxGui():
         self.all_domains.sort(key=str.lower)
 
         if app and app not in self.all_domains:
-            self.error(_("%s is not a valid domain" % app))
+            self.error(_("%s is not a valid domain") % app)
             self.quit()
 
         loading_gui.show()
@@ -1056,21 +1056,21 @@ class SELinuxGui():
         self.application_files_initialize(app)
         self.transitions_files_initialize(app)
 
-        self.executable_files_tab.set_tooltip_text(_("File path used to enter the '%s' domain." % app))
-        self.writable_files_tab.set_tooltip_text(_("Files to which the '%s' domain can write." % app))
-        self.network_out_tab.set_tooltip_text(_("Network Ports to which the '%s' is allowed to connect." % app))
-        self.network_in_tab.set_tooltip_text(_("Network Ports to which the '%s' is allowed to listen." % app))
-        self.application_files_tab.set_tooltip_text(_("File Types defined for the '%s'." % app))
-        self.boolean_radio_button.set_tooltip_text(_("Display boolean information that can be used to modify the policy for the '%s'." % app))
-        self.files_radio_button.set_tooltip_text(_("Display file type information that can be used by the '%s'." % app))
-        self.network_radio_button.set_tooltip_text(_("Display network ports to which the '%s' can connect or listen to." % app))
-        self.transitions_into_tab.set_label(_("Application Transitions Into '%s'" % app))
-        self.transitions_from_tab.set_label(_("Application Transitions From '%s'" % app))
-        self.transitions_file_tab.set_label(_("File Transitions From '%s'" % app))
+        self.executable_files_tab.set_tooltip_text(_("File path used to enter the '%s' domain.") % app)
+        self.writable_files_tab.set_tooltip_text(_("Files to which the '%s' domain can write.") % app)
+        self.network_out_tab.set_tooltip_text(_("Network Ports to which the '%s' is allowed to connect.") % app)
+        self.network_in_tab.set_tooltip_text(_("Network Ports to which the '%s' is allowed to listen.") % app)
+        self.application_files_tab.set_tooltip_text(_("File Types defined for the '%s'.") % app)
+        self.boolean_radio_button.set_tooltip_text(_("Display boolean information that can be used to modify the policy for the '%s'.") % app)
+        self.files_radio_button.set_tooltip_text(_("Display file type information that can be used by the '%s'.") % app)
+        self.network_radio_button.set_tooltip_text(_("Display network ports to which the '%s' can connect or listen to.") % app)
+        self.transitions_into_tab.set_label(_("Application Transitions Into '%s'") % app)
+        self.transitions_from_tab.set_label(_("Application Transitions From '%s'") % app)
+        self.transitions_file_tab.set_label(_("File Transitions From '%s'") % app)
         self.transitions_into_tab.set_tooltip_text(_("Executables which will transition to '%s', when executing selected domains entrypoint.") % app)
         self.transitions_from_tab.set_tooltip_text(_("Executables which will transition to a different domain, when '%s' executes them.") % app)
-        self.transitions_file_tab.set_tooltip_text(_("Files by '%s' with transitions to a different label." % app))
-        self.transitions_radio_button.set_tooltip_text(_("Display applications that can transition into or out of the '%s'." % app))
+        self.transitions_file_tab.set_tooltip_text(_("Files by '%s' with transitions to a different label.") % app)
+        self.transitions_radio_button.set_tooltip_text(_("Display applications that can transition into or out of the '%s'.") % app)
 
         self.application = app
         self.applications_selection_button.set_label(self.application)
python/sepolicy/sepolicy/interface.py +2 -2
index c64122e5e565..18374dcfed96 100644
@@ -220,7 +220,7 @@ def interface_compile_test(interface, path="/usr/share/selinux/devel/policy.xml"
     idict = get_interface_dict(path)
 
     if not (interface.split("_")[0] in exclude_interfaces or idict[interface][2] in exclude_interface_type):
-        print(_("Compiling %s interface" % interface))
+        print(_("Compiling %s interface") % interface)
         try:
             fd = open(policy_files['te'], "w")
             fd.write(generate_compile_te(interface, idict))
@@ -237,4 +237,4 @@ def interface_compile_test(interface, path="/usr/share/selinux/devel/policy.xml"
                 os.remove(v)
 
     else:
-        sys.stderr.write(_("\nCompiling of %s interface is not supported." % interface))
+        sys.stderr.write(_("\nCompiling of %s interface is not supported.") % interface)
Signature · 1 line
2.16.0