blob: d284ded652792d19d7ac0de6ae648475c8ee89e1 [file] [log] [blame]
Nicolas Iooss72dc5c62019-02-17 21:57:41 +01001#!/usr/bin/python3 -Es
Dan Walshe4bbd7c2012-04-13 11:01:32 -04002#
3# polgengui.py - GUI for SELinux Config tool in system-config-selinux
4#
5# Dan Walsh <dwalsh@redhat.com>
6#
Dan Walsh678de8f2013-10-11 09:21:48 -04007# Copyright (C) 2007-2013 Red Hat
Dan Walshe4bbd7c2012-04-13 11:01:32 -04008#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22#
23import signal
24import string
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +020025import gi
26gi.require_version('Gtk', '3.0')
27from gi.repository import Gtk
Dan Walshe4bbd7c2012-04-13 11:01:32 -040028import os
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +020029from gi.repository import GObject
Dan Walshe4bbd7c2012-04-13 11:01:32 -040030import sys
Dan Walsh678de8f2013-10-11 09:21:48 -040031try:
Jason Zamanb43991f2016-08-05 02:34:01 +080032 import sepolicy
Jason Zaman4d340e42016-08-05 02:34:03 +080033except ValueError as e:
Dan Walsh678de8f2013-10-11 09:21:48 -040034 sys.stderr.write("%s: %s\n" % (e.__class__.__name__, str(e)))
35 sys.exit(1)
36
Petr Lautrbach53331522017-03-17 15:09:08 +010037import sepolicy.generate
Dan Walshe2de21c2012-05-18 11:40:11 -040038import sepolicy.interface
Petr Lautrbach53331522017-03-17 15:09:08 +010039
Jason Zaman05d1cea2016-08-05 02:34:04 +080040try:
41 from subprocess import getstatusoutput
42except ImportError:
43 from commands import getstatusoutput
44
Dan Walshe2de21c2012-05-18 11:40:11 -040045
Dan Walshe4bbd7c2012-04-13 11:01:32 -040046import re
47
Jason Zaman789d0eb2015-07-24 16:07:13 +080048
Dan Walshe2de21c2012-05-18 11:40:11 -040049def get_all_modules():
50 try:
51 all_modules = []
Jason Zaman05d1cea2016-08-05 02:34:04 +080052 rc, output = getstatusoutput("semodule -l 2>/dev/null")
Dan Walshe2de21c2012-05-18 11:40:11 -040053 if rc == 0:
54 l = output.split("\n")
55 for i in l:
56 all_modules.append(i.split()[0])
57 except:
58 pass
59
60 return all_modules
61
Dan Walshe4bbd7c2012-04-13 11:01:32 -040062
63##
64## I18N
65##
Jason Zaman789d0eb2015-07-24 16:07:13 +080066PROGNAME = "policycoreutils"
Dan Walshe4bbd7c2012-04-13 11:01:32 -040067try:
Jason Zamanaf595442016-08-05 02:34:02 +080068 import gettext
69 kwargs = {}
70 if sys.version_info < (3,):
71 kwargs['unicode'] = True
Dan Walshe4bbd7c2012-04-13 11:01:32 -040072 gettext.install(PROGNAME,
73 localedir="/usr/share/locale",
Jason Zamanaf595442016-08-05 02:34:02 +080074 codeset='utf-8',
75 **kwargs)
76except:
77 try:
78 import builtins
79 builtins.__dict__['_'] = str
80 except ImportError:
81 import __builtin__
82 __builtin__.__dict__['_'] = unicode
Dan Walshe4bbd7c2012-04-13 11:01:32 -040083
Dan Walshe4bbd7c2012-04-13 11:01:32 -040084version = "1.0"
85
86sys.path.append('/usr/share/system-config-selinux')
87sys.path.append('.')
88
89# From John Hunter http://www.daa.com.au/pipermail/pygtk/2003-February/004454.html
Jason Zaman789d0eb2015-07-24 16:07:13 +080090
91
Dan Walshe4bbd7c2012-04-13 11:01:32 -040092def foreach(model, path, iter, selected):
93 selected.append(model.get_value(iter, 0))
94
95##
96## Pull in the Glade file
97##
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +020098xml = Gtk.Builder()
99xml.set_translation_domain(PROGNAME)
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100100if os.access("polgen.ui", os.F_OK):
101 xml.add_from_file("polgen.ui")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400102else:
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100103 xml.add_from_file("/usr/share/system-config-selinux/polgen.ui")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400104
105FILE = 1
106DIR = 2
107
Jason Zaman789d0eb2015-07-24 16:07:13 +0800108
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400109class childWindow:
110 START_PAGE = 0
111 SELECT_TYPE_PAGE = 0
112 APP_PAGE = 1
113 EXISTING_USER_PAGE = 2
114 TRANSITION_PAGE = 3
115 USER_TRANSITION_PAGE = 4
116 ADMIN_PAGE = 5
117 ROLE_PAGE = 6
118 IN_NET_PAGE = 7
119 OUT_NET_PAGE = 8
120 COMMON_APPS_PAGE = 9
121 FILES_PAGE = 10
122 BOOLEAN_PAGE = 11
123 SELECT_DIR_PAGE = 12
124 FINISH_PAGE = 12
125
126 def __init__(self):
127 self.xml = xml
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100128 self.notebook = xml.get_object("notebook")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400129 self.label_dict = {}
130 self.tooltip_dict = {}
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100131 label = xml.get_object("select_label")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400132 self.label_dict[label] = label.get_text()
133
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100134 label = xml.get_object("select_user_roles_label")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400135 self.label_dict[label] = label.get_text()
136
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100137 label = xml.get_object("select_dir_label")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400138 self.label_dict[label] = label.get_text()
139
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100140 label = xml.get_object("select_domain_admin_label")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400141 self.label_dict[label] = label.get_text()
142
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100143 label = xml.get_object("select_in_label")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400144 self.label_dict[label] = label.get_text()
145
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100146 label = xml.get_object("select_out_label")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400147 self.label_dict[label] = label.get_text()
148
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100149 label = xml.get_object("select_common_label")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400150 self.label_dict[label] = label.get_text()
151
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100152 label = xml.get_object("select_manages_label")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400153 self.label_dict[label] = label.get_text()
154
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100155 label = xml.get_object("select_booleans_label")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400156 self.label_dict[label] = label.get_text()
157
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100158 label = xml.get_object("existing_user_treeview")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400159 self.tooltip_dict[label] = label.get_tooltip_text()
160
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100161 label = xml.get_object("transition_treeview")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400162 self.tooltip_dict[label] = label.get_tooltip_text()
163
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100164 label = xml.get_object("in_tcp_all_checkbutton")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400165 self.tooltip_dict[label] = label.get_tooltip_text()
166
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100167 label = xml.get_object("in_tcp_reserved_checkbutton")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400168 self.tooltip_dict[label] = label.get_tooltip_text()
169
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100170 label = xml.get_object("in_tcp_unreserved_checkbutton")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400171 self.tooltip_dict[label] = label.get_tooltip_text()
172
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100173 label = xml.get_object("in_tcp_entry")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400174 self.tooltip_dict[label] = label.get_tooltip_text()
175
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100176 label = xml.get_object("in_udp_all_checkbutton")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400177 self.tooltip_dict[label] = label.get_tooltip_text()
178
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100179 label = xml.get_object("in_udp_reserved_checkbutton")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400180 self.tooltip_dict[label] = label.get_tooltip_text()
181
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100182 label = xml.get_object("in_udp_unreserved_checkbutton")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400183 self.tooltip_dict[label] = label.get_tooltip_text()
184
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100185 label = xml.get_object("in_udp_entry")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400186 self.tooltip_dict[label] = label.get_tooltip_text()
187
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100188 label = xml.get_object("out_tcp_entry")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400189 self.tooltip_dict[label] = label.get_tooltip_text()
190
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100191 label = xml.get_object("out_udp_entry")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400192 self.tooltip_dict[label] = label.get_tooltip_text()
193
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100194 label = xml.get_object("out_tcp_all_checkbutton")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400195 self.tooltip_dict[label] = label.get_tooltip_text()
196
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100197 label = xml.get_object("out_udp_all_checkbutton")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400198 self.tooltip_dict[label] = label.get_tooltip_text()
199
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100200 label = xml.get_object("boolean_treeview")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400201 self.tooltip_dict[label] = label.get_tooltip_text()
202
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100203 label = xml.get_object("write_treeview")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400204 self.tooltip_dict[label] = label.get_tooltip_text()
205
206 try:
Jason Zamanb43991f2016-08-05 02:34:01 +0800207 self.all_types = sepolicy.generate.get_all_types()
Dan Walshe2de21c2012-05-18 11:40:11 -0400208 self.all_modules = get_all_modules()
Jason Zamanb43991f2016-08-05 02:34:01 +0800209 self.all_roles = sepolicy.generate.get_all_roles()
210 self.all_users = sepolicy.generate.get_all_users()
Jason Zaman4d340e42016-08-05 02:34:03 +0800211 except RuntimeError as e:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400212 self.all_types = []
213 self.all_modules = []
214 self.all_roles = []
215 self.all_users = []
216 self.error(str(e))
217
Jason Zaman789d0eb2015-07-24 16:07:13 +0800218 self.name = ""
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100219 handlers = {
220 "on_delete_clicked": self.delete,
221 "on_delete_boolean_clicked": self.delete_boolean,
222 "on_exec_select_clicked": self.exec_select,
223 "on_init_script_select_clicked": self.init_script_select,
224 "on_add_clicked": self.add,
225 "on_add_boolean_clicked": self.add_boolean,
226 "on_add_dir_clicked": self.add_dir,
227 "on_about_clicked": self.on_about_clicked
228 }
229 xml.connect_signals(handlers)
230 xml.get_object("cancel_button").connect("clicked", self.quit)
231 self.forward_button = xml.get_object("forward_button")
Jason Zaman789d0eb2015-07-24 16:07:13 +0800232 self.forward_button.connect("clicked", self.forward)
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100233 self.back_button = xml.get_object("back_button")
Jason Zaman789d0eb2015-07-24 16:07:13 +0800234 self.back_button.connect("clicked", self.back)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400235
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100236 self.boolean_dialog = xml.get_object("boolean_dialog")
237 self.boolean_name_entry = xml.get_object("boolean_name_entry")
238 self.boolean_description_entry = xml.get_object("boolean_description_entry")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400239
Jason Zaman789d0eb2015-07-24 16:07:13 +0800240 self.pages = {}
Jason Zamanb43991f2016-08-05 02:34:01 +0800241 for i in sepolicy.generate.USERS:
Jason Zaman789d0eb2015-07-24 16:07:13 +0800242 self.pages[i] = [self.SELECT_TYPE_PAGE, self.APP_PAGE, self.TRANSITION_PAGE, self.ROLE_PAGE, self.IN_NET_PAGE, self.OUT_NET_PAGE, self.BOOLEAN_PAGE, self.SELECT_DIR_PAGE]
Jason Zamanb43991f2016-08-05 02:34:01 +0800243 self.pages[sepolicy.generate.RUSER] = [self.SELECT_TYPE_PAGE, self.APP_PAGE, self.ADMIN_PAGE, self.USER_TRANSITION_PAGE, self.BOOLEAN_PAGE, self.SELECT_DIR_PAGE]
244 self.pages[sepolicy.generate.LUSER] = [self.SELECT_TYPE_PAGE, self.APP_PAGE, self.TRANSITION_PAGE, self.IN_NET_PAGE, self.OUT_NET_PAGE, self.BOOLEAN_PAGE, self.SELECT_DIR_PAGE]
245 self.pages[sepolicy.generate.SANDBOX] = [self.SELECT_TYPE_PAGE, self.APP_PAGE, self.IN_NET_PAGE, self.OUT_NET_PAGE, self.BOOLEAN_PAGE, self.SELECT_DIR_PAGE]
246 self.pages[sepolicy.generate.EUSER] = [self.SELECT_TYPE_PAGE, self.EXISTING_USER_PAGE, self.TRANSITION_PAGE, self.ROLE_PAGE, self.IN_NET_PAGE, self.OUT_NET_PAGE, self.BOOLEAN_PAGE, self.SELECT_DIR_PAGE]
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400247
Jason Zamanb43991f2016-08-05 02:34:01 +0800248 for i in sepolicy.generate.APPLICATIONS:
Jason Zaman789d0eb2015-07-24 16:07:13 +0800249 self.pages[i] = [self.SELECT_TYPE_PAGE, self.APP_PAGE, self.IN_NET_PAGE, self.OUT_NET_PAGE, self.COMMON_APPS_PAGE, self.FILES_PAGE, self.BOOLEAN_PAGE, self.SELECT_DIR_PAGE]
Jason Zamanb43991f2016-08-05 02:34:01 +0800250 self.pages[sepolicy.generate.USER] = [self.SELECT_TYPE_PAGE, self.APP_PAGE, self.USER_TRANSITION_PAGE, self.IN_NET_PAGE, self.OUT_NET_PAGE, self.COMMON_APPS_PAGE, self.FILES_PAGE, self.BOOLEAN_PAGE, self.SELECT_DIR_PAGE]
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400251
252 self.current_page = 0
253 self.back_button.set_sensitive(0)
254
255 self.network_buttons = {}
256
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100257 self.in_tcp_all_checkbutton = xml.get_object("in_tcp_all_checkbutton")
258 self.in_tcp_reserved_checkbutton = xml.get_object("in_tcp_reserved_checkbutton")
259 self.in_tcp_unreserved_checkbutton = xml.get_object("in_tcp_unreserved_checkbutton")
260 self.in_tcp_entry = self.xml.get_object("in_tcp_entry")
Jason Zaman789d0eb2015-07-24 16:07:13 +0800261 self.network_buttons[self.in_tcp_all_checkbutton] = [self.in_tcp_reserved_checkbutton, self.in_tcp_unreserved_checkbutton, self.in_tcp_entry]
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400262
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100263 self.out_tcp_all_checkbutton = xml.get_object("out_tcp_all_checkbutton")
264 self.out_tcp_reserved_checkbutton = xml.get_object("out_tcp_reserved_checkbutton")
265 self.out_tcp_unreserved_checkbutton = xml.get_object("out_tcp_unreserved_checkbutton")
266 self.out_tcp_entry = self.xml.get_object("out_tcp_entry")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400267
Jason Zaman789d0eb2015-07-24 16:07:13 +0800268 self.network_buttons[self.out_tcp_all_checkbutton] = [self.out_tcp_entry]
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400269
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100270 self.in_udp_all_checkbutton = xml.get_object("in_udp_all_checkbutton")
271 self.in_udp_reserved_checkbutton = xml.get_object("in_udp_reserved_checkbutton")
272 self.in_udp_unreserved_checkbutton = xml.get_object("in_udp_unreserved_checkbutton")
273 self.in_udp_entry = self.xml.get_object("in_udp_entry")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400274
Jason Zaman789d0eb2015-07-24 16:07:13 +0800275 self.network_buttons[self.in_udp_all_checkbutton] = [self.in_udp_reserved_checkbutton, self.in_udp_unreserved_checkbutton, self.in_udp_entry]
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400276
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100277 self.out_udp_all_checkbutton = xml.get_object("out_udp_all_checkbutton")
278 self.out_udp_entry = self.xml.get_object("out_udp_entry")
Jason Zaman789d0eb2015-07-24 16:07:13 +0800279 self.network_buttons[self.out_udp_all_checkbutton] = [self.out_udp_entry]
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400280
281 for b in self.network_buttons.keys():
Jason Zaman789d0eb2015-07-24 16:07:13 +0800282 b.connect("clicked", self.network_all_clicked)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400283
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100284 self.boolean_treeview = self.xml.get_object("boolean_treeview")
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200285 self.boolean_store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400286 self.boolean_treeview.set_model(self.boolean_store)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200287 self.boolean_store.set_sort_column_id(0, Gtk.SortType.ASCENDING)
288 col = Gtk.TreeViewColumn(_("Name"), Gtk.CellRendererText(), text=0)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400289 self.boolean_treeview.append_column(col)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200290 col = Gtk.TreeViewColumn(_("Description"), Gtk.CellRendererText(), text=1)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400291 self.boolean_treeview.append_column(col)
292
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100293 self.role_treeview = self.xml.get_object("role_treeview")
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200294 self.role_store = Gtk.ListStore(GObject.TYPE_STRING)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400295 self.role_treeview.set_model(self.role_store)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200296 self.role_treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
297 self.role_store.set_sort_column_id(0, Gtk.SortType.ASCENDING)
298 col = Gtk.TreeViewColumn(_("Role"), Gtk.CellRendererText(), text=0)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400299 self.role_treeview.append_column(col)
300
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100301 self.existing_user_treeview = self.xml.get_object("existing_user_treeview")
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200302 self.existing_user_store = Gtk.ListStore(GObject.TYPE_STRING)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400303 self.existing_user_treeview.set_model(self.existing_user_store)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200304 self.existing_user_store.set_sort_column_id(0, Gtk.SortType.ASCENDING)
305 col = Gtk.TreeViewColumn(_("Existing_User"), Gtk.CellRendererText(), text=0)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400306 self.existing_user_treeview.append_column(col)
307
308 for i in self.all_roles:
309 iter = self.role_store.append()
310 self.role_store.set_value(iter, 0, i[:-2])
311
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100312 self.in_tcp_reserved_checkbutton = xml.get_object("in_tcp_reserved_checkbutton")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400313
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100314 self.transition_treeview = self.xml.get_object("transition_treeview")
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200315 self.transition_store = Gtk.ListStore(GObject.TYPE_STRING)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400316 self.transition_treeview.set_model(self.transition_store)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200317 self.transition_treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
318 self.transition_store.set_sort_column_id(0, Gtk.SortType.ASCENDING)
319 col = Gtk.TreeViewColumn(_("Application"), Gtk.CellRendererText(), text=0)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400320 self.transition_treeview.append_column(col)
321
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100322 self.user_transition_treeview = self.xml.get_object("user_transition_treeview")
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200323 self.user_transition_store = Gtk.ListStore(GObject.TYPE_STRING)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400324 self.user_transition_treeview.set_model(self.user_transition_store)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200325 self.user_transition_treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
326 self.user_transition_store.set_sort_column_id(0, Gtk.SortType.ASCENDING)
327 col = Gtk.TreeViewColumn(_("Application"), Gtk.CellRendererText(), text=0)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400328 self.user_transition_treeview.append_column(col)
329
330 for i in self.all_users:
331 iter = self.user_transition_store.append()
332 self.user_transition_store.set_value(iter, 0, i[:-2])
333 iter = self.existing_user_store.append()
334 self.existing_user_store.set_value(iter, 0, i[:-2])
335
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100336 self.admin_treeview = self.xml.get_object("admin_treeview")
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200337 self.admin_store = Gtk.ListStore(GObject.TYPE_STRING)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400338 self.admin_treeview.set_model(self.admin_store)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200339 self.admin_treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
340 self.admin_store.set_sort_column_id(0, Gtk.SortType.ASCENDING)
341 col = Gtk.TreeViewColumn(_("Application"), Gtk.CellRendererText(), text=0)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400342 self.admin_treeview.append_column(col)
343
Dan Walsh678de8f2013-10-11 09:21:48 -0400344 try:
345 for u in sepolicy.interface.get_user():
346 iter = self.transition_store.append()
347 self.transition_store.set_value(iter, 0, u)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400348
Dan Walsh678de8f2013-10-11 09:21:48 -0400349 for a in sepolicy.interface.get_admin():
350 iter = self.admin_store.append()
351 self.admin_store.set_value(iter, 0, a)
Jason Zaman4d340e42016-08-05 02:34:03 +0800352 except ValueError as e:
Dan Walsh678de8f2013-10-11 09:21:48 -0400353 self.error(e.message)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400354
355 def confine_application(self):
Jason Zamanb43991f2016-08-05 02:34:01 +0800356 return self.get_type() in sepolicy.generate.APPLICATIONS
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400357
358 def forward(self, arg):
359 type = self.get_type()
360 if self.current_page == self.START_PAGE:
361 self.back_button.set_sensitive(1)
362
363 if self.pages[type][self.current_page] == self.SELECT_TYPE_PAGE:
364 if self.on_select_type_page_next():
365 return
366
367 if self.pages[type][self.current_page] == self.IN_NET_PAGE:
368 if self.on_in_net_page_next():
369 return
370
371 if self.pages[type][self.current_page] == self.OUT_NET_PAGE:
372 if self.on_out_net_page_next():
373 return
374
375 if self.pages[type][self.current_page] == self.APP_PAGE:
376 if self.on_name_page_next():
377 return
378
379 if self.pages[type][self.current_page] == self.EXISTING_USER_PAGE:
380 if self.on_existing_user_page_next():
381 return
382
383 if self.pages[type][self.current_page] == self.SELECT_DIR_PAGE:
384 outputdir = self.output_entry.get_text()
385 if not os.path.isdir(outputdir):
Jason Zaman789d0eb2015-07-24 16:07:13 +0800386 self.error(_("%s must be a directory") % outputdir)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400387 return False
388
389 if self.pages[type][self.current_page] == self.FINISH_PAGE:
390 self.generate_policy()
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100391 self.xml.get_object("cancel_button").set_label(Gtk.STOCK_CLOSE)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400392 else:
393 self.current_page = self.current_page + 1
394 self.notebook.set_current_page(self.pages[type][self.current_page])
395 if self.pages[type][self.current_page] == self.FINISH_PAGE:
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200396 self.forward_button.set_label(Gtk.STOCK_APPLY)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400397
Jason Zaman789d0eb2015-07-24 16:07:13 +0800398 def back(self, arg):
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400399 type = self.get_type()
400 if self.pages[type][self.current_page] == self.FINISH_PAGE:
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200401 self.forward_button.set_label(Gtk.STOCK_GO_FORWARD)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400402
403 self.current_page = self.current_page - 1
404 self.notebook.set_current_page(self.pages[type][self.current_page])
405 if self.pages[type][self.current_page] == self.START_PAGE:
406 self.back_button.set_sensitive(0)
407
408 def network_all_clicked(self, button):
409 active = button.get_active()
410 for b in self.network_buttons[button]:
411 b.set_sensitive(not active)
412
Jason Zaman789d0eb2015-07-24 16:07:13 +0800413 def verify(self, message, title=""):
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200414 dlg = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO,
415 Gtk.ButtonsType.YES_NO,
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400416 message)
417 dlg.set_title(title)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200418 dlg.set_position(Gtk.WindowPosition.MOUSE)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400419 dlg.show_all()
420 rc = dlg.run()
421 dlg.destroy()
422 return rc
423
424 def info(self, message):
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200425 dlg = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO,
426 Gtk.ButtonsType.OK,
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400427 message)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200428 dlg.set_position(Gtk.WindowPosition.MOUSE)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400429 dlg.show_all()
430 dlg.run()
431 dlg.destroy()
432
433 def error(self, message):
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200434 dlg = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR,
435 Gtk.ButtonsType.CLOSE,
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400436 message)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200437 dlg.set_position(Gtk.WindowPosition.MOUSE)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400438 dlg.show_all()
439 dlg.run()
440 dlg.destroy()
441
442 def get_name(self):
443 if self.existing_user_radiobutton.get_active():
444 store, iter = self.existing_user_treeview.get_selection().get_selected()
445 if iter == None:
446 raise ValueError(_("You must select a user"))
447 return store.get_value(iter, 0)
448 else:
449 return self.name_entry.get_text()
450
451 def get_type(self):
452 if self.sandbox_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800453 return sepolicy.generate.SANDBOX
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400454 if self.cgi_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800455 return sepolicy.generate.CGI
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400456 if self.user_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800457 return sepolicy.generate.USER
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400458 if self.init_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800459 return sepolicy.generate.DAEMON
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400460 if self.dbus_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800461 return sepolicy.generate.DBUS
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400462 if self.inetd_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800463 return sepolicy.generate.INETD
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400464 if self.login_user_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800465 return sepolicy.generate.LUSER
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400466 if self.admin_user_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800467 return sepolicy.generate.AUSER
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400468 if self.xwindows_user_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800469 return sepolicy.generate.XUSER
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400470 if self.terminal_user_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800471 return sepolicy.generate.TUSER
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400472 if self.root_user_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800473 return sepolicy.generate.RUSER
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400474 if self.existing_user_radiobutton.get_active():
Jason Zamanb43991f2016-08-05 02:34:01 +0800475 return sepolicy.generate.EUSER
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400476
477 def generate_policy(self, *args):
478 outputdir = self.output_entry.get_text()
479 try:
Jason Zamanb43991f2016-08-05 02:34:01 +0800480 my_policy = sepolicy.generate.policy(self.get_name(), self.get_type())
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400481
Jason Zaman789d0eb2015-07-24 16:07:13 +0800482 iter = self.boolean_store.get_iter_first()
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400483 while(iter):
484 my_policy.add_boolean(self.boolean_store.get_value(iter, 0), self.boolean_store.get_value(iter, 1))
Jason Zaman789d0eb2015-07-24 16:07:13 +0800485 iter = self.boolean_store.iter_next(iter)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400486
Jason Zamanb43991f2016-08-05 02:34:01 +0800487 if self.get_type() in sepolicy.generate.APPLICATIONS:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400488 my_policy.set_program(self.exec_entry.get_text())
489 my_policy.gen_symbols()
490
491 my_policy.set_use_syslog(self.syslog_checkbutton.get_active() == 1)
492 my_policy.set_use_tmp(self.tmp_checkbutton.get_active() == 1)
493 my_policy.set_use_uid(self.uid_checkbutton.get_active() == 1)
494 my_policy.set_use_pam(self.pam_checkbutton.get_active() == 1)
495
496 my_policy.set_use_dbus(self.dbus_checkbutton.get_active() == 1)
497 my_policy.set_use_audit(self.audit_checkbutton.get_active() == 1)
498 my_policy.set_use_terminal(self.terminal_checkbutton.get_active() == 1)
499 my_policy.set_use_mail(self.mail_checkbutton.get_active() == 1)
Jason Zamanb43991f2016-08-05 02:34:01 +0800500 if self.get_type() is sepolicy.generate.DAEMON:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400501 my_policy.set_init_script(self.init_script_entry.get_text())
Jason Zamanb43991f2016-08-05 02:34:01 +0800502 if self.get_type() == sepolicy.generate.USER:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400503 selected = []
504 self.user_transition_treeview.get_selection().selected_foreach(foreach, selected)
505 my_policy.set_transition_users(selected)
506 else:
Jason Zamanb43991f2016-08-05 02:34:01 +0800507 if self.get_type() == sepolicy.generate.RUSER:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400508 selected = []
509 self.admin_treeview.get_selection().selected_foreach(foreach, selected)
510 my_policy.set_admin_domains(selected)
511 selected = []
512 self.user_transition_treeview.get_selection().selected_foreach(foreach, selected)
513 my_policy.set_transition_users(selected)
514 else:
515 selected = []
516 self.transition_treeview.get_selection().selected_foreach(foreach, selected)
517 my_policy.set_transition_domains(selected)
518
519 selected = []
520 self.role_treeview.get_selection().selected_foreach(foreach, selected)
521 my_policy.set_admin_roles(selected)
522
523 my_policy.set_in_tcp(self.in_tcp_all_checkbutton.get_active(), self.in_tcp_reserved_checkbutton.get_active(), self.in_tcp_unreserved_checkbutton.get_active(), self.in_tcp_entry.get_text())
524 my_policy.set_in_udp(self.in_udp_all_checkbutton.get_active(), self.in_udp_reserved_checkbutton.get_active(), self.in_udp_unreserved_checkbutton.get_active(), self.in_udp_entry.get_text())
525 my_policy.set_out_tcp(self.out_tcp_all_checkbutton.get_active(), self.out_tcp_entry.get_text())
526 my_policy.set_out_udp(self.out_udp_all_checkbutton.get_active(), self.out_udp_entry.get_text())
527
Jason Zaman789d0eb2015-07-24 16:07:13 +0800528 iter = self.store.get_iter_first()
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400529 while(iter):
530 if self.store.get_value(iter, 1) == FILE:
531 my_policy.add_file(self.store.get_value(iter, 0))
532 else:
533 my_policy.add_dir(self.store.get_value(iter, 0))
Jason Zaman789d0eb2015-07-24 16:07:13 +0800534 iter = self.store.iter_next(iter)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400535
536 self.info(my_policy.generate(outputdir))
537 return False
Jason Zaman4d340e42016-08-05 02:34:03 +0800538 except ValueError as e:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400539 self.error(e.message)
540
541 def delete(self, args):
542 store, iter = self.view.get_selection().get_selected()
543 if iter != None:
544 store.remove(iter)
Jason Zaman789d0eb2015-07-24 16:07:13 +0800545 self.view.get_selection().select_path((0,))
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400546
547 def delete_boolean(self, args):
548 store, iter = self.boolean_treeview.get_selection().get_selected()
549 if iter != None:
550 store.remove(iter)
Jason Zaman789d0eb2015-07-24 16:07:13 +0800551 self.boolean_treeview.get_selection().select_path((0,))
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400552
Jason Zaman789d0eb2015-07-24 16:07:13 +0800553 def add_boolean(self, type):
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400554 self.boolean_name_entry.set_text("")
555 self.boolean_description_entry.set_text("")
556 rc = self.boolean_dialog.run()
557 self.boolean_dialog.hide()
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200558 if rc == Gtk.ResponseType.CANCEL:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400559 return
560 iter = self.boolean_store.append()
561 self.boolean_store.set_value(iter, 0, self.boolean_name_entry.get_text())
562 self.boolean_store.set_value(iter, 1, self.boolean_description_entry.get_text())
563
Jason Zaman789d0eb2015-07-24 16:07:13 +0800564 def __add(self, type):
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400565 rc = self.file_dialog.run()
566 self.file_dialog.hide()
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200567 if rc == Gtk.ResponseType.CANCEL:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400568 return
569 for i in self.file_dialog.get_filenames():
570 iter = self.store.append()
571 self.store.set_value(iter, 0, i)
572 self.store.set_value(iter, 1, type)
573
574 def exec_select(self, args):
575 self.file_dialog.set_select_multiple(0)
576 self.file_dialog.set_title(_("Select executable file to be confined."))
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200577 self.file_dialog.set_action(Gtk.FileChooserAction.OPEN)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400578 self.file_dialog.set_current_folder("/usr/sbin")
579 rc = self.file_dialog.run()
580 self.file_dialog.hide()
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200581 if rc == Gtk.ResponseType.CANCEL:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400582 return
583 self.exec_entry.set_text(self.file_dialog.get_filename())
584
585 def init_script_select(self, args):
586 self.file_dialog.set_select_multiple(0)
587 self.file_dialog.set_title(_("Select init script file to be confined."))
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200588 self.file_dialog.set_action(Gtk.FileChooserAction.OPEN)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400589 self.file_dialog.set_current_folder("/etc/rc.d/init.d")
590 rc = self.file_dialog.run()
591 self.file_dialog.hide()
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200592 if rc == Gtk.ResponseType.CANCEL:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400593 return
594 self.init_script_entry.set_text(self.file_dialog.get_filename())
595
596 def add(self, args):
597 self.file_dialog.set_title(_("Select file(s) that confined application creates or writes"))
598 self.file_dialog.set_current_folder("/")
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200599 self.file_dialog.set_action(Gtk.FileChooserAction.OPEN)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400600 self.file_dialog.set_select_multiple(1)
601 self.__add(FILE)
602
603 def add_dir(self, args):
604 self.file_dialog.set_title(_("Select directory(s) that the confined application owns and writes into"))
605 self.file_dialog.set_current_folder("/")
606 self.file_dialog.set_select_multiple(1)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200607 self.file_dialog.set_action(Gtk.FileChooserAction.SELECT_FOLDER)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400608 self.__add(DIR)
609
610 def on_about_clicked(self, args):
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100611 dlg = xml.get_object("about_dialog")
Jason Zaman789d0eb2015-07-24 16:07:13 +0800612 dlg.run()
613 dlg.hide()
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400614
615 def quit(self, args):
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200616 Gtk.main_quit()
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400617
618 def setupScreen(self):
619 # Bring in widgets from glade file.
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100620 self.mainWindow = self.xml.get_object("main_window")
621 self.druid = self.xml.get_object("druid")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400622 self.type = 0
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100623 self.name_entry = self.xml.get_object("name_entry")
Jason Zaman789d0eb2015-07-24 16:07:13 +0800624 self.name_entry.connect("insert_text", self.on_name_entry_changed)
625 self.name_entry.connect("focus_out_event", self.on_focus_out_event)
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100626 self.exec_entry = self.xml.get_object("exec_entry")
627 self.exec_button = self.xml.get_object("exec_button")
628 self.init_script_entry = self.xml.get_object("init_script_entry")
629 self.init_script_button = self.xml.get_object("init_script_button")
630 self.output_entry = self.xml.get_object("output_entry")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400631 self.output_entry.set_text(os.getcwd())
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100632 self.xml.get_object("output_button").connect("clicked", self.output_button_clicked)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400633
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100634 self.xwindows_user_radiobutton = self.xml.get_object("xwindows_user_radiobutton")
635 self.terminal_user_radiobutton = self.xml.get_object("terminal_user_radiobutton")
636 self.root_user_radiobutton = self.xml.get_object("root_user_radiobutton")
637 self.login_user_radiobutton = self.xml.get_object("login_user_radiobutton")
638 self.admin_user_radiobutton = self.xml.get_object("admin_user_radiobutton")
639 self.existing_user_radiobutton = self.xml.get_object("existing_user_radiobutton")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400640
Petr Lautrbachaeef83c2018-02-13 13:08:48 +0100641 self.user_radiobutton = self.xml.get_object("user_radiobutton")
642 self.init_radiobutton = self.xml.get_object("init_radiobutton")
643 self.inetd_radiobutton = self.xml.get_object("inetd_radiobutton")
644 self.dbus_radiobutton = self.xml.get_object("dbus_radiobutton")
645 self.cgi_radiobutton = self.xml.get_object("cgi_radiobutton")
646 self.sandbox_radiobutton = self.xml.get_object("sandbox_radiobutton")
647 self.tmp_checkbutton = self.xml.get_object("tmp_checkbutton")
648 self.uid_checkbutton = self.xml.get_object("uid_checkbutton")
649 self.pam_checkbutton = self.xml.get_object("pam_checkbutton")
650 self.dbus_checkbutton = self.xml.get_object("dbus_checkbutton")
651 self.audit_checkbutton = self.xml.get_object("audit_checkbutton")
652 self.terminal_checkbutton = self.xml.get_object("terminal_checkbutton")
653 self.mail_checkbutton = self.xml.get_object("mail_checkbutton")
654 self.syslog_checkbutton = self.xml.get_object("syslog_checkbutton")
655 self.view = self.xml.get_object("write_treeview")
656 self.file_dialog = self.xml.get_object("filechooserdialog")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400657
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200658 self.store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_INT)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400659 self.view.set_model(self.store)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200660 col = Gtk.TreeViewColumn("", Gtk.CellRendererText(), text=0)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400661 col.set_resizable(True)
662 self.view.append_column(col)
Jason Zaman789d0eb2015-07-24 16:07:13 +0800663 self.view.get_selection().select_path((0,))
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400664
665 def output_button_clicked(self, *args):
666 self.file_dialog.set_title(_("Select directory to generate policy files in"))
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200667 self.file_dialog.set_action(Gtk.FileChooserAction.SELECT_FOLDER)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400668 self.file_dialog.set_select_multiple(0)
669 rc = self.file_dialog.run()
670 self.file_dialog.hide()
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200671 if rc == Gtk.ResponseType.CANCEL:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400672 return
673 self.output_entry.set_text(self.file_dialog.get_filename())
674
675 def on_name_entry_changed(self, entry, text, size, position):
676 if text.find(" ") >= 0:
Petr Lautrbachbb6b4c62018-02-22 18:29:01 +0100677 entry.stop_emission_by_name("insert-text")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400678
679 def on_focus_out_event(self, entry, third):
680 name = entry.get_text()
681 if self.name != name:
682 if name in self.all_types:
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200683 if self.verify(_("Type %s_t already defined in current policy.\nDo you want to continue?") % name, _("Verify Name")) == Gtk.ResponseType.NO:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400684 entry.set_text("")
685 return False
686 if name in self.all_modules:
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200687 if self.verify(_("Module %s already loaded in current policy.\nDo you want to continue?") % name, _("Verify Name")) == Gtk.ResponseType.NO:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400688 entry.set_text("")
689 return False
690
691 file = "/etc/rc.d/init.d/" + name
692 if os.path.isfile(file) and self.init_script_entry.get_text() == "":
693 self.init_script_entry.set_text(file)
694
695 file = "/usr/sbin/" + name
696 if os.path.isfile(file) and self.exec_entry.get_text() == "":
697 self.exec_entry.set_text(file)
698
699 self.name = name
700 return False
701
702 def on_in_net_page_next(self, *args):
703 try:
Petr Lautrbach53331522017-03-17 15:09:08 +0100704 sepolicy.generate.verify_ports(self.in_tcp_entry.get_text())
705 sepolicy.generate.verify_ports(self.in_udp_entry.get_text())
Jason Zaman4d340e42016-08-05 02:34:03 +0800706 except ValueError as e:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400707 self.error(e.message)
708 return True
709
710 def on_out_net_page_next(self, *args):
711 try:
Petr Lautrbach53331522017-03-17 15:09:08 +0100712 sepolicy.generate.verify_ports(self.out_tcp_entry.get_text())
713 sepolicy.generate.verify_ports(self.out_udp_entry.get_text())
Jason Zaman4d340e42016-08-05 02:34:03 +0800714 except ValueError as e:
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400715 self.error(e.message)
716 return True
717
718 def on_select_type_page_next(self, *args):
719 self.exec_entry.set_sensitive(self.confine_application())
720 self.exec_button.set_sensitive(self.confine_application())
721 self.init_script_entry.set_sensitive(self.init_radiobutton.get_active())
722 self.init_script_button.set_sensitive(self.init_radiobutton.get_active())
723
724 def on_existing_user_page_next(self, *args):
725 store, iter = self.view.get_selection().get_selected()
726 if iter != None:
727 self.error(_("You must select a user"))
728 return True
729
730 def on_name_page_next(self, *args):
Jason Zaman789d0eb2015-07-24 16:07:13 +0800731 name = self.name_entry.get_text()
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400732 if not name.isalnum():
733 self.error(_("You must add a name made up of letters and numbers and containing no spaces."))
734 return True
735
736 for i in self.label_dict:
737 text = '<b>%s</b>' % (self.label_dict[i] % ("'" + name + "'"))
738 i.set_markup(text)
739
740 for i in self.tooltip_dict:
741 text = self.tooltip_dict[i] % ("'" + name + "'")
742 i.set_tooltip_text(text)
743
744 if self.confine_application():
745 exe = self.exec_entry.get_text()
746 if exe == "":
747 self.error(_("You must enter a executable"))
748 return True
Petr Lautrbach53331522017-03-17 15:09:08 +0100749 policy = sepolicy.generate.policy(name, self.get_type())
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400750 policy.set_program(exe)
751 policy.gen_writeable()
752 policy.gen_symbols()
753 for f in policy.files.keys():
754 iter = self.store.append()
755 self.store.set_value(iter, 0, f)
756 self.store.set_value(iter, 1, FILE)
757
758 for f in policy.dirs.keys():
759 iter = self.store.append()
760 self.store.set_value(iter, 0, f)
761 self.store.set_value(iter, 1, DIR)
762 self.tmp_checkbutton.set_active(policy.use_tmp)
763 self.uid_checkbutton.set_active(policy.use_uid)
764 self.pam_checkbutton.set_active(policy.use_pam)
765 self.dbus_checkbutton.set_active(policy.use_dbus)
766 self.audit_checkbutton.set_active(policy.use_audit)
767 self.terminal_checkbutton.set_active(policy.use_terminal)
768 self.mail_checkbutton.set_active(policy.use_mail)
769 self.syslog_checkbutton.set_active(policy.use_syslog)
770
771 def stand_alone(self):
Nicolas Ioossb550c0e2019-08-05 22:11:20 +0200772 desktopName = _("Configure SELinux")
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400773
774 self.setupScreen()
775 self.mainWindow.connect("destroy", self.quit)
776
777 self.mainWindow.show_all()
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200778 Gtk.main()
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400779
780if __name__ == "__main__":
Jason Zaman789d0eb2015-07-24 16:07:13 +0800781 signal.signal(signal.SIGINT, signal.SIG_DFL)
Dan Walshe4bbd7c2012-04-13 11:01:32 -0400782
783 app = childWindow()
784 app.stand_alone()