summaryrefslogtreecommitdiff
path: root/lib/python2.7/site-packages/setools/infoflow.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python2.7/site-packages/setools/infoflow.py')
-rwxr-xr-x[-rw-r--r--]lib/python2.7/site-packages/setools/infoflow.py51
1 files changed, 35 insertions, 16 deletions
diff --git a/lib/python2.7/site-packages/setools/infoflow.py b/lib/python2.7/site-packages/setools/infoflow.py
index 5812828..15eb38e 100644..100755
--- a/lib/python2.7/site-packages/setools/infoflow.py
+++ b/lib/python2.7/site-packages/setools/infoflow.py
@@ -41,7 +41,7 @@ class InfoFlowAnalysis(object):
exclude The types excluded from the information flow analysis.
(default is none)
"""
- self.log = logging.getLogger(self.__class__.__name__)
+ self.log = logging.getLogger(__name__)
self.policy = policy
@@ -113,7 +113,8 @@ class InfoFlowAnalysis(object):
if self.rebuildsubgraph:
self._build_subgraph()
- self.log.info("Generating one shortest path from {0} to {1}...".format(s, t))
+ self.log.info("Generating one shortest information flow path from {0} to {1}...".
+ format(s, t))
try:
yield self.__generate_steps(nx.shortest_path(self.subG, s, t))
@@ -153,7 +154,8 @@ class InfoFlowAnalysis(object):
if self.rebuildsubgraph:
self._build_subgraph()
- self.log.info("Generating all paths from {0} to {1}, max len {2}...".format(s, t, maxlen))
+ self.log.info("Generating all information flow paths from {0} to {1}, max length {2}...".
+ format(s, t, maxlen))
try:
for path in nx.all_simple_paths(self.subG, s, t, maxlen):
@@ -188,7 +190,8 @@ class InfoFlowAnalysis(object):
if self.rebuildsubgraph:
self._build_subgraph()
- self.log.info("Generating all shortest paths from {0} to {1}...".format(s, t))
+ self.log.info("Generating all shortest information flow paths from {0} to {1}...".
+ format(s, t))
try:
for path in nx.all_shortest_paths(self.subG, s, t):
@@ -226,7 +229,8 @@ class InfoFlowAnalysis(object):
if self.rebuildsubgraph:
self._build_subgraph()
- self.log.info("Generating all infoflows {0} {1}".format("out of" if out else "into", s))
+ self.log.info("Generating all information flows {0} {1}".
+ format("out of" if out else "into", s))
if out:
flows = self.subG.out_edges_iter(s)
@@ -294,7 +298,7 @@ class InfoFlowAnalysis(object):
self.perm_map.map_policy(self.policy)
- self.log.info("Building graph from {0}...".format(self.policy))
+ self.log.info("Building information flow graph from {0}...".format(self.policy))
for rule in self.policy.terules():
if rule.ruletype != "allow":
@@ -318,13 +322,16 @@ class InfoFlowAnalysis(object):
self.rebuildgraph = False
self.rebuildsubgraph = True
- self.log.info("Completed building graph.")
+ self.log.info("Completed building information flow graph.")
+ self.log.debug("Graph stats: nodes: {0}, edges: {1}.".format(
+ nx.number_of_nodes(self.G),
+ nx.number_of_edges(self.G)))
def _build_subgraph(self):
if self.rebuildgraph:
self._build_graph()
- self.log.info("Building subgraph...")
+ self.log.info("Building information flow subgraph...")
self.log.debug("Excluding {0!r}".format(self.exclude))
self.log.debug("Min weight {0}".format(self.min_weight))
@@ -345,7 +352,10 @@ class InfoFlowAnalysis(object):
self.subG.remove_edges_from(delete_list)
self.rebuildsubgraph = False
- self.log.info("Completed building subgraph.")
+ self.log.info("Completed building information flow subgraph.")
+ self.log.debug("Subgraph stats: nodes: {0}, edges: {1}.".format(
+ nx.number_of_nodes(self.subG),
+ nx.number_of_edges(self.subG)))
class Edge(object):
@@ -354,6 +364,7 @@ class Edge(object):
A graph edge. Also used for returning information flow steps.
Parameters:
+ graph The NetworkX graph.
source The source type of the edge.
target The target type of the edge.
@@ -376,12 +387,6 @@ class Edge(object):
self.source = source
self.target = target
- # a bit of a hack to make edges work
- # in NetworkX functions that work on
- # 2-tuples of (source, target)
- # (see __getitem__ below)
- self.st_tuple = (source, target)
-
if not self.G.has_edge(source, target):
if create:
self.G.add_edge(source, target, weight=1)
@@ -391,4 +396,18 @@ class Edge(object):
raise ValueError("Edge does not exist in graph")
def __getitem__(self, key):
- return self.st_tuple[key]
+ # This is implemented so this object can be used in NetworkX
+ # functions that operate on (source, target) tuples
+ if isinstance(key, slice):
+ return [self._index_to_item(i) for i in range(* key.indices(2))]
+ else:
+ return self._index_to_item(key)
+
+ def _index_to_item(self, index):
+ """Return source or target based on index."""
+ if index == 0:
+ return self.source
+ elif index == 1:
+ return self.target
+ else:
+ raise IndexError("Invalid index (edges only have 2 items): {0}".format(index))