[BACK]Return to servconf.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/servconf.c, Revision 1.151

1.151   ! djm         1: /* $OpenBSD: servconf.c,v 1.150 2006/03/25 13:17:02 djm Exp $ */
1.1       deraadt     2: /*
1.26      deraadt     3:  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      4:  *                    All rights reserved
1.34      markus      5:  *
1.51      deraadt     6:  * As far as I am concerned, the code I have written for this software
                      7:  * can be used freely for any purpose.  Any derived versions of this
                      8:  * software must be clearly marked as such, and if the derived work is
                      9:  * incompatible with the protocol description in the RFC file, it must be
                     10:  * called by a name other than "ssh" or "Secure Shell".
1.26      deraadt    11:  */
1.1       deraadt    12:
                     13: #include "includes.h"
                     14:
                     15: #include "ssh.h"
1.62      markus     16: #include "log.h"
1.1       deraadt    17: #include "servconf.h"
                     18: #include "xmalloc.h"
1.33      markus     19: #include "compat.h"
1.60      markus     20: #include "pathnames.h"
1.62      markus     21: #include "misc.h"
                     22: #include "cipher.h"
1.66      markus     23: #include "kex.h"
                     24: #include "mac.h"
1.1       deraadt    25:
1.84      itojun     26: static void add_listen_addr(ServerOptions *, char *, u_short);
                     27: static void add_one_listen_addr(ServerOptions *, char *, u_short);
1.29      markus     28:
1.102     provos     29: /* Use of privilege separation or not */
                     30: extern int use_privsep;
1.62      markus     31:
1.1       deraadt    32: /* Initializes the server options to their default values. */
                     33:
1.34      markus     34: void
1.25      markus     35: initialize_server_options(ServerOptions *options)
1.1       deraadt    36: {
1.25      markus     37:        memset(options, 0, sizeof(*options));
1.29      markus     38:        options->num_ports = 0;
                     39:        options->ports_from_cmdline = 0;
                     40:        options->listen_addrs = NULL;
1.138     djm        41:        options->address_family = -1;
1.54      markus     42:        options->num_host_key_files = 0;
1.36      markus     43:        options->pid_file = NULL;
1.25      markus     44:        options->server_key_bits = -1;
                     45:        options->login_grace_time = -1;
                     46:        options->key_regeneration_time = -1;
1.67      markus     47:        options->permit_root_login = PERMIT_NOT_SET;
1.25      markus     48:        options->ignore_rhosts = -1;
                     49:        options->ignore_user_known_hosts = -1;
                     50:        options->print_motd = -1;
1.72      stevesk    51:        options->print_lastlog = -1;
1.25      markus     52:        options->x11_forwarding = -1;
                     53:        options->x11_display_offset = -1;
1.99      stevesk    54:        options->x11_use_localhost = -1;
1.42      markus     55:        options->xauth_location = NULL;
1.25      markus     56:        options->strict_modes = -1;
1.129     markus     57:        options->tcp_keep_alive = -1;
1.101     markus     58:        options->log_facility = SYSLOG_FACILITY_NOT_SET;
                     59:        options->log_level = SYSLOG_LEVEL_NOT_SET;
1.25      markus     60:        options->rhosts_rsa_authentication = -1;
1.75      markus     61:        options->hostbased_authentication = -1;
                     62:        options->hostbased_uses_name_from_packet_only = -1;
1.25      markus     63:        options->rsa_authentication = -1;
1.54      markus     64:        options->pubkey_authentication = -1;
1.25      markus     65:        options->kerberos_authentication = -1;
                     66:        options->kerberos_or_local_passwd = -1;
                     67:        options->kerberos_ticket_cleanup = -1;
1.130     jakob      68:        options->kerberos_get_afs_token = -1;
1.125     markus     69:        options->gss_authentication=-1;
                     70:        options->gss_cleanup_creds = -1;
1.25      markus     71:        options->password_authentication = -1;
1.52      markus     72:        options->kbd_interactive_authentication = -1;
1.80      markus     73:        options->challenge_response_authentication = -1;
1.25      markus     74:        options->permit_empty_passwd = -1;
1.113     markus     75:        options->permit_user_env = -1;
1.25      markus     76:        options->use_login = -1;
1.111     markus     77:        options->compression = -1;
1.53      markus     78:        options->allow_tcp_forwarding = -1;
1.25      markus     79:        options->num_allow_users = 0;
                     80:        options->num_deny_users = 0;
                     81:        options->num_allow_groups = 0;
                     82:        options->num_deny_groups = 0;
1.33      markus     83:        options->ciphers = NULL;
1.66      markus     84:        options->macs = NULL;
1.33      markus     85:        options->protocol = SSH_PROTO_UNKNOWN;
1.38      markus     86:        options->gateway_ports = -1;
1.43      jakob      87:        options->num_subsystems = 0;
1.50      markus     88:        options->max_startups_begin = -1;
                     89:        options->max_startups_rate = -1;
1.46      markus     90:        options->max_startups = -1;
1.133     dtucker    91:        options->max_authtries = -1;
1.57      markus     92:        options->banner = NULL;
1.122     markus     93:        options->use_dns = -1;
1.77      beck       94:        options->client_alive_interval = -1;
                     95:        options->client_alive_count_max = -1;
1.82      markus     96:        options->authorized_keys_file = NULL;
                     97:        options->authorized_keys_file2 = NULL;
1.131     djm        98:        options->num_accept_env = 0;
1.145     reyk       99:        options->permit_tun = -1;
1.102     provos    100:
                    101:        /* Needs to be accessable in many places */
                    102:        use_privsep = -1;
1.1       deraadt   103: }
                    104:
