diff options
author | Stephen Gallagher <sgallagh@redhat.com> | 2011-01-17 10:31:52 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2011-01-17 12:19:00 -0500 |
commit | 8d00718b943ab8b326320feb50820f0663031817 (patch) | |
tree | 99e146fae31ee1c2670d54702a4e7877b74ab4e1 /src/tools | |
parent | c99f4a333122a3c56f6843f08607de4ead6d780a (diff) | |
download | sssd-8d00718b943ab8b326320feb50820f0663031817.tar.gz sssd-8d00718b943ab8b326320feb50820f0663031817.tar.bz2 sssd-8d00718b943ab8b326320feb50820f0663031817.zip |
Fix usability of sss_obfuscate command
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/sss_obfuscate | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/tools/sss_obfuscate b/src/tools/sss_obfuscate index 220cd9be..cd911615 100644 --- a/src/tools/sss_obfuscate +++ b/src/tools/sss_obfuscate @@ -5,12 +5,19 @@ from optparse import OptionParser import pysss import SSSDConfig +import getpass def parse_options(): parser = OptionParser() + parser.set_description("sss_obfuscate converts a given password into \ + human-unreadable format and places it into \ + appropriate domain section of the SSSD config \ + file. The password can be passed in by stdin, \ + specified on the command-line or entered \ + interactively") parser.add_option("-s", "--stdin", action="store_true", dest="stdin", default=False, - help="Read input from stdin") + help="Read the password from stdin.") parser.add_option("-d", "--domain", dest="domain", default="default", help="The domain to use the password in (default: default)", @@ -19,26 +26,28 @@ def parse_options(): dest="filename", default=None, help="Set input file to FILE (default: Use system default, usually /etc/sssd/sssd.conf)", metavar="FILE") + parser.add_option("-p", "--password", + dest="password", default=None, + help="Password to obfuscate.", + metavar="PASSWORD") (options, args) = parser.parse_args() - # If no password given as positional paramater, read up from stdin - if len(args) == 0: - options.stdin = True - return options, args def main(): options, args = parse_options() if not options: - print >>sys.stderr, "Cannot parse options" + print >> sys.stderr, "Cannot parse options" return 1 - if not options.stdin: - try: - password = args[0] - except IndexError: # should never happen - print "Missing password parameter!" - return 1 + if not options.stdin and not options.password: + pprompt = lambda: (getpass.getpass("Enter password: "), getpass.getpass("Re-enter password: ")) + p1, p2 = pprompt() + while p1 != p2: + print('Passwords do not match. Try again') + p1, p2 = pprompt() + password = p1 + else: try: password = sys.stdin.read() |