1# Copyright (C) 2012 Red Hat 2# see file 'COPYING' for use and warranty information 3# 4# setrans is a tool for analyzing process transistions in SELinux policy 5# 6# This program is free software; you can redistribute it and/or 7# modify it under the terms of the GNU General Public License as 8# published by the Free Software Foundation; either version 2 of 9# the License, or (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program; if not, write to the Free Software 18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19# 02111-1307 USA 20# 21# 22import sepolicy 23import sys 24 25 26def usage(parser, msg): 27 parser.print_help() 28 29 sys.stderr.write("\n%s\n" % msg) 30 sys.stderr.flush() 31 sys.exit(1) 32 33 34def expand_attribute(attribute): 35 try: 36 return list(next(sepolicy.info(sepolicy.ATTRIBUTE, attribute))["types"]) 37 except StopIteration: 38 return [attribute] 39 40 41def get_types(src, tclass, perm): 42 allows = sepolicy.search([sepolicy.ALLOW], {sepolicy.SOURCE: src, sepolicy.CLASS: tclass, sepolicy.PERMS: perm}) 43 if not allows: 44 raise ValueError("The %s type is not allowed to %s any types" % (src, ",".join(perm))) 45 46 tlist = [] 47 for l in map(lambda y: y[sepolicy.TARGET], filter(lambda x: set(perm).issubset(x[sepolicy.PERMS]), allows)): 48 tlist = tlist + expand_attribute(l) 49 return tlist 50