version 1.28, 1999/11/24 20:19:37 |
version 1.29, 2000/01/04 00:07:59 |
|
|
#include "servconf.h" |
#include "servconf.h" |
#include "xmalloc.h" |
#include "xmalloc.h" |
|
|
|
/* add listen address */ |
|
void add_listen_addr(ServerOptions *options, char *addr); |
|
|
/* Initializes the server options to their default values. */ |
/* Initializes the server options to their default values. */ |
|
|
void |
void |
initialize_server_options(ServerOptions *options) |
initialize_server_options(ServerOptions *options) |
{ |
{ |
memset(options, 0, sizeof(*options)); |
memset(options, 0, sizeof(*options)); |
options->port = -1; |
options->num_ports = 0; |
options->listen_addr.s_addr = htonl(INADDR_ANY); |
options->ports_from_cmdline = 0; |
|
options->listen_addrs = NULL; |
options->host_key_file = NULL; |
options->host_key_file = NULL; |
options->server_key_bits = -1; |
options->server_key_bits = -1; |
options->login_grace_time = -1; |
options->login_grace_time = -1; |
|
|
void |
void |
fill_default_server_options(ServerOptions *options) |
fill_default_server_options(ServerOptions *options) |
{ |
{ |
if (options->port == -1) { |
if (options->num_ports == 0) |
struct servent *sp; |
options->ports[options->num_ports++] = SSH_DEFAULT_PORT; |
|
if (options->listen_addrs == NULL) |
sp = getservbyname(SSH_SERVICE_NAME, "tcp"); |
add_listen_addr(options, NULL); |
if (sp) |
|
options->port = ntohs(sp->s_port); |
|
else |
|
options->port = SSH_DEFAULT_PORT; |
|
endservent(); |
|
} |
|
if (options->host_key_file == NULL) |
if (options->host_key_file == NULL) |
options->host_key_file = HOST_KEY_FILE; |
options->host_key_file = HOST_KEY_FILE; |
if (options->server_key_bits == -1) |
if (options->server_key_bits == -1) |
|
|
return sBadOption; |
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. */ |
/* Reads the server configuration file. */ |
|
|
void |
void |
|
|
bad_options++; |
bad_options++; |
continue; |
continue; |
case sPort: |
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: |
parse_int: |
cp = strtok(NULL, WHITESPACE); |
cp = strtok(NULL, WHITESPACE); |
if (!cp) { |
if (!cp) { |
|
|
*intptr = value; |
*intptr = value; |
break; |
break; |
|
|
case sServerKeyBits: |
|
intptr = &options->server_key_bits; |
|
goto parse_int; |
|
|
|
case sLoginGraceTime: |
case sLoginGraceTime: |
intptr = &options->login_grace_time; |
intptr = &options->login_grace_time; |
goto parse_int; |
goto parse_int; |
|
|
|
|
case sListenAddress: |
case sListenAddress: |
cp = strtok(NULL, WHITESPACE); |
cp = strtok(NULL, WHITESPACE); |
if (!cp) { |
if (!cp) |
fprintf(stderr, "%s line %d: missing inet addr.\n", |
fatal("%s line %d: missing inet addr.\n", |
filename, linenum); |
filename, linenum); |
exit(1); |
add_listen_addr(options, cp); |
} |
|
options->listen_addr.s_addr = inet_addr(cp); |
|
break; |
break; |
|
|
case sHostKeyFile: |
case sHostKeyFile: |