Skip to contentSkip to conversation

python/semanage: Fix export of ibendport entries

PATCH New Vit Mojzis 2 participants 4 messages Nov 10, 2017 – Nov 15, 2017 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 python/semanage: Fix export of ibendport entries

Replace nonexistent switch "-x" by "-z" (entry name). Fix invalid index (the dictionary key is a 2-tuple). Add MLS/MCS range (present in all entries).

Fixes:
#semanage ibendport -E
File "/usr/sbin/semanage", line 1049, in <module>

    do_parser()
  File "/usr/sbin/semanage", line 1028, in do_parser
    args.func(args)
  File "/usr/sbin/semanage", line 605, in handleIbendport
    for i in OBJECT.customized():
  File "/usr/lib64/python2.7/site-packages/seobject/__init__.py", line 1806, in customized
    l.append("-a -t %s -x %s %s" % (ddict[k][0], k[2], k[0]))

IndexError: tuple index out of range

---
 python/semanage/seobject.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
python/semanage/seobject.py +1 -1
index 228c8ae..380256b 100644
@@ -1788,7 +1788,7 @@ class ibendportRecords(semanageRecords):
         keys = ddict.keys()
         keys.sort()
         for k in keys:
-            l.append("-a -t %s -x %s %s" % (ddict[k][0], k[2], k[0]))
+            l.append("-a -t %s -r %s -z %s %s" % (ddict[k][0], ddict[k][1], k[1], k[0]))
         return l
 
     def list(self, heading=1, locallist=0):
Signature · 1 line
2.9.4
author
#1 lore raw

PATCH 1/1 python/semanage: Update Infiniband code to work on python3

Update Infiniband "port" and "key" listing and export to work on python3.
{}.keys() does not support .sort() operation on Py3.

---
 python/semanage/seobject.py | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
python/semanage/seobject.py +6 -10
index 380256b..770745e 100644
@@ -1543,9 +1543,8 @@ class ibpkeyRecords(semanageRecords):
     def customized(self):
         l = []
         ddict = self.get_all(True)
-        keys = ddict.keys()
-        keys.sort()
-        for k in keys:
+
+        for k in sorted(ddict.keys()):
             if k[0] == k[1]:
                 l.append("-a -t %s -x %s %s" % (ddict[k][0], k[2], k[0]))
             else:
@@ -1557,11 +1556,10 @@ class ibpkeyRecords(semanageRecords):
         keys = ddict.keys()
         if len(keys) == 0:
             return
-        keys.sort()
 
         if heading:
             print("%-30s %-18s %s\n" % (_("SELinux IB Pkey Type"), _("Subnet_Prefix"), _("Pkey Number")))
-        for i in keys:
+        for i in sorted(keys):
             rec = "%-30s %-18s " % i
             rec += "%s" % ddict[i][0]
             for p in ddict[i][1:]:
@@ -1785,9 +1783,8 @@ class ibendportRecords(semanageRecords):
     def customized(self):
         l = []
         ddict = self.get_all(True)
-        keys = ddict.keys()
-        keys.sort()
-        for k in keys:
+
+        for k in sorted(ddict.keys()):
             l.append("-a -t %s -r %s -z %s %s" % (ddict[k][0], ddict[k][1], k[1], k[0]))
         return l
 
@@ -1796,11 +1793,10 @@ class ibendportRecords(semanageRecords):
         keys = ddict.keys()
         if len(keys) == 0:
             return
-        keys.sort()
 
         if heading:
             print("%-30s %-18s %s\n" % (_("SELinux IB End Port Type"), _("IB Device Name"), _("Port Number")))
-        for i in keys:
+        for i in sorted(keys):
             rec = "%-30s %-18s " % i
             rec += "%s" % ddict[i][0]
             for p in ddict[i][1:]:
Signature · 1 line
2.9.4
#2 lore raw

Re: [PATCH] python/semanage: Update Infiniband code to work on python3

Quoted 5 lines · Vit Mojzis

Update Infiniband "port" and "key" listing and export to work on python3.
{}.keys() does not support .sort() operation on Py3.

Both patches look good to me. I'll merge them tomorrow if there's no other comments.

Thanks,

Petr

Quoted 62 lines
---
 python/semanage/seobject.py | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
python/semanage/seobject.py +6 -10
index 380256b..770745e 100644
@@ -1543,9 +1543,8 @@ class ibpkeyRecords(semanageRecords):
     def customized(self):
         l = []
         ddict = self.get_all(True)
