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

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