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

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