1.34      markus    105: void
1.25      markus    106: fill_default_server_options(ServerOptions *options)
1.1       deraadt   107: {
1.54      markus    108:        if (options->protocol == SSH_PROTO_UNKNOWN)
                    109:                options->protocol = SSH_PROTO_1|SSH_PROTO_2;
                    110:        if (options->num_host_key_files == 0) {
                    111:                /* fill default hostkeys for protocols */
                    112:                if (options->protocol & SSH_PROTO_1)
1.97      stevesk   113:                        options->host_key_files[options->num_host_key_files++] =
                    114:                            _PATH_HOST_KEY_FILE;
                    115:                if (options->protocol & SSH_PROTO_2) {
                    116:                        options->host_key_files[options->num_host_key_files++] =
                    117:                            _PATH_HOST_RSA_KEY_FILE;
                    118:                        options->host_key_files[options->num_host_key_files++] =
                    119:                            _PATH_HOST_DSA_KEY_FILE;
                    120:                }
1.54      markus    121:        }
1.29      markus    122:        if (options->num_ports == 0)
                    123:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
                    124:        if (options->listen_addrs == NULL)
1.76      stevesk   125:                add_listen_addr(options, NULL, 0);
1.36      markus    126:        if (options->pid_file == NULL)
1.60      markus    127:                options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
1.25      markus    128:        if (options->server_key_bits == -1)
                    129:                options->server_key_bits = 768;
                    130:        if (options->login_grace_time == -1)
1.115     stevesk   131:                options->login_grace_time = 120;
1.25      markus    132:        if (options->key_regeneration_time == -1)
                    133:                options->key_regeneration_time = 3600;
1.67      markus    134:        if (options->permit_root_login == PERMIT_NOT_SET)
                    135:                options->permit_root_login = PERMIT_YES;
1.25      markus    136:        if (options->ignore_rhosts == -1)
1.30      markus    137:                options->ignore_rhosts = 1;
1.25      markus    138:        if (options->ignore_user_known_hosts == -1)
                    139:                options->ignore_user_known_hosts = 0;
                    140:        if (options->print_motd == -1)
                    141:                options->print_motd = 1;
1.72      stevesk   142:        if (options->print_lastlog == -1)
                    143:                options->print_lastlog = 1;
1.25      markus    144:        if (options->x11_forwarding == -1)
1.30      markus    145:                options->x11_forwarding = 0;
1.25      markus    146:        if (options->x11_display_offset == -1)
1.30      markus    147:                options->x11_display_offset = 10;
1.99      stevesk   148:        if (options->x11_use_localhost == -1)
                    149:                options->x11_use_localhost = 1;
1.42      markus    150:        if (options->xauth_location == NULL)
1.83      markus    151:                options->xauth_location = _PATH_XAUTH;
1.25      markus    152:        if (options->strict_modes == -1)
                    153:                options->strict_modes = 1;
1.129     markus    154:        if (options->tcp_keep_alive == -1)
                    155:                options->tcp_keep_alive = 1;
1.101     markus    156:        if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
1.25      markus    157:                options->log_facility = SYSLOG_FACILITY_AUTH;
1.101     markus    158:        if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.58      markus    159:                options->log_level = SYSLOG_LEVEL_INFO;
1.25      markus    160:        if (options->rhosts_rsa_authentication == -1)
1.30      markus    161:                options->rhosts_rsa_authentication = 0;
1.75      markus    162:        if (options->hostbased_authentication == -1)
                    163:                options->hostbased_authentication = 0;
                    164:        if (options->hostbased_uses_name_from_packet_only == -1)
                    165:                options->hostbased_uses_name_from_packet_only = 0;
1.25      markus    166:        if (options->rsa_authentication == -1)
                    167:                options->rsa_authentication = 1;
1.54      markus    168:        if (options->pubkey_authentication == -1)
                    169:                options->pubkey_authentication = 1;
1.25      markus    170:        if (options->kerberos_authentication == -1)
1.107     markus    171:                options->kerberos_authentication = 0;
1.25      markus    172:        if (options->kerberos_or_local_passwd == -1)
                    173:                options->kerberos_or_local_passwd = 1;
                    174:        if (options->kerberos_ticket_cleanup == -1)
                    175:                options->kerberos_ticket_cleanup = 1;
1.130     jakob     176:        if (options->kerberos_get_afs_token == -1)
                    177:                options->kerberos_get_afs_token = 0;
1.125     markus    178:        if (options->gss_authentication == -1)
                    179:                options->gss_authentication = 0;
                    180:        if (options->gss_cleanup_creds == -1)
                    181:                options->gss_cleanup_creds = 1;
1.25      markus    182:        if (options->password_authentication == -1)
                    183:                options->password_authentication = 1;
1.52      markus    184:        if (options->kbd_interactive_authentication == -1)
                    185:                options->kbd_interactive_authentication = 0;
1.80      markus    186:        if (options->challenge_response_authentication == -1)
                    187:                options->challenge_response_authentication = 1;
1.25      markus    188:        if (options->permit_empty_passwd == -1)
1.30      markus    189:                options->permit_empty_passwd = 0;
1.113     markus    190:        if (options->permit_user_env == -1)
                    191:                options->permit_user_env = 0;
1.25      markus    192:        if (options->use_login == -1)
                    193:                options->use_login = 0;
1.111     markus    194:        if (options->compression == -1)
1.143     markus    195:                options->compression = COMP_DELAYED;
1.53      markus    196:        if (options->allow_tcp_forwarding == -1)
                    197:                options->allow_tcp_forwarding = 1;
1.38      markus    198:        if (options->gateway_ports == -1)
                    199:                options->gateway_ports = 0;
1.46      markus    200:        if (options->max_startups == -1)
                    201:                options->max_startups = 10;
1.50      markus    202:        if (options->max_startups_rate == -1)
                    203:                options->max_startups_rate = 100;               /* 100% */
                    204:        if (options->max_startups_begin == -1)
                    205:                options->max_startups_begin = options->max_startups;
1.133     dtucker   206:        if (options->max_authtries == -1)
                    207:                options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
1.122     markus    208:        if (options->use_dns == -1)
                    209:                options->use_dns = 1;
1.77      beck      210:        if (options->client_alive_interval == -1)
1.95      deraadt   211:                options->client_alive_interval = 0;
1.77      beck      212:        if (options->client_alive_count_max == -1)
                    213:                options->client_alive_count_max = 3;
1.90      markus    214:        if (options->authorized_keys_file2 == NULL) {
                    215:                /* authorized_keys_file2 falls back to authorized_keys_file */
                    216:                if (options->authorized_keys_file != NULL)
                    217:                        options->authorized_keys_file2 = options->authorized_keys_file;
                    218:                else
                    219:                        options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
                    220:        }
                    221:        if (options->authorized_keys_file == NULL)
                    222:                options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
1.145     reyk      223:        if (options->permit_tun == -1)
1.146     reyk      224:                options->permit_tun = SSH_TUNMODE_NO;
1.102     provos    225:
1.110     markus    226:        /* Turn privilege separation on by default */
1.102     provos    227:        if (use_privsep == -1)
1.110     markus    228:                use_privsep = 1;
1.1       deraadt   229: }
                    230:
                    231: /* Keyword tokens. */
