1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
## fcontextPage.py - show selinux mappings
## Copyright (C) 2006 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
from gi.repository import GObject, Gtk
import seobject
try:
from subprocess import getstatusoutput
except ImportError:
from commands import getstatusoutput
from semanagePage import *
SPEC_COL = 0
TYPE_COL = 1
FTYPE_COL = 2
class context:
def __init__(self, scontext):
self.scontext = scontext
con = scontext.split(":")
self.type = con[0]
if len(con) > 1:
self.mls = con[1]
else:
self.mls = "s0"
def __str__(self):
return self.scontext
##
## I18N
##
PROGNAME = "policycoreutils"
try:
import gettext
kwargs = {}
if sys.version_info < (3,):
kwargs['unicode'] = True
gettext.install(PROGNAME,
localedir="/usr/share/locale",
codeset='utf-8',
**kwargs)
except:
try:
import builtins
builtins.__dict__['_'] = str
except ImportError:
import __builtin__
__builtin__.__dict__['_'] = unicode
class fcontextPage(semanagePage):
def __init__(self, xml):
semanagePage.__init__(self, xml, "fcontext", _("File Labeling"))
self.fcontextFilter = xml.get_object("fcontextFilterEntry")
self.fcontextFilter.connect("focus_out_event", self.filter_changed)
self.fcontextFilter.connect("activate", self.filter_changed)
self.store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING)
self.view = xml.get_object("fcontextView")
self.view.set_model(self.store)
self.view.set_search_equal_func(self.search)
col = Gtk.TreeViewColumn(_("File\nSpecification"), Gtk.CellRendererText(), text=SPEC_COL)
col.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
col.set_fixed_width(250)
col.set_sort_column_id(SPEC_COL)
col.set_resizable(True)
self.view.append_column(col)
col = Gtk.TreeViewColumn(_("Selinux\nFile Type"), Gtk.CellRendererText(), text=TYPE_COL)
col.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
col.set_fixed_width(250)
col.set_sort_column_id(TYPE_COL)
col.set_resizable(True)
self.view.append_column(col)
col = Gtk.TreeViewColumn(_("File\nType"), Gtk.CellRendererText(), text=2)
col.set_sort_column_id(FTYPE_COL)
col.set_resizable(True)
self.view.append_column(col)
self.store.set_sort_column_id(SPEC_COL, Gtk.SortType.ASCENDING)
self.load()
self.fcontextEntry = xml.get_object("fcontextEntry")
self.fcontextFileTypeCombo = xml.get_object("fcontextFileTypeCombo")
self.fcontextTypeEntry = xml.get_object("fcontextTypeEntry")
self.fcontextMLSEntry = xml.get_object("fcontextMLSEntry")
def match(self, fcon_dict, k, filter):
try:
f = filter.lower()
for con in k:
k = con.lower()
if k.find(f) >= 0:
return True
for con in fcon_dict[k]:
k = con.lower()
if k.find(f) >= 0:
return True
except:
pass
return False
def load(self, filter=""):
self.filter = filter
self.fcontext = seobject.fcontextRecords()
self.store.clear()
fcon_dict = self.fcontext.get_all(self.local)
for k in sorted(fcon_dict.keys()):
if not self.match(fcon_dict, k, filter):
continue
iter = self.store.append()
self.store.set_value(iter, SPEC_COL, k[0])
self.store.set_value(iter, FTYPE_COL, k[1])
if fcon_dict[k]:
rec = "%s:%s" % (fcon_dict[k][2], seobject.translate(fcon_dict[k][3], False))
else:
rec = "<<None>>"
self.store.set_value(iter, TYPE_COL, rec)
self.view.get_selection().select_path((0,))
def filter_changed(self, *arg):
filter = arg[0].get_text()
if filter != self.filter:
self.load(filter)
def dialogInit(self):
store, iter = self.view.get_selection().get_selected()
self.fcontextEntry.set_text(store.get_value(iter, SPEC_COL))
self.fcontextEntry.set_sensitive(False)
scontext = store.get_value(iter, TYPE_COL)
scon = context(scontext)
self.fcontextTypeEntry.set_text(scon.type)
self.fcontextMLSEntry.set_text(scon.mls)
type = store.get_value(iter, FTYPE_COL)
liststore = self.fcontextFileTypeCombo.get_model()
iter = liststore.get_iter_first()
while iter != None and liststore.get_value(iter, 0) != type:
iter = liststore.iter_next(iter)
if iter != None:
self.fcontextFileTypeCombo.set_active_iter(iter)
self.fcontextFileTypeCombo.set_sensitive(False)
def dialogClear(self):
self.fcontextEntry.set_text("")
self.fcontextEntry.set_sensitive(True)
self.fcontextFileTypeCombo.set_sensitive(True)
self.fcontextFileTypeCombo.set_active(0)
self.fcontextTypeEntry.set_text("")
self.fcontextMLSEntry.set_text("s0")
def delete(self):
store, iter = self.view.get_selection().get_selected()
try:
fspec = store.get_value(iter, SPEC_COL)
ftype = store.get_value(iter, FTYPE_COL)
self.wait()
(rc, out) = getstatusoutput("semanage fcontext -d -f '%s' '%s'" % (seobject.file_type_str_to_option[ftype], fspec))
self.ready()
if rc != 0:
return self.error(out)
store.remove(iter)
self.view.get_selection().select_path((0,))
except ValueError as e:
self.error(e.args[0])
def add(self):
fspec = self.fcontextEntry.get_text().strip()
type = self.fcontextTypeEntry.get_text().strip()
mls = self.fcontextMLSEntry.get_text().strip()
list_model = self.fcontextFileTypeCombo.get_model()
it = self.fcontextFileTypeCombo.get_active_iter()
ftype = list_model.get_value(it, 0)
self.wait()
(rc, out) = getstatusoutput("semanage fcontext -a -t %s -r %s -f '%s' '%s'" % (type, mls, seobject.file_type_str_to_option[ftype], fspec))
self.ready()
if rc != 0:
self.error(out)
return False
iter = self.store.append()
self.store.set_value(iter, SPEC_COL, fspec)
self.store.set_value(iter, FTYPE_COL, ftype)
self.store.set_value(iter, TYPE_COL, "%s:%s" % (type, mls))
def modify(self):
fspec = self.fcontextEntry.get_text().strip()
type = self.fcontextTypeEntry.get_text().strip()
mls = self.fcontextMLSEntry.get_text().strip()
list_model = self.fcontextFileTypeCombo.get_model()
iter = self.fcontextFileTypeCombo.get_active_iter()
ftype = list_model.get_value(iter, 0)
self.wait()
(rc, out) = getstatusoutput("semanage fcontext -m -t %s -r %s -f '%s' '%s'" % (type, mls, seobject.file_type_str_to_option[ftype], fspec))
self.ready()
if rc != 0:
self.error(out)
return False
store, iter = self.view.get_selection().get_selected()
self.store.set_value(iter, SPEC_COL, fspec)
self.store.set_value(iter, FTYPE_COL, ftype)
self.store.set_value(iter, TYPE_COL, "%s:%s" % (type, mls))
|