summaryrefslogtreecommitdiff
path: root/servconf.c
diff options
context:
space:
mode:
Diffstat (limited to 'servconf.c')
-rw-r--r--servconf.c93
1 files changed, 57 insertions, 36 deletions
diff --git a/servconf.c b/servconf.c
index fae3c658e..2d1a0c362 100644
--- a/servconf.c
+++ b/servconf.c
@@ -10,7 +10,7 @@
10 */ 10 */
11 11
12#include "includes.h" 12#include "includes.h"
13RCSID("$OpenBSD: servconf.c,v 1.137 2004/08/13 11:09:24 dtucker Exp $"); 13RCSID("$OpenBSD: servconf.c,v 1.139 2005/03/01 10:09:52 djm Exp $");
14 14
15#include "ssh.h" 15#include "ssh.h"
16#include "log.h" 16#include "log.h"
@@ -26,8 +26,6 @@ RCSID("$OpenBSD: servconf.c,v 1.137 2004/08/13 11:09:24 dtucker Exp $");
26static void add_listen_addr(ServerOptions *, char *, u_short); 26static void add_listen_addr(ServerOptions *, char *, u_short);
27static void add_one_listen_addr(ServerOptions *, char *, u_short); 27static void add_one_listen_addr(ServerOptions *, char *, u_short);
28 28
29/* AF_UNSPEC or AF_INET or AF_INET6 */
30extern int IPv4or6;
31/* Use of privilege separation or not */ 29/* Use of privilege separation or not */
32extern int use_privsep; 30extern int use_privsep;
33 31
@@ -45,6 +43,7 @@ initialize_server_options(ServerOptions *options)
45 options->num_ports = 0; 43 options->num_ports = 0;
46 options->ports_from_cmdline = 0; 44 options->ports_from_cmdline = 0;
47 options->listen_addrs = NULL; 45 options->listen_addrs = NULL;
46 options->address_family = -1;
48 options->num_host_key_files = 0; 47 options->num_host_key_files = 0;
49 options->pid_file = NULL; 48 options->pid_file = NULL;
50 options->server_key_bits = -1; 49 options->server_key_bits = -1;
@@ -258,7 +257,8 @@ typedef enum {
258 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup, 257 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
259 sKerberosGetAFSToken, 258 sKerberosGetAFSToken,
260 sKerberosTgtPassing, sChallengeResponseAuthentication, 259 sKerberosTgtPassing, sChallengeResponseAuthentication,
261 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress, 260 sPasswordAuthentication, sKbdInteractiveAuthentication,
261 sListenAddress, sAddressFamily,
262 sPrintMotd, sPrintLastLog, sIgnoreRhosts, 262 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
263 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost, 263 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
264 sStrictModes, sEmptyPasswd, sTCPKeepAlive, 264 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
@@ -335,6 +335,7 @@ static struct {
335 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */ 335 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
336 { "checkmail", sDeprecated }, 336 { "checkmail", sDeprecated },
337 { "listenaddress", sListenAddress }, 337 { "listenaddress", sListenAddress },
338 { "addressfamily", sAddressFamily },
338 { "printmotd", sPrintMotd }, 339 { "printmotd", sPrintMotd },
339 { "printlastlog", sPrintLastLog }, 340 { "printlastlog", sPrintLastLog },
340 { "ignorerhosts", sIgnoreRhosts }, 341 { "ignorerhosts", sIgnoreRhosts },
@@ -401,6 +402,8 @@ add_listen_addr(ServerOptions *options, char *addr, u_short port)
401 402
402 if (options->num_ports == 0) 403 if (options->num_ports == 0)
403 options->ports[options->num_ports++] = SSH_DEFAULT_PORT; 404 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
405 if (options->address_family == -1)
406 options->address_family = AF_UNSPEC;
404 if (port == 0) 407 if (port == 0)
405 for (i = 0; i < options->num_ports; i++) 408 for (i = 0; i < options->num_ports; i++)
406 add_one_listen_addr(options, addr, options->ports[i]); 409 add_one_listen_addr(options, addr, options->ports[i]);
@@ -416,7 +419,7 @@ add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
416 int gaierr; 419 int gaierr;
417 420
418 memset(&hints, 0, sizeof(hints)); 421 memset(&hints, 0, sizeof(hints));
419 hints.ai_family = IPv4or6; 422 hints.ai_family = options->address_family;
420 hints.ai_socktype = SOCK_STREAM; 423 hints.ai_socktype = SOCK_STREAM;
421 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0; 424 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
422 snprintf(strport, sizeof strport, "%u", port); 425 snprintf(strport, sizeof strport, "%u", port);
@@ -437,6 +440,7 @@ process_server_config_line(ServerOptions *options, char *line,
437 char *cp, **charptr, *arg, *p; 440 char *cp, **charptr, *arg, *p;
438 int *intptr, value, i, n; 441 int *intptr, value, i, n;
439 ServerOpCodes opcode; 442 ServerOpCodes opcode;
443 u_short port;
440 444
441 cp = line; 445 cp = line;
442 arg = strdelim(&cp); 446 arg = strdelim(&cp);
@@ -509,39 +513,40 @@ parse_time:
509 513
510 case sListenAddress: 514 case sListenAddress:
511 arg = strdelim(&cp); 515 arg = strdelim(&cp);
512 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0) 516 if (arg == NULL || *arg == '\0')
513 fatal("%s line %d: missing inet addr.", 517 fatal("%s line %d: missing address",
514 filename, linenum); 518 filename, linenum);
515 if (*arg == '[') { 519 p = hpdelim(&arg);
516 if ((p = strchr(arg, ']')) == NULL) 520 if (p == NULL)
517 fatal("%s line %d: bad ipv6 inet addr usage.", 521 fatal("%s line %d: bad address:port usage",
518 filename, linenum); 522 filename, linenum);
519 arg++; 523 p = cleanhostname(p);
520 memmove(p, p+1, strlen(p+1)+1); 524 if (arg == NULL)
521 } else if (((p = strchr(arg, ':')) == NULL) || 525 port = 0;
522 (strchr(p+1, ':') != NULL)) { 526 else if ((port = a2port(arg)) == 0)
523 add_listen_addr(options, arg, 0); 527 fatal("%s line %d: bad port number", filename, linenum);
524 break;
525 }
526 if (*p == ':') {
527 u_short port;
528 528
529 p++; 529 add_listen_addr(options, p, port);
530 if (*p == '\0') 530
531 fatal("%s line %d: bad inet addr:port usage.", 531 break;
532 filename, linenum); 532
533 else { 533 case sAddressFamily:
534 *(p-1) = '\0'; 534 arg = strdelim(&cp);
535 if ((port = a2port(p)) == 0) 535 intptr = &options->address_family;
536 fatal("%s line %d: bad port number.", 536 if (options->listen_addrs != NULL)
537 filename, linenum); 537 fatal("%s line %d: address family must be specified before "
538 add_listen_addr(options, arg, port); 538 "ListenAddress.", filename, linenum);
539 } 539 if (strcasecmp(arg, "inet") == 0)
540 } else if (*p == '\0') 540 value = AF_INET;
541 add_listen_addr(options, arg, 0); 541 else if (strcasecmp(arg, "inet6") == 0)
542 value = AF_INET6;
543 else if (strcasecmp(arg, "any") == 0)
544 value = AF_UNSPEC;
542 else 545 else
543 fatal("%s line %d: bad inet addr usage.", 546 fatal("%s line %d: unsupported address family \"%s\".",
544 filename, linenum); 547 filename, linenum, arg);
548 if (*intptr == -1)
549 *intptr = value;
545 break; 550 break;
546 551
547 case sHostKeyFile: 552 case sHostKeyFile:
@@ -720,7 +725,23 @@ parse_flag:
720 725
721 case sGatewayPorts: 726 case sGatewayPorts:
722 intptr = &options->gateway_ports; 727 intptr = &options->gateway_ports;
723 goto parse_flag; 728 arg = strdelim(&cp);
729 if (!arg || *arg == '\0')
730 fatal("%s line %d: missing yes/no/clientspecified "
731 "argument.", filename, linenum);
732 value = 0; /* silence compiler */
733 if (strcmp(arg, "clientspecified") == 0)
734 value = 2;
735 else if (strcmp(arg, "yes") == 0)
736 value = 1;
737 else if (strcmp(arg, "no") == 0)
738 value = 0;
739 else
740 fatal("%s line %d: Bad yes/no/clientspecified "
741 "argument: %s", filename, linenum, arg);
742 if (*intptr == -1)
743 *intptr = value;
744 break;
724 745
725 case sUseDNS: 746 case sUseDNS:
726 intptr = &options->use_dns; 747 intptr = &options->use_dns;