1.25      markus    232: typedef enum {
                    233:        sBadOption,             /* == unknown option */
                    234:        sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
                    235:        sPermitRootLogin, sLogFacility, sLogLevel,
1.124     markus    236:        sRhostsRSAAuthentication, sRSAAuthentication,
1.25      markus    237:        sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.130     jakob     238:        sKerberosGetAFSToken,
1.123     markus    239:        sKerberosTgtPassing, sChallengeResponseAuthentication,
1.138     djm       240:        sPasswordAuthentication, sKbdInteractiveAuthentication,
                    241:        sListenAddress, sAddressFamily,
1.72      stevesk   242:        sPrintMotd, sPrintLastLog, sIgnoreRhosts,
1.99      stevesk   243:        sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
1.129     markus    244:        sStrictModes, sEmptyPasswd, sTCPKeepAlive,
1.113     markus    245:        sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
1.53      markus    246:        sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.66      markus    247:        sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
1.133     dtucker   248:        sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
                    249:        sMaxStartups, sMaxAuthTries,
1.122     markus    250:        sBanner, sUseDNS, sHostbasedAuthentication,
1.95      deraadt   251:        sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
1.89      jakob     252:        sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
1.145     reyk      253:        sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
1.105     stevesk   254:        sUsePrivilegeSeparation,
1.121     jakob     255:        sDeprecated, sUnsupported
1.1       deraadt   256: } ServerOpCodes;
                    257:
                    258: /* Textual representation of the tokens. */
