[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.91

1.1       deraadt     1: /*
1.26      deraadt     2:  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      3:  *                    All rights reserved
1.34      markus      4:  *
1.51      deraadt     5:  * As far as I am concerned, the code I have written for this software
                      6:  * can be used freely for any purpose.  Any derived versions of this
                      7:  * software must be clearly marked as such, and if the derived work is
                      8:  * incompatible with the protocol description in the RFC file, it must be
                      9:  * called by a name other than "ssh" or "Secure Shell".
1.26      deraadt    10:  */
1.1       deraadt    11:
                     12: #include "includes.h"
1.91    ! markus     13: RCSID("$OpenBSD: servconf.c,v 1.90 2001/11/11 13:02:31 markus Exp $");
1.62      markus     14:
1.88      itojun     15: #if defined(KRB4) || defined(KRB5)
1.62      markus     16: #include <krb.h>
1.86      dugsong    17: #endif
                     18: #ifdef AFS
                     19: #include <kafs.h>
1.62      markus     20: #endif
1.1       deraadt    21:
                     22: #include "ssh.h"
1.62      markus     23: #include "log.h"
1.1       deraadt    24: #include "servconf.h"
                     25: #include "xmalloc.h"
1.33      markus     26: #include "compat.h"
1.60      markus     27: #include "pathnames.h"
1.62      markus     28: #include "tildexpand.h"
                     29: #include "misc.h"
                     30: #include "cipher.h"
1.66      markus     31: #include "kex.h"
                     32: #include "mac.h"
1.1       deraadt    33:
1.84      itojun     34: static void add_listen_addr(ServerOptions *, char *, u_short);
                     35: static void add_one_listen_addr(ServerOptions *, char *, u_short);
1.29      markus     36:
1.62      markus     37: /* AF_UNSPEC or AF_INET or AF_INET6 */
                     38: extern int IPv4or6;
                     39:
1.1       deraadt    40: /* Initializes the server options to their default values. */
                     41:
1.34      markus     42: void
1.25      markus     43: initialize_server_options(ServerOptions *options)
1.1       deraadt    44: {
1.25      markus     45:        memset(options, 0, sizeof(*options));
1.29      markus     46:        options->num_ports = 0;
                     47:        options->ports_from_cmdline = 0;
                     48:        options->listen_addrs = NULL;
1.54      markus     49:        options->num_host_key_files = 0;
1.36      markus     50:        options->pid_file = NULL;
1.25      markus     51:        options->server_key_bits = -1;
                     52:        options->login_grace_time = -1;
                     53:        options->key_regeneration_time = -1;
1.67      markus     54:        options->permit_root_login = PERMIT_NOT_SET;
1.25      markus     55:        options->ignore_rhosts = -1;
                     56:        options->ignore_user_known_hosts = -1;
                     57:        options->print_motd = -1;
1.72      stevesk    58:        options->print_lastlog = -1;
1.25      markus     59:        options->x11_forwarding = -1;
                     60:        options->x11_display_offset = -1;
1.42      markus     61:        options->xauth_location = NULL;
1.25      markus     62:        options->strict_modes = -1;
                     63:        options->keepalives = -1;
                     64:        options->log_facility = (SyslogFacility) - 1;
                     65:        options->log_level = (LogLevel) - 1;
                     66:        options->rhosts_authentication = -1;
                     67:        options->rhosts_rsa_authentication = -1;
1.75      markus     68:        options->hostbased_authentication = -1;
                     69:        options->hostbased_uses_name_from_packet_only = -1;
1.25      markus     70:        options->rsa_authentication = -1;
1.54      markus     71:        options->pubkey_authentication = -1;
1.85      dugsong    72: #if defined(KRB4) || defined(KRB5)
1.25      markus     73:        options->kerberos_authentication = -1;
                     74:        options->kerberos_or_local_passwd = -1;
                     75:        options->kerberos_ticket_cleanup = -1;
1.1       deraadt    76: #endif
1.85      dugsong    77: #if defined(AFS) || defined(KRB5)
                     78:        options->kerberos_tgt_passing = -1;
                     79: #endif
1.4       dugsong    80: #ifdef AFS
1.25      markus     81:        options->afs_token_passing = -1;
1.1       deraadt    82: #endif
1.25      markus     83:        options->password_authentication = -1;
1.52      markus     84:        options->kbd_interactive_authentication = -1;
1.80      markus     85:        options->challenge_response_authentication = -1;
1.25      markus     86:        options->permit_empty_passwd = -1;
                     87:        options->use_login = -1;
1.53      markus     88:        options->allow_tcp_forwarding = -1;
1.25      markus     89:        options->num_allow_users = 0;
                     90:        options->num_deny_users = 0;
                     91:        options->num_allow_groups = 0;
                     92:        options->num_deny_groups = 0;
1.33      markus     93:        options->ciphers = NULL;
1.66      markus     94:        options->macs = NULL;
1.33      markus     95:        options->protocol = SSH_PROTO_UNKNOWN;
1.38      markus     96:        options->gateway_ports = -1;
1.43      jakob      97:        options->num_subsystems = 0;
1.50      markus     98:        options->max_startups_begin = -1;
                     99:        options->max_startups_rate = -1;
1.46      markus    100:        options->max_startups = -1;
1.57      markus    101:        options->banner = NULL;
1.64      markus    102:        options->reverse_mapping_check = -1;
1.77      beck      103:        options->client_alive_interval = -1;
                    104:        options->client_alive_count_max = -1;
1.82      markus    105:        options->authorized_keys_file = NULL;
                    106:        options->authorized_keys_file2 = NULL;
1.1       deraadt   107: }
                    108:
1.34      markus    109: void
1.25      markus    110: fill_default_server_options(ServerOptions *options)
1.1       deraadt   111: {
1.54      markus    112:        if (options->protocol == SSH_PROTO_UNKNOWN)
                    113:                options->protocol = SSH_PROTO_1|SSH_PROTO_2;
                    114:        if (options->num_host_key_files == 0) {
                    115:                /* fill default hostkeys for protocols */
                    116:                if (options->protocol & SSH_PROTO_1)
1.60      markus    117:                        options->host_key_files[options->num_host_key_files++] = _PATH_HOST_KEY_FILE;
1.54      markus    118:                if (options->protocol & SSH_PROTO_2)
1.60      markus    119:                        options->host_key_files[options->num_host_key_files++] = _PATH_HOST_DSA_KEY_FILE;
1.54      markus    120:        }
1.29      markus    121:        if (options->num_ports == 0)
                    122:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
                    123:        if (options->listen_addrs == NULL)
1.76      stevesk   124:                add_listen_addr(options, NULL, 0);
1.36      markus    125:        if (options->pid_file == NULL)
1.60      markus    126:                options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
1.25      markus    127:        if (options->server_key_bits == -1)
                    128:                options->server_key_bits = 768;
                    129:        if (options->login_grace_time == -1)
                    130:                options->login_grace_time = 600;
                    131:        if (options->key_regeneration_time == -1)
                    132:                options->key_regeneration_time = 3600;
1.67      markus    133:        if (options->permit_root_login == PERMIT_NOT_SET)
                    134:                options->permit_root_login = PERMIT_YES;
1.25      markus    135:        if (options->ignore_rhosts == -1)
1.30      markus    136:                options->ignore_rhosts = 1;
1.25      markus    137:        if (options->ignore_user_known_hosts == -1)
                    138:                options->ignore_user_known_hosts = 0;
                    139:        if (options->print_motd == -1)
                    140:                options->print_motd = 1;
1.72      stevesk   141:        if (options->print_lastlog == -1)
                    142:                options->print_lastlog = 1;
1.25      markus    143:        if (options->x11_forwarding == -1)
1.30      markus    144:                options->x11_forwarding = 0;
1.25      markus    145:        if (options->x11_display_offset == -1)
1.30      markus    146:                options->x11_display_offset = 10;
1.83      markus    147: #ifdef _PATH_XAUTH
1.42      markus    148:        if (options->xauth_location == NULL)
1.83      markus    149:                options->xauth_location = _PATH_XAUTH;
                    150: #endif
1.25      markus    151:        if (options->strict_modes == -1)
                    152:                options->strict_modes = 1;
                    153:        if (options->keepalives == -1)
                    154:                options->keepalives = 1;
                    155:        if (options->log_facility == (SyslogFacility) (-1))
                    156:                options->log_facility = SYSLOG_FACILITY_AUTH;
                    157:        if (options->log_level == (LogLevel) (-1))
1.58      markus    158:                options->log_level = SYSLOG_LEVEL_INFO;
1.25      markus    159:        if (options->rhosts_authentication == -1)
                    160:                options->rhosts_authentication = 0;
                    161:        if (options->rhosts_rsa_authentication == -1)
1.30      markus    162:                options->rhosts_rsa_authentication = 0;
1.75      markus    163:        if (options->hostbased_authentication == -1)
                    164:                options->hostbased_authentication = 0;
                    165:        if (options->hostbased_uses_name_from_packet_only == -1)
                    166:                options->hostbased_uses_name_from_packet_only = 0;
1.25      markus    167:        if (options->rsa_authentication == -1)
                    168:                options->rsa_authentication = 1;
1.54      markus    169:        if (options->pubkey_authentication == -1)
                    170:                options->pubkey_authentication = 1;
1.85      dugsong   171: #if defined(KRB4) || defined(KRB5)
1.25      markus    172:        if (options->kerberos_authentication == -1)
                    173:                options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
                    174:        if (options->kerberos_or_local_passwd == -1)
                    175:                options->kerberos_or_local_passwd = 1;
                    176:        if (options->kerberos_ticket_cleanup == -1)
                    177:                options->kerberos_ticket_cleanup = 1;
1.85      dugsong   178: #endif
                    179: #if defined(AFS) || defined(KRB5)
1.25      markus    180:        if (options->kerberos_tgt_passing == -1)
                    181:                options->kerberos_tgt_passing = 0;
1.85      dugsong   182: #endif
                    183: #ifdef AFS
1.25      markus    184:        if (options->afs_token_passing == -1)
                    185:                options->afs_token_passing = k_hasafs();
1.85      dugsong   186: #endif
1.25      markus    187:        if (options->password_authentication == -1)
                    188:                options->password_authentication = 1;
1.52      markus    189:        if (options->kbd_interactive_authentication == -1)
                    190:                options->kbd_interactive_authentication = 0;
1.80      markus    191:        if (options->challenge_response_authentication == -1)
                    192:                options->challenge_response_authentication = 1;
1.25      markus    193:        if (options->permit_empty_passwd == -1)
1.30      markus    194:                options->permit_empty_passwd = 0;
1.25      markus    195:        if (options->use_login == -1)
                    196:                options->use_login = 0;
1.53      markus    197:        if (options->allow_tcp_forwarding == -1)
                    198:                options->allow_tcp_forwarding = 1;
1.38      markus    199:        if (options->gateway_ports == -1)
                    200:                options->gateway_ports = 0;
1.46      markus    201:        if (options->max_startups == -1)
                    202:                options->max_startups = 10;
1.50      markus    203:        if (options->max_startups_rate == -1)
                    204:                options->max_startups_rate = 100;               /* 100% */
                    205:        if (options->max_startups_begin == -1)
                    206:                options->max_startups_begin = options->max_startups;
1.64      markus    207:        if (options->reverse_mapping_check == -1)
                    208:                options->reverse_mapping_check = 0;
1.77      beck      209:        if (options->client_alive_interval == -1)
                    210:                options->client_alive_interval = 0;
                    211:        if (options->client_alive_count_max == -1)
                    212:                options->client_alive_count_max = 3;
1.90      markus    213:        if (options->authorized_keys_file2 == NULL) {
                    214:                /* authorized_keys_file2 falls back to authorized_keys_file */
                    215:                if (options->authorized_keys_file != NULL)
                    216:                        options->authorized_keys_file2 = options->authorized_keys_file;
                    217:                else
                    218:                        options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
                    219:        }
                    220:        if (options->authorized_keys_file == NULL)
                    221:                options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
1.1       deraadt   222: }
                    223:
                    224: /* Keyword tokens. */
1.25      markus    225: typedef enum {
                    226:        sBadOption,             /* == unknown option */
                    227:        sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
                    228:        sPermitRootLogin, sLogFacility, sLogLevel,
                    229:        sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
1.85      dugsong   230: #if defined(KRB4) || defined(KRB5)
1.25      markus    231:        sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.1       deraadt   232: #endif
1.85      dugsong   233: #if defined(AFS) || defined(KRB5)
                    234:        sKerberosTgtPassing,
                    235: #endif
1.1       deraadt   236: #ifdef AFS
1.85      dugsong   237:        sAFSTokenPassing,
1.1       deraadt   238: #endif
1.63      markus    239:        sChallengeResponseAuthentication,
1.52      markus    240:        sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
1.72      stevesk   241:        sPrintMotd, sPrintLastLog, sIgnoreRhosts,
                    242:        sX11Forwarding, sX11DisplayOffset,
1.89      jakob     243:        sStrictModes, sEmptyPasswd, sKeepAlives,
1.53      markus    244:        sUseLogin, sAllowTcpForwarding,
                    245:        sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.66      markus    246:        sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
1.54      markus    247:        sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
1.75      markus    248:        sBanner, sReverseMappingCheck, sHostbasedAuthentication,
1.77      beck      249:        sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
1.89      jakob     250:        sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
                    251:        sDeprecated
1.1       deraadt   252: } ServerOpCodes;
                    253:
                    254: /* Textual representation of the tokens. */
1.25      markus    255: static struct {
                    256:        const char *name;
                    257:        ServerOpCodes opcode;
                    258: } keywords[] = {
                    259:        { "port", sPort },
                    260:        { "hostkey", sHostKeyFile },
1.54      markus    261:        { "hostdsakey", sHostKeyFile },                                 /* alias */
1.65      stevesk   262:        { "pidfile", sPidFile },
1.25      markus    263:        { "serverkeybits", sServerKeyBits },
                    264:        { "logingracetime", sLoginGraceTime },
                    265:        { "keyregenerationinterval", sKeyRegenerationTime },
                    266:        { "permitrootlogin", sPermitRootLogin },
                    267:        { "syslogfacility", sLogFacility },
                    268:        { "loglevel", sLogLevel },
                    269:        { "rhostsauthentication", sRhostsAuthentication },
                    270:        { "rhostsrsaauthentication", sRhostsRSAAuthentication },
1.75      markus    271:        { "hostbasedauthentication", sHostbasedAuthentication },
                    272:        { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
1.25      markus    273:        { "rsaauthentication", sRSAAuthentication },
1.54      markus    274:        { "pubkeyauthentication", sPubkeyAuthentication },
                    275:        { "dsaauthentication", sPubkeyAuthentication },                 /* alias */
1.85      dugsong   276: #if defined(KRB4) || defined(KRB5)
1.25      markus    277:        { "kerberosauthentication", sKerberosAuthentication },
                    278:        { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
                    279:        { "kerberosticketcleanup", sKerberosTicketCleanup },
1.1       deraadt   280: #endif
1.85      dugsong   281: #if defined(AFS) || defined(KRB5)
                    282:        { "kerberostgtpassing", sKerberosTgtPassing },
                    283: #endif
1.4       dugsong   284: #ifdef AFS
1.25      markus    285:        { "afstokenpassing", sAFSTokenPassing },
1.1       deraadt   286: #endif
1.25      markus    287:        { "passwordauthentication", sPasswordAuthentication },
1.52      markus    288:        { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
1.63      markus    289:        { "challengeresponseauthentication", sChallengeResponseAuthentication },
                    290:        { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
1.89      jakob     291:        { "checkmail", sDeprecated },
1.25      markus    292:        { "listenaddress", sListenAddress },
                    293:        { "printmotd", sPrintMotd },
1.72      stevesk   294:        { "printlastlog", sPrintLastLog },
1.25      markus    295:        { "ignorerhosts", sIgnoreRhosts },
                    296:        { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
                    297:        { "x11forwarding", sX11Forwarding },
                    298:        { "x11displayoffset", sX11DisplayOffset },
1.42      markus    299:        { "xauthlocation", sXAuthLocation },
1.25      markus    300:        { "strictmodes", sStrictModes },
                    301:        { "permitemptypasswords", sEmptyPasswd },
                    302:        { "uselogin", sUseLogin },
                    303:        { "keepalive", sKeepAlives },
1.53      markus    304:        { "allowtcpforwarding", sAllowTcpForwarding },
1.25      markus    305:        { "allowusers", sAllowUsers },
                    306:        { "denyusers", sDenyUsers },
                    307:        { "allowgroups", sAllowGroups },
                    308:        { "denygroups", sDenyGroups },
1.33      markus    309:        { "ciphers", sCiphers },
1.66      markus    310:        { "macs", sMacs },
1.33      markus    311:        { "protocol", sProtocol },
1.38      markus    312:        { "gatewayports", sGatewayPorts },
1.43      jakob     313:        { "subsystem", sSubsystem },
1.46      markus    314:        { "maxstartups", sMaxStartups },
1.57      markus    315:        { "banner", sBanner },
1.64      markus    316:        { "reversemappingcheck", sReverseMappingCheck },
1.77      beck      317:        { "clientaliveinterval", sClientAliveInterval },
                    318:        { "clientalivecountmax", sClientAliveCountMax },
1.82      markus    319:        { "authorizedkeysfile", sAuthorizedKeysFile },
                    320:        { "authorizedkeysfile2", sAuthorizedKeysFile2 },
1.25      markus    321:        { NULL, 0 }
1.1       deraadt   322: };
                    323:
1.27      markus    324: /*
1.73      stevesk   325:  * Returns the number of the token pointed to by cp or sBadOption.
1.27      markus    326:  */
1.1       deraadt   327:
1.34      markus    328: static ServerOpCodes
1.25      markus    329: parse_token(const char *cp, const char *filename,
                    330:            int linenum)
1.1       deraadt   331: {
1.55      markus    332:        u_int i;
1.1       deraadt   333:
1.25      markus    334:        for (i = 0; keywords[i].name; i++)
1.28      markus    335:                if (strcasecmp(cp, keywords[i].name) == 0)
1.25      markus    336:                        return keywords[i].opcode;
                    337:
1.78      stevesk   338:        error("%s: line %d: Bad configuration option: %s",
                    339:            filename, linenum, cp);
1.25      markus    340:        return sBadOption;
1.1       deraadt   341: }
                    342:
1.84      itojun    343: static void
1.76      stevesk   344: add_listen_addr(ServerOptions *options, char *addr, u_short port)
1.74      stevesk   345: {
                    346:        int i;
                    347:
                    348:        if (options->num_ports == 0)
                    349:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
1.76      stevesk   350:        if (port == 0)
1.74      stevesk   351:                for (i = 0; i < options->num_ports; i++)
                    352:                        add_one_listen_addr(options, addr, options->ports[i]);
                    353:        else
1.76      stevesk   354:                add_one_listen_addr(options, addr, port);
1.74      stevesk   355: }
                    356:
1.84      itojun    357: static void
1.74      stevesk   358: add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
1.29      markus    359: {
                    360:        struct addrinfo hints, *ai, *aitop;
                    361:        char strport[NI_MAXSERV];
                    362:        int gaierr;
                    363:
1.74      stevesk   364:        memset(&hints, 0, sizeof(hints));
                    365:        hints.ai_family = IPv4or6;
                    366:        hints.ai_socktype = SOCK_STREAM;
                    367:        hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
                    368:        snprintf(strport, sizeof strport, "%d", port);
                    369:        if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
                    370:                fatal("bad addr or host: %s (%s)",
                    371:                    addr ? addr : "<NULL>",
                    372:                    gai_strerror(gaierr));
                    373:        for (ai = aitop; ai->ai_next; ai = ai->ai_next)
                    374:                ;
                    375:        ai->ai_next = options->listen_addrs;
                    376:        options->listen_addrs = aitop;
1.29      markus    377: }
                    378:
1.1       deraadt   379: /* Reads the server configuration file. */
                    380:
1.34      markus    381: void
1.25      markus    382: read_server_config(ServerOptions *options, const char *filename)
1.1       deraadt   383: {
1.25      markus    384:        FILE *f;
                    385:        char line[1024];
1.74      stevesk   386:        char *cp, **charptr, *arg, *p;
1.25      markus    387:        int linenum, *intptr, value;
                    388:        int bad_options = 0;
                    389:        ServerOpCodes opcode;
1.87      stevesk   390:        int i, n;
1.25      markus    391:
                    392:        f = fopen(filename, "r");
                    393:        if (!f) {
                    394:                perror(filename);
1.1       deraadt   395:                exit(1);
1.25      markus    396:        }
                    397:        linenum = 0;
                    398:        while (fgets(line, sizeof(line), f)) {
                    399:                linenum++;
1.48      provos    400:                cp = line;
                    401:                arg = strdelim(&cp);
                    402:                /* Ignore leading whitespace */
                    403:                if (*arg == '\0')
1.49      markus    404:                        arg = strdelim(&cp);
1.61      djm       405:                if (!arg || !*arg || *arg == '#')
1.25      markus    406:                        continue;
1.54      markus    407:                intptr = NULL;
                    408:                charptr = NULL;
1.47      ho        409:                opcode = parse_token(arg, filename, linenum);
1.25      markus    410:                switch (opcode) {
                    411:                case sBadOption:
                    412:                        bad_options++;
                    413:                        continue;
                    414:                case sPort:
1.29      markus    415:                        /* ignore ports from configfile if cmdline specifies ports */
                    416:                        if (options->ports_from_cmdline)
                    417:                                continue;
                    418:                        if (options->listen_addrs != NULL)
                    419:                                fatal("%s line %d: ports must be specified before "
1.79      stevesk   420:                                    "ListenAdress.", filename, linenum);
1.29      markus    421:                        if (options->num_ports >= MAX_PORTS)
1.70      millert   422:                                fatal("%s line %d: too many ports.",
1.34      markus    423:                                    filename, linenum);
1.48      provos    424:                        arg = strdelim(&cp);
1.47      ho        425:                        if (!arg || *arg == '\0')
1.70      millert   426:                                fatal("%s line %d: missing port number.",
1.29      markus    427:                                    filename, linenum);
1.76      stevesk   428:                        options->ports[options->num_ports++] = a2port(arg);
                    429:                        if (options->ports[options->num_ports-1] == 0)
                    430:                                fatal("%s line %d: Badly formatted port number.",
                    431:                                    filename, linenum);
1.29      markus    432:                        break;
                    433:
                    434:                case sServerKeyBits:
                    435:                        intptr = &options->server_key_bits;
1.25      markus    436: parse_int:
1.48      provos    437:                        arg = strdelim(&cp);
1.78      stevesk   438:                        if (!arg || *arg == '\0')
                    439:                                fatal("%s line %d: missing integer value.",
                    440:                                    filename, linenum);
1.47      ho        441:                        value = atoi(arg);
1.25      markus    442:                        if (*intptr == -1)
                    443:                                *intptr = value;
                    444:                        break;
                    445:
                    446:                case sLoginGraceTime:
                    447:                        intptr = &options->login_grace_time;
1.81      stevesk   448: parse_time:
                    449:                        arg = strdelim(&cp);
                    450:                        if (!arg || *arg == '\0')
                    451:                                fatal("%s line %d: missing time value.",
                    452:                                    filename, linenum);
                    453:                        if ((value = convtime(arg)) == -1)
                    454:                                fatal("%s line %d: invalid time value.",
                    455:                                    filename, linenum);
                    456:                        if (*intptr == -1)
                    457:                                *intptr = value;
                    458:                        break;
1.25      markus    459:
                    460:                case sKeyRegenerationTime:
                    461:                        intptr = &options->key_regeneration_time;
1.81      stevesk   462:                        goto parse_time;
1.25      markus    463:
                    464:                case sListenAddress:
1.48      provos    465:                        arg = strdelim(&cp);
1.74      stevesk   466:                        if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
1.70      millert   467:                                fatal("%s line %d: missing inet addr.",
1.29      markus    468:                                    filename, linenum);
1.74      stevesk   469:                        if (*arg == '[') {
                    470:                                if ((p = strchr(arg, ']')) == NULL)
                    471:                                        fatal("%s line %d: bad ipv6 inet addr usage.",
                    472:                                            filename, linenum);
                    473:                                arg++;
                    474:                                memmove(p, p+1, strlen(p+1)+1);
                    475:                        } else if (((p = strchr(arg, ':')) == NULL) ||
                    476:                                    (strchr(p+1, ':') != NULL)) {
1.76      stevesk   477:                                add_listen_addr(options, arg, 0);
1.74      stevesk   478:                                break;
                    479:                        }
                    480:                        if (*p == ':') {
1.76      stevesk   481:                                u_short port;
                    482:
1.74      stevesk   483:                                p++;
                    484:                                if (*p == '\0')
                    485:                                        fatal("%s line %d: bad inet addr:port usage.",
                    486:                                            filename, linenum);
                    487:                                else {
                    488:                                        *(p-1) = '\0';
1.76      stevesk   489:                                        if ((port = a2port(p)) == 0)
                    490:                                                fatal("%s line %d: bad port number.",
                    491:                                                    filename, linenum);
                    492:                                        add_listen_addr(options, arg, port);
1.74      stevesk   493:                                }
                    494:                        } else if (*p == '\0')
1.76      stevesk   495:                                add_listen_addr(options, arg, 0);
1.74      stevesk   496:                        else
                    497:                                fatal("%s line %d: bad inet addr usage.",
                    498:                                    filename, linenum);
1.25      markus    499:                        break;
                    500:
                    501:                case sHostKeyFile:
1.54      markus    502:                        intptr = &options->num_host_key_files;
1.78      stevesk   503:                        if (*intptr >= MAX_HOSTKEYS)
                    504:                                fatal("%s line %d: too many host keys specified (max %d).",
1.54      markus    505:                                    filename, linenum, MAX_HOSTKEYS);
                    506:                        charptr = &options->host_key_files[*intptr];
1.42      markus    507: parse_filename:
1.48      provos    508:                        arg = strdelim(&cp);
1.78      stevesk   509:                        if (!arg || *arg == '\0')
                    510:                                fatal("%s line %d: missing file name.",
1.36      markus    511:                                    filename, linenum);
1.54      markus    512:                        if (*charptr == NULL) {
1.47      ho        513:                                *charptr = tilde_expand_filename(arg, getuid());
1.54      markus    514:                                /* increase optional counter */
                    515:                                if (intptr != NULL)
                    516:                                        *intptr = *intptr + 1;
                    517:                        }
1.36      markus    518:                        break;
                    519:
                    520:                case sPidFile:
                    521:                        charptr = &options->pid_file;
1.42      markus    522:                        goto parse_filename;
1.25      markus    523:
                    524:                case sPermitRootLogin:
                    525:                        intptr = &options->permit_root_login;
1.48      provos    526:                        arg = strdelim(&cp);
1.78      stevesk   527:                        if (!arg || *arg == '\0')
                    528:                                fatal("%s line %d: missing yes/"
1.71      stevesk   529:                                    "without-password/forced-commands-only/no "
1.78      stevesk   530:                                    "argument.", filename, linenum);
                    531:                        value = 0;      /* silence compiler */
1.47      ho        532:                        if (strcmp(arg, "without-password") == 0)
1.67      markus    533:                                value = PERMIT_NO_PASSWD;
                    534:                        else if (strcmp(arg, "forced-commands-only") == 0)
                    535:                                value = PERMIT_FORCED_ONLY;
1.47      ho        536:                        else if (strcmp(arg, "yes") == 0)
1.67      markus    537:                                value = PERMIT_YES;
1.47      ho        538:                        else if (strcmp(arg, "no") == 0)
1.67      markus    539:                                value = PERMIT_NO;
1.78      stevesk   540:                        else
                    541:                                fatal("%s line %d: Bad yes/"
1.67      markus    542:                                    "without-password/forced-commands-only/no "
1.78      stevesk   543:                                    "argument: %s", filename, linenum, arg);
1.25      markus    544:                        if (*intptr == -1)
                    545:                                *intptr = value;
                    546:                        break;
                    547:
                    548:                case sIgnoreRhosts:
                    549:                        intptr = &options->ignore_rhosts;
                    550: parse_flag:
1.48      provos    551:                        arg = strdelim(&cp);
1.78      stevesk   552:                        if (!arg || *arg == '\0')
                    553:                                fatal("%s line %d: missing yes/no argument.",
                    554:                                    filename, linenum);
                    555:                        value = 0;      /* silence compiler */
1.47      ho        556:                        if (strcmp(arg, "yes") == 0)
1.25      markus    557:                                value = 1;
1.47      ho        558:                        else if (strcmp(arg, "no") == 0)
1.25      markus    559:                                value = 0;
1.78      stevesk   560:                        else
                    561:                                fatal("%s line %d: Bad yes/no argument: %s",
1.47      ho        562:                                        filename, linenum, arg);
1.25      markus    563:                        if (*intptr == -1)
                    564:                                *intptr = value;
                    565:                        break;
                    566:
                    567:                case sIgnoreUserKnownHosts:
                    568:                        intptr = &options->ignore_user_known_hosts;
1.31      markus    569:                        goto parse_flag;
1.25      markus    570:
                    571:                case sRhostsAuthentication:
                    572:                        intptr = &options->rhosts_authentication;
                    573:                        goto parse_flag;
                    574:
                    575:                case sRhostsRSAAuthentication:
                    576:                        intptr = &options->rhosts_rsa_authentication;
1.75      markus    577:                        goto parse_flag;
                    578:
                    579:                case sHostbasedAuthentication:
                    580:                        intptr = &options->hostbased_authentication;
                    581:                        goto parse_flag;
                    582:
                    583:                case sHostbasedUsesNameFromPacketOnly:
                    584:                        intptr = &options->hostbased_uses_name_from_packet_only;
1.25      markus    585:                        goto parse_flag;
                    586:
                    587:                case sRSAAuthentication:
                    588:                        intptr = &options->rsa_authentication;
1.39      markus    589:                        goto parse_flag;
                    590:
1.54      markus    591:                case sPubkeyAuthentication:
                    592:                        intptr = &options->pubkey_authentication;
1.25      markus    593:                        goto parse_flag;
1.85      dugsong   594: #if defined(KRB4) || defined(KRB5)
1.25      markus    595:                case sKerberosAuthentication:
                    596:                        intptr = &options->kerberos_authentication;
                    597:                        goto parse_flag;
                    598:
                    599:                case sKerberosOrLocalPasswd:
                    600:                        intptr = &options->kerberos_or_local_passwd;
                    601:                        goto parse_flag;
                    602:
                    603:                case sKerberosTicketCleanup:
                    604:                        intptr = &options->kerberos_ticket_cleanup;
                    605:                        goto parse_flag;
1.1       deraadt   606: #endif
1.85      dugsong   607: #if defined(AFS) || defined(KRB5)
1.25      markus    608:                case sKerberosTgtPassing:
                    609:                        intptr = &options->kerberos_tgt_passing;
                    610:                        goto parse_flag;
1.85      dugsong   611: #endif
                    612: #ifdef AFS
1.25      markus    613:                case sAFSTokenPassing:
                    614:                        intptr = &options->afs_token_passing;
                    615:                        goto parse_flag;
                    616: #endif
                    617:
                    618:                case sPasswordAuthentication:
                    619:                        intptr = &options->password_authentication;
1.52      markus    620:                        goto parse_flag;
                    621:
                    622:                case sKbdInteractiveAuthentication:
                    623:                        intptr = &options->kbd_interactive_authentication;
1.25      markus    624:                        goto parse_flag;
                    625:
1.63      markus    626:                case sChallengeResponseAuthentication:
1.80      markus    627:                        intptr = &options->challenge_response_authentication;
1.25      markus    628:                        goto parse_flag;
                    629:
                    630:                case sPrintMotd:
                    631:                        intptr = &options->print_motd;
1.72      stevesk   632:                        goto parse_flag;
                    633:
                    634:                case sPrintLastLog:
                    635:                        intptr = &options->print_lastlog;
1.25      markus    636:                        goto parse_flag;
                    637:
                    638:                case sX11Forwarding:
                    639:                        intptr = &options->x11_forwarding;
                    640:                        goto parse_flag;
                    641:
                    642:                case sX11DisplayOffset:
                    643:                        intptr = &options->x11_display_offset;
                    644:                        goto parse_int;
                    645:
1.42      markus    646:                case sXAuthLocation:
                    647:                        charptr = &options->xauth_location;
                    648:                        goto parse_filename;
1.65      stevesk   649:
1.25      markus    650:                case sStrictModes:
                    651:                        intptr = &options->strict_modes;
                    652:                        goto parse_flag;
                    653:
                    654:                case sKeepAlives:
                    655:                        intptr = &options->keepalives;
                    656:                        goto parse_flag;
                    657:
                    658:                case sEmptyPasswd:
                    659:                        intptr = &options->permit_empty_passwd;
                    660:                        goto parse_flag;
                    661:
                    662:                case sUseLogin:
                    663:                        intptr = &options->use_login;
1.38      markus    664:                        goto parse_flag;
                    665:
                    666:                case sGatewayPorts:
                    667:                        intptr = &options->gateway_ports;
1.64      markus    668:                        goto parse_flag;
                    669:
                    670:                case sReverseMappingCheck:
                    671:                        intptr = &options->reverse_mapping_check;
1.25      markus    672:                        goto parse_flag;
                    673:
                    674:                case sLogFacility:
                    675:                        intptr = (int *) &options->log_facility;
1.48      provos    676:                        arg = strdelim(&cp);
1.47      ho        677:                        value = log_facility_number(arg);
1.25      markus    678:                        if (value == (SyslogFacility) - 1)
1.70      millert   679:                                fatal("%.200s line %d: unsupported log facility '%s'",
1.47      ho        680:                                    filename, linenum, arg ? arg : "<NONE>");
1.25      markus    681:                        if (*intptr == -1)
                    682:                                *intptr = (SyslogFacility) value;
                    683:                        break;
                    684:
                    685:                case sLogLevel:
                    686:                        intptr = (int *) &options->log_level;
1.48      provos    687:                        arg = strdelim(&cp);
1.47      ho        688:                        value = log_level_number(arg);
1.25      markus    689:                        if (value == (LogLevel) - 1)
1.70      millert   690:                                fatal("%.200s line %d: unsupported log level '%s'",
1.47      ho        691:                                    filename, linenum, arg ? arg : "<NONE>");
1.25      markus    692:                        if (*intptr == -1)
                    693:                                *intptr = (LogLevel) value;
                    694:                        break;
1.53      markus    695:
                    696:                case sAllowTcpForwarding:
                    697:                        intptr = &options->allow_tcp_forwarding;
                    698:                        goto parse_flag;
1.25      markus    699:
                    700:                case sAllowUsers:
1.48      provos    701:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33      markus    702:                                if (options->num_allow_users >= MAX_ALLOW_USERS)
1.70      millert   703:                                        fatal("%s line %d: too many allow users.",
1.33      markus    704:                                            filename, linenum);
1.47      ho        705:                                options->allow_users[options->num_allow_users++] = xstrdup(arg);
1.25      markus    706:                        }
                    707:                        break;
                    708:
                    709:                case sDenyUsers:
1.48      provos    710:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33      markus    711:                                if (options->num_deny_users >= MAX_DENY_USERS)
1.70      millert   712:                                        fatal( "%s line %d: too many deny users.",
1.33      markus    713:                                            filename, linenum);
1.47      ho        714:                                options->deny_users[options->num_deny_users++] = xstrdup(arg);
1.25      markus    715:                        }
                    716:                        break;
                    717:
                    718:                case sAllowGroups:
1.48      provos    719:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33      markus    720:                                if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1.70      millert   721:                                        fatal("%s line %d: too many allow groups.",
1.33      markus    722:                                            filename, linenum);
1.47      ho        723:                                options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
1.25      markus    724:                        }
                    725:                        break;
                    726:
                    727:                case sDenyGroups:
1.48      provos    728:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33      markus    729:                                if (options->num_deny_groups >= MAX_DENY_GROUPS)
1.70      millert   730:                                        fatal("%s line %d: too many deny groups.",
1.33      markus    731:                                            filename, linenum);
1.47      ho        732:                                options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
1.25      markus    733:                        }
1.33      markus    734:                        break;
                    735:
                    736:                case sCiphers:
1.48      provos    737:                        arg = strdelim(&cp);
1.47      ho        738:                        if (!arg || *arg == '\0')
1.41      markus    739:                                fatal("%s line %d: Missing argument.", filename, linenum);
1.47      ho        740:                        if (!ciphers_valid(arg))
1.40      markus    741:                                fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1.47      ho        742:                                    filename, linenum, arg ? arg : "<NONE>");
1.33      markus    743:                        if (options->ciphers == NULL)
1.47      ho        744:                                options->ciphers = xstrdup(arg);
1.66      markus    745:                        break;
                    746:
                    747:                case sMacs:
                    748:                        arg = strdelim(&cp);
                    749:                        if (!arg || *arg == '\0')
                    750:                                fatal("%s line %d: Missing argument.", filename, linenum);
                    751:                        if (!mac_valid(arg))
                    752:                                fatal("%s line %d: Bad SSH2 mac spec '%s'.",
                    753:                                    filename, linenum, arg ? arg : "<NONE>");
                    754:                        if (options->macs == NULL)
                    755:                                options->macs = xstrdup(arg);
1.33      markus    756:                        break;
                    757:
                    758:                case sProtocol:
                    759:                        intptr = &options->protocol;
1.48      provos    760:                        arg = strdelim(&cp);
1.47      ho        761:                        if (!arg || *arg == '\0')
1.41      markus    762:                                fatal("%s line %d: Missing argument.", filename, linenum);
1.47      ho        763:                        value = proto_spec(arg);
1.33      markus    764:                        if (value == SSH_PROTO_UNKNOWN)
                    765:                                fatal("%s line %d: Bad protocol spec '%s'.",
1.47      ho        766:                                      filename, linenum, arg ? arg : "<NONE>");
1.33      markus    767:                        if (*intptr == SSH_PROTO_UNKNOWN)
                    768:                                *intptr = value;
1.43      jakob     769:                        break;
                    770:
                    771:                case sSubsystem:
                    772:                        if(options->num_subsystems >= MAX_SUBSYSTEMS) {
                    773:                                fatal("%s line %d: too many subsystems defined.",
                    774:                                      filename, linenum);
                    775:                        }
1.48      provos    776:                        arg = strdelim(&cp);
1.47      ho        777:                        if (!arg || *arg == '\0')
1.43      jakob     778:                                fatal("%s line %d: Missing subsystem name.",
                    779:                                      filename, linenum);
                    780:                        for (i = 0; i < options->num_subsystems; i++)
1.47      ho        781:                                if(strcmp(arg, options->subsystem_name[i]) == 0)
1.43      jakob     782:                                        fatal("%s line %d: Subsystem '%s' already defined.",
1.47      ho        783:                                              filename, linenum, arg);
                    784:                        options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1.48      provos    785:                        arg = strdelim(&cp);
1.47      ho        786:                        if (!arg || *arg == '\0')
1.43      jakob     787:                                fatal("%s line %d: Missing subsystem command.",
                    788:                                      filename, linenum);
1.47      ho        789:                        options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.43      jakob     790:                        options->num_subsystems++;
1.25      markus    791:                        break;
1.46      markus    792:
                    793:                case sMaxStartups:
1.50      markus    794:                        arg = strdelim(&cp);
                    795:                        if (!arg || *arg == '\0')
                    796:                                fatal("%s line %d: Missing MaxStartups spec.",
                    797:                                      filename, linenum);
1.87      stevesk   798:                        if ((n = sscanf(arg, "%d:%d:%d",
1.50      markus    799:                            &options->max_startups_begin,
                    800:                            &options->max_startups_rate,
1.87      stevesk   801:                            &options->max_startups)) == 3) {
1.50      markus    802:                                if (options->max_startups_begin >
                    803:                                    options->max_startups ||
                    804:                                    options->max_startups_rate > 100 ||
                    805:                                    options->max_startups_rate < 1)
1.87      stevesk   806:                                        fatal("%s line %d: Illegal MaxStartups spec.",
                    807:                                            filename, linenum);
                    808:                        } else if (n != 1)
1.50      markus    809:                                fatal("%s line %d: Illegal MaxStartups spec.",
1.87      stevesk   810:                                    filename, linenum);
                    811:                        else
                    812:                                options->max_startups = options->max_startups_begin;
                    813:                        break;
1.25      markus    814:
1.57      markus    815:                case sBanner:
                    816:                        charptr = &options->banner;
1.82      markus    817:                        goto parse_filename;
                    818:                /*
                    819:                 * These options can contain %X options expanded at
                    820:                 * connect time, so that you can specify paths like:
                    821:                 *
                    822:                 * AuthorizedKeysFile   /etc/ssh_keys/%u
                    823:                 */
                    824:                case sAuthorizedKeysFile:
                    825:                case sAuthorizedKeysFile2:
                    826:                        charptr = (opcode == sAuthorizedKeysFile ) ?
                    827:                            &options->authorized_keys_file :
                    828:                            &options->authorized_keys_file2;
1.57      markus    829:                        goto parse_filename;
1.81      stevesk   830:
1.77      beck      831:                case sClientAliveInterval:
                    832:                        intptr = &options->client_alive_interval;
1.81      stevesk   833:                        goto parse_time;
                    834:
1.77      beck      835:                case sClientAliveCountMax:
                    836:                        intptr = &options->client_alive_count_max;
                    837:                        goto parse_int;
1.89      jakob     838:
                    839:                case sDeprecated:
                    840:                        log("%s line %d: Deprecated option %s",
                    841:                            filename, linenum, arg);
                    842:                        while(arg)
                    843:                            arg = strdelim(&cp);
                    844:                        break;
1.81      stevesk   845:
1.25      markus    846:                default:
1.78      stevesk   847:                        fatal("%s line %d: Missing handler for opcode %s (%d)",
                    848:                            filename, linenum, arg, opcode);
1.13      markus    849:                }
1.78      stevesk   850:                if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
                    851:                        fatal("%s line %d: garbage at end of line; \"%.200s\".",
                    852:                            filename, linenum, arg);
1.1       deraadt   853:        }
1.25      markus    854:        fclose(f);
1.78      stevesk   855:        if (bad_options > 0)
                    856:                fatal("%s: terminating, %d bad configuration options",
                    857:                    filename, bad_options);
1.1       deraadt   858: }