mirror of
https://github.com/SELinuxProject/setools
synced 2025-04-01 22:58:12 +00:00
MLSRule: Refactor to load attributes on construction.
This commit is contained in:
parent
14b131a693
commit
6f43c9deeb
@ -32,73 +32,27 @@ cdef class MLSRule(PolicyRule):
|
|||||||
"""An MLS rule."""
|
"""An MLS rule."""
|
||||||
|
|
||||||
cdef:
|
cdef:
|
||||||
sepol.range_trans_t *handle
|
readonly ObjClass tclass
|
||||||
object rng
|
object rng
|
||||||
readonly object ruletype
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef factory(SELinuxPolicy policy, sepol.range_trans_t *symbol, sepol.mls_range_t *rng):
|
cdef inline MLSRule factory(SELinuxPolicy policy, sepol.range_trans_t *symbol,
|
||||||
|
sepol.mls_range_t *rng):
|
||||||
"""Factory function for creating MLSRule objects."""
|
"""Factory function for creating MLSRule objects."""
|
||||||
r = MLSRule(Range.factory(policy, rng))
|
cdef MLSRule r = MLSRule.__new__(MLSRule)
|
||||||
r.policy = policy
|
r.policy = policy
|
||||||
r.handle = symbol
|
r.key = <uintptr_t>symbol
|
||||||
|
r.ruletype = MLSRuletype.range_transition
|
||||||
|
r.source = type_or_attr_factory(policy, policy.type_value_to_datum(symbol.source_type - 1))
|
||||||
|
r.target = type_or_attr_factory(policy, policy.type_value_to_datum(symbol.target_type - 1))
|
||||||
|
r.tclass = ObjClass.factory(policy, policy.class_value_to_datum(symbol.target_class - 1))
|
||||||
|
r.rng = Range.factory(policy, rng)
|
||||||
|
r.origin = None
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def __cinit__(self, rng):
|
|
||||||
self.ruletype = MLSRuletype.range_transition
|
|
||||||
self.rng = rng
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{0.ruletype} {0.source} {0.target}:{0.tclass} {0.default};".format(self)
|
return "{0.ruletype} {0.source} {0.target}:{0.tclass} {0.default};".format(self)
|
||||||
|
|
||||||
def _eq(self, MLSRule other):
|
|
||||||
"""Low-level equality check (C pointers)."""
|
|
||||||
return self.handle == other.handle
|
|
||||||
|
|
||||||
@property
|
|
||||||
def source(self):
|
|
||||||
"""The rule's source type/attribute."""
|
|
||||||
return type_or_attr_factory(self.policy,
|
|
||||||
self.policy.type_value_to_datum(self.handle.source_type - 1))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def target(self):
|
|
||||||
"""The rule's target type/attribute."""
|
|
||||||
return type_or_attr_factory(self.policy,
|
|
||||||
self.policy.type_value_to_datum(self.handle.target_type - 1))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def tclass(self):
|
|
||||||
"""The rule's object class."""
|
|
||||||
return ObjClass.factory(self.policy,
|
|
||||||
self.policy.class_value_to_datum(self.handle.target_class - 1))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def default(self):
|
|
||||||
"""The rule's default range."""
|
|
||||||
return self.rng
|
|
||||||
|
|
||||||
def expand(self):
|
|
||||||
"""Expand the rule into an equivalent set of rules without attributes."""
|
|
||||||
for s, t in itertools.product(self.source.expand(), self.target.expand()):
|
|
||||||
r = ExpandedMLSRule(self.rng)
|
|
||||||
r.policy = self.policy
|
|
||||||
r.handle = self.handle
|
|
||||||
r.source = s
|
|
||||||
r.target = t
|
|
||||||
r.origin = self
|
|
||||||
yield r
|
|
||||||
|
|
||||||
|
|
||||||
cdef class ExpandedMLSRule(MLSRule):
|
|
||||||
|
|
||||||
"""An expanded MLS rule."""
|
|
||||||
|
|
||||||
cdef:
|
|
||||||
public object source
|
|
||||||
public object target
|
|
||||||
public object origin
|
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
try:
|
try:
|
||||||
cond = self.conditional
|
cond = self.conditional
|
||||||
@ -113,6 +67,31 @@ cdef class ExpandedMLSRule(MLSRule):
|
|||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return str(self) < str(other)
|
return str(self) < str(other)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def default(self):
|
||||||
|
"""The rule's default range."""
|
||||||
|
return self.rng
|
||||||
|
|
||||||
|
def expand(self):
|
||||||
|
"""Expand the rule into an equivalent set of rules without attributes."""
|
||||||
|
cdef MLSRule r
|
||||||
|
if self.origin is None:
|
||||||
|
for s, t in itertools.product(self.source.expand(), self.target.expand()):
|
||||||
|
r = MLSRule.__new__(MLSRule)
|
||||||
|
r.policy = self.policy
|
||||||
|
r.key = self.key
|
||||||
|
r.ruletype = self.ruletype
|
||||||
|
r.source = s
|
||||||
|
r.target = t
|
||||||
|
r.tclass = self.tclass
|
||||||
|
r.rng = self.rng
|
||||||
|
r.origin = self
|
||||||
|
yield r
|
||||||
|
|
||||||
|
else:
|
||||||
|
# this rule is already expanded.
|
||||||
|
yield self
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Iterators
|
# Iterators
|
||||||
|
Loading…
Reference in New Issue
Block a user