Skip to content

Commit

Permalink
python/semanage: move valid_types initialisations to class constructors
Browse files Browse the repository at this point in the history
Based on idea from Nicolas Iooss <nicolas.iooss@m4x.org>

Fixes:
$ sudo semanage
Traceback (most recent call last):
  File "/usr/sbin/semanage", line 28, in <module>
    import seobject
  File "/usr/lib/python3.7/site-packages/seobject.py", line 1045, in <module>
    class portRecords(semanageRecords):
  File "/usr/lib/python3.7/site-packages/seobject.py", line 1047, in portRecords
    valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "port_type"))[0]["types"])
  File "/usr/lib/python3.7/site-packages/sepolicy/__init__.py", line 203, in <genexpr>
    return ({
  File "/usr/lib64/python3.7/site-packages/setools/typeattrquery.py", line 65, in results
    for attr in self.policy.typeattributes():
AttributeError: 'NoneType' object has no attribute 'typeattributes'

SELinuxProject#81

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
  • Loading branch information
bachradsusi committed Dec 20, 2018
1 parent 8a8a4f8 commit 8c3ce4a
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions python/semanage/seobject.py
Expand Up @@ -1043,13 +1043,15 @@ def list(self, heading=1, locallist=0):


class portRecords(semanageRecords):
try:
valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "port_type"))[0]["types"])
except RuntimeError:
valid_types = []

valid_types = []

def __init__(self, args = None):
semanageRecords.__init__(self, args)
try:
self.valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "port_type"))[0]["types"])
except RuntimeError:
pass

def __genkey(self, port, proto):
if proto == "tcp":
Expand Down Expand Up @@ -1823,14 +1825,16 @@ def list(self, heading=1, locallist=0):
print(rec)

class nodeRecords(semanageRecords):
try:
valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "node_type"))[0]["types"])
except RuntimeError:
valid_types = []

valid_types = []

def __init__(self, args = None):
semanageRecords.__init__(self, args)
self.protocol = ["ipv4", "ipv6"]
try:
self.valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "node_type"))[0]["types"])
except RuntimeError:
pass

def validate(self, addr, mask, protocol):
newaddr = addr
Expand Down Expand Up @@ -2264,14 +2268,17 @@ def list(self, heading=1, locallist=0):


class fcontextRecords(semanageRecords):
try:
valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "file_type"))[0]["types"])
valid_types += list(list(sepolicy.info(sepolicy.ATTRIBUTE, "device_node"))[0]["types"])
except RuntimeError:
valid_types = []

valid_types = []

def __init__(self, args = None):
semanageRecords.__init__(self, args)
try:
self.valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "file_type"))[0]["types"])
self.valid_types += list(list(sepolicy.info(sepolicy.ATTRIBUTE, "device_node"))[0]["types"])
except RuntimeError:
pass

self.equiv = {}
self.equiv_dist = {}
self.equal_ind = False
Expand Down

0 comments on commit 8c3ce4a

Please sign in to comment.