1.25      markus    259: static struct {
                    260:        const char *name;
                    261:        ServerOpCodes opcode;
                    262: } keywords[] = {
                    263:        { "port", sPort },
                    264:        { "hostkey", sHostKeyFile },
1.54      markus    265:        { "hostdsakey", sHostKeyFile },                                 /* alias */
1.65      stevesk   266:        { "pidfile", sPidFile },
1.25      markus    267:        { "serverkeybits", sServerKeyBits },
                    268:        { "logingracetime", sLoginGraceTime },
                    269:        { "keyregenerationinterval", sKeyRegenerationTime },
                    270:        { "permitrootlogin", sPermitRootLogin },
                    271:        { "syslogfacility", sLogFacility },
                    272:        { "loglevel", sLogLevel },
1.124     markus    273:        { "rhostsauthentication", sDeprecated },
1.25      markus    274:        { "rhostsrsaauthentication", sRhostsRSAAuthentication },
1.75      markus    275:        { "hostbasedauthentication", sHostbasedAuthentication },
                    276:        { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
1.25      markus    277:        { "rsaauthentication", sRSAAuthentication },
1.54      markus    278:        { "pubkeyauthentication", sPubkeyAuthentication },
                    279:        { "dsaauthentication", sPubkeyAuthentication },                 /* alias */
1.123     markus    280: #ifdef KRB5
1.25      markus    281:        { "kerberosauthentication", sKerberosAuthentication },
                    282:        { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
                    283:        { "kerberosticketcleanup", sKerberosTicketCleanup },
1.130     jakob     284:        { "kerberosgetafstoken", sKerberosGetAFSToken },
1.121     jakob     285: #else
                    286:        { "kerberosauthentication", sUnsupported },
                    287:        { "kerberosorlocalpasswd", sUnsupported },
                    288:        { "kerberosticketcleanup", sUnsupported },
1.130     jakob     289:        { "kerberosgetafstoken", sUnsupported },
1.126     markus    290: #endif
1.121     jakob     291:        { "kerberostgtpassing", sUnsupported },
                    292:        { "afstokenpassing", sUnsupported },
1.125     markus    293: #ifdef GSSAPI
                    294:        { "gssapiauthentication", sGssAuthentication },
1.128     markus    295:        { "gssapicleanupcredentials", sGssCleanupCreds },
1.125     markus    296: #else
                    297:        { "gssapiauthentication", sUnsupported },
1.128     markus    298:        { "gssapicleanupcredentials", sUnsupported },
1.125     markus    299: #endif
1.25      markus    300:        { "passwordauthentication", sPasswordAuthentication },
1.52      markus    301:        { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
1.63      markus    302:        { "challengeresponseauthentication", sChallengeResponseAuthentication },
                    303:        { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
1.89      jakob     304:        { "checkmail", sDeprecated },
1.25      markus    305:        { "listenaddress", sListenAddress },
1.138     djm       306:        { "addressfamily", sAddressFamily },
1.25      markus    307:        { "printmotd", sPrintMotd },
1.72      stevesk   308:        { "printlastlog", sPrintLastLog },
1.25      markus    309:        { "ignorerhosts", sIgnoreRhosts },
                    310:        { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
                    311:        { "x11forwarding", sX11Forwarding },
                    312:        { "x11displayoffset", sX11DisplayOffset },
1.99      stevesk   313:        { "x11uselocalhost", sX11UseLocalhost },
1.42      markus    314:        { "xauthlocation", sXAuthLocation },
1.25      markus    315:        { "strictmodes", sStrictModes },
                    316:        { "permitemptypasswords", sEmptyPasswd },
1.113     markus    317:        { "permituserenvironment", sPermitUserEnvironment },
1.25      markus    318:        { "uselogin", sUseLogin },
1.111     markus    319:        { "compression", sCompression },
1.129     markus    320:        { "tcpkeepalive", sTCPKeepAlive },
                    321:        { "keepalive", sTCPKeepAlive },                         /* obsolete alias */
1.53      markus    322:        { "allowtcpforwarding", sAllowTcpForwarding },
1.25      markus    323:        { "allowusers", sAllowUsers },
                    324:        { "denyusers", sDenyUsers },
                    325:        { "allowgroups", sAllowGroups },
                    326:        { "denygroups", sDenyGroups },
1.33      markus    327:        { "ciphers", sCiphers },
1.66      markus    328:        { "macs", sMacs },
1.33      markus    329:        { "protocol", sProtocol },
1.38      markus    330:        { "gatewayports", sGatewayPorts },
1.43      jakob     331:        { "subsystem", sSubsystem },
1.46      markus    332:        { "maxstartups", sMaxStartups },
1.133     dtucker   333:        { "maxauthtries", sMaxAuthTries },
1.57      markus    334:        { "banner", sBanner },
1.122     markus    335:        { "usedns", sUseDNS },
                    336:        { "verifyreversemapping", sDeprecated },
                    337:        { "reversemappingcheck", sDeprecated },
1.77      beck      338:        { "clientaliveinterval", sClientAliveInterval },
                    339:        { "clientalivecountmax", sClientAliveCountMax },
1.82      markus    340:        { "authorizedkeysfile", sAuthorizedKeysFile },
                    341:        { "authorizedkeysfile2", sAuthorizedKeysFile2 },
1.102     provos    342:        { "useprivilegeseparation", sUsePrivilegeSeparation},
1.131     djm       343:        { "acceptenv", sAcceptEnv },
1.145     reyk      344:        { "permittunnel", sPermitTunnel },
1.92      stevesk   345:        { NULL, sBadOption }
1.1       deraadt   346: };
                    347:
1.27      markus    348: /*
1.73      stevesk   349:  * Returns the number of the token pointed to by cp or sBadOption.
1.27      markus    350:  */
1.1       deraadt   351:
1.34      markus    352: static ServerOpCodes
1.25      markus    353: parse_token(const char *cp, const char *filename,
                    354:            int linenum)
1.1       deraadt   355: {
1.55      markus    356:        u_int i;
1.1       deraadt   357:
1.25      markus    358:        for (i = 0; keywords[i].name; i++)
1.28      markus    359:                if (strcasecmp(cp, keywords[i].name) == 0)
1.25      markus    360:                        return keywords[i].opcode;
                    361:
1.78      stevesk   362:        error("%s: line %d: Bad configuration option: %s",
                    363:            filename, linenum, cp);
1.25      markus    364:        return sBadOption;
1.1       deraadt   365: }
                    366:
1.84      itojun    367: static void
1.76      stevesk   368: add_listen_addr(ServerOptions *options, char *addr, u_short port)
1.74      stevesk   369: {
1.142     djm       370:        u_int i;
1.74      stevesk   371:
                    372:        if (options->num_ports == 0)
                    373:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
1.138     djm       374:        if (options->address_family == -1)
                    375:                options->address_family = AF_UNSPEC;
1.76      stevesk   376:        if (port == 0)
1.74      stevesk   377:                for (i = 0; i < options->num_ports; i++)
                    378:                        add_one_listen_addr(options, addr, options->ports[i]);
                    379:        else
1.76      stevesk   380:                add_one_listen_addr(options, addr, port);
1.74      stevesk   381: }
                    382:
1.84      itojun    383: static void
1.74      stevesk   384: add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
1.29      markus    385: {
                    386:        struct addrinfo hints, *ai, *aitop;
                    387:        char strport[NI_MAXSERV];
                    388:        int gaierr;
                    389:
1.74      stevesk   390:        memset(&hints, 0, sizeof(hints));
1.138     djm       391:        hints.ai_family = options->address_family;
1.74      stevesk   392:        hints.ai_socktype = SOCK_STREAM;
                    393:        hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
1.112     deraadt   394:        snprintf(strport, sizeof strport, "%u", port);
1.74      stevesk   395:        if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
                    396:                fatal("bad addr or host: %s (%s)",
                    397:                    addr ? addr : "<NULL>",
                    398:                    gai_strerror(gaierr));
                    399:        for (ai = aitop; ai->ai_next; ai = ai->ai_next)
                    400:                ;
                    401:        ai->ai_next = options->listen_addrs;
                    402:        options->listen_addrs = aitop;
1.29      markus    403: }
                    404:
1.94      markus    405: int
                    406: process_server_config_line(ServerOptions *options, char *line,
                    407:     const char *filename, int linenum)
1.1       deraadt   408: {
1.74      stevesk   409:        char *cp, **charptr, *arg, *p;
1.142     djm       410:        int *intptr, value, n;
1.25      markus    411:        ServerOpCodes opcode;
1.139     djm       412:        u_short port;
1.142     djm       413:        u_int i;
1.151   ! djm       414:        size_t len;
1.25      markus    415:
1.94      markus    416:        cp = line;
1.148     dtucker   417:        if ((arg = strdelim(&cp)) == NULL)
1.147     djm       418:                return 0;
1.94      markus    419:        /* Ignore leading whitespace */
                    420:        if (*arg == '\0')
                    421:                arg = strdelim(&cp);
                    422:        if (!arg || !*arg || *arg == '#')
                    423:                return 0;
                    424:        intptr = NULL;
                    425:        charptr = NULL;
                    426:        opcode = parse_token(arg, filename, linenum);
                    427:        switch (opcode) {
                    428:        case sBadOption:
                    429:                return -1;
                    430:        case sPort:
                    431:                /* ignore ports from configfile if cmdline specifies ports */
                    432:                if (options->ports_from_cmdline)
                    433:                        return 0;
                    434:                if (options->listen_addrs != NULL)
                    435:                        fatal("%s line %d: ports must be specified before "
1.98      stevesk   436:                            "ListenAddress.", filename, linenum);
1.94      markus    437:                if (options->num_ports >= MAX_PORTS)
                    438:                        fatal("%s line %d: too many ports.",
                    439:                            filename, linenum);
1.48      provos    440:                arg = strdelim(&cp);
1.94      markus    441:                if (!arg || *arg == '\0')
                    442:                        fatal("%s line %d: missing port number.",
                    443:                            filename, linenum);
                    444:                options->ports[options->num_ports++] = a2port(arg);
                    445:                if (options->ports[options->num_ports-1] == 0)
                    446:                        fatal("%s line %d: Badly formatted port number.",
                    447:                            filename, linenum);
                    448:                break;
1.29      markus    449:
1.94      markus    450:        case sServerKeyBits:
                    451:                intptr = &options->server_key_bits;
1.25      markus    452: parse_int:
1.94      markus    453:                arg = strdelim(&cp);
                    454:                if (!arg || *arg == '\0')
                    455:                        fatal("%s line %d: missing integer value.",
                    456:                            filename, linenum);
                    457:                value = atoi(arg);
                    458:                if (*intptr == -1)
                    459:                        *intptr = value;
                    460:                break;
1.25      markus    461:
1.94      markus    462:        case sLoginGraceTime:
                    463:                intptr = &options->login_grace_time;
1.81      stevesk   464: parse_time:
1.94      markus    465:                arg = strdelim(&cp);
                    466:                if (!arg || *arg == '\0')
                    467:                        fatal("%s line %d: missing time value.",
                    468:                            filename, linenum);
                    469:                if ((value = convtime(arg)) == -1)
                    470:                        fatal("%s line %d: invalid time value.",
                    471:                            filename, linenum);
                    472:                if (*intptr == -1)
                    473:                        *intptr = value;
                    474:                break;
                    475:
                    476:        case sKeyRegenerationTime:
                    477:                intptr = &options->key_regeneration_time;
                    478:                goto parse_time;
                    479:
                    480:        case sListenAddress:
                    481:                arg = strdelim(&cp);
1.139     djm       482:                if (arg == NULL || *arg == '\0')
                    483:                        fatal("%s line %d: missing address",
1.94      markus    484:                            filename, linenum);
1.144     dtucker   485:                /* check for bare IPv6 address: no "[]" and 2 or more ":" */
                    486:                if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
                    487:                    && strchr(p+1, ':') != NULL) {
                    488:                        add_listen_addr(options, arg, 0);
                    489:                        break;
                    490:                }
1.139     djm       491:                p = hpdelim(&arg);
                    492:                if (p == NULL)
                    493:                        fatal("%s line %d: bad address:port usage",
                    494:                            filename, linenum);
                    495:                p = cleanhostname(p);
                    496:                if (arg == NULL)
                    497:                        port = 0;
                    498:                else if ((port = a2port(arg)) == 0)
                    499:                        fatal("%s line %d: bad port number", filename, linenum);
                    500:
                    501:                add_listen_addr(options, p, port);
1.25      markus    502:
1.138     djm       503:                break;
                    504:
                    505:        case sAddressFamily:
                    506:                arg = strdelim(&cp);
1.141     markus    507:                if (!arg || *arg == '\0')
                    508:                        fatal("%s line %d: missing address family.",
                    509:                            filename, linenum);
1.138     djm       510:                intptr = &options->address_family;
                    511:                if (options->listen_addrs != NULL)
                    512:                        fatal("%s line %d: address family must be specified before "
                    513:                            "ListenAddress.", filename, linenum);
                    514:                if (strcasecmp(arg, "inet") == 0)
                    515:                        value = AF_INET;
                    516:                else if (strcasecmp(arg, "inet6") == 0)
                    517:                        value = AF_INET6;
                    518:                else if (strcasecmp(arg, "any") == 0)
                    519:                        value = AF_UNSPEC;
                    520:                else
                    521:                        fatal("%s line %d: unsupported address family \"%s\".",
                    522:                            filename, linenum, arg);
                    523:                if (*intptr == -1)
                    524:                        *intptr = value;
1.94      markus    525:                break;
                    526:
                    527:        case sHostKeyFile:
                    528:                intptr = &options->num_host_key_files;
                    529:                if (*intptr >= MAX_HOSTKEYS)
                    530:                        fatal("%s line %d: too many host keys specified (max %d).",
                    531:                            filename, linenum, MAX_HOSTKEYS);
                    532:                charptr = &options->host_key_files[*intptr];
                    533: parse_filename:
                    534:                arg = strdelim(&cp);
                    535:                if (!arg || *arg == '\0')
                    536:                        fatal("%s line %d: missing file name.",
                    537:                            filename, linenum);
                    538:                if (*charptr == NULL) {
                    539:                        *charptr = tilde_expand_filename(arg, getuid());
                    540:                        /* increase optional counter */
                    541:                        if (intptr != NULL)
                    542:                                *intptr = *intptr + 1;
                    543:                }
                    544:                break;
1.76      stevesk   545:
1.94      markus    546:        case sPidFile:
                    547:                charptr = &options->pid_file;
                    548:                goto parse_filename;
1.25      markus    549:
1.94      markus    550:        case sPermitRootLogin:
                    551:                intptr = &options->permit_root_login;
                    552:                arg = strdelim(&cp);
                    553:                if (!arg || *arg == '\0')
                    554:                        fatal("%s line %d: missing yes/"
                    555:                            "without-password/forced-commands-only/no "
                    556:                            "argument.", filename, linenum);
                    557:                value = 0;      /* silence compiler */
                    558:                if (strcmp(arg, "without-password") == 0)
                    559:                        value = PERMIT_NO_PASSWD;
                    560:                else if (strcmp(arg, "forced-commands-only") == 0)
                    561:                        value = PERMIT_FORCED_ONLY;
                    562:                else if (strcmp(arg, "yes") == 0)
                    563:                        value = PERMIT_YES;
                    564:                else if (strcmp(arg, "no") == 0)
                    565:                        value = PERMIT_NO;
                    566:                else
                    567:                        fatal("%s line %d: Bad yes/"
                    568:                            "without-password/forced-commands-only/no "
                    569:                            "argument: %s", filename, linenum, arg);
                    570:                if (*intptr == -1)
                    571:                        *intptr = value;
                    572:                break;
1.36      markus    573:
1.94      markus    574:        case sIgnoreRhosts:
                    575:                intptr = &options->ignore_rhosts;
1.25      markus    576: parse_flag:
1.94      markus    577:                arg = strdelim(&cp);
                    578:                if (!arg || *arg == '\0')
                    579:                        fatal("%s line %d: missing yes/no argument.",
                    580:                            filename, linenum);
                    581:                value = 0;      /* silence compiler */
                    582:                if (strcmp(arg, "yes") == 0)
                    583:                        value = 1;
                    584:                else if (strcmp(arg, "no") == 0)
                    585:                        value = 0;
                    586:                else
                    587:                        fatal("%s line %d: Bad yes/no argument: %s",
                    588:                                filename, linenum, arg);
                    589:                if (*intptr == -1)
                    590:                        *intptr = value;
                    591:                break;
                    592:
                    593:        case sIgnoreUserKnownHosts:
                    594:                intptr = &options->ignore_user_known_hosts;
                    595:                goto parse_flag;
                    596:
                    597:        case sRhostsRSAAuthentication:
                    598:                intptr = &options->rhosts_rsa_authentication;
                    599:                goto parse_flag;
                    600:
                    601:        case sHostbasedAuthentication:
                    602:                intptr = &options->hostbased_authentication;
                    603:                goto parse_flag;
                    604:
                    605:        case sHostbasedUsesNameFromPacketOnly:
                    606:                intptr = &options->hostbased_uses_name_from_packet_only;
                    607:                goto parse_flag;
                    608:
                    609:        case sRSAAuthentication:
                    610:                intptr = &options->rsa_authentication;
                    611:                goto parse_flag;
                    612:
                    613:        case sPubkeyAuthentication:
                    614:                intptr = &options->pubkey_authentication;
                    615:                goto parse_flag;
1.119     jakob     616:
1.94      markus    617:        case sKerberosAuthentication:
                    618:                intptr = &options->kerberos_authentication;
                    619:                goto parse_flag;
                    620:
                    621:        case sKerberosOrLocalPasswd:
                    622:                intptr = &options->kerberos_or_local_passwd;
                    623:                goto parse_flag;
                    624:
                    625:        case sKerberosTicketCleanup:
                    626:                intptr = &options->kerberos_ticket_cleanup;
1.130     jakob     627:                goto parse_flag;
                    628:
                    629:        case sKerberosGetAFSToken:
                    630:                intptr = &options->kerberos_get_afs_token;
1.125     markus    631:                goto parse_flag;
                    632:
                    633:        case sGssAuthentication:
                    634:                intptr = &options->gss_authentication;
                    635:                goto parse_flag;
                    636:
                    637:        case sGssCleanupCreds:
                    638:                intptr = &options->gss_cleanup_creds;
1.94      markus    639:                goto parse_flag;
                    640:
                    641:        case sPasswordAuthentication:
                    642:                intptr = &options->password_authentication;
                    643:                goto parse_flag;
                    644:
                    645:        case sKbdInteractiveAuthentication:
                    646:                intptr = &options->kbd_interactive_authentication;
                    647:                goto parse_flag;
                    648:
                    649:        case sChallengeResponseAuthentication:
                    650:                intptr = &options->challenge_response_authentication;
                    651:                goto parse_flag;
                    652:
                    653:        case sPrintMotd:
                    654:                intptr = &options->print_motd;
                    655:                goto parse_flag;
                    656:
                    657:        case sPrintLastLog:
                    658:                intptr = &options->print_lastlog;
                    659:                goto parse_flag;
                    660:
                    661:        case sX11Forwarding:
                    662:                intptr = &options->x11_forwarding;
                    663:                goto parse_flag;
                    664:
                    665:        case sX11DisplayOffset:
                    666:                intptr = &options->x11_display_offset;
                    667:                goto parse_int;
1.99      stevesk   668:
                    669:        case sX11UseLocalhost:
                    670:                intptr = &options->x11_use_localhost;
                    671:                goto parse_flag;
1.94      markus    672:
                    673:        case sXAuthLocation:
                    674:                charptr = &options->xauth_location;
                    675:                goto parse_filename;
                    676:
                    677:        case sStrictModes:
                    678:                intptr = &options->strict_modes;
                    679:                goto parse_flag;
                    680:
1.129     markus    681:        case sTCPKeepAlive:
                    682:                intptr = &options->tcp_keep_alive;
1.94      markus    683:                goto parse_flag;
                    684:
                    685:        case sEmptyPasswd:
                    686:                intptr = &options->permit_empty_passwd;
1.113     markus    687:                goto parse_flag;
                    688:
                    689:        case sPermitUserEnvironment:
                    690:                intptr = &options->permit_user_env;
1.94      markus    691:                goto parse_flag;
                    692:
                    693:        case sUseLogin:
                    694:                intptr = &options->use_login;
1.111     markus    695:                goto parse_flag;
                    696:
                    697:        case sCompression:
                    698:                intptr = &options->compression;
1.143     markus    699:                arg = strdelim(&cp);
                    700:                if (!arg || *arg == '\0')
                    701:                        fatal("%s line %d: missing yes/no/delayed "
                    702:                            "argument.", filename, linenum);
                    703:                value = 0;      /* silence compiler */
                    704:                if (strcmp(arg, "delayed") == 0)
                    705:                        value = COMP_DELAYED;
                    706:                else if (strcmp(arg, "yes") == 0)
                    707:                        value = COMP_ZLIB;
                    708:                else if (strcmp(arg, "no") == 0)
                    709:                        value = COMP_NONE;
                    710:                else
                    711:                        fatal("%s line %d: Bad yes/no/delayed "
                    712:                            "argument: %s", filename, linenum, arg);
                    713:                if (*intptr == -1)
                    714:                        *intptr = value;
                    715:                break;
1.94      markus    716:
                    717:        case sGatewayPorts:
                    718:                intptr = &options->gateway_ports;
1.139     djm       719:                arg = strdelim(&cp);
                    720:                if (!arg || *arg == '\0')
                    721:                        fatal("%s line %d: missing yes/no/clientspecified "
                    722:                            "argument.", filename, linenum);
                    723:                value = 0;      /* silence compiler */
                    724:                if (strcmp(arg, "clientspecified") == 0)
                    725:                        value = 2;
                    726:                else if (strcmp(arg, "yes") == 0)
                    727:                        value = 1;
                    728:                else if (strcmp(arg, "no") == 0)
                    729:                        value = 0;
                    730:                else
                    731:                        fatal("%s line %d: Bad yes/no/clientspecified "
                    732:                            "argument: %s", filename, linenum, arg);
                    733:                if (*intptr == -1)
                    734:                        *intptr = value;
                    735:                break;
1.25      markus    736:
1.122     markus    737:        case sUseDNS:
                    738:                intptr = &options->use_dns;
1.94      markus    739:                goto parse_flag;
1.53      markus    740:
1.94      markus    741:        case sLogFacility:
                    742:                intptr = (int *) &options->log_facility;
                    743:                arg = strdelim(&cp);
                    744:                value = log_facility_number(arg);
1.101     markus    745:                if (value == SYSLOG_FACILITY_NOT_SET)
1.94      markus    746:                        fatal("%.200s line %d: unsupported log facility '%s'",
                    747:                            filename, linenum, arg ? arg : "<NONE>");
                    748:                if (*intptr == -1)
                    749:                        *intptr = (SyslogFacility) value;
                    750:                break;
1.25      markus    751:
1.94      markus    752:        case sLogLevel:
                    753:                intptr = (int *) &options->log_level;
                    754:                arg = strdelim(&cp);
                    755:                value = log_level_number(arg);
1.101     markus    756:                if (value == SYSLOG_LEVEL_NOT_SET)
1.94      markus    757:                        fatal("%.200s line %d: unsupported log level '%s'",
                    758:                            filename, linenum, arg ? arg : "<NONE>");
                    759:                if (*intptr == -1)
                    760:                        *intptr = (LogLevel) value;
                    761:                break;
                    762:
                    763:        case sAllowTcpForwarding:
                    764:                intptr = &options->allow_tcp_forwarding;
                    765:                goto parse_flag;
1.102     provos    766:
                    767:        case sUsePrivilegeSeparation:
                    768:                intptr = &use_privsep;
                    769:                goto parse_flag;
1.94      markus    770:
                    771:        case sAllowUsers:
                    772:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                    773:                        if (options->num_allow_users >= MAX_ALLOW_USERS)
                    774:                                fatal("%s line %d: too many allow users.",
                    775:                                    filename, linenum);
1.112     deraadt   776:                        options->allow_users[options->num_allow_users++] =
                    777:                            xstrdup(arg);
1.94      markus    778:                }
                    779:                break;
1.25      markus    780:
1.94      markus    781:        case sDenyUsers:
                    782:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                    783:                        if (options->num_deny_users >= MAX_DENY_USERS)
                    784:                                fatal( "%s line %d: too many deny users.",
                    785:                                    filename, linenum);
1.112     deraadt   786:                        options->deny_users[options->num_deny_users++] =
                    787:                            xstrdup(arg);
1.94      markus    788:                }
                    789:                break;
1.25      markus    790:
1.94      markus    791:        case sAllowGroups:
                    792:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                    793:                        if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
                    794:                                fatal("%s line %d: too many allow groups.",
                    795:                                    filename, linenum);
1.112     deraadt   796:                        options->allow_groups[options->num_allow_groups++] =
                    797:                            xstrdup(arg);
1.94      markus    798:                }
                    799:                break;
1.33      markus    800:
1.94      markus    801:        case sDenyGroups:
                    802:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                    803:                        if (options->num_deny_groups >= MAX_DENY_GROUPS)
                    804:                                fatal("%s line %d: too many deny groups.",
                    805:                                    filename, linenum);
                    806:                        options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
                    807:                }
                    808:                break;
1.66      markus    809:
1.94      markus    810:        case sCiphers:
                    811:                arg = strdelim(&cp);
                    812:                if (!arg || *arg == '\0')
                    813:                        fatal("%s line %d: Missing argument.", filename, linenum);
                    814:                if (!ciphers_valid(arg))
                    815:                        fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
                    816:                            filename, linenum, arg ? arg : "<NONE>");
                    817:                if (options->ciphers == NULL)
                    818:                        options->ciphers = xstrdup(arg);
                    819:                break;
1.33      markus    820:
1.94      markus    821:        case sMacs:
                    822:                arg = strdelim(&cp);
                    823:                if (!arg || *arg == '\0')
                    824:                        fatal("%s line %d: Missing argument.", filename, linenum);
                    825:                if (!mac_valid(arg))
                    826:                        fatal("%s line %d: Bad SSH2 mac spec '%s'.",
                    827:                            filename, linenum, arg ? arg : "<NONE>");
                    828:                if (options->macs == NULL)
                    829:                        options->macs = xstrdup(arg);
                    830:                break;
1.43      jakob     831:
1.94      markus    832:        case sProtocol:
                    833:                intptr = &options->protocol;
                    834:                arg = strdelim(&cp);
                    835:                if (!arg || *arg == '\0')
                    836:                        fatal("%s line %d: Missing argument.", filename, linenum);
                    837:                value = proto_spec(arg);
                    838:                if (value == SSH_PROTO_UNKNOWN)
                    839:                        fatal("%s line %d: Bad protocol spec '%s'.",
1.95      deraadt   840:                            filename, linenum, arg ? arg : "<NONE>");
1.94      markus    841:                if (*intptr == SSH_PROTO_UNKNOWN)
                    842:                        *intptr = value;
                    843:                break;
                    844:
                    845:        case sSubsystem:
                    846:                if (options->num_subsystems >= MAX_SUBSYSTEMS) {
                    847:                        fatal("%s line %d: too many subsystems defined.",
1.95      deraadt   848:                            filename, linenum);
1.94      markus    849:                }
                    850:                arg = strdelim(&cp);
                    851:                if (!arg || *arg == '\0')
                    852:                        fatal("%s line %d: Missing subsystem name.",
1.95      deraadt   853:                            filename, linenum);
1.94      markus    854:                for (i = 0; i < options->num_subsystems; i++)
                    855:                        if (strcmp(arg, options->subsystem_name[i]) == 0)
                    856:                                fatal("%s line %d: Subsystem '%s' already defined.",
1.95      deraadt   857:                                    filename, linenum, arg);
1.94      markus    858:                options->subsystem_name[options->num_subsystems] = xstrdup(arg);
                    859:                arg = strdelim(&cp);
                    860:                if (!arg || *arg == '\0')
                    861:                        fatal("%s line %d: Missing subsystem command.",
1.95      deraadt   862:                            filename, linenum);
1.94      markus    863:                options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151   ! djm       864:
        !           865:                /* Collect arguments (separate to executable) */
        !           866:                p = xstrdup(arg);
        !           867:                len = strlen(p) + 1;
        !           868:                while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
        !           869:                        len += 1 + strlen(arg);
        !           870:                        p = xrealloc(p, 1, len);
        !           871:                        strlcat(p, " ", len);
        !           872:                        strlcat(p, arg, len);
        !           873:                }
        !           874:                options->subsystem_args[options->num_subsystems] = p;
