diff options
author | Stephen Gallagher <sgallagh@redhat.com> | 2011-03-24 10:54:34 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2011-03-25 09:08:57 -0400 |
commit | 3bc158bf98ff5e8aee6923ce86647b5566f8ff20 (patch) | |
tree | 719a23ca37db7713edc205abc273b5fa4ba54c95 /src | |
parent | 0fb5e92cec8734b77b9051f74fb05be45bcafff2 (diff) | |
download | sssd_unused-3bc158bf98ff5e8aee6923ce86647b5566f8ff20.tar.gz sssd_unused-3bc158bf98ff5e8aee6923ce86647b5566f8ff20.tar.xz sssd_unused-3bc158bf98ff5e8aee6923ce86647b5566f8ff20.zip |
sss_obfuscate: Avoid traceback on ctrl+d
sss_obfuscate: abort on ctrl+c
There is a python bug (http://bugs.python.org/issue11236) where
getpass.getpass() does not throw KeyboardInterrupt on ctrl+c. This
workaround is the closest we can get: if we detect the control
character in the string that we read, we'll cancel.
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/sss_obfuscate | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/tools/sss_obfuscate b/src/tools/sss_obfuscate index 506e2c41..fbea1213 100644 --- a/src/tools/sss_obfuscate +++ b/src/tools/sss_obfuscate @@ -41,12 +41,28 @@ def main(): return 1 if not options.stdin: - pprompt = lambda: (getpass.getpass("Enter password: "), getpass.getpass("Re-enter password: ")) - p1, p2 = pprompt() - while p1 != p2: - print('Passwords do not match. Try again') + try: + pprompt = lambda: (getpass.getpass("Enter password: "), getpass.getpass("Re-enter password: ")) p1, p2 = pprompt() - password = p1 + + #Work around bug in Python 2.6 + if '\x03' in p1 or '\x03' in p2: + raise KeyboardInterrupt + + while p1 != p2: + print('Passwords do not match. Try again') + p1, p2 = pprompt() + + #Work around bug in Python 2.6 + if '\x03' in p1 or '\x03' in p2: + raise KeyboardInterrupt + password = p1 + + except EOFError: + print >> sys.stderr, '\nUnexpected end-of-file. Password change aborted' + return 1 + except KeyboardInterrupt: + return 1 else: try: |