|
|
bccf27 |
From 716a1d9e1db6701c0b310dd7e10dc4a10656da0f Mon Sep 17 00:00:00 2001
|
|
|
bccf27 |
From: Chris PeBenito <chpebeni@linux.microsoft.com>
|
|
|
bccf27 |
Date: Tue, 14 Dec 2021 14:24:20 -0500
|
|
|
bccf27 |
Subject: [PATCH] Make NetworkX optional.
|
|
|
bccf27 |
Content-type: text/plain
|
|
|
bccf27 |
|
|
|
bccf27 |
The CLI tools get installed to most distros, but sedta and seinfoflow are
|
|
|
bccf27 |
not typically used or separated into a different package. This will allow
|
|
|
bccf27 |
seinfo, sesearch, and sediff to function if NetworkX is missing, since they
|
|
|
bccf27 |
don't require it.
|
|
|
bccf27 |
|
|
|
bccf27 |
Signed-off-by: Chris PeBenito <chpebeni@linux.microsoft.com>
|
|
|
bccf27 |
---
|
|
|
bccf27 |
setools/dta.py | 18 ++++++++++++++----
|
|
|
bccf27 |
setools/infoflow.py | 17 +++++++++++++----
|
|
|
bccf27 |
2 files changed, 27 insertions(+), 8 deletions(-)
|
|
|
bccf27 |
|
|
|
bccf27 |
diff --git a/setools/dta.py b/setools/dta.py
|
|
|
bccf27 |
index ce5a36463684..ded88ff4f615 100644
|
|
|
bccf27 |
--- a/setools/dta.py
|
|
|
bccf27 |
+++ b/setools/dta.py
|
|
|
bccf27 |
@@ -10,8 +10,11 @@ from collections import defaultdict
|
|
|
bccf27 |
from contextlib import suppress
|
|
|
bccf27 |
from typing import DefaultDict, Iterable, List, NamedTuple, Optional, Union
|
|
|
bccf27 |
|
|
|
bccf27 |
-import networkx as nx
|
|
|
bccf27 |
-from networkx.exception import NetworkXError, NetworkXNoPath, NodeNotFound
|
|
|
bccf27 |
+try:
|
|
|
bccf27 |
+ import networkx as nx
|
|
|
bccf27 |
+ from networkx.exception import NetworkXError, NetworkXNoPath, NodeNotFound
|
|
|
bccf27 |
+except ImportError:
|
|
|
bccf27 |
+ logging.getLogger(__name__).debug("NetworkX failed to import.")
|
|
|
bccf27 |
|
|
|
bccf27 |
from .descriptors import EdgeAttrDict, EdgeAttrList
|
|
|
bccf27 |
from .policyrep import AnyTERule, SELinuxPolicy, TERuletype, Type
|
|
|
bccf27 |
@@ -73,8 +76,15 @@ class DomainTransitionAnalysis:
|
|
|
bccf27 |
self.reverse = reverse
|
|
|
bccf27 |
self.rebuildgraph = True
|
|
|
bccf27 |
self.rebuildsubgraph = True
|
|
|
bccf27 |
- self.G = nx.DiGraph()
|
|
|
bccf27 |
- self.subG = self.G.copy()
|
|
|
bccf27 |
+
|
|
|
bccf27 |
+ try:
|
|
|
bccf27 |
+ self.G = nx.DiGraph()
|
|
|
bccf27 |
+ self.subG = self.G.copy()
|
|
|
bccf27 |
+ except NameError:
|
|
|
bccf27 |
+ self.log.critical("NetworkX is not available. This is "
|
|
|
bccf27 |
+ "requried for Domain Transition Analysis.")
|
|
|
bccf27 |
+ self.log.critical("This is typically in the python3-networkx package.")
|
|
|
bccf27 |
+ raise
|
|
|
bccf27 |
|
|
|
bccf27 |
@property
|
|
|
bccf27 |
def reverse(self) -> bool:
|
|
|
bccf27 |
diff --git a/setools/infoflow.py b/setools/infoflow.py
|
|
|
bccf27 |
index 0ef240a9993f..4b94a0c2d6dd 100644
|
|
|
bccf27 |
--- a/setools/infoflow.py
|
|
|
bccf27 |
+++ b/setools/infoflow.py
|
|
|
bccf27 |
@@ -7,8 +7,11 @@ import logging
|
|
|
bccf27 |
from contextlib import suppress
|
|
|
bccf27 |
from typing import cast, Iterable, List, Mapping, Optional, Union
|
|
|
bccf27 |
|
|
|
bccf27 |
-import networkx as nx
|
|
|
bccf27 |
-from networkx.exception import NetworkXError, NetworkXNoPath, NodeNotFound
|
|
|
bccf27 |
+try:
|
|
|
bccf27 |
+ import networkx as nx
|
|
|
bccf27 |
+ from networkx.exception import NetworkXError, NetworkXNoPath, NodeNotFound
|
|
|
bccf27 |
+except ImportError:
|
|
|
bccf27 |
+ logging.getLogger(__name__).debug("NetworkX failed to import.")
|
|
|
bccf27 |
|
|
|
bccf27 |
from .descriptors import EdgeAttrIntMax, EdgeAttrList
|
|
|
bccf27 |
from .permmap import PermissionMap
|
|
|
bccf27 |
@@ -54,8 +57,14 @@ class InfoFlowAnalysis:
|
|
|
bccf27 |
self.rebuildgraph = True
|
|
|
bccf27 |
self.rebuildsubgraph = True
|
|
|
bccf27 |
|
|
|
bccf27 |
- self.G = nx.DiGraph()
|
|
|
bccf27 |
- self.subG = self.G.copy()
|
|
|
bccf27 |
+ try:
|
|
|
bccf27 |
+ self.G = nx.DiGraph()
|
|
|
bccf27 |
+ self.subG = self.G.copy()
|
|
|
bccf27 |
+ except NameError:
|
|
|
bccf27 |
+ self.log.critical("NetworkX is not available. This is "
|
|
|
bccf27 |
+ "requried for Information Flow Analysis.")
|
|
|
bccf27 |
+ self.log.critical("This is typically in the python3-networkx package.")
|
|
|
bccf27 |
+ raise
|
|
|
bccf27 |
|
|
|
bccf27 |
@property
|
|
|
bccf27 |
def min_weight(self) -> int:
|
|
|
bccf27 |
--
|
|
|
bccf27 |
2.39.1
|
|
|
bccf27 |
|