2012-04-13 15:04:45 +00:00
|
|
|
#
|
|
|
|
# booleansPage.py - GUI for Booleans page in system-config-securitylevel
|
|
|
|
#
|
|
|
|
# Dan Walsh <dwalsh@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright 2006, 2007 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
#
|
|
|
|
import sys
|
2017-09-20 06:56:54 +00:00
|
|
|
from gi.repository import Gdk, GObject, Gtk
|
2012-04-13 15:04:45 +00:00
|
|
|
import seobject
|
|
|
|
import semanagePage
|
|
|
|
|
2015-07-24 08:07:13 +00:00
|
|
|
INSTALLPATH = '/usr/share/system-config-selinux'
|
2012-04-13 15:04:45 +00:00
|
|
|
sys.path.append(INSTALLPATH)
|
|
|
|
|
2016-08-04 18:34:04 +00:00
|
|
|
try:
|
|
|
|
from subprocess import getstatusoutput
|
|
|
|
except ImportError:
|
|
|
|
from commands import getstatusoutput
|
|
|
|
|
2015-07-24 08:07:13 +00:00
|
|
|
ENFORCING = 0
|
|
|
|
PERMISSIVE = 1
|
|
|
|
DISABLED = 2
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
## I18N
|
|
|
|
##
|
2022-04-01 09:57:24 +00:00
|
|
|
PROGNAME = "selinux-gui"
|
2012-04-13 15:04:45 +00:00
|
|
|
try:
|
2016-08-04 18:34:02 +00:00
|
|
|
import gettext
|
|
|
|
kwargs = {}
|
|
|
|
if sys.version_info < (3,):
|
|
|
|
kwargs['unicode'] = True
|
2022-05-06 14:06:23 +00:00
|
|
|
t = gettext.translation(PROGNAME,
|
2012-04-13 15:04:45 +00:00
|
|
|
localedir="/usr/share/locale",
|
2022-06-24 14:24:25 +00:00
|
|
|
**kwargs,
|
|
|
|
fallback=True)
|
2022-05-06 14:06:23 +00:00
|
|
|
_ = t.gettext
|
2016-08-04 18:34:02 +00:00
|
|
|
except:
|
|
|
|
try:
|
|
|
|
import builtins
|
|
|
|
builtins.__dict__['_'] = str
|
|
|
|
except ImportError:
|
|
|
|
import __builtin__
|
|
|
|
__builtin__.__dict__['_'] = unicode
|
2012-04-13 15:04:45 +00:00
|
|
|
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2012-04-13 15:04:45 +00:00
|
|
|
class Modifier:
|
|
|
|
|
2015-07-24 08:07:13 +00:00
|
|
|
def __init__(self, name, on, save):
|
|
|
|
self.on = on
|
|
|
|
self.name = name
|
|
|
|
self.save = save
|
|
|
|
|
|
|
|
def set(self, value):
|
|
|
|
self.on = value
|
|
|
|
self.save = True
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
def isOn(self):
|
|
|
|
return self.on
|
|
|
|
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2012-04-13 15:04:45 +00:00
|
|
|
class Boolean(Modifier):
|
2015-07-24 08:07:13 +00:00
|
|
|
|
|
|
|
def __init__(self, name, val, save=False):
|
|
|
|
Modifier.__init__(self, name, val, save)
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
ACTIVE = 0
|
|
|
|
MODULE = 1
|
|
|
|
DESC = 2
|
|
|
|
BOOLEAN = 3
|
|
|
|
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2012-04-13 15:04:45 +00:00
|
|
|
class booleansPage:
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2012-04-13 15:04:45 +00:00
|
|
|
def __init__(self, xml, doDebug=None):
|
|
|
|
self.xml = xml
|
2017-09-20 06:56:54 +00:00
|
|
|
self.window = self.xml.get_object("mainWindow").get_root_window()
|
2012-04-13 15:04:45 +00:00
|
|
|
self.local = False
|
2015-07-24 08:07:13 +00:00
|
|
|
self.types = []
|
2012-04-13 15:04:45 +00:00
|
|
|
self.selinuxsupport = True
|
|
|
|
self.typechanged = False
|
|
|
|
self.doDebug = doDebug
|
2017-09-20 06:56:54 +00:00
|
|
|
self.busy_cursor = Gdk.Cursor.new(Gdk.CursorType.WATCH)
|
|
|
|
self.ready_cursor = Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR)
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
# Bring in widgets from glade file.
|
2017-09-20 06:56:54 +00:00
|
|
|
self.booleansFilter = xml.get_object("booleansFilter")
|
2012-04-13 15:04:45 +00:00
|
|
|
self.booleansFilter.connect("focus_out_event", self.filter_changed)
|
|
|
|
self.booleansFilter.connect("activate", self.filter_changed)
|
2017-09-20 06:56:54 +00:00
|
|
|
self.booleansFilter.connect("changed", self.filter_changed)
|
2012-04-13 15:04:45 +00:00
|
|
|
|
2017-09-20 06:56:54 +00:00
|
|
|
self.booleansView = xml.get_object("booleansView")
|
2012-04-13 15:04:45 +00:00
|
|
|
|
2017-09-20 06:56:54 +00:00
|
|
|
self.revertButton = xml.get_object("booleanRevertButton")
|
2012-04-13 15:04:45 +00:00
|
|
|
self.revertButton.set_sensitive(self.local)
|
|
|
|
self.revertButton.connect("clicked", self.on_revert_clicked)
|
2017-09-20 06:56:54 +00:00
|
|
|
listStore = Gtk.ListStore(GObject.TYPE_STRING)
|
|
|
|
cell = Gtk.CellRendererText()
|
2012-04-13 15:04:45 +00:00
|
|
|
|
2017-09-20 06:56:54 +00:00
|
|
|
self.store = Gtk.ListStore(GObject.TYPE_BOOLEAN, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING)
|
|
|
|
self.store.set_sort_column_id(1, Gtk.SortType.ASCENDING)
|
2012-04-13 15:04:45 +00:00
|
|
|
self.booleansView.set_model(self.store)
|
|
|
|
|
2017-09-20 06:56:54 +00:00
|
|
|
checkbox = Gtk.CellRendererToggle()
|
2012-04-13 15:04:45 +00:00
|
|
|
checkbox.connect("toggled", self.boolean_toggled)
|
2017-09-20 06:56:54 +00:00
|
|
|
col = Gtk.TreeViewColumn('Active', checkbox, active=ACTIVE)
|
2012-04-13 15:04:45 +00:00
|
|
|
col.set_clickable(True)
|
|
|
|
col.set_sort_column_id(ACTIVE)
|
|
|
|
self.booleansView.append_column(col)
|
|
|
|
|
2017-09-20 06:56:54 +00:00
|
|
|
col = Gtk.TreeViewColumn("Module", Gtk.CellRendererText(), text=MODULE)
|
2012-04-13 15:04:45 +00:00
|
|
|
col.set_sort_column_id(MODULE)
|
|
|
|
col.set_resizable(True)
|
|
|
|
self.booleansView.append_column(col)
|
|
|
|
|
2017-09-20 06:56:54 +00:00
|
|
|
col = Gtk.TreeViewColumn("Description", Gtk.CellRendererText(), text=DESC)
|
|
|
|
col.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
|
2012-04-13 15:04:45 +00:00
|
|
|
col.set_fixed_width(400)
|
|
|
|
col.set_sort_column_id(DESC)
|
|
|
|
col.set_resizable(True)
|
|
|
|
self.booleansView.append_column(col)
|
|
|
|
|
2017-09-20 06:56:54 +00:00
|
|
|
col = Gtk.TreeViewColumn("Name", Gtk.CellRendererText(), text=BOOLEAN)
|
2012-04-13 15:04:45 +00:00
|
|
|
col.set_sort_column_id(BOOLEAN)
|
|
|
|
col.set_resizable(True)
|
|
|
|
self.booleansView.set_search_equal_func(self.__search)
|
|
|
|
self.booleansView.append_column(col)
|
2015-07-24 08:07:13 +00:00
|
|
|
self.filter = ""
|
2012-04-13 15:04:45 +00:00
|
|
|
self.load(self.filter)
|
|
|
|
|
2012-05-24 09:51:41 +00:00
|
|
|
def error(self, message):
|
2017-09-20 06:56:54 +00:00
|
|
|
dlg = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR,
|
|
|
|
Gtk.ButtonsType.CLOSE,
|
2012-05-24 09:51:41 +00:00
|
|
|
message)
|
2017-09-20 06:56:54 +00:00
|
|
|
dlg.set_position(Gtk.WindowPosition.MOUSE)
|
2012-05-24 09:51:41 +00:00
|
|
|
dlg.show_all()
|
|
|
|
dlg.run()
|
|
|
|
dlg.destroy()
|
|
|
|
|
2012-04-13 15:04:45 +00:00
|
|
|
def __search(self, model, col, key, i):
|
|
|
|
sort_col = self.store.get_sort_column_id()[0]
|
|
|
|
if sort_col > 0:
|
|
|
|
val = model.get_value(i, sort_col)
|
|
|
|
if val.lower().startswith(key.lower()):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def wait(self):
|
|
|
|
self.window.set_cursor(self.busy_cursor)
|
|
|
|
semanagePage.idle_func()
|
|
|
|
|
|
|
|
def ready(self):
|
|
|
|
self.window.set_cursor(self.ready_cursor)
|
|
|
|
semanagePage.idle_func()
|
|
|
|
|
|
|
|
def deleteDialog(self):
|
|
|
|
store, iter = self.booleansView.get_selection().get_selected()
|
2017-09-20 06:56:54 +00:00
|
|
|
if iter is None:
|
2012-04-13 15:04:45 +00:00
|
|
|
return
|
|
|
|
boolean = store.get_value(iter, BOOLEAN)
|
|
|
|
# change cursor
|
2017-09-20 06:56:54 +00:00
|
|
|
if boolean is None:
|
2012-04-13 15:04:45 +00:00
|
|
|
return
|
|
|
|
try:
|
|
|
|
self.wait()
|
2016-08-04 18:34:04 +00:00
|
|
|
(rc, out) = getstatusoutput("semanage boolean -d %s" % boolean)
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
self.ready()
|
|
|
|
if rc != 0:
|
|
|
|
return self.error(out)
|
|
|
|
self.load(self.filter)
|
2016-08-04 18:34:03 +00:00
|
|
|
except ValueError as e:
|
2012-04-13 15:04:45 +00:00
|
|
|
self.error(e.args[0])
|
|
|
|
|
|
|
|
def filter_changed(self, *arg):
|
2015-07-24 08:07:13 +00:00
|
|
|
filter = arg[0].get_text()
|
2012-04-13 15:04:45 +00:00
|
|
|
if filter != self.filter:
|
|
|
|
self.load(filter)
|
2015-07-24 08:07:13 +00:00
|
|
|
self.filter = filter
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
def use_menus(self):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_description(self):
|
|
|
|
return _("Boolean")
|
|
|
|
|
2015-07-24 08:07:13 +00:00
|
|
|
def match(self, key, filter=""):
|
2012-04-13 15:04:45 +00:00
|
|
|
try:
|
2015-07-24 08:07:13 +00:00
|
|
|
f = filter.lower()
|
|
|
|
cat = self.booleans.get_category(key).lower()
|
|
|
|
val = self.booleans.get_desc(key).lower()
|
|
|
|
k = key.lower()
|
2012-04-13 15:04:45 +00:00
|
|
|
return val.find(f) >= 0 or k.find(f) >= 0 or cat.find(f) >= 0
|
|
|
|
except:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def load(self, filter=None):
|
|
|
|
self.store.clear()
|
|
|
|
self.booleans = seobject.booleanRecords()
|
|
|
|
booleansList = self.booleans.get_all(self.local)
|
|
|
|
for name in booleansList:
|
|
|
|
rec = booleansList[name]
|
|
|
|
if self.match(name, filter):
|
2015-07-24 08:07:13 +00:00
|
|
|
iter = self.store.append()
|
2012-04-13 15:04:45 +00:00
|
|
|
self.store.set_value(iter, ACTIVE, rec[2] == 1)
|
|
|
|
self.store.set_value(iter, MODULE, self.booleans.get_category(name))
|
|
|
|
self.store.set_value(iter, DESC, self.booleans.get_desc(name))
|
|
|
|
self.store.set_value(iter, BOOLEAN, name)
|
|
|
|
|
|
|
|
def boolean_toggled(self, widget, row):
|
|
|
|
iter = self.store.get_iter(row)
|
|
|
|
val = self.store.get_value(iter, ACTIVE)
|
|
|
|
key = self.store.get_value(iter, BOOLEAN)
|
2015-07-24 08:07:13 +00:00
|
|
|
self.store.set_value(iter, ACTIVE, not val)
|
2012-04-13 15:04:45 +00:00
|
|
|
self.wait()
|
2015-07-24 08:07:13 +00:00
|
|
|
setsebool = "/usr/sbin/setsebool -P %s %d" % (key, not val)
|
2016-08-04 18:34:04 +00:00
|
|
|
rc, out = getstatusoutput(setsebool)
|
2012-05-24 09:51:41 +00:00
|
|
|
if rc != 0:
|
|
|
|
self.error(out)
|
2012-04-13 15:04:45 +00:00
|
|
|
self.load(self.filter)
|
|
|
|
self.ready()
|
|
|
|
|
|
|
|
def on_revert_clicked(self, button):
|
|
|
|
self.wait()
|
2015-07-24 08:07:13 +00:00
|
|
|
setsebool = "semanage boolean --deleteall"
|
2016-08-04 18:34:04 +00:00
|
|
|
getstatusoutput(setsebool)
|
2012-04-13 15:04:45 +00:00
|
|
|
self.load(self.filter)
|
|
|
|
self.ready()
|
|
|
|
|
|
|
|
def on_local_clicked(self, button):
|
|
|
|
self.local = not self.local
|
|
|
|
self.revertButton.set_sensitive(self.local)
|
|
|
|
|
|
|
|
if self.local:
|
|
|
|
button.set_label(_("all"))
|
|
|
|
else:
|
|
|
|
button.set_label(_("Customized"))
|
|
|
|
|
|
|
|
self.load(self.filter)
|
|
|
|
return True
|