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."""
|
||||
logger.debug('Applying changes...')
|
||||
if self.get_chfn_details_updated():
|
||||
result = self.save_chfn_details()
|
||||
if result != [0, 0]:
|
||||
if not self.save_chfn_details():
|
||||
# Password was incorrect, complain.
|
||||
primary = _("Authentication Failed")
|
||||
secondary = _("User details were not updated.")
|
||||
|
@ -576,15 +575,28 @@ class MugshotWindow(Window):
|
|||
logger.debug('chfn details have NOT been modified.')
|
||||
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):
|
||||
"""Commit changes to chfn-related details. For full name, changes must
|
||||
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
|
||||
changes.
|
||||
|
||||
e.g. [0, 0] (both passed)"""
|
||||
return_codes = []
|
||||
Return TRUE if successful."""
|
||||
success = True
|
||||
|
||||
# Get the password for sudo
|
||||
sudo_dialog = SudoDialog.SudoDialog(
|
||||
|
@ -600,7 +612,7 @@ class MugshotWindow(Window):
|
|||
sudo_dialog.destroy()
|
||||
|
||||
if not password:
|
||||
return return_codes
|
||||
return False
|
||||
|
||||
sudo = which('sudo')
|
||||
chfn = which('chfn')
|
||||
|
@ -619,52 +631,29 @@ class MugshotWindow(Window):
|
|||
|
||||
# Full name can only be modified by root. Try using sudo to modify.
|
||||
if SudoDialog.check_sudo():
|
||||
logger.debug('Attempting to set fullname with sudo chfn')
|
||||
# Force the C language for guaranteed english strings in the script.
|
||||
child = pexpect.spawn('%s %s %s' % (sudo, chfn, username),
|
||||
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:
|
||||
logger.debug('Updating Full Name...')
|
||||
command = "%s %s -f \"%s\" %s" % (sudo, chfn, full_name, username)
|
||||
if self.process_terminal_password(command, password):
|
||||
self.first_name = first_name
|
||||
self.last_name = last_name
|
||||
return_codes.append(child.exitstatus)
|
||||
else:
|
||||
return_codes.append(0)
|
||||
success = False
|
||||
|
||||
logger.debug('Attempting to set user details with chfn')
|
||||
child = pexpect.spawn(chfn, env={"LANG": "C"})
|
||||
child.timeout = 5
|
||||
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
|
||||
logger.debug('Updating Home Phone...')
|
||||
command = "%s -h \"%s\" %s" % (chfn, home_phone, username)
|
||||
if self.process_terminal_password(command, password):
|
||||
self.home_phone = home_phone
|
||||
return_codes.append(child.exitstatus)
|
||||
return return_codes
|
||||
else:
|
||||
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 ========================================================= #
|
||||
def get_libreoffice_details_updated(self):
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\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"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -61,7 +61,7 @@ msgstr ""
|
|||
msgid "Browse…"
|
||||
msgstr ""
|
||||
|
||||
#: ../data/ui/MugshotWindow.ui.h:9 ../mugshot/MugshotWindow.py:591
|
||||
#: ../data/ui/MugshotWindow.ui.h:9 ../mugshot/MugshotWindow.py:603
|
||||
msgid "Mugshot"
|
||||
msgstr ""
|
||||
|
||||
|
@ -131,37 +131,37 @@ msgid "Retry"
|
|||
msgstr ""
|
||||
|
||||
#. Password was incorrect, complain.
|
||||
#: ../mugshot/MugshotWindow.py:341
|
||||
#: ../mugshot/MugshotWindow.py:340
|
||||
msgid "Authentication Failed"
|
||||
msgstr ""
|
||||
|
||||
#: ../mugshot/MugshotWindow.py:342
|
||||
#: ../mugshot/MugshotWindow.py:341
|
||||
msgid "User details were not updated."
|
||||
msgstr ""
|
||||
|
||||
#: ../mugshot/MugshotWindow.py:513
|
||||
#: ../mugshot/MugshotWindow.py:512
|
||||
msgid "Update Pidgin buddy icon?"
|
||||
msgstr ""
|
||||
|
||||
#: ../mugshot/MugshotWindow.py:514
|
||||
#: ../mugshot/MugshotWindow.py:513
|
||||
msgid "Would you also like to update your Pidgin buddy icon?"
|
||||
msgstr ""
|
||||
|
||||
#: ../mugshot/MugshotWindow.py:592
|
||||
#: ../mugshot/MugshotWindow.py:604
|
||||
msgid "Enter your password to change user details."
|
||||
msgstr ""
|
||||
|
||||
#: ../mugshot/MugshotWindow.py:594
|
||||
#: ../mugshot/MugshotWindow.py:606
|
||||
msgid ""
|
||||
"This is a security measure to prevent unwanted updates\n"
|
||||
"to your personal information."
|
||||
msgstr ""
|
||||
|
||||
#: ../mugshot/MugshotWindow.py:745
|
||||
#: ../mugshot/MugshotWindow.py:734
|
||||
msgid "Update LibreOffice user details?"
|
||||
msgstr ""
|
||||
|
||||
#: ../mugshot/MugshotWindow.py:746
|
||||
#: ../mugshot/MugshotWindow.py:735
|
||||
msgid "Would you also like to update your user details in LibreOffice?"
|
||||
msgstr ""
|
||||
|
||||
|
|
Loading…
Reference in New Issue