Home | History | Annotate | Download | only in gui
      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
     19 import string
     20 import gtk
     21 import gtk.glade
     22 import os
     23 import commands
     24 import gobject
     25 import sys
     26 import seobject
     27 import selinux
     28 from semanagePage import *;
     29 from sepolicy import get_all_entrypoint_domains
     30 
     31 ##
     32 ## I18N
     33 ##
     34 PROGNAME="policycoreutils"
     35 import gettext
     36 gettext.bindtextdomain(PROGNAME, "/usr/share/locale")
     37 gettext.textdomain(PROGNAME)
     38 try:
     39     gettext.install(PROGNAME,
     40                     localedir="/usr/share/locale",
     41                     unicode=False,
     42                     codeset = 'utf-8')
     43 except IOError:
     44     import __builtin__
     45     __builtin__.__dict__['_'] = unicode
     46 
     47 class domainsPage(semanagePage):
     48     def __init__(self, xml):
     49         semanagePage.__init__(self, xml, "domains", _("Process Domain"))
     50         self.domain_filter = xml.get_widget("domainsFilterEntry")
     51         self.domain_filter.connect("focus_out_event", self.filter_changed)
     52         self.domain_filter.connect("activate", self.filter_changed)
     53 
     54         self.store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
     55         self.view.set_model(self.store)
     56         self.store.set_sort_column_id(0, gtk.SORT_ASCENDING)
     57         col = gtk.TreeViewColumn(_("Domain Name"), gtk.CellRendererText(), text = 0)
     58         col.set_sort_column_id(0)
     59         col.set_resizable(True)
     60         self.view.append_column(col)
     61         self.store.set_sort_column_id(0, gtk.SORT_ASCENDING)
     62         col = gtk.TreeViewColumn(_("Mode"), gtk.CellRendererText(), text = 1)
     63         col.set_sort_column_id(1)
     64         col.set_resizable(True)
     65         self.view.append_column(col)
     66         self.view.get_selection().connect("changed", self.itemSelected)
     67 
     68         self.permissive_button = xml.get_widget("permissiveButton")
     69         self.enforcing_button = xml.get_widget("enforcingButton")
     70 
     71         self.domains=get_all_entrypoint_domains()
     72         self.load()
     73 
     74     def get_modules(self):
     75         modules=[]
     76         fd=os.popen("semodule -l")
     77         mods = fd.readlines()
     78         fd.close()
     79         for l in mods:
     80             modules.append(l.split()[0])
     81         return modules
     82 
     83     def load(self, filter=""):
     84         self.filter=filter
     85         self.store.clear()
     86         try:
     87             modules=self.get_modules()
     88             for domain in self.domains:
     89                 if not self.match(domain, filter):
     90                     continue
     91                 iter = self.store.append()
     92                 self.store.set_value(iter, 0, domain)
     93                 t = "permissive_%s_t" % domain
     94                 if t in modules:
     95                     self.store.set_value(iter, 1, _("Permissive"))
     96                 else:
     97                     self.store.set_value(iter, 1, "")
     98         except:
     99             pass
    100         self.view.get_selection().select_path ((0,))
    101 
    102     def itemSelected(self, selection):
    103         store, iter = selection.get_selected()
    104         if iter == None:
    105             return
    106         p = store.get_value(iter, 1) == _("Permissive")
    107         self.permissive_button.set_sensitive(not p)
    108         self.enforcing_button.set_sensitive(p)
    109 
    110     def deleteDialog(self):
    111         # Do nothing
    112         return self.delete()
    113 
    114     def delete(self):
    115         selection = self.view.get_selection()
    116         store, iter = selection.get_selected()
    117         domain = store.get_value(iter, 0)
    118         try:
    119             self.wait()
    120             status, output = commands.getstatusoutput("semanage permissive -d %s_t" % domain)
    121             self.ready()
    122             if status != 0:
    123                 self.error(output)
    124             else:
    125                 domain = store.set_value(iter, 1, "")
    126                 self.itemSelected(selection)
    127 
    128         except ValueError, e:
    129             self.error(e.args[0])
    130 
    131     def propertiesDialog(self):
    132         # Do nothing
    133         return
    134 
    135     def addDialog(self):
    136         # Do nothing
    137         return self.add()
    138 
    139     def add(self):
    140         selection = self.view.get_selection()
    141         store, iter = selection.get_selected()
    142         domain = store.get_value(iter, 0)
    143         try:
    144             self.wait()
    145             status, output = commands.getstatusoutput("semanage permissive -a %s_t" % domain)
    146             self.ready()
    147             if status != 0:
    148                 self.error(output)
    149             else:
    150                 domain = store.set_value(iter, 1, _("Permissive"))
    151                 self.itemSelected(selection)
    152 
    153         except ValueError, e:
    154             self.error(e.args[0])
    155