From aa8c4a53bf149aa0e9adfdf2058925eb71cca61b Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Fri, 12 Sep 2008 20:34:25 -0400 Subject: Allow passwords to work without a tty ala: echo password | some_program --- ipa-server/ipaserver/installutils.py | 10 ++++++++-- 1 file 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 "" -- cgit