diff options
author | Rob Crittenden <rcritten@redhat.com> | 2008-09-12 20:34:25 -0400 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2008-09-17 20:56:03 -0400 |
commit | aa8c4a53bf149aa0e9adfdf2058925eb71cca61b (patch) | |
tree | 9b64e17e4147a11673c8f85323bf2029e5cf61bb | |
parent | 661dee8c030e387002e031d4cdef781e2e8f4cf5 (diff) | |
download | freeipa-aa8c4a53bf149aa0e9adfdf2058925eb71cca61b.tar.gz freeipa-aa8c4a53bf149aa0e9adfdf2058925eb71cca61b.tar.xz freeipa-aa8c4a53bf149aa0e9adfdf2058925eb71cca61b.zip |
Allow passwords to work without a tty ala: echo password | some_program
-rw-r--r-- | ipa-server/ipaserver/installutils.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ipa-server/ipaserver/installutils.py b/ipa-server/ipaserver/installutils.py index 674cf7d04..90e1c6ab6 100644 --- a/ipa-server/ipaserver/installutils.py +++ b/ipa-server/ipaserver/installutils.py @@ -163,11 +163,17 @@ def standard_logging_setup(log_filename, debug=False): console.setFormatter(formatter) logging.getLogger('').addHandler(console) +def get_password(prompt): + if os.isatty(sys.stdin.fileno()): + return getpass.getpass(prompt) + else: + return sys.stdin.readline().rstrip() + def read_password(user, confirm=True, validate=True): correct = False pwd = "" while not correct: - pwd = getpass.getpass(user + " password: ") + pwd = get_password(user + " password: ") if not pwd: continue if validate and len(pwd) < 8: @@ -176,7 +182,7 @@ def read_password(user, confirm=True, validate=True): if not confirm: correct = True continue - pwd_confirm = getpass.getpass("Password (confirm): ") + pwd_confirm = get_password("Password (confirm): ") if pwd != pwd_confirm: print "Password mismatch!" print "" |