diff options
Diffstat (limited to 'servconf.c')
-rw-r--r-- | servconf.c | 88 |
1 files changed, 64 insertions, 24 deletions
diff --git a/servconf.c b/servconf.c index 99cccbf21..3425fe0ee 100644 --- a/servconf.c +++ b/servconf.c | |||
@@ -12,20 +12,24 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include "includes.h" | 14 | #include "includes.h" |
15 | RCSID("$Id: servconf.c,v 1.7 1999/11/25 00:54:59 damien Exp $"); | 15 | RCSID("$Id: servconf.c,v 1.8 2000/01/14 04:45:51 damien Exp $"); |
16 | 16 | ||
17 | #include "ssh.h" | 17 | #include "ssh.h" |
18 | #include "servconf.h" | 18 | #include "servconf.h" |
19 | #include "xmalloc.h" | 19 | #include "xmalloc.h" |
20 | 20 | ||
21 | /* add listen address */ | ||
22 | void add_listen_addr(ServerOptions *options, char *addr); | ||
23 | |||
21 | /* Initializes the server options to their default values. */ | 24 | /* Initializes the server options to their default values. */ |
22 | 25 | ||
23 | void | 26 | void |
24 | initialize_server_options(ServerOptions *options) | 27 | initialize_server_options(ServerOptions *options) |
25 | { | 28 | { |
26 | memset(options, 0, sizeof(*options)); | 29 | memset(options, 0, sizeof(*options)); |
27 | options->port = -1; | 30 | options->num_ports = 0; |
28 | options->listen_addr.s_addr = htonl(INADDR_ANY); | 31 | options->ports_from_cmdline = 0; |
32 | options->listen_addrs = NULL; | ||
29 | options->host_key_file = NULL; | 33 | options->host_key_file = NULL; |
30 | options->server_key_bits = -1; | 34 | options->server_key_bits = -1; |
31 | options->login_grace_time = -1; | 35 | options->login_grace_time = -1; |
@@ -68,16 +72,10 @@ initialize_server_options(ServerOptions *options) | |||
68 | void | 72 | void |
69 | fill_default_server_options(ServerOptions *options) | 73 | fill_default_server_options(ServerOptions *options) |
70 | { | 74 | { |
71 | if (options->port == -1) { | 75 | if (options->num_ports == 0) |
72 | struct servent *sp; | 76 | options->ports[options->num_ports++] = SSH_DEFAULT_PORT; |
73 | 77 | if (options->listen_addrs == NULL) | |
74 | sp = getservbyname(SSH_SERVICE_NAME, "tcp"); | 78 | add_listen_addr(options, NULL); |
75 | if (sp) | ||
76 | options->port = ntohs(sp->s_port); | ||
77 | else | ||
78 | options->port = SSH_DEFAULT_PORT; | ||
79 | endservent(); | ||
80 | } | ||
81 | if (options->host_key_file == NULL) | 79 | if (options->host_key_file == NULL) |
82 | options->host_key_file = HOST_KEY_FILE; | 80 | options->host_key_file = HOST_KEY_FILE; |
83 | if (options->server_key_bits == -1) | 81 | if (options->server_key_bits == -1) |
@@ -232,6 +230,37 @@ parse_token(const char *cp, const char *filename, | |||
232 | return sBadOption; | 230 | return sBadOption; |
233 | } | 231 | } |
234 | 232 | ||
233 | /* | ||
234 | * add listen address | ||
235 | */ | ||
236 | void | ||
237 | add_listen_addr(ServerOptions *options, char *addr) | ||
238 | { | ||
239 | extern int IPv4or6; | ||
240 | struct addrinfo hints, *ai, *aitop; | ||
241 | char strport[NI_MAXSERV]; | ||
242 | int gaierr; | ||
243 | int i; | ||
244 | |||
245 | if (options->num_ports == 0) | ||
246 | options->ports[options->num_ports++] = SSH_DEFAULT_PORT; | ||
247 | for (i = 0; i < options->num_ports; i++) { | ||
248 | memset(&hints, 0, sizeof(hints)); | ||
249 | hints.ai_family = IPv4or6; | ||
250 | hints.ai_socktype = SOCK_STREAM; | ||
251 | hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0; | ||
252 | snprintf(strport, sizeof strport, "%d", options->ports[i]); | ||
253 | if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0) | ||
254 | fatal("bad addr or host: %s (%s)\n", | ||
255 | addr ? addr : "<NULL>", | ||
256 | gai_strerror(gaierr)); | ||
257 | for (ai = aitop; ai->ai_next; ai = ai->ai_next) | ||
258 | ; | ||
259 | ai->ai_next = options->listen_addrs; | ||
260 | options->listen_addrs = aitop; | ||
261 | } | ||
262 | } | ||
263 | |||
235 | /* Reads the server configuration file. */ | 264 | /* Reads the server configuration file. */ |
236 | 265 | ||
237 | void | 266 | void |
@@ -262,7 +291,24 @@ read_server_config(ServerOptions *options, const char *filename) | |||
262 | bad_options++; | 291 | bad_options++; |
263 | continue; | 292 | continue; |
264 | case sPort: | 293 | case sPort: |
265 | intptr = &options->port; | 294 | /* ignore ports from configfile if cmdline specifies ports */ |
295 | if (options->ports_from_cmdline) | ||
296 | continue; | ||
297 | if (options->listen_addrs != NULL) | ||
298 | fatal("%s line %d: ports must be specified before " | ||
299 | "ListenAdress.\n", filename, linenum); | ||
300 | if (options->num_ports >= MAX_PORTS) | ||
301 | fatal("%s line %d: too many ports.\n", | ||
302 | filename, linenum); | ||
303 | cp = strtok(NULL, WHITESPACE); | ||
304 | if (!cp) | ||
305 | fatal("%s line %d: missing port number.\n", | ||
306 | filename, linenum); | ||
307 | options->ports[options->num_ports++] = atoi(cp); | ||
308 | break; | ||
309 | |||
310 | case sServerKeyBits: | ||
311 | intptr = &options->server_key_bits; | ||
266 | parse_int: | 312 | parse_int: |
267 | cp = strtok(NULL, WHITESPACE); | 313 | cp = strtok(NULL, WHITESPACE); |
268 | if (!cp) { | 314 | if (!cp) { |
@@ -275,10 +321,6 @@ parse_int: | |||
275 | *intptr = value; | 321 | *intptr = value; |
276 | break; | 322 | break; |
277 | 323 | ||
278 | case sServerKeyBits: | ||
279 | intptr = &options->server_key_bits; | ||
280 | goto parse_int; | ||
281 | |||
282 | case sLoginGraceTime: | 324 | case sLoginGraceTime: |
283 | intptr = &options->login_grace_time; | 325 | intptr = &options->login_grace_time; |
284 | goto parse_int; | 326 | goto parse_int; |
@@ -289,12 +331,10 @@ parse_int: | |||
289 | 331 | ||
290 | case sListenAddress: | 332 | case sListenAddress: |
291 | cp = strtok(NULL, WHITESPACE); | 333 | cp = strtok(NULL, WHITESPACE); |
292 | if (!cp) { | 334 | if (!cp) |
293 | fprintf(stderr, "%s line %d: missing inet addr.\n", | 335 | fatal("%s line %d: missing inet addr.\n", |
294 | filename, linenum); | 336 | filename, linenum); |
295 | exit(1); | 337 | add_listen_addr(options, cp); |
296 | } | ||
297 | options->listen_addr.s_addr = inet_addr(cp); | ||
298 | break; | 338 | break; |
299 | 339 | ||
300 | case sHostKeyFile: | 340 | case sHostKeyFile: |