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

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.62    ! markus     13: RCSID("$OpenBSD: servconf.c,v 1.61 2001/01/20 23:00:56 djm Exp $");
        !            14:
        !            15: #ifdef KRB4
        !            16: #include <krb.h>
        !            17: #endif
        !            18: #ifdef AFS
        !            19: #include <kafs.h>
        !            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.1       deraadt    31:
1.29      markus     32: /* add listen address */
                     33: void add_listen_addr(ServerOptions *options, char *addr);
                     34:
1.62    ! markus     35: /* AF_UNSPEC or AF_INET or AF_INET6 */
        !            36: extern int IPv4or6;
        !            37:
1.1       deraadt    38: /* Initializes the server options to their default values. */
                     39:
1.34      markus     40: void
1.25      markus     41: initialize_server_options(ServerOptions *options)
1.1       deraadt    42: {
1.25      markus     43:        memset(options, 0, sizeof(*options));
1.29      markus     44:        options->num_ports = 0;
                     45:        options->ports_from_cmdline = 0;
                     46:        options->listen_addrs = NULL;
1.54      markus     47:        options->num_host_key_files = 0;
1.36      markus     48:        options->pid_file = NULL;
1.25      markus     49:        options->server_key_bits = -1;
                     50:        options->login_grace_time = -1;
                     51:        options->key_regeneration_time = -1;
                     52:        options->permit_root_login = -1;
                     53:        options->ignore_rhosts = -1;
                     54:        options->ignore_user_known_hosts = -1;
                     55:        options->print_motd = -1;
                     56:        options->check_mail = -1;
                     57:        options->x11_forwarding = -1;
                     58:        options->x11_display_offset = -1;
1.42      markus     59:        options->xauth_location = NULL;
1.25      markus     60:        options->strict_modes = -1;
                     61:        options->keepalives = -1;
                     62:        options->log_facility = (SyslogFacility) - 1;
                     63:        options->log_level = (LogLevel) - 1;
                     64:        options->rhosts_authentication = -1;
                     65:        options->rhosts_rsa_authentication = -1;
                     66:        options->rsa_authentication = -1;
1.54      markus     67:        options->pubkey_authentication = -1;
1.1       deraadt    68: #ifdef KRB4
1.25      markus     69:        options->kerberos_authentication = -1;
                     70:        options->kerberos_or_local_passwd = -1;
                     71:        options->kerberos_ticket_cleanup = -1;
1.1       deraadt    72: #endif
1.4       dugsong    73: #ifdef AFS
1.25      markus     74:        options->kerberos_tgt_passing = -1;
                     75:        options->afs_token_passing = -1;
1.1       deraadt    76: #endif
1.25      markus     77:        options->password_authentication = -1;
1.52      markus     78:        options->kbd_interactive_authentication = -1;
1.25      markus     79:        options->skey_authentication = -1;
                     80:        options->permit_empty_passwd = -1;
                     81:        options->use_login = -1;
1.53      markus     82:        options->allow_tcp_forwarding = -1;
1.25      markus     83:        options->num_allow_users = 0;
                     84:        options->num_deny_users = 0;
                     85:        options->num_allow_groups = 0;
                     86:        options->num_deny_groups = 0;
1.33      markus     87:        options->ciphers = NULL;
                     88:        options->protocol = SSH_PROTO_UNKNOWN;
1.38      markus     89:        options->gateway_ports = -1;
1.43      jakob      90:        options->num_subsystems = 0;
1.50      markus     91:        options->max_startups_begin = -1;
                     92:        options->max_startups_rate = -1;
1.46      markus     93:        options->max_startups = -1;
1.57      markus     94:        options->banner = NULL;
1.1       deraadt    95: }
                     96:
