Install tools crash when password prompt is interrupted

When getpass.getpass() function is interrupted via CTRL+D, EOFError
exception is thrown. Most of the install tools are not prepared for
this event and crash with this exception. Make sure that it is
handled properly and nice error message is printed.

https://fedorahosted.org/freeipa/ticket/1916
This commit is contained in:
Martin Kosek
2011-10-06 08:22:08 +02:00
parent 7d5106de97
commit 185ca8f6fc
15 changed files with 81 additions and 34 deletions

View File

@@ -319,30 +319,33 @@ def _read_password_default_validator(password):
def read_password(user, confirm=True, validate=True, retry=True, validator=_read_password_default_validator):
correct = False
pwd = ""
while not correct:
if not retry:
correct = True
pwd = get_password(user + " password: ")
if not pwd:
continue
if validate:
try:
validator(pwd)
except ValueError, e:
print str(e)
pwd = ""
pwd = None
try:
while not correct:
if not retry:
correct = True
pwd = get_password(user + " password: ")
if not pwd:
continue
if not confirm:
correct = True
continue
pwd_confirm = get_password("Password (confirm): ")
if pwd != pwd_confirm:
print "Password mismatch!"
print ""
pwd = ""
else:
correct = True
if validate:
try:
validator(pwd)
except ValueError, e:
print str(e)
pwd = None
continue
if not confirm:
correct = True
continue
pwd_confirm = get_password("Password (confirm): ")
if pwd != pwd_confirm:
print "Password mismatch!"
print ""
pwd = None
else:
correct = True
except EOFError:
return None
print ""
return pwd