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 import re 21 22 from . import compquery, mixins 23 24 25 class CommonQuery(mixins.MatchPermission, compquery.ComponentQuery): 26 27 """ 28 Query common permission sets. 29 30 Parameter: 31 policy The policy to query. 32 33 Keyword Parameters/Class attributes: 34 name The name of the common to match. 35 name_regex If true, regular expression matching will 36 be used for matching the name. 37 perms The permissions to match. 38 perms_equal If true, only commons with permission sets 39 that are equal to the criteria will 40 match. Otherwise, any intersection 41 will match. 42 perms_regex If true, regular expression matching will be used 43 on the permission names instead of set logic. 44 """ 45 46 def results(self): 47 """Generator which yields all matching commons.""" 48 self.log.info("Generating results from {0.policy}".format(self)) 49 self.log.debug("Name: {0.name!r}, regex: {0.name_regex}".format(self)) 50 self.log.debug("Perms: {0.perms!r}, regex: {0.perms_regex}, eq: {0.perms_equal}". 51 format(self)) 52 53 for com in self.policy.commons(): 54 if not self._match_name(com): 55 continue 56 57 if not self._match_perms(com): 58 continue 59 60 yield com 61