summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2009-05-26 16:49:13 -0400
committerRob Crittenden <rcritten@redhat.com>2009-07-10 16:47:35 -0400
commitc0b6a780409b5dc1c4c30d6bed2ec70ada951d4c (patch)
tree2567c5c9e7401ff145241618ac8df83e537b3789 /ipalib
parentd6e1e15fcd6eb924320fdb8f3d8138aba9eae0c3 (diff)
downloadfreeipa-c0b6a780409b5dc1c4c30d6bed2ec70ada951d4c.tar.gz
freeipa-c0b6a780409b5dc1c4c30d6bed2ec70ada951d4c.tar.xz
freeipa-c0b6a780409b5dc1c4c30d6bed2ec70ada951d4c.zip
Require a password only once when it is passed in via a pipe
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/cli.py34
1 files changed, 13 insertions, 21 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index d1052370..00e32847 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -393,31 +393,23 @@ 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.
+ Prompt user for a password or read it in via stdin depending
+ on whether there is a tty or not.
"""
try:
- while True:
- pw1 = self.read_password('%s: ' % label)
- pw2 = self.read_password(
- _('Enter %(label)s again to verify: ') % dict(label=label)
- )
- if pw1 == pw2:
- return self.decode(pw1)
- self.print_error( _('Passwords do not match!'))
+ if sys.stdin.isatty():
+ while True:
+ pw1 = getpass.getpass('%s: ' % label)
+ pw2 = getpass.getpass(
+ _('Enter %(label)s again to verify: ') % dict(label=label)
+ )
+ if pw1 == pw2:
+ return self.decode(pw1)
+ self.print_error( _('Passwords do not match!'))
+ else:
+ return self.decode(sys.stdin.readline().strip())
except KeyboardInterrupt:
print ''
self.print_error(_('Cancelled.'))