summaryrefslogtreecommitdiff
path: root/servconf.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 /servconf.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 'servconf.c')
-rw-r--r--servconf.c88
1 files changed, 64 insertions, 24 deletions
diff --git a/servconf.c b/servconf.c
index 99cccbf2..3425fe0e 100644
--- a/servconf.c
+++ b/servconf.c
@@ -12,20 +12,24 @@
*/
#include "includes.h"
-RCSID("$Id: servconf.c,v 1.7 1999/11/25 00:54:59 damien Exp $");
+RCSID("$Id: servconf.c,v 1.8 2000/01/14 04:45:51 damien Exp $");
#include "ssh.h"
#include "servconf.h"
#include "xmalloc.h"
+/* add listen address */
+void add_listen_addr(ServerOptions *options, char *addr);
+
/* Initializes the server options to their default values. */
void
initialize_server_options(ServerOptions *options)
{
memset(options, 0, sizeof(*options));
- options->port = -1;
- options->listen_addr.s_addr = htonl(INADDR_ANY);
+ options->num_ports = 0;
+ options->ports_from_cmdline = 0;
+ options->listen_addrs = NULL;
options->host_key_file = NULL;
options->server_key_bits = -1;
options->login_grace_time = -1;
@@ -68,16 +72,10 @@ initialize_server_options(ServerOptions *options)
void
fill_default_server_options(ServerOptions *options)
{
- if (options->port == -1) {
- struct servent *sp;
-
- sp = getservbyname(SSH_SERVICE_NAME, "tcp");
- if (sp)
- options->port = ntohs(sp->s_port);
- else
- options->port = SSH_DEFAULT_PORT;
- endservent();
- }
+ if (options->num_ports == 0)
+ options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
+ if (options->listen_addrs == NULL)
+ add_listen_addr(options, NULL);
if (options->host_key_file == NULL)
options->host_key_file = HOST_KEY_FILE;
if (options->server_key_bits == -1)
@@ -232,6 +230,37 @@ parse_token(const char *cp, const char *filename,
return sBadOption;
}
+/*
+ * add listen address
+ */
+void
+add_listen_addr(ServerOptions *options, char *addr)
+{
+ extern int IPv4or6;
+ struct addrinfo hints, *ai, *aitop;
+ char strport[NI_MAXSERV];
+ int gaierr;
+ int i;
+
+ if (options->num_ports == 0)
+ options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
+ for (i = 0; i < options->num_ports; i++) {
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = IPv4or6;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
+ snprintf(strport, sizeof strport, "%d", options->ports[i]);
+ if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
+ fatal("bad addr or host: %s (%s)\n",
+ addr ? addr : "<NULL>",
+ gai_strerror(gaierr));
+ for (ai = aitop; ai->ai_next; ai = ai->ai_next)
+ ;
+ ai->ai_next = options->listen_addrs;
+ options->listen_addrs = aitop;
+ }
+}
+
/* Reads the server configuration file. */
void
@@ -262,7 +291,24 @@ read_server_config(ServerOptions *options, const char *filename)
bad_options++;
continue;
case sPort:
- intptr = &options->port;
+ /* ignore ports from configfile if cmdline specifies ports */
+ if (options->ports_from_cmdline)
+ continue;
+ if (options->listen_addrs != NULL)
+ fatal("%s line %d: ports must be specified before "
+ "ListenAdress.\n", filename, linenum);
+ if (options->num_ports >= MAX_PORTS)
+ fatal("%s line %d: too many ports.\n",
+ filename, linenum);
+ cp = strtok(NULL, WHITESPACE);
+ if (!cp)
+ fatal("%s line %d: missing port number.\n",
+ filename, linenum);
+ options->ports[options->num_ports++] = atoi(cp);
+ break;
+
+ case sServerKeyBits:
+ intptr = &options->server_key_bits;
parse_int:
cp = strtok(NULL, WHITESPACE);
if (!cp) {
@@ -275,10 +321,6 @@ parse_int:
*intptr = value;
break;
- case sServerKeyBits:
- intptr = &options->server_key_bits;
- goto parse_int;
-
case sLoginGraceTime:
intptr = &options->login_grace_time;
goto parse_int;
@@ -289,12 +331,10 @@ parse_int:
case sListenAddress:
cp = strtok(NULL, WHITESPACE);
- if (!cp) {
- fprintf(stderr, "%s line %d: missing inet addr.\n",
- filename, linenum);
- exit(1);
- }
- options->listen_addr.s_addr = inet_addr(cp);
+ if (!cp)
+ fatal("%s line %d: missing inet addr.\n",
+ filename, linenum);
+ add_listen_addr(options, cp);
break;
case sHostKeyFile: