mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
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
This commit is contained in:
parent
7f366d745c
commit
ca0d38596d
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user