mirror of
https://github.com/SELinuxProject/setools
synced 2025-03-30 15:26:23 +00:00
policyrep: Refactor base classes for loading attributes on construction.
This commit is contained in:
parent
79b56f4fa8
commit
22967fa6a2
@ -22,48 +22,21 @@ cdef class PolicyRule(PolicySymbol):
|
|||||||
|
|
||||||
"""This is base class for policy rules."""
|
"""This is base class for policy rules."""
|
||||||
|
|
||||||
# This is initialized to False
|
|
||||||
cdef readonly bint extended
|
cdef:
|
||||||
|
uintptr_t key
|
||||||
|
readonly object ruletype
|
||||||
|
readonly object source
|
||||||
|
readonly object target
|
||||||
|
readonly object origin
|
||||||
|
# This is initialized to False:
|
||||||
|
readonly bint extended
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def __lt__(self, other):
|
def _eq(self, PolicyRule other):
|
||||||
return str(self) < str(other)
|
return self.key == other.key
|
||||||
|
|
||||||
@property
|
|
||||||
def ruletype(self):
|
|
||||||
"""The rule type for the rule."""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@property
|
|
||||||
def source(self):
|
|
||||||
"""
|
|
||||||
The source for the rule. This should be overridden by
|
|
||||||
subclasses.
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@property
|
|
||||||
def target(self):
|
|
||||||
"""
|
|
||||||
The target for the rule. This should be overridden by
|
|
||||||
subclasses.
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@property
|
|
||||||
def tclass(self):
|
|
||||||
"""The object class for the rule."""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@property
|
|
||||||
def default(self):
|
|
||||||
"""
|
|
||||||
The default for the rule. This should be overridden by
|
|
||||||
subclasses.
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def conditional(self):
|
def conditional(self):
|
||||||
|
@ -30,6 +30,15 @@ cdef class PolicySymbol:
|
|||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(str(self))
|
return hash(str(self))
|
||||||
|
|
||||||
|
def __copy__(self):
|
||||||
|
# Do not copy.
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __deepcopy__(self, memo):
|
||||||
|
# Do not copy.
|
||||||
|
memo[id(self)] = self
|
||||||
|
return self
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
try:
|
try:
|
||||||
# This is a regular Python function, so it cannot
|
# This is a regular Python function, so it cannot
|
||||||
@ -68,16 +77,13 @@ cdef class Ocontext(PolicySymbol):
|
|||||||
|
|
||||||
"""Base class for most in-policy labeling statements, (portcon, nodecon, etc.)"""
|
"""Base class for most in-policy labeling statements, (portcon, nodecon, etc.)"""
|
||||||
|
|
||||||
cdef sepol.ocontext_t *handle
|
cdef:
|
||||||
|
uintptr_t key
|
||||||
|
readonly Context context
|
||||||
|
|
||||||
def _eq(self, Ocontext other):
|
def _eq(self, Ocontext other):
|
||||||
"""Low-level equality check (C pointers)."""
|
"""Low-level equality check (C pointers)."""
|
||||||
return self.handle == other.handle
|
return self.key == other.key
|
||||||
|
|
||||||
@property
|
|
||||||
def context(self):
|
|
||||||
"""The context for this statement."""
|
|
||||||
return Context.factory(self.policy, self.handle.context)
|
|
||||||
|
|
||||||
def statement(self):
|
def statement(self):
|
||||||
return str(self)
|
return str(self)
|
||||||
|
@ -45,42 +45,10 @@ cdef class BaseTERule(PolicyRule):
|
|||||||
"""Base class for TE rules."""
|
"""Base class for TE rules."""
|
||||||
|
|
||||||
cdef:
|
cdef:
|
||||||
sepol.avtab_key_t *key
|
readonly ObjClass tclass
|
||||||
sepol.avtab_datum_t *datum
|
str rule_string
|
||||||
object rule_string
|
Conditional _conditional
|
||||||
object _conditional
|
bint _conditional_block
|
||||||
object _conditional_block
|
|
||||||
|
|
||||||
def __hash__(self):
|
|
||||||
return hash("{0.ruletype}|{0.source}|{0.target}|{0.tclass}|{1}|{2}".format(
|
|
||||||
self, self._conditional, self._conditional_block))
|
|
||||||
|
|
||||||
def _eq(self, BaseTERule other):
|
|
||||||
return self.key == other.key and self.datum == other.datum
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ruletype(self):
|
|
||||||
"""The rule type."""
|
|
||||||
# mask the enabled bit for the ruletype lookup in conditional rules
|
|
||||||
return TERuletype(self.key.specified & ~sepol.AVTAB_ENABLED)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def source(self):
|
|
||||||
"""The rule's source type/attribute."""
|
|
||||||
return type_or_attr_factory(self.policy,
|
|
||||||
self.policy.type_value_to_datum(self.key.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.key.target_type - 1))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def tclass(self):
|
|
||||||
"""The rule's object class."""
|
|
||||||
return ObjClass.factory(self.policy,
|
|
||||||
self.policy.class_value_to_datum(self.key.target_class - 1))
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def filename(self):
|
def filename(self):
|
||||||
|
@ -46,19 +46,17 @@ cdef class BaseType(PolicySymbol):
|
|||||||
|
|
||||||
"""Type/attribute base class."""
|
"""Type/attribute base class."""
|
||||||
|
|
||||||
cdef sepol.type_datum_t *handle
|
cdef:
|
||||||
|
sepol.type_datum_t *handle
|
||||||
|
readonly str name
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.policy.type_value_to_name(self.handle.s.value - 1)
|
return self.name
|
||||||
|
|
||||||
def _eq(self, BaseType other):
|
def _eq(self, BaseType other):
|
||||||
"""Low-level equality check (C pointers)."""
|
"""Low-level equality check (C pointers)."""
|
||||||
return self.handle == other.handle
|
return self.handle == other.handle
|
||||||
|
|
||||||
@property
|
|
||||||
def ispermissive(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def expand(self):
|
def expand(self):
|
||||||
"""Generator that expands this attribute into its member types."""
|
"""Generator that expands this attribute into its member types."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
Loading…
Reference in New Issue
Block a user