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