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