View | Details | Raw Unified | Return to bug 910 | Differences between
and this patch

Collapse All | Expand All

(-)misc.c (+18 lines)
Lines 38-43 Link Here
38
#include "misc.h"
38
#include "misc.h"
39
#include "log.h"
39
#include "log.h"
40
#include "xmalloc.h"
40
#include "xmalloc.h"
41
#include "ssh.h"
41
42
42
/* remove newline at end of string */
43
/* remove newline at end of string */
43
char *
44
char *
Lines 330-335 convtime(const char *s) Link Here
330
}
331
}
331
332
332
/*
333
/*
334
 * Returns a standardized host+port identifier string.
335
 * Caller must free returned string.
336
 */
337
char *
338
put_host_port(const char *host, u_short port)
339
{
340
	char *hoststr;
341
342
	if (port == 0 || port == SSH_DEFAULT_PORT)
343
		return(xstrdup(host));
344
	if (asprintf(&hoststr, "[%s]:%d", host, (int)port) < 0)
345
		fatal("put_host_port: asprintf: %s", strerror(errno));
346
	debug3("put_host_port: %s", hoststr);
347
	return hoststr;
348
}
349
350
/*
333
 * Search for next delimiter between hostnames/addresses and ports.
351
 * Search for next delimiter between hostnames/addresses and ports.
334
 * Argument may be modified (for termination).
352
 * Argument may be modified (for termination).
335
 * Returns *cp if parsing succeeds.
353
 * Returns *cp if parsing succeeds.
(-)misc.h (+1 lines)
Lines 23-28 int set_nonblock(int); Link Here
23
int	 unset_nonblock(int);
23
int	 unset_nonblock(int);
24
void	 set_nodelay(int);
24
void	 set_nodelay(int);
25
int	 a2port(const char *);
25
int	 a2port(const char *);
26
char	*put_host_port(const char *, u_short);
26
int	 a2tun(const char *, int *);
27
int	 a2tun(const char *, int *);
27
char	*hpdelim(char **);
28
char	*hpdelim(char **);
28
char	*cleanhostname(char *);
29
char	*cleanhostname(char *);
(-)sshconnect.c (-16 / +36 lines)
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
/*
(-)sshd.8 (+7 lines)
Lines 588-593 A pattern may also be preceded by Link Here
588
to indicate negation: if the host name matches a negated
588
to indicate negation: if the host name matches a negated
589
pattern, it is not accepted (by that line) even if it matched another
589
pattern, it is not accepted (by that line) even if it matched another
590
pattern on the line.
590
pattern on the line.
591
A hostname or address may optionally be enclosed within
592
.Ql \&[
593
and
594
.Ql \&]
595
brackets then followed by
596
.Ql \&:
597
and and a non-standard port number.
591
.Pp
598
.Pp
592
Alternately, hostnames may be stored in a hashed form which hides host names
599
Alternately, hostnames may be stored in a hashed form which hides host names
593
and addresses should the file's contents be disclosed.
600
and addresses should the file's contents be disclosed.

Return to bug 910