mirror of
https://github.com/sudo-project/sudo.git
synced 2025-09-04 00:05:11 +00:00
the prompt is expanded before tgetpass is called
This commit is contained in:
31
tgetpass.c
31
tgetpass.c
@@ -95,11 +95,9 @@ static char rcsid[] = "$Id$";
|
|||||||
* and input will time out based on the value of timeout.
|
* and input will time out based on the value of timeout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char * tgetpass(prompt, timeout, user, host)
|
char * tgetpass(prompt, timeout)
|
||||||
const char *prompt;
|
const char *prompt;
|
||||||
int timeout;
|
int timeout;
|
||||||
char *user;
|
|
||||||
char *host;
|
|
||||||
{
|
{
|
||||||
#ifdef HAVE_TERMIOS_H
|
#ifdef HAVE_TERMIOS_H
|
||||||
struct termios term;
|
struct termios term;
|
||||||
@@ -121,7 +119,6 @@ char * tgetpass(prompt, timeout, user, host)
|
|||||||
static char buf[_PASSWD_LEN + 1];
|
static char buf[_PASSWD_LEN + 1];
|
||||||
fd_set *readfds;
|
fd_set *readfds;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
char *p;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* mask out SIGINT and SIGTSTP, should probably just catch and deal.
|
* mask out SIGINT and SIGTSTP, should probably just catch and deal.
|
||||||
@@ -144,30 +141,12 @@ char * tgetpass(prompt, timeout, user, host)
|
|||||||
output = stderr;
|
output = stderr;
|
||||||
} else {
|
} else {
|
||||||
output = input;
|
output = input;
|
||||||
|
setbuf(output, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* print the prompt */
|
||||||
* print the prompt
|
if (prompt)
|
||||||
*/
|
fputs(prompt, output);
|
||||||
if (prompt) {
|
|
||||||
p = (char *) prompt;
|
|
||||||
do {
|
|
||||||
/* expand %u -> username, %h -> host */
|
|
||||||
switch (*p) {
|
|
||||||
case '%': if (user && *(p+1) == 'u') {
|
|
||||||
(void) fputs(user, output);
|
|
||||||
p++;
|
|
||||||
break;
|
|
||||||
} else if (host && *(p+1) == 'h') {
|
|
||||||
(void) fputs(host, output);
|
|
||||||
p++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: (void) fputc(*p, output);
|
|
||||||
}
|
|
||||||
} while (*(++p));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* rewind if necesary */
|
/* rewind if necesary */
|
||||||
if (input == output) {
|
if (input == output) {
|
||||||
|
Reference in New Issue
Block a user