version 1.111, 2001/10/01 21:51:16 |
version 1.112, 2001/10/06 00:14:50 |
|
|
|
|
/* defaults to 'no' */ |
/* defaults to 'no' */ |
static int |
static int |
read_yes_or_no(const char *prompt, int defval) |
confirm(const char *prompt) |
{ |
{ |
char buf[1024]; |
char buf[1024]; |
FILE *f; |
FILE *f; |
|
|
|
|
if (options.batch_mode) |
if (options.batch_mode) |
return 0; |
return 0; |
|
|
if (isatty(STDIN_FILENO)) |
if (isatty(STDIN_FILENO)) |
f = stdin; |
f = stdin; |
else |
else |
f = fopen(_PATH_TTY, "rw"); |
f = fopen(_PATH_TTY, "rw"); |
|
|
if (f == NULL) |
if (f == NULL) |
return 0; |
return 0; |
|
|
fflush(stdout); |
fflush(stdout); |
|
|
while (1) { |
while (1) { |
fprintf(stderr, "%s", prompt); |
fprintf(stderr, "%s", prompt); |
if (fgets(buf, sizeof(buf), f) == NULL) { |
if (fgets(buf, sizeof(buf), f) == NULL) { |
/* |
|
* Print a newline (the prompt probably didn\'t have |
|
* one). |
|
*/ |
|
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
strlcpy(buf, "no", sizeof buf); |
strlcpy(buf, "no", sizeof buf); |
} |
} |
/* Remove newline from response. */ |
/* Remove newline from response. */ |
if (strchr(buf, '\n')) |
if (strchr(buf, '\n')) |
*strchr(buf, '\n') = 0; |
*strchr(buf, '\n') = 0; |
|
|
if (buf[0] == 0) |
|
retval = defval; |
|
if (strcmp(buf, "yes") == 0) |
if (strcmp(buf, "yes") == 0) |
retval = 1; |
retval = 1; |
else if (strcmp(buf, "no") == 0) |
else if (strcmp(buf, "no") == 0) |
|
|
"Are you sure you want to continue connecting " |
"Are you sure you want to continue connecting " |
"(yes/no)? ", host, ip, type, fp); |
"(yes/no)? ", host, ip, type, fp); |
xfree(fp); |
xfree(fp); |
if (!read_yes_or_no(prompt, -1)) { |
if (!confirm(prompt)) { |
log("Aborted by user!"); |
log("Aborted by user!"); |
goto fail; |
goto fail; |
} |
} |
|
|
error("Exiting, you have requested strict checking."); |
error("Exiting, you have requested strict checking."); |
goto fail; |
goto fail; |
} else if (options.strict_host_key_checking == 2) { |
} else if (options.strict_host_key_checking == 2) { |
if (!read_yes_or_no("Are you sure you want " |
if (!confirm("Are you sure you want " |
"to continue connecting (yes/no)? ", -1)) { |
"to continue connecting (yes/no)? ")) { |
log("Aborted by user!"); |
log("Aborted by user!"); |
goto fail; |
goto fail; |
} |
} |