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

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