Skip to content

Commit

Permalink
[WIP] python/semanage: move valid_types initialisations to class cons…
Browse files Browse the repository at this point in the history
…tructors

This is to allow running "semanage" without triggering a stack trace
like in https://github.com/SELinuxProject/selinux SELinuxProject/issues/81.

TODO: gui/ uses seobject.portRecords several times. The result could be
cached, in a class attribute
TODO: IB data does not use sepolicy but reloads the policy !?!

Not-yet-Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
  • Loading branch information
fishilico committed Aug 15, 2018
1 parent 4d5df3d commit f8ab2c2
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions python/semanage/seobject.py
Expand Up @@ -1037,13 +1037,13 @@ 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 = []

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:
self.valid_types = []

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

class ibpkeyRecords(semanageRecords):
try:
q = setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_policy()), attrs=["ibpkey_type"])
valid_types = sorted(str(t) for t in q.results())
except ValueError:
valid_types = []

def __init__(self, args = None):
semanageRecords.__init__(self, args)
try:
q = setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_policy()), attrs=["ibpkey_type"])
self.alid_types = sorted(str(t) for t in q.results())
except ValueError:
self.valid_types = []

def __genkey(self, pkey, subnet_prefix):
if subnet_prefix == "":
Expand Down Expand Up @@ -1564,14 +1564,14 @@ def list(self, heading=1, locallist=0):
print(rec)

class ibendportRecords(semanageRecords):
try:
q = setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_policy()), attrs=["ibendport_type"])
valid_types = set(str(t) for t in q.results())
except ValueError:
valid_types = []

def __init__(self, args = None):
semanageRecords.__init__(self, args)
try:
q = setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_policy()), attrs=["ibendport_type"])
self.valid_types = set(str(t) for t in q.results())
except ValueError:
self.valid_types = []

def __genkey(self, ibendport, ibdev_name):
if ibdev_name == "":
Expand Down Expand Up @@ -1801,14 +1801,14 @@ 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 = []

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:
self.valid_types = []

def validate(self, addr, mask, protocol):
newaddr = addr
Expand Down Expand Up @@ -2232,15 +2232,15 @@ 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"])
valid_types.append("<<none>>")
except RuntimeError:
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"])
self.valid_types.append("<<none>>")
except RuntimeError:
self.valid_types = []
self.equiv = {}
self.equiv_dist = {}
self.equal_ind = False
Expand Down

0 comments on commit f8ab2c2

Please sign in to comment.