version 1.104.2.1, 2001/09/27 19:03:55 |
version 1.104.2.2, 2001/11/15 00:15:19 |
|
|
extern Options options; |
extern Options options; |
extern char *__progname; |
extern char *__progname; |
|
|
/* AF_UNSPEC or AF_INET or AF_INET6 */ |
|
extern int IPv4or6; |
|
|
|
static const char * |
static const char * |
sockaddr_ntop(struct sockaddr *sa) |
sockaddr_ntop(struct sockaddr *sa) |
{ |
{ |
|
|
return sock; |
return sock; |
|
|
memset(&hints, 0, sizeof(hints)); |
memset(&hints, 0, sizeof(hints)); |
hints.ai_family = IPv4or6; |
hints.ai_family = family; |
hints.ai_socktype = SOCK_STREAM; |
hints.ai_socktype = SOCK_STREAM; |
hints.ai_flags = AI_PASSIVE; |
hints.ai_flags = AI_PASSIVE; |
gaierr = getaddrinfo(options.bind_address, "0", &hints, &res); |
gaierr = getaddrinfo(options.bind_address, "0", &hints, &res); |
|
|
*/ |
*/ |
int |
int |
ssh_connect(const char *host, struct sockaddr_storage * hostaddr, |
ssh_connect(const char *host, struct sockaddr_storage * hostaddr, |
u_short port, int connection_attempts, |
u_short port, int family, int connection_attempts, |
int anonymous, struct passwd *pw, |
int anonymous, struct passwd *pw, const char *proxy_command) |
const char *proxy_command) |
|
{ |
{ |
int gaierr; |
int gaierr; |
int on = 1; |
int on = 1; |
|
|
/* No proxy command. */ |
/* No proxy command. */ |
|
|
memset(&hints, 0, sizeof(hints)); |
memset(&hints, 0, sizeof(hints)); |
hints.ai_family = IPv4or6; |
hints.ai_family = family; |
hints.ai_socktype = SOCK_STREAM; |
hints.ai_socktype = SOCK_STREAM; |
snprintf(strport, sizeof strport, "%d", port); |
snprintf(strport, sizeof strport, "%d", port); |
if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0) |
if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0) |
|
|
|
|
/* 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); |
|
fprintf(stderr, "%s", prompt); |
while (1) { |
while (1) { |
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) |
retval = 0; |
retval = 0; |
else |
else |
fprintf(stderr, "Please type 'yes' or 'no'.\n"); |
fprintf(stderr, "Please type 'yes' or 'no': "); |
|
|
if (retval != -1) { |
if (retval != -1) { |
if (f != stdin) |
if (f != stdin) |
|
|
local = 0; |
local = 0; |
break; |
break; |
} |
} |
if (local && options.host_key_alias == NULL) { |
if (options.no_host_authentication_for_localhost == 1 && local && |
|
options.host_key_alias == NULL) { |
debug("Forcing accepting of host key for " |
debug("Forcing accepting of host key for " |
"loopback/localhost."); |
"loopback/localhost."); |
return 0; |
return 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!"); |
|
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!"); |
|
goto fail; |
goto fail; |
} |
} |
} |
} |