Viewing file: mainWindow.py (35.4 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
## mainWindow.py - main interface window for redhat-config-users ## Copyright (C) 2001-2003 Red Hat, Inc. ## Copyright (C) 2001-2003 Brent Fox <bfox@redhat.com>
## 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: Brent Fox
import signal import gtk import gobject import gtk.glade import string import sys import time import os import rpm
import libuser
import preferences
import groupWindow import userWindow import userProperties import groupProperties import messageDialog import prefWindow
## ## I18N ## from rhpl.translate import _, N_ import rhpl.translate as translate import rhpl.executil domain = "system-config-users" translate.textdomain (domain) gtk.glade.bindtextdomain(domain)
def service_pending_events(): while gtk.events_pending(): if gtk.__dict__.has_key ("main_iteration"): gtk.main_iteration() else: gtk.mainiteration()
def admin_prompt_callback(prompts, title): dialog = gtk.Dialog() dialog.set_title(title) dialog.set_position(gtk.WIN_POS_CENTER) dialog.set_icon(iconPixbuf) dialog.add_button(gtk.STOCK_OK, 1) dialog.add_button(gtk.STOCK_CANCEL, 0)
table = gtk.Table(rows = len(prompts), columns = 2) dialog.vbox.pack_start(table)
table.set_row_spacings(4) table.set_col_spacings(4)
ret_list = [] for i in range(len(prompts)): prompt = prompts[i]
label = gtk.Label(prompt.prompt) label.set_alignment(1.0, 0.5) table.attach(label, 0, 1, i, i + 1)
entry = gtk.Entry() entry.set_visibility(prompt.visible) if prompt.default_value: entry.set_text(prompt.default_value) table.attach(entry, 1, 2, i, i + 1)
ret_list.append((prompt, entry)) table.show_all()
i = dialog.run() if i == 1: for (prompt, entry) in ret_list: prompt.value = entry.get_text() dialog.destroy() return True
sys.exit(1)
gtk.glade.bindtextdomain(domain) if os.access("system-config-users.glade", os.F_OK): xml = gtk.glade.XML ("./system-config-users.glade", domain=domain) else: xml = gtk.glade.XML ("/usr/share/system-config-users/system-config-users.glade", domain=domain)
busy_cursor = gtk.gdk.Cursor(gtk.gdk.WATCH) ready_cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
## ## Icon for windows ##
iconPixbuf = None try: iconPixbuf = gtk.gdk.pixbuf_new_from_file("/usr/share/system-config-users/system-config-users.png") except: pass
class mainWindow:
def version(): # substituted to the real version by the Makefile at installation time. return "1.2.51"
def destroy (self, *args): try: self.preferences.save () except IOError: print _("Error saving settings to %s") % preferences.filename if gtk.__dict__.has_key ("main_quit"): gtk.main_quit() else: gtk.mainquit()
def __init__(self): self.preferences = preferences.Preferences () self.preferences.load () self.prefWindow = prefWindow.PrefWindow (xml, iconPixbuf) nameTag = _("Users and Groups") commentTag = _("Add or remove users and groups") self.toplevel = xml.get_widget ('mainWindow') self.toplevel.resize(775, 550) self.toplevel.set_icon(iconPixbuf) self.add_user_button = xml.get_widget("add_user_button") self.add_group_button = xml.get_widget("add_group_button") self.properties_button = xml.get_widget("properties_button") self.properties_menu = xml.get_widget("properties_menu") self.delete_button = xml.get_widget("delete_button") self.delete_menu = xml.get_widget("delete_menu") self.toplevel.connect("destroy", self.destroy)
self.ADMIN = libuser.admin(prompt=admin_prompt_callback, prompt_data=(_('Logon Information Required'),))
self.userStore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT) self.userStore.set_sort_column_id(1, gtk.SORT_ASCENDING) self.userTreeView = xml.get_widget('user_view') self.userTreeView.set_rules_hint(True) self.userTreeView.set_model(self.userStore) self.userTreeView.get_selection().connect("changed", self.itemSelected) self.userTreeView.connect("row_activated", self.rowActivated)
col = gtk.TreeViewColumn(_("User Name"), gtk.CellRendererText(), text=0) col.set_sort_column_id(0) col.set_resizable(True) self.userTreeView.append_column(col) col = gtk.TreeViewColumn(_("User ID"), gtk.CellRendererText(), text=1) col.set_sort_column_id(1) col.set_resizable(True) self.userTreeView.append_column(col) col = gtk.TreeViewColumn(_("Primary Group"), gtk.CellRendererText(), text=2) col.set_sort_column_id(2) col.set_resizable(True) self.userTreeView.append_column(col) col = gtk.TreeViewColumn(_("Full Name"), gtk.CellRendererText(), text=3) col.set_sort_column_id(3) col.set_resizable(True) self.userTreeView.append_column(col) col = gtk.TreeViewColumn(_("Login Shell"), gtk.CellRendererText(), text=4) col.set_sort_column_id(4) col.set_resizable(True) self.userTreeView.append_column(col) col = gtk.TreeViewColumn(_("Home Directory"), gtk.CellRendererText(), text=5) col.set_sort_column_id(5) col.set_resizable(True) self.userTreeView.append_column(col)
self.userTreeView.set_property("headers-visible", True)
self.groupStore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT) self.groupStore.set_sort_column_id(1, gtk.SORT_ASCENDING) self.groupTreeView = xml.get_widget('group_view') self.groupTreeView.set_rules_hint(True) self.groupTreeView.set_model(self.groupStore) self.groupTreeView.get_selection().connect("changed", self.itemSelected) self.groupTreeView.connect("row_activated", self.rowActivated) col = gtk.TreeViewColumn(_("Group Name"), gtk.CellRendererText(), text=0) col.set_sort_column_id(0) col.set_resizable(True) self.groupTreeView.append_column(col) col = gtk.TreeViewColumn(_("Group ID"), gtk.CellRendererText(), text=1) col.set_sort_column_id(1) col.set_resizable(True) self.groupTreeView.append_column(col) col = gtk.TreeViewColumn(_("Group Members"), gtk.CellRendererText(), text=2) col.set_resizable(True) self.groupTreeView.append_column(col)
self.notebook = xml.get_widget('notebook1') self.notebook.connect('switch-page', self.changeNotebookPage) self.filter = xml.get_widget('filterEntry')
self.filterSystemUsersGroupsCheckButton = xml.get_widget ('filterSystemUsersGroupsCheckButton') self.filterSystemUsersGroupsCheckButton.set_active (self.preferences['FILTER']) self.assignHighestUidCheckButton = xml.get_widget ('assignHighestUidCheckButton') self.assignHighestUidCheckButton.set_active (self.preferences['ASSIGN_HIGHEST_UID']) self.assignHighestGidCheckButton = xml.get_widget ('assignHighestGidCheckButton') self.assignHighestGidCheckButton.set_active (self.preferences['ASSIGN_HIGHEST_GID']) self.preferSameUIDGIDCheckButton = xml.get_widget ('preferSameUIDGIDCheckButton') self.preferSameUIDGIDCheckButton.set_active (self.preferences['PREFER_SAME_UID_GID'])
self.user_dict = {} self.group_dict = {} self.gid_dict = {} self.member_dict = {} self.service_interval = 10
selinuxEnabled = self.isSELinuxEnabled()
self.userWin = userWindow.userWindow(self, self.userStore, self.groupTreeView, xml, selinuxEnabled) self.groupWin = groupWindow.groupWindow(self, self.userTreeView, self.groupTreeView, xml) self.userProperties = userProperties.userProperties(self, self.userTreeView, self.groupTreeView, xml, selinuxEnabled) self.groupProperties = groupProperties.groupProperties(self, self.userTreeView, self.groupTreeView, xml) self.userSelectedRow = None self.groupSelectedRow = None self.toplevel.show_all ()
xml.signal_connect("on_about_activate", self.on_about_button_clicked) xml.signal_connect("on_manual_activate", self.on_manual_button_clicked) xml.signal_connect("on_add_user_activate", self.on_add_user_activate) xml.signal_connect("on_add_user_button_clicked", self.on_add_user_activate) xml.signal_connect("on_add_group_activate", self.on_add_group_activate) xml.signal_connect("on_add_group_button_clicked", self.on_add_group_activate) xml.signal_connect("on_properties_activate", self.on_properties_activate) xml.signal_connect("on_properties_button_clicked", self.on_properties_activate) xml.signal_connect("on_preferences_activate", self.on_preferences_activate) xml.signal_connect("on_delete_activate", self.on_delete_activate) xml.signal_connect("on_delete_button_clicked", self.on_delete_activate) xml.signal_connect("on_help_button_clicked", self.on_help_button_clicked) xml.signal_connect("on_new_user_activate", self.on_add_user_activate) xml.signal_connect("on_filterButton_clicked", self.refresh) xml.signal_connect("on_filterEntry_activate", self.refresh) xml.signal_connect("on_refreshButton_clicked", self.refresh) xml.signal_connect("on_exit_activate", self.on_exit_activate)
xml.signal_connect("on_filterSystemUsersGroupsCheckButton_toggled", self.on_filterSystemUsersGroupsCheckButton_toggled) xml.signal_connect("on_assignHighestUidCheckButton_toggled", self.on_assignHighestUidCheckButton_toggled) xml.signal_connect("on_assignHighestGidCheckButton_toggled", self.on_assignHighestGidCheckButton_toggled) xml.signal_connect("on_preferSameUIDGIDCheckButton_toggled", self.on_preferSameUIDGIDCheckButton_toggled)
self.refresh() self.ready() if gtk.__dict__.has_key ("main"): gtk.main () else: gtk.mainloop ()
def on_exit_activate(self, args): self.destroy()
def busy(self): self.toplevel.set_sensitive(False) self.toplevel.window.set_cursor(busy_cursor) pass
def ready(self): self.toplevel.window.set_cursor(ready_cursor) self.toplevel.set_sensitive(True) pass
def get_user_list (self, filter): if filter == "": users = self.ADMIN.enumerateUsersFull() else: users = self.ADMIN.enumerateUsersFull(filter)
users.sort() return users
def get_group_list(self, filter): if filter == "": groups = self.ADMIN.enumerateGroupsFull() else: groups = self.ADMIN.enumerateGroupsFull(filter) groups.sort()
return groups
def refresh_users(self): self.user_dict = {} self.gid_dict = {}
# pull up information about users and store the objects in # a dictionary keyed by user name i = 0 for user in self.get_user_list(self.get_filter_data()): i = i + 1 if i >= self.service_interval: service_pending_events() i = 0
userName = user.get(libuser.USERNAME)[0] self.user_dict[userName] = user
# try to get a name to associate with the user's primary gid, # and attempt to minimize lookups by caching answers try: gidNumber = user.get(libuser.GIDNUMBER)[0] except Exception, e: messageDialog.show_message_dialog (_("The user database cannot be read. This problem is most likely caused by a mismatch between /etc/passwd and /etc/shadow or /etc/group and /etc/gshadow. The program will exit now.")) os._exit(0)
try: group = self.gid_dict[long (gidNumber)] except: try: group = self.ADMIN.lookupGroupById(long (gidNumber)) self.gid_dict[long (gidNumber)] = group except: pass
def refresh_groups(self): self.group_dict = {} self.member_dict = {}
i = 0 for group in self.get_group_list(self.get_filter_data()): i = i + 1 if i >= self.service_interval: service_pending_events() i = 0
groupName = group.get(libuser.GROUPNAME)[0]
# /etc/group <-> /etc/gshadow inconsistency canary try: gidNumber = group.get (libuser.GIDNUMBER)[0] except Exception, e: messageDialog.show_message_dialog (_("The user database cannot be read. This problem is most likely caused by a mismatch between /etc/passwd and /etc/shadow or /etc/group and /etc/gshadow. The program will exit now.")) os._exit(0)
self.group_dict[groupName] = group
members = self.ADMIN.enumerateUsersByGroup(groupName)
if not members: members = [] members.sort()
self.member_dict[groupName] = members
def refresh_users_and_groups(self, names): self.busy() updated_names = {} for name in names: # If we've already updated this user/group, skip it. if updated_names.has_key(name): continue updated_names[name] = name service_pending_events()
userEnt = self.ADMIN.lookupUserByName(name) if userEnt: self.user_dict[name] = userEnt gidNumber = userEnt.get(libuser.GIDNUMBER)[0] try: groupEnt = self.gid_dict[long (gidNumber)] except: try: groupEnt = self.ADMIN.lookupGroupById(long (gidNumber)) self.gid_dict[long (gidNumber)] = groupEnt except: pass else: try: del(self.user_dict[name]) except: pass
groupEnt = self.ADMIN.lookupGroupByName(name) if groupEnt: self.group_dict[name] = groupEnt self.member_dict[name] = self.ADMIN.enumerateUsersByGroup(name) gidNumber = groupEnt.get(libuser.GIDNUMBER) gidNumber = gidNumber[0] self.gid_dict[long (gidNumber)] = groupEnt else: try: del(self.group_dict[name]) del(self.member_dict[name]) except: pass
users = self.get_user_list(self.get_filter_data()) for user in self.user_dict.keys(): if user not in users: del self.user_dict[user]
groups = self.get_group_list(self.get_filter_data()) for group in self.group_dict.keys(): if group not in groups: del self.group_dict[group]
self.refresh() self.ready()
def refresh(self, *args): self.busy() self.refresh_users() self.refresh_groups() self.populate_lists() self.toggleWidgets(False) self.ready()
def populate_user_list(self): self.userStore.clear() for user in self.user_dict.keys(): userEnt = self.user_dict[user] uid = userEnt.get(libuser.USERNAME)[0] uidNumber = userEnt.get(libuser.UIDNUMBER)[0] gidNumber = userEnt.get(libuser.GIDNUMBER)[0] if userEnt.get(libuser.GECOS): gecos = userEnt.get(libuser.GECOS)[0] else: gecos = uid if userEnt.get(libuser.HOMEDIRECTORY): homeDir = userEnt.get(libuser.HOMEDIRECTORY)[0] else: homeDir = '' if userEnt.get(libuser.LOGINSHELL): shell = userEnt.get(libuser.LOGINSHELL)[0] else: shell = ''
try: groupEnt = self.gid_dict[long (gidNumber)] groupName = groupEnt.get(libuser.GROUPNAME)[0] except: groupName = gidNumber
#Convert the user fullName into unicode so pygtk2 doesn't truncate strings gecos = unicode (gecos, 'utf-8')
if self.preferences['FILTER'] == True: #display users with UIDs > 499 if long (uidNumber) > 499L and not (uid == "nfsnobody" and (long (uidNumber) == 65534L or long (uidNumber) == 4294967294L)): iter = self.userStore.append() self.userStore.set_value(iter, 0, uid) self.userStore.set_value(iter, 1, uidNumber) self.userStore.set_value(iter, 2, groupName) self.userStore.set_value(iter, 3, gecos) self.userStore.set_value(iter, 4, shell) self.userStore.set_value(iter, 5, homeDir) self.userStore.set_value(iter, 6, userEnt) else: #display users with UIDs > 499 if long (uidNumber) > -1L: iter = self.userStore.append() self.userStore.set_value(iter, 0, uid) self.userStore.set_value(iter, 1, uidNumber) self.userStore.set_value(iter, 2, groupName) self.userStore.set_value(iter, 3, gecos) self.userStore.set_value(iter, 4, shell) self.userStore.set_value(iter, 5, homeDir) self.userStore.set_value(iter, 6, userEnt)
def populate_group_list(self): self.groupStore.clear() members = []
for group in self.group_dict.keys(): groupEnt = self.group_dict[group]
if groupEnt.get(libuser.GIDNUMBER) != []: cn = groupEnt.get(libuser.GROUPNAME)[0] gid = groupEnt.get(libuser.GIDNUMBER)[0] members = self.member_dict[group] if not members: members = []
#concatenate the list of members in the group into a comma separated list memberlist = string.join(members, ", ")
if self.preferences['FILTER'] == True: #display groups with UIDs > 499 if long (gid) > 499 and not (cn == "nfsnobody" and (long (gid) == 65534L or long (gid) == 4294967294L)): iter = self.groupStore.append() self.groupStore.set_value(iter, 0, cn) self.groupStore.set_value(iter, 1, gid) self.groupStore.set_value(iter, 2, memberlist) self.groupStore.set_value(iter, 3, groupEnt) else: #display groups with UIDs > 499 if long (gid) > -1: iter = self.groupStore.append() self.groupStore.set_value(iter, 0, cn) self.groupStore.set_value(iter, 1, gid) self.groupStore.set_value(iter, 2, memberlist) self.groupStore.set_value(iter, 3, groupEnt) def populate_lists(self): self.populate_user_list() self.populate_group_list() pass
#------------Event handlers-------------# #---------------------------------------#
#--------Event handlers for toplevel window-----# def on_about_button_clicked(self, *args): dlg = xml.get_widget ("aboutWindow") version = xml.get_widget ("aboutWindowVersion") version.set_text (_("Version %s") % ("1.2.51")) copyright = xml.get_widget ("aboutWindowCopyright") copyright_by = [ [ "2001 - 2006", "Red Hat, Inc." ], [ "2001 - 2004", "Brent Fox", "bfox@redhat.com" ], [ "2004 - 2006", "Nils Philippsen", "nphilipp@redhat.com" ] ] cb_strings = [] for cb in copyright_by: years = cb[0] holder = cb[1] try: email = cb[2] cb_strings.append (_("Copyright (c) %s %s <%s>") % (years, holder, email)) except IndexError: cb_strings.append (_("Copyright (c) %s %s") % (years, holder)) copyright.set_text ('\n'.join (cb_strings)) dlg.run () dlg.hide ()
def on_help_button_clicked(self, *args): help_pages = ["file:///usr/share/doc/system-config-users-1.2.51/user-new.html", "file:///usr/share/doc/system-config-users-1.2.51/group-new.html",] page = help_pages [self.notebook.get_current_page ()] path = "/usr/bin/htmlview"
if path == None: messageDialog.show_message_dialog(_("Help is not available.")) return pid = os.fork() if not pid: os.execv(path, [path, page]) def on_manual_button_clicked(self, *args): page = "file:///usr/share/doc/system-config-users-1.2.51/index.html" path = "/usr/bin/htmlview"
if path == None: messageDialog.show_message_dialog(_("Help is not available.")) return pid = os.fork() if not pid: os.execv(path, [path, page])
def on_exit1_activate(self, *args): if gtk.__dict__.has_key ("main_quit"): gtk.main_quit() else: gtk.mainquit()
def on_add_user_activate(self, *args): filter = self.get_filter_data() self.userWin.newUserWin(filter) self.userWin.userWin.set_transient_for(self.toplevel)
def on_add_group_activate(self, *args): self.groupWin.newGroupWin() self.groupWin.groupWin.set_transient_for(self.toplevel)
def on_delete_activate(self, *args): page = self.notebook.get_current_page() if page == 0: if self.userTreeView.get_selection().get_selected(): data, iter = self.userTreeView.get_selection().get_selected() userEnt = self.userStore.get_value(iter, 6)
user = userEnt.get(libuser.USERNAME)[0] uid = userEnt.get(libuser.UIDNUMBER)[0] homeDir = userEnt.get(libuser.HOMEDIRECTORY)[0] mailSpool = "/var/spool/mail/%s" % (user)
errMsgs = []
if uid == 0: dlg = gtk.MessageDialog (None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("Deleting the root user is not allowed.")) dlg.set_position(gtk.WIN_POS_CENTER) dlg.set_modal (True) dlg.set_icon (iconPixbuf) dlg.run () dlg.destroy () return ts = rpm.TransactionSet () if ts.dbMatch ("basenames", homeDir).count () > 0 or ts.dbMatch ("basenames", os.path.abspath (homeDir)).count () > 0 or ts.dbMatch ("basenames", os.path.realpath (homeDir)).count () > 0: errMsgs.append (_("- An installed software package contains this directory.")) if uid < 500 or (user == "nfsnobody" and (long (uid) == 65534L or long (uid) == 4294967294L)): errMsgs.append (_("- A system user owns this directory and removing it may impair the system's integrity.")) if not os.access(homeDir, os.W_OK): errMsgs.append (_("- This directory doesn't exist or isn't writable.")) elif os.lstat (homeDir).st_uid != uid: errMsgs.append (_("- The user '%s' doesn't own this directory.") % (user)) pipe = os.popen ("/usr/bin/pgrep -fl -U %d; /usr/bin/pgrep -u %d" % (uid, uid)) processes = pipe.readlines () pipe.close () processes_running_text = "" if len (processes) > 0: processes_running_text = _("<b>There are currently processes running that are owned by '%s'!</b> This user is probably still logged in. ") % (user) text = _("Do you really want to remove the user '%s'?") % (user) dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, (processes_running_text + text)) dlg.set_position(gtk.WIN_POS_CENTER) dlg.set_modal(True) dlg.set_icon(iconPixbuf) dlg.label.set_use_markup (True) filesDeleteCheckButton = None if len (errMsgs) == 0: filesDeleteText = _("Delete %s's home directory ('%s') and temporary files.") % (user, homeDir) if os.access (mailSpool, os.W_OK) and os.lstat (mailSpool).st_uid == uid: filesDeleteText = _("Delete %s's home directory ('%s'), mail spool ('%s') and temporary files.") % (user, homeDir, mailSpool) filesDeleteCheckButton = gtk.CheckButton (filesDeleteText) filesDeleteCheckButton.set_active(True) filesDeleteCheckButton.set_border_width(5) filesDeleteCheckButton.get_child().set_line_wrap (True) dlg.vbox.pack_start(filesDeleteCheckButton) else: if len(errMsgs) == 1: l_txt = _("I won't delete %s's home directory ('%s') due to this reason:\n%s") else: l_txt = _("I won't delete %s's home directory ('%s') due to these reasons:\n%s") errLabel = gtk.Label (l_txt % (user, homeDir, string.join (errMsgs, "\n"))) errLabel.set_line_wrap (True) dlg.vbox.pack_start (errLabel) dlg.show_all() rc = dlg.run()
if rc == gtk.RESPONSE_NO: #bail out dlg.destroy() return else: #Ok, we're going to delete the user if filesDeleteCheckButton and filesDeleteCheckButton.get_active() == 1: #Let's delete the home directory too self.rmrf(homeDir) if os.access (mailSpool, os.W_OK) and os.lstat (mailSpool).st_uid == uid: self.rmrf(mailSpool) self.rmtmpfiles (("/tmp", "/var/tmp"), uid) self.ADMIN.deleteUser(userEnt) dlg.destroy() try: del self.user_dict[user] except: pass
need_refresh = [user] for group in self.group_dict.keys(): groupEnt = self.group_dict[group] members = groupEnt.get(libuser.MEMBERNAME)
if members: if user in members: members.remove(user) groupEnt.set(libuser.MEMBERNAME, members) self.ADMIN.modifyGroup(groupEnt)
self.userSelectedRow = None
#Let's check out the user's primary group groupEnt = self.ADMIN.lookupGroupById(userEnt.get(libuser.GIDNUMBER)[0]) if groupEnt != None and len(groupEnt.get(libuser.MEMBERNAME)) == 0: #Get the user's primary group. If there's no one besides that user in the group, #delete it.
if groupEnt.get(libuser.GIDNUMBER)[0] > 500: #Only delete the group if it is a non-system group self.ADMIN.deleteGroup(groupEnt) try: del self.group_dict[groupName] except: pass self.refresh_users_and_groups(need_refresh)
elif page == 1: if self.groupTreeView.get_selection().get_selected(): data, iter = self.groupTreeView.get_selection().get_selected() groupEnt = self.groupStore.get_value(iter, 3) groupName = groupEnt.get(libuser.GROUPNAME)[0]
#Let's check and see if we are deleting a user's primary group. We don't want that to happen members = self.ADMIN.enumerateUsersByGroup(groupName) for userName in members: userEnt = self.ADMIN.lookupUserByName(userName) if userEnt.get(libuser.GIDNUMBER)[0] == groupEnt.get(libuser.GIDNUMBER)[0]: messageDialog.show_message_dialog(_("You cannot remove user '%s' from their primary " "group.") % userName) return rc = messageDialog.show_confirm_dialog(_("Are you sure you want to delete the group '%s'?") % groupName) if rc == gtk.RESPONSE_NO: return self.ADMIN.deleteGroup(groupEnt) try: del self.group_dict[groupName] except: pass self.refresh_users_and_groups(groupName)
def on_properties_activate(self, *args): page = self.notebook.get_current_page() if page == 0: self.user_properties() elif page == 1: self.group_properties()
def on_preferences_activate (self, *args): self.prefWindow.show ()
def user_properties(self): if self.userTreeView.get_selection().get_selected(): data, iter = self.userTreeView.get_selection().get_selected() userEnt = self.userStore.get_value(iter, 6) self.userProperties.showUserProperties(userEnt) self.userProperties.userWin.set_transient_for(self.toplevel)
def group_properties(self): if self.groupTreeView.get_selection().get_selected(): data, iter = self.groupTreeView.get_selection().get_selected() groupEnt = self.groupStore.get_value(iter, 3) self.groupProperties.showGroupProperties(groupEnt) self.groupProperties.groupWin.set_transient_for(self.toplevel)
def itemSelected(self, *args): # When an item is selected, sensitize the properties and the delete buttons. # When an item is unselected, desensitize the properties and delete buttons. page = self.notebook.get_current_page()
if page == 0: object, data = self.userTreeView.get_selection().get_selected() elif page == 1: object, data = self.groupTreeView.get_selection().get_selected()
if data == None: self.toggleWidgets(False) else: self.toggleWidgets(True)
def changeNotebookPage(self, *args): # When the user changes a notebook page, unselect all the choices on both the user and group lists # This keeps the program from getting confused on which widget is currently selected page = self.notebook.get_current_page()
if page == 0: self.groupTreeView.get_selection().unselect_all() elif page == 1: self.userTreeView.get_selection().unselect_all()
self.toggleWidgets(False) def toggleWidgets(self, value): self.properties_button.set_sensitive(value) self.properties_menu.set_sensitive(value) self.delete_button.set_sensitive(value) self.delete_menu.set_sensitive(value) def get_filter_data(self): filter = self.filter.get_text() filter = string.strip(filter)
if len(filter) == 0: filter = '' else: index = string.find(filter, '*') length = len(filter) - 1
if index != length: filter = filter + "*" return filter
def on_filterSystemUsersGroupsCheckButton_toggled (self, *args): if self.filterSystemUsersGroupsCheckButton.get_active () == True: self.preferences['FILTER'] = True else: self.preferences['FILTER'] = False self.populate_lists()
def on_assignHighestUidCheckButton_toggled (self, *args): if self.assignHighestUidCheckButton.get_active () == True: self.preferences['ASSIGN_HIGHEST_UID'] = True else: self.preferences['ASSIGN_HIGHEST_UID'] = False
def on_assignHighestGidCheckButton_toggled (self, *args): if self.assignHighestGidCheckButton.get_active () == True: self.preferences['ASSIGN_HIGHEST_GID'] = True else: self.preferences['ASSIGN_HIGHEST_GID'] = False
def on_preferSameUIDGIDCheckButton_toggled (self, *args): if self.preferSameUIDGIDCheckButton.get_active () == True: self.preferences['PREFER_SAME_UID_GID'] = True else: self.preferences['PREFER_SAME_UID_GID'] = False def rmrf(self, path): if path != "/dev/null": #Don't allow /dev/null to be deleted # just use rm to avoid having to worry about races args = [ "/bin/rm", "-rf", "%s" %(path,) ] rhpl.executil.execWithRedirect(args[0], args)
def do_rm_userowned (self, path, uid): if os.path.isdir (path) and not os.path.islink (path): for file in os.listdir (path): self.do_rm_userowned (path + os.sep + file, uid) if os.lstat (path).st_uid == uid: try: os.rmdir (path) except OSError: pass else: if os.lstat (path).st_uid == uid: try: os.unlink (path) except OSError: pass
def rmtmpfiles (self, tmppaths, uid): for path in tmppaths: self.do_rm_userowned (path, uid) def rowActivated(self, *args): self.on_properties_activate()
def isSELinuxInstalled(self): ts = rpm.TransactionSet()
mi = ts.dbMatch('name', 'policy-sources') if mi.count() > 0: return 1 return 0
def isSELinuxEnabled(self): if self.isSELinuxInstalled(): if os.system("/usr/bin/selinuxenabled") > 0: #it's enabled, return 1 return 1 else: #it's installed, but not enabled return 0 else: #not installed return 0
|