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

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