servconf.c revision 6f8d59d8fcaf391990ca04c7bdcf65ab23320fe0
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
*
* 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".
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "includes.h"
RCSID("$OpenBSD: servconf.c,v 1.115 2002/09/04 18:52:42 stevesk Exp $");
#ifdef HAVE_DEFOPEN
#include <deflt.h>
#endif /* HAVE_DEFOPEN */
#if defined(KRB4)
#include <krb.h>
#endif
#if defined(KRB5)
#ifdef HEIMDAL
#include <krb.h>
#else
/* Bodge - but then, so is using the kerberos IV KEYFILE to get a Kerberos V
* keytab */
#define KEYFILE "/etc/krb5.keytab"
#endif
#endif
#ifdef AFS
#include <kafs.h>
#endif
#include "ssh.h"
#include "log.h"
#include "servconf.h"
#include "xmalloc.h"
#include "compat.h"
#include "pathnames.h"
#include "tildexpand.h"
#include "misc.h"
#include "cipher.h"
#include "kex.h"
#include "mac.h"
#include "auth.h"
/* AF_UNSPEC or AF_INET or AF_INET6 */
extern int IPv4or6;
/*
* Initializes the server options to their initial (unset) values. Some of those
* that stay unset after the command line options and configuration files are
* read are set to their default values in fill_default_server_options().
*/
void
{
/* Portable-specific options */
/* Standard Options */
options->ports_from_cmdline = 0;
options->num_host_key_files = 0;
#ifdef GSSAPI
#endif
#endif
#endif
#ifdef AFS
#endif
options->num_allow_users = 0;
options->num_deny_users = 0;
options->num_allow_groups = 0;
options->num_deny_groups = 0;
options->num_subsystems = 0;
}
#ifdef HAVE_DEFOPEN
/*
*
* PermitRootLogin
* PermitEmptyPasswords
* LoginGraceTime
*
* CONSOLE=* -> PermitRootLogin=without-password
* #CONSOLE=* -> PermitRootLogin=yes
*
* PASSREQ=YES -> PermitEmptyPasswords=no
* PASSREQ=NO -> PermitEmptyPasswords=yes
* #PASSREQ=* -> PermitEmptyPasswords=no
*
* TIMEOUT=<secs> -> LoginGraceTime=<secs>
* #TIMEOUT=<secs> -> LoginGraceTime=300
*/
static
void
{
int flags;
char *ptr;
if (defopen(_PATH_DEFAULT_LOGIN))
return;
/* Ignore case */
options->permit_empty_passwd = 0;
}
}
}
else
}
}
#endif /* HAVE_DEFOPEN */
void
{
#ifdef HAVE_DEFOPEN
#endif /* HAVE_DEFOPEN */
/* Portable-specific options */
/* Standard Options */
if (options->num_host_key_files == 0) {
/* fill default hostkeys for protocols */
#ifndef GSSAPI
/* With GSS keyex we can run v2 w/ no host keys */
}
#endif /* GSSAPI */
}
options->rhosts_authentication = 0;
#ifdef GSSAPI
#endif
#endif
options->kerberos_tgt_passing = 0;
#endif
#ifdef AFS
options->afs_token_passing = 0;
#endif
options->permit_empty_passwd = 0;
options->permit_user_env = 0;
options->gateway_ports = 0;
options->client_alive_interval = 0;
/* authorized_keys_file2 falls back to authorized_keys_file */
else
}
}
/* Keyword tokens. */
typedef enum {
sBadOption, /* == unknown option */
/* Portable-specific options */
/* Standard Options */
#ifdef GSSAPI
#endif /* GSSAPI */
#endif
#endif
#ifdef AFS
#endif
/* Textual representation of the tokens. */
static struct {
const char *name;
} keywords[] = {
/* Portable-specific options */
{ "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt },
/* Standard Options */
{ "port", sPort },
{ "hostkey", sHostKeyFile },
{ "pidfile", sPidFile },
{ "serverkeybits", sServerKeyBits },
{ "logingracetime", sLoginGraceTime },
{ "keyregenerationinterval", sKeyRegenerationTime },
{ "permitrootlogin", sPermitRootLogin },
{ "syslogfacility", sLogFacility },
{ "loglevel", sLogLevel },
{ "rhostsauthentication", sRhostsAuthentication },
{ "rhostsrsaauthentication", sRhostsRSAAuthentication },
{ "hostbasedauthentication", sHostbasedAuthentication },
{ "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
{ "rsaauthentication", sRSAAuthentication },
{ "pubkeyauthentication", sPubkeyAuthentication },
#ifdef GSSAPI
{ "gssapiauthentication", sGssAuthentication },
{ "gssapikeyexchange", sGssKeyEx },
{ "gssapistoredelegatedcredentials", sGssStoreDelegCreds },
#ifndef SUNW_GSSAPI
{ "gssusesessionccache", sGssUseSessionCredCache },
{ "gssusesessioncredcache", sGssUseSessionCredCache },
{ "gsscleanupcreds", sGssCleanupCreds },
#endif /* SUNW_GSSAPI */
#endif
{ "kerberosauthentication", sKerberosAuthentication },
{ "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
{ "kerberosticketcleanup", sKerberosTicketCleanup },
#endif
{ "kerberostgtpassing", sKerberosTgtPassing },
#endif
#ifdef AFS
{ "afstokenpassing", sAFSTokenPassing },
#endif
{ "passwordauthentication", sPasswordAuthentication },
{ "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
{ "challengeresponseauthentication", sChallengeResponseAuthentication },
{ "checkmail", sDeprecated },
{ "listenaddress", sListenAddress },
{ "printmotd", sPrintMotd },
{ "printlastlog", sPrintLastLog },
{ "ignorerhosts", sIgnoreRhosts },
{ "ignoreuserknownhosts", sIgnoreUserKnownHosts },
{ "x11forwarding", sX11Forwarding },
{ "x11displayoffset", sX11DisplayOffset },
{ "x11uselocalhost", sX11UseLocalhost },
{ "xauthlocation", sXAuthLocation },
{ "strictmodes", sStrictModes },
{ "permitemptypasswords", sEmptyPasswd },
{ "permituserenvironment", sPermitUserEnvironment },
{ "uselogin", sUseLogin },
{ "compression", sCompression },
{ "keepalive", sKeepAlives },
{ "allowtcpforwarding", sAllowTcpForwarding },
{ "allowusers", sAllowUsers },
{ "denyusers", sDenyUsers },
{ "allowgroups", sAllowGroups },
{ "denygroups", sDenyGroups },
{ "ciphers", sCiphers },
{ "macs", sMacs },
{ "protocol", sProtocol },
{ "gatewayports", sGatewayPorts },
{ "subsystem", sSubsystem },
{ "maxstartups", sMaxStartups },
{ "banner", sBanner },
{ "verifyreversemapping", sVerifyReverseMapping },
{ "reversemappingcheck", sVerifyReverseMapping },
{ "clientaliveinterval", sClientAliveInterval },
{ "clientalivecountmax", sClientAliveCountMax },
{ "authorizedkeysfile", sAuthorizedKeysFile },
{ "authorizedkeysfile2", sAuthorizedKeysFile2 },
{ "maxauthtries", sMaxAuthTries },
{ "maxauthtrieslog", sMaxAuthTriesLog },
{ "useprivilegeseparation", sUsePrivilegeSeparation},
{ "lookupclienthostnames", sLookupClientHostnames},
{ "useopensslengine", sUseOpenSSLEngine},
{ "chrootdirectory", sChrootDirectory},
{ NULL, sBadOption }
};
/*
* Returns the number of the token pointed to by cp or sBadOption.
*/
static ServerOpCodes
int linenum)
{
u_int i;
error("%s: line %d: Bad configuration option: %s",
return sBadOption;
}
static void
{
int i;
if (port == 0)
else
}
static void
{
char strport[NI_MAXSERV];
int gaierr;
fatal("bad addr or host: %s (%s)",
;
}
int
{
/* Ignore leading whitespace */
if (*arg == '\0')
return 0;
switch (opcode) {
/* Portable-specific options */
goto parse_flag;
/* Standard Options */
case sBadOption:
return -1;
case sPort:
/* ignore ports from configfile if cmdline specifies ports */
if (options->ports_from_cmdline)
return 0;
fatal("%s line %d: ports must be specified before "
fatal("%s line %d: too many ports.",
fatal("%s line %d: missing port number.",
fatal("%s line %d: Badly formatted port number.",
break;
case sServerKeyBits:
fatal("%s line %d: missing integer value.",
if (*intptr == -1)
break;
case sLoginGraceTime:
fatal("%s line %d: missing time value.",
fatal("%s line %d: invalid time value.",
if (*intptr == -1)
break;
case sKeyRegenerationTime:
goto parse_time;
case sListenAddress:
fatal("%s line %d: missing inet addr.",
if (*arg == '[') {
fatal("%s line %d: bad ipv6 inet addr usage.",
arg++;
break;
}
if (*p == ':') {
p++;
if (*p == '\0')
fatal("%s line %d: bad inet addr:port usage.",
else {
*(p-1) = '\0';
fatal("%s line %d: bad port number.",
}
} else if (*p == '\0')
else
fatal("%s line %d: bad inet addr usage.",
break;
case sHostKeyFile:
if (*intptr >= MAX_HOSTKEYS)
fatal("%s line %d: too many host keys specified (max %d).",
fatal("%s line %d: missing file name.",
/* increase optional counter */
}
break;
case sPidFile:
goto parse_filename;
case sPermitRootLogin:
fatal("%s line %d: missing yes/"
value = 0; /* silence compiler */
value = PERMIT_YES;
else
fatal("%s line %d: Bad yes/"
if (*intptr == -1)
break;
case sIgnoreRhosts:
value = 0; /* silence compiler */
value = 1;
value = 0;
else
if (*intptr == -1)
break;
case sIgnoreUserKnownHosts:
goto parse_flag;
case sRhostsAuthentication:
goto parse_flag;
case sRhostsRSAAuthentication:
goto parse_flag;
case sHostbasedAuthentication:
goto parse_flag;
goto parse_flag;
case sRSAAuthentication:
goto parse_flag;
case sPubkeyAuthentication:
goto parse_flag;
#ifdef GSSAPI
case sGssAuthentication:
goto parse_flag;
case sGssKeyEx:
goto parse_flag;
case sGssStoreDelegCreds:
goto parse_flag;
#ifndef SUNW_GSSAPI
case sGssUseSessionCredCache:
goto parse_flag;
case sGssCleanupCreds:
goto parse_flag;
#endif /* SUNW_GSSAPI */
#endif /* GSSAPI */
case sKerberosAuthentication:
goto parse_flag;
case sKerberosOrLocalPasswd:
goto parse_flag;
case sKerberosTicketCleanup:
goto parse_flag;
#endif
case sKerberosTgtPassing:
goto parse_flag;
#endif
#ifdef AFS
case sAFSTokenPassing:
goto parse_flag;
#endif
case sPasswordAuthentication:
goto parse_flag;
goto parse_flag;
goto parse_flag;
case sPrintMotd:
goto parse_flag;
case sPrintLastLog:
goto parse_flag;
case sX11Forwarding:
goto parse_flag;
case sX11DisplayOffset:
goto parse_int;
case sX11UseLocalhost:
goto parse_flag;
case sXAuthLocation:
goto parse_filename;
case sStrictModes:
goto parse_flag;
case sKeepAlives:
goto parse_flag;
case sEmptyPasswd:
goto parse_flag;
case sPermitUserEnvironment:
goto parse_flag;
case sUseLogin:
goto parse_flag;
case sCompression:
goto parse_flag;
case sGatewayPorts:
break;
else
fatal("%.200s line %d: Bad yes/no/clientspecified "
break;
case sVerifyReverseMapping:
goto parse_flag;
case sLogFacility:
if (value == SYSLOG_FACILITY_NOT_SET)
fatal("%.200s line %d: unsupported log facility '%s'",
if (*intptr == -1)
break;
case sLogLevel:
if (value == SYSLOG_LEVEL_NOT_SET)
fatal("%.200s line %d: unsupported log level '%s'",
if (*intptr == -1)
break;
case sAllowTcpForwarding:
goto parse_flag;
case sUsePrivilegeSeparation:
log("%s line %d: ignoring UsePrivilegeSeparation option value."
while (arg)
break;
case sAllowUsers:
fatal("%s line %d: too many allow users.",
}
break;
case sDenyUsers:
fatal( "%s line %d: too many deny users.",
}
break;
case sAllowGroups:
fatal("%s line %d: too many allow groups.",
}
break;
case sDenyGroups:
fatal("%s line %d: too many deny groups.",
}
break;
case sCiphers:
if (!ciphers_valid(arg))
fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
break;
case sMacs:
fatal("%s line %d: Bad SSH2 mac spec '%s'.",
break;
case sProtocol:
if (value == SSH_PROTO_UNKNOWN)
fatal("%s line %d: Bad protocol spec '%s'.",
if (*intptr == SSH_PROTO_UNKNOWN)
break;
case sSubsystem:
fatal("%s line %d: too many subsystems defined.",
}
fatal("%s line %d: Missing subsystem name.",
for (i = 0; i < options->num_subsystems; i++)
fatal("%s line %d: Subsystem '%s' already defined.",
fatal("%s line %d: Missing subsystem command.",
/*
* Collect arguments (separate to executable), including the
* name of the executable, in a way that is easier to parse
* later.
*/
}
break;
case sMaxStartups:
fatal("%s line %d: Missing MaxStartups spec.",
if (options->max_startups_begin >
options->max_startups ||
fatal("%s line %d: Illegal MaxStartups spec.",
} else if (n != 1)
fatal("%s line %d: Illegal MaxStartups spec.",
else
break;
case sBanner:
goto parse_filename;
/*
* These options can contain %X options expanded at
* connect time, so that you can specify paths like:
*
*/
case sAuthorizedKeysFile:
case sAuthorizedKeysFile2:
goto parse_filename;
case sClientAliveInterval:
goto parse_time;
case sClientAliveCountMax:
goto parse_int;
case sMaxAuthTries:
goto parse_int;
case sMaxAuthTriesLog:
goto parse_int;
case sLookupClientHostnames:
goto parse_flag;
case sUseOpenSSLEngine:
goto parse_flag;
case sChrootDirectory:
fatal("%s line %d: missing directory name for "
break;
case sDeprecated:
log("%s line %d: Deprecated option %s",
while (arg)
break;
default:
fatal("%s line %d: Missing handler for opcode %s (%d)",
}
fatal("%s line %d: garbage at end of line; \"%.200s\".",
return 0;
}
/* Reads the server configuration file. */
void
{
int linenum, bad_options = 0;
char line[1024];
FILE *f;
if (!f) {
exit(1);
}
linenum = 0;
/* Update line number counter. */
linenum++;
bad_options++;
}
(void) fclose(f);
if (bad_options > 0)
fatal("%s: terminating, %d bad configuration options",
}
/*
* Note that "none" is a special path having the same affect on sshd
* configuration as not specifying ChrootDirectory at all.
*/
int
chroot_requested(char *chroot_directory)
{
return (chroot_directory != NULL &&
}