summaryrefslogtreecommitdiff
path: root/lib/python2.7/site-packages/setools/portconquery.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python2.7/site-packages/setools/portconquery.py')
-rwxr-xr-x[-rw-r--r--]lib/python2.7/site-packages/setools/portconquery.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/lib/python2.7/site-packages/setools/portconquery.py b/lib/python2.7/site-packages/setools/portconquery.py
index 798a828..0b9627a 100644..100755
--- a/lib/python2.7/site-packages/setools/portconquery.py
+++ b/lib/python2.7/site-packages/setools/portconquery.py
@@ -19,11 +19,13 @@
import logging
from socket import IPPROTO_TCP, IPPROTO_UDP
-from . import contextquery
-from .policyrep.netcontext import port_range
+from .mixins import MatchContext
+from .query import PolicyQuery
+from .policyrep import port_range, PortconProtocol
+from .util import match_range
-class PortconQuery(contextquery.ContextQuery):
+class PortconQuery(MatchContext, PolicyQuery):
"""
Port context query.
@@ -105,30 +107,26 @@ class PortconQuery(contextquery.ContextQuery):
@protocol.setter
def protocol(self, value):
if value:
- if not (value == IPPROTO_TCP or value == IPPROTO_UDP):
- raise ValueError(
- "The protocol must be {0} for TCP or {1} for UDP.".
- format(IPPROTO_TCP, IPPROTO_UDP))
-
- self._protocol = value
+ self._protocol = PortconProtocol(value)
else:
self._protocol = None
+ def __init__(self, policy, **kwargs):
+ super(PortconQuery, self).__init__(policy, **kwargs)
+ self.log = logging.getLogger(__name__)
+
def results(self):
"""Generator which yields all matching portcons."""
- self.log.info("Generating results from {0.policy}".format(self))
+ self.log.info("Generating portcon results from {0.policy}".format(self))
self.log.debug("Ports: {0.ports}, overlap: {0.ports_overlap}, "
"subset: {0.ports_subset}, superset: {0.ports_superset}, "
"proper: {0.ports_proper}".format(self))
- self.log.debug("User: {0.user!r}, regex: {0.user_regex}".format(self))
- self.log.debug("Role: {0.role!r}, regex: {0.role_regex}".format(self))
- self.log.debug("Type: {0.type_!r}, regex: {0.type_regex}".format(self))
- self.log.debug("Range: {0.range_!r}, subset: {0.range_subset}, overlap: {0.range_overlap}, "
- "superset: {0.range_superset}, proper: {0.range_proper}".format(self))
+ self.log.debug("Protocol: {0.protocol!r}".format(self))
+ self._match_context_debug(self.log)
for portcon in self.policy.portcons():
- if self.ports and not self._match_range(
+ if self.ports and not match_range(
portcon.ports,
self.ports,
self.ports_subset,