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 23 24 25def get_types(src, tclass, perm, check_bools=False): 26 allows = sepolicy.search([sepolicy.ALLOW], {sepolicy.SOURCE: src, sepolicy.CLASS: tclass, sepolicy.PERMS: perm}) 27 nlist = [] 28 if allows: 29 for i in map(lambda y: y[sepolicy.TARGET], filter(lambda x: set(perm).issubset(x[sepolicy.PERMS]) and (not check_bools or x["enabled"]), allows)): 30 if i not in nlist: 31 nlist.append(i) 32 return nlist 33 34 35def get_network_connect(src, protocol, perm, check_bools=False): 36 portrecs, portrecsbynum = sepolicy.gen_port_dict() 37 d = {} 38 tlist = get_types(src, "%s_socket" % protocol, [perm], check_bools) 39 if len(tlist) > 0: 40 d[(src, protocol, perm)] = [] 41 for i in tlist: 42 if i == "ephemeral_port_type": 43 if "unreserved_port_type" in tlist: 44 continue 45 i = "ephemeral_port_t" 46 if i == "unreserved_port_t": 47 if "unreserved_port_type" in tlist: 48 continue 49 if "port_t" in tlist: 50 continue 51 if i == "port_t": 52 d[(src, protocol, perm)].append((i, ["all ports with out defined types"])) 53 if i == "port_type": 54 d[(src, protocol, perm)].append((i, ["all ports"])) 55 elif i == "unreserved_port_type": 56 d[(src, protocol, perm)].append((i, ["all ports > 1024"])) 57 elif i == "reserved_port_type": 58 d[(src, protocol, perm)].append((i, ["all ports < 1024"])) 59 elif i == "rpc_port_type": 60 d[(src, protocol, perm)].append((i, ["all ports > 500 and < 1024"])) 61 else: 62 try: 63 d[(src, protocol, perm)].append((i, portrecs[(i, protocol)])) 64 except KeyError: 65 pass 66 return d 67