-        keys = ddict.keys()
-        keys.sort()
-        for k in keys:
+
+        for k in sorted(ddict.keys()):
             if k[0] == k[1]:
                 l.append("-a -t %s -x %s %s" % (ddict[k][0], k[2], k[0]))
             else:
@@ -1557,11 +1556,10 @@ class ibpkeyRecords(semanageRecords):
         keys = ddict.keys()
         if len(keys) == 0:
             return
-        keys.sort()
 
         if heading:
             print("%-30s %-18s %s\n" % (_("SELinux IB Pkey Type"), _("Subnet_Prefix"), _("Pkey Number")))
-        for i in keys:
+        for i in sorted(keys):
             rec = "%-30s %-18s " % i
             rec += "%s" % ddict[i][0]
             for p in ddict[i][1:]:
@@ -1785,9 +1783,8 @@ class ibendportRecords(semanageRecords):
     def customized(self):
         l = []
         ddict = self.get_all(True)
-        keys = ddict.keys()
-        keys.sort()
-        for k in keys:
+
+        for k in sorted(ddict.keys()):
             l.append("-a -t %s -r %s -z %s %s" % (ddict[k][0], ddict[k][1], k[1], k[0]))
         return l
 
@@ -1796,11 +1793,10 @@ class ibendportRecords(semanageRecords):
         keys = ddict.keys()
         if len(keys) == 0:
             return
-        keys.sort()
 
         if heading:
             print("%-30s %-18s %s\n" % (_("SELinux IB End Port Type"), _("IB Device Name"), _("Port Number")))
-        for i in keys:
+        for i in sorted(keys):
             rec = "%-30s %-18s " % i
             rec += "%s" % ddict[i][0]
             for p in ddict[i][1:]:
Signature · 1 line
2.9.4
#3 lore raw

Re: [PATCH] python/semanage: Update Infiniband code to work on python3

Quoted 10 lines · Petr Lautrbach
Quoted 5 lines · Vit Mojzis

Update Infiniband "port" and "key" listing and export to work on python3.
{}.keys() does not support .sort() operation on Py3.

Both patches look good to me. I'll merge them tomorrow if there's no other comments.

Merged. Thanks!

Quoted 65 lines
Quoted 64 lines

---
 python/semanage/seobject.py | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
python/semanage/seobject.py +6 -10
index 380256b..770745e 100644
@@ -1543,9 +1543,8 @@ class ibpkeyRecords(semanageRecords):
     def customized(self):
         l = []
         ddict = self.get_all(True)
-        keys = ddict.keys()
-        keys.sort()
-        for k in keys:
+
+        for k in sorted(ddict.keys()):
             if k[0] == k[1]:
                 l.append("-a -t %s -x %s %s" % (ddict[k][0], k[2], k[0]))
             else:
@@ -1557,11 +1556,10 @@ class ibpkeyRecords(semanageRecords):
         keys = ddict.keys()
         if len(keys) == 0:
             return
-        keys.sort()
 
         if heading:
             print("%-30s %-18s %s\n" % (_("SELinux IB Pkey Type"), _("Subnet_Prefix"), _("Pkey Number")))
-        for i in keys:
+        for i in sorted(keys):
             rec = "%-30s %-18s " % i
             rec += "%s" % ddict[i][0]
             for p in ddict[i][1:]:
@@ -1785,9 +1783,8 @@ class ibendportRecords(semanageRecords):
     def customized(self):
         l = []
         ddict = self.get_all(True)
-        keys = ddict.keys()
-        keys.sort()
-        for k in keys:
+
+        for k in sorted(ddict.keys()):
             l.append("-a -t %s -r %s -z %s %s" % (ddict[k][0], ddict[k][1], k[1], k[0]))
         return l
 
@@ -1796,11 +1793,10 @@ class ibendportRecords(semanageRecords):
         keys = ddict.keys()
         if len(keys) == 0:
             return
-        keys.sort()
 
         if heading:
             print("%-30s %-18s %s\n" % (_("SELinux IB End Port Type"), _("IB Device Name"), _("Port Number")))
-        for i in keys:
+        for i in sorted(keys):
             rec = "%-30s %-18s " % i
             rec += "%s" % ddict[i][0]
             for p in ddict[i][1:]:
Signature · 1 line
2.9.4