1 # Copyright 2014-2015, Tresys Technology, LLC 2 # 3 # This file is part of SETools. 4 # 5 # SETools is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU Lesser General Public License as 7 # published by the Free Software Foundation, either version 2.1 of 8 # the License, or (at your option) any later version. 9 # 10 # SETools is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU Lesser General Public License for more details. 14 # 15 # You should have received a copy of the GNU Lesser General Public 16 # License along with SETools. If not, see 17 # <http://www.gnu.org/licenses/>. 18 # 19 import logging 20 21 22 class PolicyQuery(object): 23 24 """Base class for SELinux policy queries.""" 25 26 def __init__(self, policy, **kwargs): 27 self.policy = policy 28 29 # keys are sorted in reverse order so regex settings 30 # are set before the criteria, e.g. name_regex 31 # is set before name. This ensures correct behavior 32 # since the criteria descriptors are sensitve to 33 # regex settings. 34 for name in sorted(kwargs.keys(), reverse=True): 35 attr = getattr(self, name, None) # None is not callable 36 if callable(attr): 37 raise ValueError("Keyword parameter {0} conflicts with a callable.".format(name)) 38 39 setattr(self, name, kwargs[name]) 40 41 def results(self): 42 """ 43 Generator which returns the matches for the query. This method 44 should be overridden by subclasses. 45 """ 46 raise NotImplementedError 47