1.94      markus    875:                options->num_subsystems++;
                    876:                break;
1.46      markus    877:
1.94      markus    878:        case sMaxStartups:
                    879:                arg = strdelim(&cp);
                    880:                if (!arg || *arg == '\0')
                    881:                        fatal("%s line %d: Missing MaxStartups spec.",
1.95      deraadt   882:                            filename, linenum);
1.94      markus    883:                if ((n = sscanf(arg, "%d:%d:%d",
                    884:                    &options->max_startups_begin,
                    885:                    &options->max_startups_rate,
                    886:                    &options->max_startups)) == 3) {
                    887:                        if (options->max_startups_begin >
                    888:                            options->max_startups ||
                    889:                            options->max_startups_rate > 100 ||
                    890:                            options->max_startups_rate < 1)
1.50      markus    891:                                fatal("%s line %d: Illegal MaxStartups spec.",
1.87      stevesk   892:                                    filename, linenum);
1.94      markus    893:                } else if (n != 1)
                    894:                        fatal("%s line %d: Illegal MaxStartups spec.",
                    895:                            filename, linenum);
                    896:                else
                    897:                        options->max_startups = options->max_startups_begin;
                    898:                break;
1.133     dtucker   899:
                    900:        case sMaxAuthTries:
                    901:                intptr = &options->max_authtries;
                    902:                goto parse_int;
