Use non-interactive chfn, fix timeout (lp 1315709)
This commit is contained in:
parent
323ae84363
commit
14f9179fee
|
@ -335,8 +335,7 @@ class MugshotWindow(Window):
|
||||||
changes."""
|
changes."""
|
||||||
logger.debug('Applying changes...')
|
logger.debug('Applying changes...')
|
||||||
if self.get_chfn_details_updated():
|
if self.get_chfn_details_updated():
|
||||||
result = self.save_chfn_details()
|
if not self.save_chfn_details():
|
||||||
if result != [0, 0]:
|
|
||||||
# Password was incorrect, complain.
|
# Password was incorrect, complain.
|
||||||
primary = _("Authentication Failed")
|
primary = _("Authentication Failed")
|
||||||
secondary = _("User details were not updated.")
|
secondary = _("User details were not updated.")
|
||||||
|
@ -576,31 +575,44 @@ class MugshotWindow(Window):
|
||||||
logger.debug('chfn details have NOT been modified.')
|
logger.debug('chfn details have NOT been modified.')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def process_terminal_password(self, command, password):
|
||||||
|
"""Handle password prompts from the interactive chfn commands."""
|
||||||
|
# Force the C language for guaranteed english strings in the script.
|
||||||
|
logger.debug('Executing: %s' % command)
|
||||||
|
child = pexpect.spawn(command, env={"LANG": "C"})
|
||||||
|
child.timeout = 5
|
||||||
|
child.write_to_stdout = True
|
||||||
|
try:
|
||||||
|
child.expect([".*ssword.*", pexpect.EOF])
|
||||||
|
child.sendline(password)
|
||||||
|
child.expect([pexpect.EOF])
|
||||||
|
except pexpect.TIMEOUT:
|
||||||
|
logger.warning('Timeout reached, password was likely incorrect.')
|
||||||
|
child.close(True)
|
||||||
|
return child.exitstatus == 0
|
||||||
|
|
||||||
def save_chfn_details(self):
|
def save_chfn_details(self):
|
||||||
"""Commit changes to chfn-related details. For full name, changes must
|
"""Commit changes to chfn-related details. For full name, changes must
|
||||||
be performed as root. Other changes are done with the user password.
|
be performed as root. Other changes are done with the user password.
|
||||||
|
|
||||||
Return exit codes for 1) full name changes and 2) home/work phone
|
Return TRUE if successful."""
|
||||||
changes.
|
success = True
|
||||||
|
|
||||||
e.g. [0, 0] (both passed)"""
|
|
||||||
return_codes = []
|
|
||||||
|
|
||||||
# Get the password for sudo
|
# Get the password for sudo
|
||||||
sudo_dialog = SudoDialog.SudoDialog(
|
sudo_dialog = SudoDialog.SudoDialog(
|
||||||
icon=None, name=_("Mugshot"), retries=3)
|
icon=None, name=_("Mugshot"), retries=3)
|
||||||
sudo_dialog.format_primary_text(_("Enter your password to change user "
|
sudo_dialog.format_primary_text(_("Enter your password to change user "
|
||||||
"details."))
|
"details."))
|
||||||
sudo_dialog.format_secondary_text(_("This is a security measure to "
|
sudo_dialog.format_secondary_text(_("This is a security measure to "
|
||||||
"prevent unwanted updates\n"
|
"prevent unwanted updates\n"
|
||||||
"to your personal information."))
|
"to your personal information."))
|
||||||
sudo_dialog.run()
|
sudo_dialog.run()
|
||||||
sudo_dialog.hide()
|
sudo_dialog.hide()
|
||||||
password = sudo_dialog.get_password()
|
password = sudo_dialog.get_password()
|
||||||
sudo_dialog.destroy()
|
sudo_dialog.destroy()
|
||||||
|
|
||||||
if not password:
|
if not password:
|
||||||
return return_codes
|
return False
|
||||||
|
|
||||||
sudo = which('sudo')
|
sudo = which('sudo')
|
||||||
chfn = which('chfn')
|
chfn = which('chfn')
|
||||||
|
@ -619,52 +631,29 @@ class MugshotWindow(Window):
|
||||||
|
|
||||||
# Full name can only be modified by root. Try using sudo to modify.
|
# Full name can only be modified by root. Try using sudo to modify.
|
||||||
if SudoDialog.check_sudo():
|
if SudoDialog.check_sudo():
|
||||||
logger.debug('Attempting to set fullname with sudo chfn')
|
logger.debug('Updating Full Name...')
|
||||||
# Force the C language for guaranteed english strings in the script.
|
command = "%s %s -f \"%s\" %s" % (sudo, chfn, full_name, username)
|
||||||
child = pexpect.spawn('%s %s %s' % (sudo, chfn, username),
|
if self.process_terminal_password(command, password):
|
||||||
env={"LANG": "C"})
|
|
||||||
child.timeout = 5
|
|
||||||
try:
|
|
||||||
child.expect([".*ssword.*", pexpect.EOF])
|
|
||||||
child.sendline(password)
|
|
||||||
child.expect(".*ame.*:")
|
|
||||||
child.sendline(full_name)
|
|
||||||
for i in range(5):
|
|
||||||
child.sendline('')
|
|
||||||
except pexpect.TIMEOUT:
|
|
||||||
# Password was incorrect, or sudo rights not granted
|
|
||||||
logger.warning('Timeout reached, password was incorrect or '
|
|
||||||
'sudo rights not granted.')
|
|
||||||
pass
|
|
||||||
child.close()
|
|
||||||
if child.exitstatus == 0:
|
|
||||||
self.first_name = first_name
|
self.first_name = first_name
|
||||||
self.last_name = last_name
|
self.last_name = last_name
|
||||||
return_codes.append(child.exitstatus)
|
else:
|
||||||
else:
|
success = False
|
||||||
return_codes.append(0)
|
|
||||||
|
|
||||||
logger.debug('Attempting to set user details with chfn')
|
logger.debug('Updating Home Phone...')
|
||||||
child = pexpect.spawn(chfn, env={"LANG": "C"})
|
command = "%s -h \"%s\" %s" % (chfn, home_phone, username)
|
||||||
child.timeout = 5
|
if self.process_terminal_password(command, password):
|
||||||
try:
|
|
||||||
child.expect([".*ssword.*", pexpect.EOF])
|
|
||||||
child.sendline(password)
|
|
||||||
child.expect(['Room Number.*:', 'Office.*:'])
|
|
||||||
child.sendline('')
|
|
||||||
child.expect(['Work Phone.*:', 'Office Phone.*:'])
|
|
||||||
child.sendline(office_phone)
|
|
||||||
child.expect('Home Phone.*:')
|
|
||||||
child.sendline(home_phone)
|
|
||||||
child.sendline(home_phone)
|
|
||||||
except pexpect.TIMEOUT:
|
|
||||||
logger.warning('Timeout reached, password was likely incorrect.')
|
|
||||||
child.close(True)
|
|
||||||
if child.exitstatus == 0:
|
|
||||||
self.office_phone = office_phone
|
|
||||||
self.home_phone = home_phone
|
self.home_phone = home_phone
|
||||||
return_codes.append(child.exitstatus)
|
else:
|
||||||
return return_codes
|
success = False
|
||||||
|
|
||||||
|
logger.debug('Updating Office Phone...')
|
||||||
|
command = "%s -w \"%s\" %s" % (chfn, office_phone, username)
|
||||||
|
if self.process_terminal_password(command, password):
|
||||||
|
self.office_phone = office_phone
|
||||||
|
else:
|
||||||
|
success = False
|
||||||
|
|
||||||
|
return success
|
||||||
|
|
||||||
# = LibreOffice ========================================================= #
|
# = LibreOffice ========================================================= #
|
||||||
def get_libreoffice_details_updated(self):
|
def get_libreoffice_details_updated(self):
|
||||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2014-05-14 07:11-0400\n"
|
"POT-Creation-Date: 2014-05-14 20:43-0400\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
@ -61,7 +61,7 @@ msgstr ""
|
||||||
msgid "Browse…"
|
msgid "Browse…"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../data/ui/MugshotWindow.ui.h:9 ../mugshot/MugshotWindow.py:591
|
#: ../data/ui/MugshotWindow.ui.h:9 ../mugshot/MugshotWindow.py:603
|
||||||
msgid "Mugshot"
|
msgid "Mugshot"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -131,37 +131,37 @@ msgid "Retry"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#. Password was incorrect, complain.
|
#. Password was incorrect, complain.
|
||||||
#: ../mugshot/MugshotWindow.py:341
|
#: ../mugshot/MugshotWindow.py:340
|
||||||
msgid "Authentication Failed"
|
msgid "Authentication Failed"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../mugshot/MugshotWindow.py:342
|
#: ../mugshot/MugshotWindow.py:341
|
||||||
msgid "User details were not updated."
|
msgid "User details were not updated."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../mugshot/MugshotWindow.py:513
|
#: ../mugshot/MugshotWindow.py:512
|
||||||
msgid "Update Pidgin buddy icon?"
|
msgid "Update Pidgin buddy icon?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../mugshot/MugshotWindow.py:514
|
#: ../mugshot/MugshotWindow.py:513
|
||||||
msgid "Would you also like to update your Pidgin buddy icon?"
|
msgid "Would you also like to update your Pidgin buddy icon?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../mugshot/MugshotWindow.py:592
|
#: ../mugshot/MugshotWindow.py:604
|
||||||
msgid "Enter your password to change user details."
|
msgid "Enter your password to change user details."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../mugshot/MugshotWindow.py:594
|
#: ../mugshot/MugshotWindow.py:606
|
||||||
msgid ""
|
msgid ""
|
||||||
"This is a security measure to prevent unwanted updates\n"
|
"This is a security measure to prevent unwanted updates\n"
|
||||||
"to your personal information."
|
"to your personal information."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../mugshot/MugshotWindow.py:745
|
#: ../mugshot/MugshotWindow.py:734
|
||||||
msgid "Update LibreOffice user details?"
|
msgid "Update LibreOffice user details?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../mugshot/MugshotWindow.py:746
|
#: ../mugshot/MugshotWindow.py:735
|
||||||
msgid "Would you also like to update your user details in LibreOffice?"
|
msgid "Would you also like to update your user details in LibreOffice?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue