2012-04-13 15:04:45 +00:00
|
|
|
## modulesPage.py - show selinux mappings
|
|
|
|
## Copyright (C) 2006-2009 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
|
|
|
|
## along with this program; if not, write to the Free Software
|
|
|
|
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
## Author: Dan Walsh
|
2017-09-20 06:56:54 +00:00
|
|
|
import sys
|
|
|
|
from subprocess import Popen, PIPE
|
2016-08-04 18:34:04 +00:00
|
|
|
try:
|
|
|
|
from subprocess import getstatusoutput
|
|
|
|
except ImportError:
|
|
|
|
from commands import getstatusoutput
|
|
|
|
|
2017-09-20 06:56:54 +00:00
|
|
|
from gi.repository import GObject, Gtk
|
2012-04-13 15:04:45 +00:00
|
|
|
import selinux
|
2015-07-24 08:07:13 +00:00
|
|
|
from semanagePage import *
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
## I18N
|
|
|
|
##
|
2015-07-24 08:07:13 +00:00
|
|
|
PROGNAME = "policycoreutils"
|
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
|
2012-04-13 15:04:45 +00:00
|
|
|
gettext.install(PROGNAME,
|
|
|
|
localedir="/usr/share/locale",
|
2016-08-04 18:34:02 +00:00
|
|
|
codeset='utf-8',
|
|
|
|
**kwargs)
|
|
|
|
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 modulesPage(semanagePage):
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2012-04-13 15:04:45 +00:00
|
|
|
def __init__(self, xml):
|
|
|
|
semanagePage.__init__(self, xml, "modules", _("Policy Module"))
|
2017-09-20 06:56:54 +00:00
|
|
|
self.module_filter = xml.get_object("modulesFilterEntry")
|
2012-04-13 15:04:45 +00:00
|
|
|
self.module_filter.connect("focus_out_event", self.filter_changed)
|
|
|
|
self.module_filter.connect("activate", self.filter_changed)
|
|
|
|
self.audit_enabled = False
|
|
|
|
|
2017-10-01 16:15:15 +00:00
|
|
|
self.store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING,
|
|
|
|
GObject.TYPE_STRING)
|
2012-04-13 15:04:45 +00:00
|
|
|
self.view.set_model(self.store)
|
2017-09-20 06:56:54 +00:00
|
|
|
self.store.set_sort_column_id(0, Gtk.SortType.ASCENDING)
|
|
|
|
col = Gtk.TreeViewColumn(_("Module Name"), Gtk.CellRendererText(), text=0)
|
2012-04-13 15:04:45 +00:00
|
|
|
col.set_sort_column_id(0)
|
|
|
|
col.set_resizable(True)
|
|
|
|
self.view.append_column(col)
|
2017-09-20 06:56:54 +00:00
|
|
|
self.store.set_sort_column_id(0, Gtk.SortType.ASCENDING)
|
2017-10-01 16:15:15 +00:00
|
|
|
col = Gtk.TreeViewColumn(_("Priority"), Gtk.CellRendererText(), text=1)
|
2017-09-20 06:56:54 +00:00
|
|
|
self.enable_audit_button = xml.get_object("enableAuditButton")
|
2012-04-13 15:04:45 +00:00
|
|
|
self.enable_audit_button.connect("clicked", self.enable_audit)
|
2017-09-20 06:56:54 +00:00
|
|
|
self.new_button = xml.get_object("newModuleButton")
|
2012-04-13 15:04:45 +00:00
|
|
|
self.new_button.connect("clicked", self.new_module)
|
|
|
|
col.set_sort_column_id(1)
|
|
|
|
col.set_resizable(True)
|
|
|
|
self.view.append_column(col)
|
2017-10-01 16:15:15 +00:00
|
|
|
self.store.set_sort_column_id(2, Gtk.SortType.ASCENDING)
|
|
|
|
col = Gtk.TreeViewColumn(_("Kind"), Gtk.CellRendererText(), text=2)
|
|
|
|
col.set_sort_column_id(2)
|
|
|
|
col.set_resizable(True)
|
|
|
|
self.view.append_column(col)
|
2015-07-24 08:07:13 +00:00
|
|
|
self.store.set_sort_func(1, self.sort_int, "")
|
2012-04-13 15:04:45 +00:00
|
|
|
status, self.policy_type = selinux.selinux_getpolicytype()
|
|
|
|
|
|
|
|
self.load()
|
|
|
|
|
|
|
|
def sort_int(self, treemodel, iter1, iter2, user_data):
|
|
|
|
try:
|
2015-07-24 08:07:13 +00:00
|
|
|
p1 = int(treemodel.get_value(iter1, 1))
|
|
|
|
p2 = int(treemodel.get_value(iter1, 1))
|
2012-04-13 15:04:45 +00:00
|
|
|
if p1 > p2:
|
|
|
|
return 1
|
|
|
|
if p1 == p2:
|
|
|
|
return 0
|
|
|
|
return -1
|
|
|
|
except:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def load(self, filter=""):
|
2015-07-24 08:07:13 +00:00
|
|
|
self.filter = filter
|
2012-04-13 15:04:45 +00:00
|
|
|
self.store.clear()
|
|
|
|
try:
|
2017-10-01 16:15:15 +00:00
|
|
|
fd = Popen("semodule -lfull", shell=True, stdout=PIPE).stdout
|
2012-04-13 15:04:45 +00:00
|
|
|
l = fd.readlines()
|
|
|
|
fd.close()
|
|
|
|
for i in l:
|
2017-10-01 16:15:15 +00:00
|
|
|
priority, module, kind = i.decode('utf-8').split()
|
|
|
|
if not (self.match(module, filter) or self.match(priority, filter)):
|
2012-04-13 15:04:45 +00:00
|
|
|
continue
|
|
|
|
iter = self.store.append()
|
|
|
|
self.store.set_value(iter, 0, module.strip())
|
2017-10-01 16:15:15 +00:00
|
|
|
self.store.set_value(iter, 1, priority.strip())
|
|
|
|
self.store.set_value(iter, 2, kind.strip())
|
2012-04-13 15:04:45 +00:00
|
|
|
except:
|
|
|
|
pass
|
2015-07-24 08:07:13 +00:00
|
|
|
self.view.get_selection().select_path((0,))
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
def new_module(self, args):
|
|
|
|
try:
|
2019-03-05 16:38:55 +00:00
|
|
|
Popen(["selinux-polgengui"])
|
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 delete(self):
|
|
|
|
store, iter = self.view.get_selection().get_selected()
|
|
|
|
module = store.get_value(iter, 0)
|
2019-09-24 19:12:21 +00:00
|
|
|
priority = store.get_value(iter, 1)
|
2012-04-13 15:04:45 +00:00
|
|
|
try:
|
|
|
|
self.wait()
|
2019-09-24 19:12:21 +00:00
|
|
|
status, output = getstatusoutput("semodule -X %s -r %s" % (priority, module))
|
2012-04-13 15:04:45 +00:00
|
|
|
self.ready()
|
|
|
|
if status != 0:
|
|
|
|
self.error(output)
|
|
|
|
else:
|
|
|
|
store.remove(iter)
|
2015-07-24 08:07:13 +00:00
|
|
|
self.view.get_selection().select_path((0,))
|
2012-04-13 15:04:45 +00:00
|
|
|
|
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 enable_audit(self, button):
|
|
|
|
self.audit_enabled = not self.audit_enabled
|
|
|
|
try:
|
|
|
|
self.wait()
|
|
|
|
if self.audit_enabled:
|
2016-08-04 18:34:04 +00:00
|
|
|
status, output = getstatusoutput("semodule -DB")
|
2012-04-13 15:04:45 +00:00
|
|
|
button.set_label(_("Disable Audit"))
|
|
|
|
else:
|
2016-08-04 18:34:04 +00:00
|
|
|
status, output = getstatusoutput("semodule -B")
|
2012-04-13 15:04:45 +00:00
|
|
|
button.set_label(_("Enable Audit"))
|
|
|
|
self.ready()
|
|
|
|
|
|
|
|
if status != 0:
|
|
|
|
self.error(output)
|
|
|
|
|
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 disable_audit(self, button):
|
|
|
|
try:
|
|
|
|
self.wait()
|
2016-08-04 18:34:04 +00:00
|
|
|
status, output = getstatusoutput("semodule -B")
|
2012-04-13 15:04:45 +00:00
|
|
|
self.ready()
|
|
|
|
if status != 0:
|
|
|
|
self.error(output)
|
|
|
|
|
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 propertiesDialog(self):
|
|
|
|
# Do nothing
|
|
|
|
return
|
|
|
|
|
|
|
|
def addDialog(self):
|
2017-09-20 06:56:54 +00:00
|
|
|
dialog = Gtk.FileChooserDialog(_("Load Policy Module"),
|
2012-04-13 15:04:45 +00:00
|
|
|
None,
|
2017-09-20 06:56:54 +00:00
|
|
|
Gtk.FileChooserAction.OPEN,
|
|
|
|
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
|
|
|
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
|
|
|
dialog.set_default_response(Gtk.ResponseType.OK)
|
2012-04-13 15:04:45 +00:00
|
|
|
|
2017-09-20 06:56:54 +00:00
|
|
|
filter = Gtk.FileFilter()
|
2012-04-13 15:04:45 +00:00
|
|
|
filter.set_name("Policy Files")
|
|
|
|
filter.add_pattern("*.pp")
|
|
|
|
dialog.add_filter(filter)
|
|
|
|
|
|
|
|
response = dialog.run()
|
2017-09-20 06:56:54 +00:00
|
|
|
if response == Gtk.ResponseType.OK:
|
2012-04-13 15:04:45 +00:00
|
|
|
self.add(dialog.get_filename())
|
|
|
|
dialog.destroy()
|
|
|
|
|
|
|
|
def add(self, file):
|
|
|
|
try:
|
|
|
|
self.wait()
|
2016-08-04 18:34:04 +00:00
|
|
|
status, output = getstatusoutput("semodule -i %s" % file)
|
2012-04-13 15:04:45 +00:00
|
|
|
self.ready()
|
|
|
|
if status != 0:
|
|
|
|
self.error(output)
|
|
|
|
else:
|
|
|
|
self.load()
|
|
|
|
|
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])
|