2000-02-24 14:29:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
|
|
|
* All rights reserved
|
2000-05-15 05:24:25 +00:00
|
|
|
*
|
2000-09-10 09:35:38 +00:00
|
|
|
* As far as I am concerned, the code I have written for this software
|
|
|
|
* can be used freely for any purpose. Any derived versions of this
|
|
|
|
* software must be clearly marked as such, and if the derived work is
|
|
|
|
* incompatible with the protocol description in the RFC file, it must be
|
|
|
|
* called by a name other than "ssh" or "Secure Shell".
|
2000-02-24 14:29:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "includes.h"
|
2000-12-05 02:55:12 +00:00
|
|
|
RCSID("$OpenBSD: servconf.c,v 1.53 2000/10/14 12:12:09 markus Exp $");
|
2000-09-10 09:35:38 +00:00
|
|
|
RCSID("$FreeBSD$");
|
2000-02-24 14:29:47 +00:00
|
|
|
|
|
|
|
#include "ssh.h"
|
|
|
|
#include "servconf.h"
|
|
|
|
#include "xmalloc.h"
|
2000-05-15 05:24:25 +00:00
|
|
|
#include "compat.h"
|
2000-02-24 14:29:47 +00:00
|
|
|
|
|
|
|
/* add listen address */
|
|
|
|
void add_listen_addr(ServerOptions *options, char *addr);
|
|
|
|
|
|
|
|
/* Initializes the server options to their default values. */
|
|
|
|
|
2000-05-15 05:24:25 +00:00
|
|
|
void
|
2000-02-24 14:29:47 +00:00
|
|
|
initialize_server_options(ServerOptions *options)
|
|
|
|
{
|
|
|
|
memset(options, 0, sizeof(*options));
|
|
|
|
options->num_ports = 0;
|
|
|
|
options->ports_from_cmdline = 0;
|
|
|
|
options->listen_addrs = NULL;
|
|
|
|
options->host_key_file = NULL;
|
2000-05-15 05:24:25 +00:00
|
|
|
options->host_dsa_key_file = NULL;
|
|
|
|
options->pid_file = NULL;
|
2000-02-24 14:29:47 +00:00
|
|
|
options->server_key_bits = -1;
|
|
|
|
options->login_grace_time = -1;
|
|
|
|
options->key_regeneration_time = -1;
|
|
|
|
options->permit_root_login = -1;
|
|
|
|
options->ignore_rhosts = -1;
|
|
|
|
options->ignore_user_known_hosts = -1;
|
|
|
|
options->print_motd = -1;
|
|
|
|
options->check_mail = -1;
|
|
|
|
options->x11_forwarding = -1;
|
|
|
|
options->x11_display_offset = -1;
|
2000-09-10 09:35:38 +00:00
|
|
|
options->xauth_location = NULL;
|
2000-02-24 14:29:47 +00:00
|
|
|
options->strict_modes = -1;
|
|
|
|
options->keepalives = -1;
|
|
|
|
options->log_facility = (SyslogFacility) - 1;
|
|
|
|
options->log_level = (LogLevel) - 1;
|
|
|
|
options->rhosts_authentication = -1;
|
|
|
|
options->rhosts_rsa_authentication = -1;
|
|
|
|
options->rsa_authentication = -1;
|
2000-05-15 05:24:25 +00:00
|
|
|
options->dsa_authentication = -1;
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef KRB4
|
2000-02-28 19:03:50 +00:00
|
|
|
options->krb4_authentication = -1;
|
|
|
|
options->krb4_or_local_passwd = -1;
|
|
|
|
options->krb4_ticket_cleanup = -1;
|
2000-02-24 14:29:47 +00:00
|
|
|
#endif
|
2000-02-28 19:03:50 +00:00
|
|
|
#ifdef KRB5
|
|
|
|
options->krb5_authentication = -1;
|
|
|
|
options->krb5_tgt_passing = -1;
|
|
|
|
#endif /* KRB5 */
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef AFS
|
2000-02-28 19:03:50 +00:00
|
|
|
options->krb4_tgt_passing = -1;
|
2000-02-24 14:29:47 +00:00
|
|
|
options->afs_token_passing = -1;
|
|
|
|
#endif
|
|
|
|
options->password_authentication = -1;
|
2000-12-05 02:55:12 +00:00
|
|
|
options->kbd_interactive_authentication = -1;
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef SKEY
|
|
|
|
options->skey_authentication = -1;
|
|
|
|
#endif
|
|
|
|
options->permit_empty_passwd = -1;
|
|
|
|
options->use_login = -1;
|
2000-12-05 02:55:12 +00:00
|
|
|
options->allow_tcp_forwarding = -1;
|
2000-02-24 14:29:47 +00:00
|
|
|
options->num_allow_users = 0;
|
|
|
|
options->num_deny_users = 0;
|
|
|
|
options->num_allow_groups = 0;
|
|
|
|
options->num_deny_groups = 0;
|
2000-05-15 05:24:25 +00:00
|
|
|
options->ciphers = NULL;
|
|
|
|
options->protocol = SSH_PROTO_UNKNOWN;
|
|
|
|
options->gateway_ports = -1;
|
2000-02-24 15:29:42 +00:00
|
|
|
options->connections_per_period = 0;
|
|
|
|
options->connections_period = 0;
|
2000-09-10 09:35:38 +00:00
|
|
|
options->num_subsystems = 0;
|
|
|
|
options->max_startups_begin = -1;
|
|
|
|
options->max_startups_rate = -1;
|
|
|
|
options->max_startups = -1;
|
2000-02-24 14:29:47 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 05:24:25 +00:00
|
|
|
void
|
2000-02-24 14:29:47 +00:00
|
|
|
fill_default_server_options(ServerOptions *options)
|
|
|
|
{
|
|
|
|
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;
|
2000-05-15 05:24:25 +00:00
|
|
|
if (options->host_dsa_key_file == NULL)
|
|
|
|
options->host_dsa_key_file = HOST_DSA_KEY_FILE;
|
|
|
|
if (options->pid_file == NULL)
|
|
|
|
options->pid_file = SSH_DAEMON_PID_FILE;
|
2000-02-24 14:29:47 +00:00
|
|
|
if (options->server_key_bits == -1)
|
|
|
|
options->server_key_bits = 768;
|
|
|
|
if (options->login_grace_time == -1)
|
2000-08-23 09:47:25 +00:00
|
|
|
options->login_grace_time = 120;
|
2000-02-24 14:29:47 +00:00
|
|
|
if (options->key_regeneration_time == -1)
|
|
|
|
options->key_regeneration_time = 3600;
|
|
|
|
if (options->permit_root_login == -1)
|
2000-07-11 09:50:15 +00:00
|
|
|
options->permit_root_login = 0; /* no */
|
2000-02-24 14:29:47 +00:00
|
|
|
if (options->ignore_rhosts == -1)
|
2000-02-28 19:03:50 +00:00
|
|
|
options->ignore_rhosts = 1;
|
2000-02-24 14:29:47 +00:00
|
|
|
if (options->ignore_user_known_hosts == -1)
|
|
|
|
options->ignore_user_known_hosts = 0;
|
|
|
|
if (options->check_mail == -1)
|
2000-07-11 09:54:24 +00:00
|
|
|
options->check_mail = 1;
|
2000-02-24 14:29:47 +00:00
|
|
|
if (options->print_motd == -1)
|
|
|
|
options->print_motd = 1;
|
|
|
|
if (options->x11_forwarding == -1)
|
2000-09-02 03:49:22 +00:00
|
|
|
options->x11_forwarding = 1;
|
2000-02-24 14:29:47 +00:00
|
|
|
if (options->x11_display_offset == -1)
|
2000-02-28 19:03:50 +00:00
|
|
|
options->x11_display_offset = 10;
|
2000-09-10 09:35:38 +00:00
|
|
|
#ifdef XAUTH_PATH
|
|
|
|
if (options->xauth_location == NULL)
|
|
|
|
options->xauth_location = XAUTH_PATH;
|
|
|
|
#endif /* XAUTH_PATH */
|
2000-02-24 14:29:47 +00:00
|
|
|
if (options->strict_modes == -1)
|
|
|
|
options->strict_modes = 1;
|
|
|
|
if (options->keepalives == -1)
|
|
|
|
options->keepalives = 1;
|
|
|
|
if (options->log_facility == (SyslogFacility) (-1))
|
|
|
|
options->log_facility = SYSLOG_FACILITY_AUTH;
|
|
|
|
if (options->log_level == (LogLevel) (-1))
|
|
|
|
options->log_level = SYSLOG_LEVEL_INFO;
|
|
|
|
if (options->rhosts_authentication == -1)
|
|
|
|
options->rhosts_authentication = 0;
|
|
|
|
if (options->rhosts_rsa_authentication == -1)
|
2000-02-28 19:03:50 +00:00
|
|
|
options->rhosts_rsa_authentication = 0;
|
2000-02-24 14:29:47 +00:00
|
|
|
if (options->rsa_authentication == -1)
|
|
|
|
options->rsa_authentication = 1;
|
2000-05-15 05:24:25 +00:00
|
|
|
if (options->dsa_authentication == -1)
|
|
|
|
options->dsa_authentication = 1;
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef KRB4
|
2000-02-28 19:03:50 +00:00
|
|
|
if (options->krb4_authentication == -1)
|
|
|
|
options->krb4_authentication = (access(KEYFILE, R_OK) == 0);
|
|
|
|
if (options->krb4_or_local_passwd == -1)
|
|
|
|
options->krb4_or_local_passwd = 1;
|
|
|
|
if (options->krb4_ticket_cleanup == -1)
|
|
|
|
options->krb4_ticket_cleanup = 1;
|
2000-02-24 14:29:47 +00:00
|
|
|
#endif /* KRB4 */
|
2000-02-28 19:03:50 +00:00
|
|
|
#ifdef KRB5
|
|
|
|
if (options->krb5_authentication == -1)
|
|
|
|
options->krb5_authentication = 1;
|
|
|
|
if (options->krb5_tgt_passing == -1)
|
|
|
|
options->krb5_tgt_passing = 1;
|
|
|
|
#endif /* KRB5 */
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef AFS
|
2000-02-28 19:03:50 +00:00
|
|
|
if (options->krb4_tgt_passing == -1)
|
|
|
|
options->krb4_tgt_passing = 0;
|
2000-02-24 14:29:47 +00:00
|
|
|
if (options->afs_token_passing == -1)
|
|
|
|
options->afs_token_passing = k_hasafs();
|
|
|
|
#endif /* AFS */
|
|
|
|
if (options->password_authentication == -1)
|
|
|
|
options->password_authentication = 1;
|
2000-12-05 02:55:12 +00:00
|
|
|
if (options->kbd_interactive_authentication == -1)
|
|
|
|
options->kbd_interactive_authentication = 0;
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef SKEY
|
|
|
|
if (options->skey_authentication == -1)
|
|
|
|
options->skey_authentication = 1;
|
|
|
|
#endif
|
|
|
|
if (options->permit_empty_passwd == -1)
|
2000-02-28 19:03:50 +00:00
|
|
|
options->permit_empty_passwd = 0;
|
2000-02-24 14:29:47 +00:00
|
|
|
if (options->use_login == -1)
|
|
|
|
options->use_login = 0;
|
2000-12-05 02:55:12 +00:00
|
|
|
if (options->allow_tcp_forwarding == -1)
|
|
|
|
options->allow_tcp_forwarding = 1;
|
2000-05-15 05:24:25 +00:00
|
|
|
if (options->protocol == SSH_PROTO_UNKNOWN)
|
|
|
|
options->protocol = SSH_PROTO_1|SSH_PROTO_2;
|
|
|
|
if (options->gateway_ports == -1)
|
|
|
|
options->gateway_ports = 0;
|
2000-09-10 09:35:38 +00:00
|
|
|
if (options->max_startups == -1)
|
|
|
|
options->max_startups = 10;
|
|
|
|
if (options->max_startups_rate == -1)
|
|
|
|
options->max_startups_rate = 100; /* 100% */
|
|
|
|
if (options->max_startups_begin == -1)
|
|
|
|
options->max_startups_begin = options->max_startups;
|
2000-02-24 14:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Keyword tokens. */
|
|
|
|
typedef enum {
|
|
|
|
sBadOption, /* == unknown option */
|
|
|
|
sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
|
|
|
|
sPermitRootLogin, sLogFacility, sLogLevel,
|
|
|
|
sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
|
|
|
|
#ifdef KRB4
|
2000-02-28 19:03:50 +00:00
|
|
|
sKrb4Authentication, sKrb4OrLocalPasswd, sKrb4TicketCleanup,
|
2000-02-24 14:29:47 +00:00
|
|
|
#endif
|
2000-02-28 19:03:50 +00:00
|
|
|
#ifdef KRB5
|
|
|
|
sKrb5Authentication, sKrb5TgtPassing,
|
|
|
|
#endif /* KRB5 */
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef AFS
|
2000-02-28 19:03:50 +00:00
|
|
|
sKrb4TgtPassing, sAFSTokenPassing,
|
2000-02-24 14:29:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SKEY
|
|
|
|
sSkeyAuthentication,
|
|
|
|
#endif
|
2000-12-05 02:55:12 +00:00
|
|
|
sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
|
2000-02-24 14:29:47 +00:00
|
|
|
sPrintMotd, sIgnoreRhosts, sX11Forwarding, sX11DisplayOffset,
|
|
|
|
sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail,
|
2000-12-05 02:55:12 +00:00
|
|
|
sUseLogin, sAllowTcpForwarding,
|
|
|
|
sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
|
2000-05-15 05:24:25 +00:00
|
|
|
sIgnoreUserKnownHosts, sHostDSAKeyFile, sCiphers, sProtocol, sPidFile,
|
2000-09-10 09:35:38 +00:00
|
|
|
sGatewayPorts, sDSAAuthentication, sConnectionsPerPeriod, sXAuthLocation,
|
|
|
|
sSubsystem, sMaxStartups
|
2000-02-24 14:29:47 +00:00
|
|
|
} ServerOpCodes;
|
|
|
|
|
|
|
|
/* Textual representation of the tokens. */
|
|
|
|
static struct {
|
|
|
|
const char *name;
|
|
|
|
ServerOpCodes opcode;
|
|
|
|
} keywords[] = {
|
|
|
|
{ "port", sPort },
|
|
|
|
{ "hostkey", sHostKeyFile },
|
2000-05-15 05:24:25 +00:00
|
|
|
{ "hostdsakey", sHostDSAKeyFile },
|
|
|
|
{ "pidfile", sPidFile },
|
2000-02-24 14:29:47 +00:00
|
|
|
{ "serverkeybits", sServerKeyBits },
|
|
|
|
{ "logingracetime", sLoginGraceTime },
|
|
|
|
{ "keyregenerationinterval", sKeyRegenerationTime },
|
|
|
|
{ "permitrootlogin", sPermitRootLogin },
|
|
|
|
{ "syslogfacility", sLogFacility },
|
|
|
|
{ "loglevel", sLogLevel },
|
|
|
|
{ "rhostsauthentication", sRhostsAuthentication },
|
|
|
|
{ "rhostsrsaauthentication", sRhostsRSAAuthentication },
|
|
|
|
{ "rsaauthentication", sRSAAuthentication },
|
2000-05-15 05:24:25 +00:00
|
|
|
{ "dsaauthentication", sDSAAuthentication },
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef KRB4
|
2000-02-28 19:03:50 +00:00
|
|
|
{ "kerberos4authentication", sKrb4Authentication },
|
|
|
|
{ "kerberos4orlocalpasswd", sKrb4OrLocalPasswd },
|
|
|
|
{ "kerberos4ticketcleanup", sKrb4TicketCleanup },
|
2000-02-24 14:29:47 +00:00
|
|
|
#endif
|
2000-02-28 19:03:50 +00:00
|
|
|
#ifdef KRB5
|
|
|
|
{ "kerberos5authentication", sKrb5Authentication },
|
|
|
|
{ "kerberos5tgtpassing", sKrb5TgtPassing },
|
|
|
|
#endif /* KRB5 */
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef AFS
|
2000-02-28 19:03:50 +00:00
|
|
|
{ "kerberos4tgtpassing", sKrb4TgtPassing },
|
2000-02-24 14:29:47 +00:00
|
|
|
{ "afstokenpassing", sAFSTokenPassing },
|
|
|
|
#endif
|
|
|
|
{ "passwordauthentication", sPasswordAuthentication },
|
2000-12-05 02:55:12 +00:00
|
|
|
{ "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef SKEY
|
|
|
|
{ "skeyauthentication", sSkeyAuthentication },
|
|
|
|
#endif
|
|
|
|
{ "checkmail", sCheckMail },
|
|
|
|
{ "listenaddress", sListenAddress },
|
|
|
|
{ "printmotd", sPrintMotd },
|
|
|
|
{ "ignorerhosts", sIgnoreRhosts },
|
|
|
|
{ "ignoreuserknownhosts", sIgnoreUserKnownHosts },
|
|
|
|
{ "x11forwarding", sX11Forwarding },
|
|
|
|
{ "x11displayoffset", sX11DisplayOffset },
|
2000-09-10 09:35:38 +00:00
|
|
|
{ "xauthlocation", sXAuthLocation },
|
2000-02-24 14:29:47 +00:00
|
|
|
{ "strictmodes", sStrictModes },
|
|
|
|
{ "permitemptypasswords", sEmptyPasswd },
|
|
|
|
{ "uselogin", sUseLogin },
|
|
|
|
{ "randomseed", sRandomSeedFile },
|
|
|
|
{ "keepalive", sKeepAlives },
|
2000-12-05 02:55:12 +00:00
|
|
|
{ "allowtcpforwarding", sAllowTcpForwarding },
|
2000-02-24 14:29:47 +00:00
|
|
|
{ "allowusers", sAllowUsers },
|
|
|
|
{ "denyusers", sDenyUsers },
|
|
|
|
{ "allowgroups", sAllowGroups },
|
|
|
|
{ "denygroups", sDenyGroups },
|
2000-05-15 05:24:25 +00:00
|
|
|
{ "ciphers", sCiphers },
|
|
|
|
{ "protocol", sProtocol },
|
|
|
|
{ "gatewayports", sGatewayPorts },
|
2000-02-24 15:29:42 +00:00
|
|
|
{ "connectionsperperiod", sConnectionsPerPeriod },
|
2000-09-10 09:35:38 +00:00
|
|
|
{ "subsystem", sSubsystem },
|
|
|
|
{ "maxstartups", sMaxStartups },
|
2000-02-24 14:29:47 +00:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the number of the token pointed to by cp of length len. Never
|
|
|
|
* returns if the token is not known.
|
|
|
|
*/
|
|
|
|
|
2000-05-15 05:24:25 +00:00
|
|
|
static ServerOpCodes
|
2000-02-24 14:29:47 +00:00
|
|
|
parse_token(const char *cp, const char *filename,
|
|
|
|
int linenum)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; keywords[i].name; i++)
|
|
|
|
if (strcasecmp(cp, keywords[i].name) == 0)
|
|
|
|
return keywords[i].opcode;
|
|
|
|
|
|
|
|
fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
|
|
|
|
filename, linenum, cp);
|
|
|
|
return sBadOption;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* add listen address
|
|
|
|
*/
|
2000-05-15 05:24:25 +00:00
|
|
|
void
|
2000-02-24 14:29:47 +00:00
|
|
|
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. */
|
|
|
|
|
2000-05-15 05:24:25 +00:00
|
|
|
void
|
2000-02-24 14:29:47 +00:00
|
|
|
read_server_config(ServerOptions *options, const char *filename)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char line[1024];
|
2000-09-10 09:35:38 +00:00
|
|
|
char *cp, **charptr, *arg;
|
2000-02-24 14:29:47 +00:00
|
|
|
int linenum, *intptr, value;
|
|
|
|
int bad_options = 0;
|
|
|
|
ServerOpCodes opcode;
|
2000-09-10 09:35:38 +00:00
|
|
|
int i;
|
2000-02-24 14:29:47 +00:00
|
|
|
|
|
|
|
f = fopen(filename, "r");
|
|
|
|
if (!f) {
|
|
|
|
perror(filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
linenum = 0;
|
|
|
|
while (fgets(line, sizeof(line), f)) {
|
|
|
|
linenum++;
|
2000-09-10 09:35:38 +00:00
|
|
|
cp = line;
|
|
|
|
arg = strdelim(&cp);
|
|
|
|
/* Ignore leading whitespace */
|
|
|
|
if (*arg == '\0')
|
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!*arg || *arg == '#')
|
2000-02-24 14:29:47 +00:00
|
|
|
continue;
|
2000-09-10 09:35:38 +00:00
|
|
|
opcode = parse_token(arg, filename, linenum);
|
2000-02-24 14:29:47 +00:00
|
|
|
switch (opcode) {
|
|
|
|
case sBadOption:
|
|
|
|
bad_options++;
|
|
|
|
continue;
|
|
|
|
case sPort:
|
|
|
|
/* 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",
|
2000-05-15 05:24:25 +00:00
|
|
|
filename, linenum);
|
2000-09-10 09:35:38 +00:00
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!arg || *arg == '\0')
|
2000-02-24 14:29:47 +00:00
|
|
|
fatal("%s line %d: missing port number.\n",
|
|
|
|
filename, linenum);
|
2000-09-10 09:35:38 +00:00
|
|
|
options->ports[options->num_ports++] = atoi(arg);
|
2000-02-24 14:29:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sServerKeyBits:
|
|
|
|
intptr = &options->server_key_bits;
|
|
|
|
parse_int:
|
2000-09-10 09:35:38 +00:00
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!arg || *arg == '\0') {
|
2000-02-24 14:29:47 +00:00
|
|
|
fprintf(stderr, "%s line %d: missing integer value.\n",
|
|
|
|
filename, linenum);
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-09-10 09:35:38 +00:00
|
|
|
value = atoi(arg);
|
|
|
|
if (value == 0) {
|
2000-02-24 15:29:42 +00:00
|
|
|
fprintf(stderr, "%s line %d: invalid integer value.\n",
|
|
|
|
filename, linenum);
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-02-24 14:29:47 +00:00
|
|
|
if (*intptr == -1)
|
|
|
|
*intptr = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sLoginGraceTime:
|
|
|
|
intptr = &options->login_grace_time;
|
|
|
|
goto parse_int;
|
|
|
|
|
|
|
|
case sKeyRegenerationTime:
|
|
|
|
intptr = &options->key_regeneration_time;
|
|
|
|
goto parse_int;
|
|
|
|
|
|
|
|
case sListenAddress:
|
2000-09-10 09:35:38 +00:00
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!arg || *arg == '\0')
|
2000-02-24 14:29:47 +00:00
|
|
|
fatal("%s line %d: missing inet addr.\n",
|
|
|
|
filename, linenum);
|
2000-09-10 09:35:38 +00:00
|
|
|
add_listen_addr(options, arg);
|
2000-02-24 14:29:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sHostKeyFile:
|
2000-05-15 05:24:25 +00:00
|
|
|
case sHostDSAKeyFile:
|
|
|
|
charptr = (opcode == sHostKeyFile ) ?
|
|
|
|
&options->host_key_file : &options->host_dsa_key_file;
|
2000-09-10 09:35:38 +00:00
|
|
|
parse_filename:
|
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!arg || *arg == '\0') {
|
2000-02-24 14:29:47 +00:00
|
|
|
fprintf(stderr, "%s line %d: missing file name.\n",
|
2000-05-15 05:24:25 +00:00
|
|
|
filename, linenum);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (*charptr == NULL)
|
2000-09-10 09:35:38 +00:00
|
|
|
*charptr = tilde_expand_filename(arg, getuid());
|
2000-05-15 05:24:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sPidFile:
|
|
|
|
charptr = &options->pid_file;
|
2000-09-10 09:35:38 +00:00
|
|
|
goto parse_filename;
|
2000-02-24 14:29:47 +00:00
|
|
|
|
|
|
|
case sRandomSeedFile:
|
|
|
|
fprintf(stderr, "%s line %d: \"randomseed\" option is obsolete.\n",
|
|
|
|
filename, linenum);
|
2000-09-10 09:35:38 +00:00
|
|
|
arg = strdelim(&cp);
|
2000-02-24 14:29:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sPermitRootLogin:
|
|
|
|
intptr = &options->permit_root_login;
|
2000-09-10 09:35:38 +00:00
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!arg || *arg == '\0') {
|
2000-02-24 14:29:47 +00:00
|
|
|
fprintf(stderr, "%s line %d: missing yes/without-password/no argument.\n",
|
|
|
|
filename, linenum);
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-09-10 09:35:38 +00:00
|
|
|
if (strcmp(arg, "without-password") == 0)
|
2000-02-24 14:29:47 +00:00
|
|
|
value = 2;
|
2000-09-10 09:35:38 +00:00
|
|
|
else if (strcmp(arg, "yes") == 0)
|
2000-02-24 14:29:47 +00:00
|
|
|
value = 1;
|
2000-09-10 09:35:38 +00:00
|
|
|
else if (strcmp(arg, "no") == 0)
|
2000-02-24 14:29:47 +00:00
|
|
|
value = 0;
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "%s line %d: Bad yes/without-password/no argument: %s\n",
|
2000-09-10 09:35:38 +00:00
|
|
|
filename, linenum, arg);
|
2000-02-24 14:29:47 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (*intptr == -1)
|
|
|
|
*intptr = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sIgnoreRhosts:
|
|
|
|
intptr = &options->ignore_rhosts;
|
|
|
|
parse_flag:
|
2000-09-10 09:35:38 +00:00
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!arg || *arg == '\0') {
|
2000-02-24 14:29:47 +00:00
|
|
|
fprintf(stderr, "%s line %d: missing yes/no argument.\n",
|
|
|
|
filename, linenum);
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-09-10 09:35:38 +00:00
|
|
|
if (strcmp(arg, "yes") == 0)
|
2000-02-24 14:29:47 +00:00
|
|
|
value = 1;
|
2000-09-10 09:35:38 +00:00
|
|
|
else if (strcmp(arg, "no") == 0)
|
2000-02-24 14:29:47 +00:00
|
|
|
value = 0;
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
|
2000-09-10 09:35:38 +00:00
|
|
|
filename, linenum, arg);
|
2000-02-24 14:29:47 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (*intptr == -1)
|
|
|
|
*intptr = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sIgnoreUserKnownHosts:
|
|
|
|
intptr = &options->ignore_user_known_hosts;
|
2000-03-22 09:36:35 +00:00
|
|
|
goto parse_flag;
|
2000-02-24 14:29:47 +00:00
|
|
|
|
|
|
|
case sRhostsAuthentication:
|
|
|
|
intptr = &options->rhosts_authentication;
|
|
|
|
goto parse_flag;
|
|
|
|
|
|
|
|
case sRhostsRSAAuthentication:
|
|
|
|
intptr = &options->rhosts_rsa_authentication;
|
|
|
|
goto parse_flag;
|
|
|
|
|
|
|
|
case sRSAAuthentication:
|
|
|
|
intptr = &options->rsa_authentication;
|
|
|
|
goto parse_flag;
|
|
|
|
|
2000-05-15 05:24:25 +00:00
|
|
|
case sDSAAuthentication:
|
|
|
|
intptr = &options->dsa_authentication;
|
|
|
|
goto parse_flag;
|
|
|
|
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef KRB4
|
2000-02-28 19:03:50 +00:00
|
|
|
case sKrb4Authentication:
|
|
|
|
intptr = &options->krb4_authentication;
|
2000-02-24 14:29:47 +00:00
|
|
|
goto parse_flag;
|
|
|
|
|
2000-02-28 19:03:50 +00:00
|
|
|
case sKrb4OrLocalPasswd:
|
|
|
|
intptr = &options->krb4_or_local_passwd;
|
2000-02-24 14:29:47 +00:00
|
|
|
goto parse_flag;
|
|
|
|
|
2000-02-28 19:03:50 +00:00
|
|
|
case sKrb4TicketCleanup:
|
|
|
|
intptr = &options->krb4_ticket_cleanup;
|
2000-02-24 14:29:47 +00:00
|
|
|
goto parse_flag;
|
|
|
|
#endif
|
|
|
|
|
2000-02-28 19:03:50 +00:00
|
|
|
#ifdef KRB5
|
|
|
|
case sKrb5Authentication:
|
|
|
|
intptr = &options->krb5_authentication;
|
|
|
|
goto parse_flag;
|
|
|
|
|
|
|
|
case sKrb5TgtPassing:
|
|
|
|
intptr = &options->krb5_tgt_passing;
|
|
|
|
goto parse_flag;
|
|
|
|
#endif /* KRB5 */
|
|
|
|
|
2000-02-24 14:29:47 +00:00
|
|
|
#ifdef AFS
|
2000-02-28 19:03:50 +00:00
|
|
|
case sKrb4TgtPassing:
|
|
|
|
intptr = &options->krb4_tgt_passing;
|
2000-02-24 14:29:47 +00:00
|
|
|
goto parse_flag;
|
|
|
|
|
|
|
|
case sAFSTokenPassing:
|
|
|
|
intptr = &options->afs_token_passing;
|
|
|
|
goto parse_flag;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case sPasswordAuthentication:
|
|
|
|
intptr = &options->password_authentication;
|
|
|
|
goto parse_flag;
|
|
|
|
|
2000-12-05 02:55:12 +00:00
|
|
|
case sKbdInteractiveAuthentication:
|
|
|
|
intptr = &options->kbd_interactive_authentication;
|
|
|
|
goto parse_flag;
|
|
|
|
|
2000-02-24 14:29:47 +00:00
|
|
|
case sCheckMail:
|
|
|
|
intptr = &options->check_mail;
|
|
|
|
goto parse_flag;
|
|
|
|
|
|
|
|
#ifdef SKEY
|
|
|
|
case sSkeyAuthentication:
|
|
|
|
intptr = &options->skey_authentication;
|
|
|
|
goto parse_flag;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case sPrintMotd:
|
|
|
|
intptr = &options->print_motd;
|
|
|
|
goto parse_flag;
|
|
|
|
|
|
|
|
case sX11Forwarding:
|
|
|
|
intptr = &options->x11_forwarding;
|
|
|
|
goto parse_flag;
|
|
|
|
|
|
|
|
case sX11DisplayOffset:
|
|
|
|
intptr = &options->x11_display_offset;
|
|
|
|
goto parse_int;
|
|
|
|
|
2000-09-10 09:35:38 +00:00
|
|
|
case sXAuthLocation:
|
|
|
|
charptr = &options->xauth_location;
|
|
|
|
goto parse_filename;
|
|
|
|
|
2000-02-24 14:29:47 +00:00
|
|
|
case sStrictModes:
|
|
|
|
intptr = &options->strict_modes;
|
|
|
|
goto parse_flag;
|
|
|
|
|
|
|
|
case sKeepAlives:
|
|
|
|
intptr = &options->keepalives;
|
|
|
|
goto parse_flag;
|
|
|
|
|
|
|
|
case sEmptyPasswd:
|
|
|
|
intptr = &options->permit_empty_passwd;
|
|
|
|
goto parse_flag;
|
|
|
|
|
|
|
|
case sUseLogin:
|
|
|
|
intptr = &options->use_login;
|
|
|
|
goto parse_flag;
|
|
|
|
|
2000-05-15 05:24:25 +00:00
|
|
|
case sGatewayPorts:
|
|
|
|
intptr = &options->gateway_ports;
|
|
|
|
goto parse_flag;
|
|
|
|
|
2000-02-24 14:29:47 +00:00
|
|
|
case sLogFacility:
|
|
|
|
intptr = (int *) &options->log_facility;
|
2000-09-10 09:35:38 +00:00
|
|
|
arg = strdelim(&cp);
|
|
|
|
value = log_facility_number(arg);
|
2000-02-24 14:29:47 +00:00
|
|
|
if (value == (SyslogFacility) - 1)
|
|
|
|
fatal("%.200s line %d: unsupported log facility '%s'\n",
|
2000-09-10 09:35:38 +00:00
|
|
|
filename, linenum, arg ? arg : "<NONE>");
|
2000-02-24 14:29:47 +00:00
|
|
|
if (*intptr == -1)
|
|
|
|
*intptr = (SyslogFacility) value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sLogLevel:
|
|
|
|
intptr = (int *) &options->log_level;
|
2000-09-10 09:35:38 +00:00
|
|
|
arg = strdelim(&cp);
|
|
|
|
value = log_level_number(arg);
|
2000-02-24 14:29:47 +00:00
|
|
|
if (value == (LogLevel) - 1)
|
|
|
|
fatal("%.200s line %d: unsupported log level '%s'\n",
|
2000-09-10 09:35:38 +00:00
|
|
|
filename, linenum, arg ? arg : "<NONE>");
|
2000-02-24 14:29:47 +00:00
|
|
|
if (*intptr == -1)
|
|
|
|
*intptr = (LogLevel) value;
|
|
|
|
break;
|
|
|
|
|
2000-12-05 02:55:12 +00:00
|
|
|
case sAllowTcpForwarding:
|
|
|
|
intptr = &options->allow_tcp_forwarding;
|
|
|
|
goto parse_flag;
|
|
|
|
|
2000-02-24 14:29:47 +00:00
|
|
|
case sAllowUsers:
|
2000-09-10 09:35:38 +00:00
|
|
|
while ((arg = strdelim(&cp)) && *arg != '\0') {
|
2000-02-24 15:29:42 +00:00
|
|
|
if (options->num_allow_users >= MAX_ALLOW_USERS)
|
2000-05-15 05:24:25 +00:00
|
|
|
fatal("%.200s line %d: too many allow users.\n",
|
|
|
|
filename, linenum);
|
2000-09-10 09:35:38 +00:00
|
|
|
options->allow_users[options->num_allow_users++] = xstrdup(arg);
|
2000-02-24 14:29:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sDenyUsers:
|
2000-09-10 09:35:38 +00:00
|
|
|
while ((arg = strdelim(&cp)) && *arg != '\0') {
|
2000-06-06 06:16:55 +00:00
|
|
|
if (options->num_deny_users >= MAX_DENY_USERS)
|
2000-05-15 05:24:25 +00:00
|
|
|
fatal("%.200s line %d: too many deny users.\n",
|
|
|
|
filename, linenum);
|
2000-09-10 09:35:38 +00:00
|
|
|
options->deny_users[options->num_deny_users++] = xstrdup(arg);
|
2000-02-24 14:29:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sAllowGroups:
|
2000-09-10 09:35:38 +00:00
|
|
|
while ((arg = strdelim(&cp)) && *arg != '\0') {
|
2000-02-24 15:29:42 +00:00
|
|
|
if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
|
2000-05-15 05:24:25 +00:00
|
|
|
fatal("%.200s line %d: too many allow groups.\n",
|
|
|
|
filename, linenum);
|
2000-09-10 09:35:38 +00:00
|
|
|
options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
|
2000-02-24 14:29:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sDenyGroups:
|
2000-09-10 09:35:38 +00:00
|
|
|
while ((arg = strdelim(&cp)) && *arg != '\0') {
|
2000-02-24 15:29:42 +00:00
|
|
|
if (options->num_deny_groups >= MAX_DENY_GROUPS)
|
2000-05-15 05:24:25 +00:00
|
|
|
fatal("%.200s line %d: too many deny groups.\n",
|
|
|
|
filename, linenum);
|
2000-09-10 09:35:38 +00:00
|
|
|
options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
|
2000-02-24 14:29:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-05-15 05:24:25 +00:00
|
|
|
case sCiphers:
|
2000-09-10 09:35:38 +00:00
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!arg || *arg == '\0')
|
2000-06-03 09:58:15 +00:00
|
|
|
fatal("%s line %d: Missing argument.", filename, linenum);
|
2000-09-10 09:35:38 +00:00
|
|
|
if (!ciphers_valid(arg))
|
2000-05-15 05:24:25 +00:00
|
|
|
fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
|
2000-09-10 09:35:38 +00:00
|
|
|
filename, linenum, arg ? arg : "<NONE>");
|
2000-05-15 05:24:25 +00:00
|
|
|
if (options->ciphers == NULL)
|
2000-09-10 09:35:38 +00:00
|
|
|
options->ciphers = xstrdup(arg);
|
2000-05-15 05:24:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sProtocol:
|
|
|
|
intptr = &options->protocol;
|
2000-09-10 09:35:38 +00:00
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!arg || *arg == '\0')
|
2000-06-03 09:58:15 +00:00
|
|
|
fatal("%s line %d: Missing argument.", filename, linenum);
|
2000-09-10 09:35:38 +00:00
|
|
|
value = proto_spec(arg);
|
2000-05-15 05:24:25 +00:00
|
|
|
if (value == SSH_PROTO_UNKNOWN)
|
|
|
|
fatal("%s line %d: Bad protocol spec '%s'.",
|
2000-09-10 09:35:38 +00:00
|
|
|
filename, linenum, arg ? arg : "<NONE>");
|
2000-05-15 05:24:25 +00:00
|
|
|
if (*intptr == SSH_PROTO_UNKNOWN)
|
|
|
|
*intptr = value;
|
|
|
|
break;
|
|
|
|
|
2000-02-24 15:29:42 +00:00
|
|
|
case sConnectionsPerPeriod:
|
2001-02-18 01:33:31 +00:00
|
|
|
(void)strdelim(&cp);
|
2001-02-04 20:15:53 +00:00
|
|
|
error("ConnectionsPerPeriod has been deprecated!");
|
2000-02-24 15:29:42 +00:00
|
|
|
break;
|
|
|
|
|
2000-09-10 09:35:38 +00:00
|
|
|
case sSubsystem:
|
|
|
|
if(options->num_subsystems >= MAX_SUBSYSTEMS) {
|
|
|
|
fatal("%s line %d: too many subsystems defined.",
|
|
|
|
filename, linenum);
|
|
|
|
}
|
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!arg || *arg == '\0')
|
|
|
|
fatal("%s line %d: Missing subsystem name.",
|
|
|
|
filename, linenum);
|
|
|
|
for (i = 0; i < options->num_subsystems; i++)
|
|
|
|
if(strcmp(arg, options->subsystem_name[i]) == 0)
|
|
|
|
fatal("%s line %d: Subsystem '%s' already defined.",
|
|
|
|
filename, linenum, arg);
|
|
|
|
options->subsystem_name[options->num_subsystems] = xstrdup(arg);
|
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!arg || *arg == '\0')
|
|
|
|
fatal("%s line %d: Missing subsystem command.",
|
|
|
|
filename, linenum);
|
|
|
|
options->subsystem_command[options->num_subsystems] = xstrdup(arg);
|
|
|
|
options->num_subsystems++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sMaxStartups:
|
|
|
|
arg = strdelim(&cp);
|
|
|
|
if (!arg || *arg == '\0')
|
|
|
|
fatal("%s line %d: Missing MaxStartups spec.",
|
|
|
|
filename, linenum);
|
|
|
|
if (sscanf(arg, "%d:%d:%d",
|
|
|
|
&options->max_startups_begin,
|
|
|
|
&options->max_startups_rate,
|
|
|
|
&options->max_startups) == 3) {
|
|
|
|
if (options->max_startups_begin >
|
|
|
|
options->max_startups ||
|
|
|
|
options->max_startups_rate > 100 ||
|
|
|
|
options->max_startups_rate < 1)
|
|
|
|
fatal("%s line %d: Illegal MaxStartups spec.",
|
|
|
|
filename, linenum);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
intptr = &options->max_startups;
|
|
|
|
goto parse_int;
|
|
|
|
|
2000-02-24 14:29:47 +00:00
|
|
|
default:
|
2000-02-24 15:29:42 +00:00
|
|
|
fatal("%.200s line %d: Missing handler for opcode %s (%d)\n",
|
2000-09-10 09:35:38 +00:00
|
|
|
filename, linenum,arg, opcode);
|
2000-02-24 14:29:47 +00:00
|
|
|
}
|
2000-09-10 09:35:38 +00:00
|
|
|
if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s line %d: garbage at end of line; \"%.200s\".\n",
|
|
|
|
filename, linenum, arg);
|
|
|
|
exit(1);
|
2000-05-15 05:24:25 +00:00
|
|
|
}
|
2000-02-24 14:29:47 +00:00
|
|
|
}
|
|
|
|
fclose(f);
|
2000-05-15 05:24:25 +00:00
|
|
|
if (bad_options > 0) {
|
2000-02-24 15:29:42 +00:00
|
|
|
fatal("%.200s: terminating, %d bad configuration options\n",
|
2000-02-24 14:29:47 +00:00
|
|
|
filename, bad_options);
|
2000-05-15 05:24:25 +00:00
|
|
|
}
|
2000-02-24 14:29:47 +00:00
|
|
|
}
|