summaryrefslogtreecommitdiff
path: root/lib/util/getpass.c
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-04-04 15:55:10 +0200
committerAlexander Bokovoy <ab@samba.org>2013-04-05 07:34:37 +0200
commitca0d38596d711e70a1d58657024aabd8c131512b (patch)
tree9a35623e78261a2d21a872bb2ae46961990da814 /lib/util/getpass.c
parent7f366d745c1d4e833470d853ec484459157616e7 (diff)
downloadsamba-ca0d38596d711e70a1d58657024aabd8c131512b.tar.gz
samba-ca0d38596d711e70a1d58657024aabd8c131512b.tar.bz2
samba-ca0d38596d711e70a1d58657024aabd8c131512b.zip
getpass: Don't fail if stdin is not a tty
We don't need to manipulate the tty state (such as turning off echo) when prompting for passwords if we're not reading from a tty. Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Alexander Bokovoy <ab@samba.org> Autobuild-User(master): Alexander Bokovoy <ab@samba.org> Autobuild-Date(master): Fri Apr 5 07:34:37 CEST 2013 on sn-devel-104
Diffstat (limited to 'lib/util/getpass.c')
-rw-r--r--lib/util/getpass.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/lib/util/getpass.c b/lib/util/getpass.c
index 480bd56898..0cbc7dd253 100644
--- a/lib/util/getpass.c
+++ b/lib/util/getpass.c
@@ -170,31 +170,34 @@ int samba_getpass(const char *prompt,
return -1;
}
- ZERO_STRUCT(attr);
- ZERO_STRUCT(old_attr);
+ if (isatty (STDIN_FILENO)) {
- /* get local terminal attributes */
- if (tcgetattr(STDIN_FILENO, &attr) < 0) {
- perror("tcgetattr");
- return -1;
- }
+ ZERO_STRUCT(attr);
+ ZERO_STRUCT(old_attr);
- /* save terminal attributes */
- memcpy(&old_attr, &attr, sizeof(attr));
- if((fd = fcntl(0, F_GETFL, 0)) < 0) {
- perror("fcntl");
- return -1;
- }
+ /* get local terminal attributes */
+ if (tcgetattr(STDIN_FILENO, &attr) < 0) {
+ perror("tcgetattr");
+ return -1;
+ }
- /* disable echo */
- if (!echo) {
- attr.c_lflag &= ~(ECHO);
- }
+ /* save terminal attributes */
+ memcpy(&old_attr, &attr, sizeof(attr));
+ if((fd = fcntl(0, F_GETFL, 0)) < 0) {
+ perror("fcntl");
+ return -1;
+ }
- /* write attributes to terminal */
- if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) < 0) {
- perror("tcsetattr");
- return -1;
+ /* disable echo */
+ if (!echo) {
+ attr.c_lflag &= ~(ECHO);
+ }
+
+ /* write attributes to terminal */
+ if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) < 0) {
+ perror("tcsetattr");
+ return -1;
+ }
}
/* disable nonblocking I/O */
@@ -204,8 +207,11 @@ int samba_getpass(const char *prompt,
ok = samba_gets(prompt, buf, len, verify);
- /* reset terminal */
- tcsetattr(STDIN_FILENO, TCSANOW, &old_attr);
+ if (isatty (STDIN_FILENO)) {
+
+ /* reset terminal */
+ tcsetattr(STDIN_FILENO, TCSANOW, &old_attr);
+ }
/* close fd */
if (fd & O_NDELAY) {