1## domainsPage.py - show selinux domains 2## Copyright (C) 2009 Red Hat, Inc. 3 4## This program is free software; you can redistribute it and/or modify 5## it under the terms of the GNU General Public License as published by 6## the Free Software Foundation; either version 2 of the License, or 7## (at your option) any later version. 8 9## This program is distributed in the hope that it will be useful, 10## but WITHOUT ANY WARRANTY; without even the implied warranty of 11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12## GNU General Public License for more details. 13 14## You should have received a copy of the GNU General Public License 15## along with this program; if not, write to the Free Software 16## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 18## Author: Dan Walsh 19import string 20import gtk 21import gtk.glade 22import os 23import commands 24import gobject 25import sys 26import seobject 27import selinux 28from semanagePage import * 29from sepolicy import get_all_entrypoint_domains 30 31## 32## I18N 33## 34PROGNAME = "policycoreutils" 35import gettext 36gettext.bindtextdomain(PROGNAME, "/usr/share/locale") 37gettext.textdomain(PROGNAME) 38try: 39 gettext.install(PROGNAME, 40 localedir="/usr/share/locale", 41 unicode=False, 42 codeset='utf-8') 43except IOError: 44 import __builtin__ 45 __builtin__.__dict__['_'] = unicode 46 47 48class domainsPage(semanagePage): 49 50 def __init__(self, xml): 51 semanagePage.__init__(self, xml, "domains", _("Process Domain")) 52 self.domain_filter = xml.get_widget("domainsFilterEntry") 53 self.domain_filter.connect("focus_out_event", self.filter_changed) 54 self.domain_filter.connect("activate", self.filter_changed) 55 56 self.store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) 57 self.view.set_model(self.store) 58 self.store.set_sort_column_id(0, gtk.SORT_ASCENDING) 59 col = gtk.TreeViewColumn(_("Domain Name"), gtk.CellRendererText(), text=0) 60 col.set_sort_column_id(0) 61 col.set_resizable(True) 62 self.view.append_column(col) 63 self.store.set_sort_column_id(0, gtk.SORT_ASCENDING) 64 col = gtk.TreeViewColumn(_("Mode"), gtk.CellRendererText(), text=1) 65 col.set_sort_column_id(1) 66 col.set_resizable(True) 67 self.view.append_column(col) 68 self.view.get_selection().connect("changed", self.itemSelected) 69 70 self.permissive_button = xml.get_widget("permissiveButton") 71 self.enforcing_button = xml.get_widget("enforcingButton") 72 73 self.domains = get_all_entrypoint_domains() 74 self.load() 75 76 def get_modules(self): 77 modules = [] 78 fd = os.popen("semodule -l") 79 mods = fd.readlines() 80 fd.close() 81 for l in mods: 82 modules.append(l.split()[0]) 83 return modules 84 85 def load(self, filter=""): 86 self.filter = filter 87 self.store.clear() 88 try: 89 modules = self.get_modules() 90 for domain in self.domains: 91 if not self.match(domain, filter): 92 continue 93 iter = self.store.append() 94 self.store.set_value(iter, 0, domain) 95 t = "permissive_%s_t" % domain 96 if t in modules: 97 self.store.set_value(iter, 1, _("Permissive")) 98 else: 99 self.store.set_value(iter, 1, "") 100 except: 101 pass 102 self.view.get_selection().select_path((0,)) 103 104 def itemSelected(self, selection): 105 store, iter = selection.get_selected() 106 if iter == None: 107 return 108 p = store.get_value(iter, 1) == _("Permissive") 109 self.permissive_button.set_sensitive(not p) 110 self.enforcing_button.set_sensitive(p) 111 112 def deleteDialog(self): 113 # Do nothing 114 return self.delete() 115 116 def delete(self): 117 selection = self.view.get_selection() 118 store, iter = selection.get_selected() 119 domain = store.get_value(iter, 0) 120 try: 121 self.wait() 122 status, output = commands.getstatusoutput("semanage permissive -d %s_t" % domain) 123 self.ready() 124 if status != 0: 125 self.error(output) 126 else: 127 domain = store.set_value(iter, 1, "") 128 self.itemSelected(selection) 129 130 except ValueError, e: 131 self.error(e.args[0]) 132 133 def propertiesDialog(self): 134 # Do nothing 135 return 136 137 def addDialog(self): 138 # Do nothing 139 return self.add() 140 141 def add(self): 142 selection = self.view.get_selection() 143 store, iter = selection.get_selected() 144 domain = store.get_value(iter, 0) 145 try: 146 self.wait() 147 status, output = commands.getstatusoutput("semanage permissive -a %s_t" % domain) 148 self.ready() 149 if status != 0: 150 self.error(output) 151 else: 152 domain = store.set_value(iter, 1, _("Permissive")) 153 self.itemSelected(selection) 154 155 except ValueError, e: 156 self.error(e.args[0]) 157