mirror of
https://github.com/SELinuxProject/setools
synced 2025-04-01 14:48:07 +00:00
FSUse/Genfscon: Refactor to load attributes on construction.
This commit is contained in:
parent
3c8f2d9ad4
commit
f1d8e4aef6
@ -36,13 +36,19 @@ cdef class FSUse(Ocontext):
|
|||||||
|
|
||||||
"""An fs_use_* statement."""
|
"""An fs_use_* statement."""
|
||||||
|
|
||||||
|
cdef:
|
||||||
|
readonly object ruletype
|
||||||
|
readonly str fs
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef factory(SELinuxPolicy policy, sepol.ocontext_t *symbol):
|
cdef inline FSUse factory(SELinuxPolicy policy, sepol.ocontext_t *symbol):
|
||||||
"""Factory function for creating FSUse objects."""
|
"""Factory function for creating FSUse objects."""
|
||||||
r = FSUse()
|
cdef FSUse f = FSUse.__new__(FSUse)
|
||||||
r.policy = policy
|
f.policy = policy
|
||||||
r.handle = symbol
|
f.ruletype = FSUseRuletype(symbol.v.behavior)
|
||||||
return r
|
f.fs = intern(symbol.u.name)
|
||||||
|
f.context = Context.factory(policy, symbol.context)
|
||||||
|
return f
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{0.ruletype} {0.fs} {0.context};".format(self)
|
return "{0.ruletype} {0.fs} {0.context};".format(self)
|
||||||
@ -54,16 +60,6 @@ cdef class FSUse(Ocontext):
|
|||||||
# this is used by Python sorting functions
|
# this is used by Python sorting functions
|
||||||
return str(self) < str(other)
|
return str(self) < str(other)
|
||||||
|
|
||||||
@property
|
|
||||||
def fs(self):
|
|
||||||
"""The filesystem type for this statement."""
|
|
||||||
return intern(self.handle.u.name)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ruletype(self):
|
|
||||||
"""The rule type for this fs_use_* statement."""
|
|
||||||
return FSUseRuletype(self.handle.v.behavior)
|
|
||||||
|
|
||||||
|
|
||||||
class GenfsFiletype(int):
|
class GenfsFiletype(int):
|
||||||
|
|
||||||
@ -95,7 +91,10 @@ cdef class Genfscon(Ocontext):
|
|||||||
|
|
||||||
"""A genfscon statement."""
|
"""A genfscon statement."""
|
||||||
|
|
||||||
cdef readonly str fs
|
cdef:
|
||||||
|
readonly str fs
|
||||||
|
readonly object filetype
|
||||||
|
readonly str path
|
||||||
|
|
||||||
_sclass_to_stat = {0: 0,
|
_sclass_to_stat = {0: 0,
|
||||||
sepol.SECCLASS_BLK_FILE: S_IFBLK,
|
sepol.SECCLASS_BLK_FILE: S_IFBLK,
|
||||||
@ -107,13 +106,16 @@ cdef class Genfscon(Ocontext):
|
|||||||
sepol.SECCLASS_SOCK_FILE: S_IFSOCK}
|
sepol.SECCLASS_SOCK_FILE: S_IFSOCK}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef factory(SELinuxPolicy policy, sepol.ocontext_t *symbol, fstype):
|
cdef inline Genfscon factory(SELinuxPolicy policy, sepol.ocontext_t *symbol, fstype):
|
||||||
"""Factory function for creating Genfscon objects."""
|
"""Factory function for creating Genfscon objects."""
|
||||||
r = Genfscon()
|
cdef Genfscon g = Genfscon.__new__(Genfscon)
|
||||||
r.policy = policy
|
g.policy = policy
|
||||||
r.handle = symbol
|
g.key = <uintptr_t>symbol
|
||||||
r.fs = fstype
|
g.fs = fstype
|
||||||
return r
|
g.filetype = GenfsFiletype(Genfscon._sclass_to_stat[symbol.v.sclass])
|
||||||
|
g.path = intern(symbol.u.name)
|
||||||
|
g.context = Context.factory(policy, symbol.context)
|
||||||
|
return g
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "genfscon {0.fs} {0.path} {0.filetype} {0.context}".format(self)
|
return "genfscon {0.fs} {0.path} {0.filetype} {0.context}".format(self)
|
||||||
@ -125,16 +127,6 @@ cdef class Genfscon(Ocontext):
|
|||||||
# this is used by Python sorting functions
|
# this is used by Python sorting functions
|
||||||
return str(self) < str(other)
|
return str(self) < str(other)
|
||||||
|
|
||||||
@property
|
|
||||||
def filetype(self):
|
|
||||||
"""The file type (e.g. stat.S_IFBLK) for this genfscon statement."""
|
|
||||||
return GenfsFiletype(self._sclass_to_stat[self.handle.v.sclass])
|
|
||||||
|
|
||||||
@property
|
|
||||||
def path(self):
|
|
||||||
"""The path for this genfscon statement."""
|
|
||||||
return intern(self.handle.u.name)
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Iterators
|
# Iterators
|
||||||
|
Loading…
Reference in New Issue
Block a user