1.94      markus    903:
                    904:        case sBanner:
                    905:                charptr = &options->banner;
                    906:                goto parse_filename;
                    907:        /*
                    908:         * These options can contain %X options expanded at
                    909:         * connect time, so that you can specify paths like:
                    910:         *
                    911:         * AuthorizedKeysFile   /etc/ssh_keys/%u
                    912:         */
                    913:        case sAuthorizedKeysFile:
                    914:        case sAuthorizedKeysFile2:
                    915:                charptr = (opcode == sAuthorizedKeysFile ) ?
                    916:                    &options->authorized_keys_file :
                    917:                    &options->authorized_keys_file2;
                    918:                goto parse_filename;
                    919:
                    920:        case sClientAliveInterval:
                    921:                intptr = &options->client_alive_interval;
                    922:                goto parse_time;
                    923:
                    924:        case sClientAliveCountMax:
                    925:                intptr = &options->client_alive_count_max;
                    926:                goto parse_int;
1.131     djm       927:
                    928:        case sAcceptEnv:
                    929:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                    930:                        if (strchr(arg, '=') != NULL)
                    931:                                fatal("%s line %d: Invalid environment name.",
                    932:                                    filename, linenum);
                    933:                        if (options->num_accept_env >= MAX_ACCEPT_ENV)
                    934:                                fatal("%s line %d: too many allow env.",
                    935:                                    filename, linenum);
                    936:                        options->accept_env[options->num_accept_env++] =
                    937:                            xstrdup(arg);
                    938:                }
                    939:                break;
1.145     reyk      940:
                    941:        case sPermitTunnel:
                    942:                intptr = &options->permit_tun;
1.146     reyk      943:                arg = strdelim(&cp);
                    944:                if (!arg || *arg == '\0')
                    945:                        fatal("%s line %d: Missing yes/point-to-point/"
                    946:                            "ethernet/no argument.", filename, linenum);
                    947:                value = 0;      /* silence compiler */
                    948:                if (strcasecmp(arg, "ethernet") == 0)
                    949:                        value = SSH_TUNMODE_ETHERNET;
                    950:                else if (strcasecmp(arg, "point-to-point") == 0)
                    951:                        value = SSH_TUNMODE_POINTOPOINT;
                    952:                else if (strcasecmp(arg, "yes") == 0)
                    953:                        value = SSH_TUNMODE_YES;
                    954:                else if (strcasecmp(arg, "no") == 0)
                    955:                        value = SSH_TUNMODE_NO;
                    956:                else
                    957:                        fatal("%s line %d: Bad yes/point-to-point/ethernet/"
                    958:                            "no argument: %s", filename, linenum, arg);
                    959:                if (*intptr == -1)
                    960:                        *intptr = value;
                    961:                break;
1.94      markus    962:
                    963:        case sDeprecated:
1.117     itojun    964:                logit("%s line %d: Deprecated option %s",
1.121     jakob     965:                    filename, linenum, arg);
                    966:                while (arg)
                    967:                    arg = strdelim(&cp);
                    968:                break;
                    969:
                    970:        case sUnsupported:
                    971:                logit("%s line %d: Unsupported option %s",
1.94      markus    972:                    filename, linenum, arg);
                    973:                while (arg)
                    974:                    arg = strdelim(&cp);
                    975:                break;
                    976:
                    977:        default:
                    978:                fatal("%s line %d: Missing handler for opcode %s (%d)",
                    979:                    filename, linenum, arg, opcode);
                    980:        }
                    981:        if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
                    982:                fatal("%s line %d: garbage at end of line; \"%.200s\".",
                    983:                    filename, linenum, arg);
                    984:        return 0;
                    985: }
                    986:
                    987: /* Reads the server configuration file. */
