summaryrefslogtreecommitdiff
path: root/ssh.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2000-01-14 15:45:46 +1100
committerDamien Miller <djm@mindrot.org>2000-01-14 15:45:46 +1100
commit34132e54cbd221d17d373fc54f4e3f7b85727f7f (patch)
tree7c73917b1082ff91786f9e02d25b853bedd1d472 /ssh.c
parent25e4256ad4f453d8a7c1866243ec1984f859b1de (diff)
- Merged OpenBSD IPv6 patch:
- [sshd.c sshd.8 sshconnect.c ssh.h ssh.c servconf.h servconf.c scp.1] [scp.c packet.h packet.c login.c log.c canohost.c channels.c] [hostfile.c sshd_config] ipv6 support: mostly gethostbyname->getaddrinfo/getnameinfo, new features: sshd allows multiple ListenAddress and Port options. note that libwrap is not IPv6-ready. (based on patches from fujiwara@rcac.tdi.co.jp) - [ssh.c canohost.c] more hints (hints.ai_socktype=SOCK_STREAM) for getaddrinfo, from itojun@ - [channels.c] listen on _all_ interfaces for X11-Fwd (hints.ai_flags = AI_PASSIVE) - [packet.h] allow auth-kerberos for IPv4 only - [scp.1 sshd.8 servconf.h scp.c] document -4, -6, and 'ssh -L 2022/::1/22' - [ssh.c] 'ssh @host' is illegal (null user name), from karsten@gedankenpolizei.de - [sshconnect.c] better error message - [sshd.c] allow auth-kerberos for IPv4 only - Big IPv6 merge: - Cleanup overrun in sockaddr copying on RHL 6.1 - Replacements for getaddrinfo, getnameinfo, etc based on versions from patch from KIKUCHI Takahiro <kick@kyoto.wide.ad.jp> - Replacement for missing structures on systems that lack IPv6 - record_login needed to know about AF_INET6 addresses - Borrowed more code from OpenBSD: rresvport_af and requisites
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/ssh.c b/ssh.c
index f9e77220c..962aa2d43 100644
--- a/ssh.c
+++ b/ssh.c
@@ -11,7 +11,7 @@
11 */ 11 */
12 12
13#include "includes.h" 13#include "includes.h"
14RCSID("$Id: ssh.c,v 1.15 1999/12/28 23:17:09 damien Exp $"); 14RCSID("$Id: ssh.c,v 1.16 2000/01/14 04:45:51 damien Exp $");
15 15
16#include "xmalloc.h" 16#include "xmalloc.h"
17#include "ssh.h" 17#include "ssh.h"
@@ -27,6 +27,10 @@ extern char *__progname;
27const char *__progname = "ssh"; 27const char *__progname = "ssh";
28#endif /* HAVE___PROGNAME */ 28#endif /* HAVE___PROGNAME */
29 29
30/* Flag indicating whether IPv4 or IPv6. This can be set on the command line.
31 Default value is AF_UNSPEC means both IPv4 and IPv6. */
32int IPv4or6 = AF_UNSPEC;
33
30/* Flag indicating whether debug mode is on. This can be set on the command line. */ 34/* Flag indicating whether debug mode is on. This can be set on the command line. */
31int debug_flag = 0; 35int debug_flag = 0;
32 36
@@ -59,7 +63,7 @@ Options options;
59char *host; 63char *host;
60 64
61/* socket address the host resolves to */ 65/* socket address the host resolves to */
62struct sockaddr_in hostaddr; 66struct sockaddr_storage hostaddr;
63 67
64/* 68/*
65 * Flag to indicate that we have received a window change signal which has 69 * Flag to indicate that we have received a window change signal which has
@@ -114,6 +118,8 @@ usage()
114 fprintf(stderr, " forward them to the other side by connecting to host:port.\n"); 118 fprintf(stderr, " forward them to the other side by connecting to host:port.\n");
115 fprintf(stderr, " -C Enable compression.\n"); 119 fprintf(stderr, " -C Enable compression.\n");
116 fprintf(stderr, " -g Allow remote hosts to connect to forwarded ports.\n"); 120 fprintf(stderr, " -g Allow remote hosts to connect to forwarded ports.\n");
121 fprintf(stderr, " -4 Use IPv4 only.\n");
122 fprintf(stderr, " -6 Use IPv6 only.\n");
117 fprintf(stderr, " -o 'option' Process the option as if it was read from a configuration file.\n"); 123 fprintf(stderr, " -o 'option' Process the option as if it was read from a configuration file.\n");
118 exit(1); 124 exit(1);
119} 125}
@@ -227,6 +233,8 @@ main(int ac, char **av)
227 if (host) 233 if (host)
228 break; 234 break;
229 if ((cp = strchr(av[optind], '@'))) { 235 if ((cp = strchr(av[optind], '@'))) {
236 if(cp == av[optind])
237 usage();
230 options.user = av[optind]; 238 options.user = av[optind];
231 *cp = '\0'; 239 *cp = '\0';
232 host = ++cp; 240 host = ++cp;
@@ -250,6 +258,14 @@ main(int ac, char **av)
250 optarg = NULL; 258 optarg = NULL;
251 } 259 }
252 switch (opt) { 260 switch (opt) {
261 case '4':
262 IPv4or6 = AF_INET;
263 break;
264
265 case '6':
266 IPv4or6 = AF_INET6;
267 break;
268
253 case 'n': 269 case 'n':
254 stdin_null_flag = 1; 270 stdin_null_flag = 1;
255 break; 271 break;
@@ -351,8 +367,10 @@ main(int ac, char **av)
351 break; 367 break;
352 368
353 case 'R': 369 case 'R':
354 if (sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf, 370 if (sscanf(optarg, "%hu/%255[^/]/%hu", &fwd_port, buf,
355 &fwd_host_port) != 3) { 371 &fwd_host_port) != 3 &&
372 sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf,
373 &fwd_host_port) != 3) {
356 fprintf(stderr, "Bad forwarding specification '%s'.\n", optarg); 374 fprintf(stderr, "Bad forwarding specification '%s'.\n", optarg);
357 usage(); 375 usage();
358 /* NOTREACHED */ 376 /* NOTREACHED */
@@ -361,8 +379,10 @@ main(int ac, char **av)
361 break; 379 break;
362 380
363 case 'L': 381 case 'L':
364 if (sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf, 382 if (sscanf(optarg, "%hu/%255[^/]/%hu", &fwd_port, buf,
365 &fwd_host_port) != 3) { 383 &fwd_host_port) != 3 &&
384 sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf,
385 &fwd_host_port) != 3) {
366 fprintf(stderr, "Bad forwarding specification '%s'.\n", optarg); 386 fprintf(stderr, "Bad forwarding specification '%s'.\n", optarg);
367 usage(); 387 usage();
368 /* NOTREACHED */ 388 /* NOTREACHED */
@@ -473,14 +493,18 @@ main(int ac, char **av)
473 493
474 /* Find canonic host name. */ 494 /* Find canonic host name. */
475 if (strchr(host, '.') == 0) { 495 if (strchr(host, '.') == 0) {
476 struct hostent *hp = gethostbyname(host); 496 struct addrinfo hints;
477 if (hp != 0) { 497 struct addrinfo *ai = NULL;
478 if (strchr(hp->h_name, '.') != 0) 498 int errgai;
479 host = xstrdup(hp->h_name); 499 memset(&hints, 0, sizeof(hints));
480 else if (hp->h_aliases != 0 500 hints.ai_family = AF_UNSPEC;
481 && hp->h_aliases[0] != 0 501 hints.ai_flags = AI_CANONNAME;
482 && strchr(hp->h_aliases[0], '.') != 0) 502 hints.ai_socktype = SOCK_STREAM;
483 host = xstrdup(hp->h_aliases[0]); 503 errgai = getaddrinfo(host, NULL, &hints, &ai);
504 if (errgai == 0) {
505 if (ai->ai_canonname != NULL)
506 host = xstrdup(ai->ai_canonname);
507 freeaddrinfo(ai);
484 } 508 }
485 } 509 }
486 /* Disable rhosts authentication if not running as root. */ 510 /* Disable rhosts authentication if not running as root. */
@@ -587,7 +611,7 @@ main(int ac, char **av)
587 611
588 /* Log into the remote system. This never returns if the login fails. */ 612 /* Log into the remote system. This never returns if the login fails. */
589 ssh_login(host_private_key_loaded, host_private_key, 613 ssh_login(host_private_key_loaded, host_private_key,
590 host, &hostaddr, original_real_uid); 614 host, (struct sockaddr *)&hostaddr, original_real_uid);
591 615
592 /* We no longer need the host private key. Clear it now. */ 616 /* We no longer need the host private key. Clear it now. */
593 if (host_private_key_loaded) 617 if (host_private_key_loaded)