summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2009-04-30 15:06:25 -0400
committerRob Crittenden <rcritten@redhat.com>2009-05-04 17:43:14 -0400
commita7a16272b124b127ac964f128d39bcb59a7f5714 (patch)
tree2edffce867bbeae51050aa007ea10fee2ab43c10
parentd4076915cd8f5c0ed7dc430f6f91ff059b4d7a35 (diff)
downloadfreeipa-a7a16272b124b127ac964f128d39bcb59a7f5714.tar.gz
freeipa-a7a16272b124b127ac964f128d39bcb59a7f5714.tar.xz
freeipa-a7a16272b124b127ac964f128d39bcb59a7f5714.zip
When reading a password, if there is no tty, read from stdin instead.
This will allow one to pipe a password in: echo -e "secret123\secret123\n" | ipa password someuser
-rw-r--r--ipalib/cli.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 1e77657d3..362da18ef 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -393,14 +393,26 @@ class textui(backend.Backend):
raw_input(self.encode(prompt))
)
+ def read_password(self, label):
+ """
+ Read a password either by prompting the user or from stdin depending
+ on whether there is a tty.
+
+ This will let you do something like: echo -e "foo\nfoo\n" | ipa passwd
+ """
+ if sys.stdin.isatty():
+ return getpass.getpass(label)
+ else:
+ return sys.stdin.readline().strip()
+
def prompt_password(self, label):
"""
Prompt user for a password.
"""
try:
while True:
- pw1 = getpass.getpass('%s: ' % label)
- pw2 = getpass.getpass(
+ pw1 = self.read_password('%s: ' % label)
+ pw2 = self.read_password(
_('Enter %(label)s again to verify: ') % dict(label=label)
)
if pw1 == pw2: