|
Lines 504-519
confirm(const char *prompt)
Link Here
|
| 504 |
} |
504 |
} |
| 505 |
|
505 |
|
| 506 |
/* |
506 |
/* |
| 507 |
* check whether the supplied host key is valid, return -1 if the key |
507 |
* Check whether the supplied host key is valid, return -1 if the key |
| 508 |
* is not valid. the user_hostfile will not be updated if 'readonly' is true. |
508 |
* is not valid. If readonly is non-zero, user_hostfile will not be |
|
|
509 |
* updated and if it's 2 then a changed host key warning will not be |
| 510 |
* generated. |
| 509 |
*/ |
511 |
*/ |
| 510 |
static int |
512 |
static int |
| 511 |
check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key, |
513 |
check_host_key(char *hostname, struct sockaddr *hostaddr, u_short port, |
| 512 |
int readonly, const char *user_hostfile, const char *system_hostfile) |
514 |
Key *host_key, int readonly, const char *user_hostfile, |
|
|
515 |
const char *system_hostfile) |
| 513 |
{ |
516 |
{ |
| 514 |
Key *file_key; |
517 |
Key *file_key; |
| 515 |
const char *type = key_type(host_key); |
518 |
const char *type = key_type(host_key); |
| 516 |
char *ip = NULL; |
519 |
char *ip = NULL, *host = NULL; |
| 517 |
char hostline[1000], *hostp, *fp; |
520 |
char hostline[1000], *hostp, *fp; |
| 518 |
HostStatus host_status; |
521 |
HostStatus host_status; |
| 519 |
HostStatus ip_status; |
522 |
HostStatus ip_status; |
|
Lines 564-570
check_host_key(char *host, struct sockad
Link Here
|
| 564 |
if (getnameinfo(hostaddr, salen, ntop, sizeof(ntop), |
567 |
if (getnameinfo(hostaddr, salen, ntop, sizeof(ntop), |
| 565 |
NULL, 0, NI_NUMERICHOST) != 0) |
568 |
NULL, 0, NI_NUMERICHOST) != 0) |
| 566 |
fatal("check_host_key: getnameinfo failed"); |
569 |
fatal("check_host_key: getnameinfo failed"); |
| 567 |
ip = xstrdup(ntop); |
570 |
ip = put_host_port(ntop, port); |
| 568 |
} else { |
571 |
} else { |
| 569 |
ip = xstrdup("<no hostip for proxy command>"); |
572 |
ip = xstrdup("<no hostip for proxy command>"); |
| 570 |
} |
573 |
} |
|
Lines 572-589
check_host_key(char *host, struct sockad
Link Here
|
| 572 |
* Turn off check_host_ip if the connection is to localhost, via proxy |
575 |
* Turn off check_host_ip if the connection is to localhost, via proxy |
| 573 |
* command or if we don't have a hostname to compare with |
576 |
* command or if we don't have a hostname to compare with |
| 574 |
*/ |
577 |
*/ |
| 575 |
if (options.check_host_ip && |
578 |
if (options.check_host_ip && (local || |
| 576 |
(local || strcmp(host, ip) == 0 || options.proxy_command != NULL)) |
579 |
strcmp(hostname, ip) == 0 || options.proxy_command != NULL)) |
| 577 |
options.check_host_ip = 0; |
580 |
options.check_host_ip = 0; |
| 578 |
|
581 |
|
| 579 |
/* |
582 |
/* |
| 580 |
* Allow the user to record the key under a different name. This is |
583 |
* Allow the user to record the key under a different name or |
| 581 |
* useful for ssh tunneling over forwarded connections or if you run |
584 |
* differentiate a non-standard port. This is useful for ssh |
| 582 |
* multiple sshd's on different ports on the same machine. |
585 |
* tunneling over forwarded connections or if you run multiple |
|
|
586 |
* sshd's on different ports on the same machine. |
| 583 |
*/ |
587 |
*/ |
| 584 |
if (options.host_key_alias != NULL) { |
588 |
if (options.host_key_alias != NULL) { |
| 585 |
host = options.host_key_alias; |
589 |
host = xstrdup(options.host_key_alias); |
| 586 |
debug("using hostkeyalias: %s", host); |
590 |
debug("using hostkeyalias: %s", host); |
|
|
591 |
} else { |
| 592 |
host = put_host_port(hostname, port); |
| 587 |
} |
593 |
} |
| 588 |
|
594 |
|
| 589 |
/* |
595 |
/* |
|
Lines 652-657
check_host_key(char *host, struct sockad
Link Here
|
| 652 |
} |
658 |
} |
| 653 |
break; |
659 |
break; |
| 654 |
case HOST_NEW: |
660 |
case HOST_NEW: |
|
|
661 |
if (options.host_key_alias == NULL && port != 0 && |
| 662 |
port != SSH_DEFAULT_PORT) { |
| 663 |
debug("checking without port identifier"); |
| 664 |
if (check_host_key(hostname, hostaddr, 0, host_key, 2, |
| 665 |
user_hostfile, system_hostfile) == 0) { |
| 666 |
debug("found matching key w/out port"); |
| 667 |
break; |
| 668 |
} |
| 669 |
} |
| 655 |
if (readonly) |
670 |
if (readonly) |
| 656 |
goto fail; |
671 |
goto fail; |
| 657 |
/* The host is new. */ |
672 |
/* The host is new. */ |
|
Lines 731-736
check_host_key(char *host, struct sockad
Link Here
|
| 731 |
"list of known hosts.", hostp, type); |
746 |
"list of known hosts.", hostp, type); |
| 732 |
break; |
747 |
break; |
| 733 |
case HOST_CHANGED: |
748 |
case HOST_CHANGED: |
|
|
749 |
if (readonly == 2) |
| 750 |
goto fail; |
| 734 |
if (options.check_host_ip && host_ip_differ) { |
751 |
if (options.check_host_ip && host_ip_differ) { |
| 735 |
char *key_msg; |
752 |
char *key_msg; |
| 736 |
if (ip_status == HOST_NEW) |
753 |
if (ip_status == HOST_NEW) |
|
Lines 845-854
check_host_key(char *host, struct sockad
Link Here
|
| 845 |
} |
862 |
} |
| 846 |
|
863 |
|
| 847 |
xfree(ip); |
864 |
xfree(ip); |
|
|
865 |
xfree(host); |
| 848 |
return 0; |
866 |
return 0; |
| 849 |
|
867 |
|
| 850 |
fail: |
868 |
fail: |
| 851 |
xfree(ip); |
869 |
xfree(ip); |
|
|
870 |
xfree(host); |
| 852 |
return -1; |
871 |
return -1; |
| 853 |
} |
872 |
} |
| 854 |
|
873 |
|
|
Lines 882-893
verify_host_key(char *host, struct socka
Link Here
|
| 882 |
/* return ok if the key can be found in an old keyfile */ |
901 |
/* return ok if the key can be found in an old keyfile */ |
| 883 |
if (stat(options.system_hostfile2, &st) == 0 || |
902 |
if (stat(options.system_hostfile2, &st) == 0 || |
| 884 |
stat(options.user_hostfile2, &st) == 0) { |
903 |
stat(options.user_hostfile2, &st) == 0) { |
| 885 |
if (check_host_key(host, hostaddr, host_key, /*readonly*/ 1, |
904 |
if (check_host_key(host, hostaddr, options.port, host_key, |
| 886 |
options.user_hostfile2, options.system_hostfile2) == 0) |
905 |
/*readonly*/ 1, options.user_hostfile2, |
|
|
906 |
options.system_hostfile2) == 0) |
| 887 |
return 0; |
907 |
return 0; |
| 888 |
} |
908 |
} |
| 889 |
return check_host_key(host, hostaddr, host_key, /*readonly*/ 0, |
909 |
return check_host_key(host, hostaddr, options.port, host_key, |
| 890 |
options.user_hostfile, options.system_hostfile); |
910 |
/*readonly*/ 0, options.user_hostfile, options.system_hostfile); |
| 891 |
} |
911 |
} |
| 892 |
|
912 |
|
| 893 |
/* |
913 |
/* |