1.34      markus     97: void
1.25      markus     98: fill_default_server_options(ServerOptions *options)
1.1       deraadt    99: {
1.54      markus    100:        if (options->protocol == SSH_PROTO_UNKNOWN)
                    101:                options->protocol = SSH_PROTO_1|SSH_PROTO_2;
                    102:        if (options->num_host_key_files == 0) {
                    103:                /* fill default hostkeys for protocols */
                    104:                if (options->protocol & SSH_PROTO_1)
1.60      markus    105:                        options->host_key_files[options->num_host_key_files++] = _PATH_HOST_KEY_FILE;
1.54      markus    106:                if (options->protocol & SSH_PROTO_2)
1.60      markus    107:                        options->host_key_files[options->num_host_key_files++] = _PATH_HOST_DSA_KEY_FILE;
1.54      markus    108:        }
1.29      markus    109:        if (options->num_ports == 0)
                    110:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
                    111:        if (options->listen_addrs == NULL)
                    112:                add_listen_addr(options, NULL);
1.36      markus    113:        if (options->pid_file == NULL)
1.60      markus    114:                options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
1.25      markus    115:        if (options->server_key_bits == -1)
                    116:                options->server_key_bits = 768;
                    117:        if (options->login_grace_time == -1)
                    118:                options->login_grace_time = 600;
                    119:        if (options->key_regeneration_time == -1)
                    120:                options->key_regeneration_time = 3600;
                    121:        if (options->permit_root_login == -1)
                    122:                options->permit_root_login = 1;                 /* yes */
                    123:        if (options->ignore_rhosts == -1)
1.30      markus    124:                options->ignore_rhosts = 1;
1.25      markus    125:        if (options->ignore_user_known_hosts == -1)
                    126:                options->ignore_user_known_hosts = 0;
                    127:        if (options->check_mail == -1)
                    128:                options->check_mail = 0;
                    129:        if (options->print_motd == -1)
                    130:                options->print_motd = 1;
                    131:        if (options->x11_forwarding == -1)
1.30      markus    132:                options->x11_forwarding = 0;
1.25      markus    133:        if (options->x11_display_offset == -1)
1.30      markus    134:                options->x11_display_offset = 10;
1.42      markus    135: #ifdef XAUTH_PATH
                    136:        if (options->xauth_location == NULL)
                    137:                options->xauth_location = XAUTH_PATH;
                    138: #endif /* XAUTH_PATH */
1.25      markus    139:        if (options->strict_modes == -1)
                    140:                options->strict_modes = 1;
                    141:        if (options->keepalives == -1)
                    142:                options->keepalives = 1;
                    143:        if (options->log_facility == (SyslogFacility) (-1))
                    144:                options->log_facility = SYSLOG_FACILITY_AUTH;
                    145:        if (options->log_level == (LogLevel) (-1))
1.58      markus    146:                options->log_level = SYSLOG_LEVEL_INFO;
1.25      markus    147:        if (options->rhosts_authentication == -1)
                    148:                options->rhosts_authentication = 0;
                    149:        if (options->rhosts_rsa_authentication == -1)
1.30      markus    150:                options->rhosts_rsa_authentication = 0;
1.25      markus    151:        if (options->rsa_authentication == -1)
                    152:                options->rsa_authentication = 1;
1.54      markus    153:        if (options->pubkey_authentication == -1)
                    154:                options->pubkey_authentication = 1;
1.1       deraadt   155: #ifdef KRB4
1.25      markus    156:        if (options->kerberos_authentication == -1)
                    157:                options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
                    158:        if (options->kerberos_or_local_passwd == -1)
                    159:                options->kerberos_or_local_passwd = 1;
                    160:        if (options->kerberos_ticket_cleanup == -1)
                    161:                options->kerberos_ticket_cleanup = 1;
1.4       dugsong   162: #endif /* KRB4 */
                    163: #ifdef AFS
1.25      markus    164:        if (options->kerberos_tgt_passing == -1)
                    165:                options->kerberos_tgt_passing = 0;
                    166:        if (options->afs_token_passing == -1)
                    167:                options->afs_token_passing = k_hasafs();
1.4       dugsong   168: #endif /* AFS */
1.25      markus    169:        if (options->password_authentication == -1)
                    170:                options->password_authentication = 1;
1.52      markus    171:        if (options->kbd_interactive_authentication == -1)
                    172:                options->kbd_interactive_authentication = 0;
1.25      markus    173:        if (options->skey_authentication == -1)
                    174:                options->skey_authentication = 1;
                    175:        if (options->permit_empty_passwd == -1)
1.30      markus    176:                options->permit_empty_passwd = 0;
1.25      markus    177:        if (options->use_login == -1)
                    178:                options->use_login = 0;
1.53      markus    179:        if (options->allow_tcp_forwarding == -1)
                    180:                options->allow_tcp_forwarding = 1;
1.38      markus    181:        if (options->gateway_ports == -1)
                    182:                options->gateway_ports = 0;
1.46      markus    183:        if (options->max_startups == -1)
                    184:                options->max_startups = 10;
1.50      markus    185:        if (options->max_startups_rate == -1)
                    186:                options->max_startups_rate = 100;               /* 100% */
                    187:        if (options->max_startups_begin == -1)
                    188:                options->max_startups_begin = options->max_startups;
1.1       deraadt   189: }
                    190:
                    191: /* Keyword tokens. */