1.25      markus    988:
1.94      markus    989: void
1.134     djm       990: load_server_config(const char *filename, Buffer *conf)
1.94      markus    991: {
1.134     djm       992:        char line[1024], *cp;
1.94      markus    993:        FILE *f;
1.81      stevesk   994:
1.134     djm       995:        debug2("%s: filename %s", __func__, filename);
                    996:        if ((f = fopen(filename, "r")) == NULL) {
1.94      markus    997:                perror(filename);
                    998:                exit(1);
                    999:        }
1.134     djm      1000:        buffer_clear(conf);
                   1001:        while (fgets(line, sizeof(line), f)) {
                   1002:                /*
                   1003:                 * Trim out comments and strip whitespace
1.135     deraadt  1004:                 * NB - preserve newlines, they are needed to reproduce
1.134     djm      1005:                 * line numbers later for error messages
                   1006:                 */
                   1007:                if ((cp = strchr(line, '#')) != NULL)
                   1008:                        memcpy(cp, "\n", 2);
                   1009:                cp = line + strspn(line, " \t\r");
                   1010:
                   1011:                buffer_append(conf, cp, strlen(cp));
                   1012:        }
                   1013:        buffer_append(conf, "\0", 1);
                   1014:        fclose(f);
                   1015:        debug2("%s: done config len = %d", __func__, buffer_len(conf));
                   1016: }
                   1017:
                   1018: void
                   1019: parse_server_config(ServerOptions *options, const char *filename, Buffer *conf)
                   1020: {
                   1021:        int linenum, bad_options = 0;
1.136     dtucker  1022:        char *cp, *obuf, *cbuf;
1.134     djm      1023:
                   1024:        debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
                   1025:
1.136     dtucker  1026:        obuf = cbuf = xstrdup(buffer_ptr(conf));
1.137     dtucker  1027:        linenum = 1;
1.140     deraadt  1028:        while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134     djm      1029:                if (process_server_config_line(options, cp, filename,
                   1030:                    linenum++) != 0)
1.94      markus   1031:                        bad_options++;
1.1       deraadt  1032:        }
1.136     dtucker  1033:        xfree(obuf);
1.78      stevesk  1034:        if (bad_options > 0)
                   1035:                fatal("%s: terminating, %d bad configuration options",
                   1036:                    filename, bad_options);
1.1       deraadt  1037: }