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

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