1.25      markus    192: typedef enum {
                    193:        sBadOption,             /* == unknown option */
                    194:        sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
                    195:        sPermitRootLogin, sLogFacility, sLogLevel,
                    196:        sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
1.1       deraadt   197: #ifdef KRB4
1.25      markus    198:        sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.1       deraadt   199: #endif
                    200: #ifdef AFS
1.25      markus    201:        sKerberosTgtPassing, sAFSTokenPassing,
1.1       deraadt   202: #endif
1.25      markus    203:        sSkeyAuthentication,
1.52      markus    204:        sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
1.25      markus    205:        sPrintMotd, sIgnoreRhosts, sX11Forwarding, sX11DisplayOffset,
                    206:        sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail,
1.53      markus    207:        sUseLogin, sAllowTcpForwarding,
                    208:        sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.54      markus    209:        sIgnoreUserKnownHosts, sCiphers, sProtocol, sPidFile,
                    210:        sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
1.57      markus    211:        sBanner
1.1       deraadt   212: } ServerOpCodes;
                    213:
                    214: /* Textual representation of the tokens. */
1.25      markus    215: static struct {
                    216:        const char *name;
                    217:        ServerOpCodes opcode;
                    218: } keywords[] = {
                    219:        { "port", sPort },
                    220:        { "hostkey", sHostKeyFile },
1.54      markus    221:        { "hostdsakey", sHostKeyFile },                                 /* alias */
1.36      markus    222:        { "pidfile", sPidFile },
1.25      markus    223:        { "serverkeybits", sServerKeyBits },
                    224:        { "logingracetime", sLoginGraceTime },
                    225:        { "keyregenerationinterval", sKeyRegenerationTime },
                    226:        { "permitrootlogin", sPermitRootLogin },
                    227:        { "syslogfacility", sLogFacility },
                    228:        { "loglevel", sLogLevel },
                    229:        { "rhostsauthentication", sRhostsAuthentication },
                    230:        { "rhostsrsaauthentication", sRhostsRSAAuthentication },
                    231:        { "rsaauthentication", sRSAAuthentication },
1.54      markus    232:        { "pubkeyauthentication", sPubkeyAuthentication },
                    233:        { "dsaauthentication", sPubkeyAuthentication },                 /* alias */
1.1       deraadt   234: #ifdef KRB4
1.25      markus    235:        { "kerberosauthentication", sKerberosAuthentication },
                    236:        { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
                    237:        { "kerberosticketcleanup", sKerberosTicketCleanup },
1.1       deraadt   238: #endif
1.4       dugsong   239: #ifdef AFS
1.25      markus    240:        { "kerberostgtpassing", sKerberosTgtPassing },
                    241:        { "afstokenpassing", sAFSTokenPassing },
1.1       deraadt   242: #endif
1.25      markus    243:        { "passwordauthentication", sPasswordAuthentication },
1.52      markus    244:        { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
1.25      markus    245:        { "skeyauthentication", sSkeyAuthentication },
                    246:        { "checkmail", sCheckMail },
                    247:        { "listenaddress", sListenAddress },
                    248:        { "printmotd", sPrintMotd },
                    249:        { "ignorerhosts", sIgnoreRhosts },
                    250:        { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
                    251:        { "x11forwarding", sX11Forwarding },
                    252:        { "x11displayoffset", sX11DisplayOffset },
1.42      markus    253:        { "xauthlocation", sXAuthLocation },
1.25      markus    254:        { "strictmodes", sStrictModes },
                    255:        { "permitemptypasswords", sEmptyPasswd },
                    256:        { "uselogin", sUseLogin },
                    257:        { "randomseed", sRandomSeedFile },
                    258:        { "keepalive", sKeepAlives },
1.53      markus    259:        { "allowtcpforwarding", sAllowTcpForwarding },
1.25      markus    260:        { "allowusers", sAllowUsers },
                    261:        { "denyusers", sDenyUsers },
                    262:        { "allowgroups", sAllowGroups },
                    263:        { "denygroups", sDenyGroups },
1.33      markus    264:        { "ciphers", sCiphers },
                    265:        { "protocol", sProtocol },
1.38      markus    266:        { "gatewayports", sGatewayPorts },
1.43      jakob     267:        { "subsystem", sSubsystem },
1.46      markus    268:        { "maxstartups", sMaxStartups },
1.57      markus    269:        { "banner", sBanner },
1.25      markus    270:        { NULL, 0 }
1.1       deraadt   271: };
                    272:
1.27      markus    273: /*
                    274:  * Returns the number of the token pointed to by cp of length len. Never
                    275:  * returns if the token is not known.
                    276:  */
1.1       deraadt   277:
1.34      markus    278: static ServerOpCodes
1.25      markus    279: parse_token(const char *cp, const char *filename,
                    280:            int linenum)
1.1       deraadt   281: {
1.55      markus    282:        u_int i;
1.1       deraadt   283:
1.25      markus    284:        for (i = 0; keywords[i].name; i++)
1.28      markus    285:                if (strcasecmp(cp, keywords[i].name) == 0)
1.25      markus    286:                        return keywords[i].opcode;
                    287:
                    288:        fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
                    289:                filename, linenum, cp);
                    290:        return sBadOption;
1.1       deraadt   291: }
                    292:
1.29      markus    293: /*
                    294:  * add listen address
                    295:  */
1.34      markus    296: void
1.29      markus    297: add_listen_addr(ServerOptions *options, char *addr)
                    298: {
                    299:        struct addrinfo hints, *ai, *aitop;
                    300:        char strport[NI_MAXSERV];
                    301:        int gaierr;
                    302:        int i;
                    303:
                    304:        if (options->num_ports == 0)
                    305:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
                    306:        for (i = 0; i < options->num_ports; i++) {
                    307:                memset(&hints, 0, sizeof(hints));
                    308:                hints.ai_family = IPv4or6;
                    309:                hints.ai_socktype = SOCK_STREAM;
                    310:                hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
                    311:                snprintf(strport, sizeof strport, "%d", options->ports[i]);
                    312:                if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
                    313:                        fatal("bad addr or host: %s (%s)\n",
                    314:                            addr ? addr : "<NULL>",
                    315:                            gai_strerror(gaierr));
                    316:                for (ai = aitop; ai->ai_next; ai = ai->ai_next)
                    317:                        ;
                    318:                ai->ai_next = options->listen_addrs;
                    319:                options->listen_addrs = aitop;
                    320:        }
                    321: }
                    322:
1.1       deraadt   323: /* Reads the server configuration file. */
                    324:
1.34      markus    325: void
1.25      markus    326: read_server_config(ServerOptions *options, const char *filename)
1.1       deraadt   327: {
1.25      markus    328:        FILE *f;
                    329:        char line[1024];
1.47      ho        330:        char *cp, **charptr, *arg;
1.25      markus    331:        int linenum, *intptr, value;
                    332:        int bad_options = 0;
                    333:        ServerOpCodes opcode;
1.43      jakob     334:        int i;
1.25      markus    335:
                    336:        f = fopen(filename, "r");
                    337:        if (!f) {
                    338:                perror(filename);
1.1       deraadt   339:                exit(1);
1.25      markus    340:        }
                    341:        linenum = 0;
                    342:        while (fgets(line, sizeof(line), f)) {
                    343:                linenum++;
1.48      provos    344:                cp = line;
                    345:                arg = strdelim(&cp);
                    346:                /* Ignore leading whitespace */
                    347:                if (*arg == '\0')
1.49      markus    348:                        arg = strdelim(&cp);
1.61      djm       349:                if (!arg || !*arg || *arg == '#')
1.25      markus    350:                        continue;
1.54      markus    351:                intptr = NULL;
                    352:                charptr = NULL;
1.47      ho        353:                opcode = parse_token(arg, filename, linenum);
1.25      markus    354:                switch (opcode) {
                    355:                case sBadOption:
                    356:                        bad_options++;
                    357:                        continue;
                    358:                case sPort:
1.29      markus    359:                        /* ignore ports from configfile if cmdline specifies ports */
                    360:                        if (options->ports_from_cmdline)
                    361:                                continue;
                    362:                        if (options->listen_addrs != NULL)
                    363:                                fatal("%s line %d: ports must be specified before "
                    364:                                    "ListenAdress.\n", filename, linenum);
                    365:                        if (options->num_ports >= MAX_PORTS)
                    366:                                fatal("%s line %d: too many ports.\n",
1.34      markus    367:                                    filename, linenum);
1.48      provos    368:                        arg = strdelim(&cp);
1.47      ho        369:                        if (!arg || *arg == '\0')
1.29      markus    370:                                fatal("%s line %d: missing port number.\n",
                    371:                                    filename, linenum);
1.47      ho        372:                        options->ports[options->num_ports++] = atoi(arg);
1.29      markus    373:                        break;
                    374:
                    375:                case sServerKeyBits:
                    376:                        intptr = &options->server_key_bits;
1.25      markus    377: parse_int:
1.48      provos    378:                        arg = strdelim(&cp);
1.47      ho        379:                        if (!arg || *arg == '\0') {
1.25      markus    380:                                fprintf(stderr, "%s line %d: missing integer value.\n",
                    381:                                        filename, linenum);
                    382:                                exit(1);
                    383:                        }
1.47      ho        384:                        value = atoi(arg);
1.25      markus    385:                        if (*intptr == -1)
                    386:                                *intptr = value;
                    387:                        break;
                    388:
                    389:                case sLoginGraceTime:
                    390:                        intptr = &options->login_grace_time;
                    391:                        goto parse_int;
                    392:
                    393:                case sKeyRegenerationTime:
                    394:                        intptr = &options->key_regeneration_time;
                    395:                        goto parse_int;
                    396:
                    397:                case sListenAddress:
1.48      provos    398:                        arg = strdelim(&cp);
1.47      ho        399:                        if (!arg || *arg == '\0')
1.29      markus    400:                                fatal("%s line %d: missing inet addr.\n",
                    401:                                    filename, linenum);
1.47      ho        402:                        add_listen_addr(options, arg);
1.25      markus    403:                        break;
                    404:
                    405:                case sHostKeyFile:
1.54      markus    406:                        intptr = &options->num_host_key_files;
                    407:                        if (*intptr >= MAX_HOSTKEYS) {
                    408:                                fprintf(stderr, "%s line %d: to many host keys specified (max %d).\n",
                    409:                                    filename, linenum, MAX_HOSTKEYS);
                    410:                                exit(1);
                    411:                        }
                    412:                        charptr = &options->host_key_files[*intptr];
1.42      markus    413: parse_filename:
1.48      provos    414:                        arg = strdelim(&cp);
1.47      ho        415:                        if (!arg || *arg == '\0') {
1.25      markus    416:                                fprintf(stderr, "%s line %d: missing file name.\n",
1.36      markus    417:                                    filename, linenum);
                    418:                                exit(1);
                    419:                        }
1.54      markus    420:                        if (*charptr == NULL) {
1.47      ho        421:                                *charptr = tilde_expand_filename(arg, getuid());
1.54      markus    422:                                /* increase optional counter */
                    423:                                if (intptr != NULL)
                    424:                                        *intptr = *intptr + 1;
                    425:                        }
1.36      markus    426:                        break;
                    427:
                    428:                case sPidFile:
                    429:                        charptr = &options->pid_file;
1.42      markus    430:                        goto parse_filename;
1.25      markus    431:
                    432:                case sRandomSeedFile:
                    433:                        fprintf(stderr, "%s line %d: \"randomseed\" option is obsolete.\n",
                    434:                                filename, linenum);
1.48      provos    435:                        arg = strdelim(&cp);
1.25      markus    436:                        break;
                    437:
                    438:                case sPermitRootLogin:
                    439:                        intptr = &options->permit_root_login;
1.48      provos    440:                        arg = strdelim(&cp);
1.47      ho        441:                        if (!arg || *arg == '\0') {
1.25      markus    442:                                fprintf(stderr, "%s line %d: missing yes/without-password/no argument.\n",
                    443:                                        filename, linenum);
                    444:                                exit(1);
                    445:                        }
1.47      ho        446:                        if (strcmp(arg, "without-password") == 0)
1.25      markus    447:                                value = 2;
1.47      ho        448:                        else if (strcmp(arg, "yes") == 0)
1.25      markus    449:                                value = 1;
1.47      ho        450:                        else if (strcmp(arg, "no") == 0)
1.25      markus    451:                                value = 0;
                    452:                        else {
                    453:                                fprintf(stderr, "%s line %d: Bad yes/without-password/no argument: %s\n",
1.47      ho        454:                                        filename, linenum, arg);
1.25      markus    455:                                exit(1);
                    456:                        }
                    457:                        if (*intptr == -1)
                    458:                                *intptr = value;
                    459:                        break;
                    460:
                    461:                case sIgnoreRhosts:
                    462:                        intptr = &options->ignore_rhosts;
                    463: parse_flag:
1.48      provos    464:                        arg = strdelim(&cp);
1.47      ho        465:                        if (!arg || *arg == '\0') {
1.25      markus    466:                                fprintf(stderr, "%s line %d: missing yes/no argument.\n",
                    467:                                        filename, linenum);
                    468:                                exit(1);
                    469:                        }
1.47      ho        470:                        if (strcmp(arg, "yes") == 0)
1.25      markus    471:                                value = 1;
1.47      ho        472:                        else if (strcmp(arg, "no") == 0)
1.25      markus    473:                                value = 0;
                    474:                        else {
                    475:                                fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
1.47      ho        476:                                        filename, linenum, arg);
1.25      markus    477:                                exit(1);
                    478:                        }
                    479:                        if (*intptr == -1)
                    480:                                *intptr = value;
                    481:                        break;
                    482:
                    483:                case sIgnoreUserKnownHosts:
                    484:                        intptr = &options->ignore_user_known_hosts;
1.31      markus    485:                        goto parse_flag;
1.25      markus    486:
                    487:                case sRhostsAuthentication:
                    488:                        intptr = &options->rhosts_authentication;
                    489:                        goto parse_flag;
                    490:
                    491:                case sRhostsRSAAuthentication:
                    492:                        intptr = &options->rhosts_rsa_authentication;
                    493:                        goto parse_flag;
                    494:
                    495:                case sRSAAuthentication:
                    496:                        intptr = &options->rsa_authentication;
1.39      markus    497:                        goto parse_flag;
                    498:
1.54      markus    499:                case sPubkeyAuthentication:
                    500:                        intptr = &options->pubkey_authentication;
1.25      markus    501:                        goto parse_flag;
                    502:
1.1       deraadt   503: #ifdef KRB4
1.25      markus    504:                case sKerberosAuthentication:
                    505:                        intptr = &options->kerberos_authentication;
                    506:                        goto parse_flag;
                    507:
                    508:                case sKerberosOrLocalPasswd:
                    509:                        intptr = &options->kerberos_or_local_passwd;
                    510:                        goto parse_flag;
                    511:
                    512:                case sKerberosTicketCleanup:
                    513:                        intptr = &options->kerberos_ticket_cleanup;
                    514:                        goto parse_flag;
1.1       deraadt   515: #endif
1.25      markus    516:
1.4       dugsong   517: #ifdef AFS
1.25      markus    518:                case sKerberosTgtPassing:
                    519:                        intptr = &options->kerberos_tgt_passing;
                    520:                        goto parse_flag;
                    521:
                    522:                case sAFSTokenPassing:
                    523:                        intptr = &options->afs_token_passing;
                    524:                        goto parse_flag;
                    525: #endif
                    526:
                    527:                case sPasswordAuthentication:
                    528:                        intptr = &options->password_authentication;
1.52      markus    529:                        goto parse_flag;
                    530:
                    531:                case sKbdInteractiveAuthentication:
                    532:                        intptr = &options->kbd_interactive_authentication;
1.25      markus    533:                        goto parse_flag;
                    534:
                    535:                case sCheckMail:
                    536:                        intptr = &options->check_mail;
                    537:                        goto parse_flag;
1.10      markus    538:
1.25      markus    539:                case sSkeyAuthentication:
                    540:                        intptr = &options->skey_authentication;
                    541:                        goto parse_flag;
                    542:
                    543:                case sPrintMotd:
                    544:                        intptr = &options->print_motd;
                    545:                        goto parse_flag;
                    546:
                    547:                case sX11Forwarding:
                    548:                        intptr = &options->x11_forwarding;
                    549:                        goto parse_flag;
                    550:
                    551:                case sX11DisplayOffset:
                    552:                        intptr = &options->x11_display_offset;
                    553:                        goto parse_int;
                    554:
1.42      markus    555:                case sXAuthLocation:
                    556:                        charptr = &options->xauth_location;
                    557:                        goto parse_filename;
                    558:
1.25      markus    559:                case sStrictModes:
                    560:                        intptr = &options->strict_modes;
                    561:                        goto parse_flag;
                    562:
                    563:                case sKeepAlives:
                    564:                        intptr = &options->keepalives;
                    565:                        goto parse_flag;
                    566:
                    567:                case sEmptyPasswd:
                    568:                        intptr = &options->permit_empty_passwd;
                    569:                        goto parse_flag;
                    570:
                    571:                case sUseLogin:
                    572:                        intptr = &options->use_login;
1.38      markus    573:                        goto parse_flag;
                    574:
                    575:                case sGatewayPorts:
                    576:                        intptr = &options->gateway_ports;
1.25      markus    577:                        goto parse_flag;
                    578:
                    579:                case sLogFacility:
                    580:                        intptr = (int *) &options->log_facility;
1.48      provos    581:                        arg = strdelim(&cp);
1.47      ho        582:                        value = log_facility_number(arg);
1.25      markus    583:                        if (value == (SyslogFacility) - 1)
                    584:                                fatal("%.200s line %d: unsupported log facility '%s'\n",
1.47      ho        585:                                    filename, linenum, arg ? arg : "<NONE>");
1.25      markus    586:                        if (*intptr == -1)
                    587:                                *intptr = (SyslogFacility) value;
                    588:                        break;
                    589:
                    590:                case sLogLevel:
                    591:                        intptr = (int *) &options->log_level;
1.48      provos    592:                        arg = strdelim(&cp);
1.47      ho        593:                        value = log_level_number(arg);
1.25      markus    594:                        if (value == (LogLevel) - 1)
                    595:                                fatal("%.200s line %d: unsupported log level '%s'\n",
1.47      ho        596:                                    filename, linenum, arg ? arg : "<NONE>");
1.25      markus    597:                        if (*intptr == -1)
                    598:                                *intptr = (LogLevel) value;
                    599:                        break;
1.53      markus    600:
                    601:                case sAllowTcpForwarding:
                    602:                        intptr = &options->allow_tcp_forwarding;
                    603:                        goto parse_flag;
1.25      markus    604:
                    605:                case sAllowUsers:
1.48      provos    606:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33      markus    607:                                if (options->num_allow_users >= MAX_ALLOW_USERS)
                    608:                                        fatal("%s line %d: too many allow users.\n",
                    609:                                            filename, linenum);
1.47      ho        610:                                options->allow_users[options->num_allow_users++] = xstrdup(arg);
1.25      markus    611:                        }
                    612:                        break;
                    613:
                    614:                case sDenyUsers:
1.48      provos    615:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33      markus    616:                                if (options->num_deny_users >= MAX_DENY_USERS)
                    617:                                        fatal( "%s line %d: too many deny users.\n",
                    618:                                            filename, linenum);
1.47      ho        619:                                options->deny_users[options->num_deny_users++] = xstrdup(arg);
1.25      markus    620:                        }
                    621:                        break;
                    622:
                    623:                case sAllowGroups:
1.48      provos    624:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33      markus    625:                                if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
                    626:                                        fatal("%s line %d: too many allow groups.\n",
                    627:                                            filename, linenum);
1.47      ho        628:                                options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
1.25      markus    629:                        }
                    630:                        break;
                    631:
                    632:                case sDenyGroups:
1.48      provos    633:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33      markus    634:                                if (options->num_deny_groups >= MAX_DENY_GROUPS)
                    635:                                        fatal("%s line %d: too many deny groups.\n",
                    636:                                            filename, linenum);
1.47      ho        637:                                options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
1.25      markus    638:                        }
1.33      markus    639:                        break;
                    640:
                    641:                case sCiphers:
1.48      provos    642:                        arg = strdelim(&cp);
1.47      ho        643:                        if (!arg || *arg == '\0')
1.41      markus    644:                                fatal("%s line %d: Missing argument.", filename, linenum);
1.47      ho        645:                        if (!ciphers_valid(arg))
1.40      markus    646:                                fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1.47      ho        647:                                    filename, linenum, arg ? arg : "<NONE>");
1.33      markus    648:                        if (options->ciphers == NULL)
1.47      ho        649:                                options->ciphers = xstrdup(arg);
1.33      markus    650:                        break;
                    651:
                    652:                case sProtocol:
                    653:                        intptr = &options->protocol;
1.48      provos    654:                        arg = strdelim(&cp);
1.47      ho        655:                        if (!arg || *arg == '\0')
1.41      markus    656:                                fatal("%s line %d: Missing argument.", filename, linenum);
1.47      ho        657:                        value = proto_spec(arg);
1.33      markus    658:                        if (value == SSH_PROTO_UNKNOWN)
                    659:                                fatal("%s line %d: Bad protocol spec '%s'.",
1.47      ho        660:                                      filename, linenum, arg ? arg : "<NONE>");
1.33      markus    661:                        if (*intptr == SSH_PROTO_UNKNOWN)
                    662:                                *intptr = value;
1.43      jakob     663:                        break;
                    664:
                    665:                case sSubsystem:
                    666:                        if(options->num_subsystems >= MAX_SUBSYSTEMS) {
                    667:                                fatal("%s line %d: too many subsystems defined.",
                    668:                                      filename, linenum);
                    669:                        }
1.48      provos    670:                        arg = strdelim(&cp);
1.47      ho        671:                        if (!arg || *arg == '\0')
1.43      jakob     672:                                fatal("%s line %d: Missing subsystem name.",
                    673:                                      filename, linenum);
                    674:                        for (i = 0; i < options->num_subsystems; i++)
1.47      ho        675:                                if(strcmp(arg, options->subsystem_name[i]) == 0)
1.43      jakob     676:                                        fatal("%s line %d: Subsystem '%s' already defined.",
1.47      ho        677:                                              filename, linenum, arg);
                    678:                        options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1.48      provos    679:                        arg = strdelim(&cp);
1.47      ho        680:                        if (!arg || *arg == '\0')
1.43      jakob     681:                                fatal("%s line %d: Missing subsystem command.",
                    682:                                      filename, linenum);
1.47      ho        683:                        options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.43      jakob     684:                        options->num_subsystems++;
1.25      markus    685:                        break;
1.46      markus    686:
                    687:                case sMaxStartups:
1.50      markus    688:                        arg = strdelim(&cp);
                    689:                        if (!arg || *arg == '\0')
                    690:                                fatal("%s line %d: Missing MaxStartups spec.",
                    691:                                      filename, linenum);
                    692:                        if (sscanf(arg, "%d:%d:%d",
                    693:                            &options->max_startups_begin,
                    694:                            &options->max_startups_rate,
                    695:                            &options->max_startups) == 3) {
                    696:                                if (options->max_startups_begin >
                    697:                                    options->max_startups ||
                    698:                                    options->max_startups_rate > 100 ||
                    699:                                    options->max_startups_rate < 1)
                    700:                                fatal("%s line %d: Illegal MaxStartups spec.",
                    701:                                      filename, linenum);
                    702:                                break;
                    703:                        }
1.46      markus    704:                        intptr = &options->max_startups;
                    705:                        goto parse_int;
1.25      markus    706:
1.57      markus    707:                case sBanner:
                    708:                        charptr = &options->banner;
                    709:                        goto parse_filename;
                    710:
1.25      markus    711:                default:
                    712:                        fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
1.47      ho        713:                                filename, linenum, arg, opcode);
1.25      markus    714:                        exit(1);
1.13      markus    715:                }
1.48      provos    716:                if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1.47      ho        717:                        fprintf(stderr,
                    718:                                "%s line %d: garbage at end of line; \"%.200s\".\n",
                    719:                                filename, linenum, arg);
1.25      markus    720:                        exit(1);
1.13      markus    721:                }
1.1       deraadt   722:        }
1.25      markus    723:        fclose(f);
                    724:        if (bad_options > 0) {
                    725:                fprintf(stderr, "%s: terminating, %d bad configuration options\n",
                    726:                        filename, bad_options);
                    727:                exit(1);
1.1       deraadt   728:        }
                    729: }