mirror of
https://github.com/SELinuxProject/setools
synced 2025-05-11 04:33:37 +00:00
DirectedGraphAnalysis: Create new base class for graph analyses.
Also move typing imports into TYPE_CHECKING block. Signed-off-by: Chris PeBenito <pebenito@ieee.org>
This commit is contained in:
parent
f253e4e56e
commit
e3a65cc0b8
@ -20,6 +20,7 @@ except ImportError:
|
|||||||
from .descriptors import EdgeAttrDict, EdgeAttrList
|
from .descriptors import EdgeAttrDict, EdgeAttrList
|
||||||
from .mixins import NetworkXGraphEdge
|
from .mixins import NetworkXGraphEdge
|
||||||
from .policyrep import AnyTERule, SELinuxPolicy, TERuletype, Type
|
from .policyrep import AnyTERule, SELinuxPolicy, TERuletype, Type
|
||||||
|
from .query import DirectedGraphAnalysis
|
||||||
|
|
||||||
__all__ = ['DomainTransitionAnalysis', 'DomainTransition', 'DomainEntrypoint', 'DTAPath']
|
__all__ = ['DomainTransitionAnalysis', 'DomainTransition', 'DomainEntrypoint', 'DTAPath']
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ DTAPath = Iterable[DomainTransition]
|
|||||||
RuleHash = DefaultDict[Type, List[AnyTERule]]
|
RuleHash = DefaultDict[Type, List[AnyTERule]]
|
||||||
|
|
||||||
|
|
||||||
class DomainTransitionAnalysis:
|
class DomainTransitionAnalysis(DirectedGraphAnalysis):
|
||||||
|
|
||||||
"""Domain transition analysis."""
|
"""Domain transition analysis."""
|
||||||
|
|
||||||
|
@ -18,13 +18,14 @@ from .descriptors import EdgeAttrIntMax, EdgeAttrList
|
|||||||
from .mixins import NetworkXGraphEdge
|
from .mixins import NetworkXGraphEdge
|
||||||
from .permmap import PermissionMap
|
from .permmap import PermissionMap
|
||||||
from .policyrep import AVRule, SELinuxPolicy, TERuletype, Type
|
from .policyrep import AVRule, SELinuxPolicy, TERuletype, Type
|
||||||
|
from .query import DirectedGraphAnalysis
|
||||||
|
|
||||||
__all__ = ['InfoFlowAnalysis']
|
__all__ = ['InfoFlowAnalysis']
|
||||||
|
|
||||||
InfoFlowPath = Iterable['InfoFlowStep']
|
InfoFlowPath = Iterable['InfoFlowStep']
|
||||||
|
|
||||||
|
|
||||||
class InfoFlowAnalysis:
|
class InfoFlowAnalysis(DirectedGraphAnalysis):
|
||||||
|
|
||||||
"""Information flow analysis."""
|
"""Information flow analysis."""
|
||||||
|
|
||||||
|
@ -4,21 +4,24 @@
|
|||||||
# SPDX-License-Identifier: LGPL-2.1-only
|
# SPDX-License-Identifier: LGPL-2.1-only
|
||||||
#
|
#
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from logging import Logger
|
from typing import TYPE_CHECKING
|
||||||
from typing import Iterable
|
|
||||||
|
|
||||||
from .policyrep import SELinuxPolicy
|
if TYPE_CHECKING:
|
||||||
|
from logging import Logger
|
||||||
|
from typing import Iterable
|
||||||
|
from networkx import DiGraph
|
||||||
|
from .policyrep import SELinuxPolicy
|
||||||
|
|
||||||
|
|
||||||
class PolicyQuery(ABC):
|
class PolicyQuery(ABC):
|
||||||
|
|
||||||
"""Abstract base class for SELinux policy queries."""
|
"""Abstract base class for all SELinux policy analyses."""
|
||||||
|
|
||||||
log: Logger
|
log: "Logger"
|
||||||
policy: SELinuxPolicy
|
policy: "SELinuxPolicy"
|
||||||
|
|
||||||
def __init__(self, policy: SELinuxPolicy, **kwargs) -> None:
|
def __init__(self, policy: "SELinuxPolicy", **kwargs) -> None:
|
||||||
self.policy = policy
|
self.policy: "SELinuxPolicy" = policy
|
||||||
|
|
||||||
# keys are sorted in reverse order so regex settings
|
# keys are sorted in reverse order so regex settings
|
||||||
# are set before the criteria, e.g. name_regex
|
# are set before the criteria, e.g. name_regex
|
||||||
@ -33,9 +36,16 @@ class PolicyQuery(ABC):
|
|||||||
setattr(self, name, kwargs[name])
|
setattr(self, name, kwargs[name])
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def results(self) -> Iterable:
|
def results(self) -> "Iterable":
|
||||||
"""
|
"""
|
||||||
Generator which returns the matches for the query. This method
|
Generator which returns the matches for the query. This method
|
||||||
should be overridden by subclasses.
|
should be overridden by subclasses.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DirectedGraphAnalysis(PolicyQuery):
|
||||||
|
|
||||||
|
"""Abstract base class for graph-basded SELinux policy analysis."""
|
||||||
|
|
||||||
|
G: "DiGraph"
|
||||||
|
Loading…
Reference in New Issue
Block a user