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

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