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

1.226     dtucker     1:
1.297   ! djm         2: /* $OpenBSD: servconf.c,v 1.296 2016/09/28 16:33:07 djm Exp $ */
1.1       deraadt     3: /*
1.26      deraadt     4:  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      5:  *                    All rights reserved
1.34      markus      6:  *
1.51      deraadt     7:  * As far as I am concerned, the code I have written for this software
                      8:  * can be used freely for any purpose.  Any derived versions of this
                      9:  * software must be clearly marked as such, and if the derived work is
                     10:  * incompatible with the protocol description in the RFC file, it must be
                     11:  * called by a name other than "ssh" or "Secure Shell".
1.26      deraadt    12:  */
1.1       deraadt    13:
1.152     stevesk    14: #include <sys/types.h>
                     15: #include <sys/socket.h>
1.179     djm        16: #include <sys/queue.h>
1.154     stevesk    17:
1.213     djm        18: #include <netinet/in.h>
                     19: #include <netinet/ip.h>
                     20:
1.235     dtucker    21: #include <ctype.h>
1.154     stevesk    22: #include <netdb.h>
1.165     dtucker    23: #include <pwd.h>
1.162     stevesk    24: #include <stdio.h>
1.161     stevesk    25: #include <stdlib.h>
1.160     stevesk    26: #include <string.h>
1.164     deraadt    27: #include <signal.h>
1.155     stevesk    28: #include <unistd.h>
1.259     deraadt    29: #include <limits.h>
1.164     deraadt    30: #include <stdarg.h>
1.182     dtucker    31: #include <errno.h>
1.236     dtucker    32: #include <util.h>
1.1       deraadt    33:
1.164     deraadt    34: #include "xmalloc.h"
1.1       deraadt    35: #include "ssh.h"
1.62      markus     36: #include "log.h"
1.164     deraadt    37: #include "buffer.h"
1.251     millert    38: #include "misc.h"
1.1       deraadt    39: #include "servconf.h"
1.33      markus     40: #include "compat.h"
1.60      markus     41: #include "pathnames.h"
1.62      markus     42: #include "cipher.h"
1.164     deraadt    43: #include "key.h"
1.66      markus     44: #include "kex.h"
                     45: #include "mac.h"
1.153     dtucker    46: #include "match.h"
1.156     dtucker    47: #include "channels.h"
1.165     dtucker    48: #include "groupaccess.h"
1.226     dtucker    49: #include "canohost.h"
                     50: #include "packet.h"
1.232     djm        51: #include "hostfile.h"
                     52: #include "auth.h"
1.252     djm        53: #include "myproposal.h"
1.256     djm        54: #include "digest.h"
1.1       deraadt    55:
1.194     djm        56: static void add_listen_addr(ServerOptions *, char *, int);
                     57: static void add_one_listen_addr(ServerOptions *, char *, int);
1.29      markus     58:
1.102     provos     59: /* Use of privilege separation or not */
                     60: extern int use_privsep;
1.153     dtucker    61: extern Buffer cfg;
1.62      markus     62:
1.1       deraadt    63: /* Initializes the server options to their default values. */
                     64:
1.34      markus     65: void
1.25      markus     66: initialize_server_options(ServerOptions *options)
1.1       deraadt    67: {
1.25      markus     68:        memset(options, 0, sizeof(*options));
1.29      markus     69:        options->num_ports = 0;
                     70:        options->ports_from_cmdline = 0;
1.266     dtucker    71:        options->queued_listen_addrs = NULL;
                     72:        options->num_queued_listens = 0;
1.29      markus     73:        options->listen_addrs = NULL;
1.138     djm        74:        options->address_family = -1;
1.54      markus     75:        options->num_host_key_files = 0;
1.203     djm        76:        options->num_host_cert_files = 0;
1.240     markus     77:        options->host_key_agent = NULL;
1.36      markus     78:        options->pid_file = NULL;
1.25      markus     79:        options->login_grace_time = -1;
1.279     chris      80:        options->permit_root_login = PERMIT_NOT_SET;
1.25      markus     81:        options->ignore_rhosts = -1;
                     82:        options->ignore_user_known_hosts = -1;
                     83:        options->print_motd = -1;
1.72      stevesk    84:        options->print_lastlog = -1;
1.25      markus     85:        options->x11_forwarding = -1;
                     86:        options->x11_display_offset = -1;
1.99      stevesk    87:        options->x11_use_localhost = -1;
1.244     djm        88:        options->permit_tty = -1;
1.250     djm        89:        options->permit_user_rc = -1;
1.42      markus     90:        options->xauth_location = NULL;
1.25      markus     91:        options->strict_modes = -1;
1.129     markus     92:        options->tcp_keep_alive = -1;
1.101     markus     93:        options->log_facility = SYSLOG_FACILITY_NOT_SET;
                     94:        options->log_level = SYSLOG_LEVEL_NOT_SET;
1.75      markus     95:        options->hostbased_authentication = -1;
                     96:        options->hostbased_uses_name_from_packet_only = -1;
1.258     djm        97:        options->hostbased_key_types = NULL;
1.276     markus     98:        options->hostkeyalgorithms = NULL;
1.54      markus     99:        options->pubkey_authentication = -1;
1.258     djm       100:        options->pubkey_key_types = NULL;
1.25      markus    101:        options->kerberos_authentication = -1;
                    102:        options->kerberos_or_local_passwd = -1;
                    103:        options->kerberos_ticket_cleanup = -1;
1.130     jakob     104:        options->kerberos_get_afs_token = -1;
1.125     markus    105:        options->gss_authentication=-1;
                    106:        options->gss_cleanup_creds = -1;
1.271     djm       107:        options->gss_strict_acceptor = -1;
1.25      markus    108:        options->password_authentication = -1;
1.52      markus    109:        options->kbd_interactive_authentication = -1;
1.80      markus    110:        options->challenge_response_authentication = -1;
1.25      markus    111:        options->permit_empty_passwd = -1;
1.113     markus    112:        options->permit_user_env = -1;
1.111     markus    113:        options->compression = -1;
1.235     dtucker   114:        options->rekey_limit = -1;
                    115:        options->rekey_interval = -1;
1.53      markus    116:        options->allow_tcp_forwarding = -1;
1.251     millert   117:        options->allow_streamlocal_forwarding = -1;
1.178     pyr       118:        options->allow_agent_forwarding = -1;
1.25      markus    119:        options->num_allow_users = 0;
                    120:        options->num_deny_users = 0;
                    121:        options->num_allow_groups = 0;
                    122:        options->num_deny_groups = 0;
1.33      markus    123:        options->ciphers = NULL;
1.66      markus    124:        options->macs = NULL;
1.211     djm       125:        options->kex_algorithms = NULL;
1.251     millert   126:        options->fwd_opts.gateway_ports = -1;
                    127:        options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
                    128:        options->fwd_opts.streamlocal_bind_unlink = -1;
1.43      jakob     129:        options->num_subsystems = 0;
1.50      markus    130:        options->max_startups_begin = -1;
                    131:        options->max_startups_rate = -1;
1.46      markus    132:        options->max_startups = -1;
1.133     dtucker   133:        options->max_authtries = -1;
1.180     djm       134:        options->max_sessions = -1;
1.57      markus    135:        options->banner = NULL;
1.122     markus    136:        options->use_dns = -1;
1.77      beck      137:        options->client_alive_interval = -1;
                    138:        options->client_alive_count_max = -1;
1.219     djm       139:        options->num_authkeys_files = 0;
1.131     djm       140:        options->num_accept_env = 0;
1.145     reyk      141:        options->permit_tun = -1;
1.159     dtucker   142:        options->num_permitted_opens = -1;
1.158     dtucker   143:        options->adm_forced_command = NULL;
1.176     djm       144:        options->chroot_directory = NULL;
1.231     djm       145:        options->authorized_keys_command = NULL;
                    146:        options->authorized_keys_command_user = NULL;
1.204     djm       147:        options->revoked_keys_file = NULL;
                    148:        options->trusted_user_ca_keys = NULL;
1.208     djm       149:        options->authorized_principals_file = NULL;
1.270     djm       150:        options->authorized_principals_command = NULL;
                    151:        options->authorized_principals_command_user = NULL;
1.213     djm       152:        options->ip_qos_interactive = -1;
                    153:        options->ip_qos_bulk = -1;
1.225     djm       154:        options->version_addendum = NULL;
1.256     djm       155:        options->fingerprint_hash = -1;
1.1       deraadt   156: }
                    157:
1.257     djm       158: /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
                    159: static int
                    160: option_clear_or_none(const char *o)
                    161: {
                    162:        return o == NULL || strcasecmp(o, "none") == 0;
                    163: }
                    164:
1.282     djm       165: static void
                    166: assemble_algorithms(ServerOptions *o)
                    167: {
                    168:        if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
                    169:            kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
                    170:            kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
                    171:            kex_assemble_names(KEX_DEFAULT_PK_ALG,
                    172:            &o->hostkeyalgorithms) != 0 ||
                    173:            kex_assemble_names(KEX_DEFAULT_PK_ALG,
                    174:            &o->hostbased_key_types) != 0 ||
                    175:            kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
                    176:                fatal("kex_assemble_names failed");
                    177: }
                    178:
1.34      markus    179: void
1.25      markus    180: fill_default_server_options(ServerOptions *options)
1.1       deraadt   181: {
1.257     djm       182:        int i;
                    183:
1.54      markus    184:        if (options->num_host_key_files == 0) {
1.293     naddy     185:                /* fill default hostkeys */
                    186:                options->host_key_files[options->num_host_key_files++] =
                    187:                    _PATH_HOST_RSA_KEY_FILE;
                    188:                options->host_key_files[options->num_host_key_files++] =
                    189:                    _PATH_HOST_DSA_KEY_FILE;
                    190:                options->host_key_files[options->num_host_key_files++] =
                    191:                    _PATH_HOST_ECDSA_KEY_FILE;
                    192:                options->host_key_files[options->num_host_key_files++] =
                    193:                    _PATH_HOST_ED25519_KEY_FILE;
1.54      markus    194:        }
1.203     djm       195:        /* No certificates by default */
1.29      markus    196:        if (options->num_ports == 0)
                    197:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
1.266     dtucker   198:        if (options->address_family == -1)
                    199:                options->address_family = AF_UNSPEC;
1.29      markus    200:        if (options->listen_addrs == NULL)
1.76      stevesk   201:                add_listen_addr(options, NULL, 0);
1.36      markus    202:        if (options->pid_file == NULL)
1.257     djm       203:                options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
1.25      markus    204:        if (options->login_grace_time == -1)
1.115     stevesk   205:                options->login_grace_time = 120;
1.67      markus    206:        if (options->permit_root_login == PERMIT_NOT_SET)
1.279     chris     207:                options->permit_root_login = PERMIT_NO_PASSWD;
1.25      markus    208:        if (options->ignore_rhosts == -1)
1.30      markus    209:                options->ignore_rhosts = 1;
1.25      markus    210:        if (options->ignore_user_known_hosts == -1)
                    211:                options->ignore_user_known_hosts = 0;
                    212:        if (options->print_motd == -1)
                    213:                options->print_motd = 1;
1.72      stevesk   214:        if (options->print_lastlog == -1)
                    215:                options->print_lastlog = 1;
1.25      markus    216:        if (options->x11_forwarding == -1)
1.30      markus    217:                options->x11_forwarding = 0;
1.25      markus    218:        if (options->x11_display_offset == -1)
1.30      markus    219:                options->x11_display_offset = 10;
1.99      stevesk   220:        if (options->x11_use_localhost == -1)
                    221:                options->x11_use_localhost = 1;
1.42      markus    222:        if (options->xauth_location == NULL)
1.257     djm       223:                options->xauth_location = xstrdup(_PATH_XAUTH);
1.244     djm       224:        if (options->permit_tty == -1)
                    225:                options->permit_tty = 1;
1.250     djm       226:        if (options->permit_user_rc == -1)
                    227:                options->permit_user_rc = 1;
1.25      markus    228:        if (options->strict_modes == -1)
                    229:                options->strict_modes = 1;
1.129     markus    230:        if (options->tcp_keep_alive == -1)
                    231:                options->tcp_keep_alive = 1;
1.101     markus    232:        if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
1.25      markus    233:                options->log_facility = SYSLOG_FACILITY_AUTH;
1.101     markus    234:        if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.58      markus    235:                options->log_level = SYSLOG_LEVEL_INFO;
1.75      markus    236:        if (options->hostbased_authentication == -1)
                    237:                options->hostbased_authentication = 0;
                    238:        if (options->hostbased_uses_name_from_packet_only == -1)
                    239:                options->hostbased_uses_name_from_packet_only = 0;
1.54      markus    240:        if (options->pubkey_authentication == -1)
                    241:                options->pubkey_authentication = 1;
1.25      markus    242:        if (options->kerberos_authentication == -1)
1.107     markus    243:                options->kerberos_authentication = 0;
1.25      markus    244:        if (options->kerberos_or_local_passwd == -1)
                    245:                options->kerberos_or_local_passwd = 1;
                    246:        if (options->kerberos_ticket_cleanup == -1)
                    247:                options->kerberos_ticket_cleanup = 1;
1.130     jakob     248:        if (options->kerberos_get_afs_token == -1)
                    249:                options->kerberos_get_afs_token = 0;
1.125     markus    250:        if (options->gss_authentication == -1)
                    251:                options->gss_authentication = 0;
                    252:        if (options->gss_cleanup_creds == -1)
                    253:                options->gss_cleanup_creds = 1;
1.271     djm       254:        if (options->gss_strict_acceptor == -1)
                    255:                options->gss_strict_acceptor = 0;
1.25      markus    256:        if (options->password_authentication == -1)
                    257:                options->password_authentication = 1;
1.52      markus    258:        if (options->kbd_interactive_authentication == -1)
                    259:                options->kbd_interactive_authentication = 0;
1.80      markus    260:        if (options->challenge_response_authentication == -1)
                    261:                options->challenge_response_authentication = 1;
1.25      markus    262:        if (options->permit_empty_passwd == -1)
1.30      markus    263:                options->permit_empty_passwd = 0;
1.113     markus    264:        if (options->permit_user_env == -1)
                    265:                options->permit_user_env = 0;
1.111     markus    266:        if (options->compression == -1)
1.143     markus    267:                options->compression = COMP_DELAYED;
1.235     dtucker   268:        if (options->rekey_limit == -1)
                    269:                options->rekey_limit = 0;
                    270:        if (options->rekey_interval == -1)
                    271:                options->rekey_interval = 0;
1.53      markus    272:        if (options->allow_tcp_forwarding == -1)
1.233     djm       273:                options->allow_tcp_forwarding = FORWARD_ALLOW;
1.251     millert   274:        if (options->allow_streamlocal_forwarding == -1)
                    275:                options->allow_streamlocal_forwarding = FORWARD_ALLOW;
1.178     pyr       276:        if (options->allow_agent_forwarding == -1)
                    277:                options->allow_agent_forwarding = 1;
1.251     millert   278:        if (options->fwd_opts.gateway_ports == -1)
                    279:                options->fwd_opts.gateway_ports = 0;
1.46      markus    280:        if (options->max_startups == -1)
1.234     dtucker   281:                options->max_startups = 100;
1.50      markus    282:        if (options->max_startups_rate == -1)
1.234     dtucker   283:                options->max_startups_rate = 30;                /* 30% */
1.50      markus    284:        if (options->max_startups_begin == -1)
1.234     dtucker   285:                options->max_startups_begin = 10;
1.133     dtucker   286:        if (options->max_authtries == -1)
                    287:                options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
1.180     djm       288:        if (options->max_sessions == -1)
                    289:                options->max_sessions = DEFAULT_SESSIONS_MAX;
1.122     markus    290:        if (options->use_dns == -1)
1.260     deraadt   291:                options->use_dns = 0;
1.77      beck      292:        if (options->client_alive_interval == -1)
1.95      deraadt   293:                options->client_alive_interval = 0;
1.77      beck      294:        if (options->client_alive_count_max == -1)
                    295:                options->client_alive_count_max = 3;
1.219     djm       296:        if (options->num_authkeys_files == 0) {
                    297:                options->authorized_keys_files[options->num_authkeys_files++] =
                    298:                    xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
                    299:                options->authorized_keys_files[options->num_authkeys_files++] =
                    300:                    xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
                    301:        }
1.145     reyk      302:        if (options->permit_tun == -1)
1.146     reyk      303:                options->permit_tun = SSH_TUNMODE_NO;
1.213     djm       304:        if (options->ip_qos_interactive == -1)
                    305:                options->ip_qos_interactive = IPTOS_LOWDELAY;
                    306:        if (options->ip_qos_bulk == -1)
                    307:                options->ip_qos_bulk = IPTOS_THROUGHPUT;
1.225     djm       308:        if (options->version_addendum == NULL)
                    309:                options->version_addendum = xstrdup("");
1.251     millert   310:        if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
                    311:                options->fwd_opts.streamlocal_bind_mask = 0177;
                    312:        if (options->fwd_opts.streamlocal_bind_unlink == -1)
                    313:                options->fwd_opts.streamlocal_bind_unlink = 0;
1.256     djm       314:        if (options->fingerprint_hash == -1)
                    315:                options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
1.277     djm       316:
1.282     djm       317:        assemble_algorithms(options);
1.277     djm       318:
1.285     djm       319:        /* Turn privilege separation and sandboxing on by default */
1.102     provos    320:        if (use_privsep == -1)
1.285     djm       321:                use_privsep = PRIVSEP_ON;
1.257     djm       322:
                    323: #define CLEAR_ON_NONE(v) \
                    324:        do { \
                    325:                if (option_clear_or_none(v)) { \
                    326:                        free(v); \
                    327:                        v = NULL; \
                    328:                } \
                    329:        } while(0)
                    330:        CLEAR_ON_NONE(options->pid_file);
                    331:        CLEAR_ON_NONE(options->xauth_location);
                    332:        CLEAR_ON_NONE(options->banner);
                    333:        CLEAR_ON_NONE(options->trusted_user_ca_keys);
                    334:        CLEAR_ON_NONE(options->revoked_keys_file);
1.267     djm       335:        CLEAR_ON_NONE(options->authorized_principals_file);
1.283     djm       336:        CLEAR_ON_NONE(options->adm_forced_command);
                    337:        CLEAR_ON_NONE(options->chroot_directory);
1.257     djm       338:        for (i = 0; i < options->num_host_key_files; i++)
                    339:                CLEAR_ON_NONE(options->host_key_files[i]);
                    340:        for (i = 0; i < options->num_host_cert_files; i++)
                    341:                CLEAR_ON_NONE(options->host_cert_files[i]);
                    342: #undef CLEAR_ON_NONE
1.291     djm       343:
                    344:        /* Similar handling for AuthenticationMethods=any */
                    345:        if (options->num_auth_methods == 1 &&
                    346:            strcmp(options->auth_methods[0], "any") == 0) {
                    347:                free(options->auth_methods[0]);
                    348:                options->auth_methods[0] = NULL;
                    349:                options->num_auth_methods = 0;
                    350:        }
                    351:
1.1       deraadt   352: }
                    353:
                    354: /* Keyword tokens. */
1.25      markus    355: typedef enum {
                    356:        sBadOption,             /* == unknown option */
1.293     naddy     357:        sPort, sHostKeyFile, sLoginGraceTime,
                    358:        sPermitRootLogin, sLogFacility, sLogLevel,
1.25      markus    359:        sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.130     jakob     360:        sKerberosGetAFSToken,
1.123     markus    361:        sKerberosTgtPassing, sChallengeResponseAuthentication,
1.138     djm       362:        sPasswordAuthentication, sKbdInteractiveAuthentication,
                    363:        sListenAddress, sAddressFamily,
1.72      stevesk   364:        sPrintMotd, sPrintLastLog, sIgnoreRhosts,
1.99      stevesk   365:        sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
1.244     djm       366:        sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
1.294     djm       367:        sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
1.235     dtucker   368:        sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.293     naddy     369:        sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
1.258     djm       370:        sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
                    371:        sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
1.122     markus    372:        sBanner, sUseDNS, sHostbasedAuthentication,
1.258     djm       373:        sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
1.276     markus    374:        sHostKeyAlgorithms,
1.258     djm       375:        sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
1.271     djm       376:        sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
                    377:        sAcceptEnv, sPermitTunnel,
1.176     djm       378:        sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
1.200     dtucker   379:        sUsePrivilegeSeparation, sAllowAgentForwarding,
1.249     djm       380:        sHostCertificate,
1.208     djm       381:        sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
1.270     djm       382:        sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
1.225     djm       383:        sKexAlgorithms, sIPQoS, sVersionAddendum,
1.231     djm       384:        sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
1.250     djm       385:        sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
1.251     millert   386:        sStreamLocalBindMask, sStreamLocalBindUnlink,
1.256     djm       387:        sAllowStreamLocalForwarding, sFingerprintHash,
1.295     djm       388:        sDeprecated, sIgnore, sUnsupported
1.1       deraadt   389: } ServerOpCodes;
                    390:
1.153     dtucker   391: #define SSHCFG_GLOBAL  0x01    /* allowed in main section of sshd_config */
                    392: #define SSHCFG_MATCH   0x02    /* allowed inside a Match section */
                    393: #define SSHCFG_ALL     (SSHCFG_GLOBAL|SSHCFG_MATCH)
                    394:
1.1       deraadt   395: /* Textual representation of the tokens. */
1.25      markus    396: static struct {
                    397:        const char *name;
                    398:        ServerOpCodes opcode;
1.153     dtucker   399:        u_int flags;
1.25      markus    400: } keywords[] = {
1.153     dtucker   401:        { "port", sPort, SSHCFG_GLOBAL },
                    402:        { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
                    403:        { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL },          /* alias */
1.240     markus    404:        { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
1.153     dtucker   405:        { "pidfile", sPidFile, SSHCFG_GLOBAL },
1.293     naddy     406:        { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
1.153     dtucker   407:        { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
1.293     naddy     408:        { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
1.175     dtucker   409:        { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
1.153     dtucker   410:        { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
                    411:        { "loglevel", sLogLevel, SSHCFG_GLOBAL },
                    412:        { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
1.293     naddy     413:        { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
1.168     dtucker   414:        { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
1.209     djm       415:        { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
1.258     djm       416:        { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
1.276     markus    417:        { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
1.293     naddy     418:        { "rsaauthentication", sDeprecated, SSHCFG_ALL },
1.168     dtucker   419:        { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
1.258     djm       420:        { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
1.153     dtucker   421:        { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
1.123     markus    422: #ifdef KRB5
1.168     dtucker   423:        { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
1.153     dtucker   424:        { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
                    425:        { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
                    426:        { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
1.121     jakob     427: #else
1.168     dtucker   428:        { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
1.153     dtucker   429:        { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
                    430:        { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
                    431:        { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
1.126     markus    432: #endif
1.153     dtucker   433:        { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
                    434:        { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
1.125     markus    435: #ifdef GSSAPI
1.168     dtucker   436:        { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
1.153     dtucker   437:        { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
1.271     djm       438:        { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
1.125     markus    439: #else
1.168     dtucker   440:        { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
1.153     dtucker   441:        { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
1.271     djm       442:        { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
1.125     markus    443: #endif
1.168     dtucker   444:        { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
                    445:        { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
1.170     dtucker   446:        { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
1.153     dtucker   447:        { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
                    448:        { "checkmail", sDeprecated, SSHCFG_GLOBAL },
                    449:        { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
                    450:        { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
                    451:        { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
                    452:        { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
                    453:        { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
                    454:        { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
1.157     dtucker   455:        { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
                    456:        { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
                    457:        { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
1.153     dtucker   458:        { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
                    459:        { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
1.188     djm       460:        { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
1.153     dtucker   461:        { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
1.294     djm       462:        { "uselogin", sDeprecated, SSHCFG_GLOBAL },
1.153     dtucker   463:        { "compression", sCompression, SSHCFG_GLOBAL },
1.235     dtucker   464:        { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
1.153     dtucker   465:        { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
                    466:        { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL },  /* obsolete alias */
                    467:        { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
1.178     pyr       468:        { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
1.227     markus    469:        { "allowusers", sAllowUsers, SSHCFG_ALL },
                    470:        { "denyusers", sDenyUsers, SSHCFG_ALL },
                    471:        { "allowgroups", sAllowGroups, SSHCFG_ALL },
                    472:        { "denygroups", sDenyGroups, SSHCFG_ALL },
1.153     dtucker   473:        { "ciphers", sCiphers, SSHCFG_GLOBAL },
                    474:        { "macs", sMacs, SSHCFG_GLOBAL },
1.295     djm       475:        { "protocol", sIgnore, SSHCFG_GLOBAL },
1.153     dtucker   476:        { "gatewayports", sGatewayPorts, SSHCFG_ALL },
                    477:        { "subsystem", sSubsystem, SSHCFG_GLOBAL },
                    478:        { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
1.184     dtucker   479:        { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
1.180     djm       480:        { "maxsessions", sMaxSessions, SSHCFG_ALL },
1.168     dtucker   481:        { "banner", sBanner, SSHCFG_ALL },
1.153     dtucker   482:        { "usedns", sUseDNS, SSHCFG_GLOBAL },
                    483:        { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
                    484:        { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
                    485:        { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
                    486:        { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
1.209     djm       487:        { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
1.219     djm       488:        { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
1.153     dtucker   489:        { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
1.227     markus    490:        { "acceptenv", sAcceptEnv, SSHCFG_ALL },
1.209     djm       491:        { "permittunnel", sPermitTunnel, SSHCFG_ALL },
1.244     djm       492:        { "permittty", sPermitTTY, SSHCFG_ALL },
1.250     djm       493:        { "permituserrc", sPermitUserRC, SSHCFG_ALL },
1.153     dtucker   494:        { "match", sMatch, SSHCFG_ALL },
1.156     dtucker   495:        { "permitopen", sPermitOpen, SSHCFG_ALL },
1.158     dtucker   496:        { "forcecommand", sForceCommand, SSHCFG_ALL },
1.176     djm       497:        { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
1.203     djm       498:        { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
1.204     djm       499:        { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
                    500:        { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
1.209     djm       501:        { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
1.211     djm       502:        { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
1.213     djm       503:        { "ipqos", sIPQoS, SSHCFG_ALL },
1.231     djm       504:        { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
                    505:        { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
1.270     djm       506:        { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
                    507:        { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
1.225     djm       508:        { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
1.232     djm       509:        { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
1.251     millert   510:        { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
                    511:        { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
                    512:        { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
1.256     djm       513:        { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
1.153     dtucker   514:        { NULL, sBadOption, 0 }
1.1       deraadt   515: };
                    516:
1.182     dtucker   517: static struct {
                    518:        int val;
                    519:        char *text;
                    520: } tunmode_desc[] = {
                    521:        { SSH_TUNMODE_NO, "no" },
                    522:        { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
                    523:        { SSH_TUNMODE_ETHERNET, "ethernet" },
                    524:        { SSH_TUNMODE_YES, "yes" },
                    525:        { -1, NULL }
                    526: };
                    527:
1.27      markus    528: /*
1.73      stevesk   529:  * Returns the number of the token pointed to by cp or sBadOption.
1.27      markus    530:  */
1.1       deraadt   531:
1.34      markus    532: static ServerOpCodes
1.25      markus    533: parse_token(const char *cp, const char *filename,
1.153     dtucker   534:            int linenum, u_int *flags)
1.1       deraadt   535: {
1.55      markus    536:        u_int i;
1.1       deraadt   537:
1.25      markus    538:        for (i = 0; keywords[i].name; i++)
1.153     dtucker   539:                if (strcasecmp(cp, keywords[i].name) == 0) {
                    540:                        *flags = keywords[i].flags;
1.25      markus    541:                        return keywords[i].opcode;
1.153     dtucker   542:                }
1.25      markus    543:
1.78      stevesk   544:        error("%s: line %d: Bad configuration option: %s",
                    545:            filename, linenum, cp);
1.25      markus    546:        return sBadOption;
1.1       deraadt   547: }
                    548:
1.202     djm       549: char *
                    550: derelativise_path(const char *path)
                    551: {
1.259     deraadt   552:        char *expanded, *ret, cwd[PATH_MAX];
1.202     djm       553:
1.257     djm       554:        if (strcasecmp(path, "none") == 0)
                    555:                return xstrdup("none");
1.202     djm       556:        expanded = tilde_expand_filename(path, getuid());
                    557:        if (*expanded == '/')
                    558:                return expanded;
1.207     djm       559:        if (getcwd(cwd, sizeof(cwd)) == NULL)
1.202     djm       560:                fatal("%s: getcwd: %s", __func__, strerror(errno));
                    561:        xasprintf(&ret, "%s/%s", cwd, expanded);
1.239     djm       562:        free(expanded);
1.202     djm       563:        return ret;
                    564: }
                    565:
1.84      itojun    566: static void
1.194     djm       567: add_listen_addr(ServerOptions *options, char *addr, int port)
1.74      stevesk   568: {
1.142     djm       569:        u_int i;
1.74      stevesk   570:
1.76      stevesk   571:        if (port == 0)
1.74      stevesk   572:                for (i = 0; i < options->num_ports; i++)
                    573:                        add_one_listen_addr(options, addr, options->ports[i]);
                    574:        else
1.76      stevesk   575:                add_one_listen_addr(options, addr, port);
1.74      stevesk   576: }
                    577:
1.84      itojun    578: static void
1.194     djm       579: add_one_listen_addr(ServerOptions *options, char *addr, int port)
1.29      markus    580: {
                    581:        struct addrinfo hints, *ai, *aitop;
                    582:        char strport[NI_MAXSERV];
                    583:        int gaierr;
                    584:
1.74      stevesk   585:        memset(&hints, 0, sizeof(hints));
1.138     djm       586:        hints.ai_family = options->address_family;
1.74      stevesk   587:        hints.ai_socktype = SOCK_STREAM;
                    588:        hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
1.194     djm       589:        snprintf(strport, sizeof strport, "%d", port);
1.74      stevesk   590:        if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
                    591:                fatal("bad addr or host: %s (%s)",
                    592:                    addr ? addr : "<NULL>",
1.173     dtucker   593:                    ssh_gai_strerror(gaierr));
1.74      stevesk   594:        for (ai = aitop; ai->ai_next; ai = ai->ai_next)
                    595:                ;
                    596:        ai->ai_next = options->listen_addrs;
                    597:        options->listen_addrs = aitop;
1.29      markus    598: }
                    599:
1.266     dtucker   600: /*
                    601:  * Queue a ListenAddress to be processed once we have all of the Ports
                    602:  * and AddressFamily options.
                    603:  */
                    604: static void
                    605: queue_listen_addr(ServerOptions *options, char *addr, int port)
                    606: {
                    607:        options->queued_listen_addrs = xreallocarray(
                    608:            options->queued_listen_addrs, options->num_queued_listens + 1,
                    609:            sizeof(addr));
                    610:        options->queued_listen_ports = xreallocarray(
                    611:            options->queued_listen_ports, options->num_queued_listens + 1,
                    612:            sizeof(port));
                    613:        options->queued_listen_addrs[options->num_queued_listens] =
                    614:            xstrdup(addr);
                    615:        options->queued_listen_ports[options->num_queued_listens] = port;
                    616:        options->num_queued_listens++;
                    617: }
                    618:
                    619: /*
                    620:  * Process queued (text) ListenAddress entries.
                    621:  */
                    622: static void
                    623: process_queued_listen_addrs(ServerOptions *options)
                    624: {
                    625:        u_int i;
                    626:
                    627:        if (options->num_ports == 0)
                    628:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
                    629:        if (options->address_family == -1)
                    630:                options->address_family = AF_UNSPEC;
                    631:
                    632:        for (i = 0; i < options->num_queued_listens; i++) {
                    633:                add_listen_addr(options, options->queued_listen_addrs[i],
                    634:                    options->queued_listen_ports[i]);
                    635:                free(options->queued_listen_addrs[i]);
                    636:                options->queued_listen_addrs[i] = NULL;
                    637:        }
                    638:        free(options->queued_listen_addrs);
                    639:        options->queued_listen_addrs = NULL;
                    640:        free(options->queued_listen_ports);
                    641:        options->queued_listen_ports = NULL;
                    642:        options->num_queued_listens = 0;
                    643: }
                    644:
1.226     dtucker   645: struct connection_info *
                    646: get_connection_info(int populate, int use_dns)
                    647: {
1.286     djm       648:        struct ssh *ssh = active_state; /* XXX */
1.226     dtucker   649:        static struct connection_info ci;
                    650:
                    651:        if (!populate)
                    652:                return &ci;
1.286     djm       653:        ci.host = auth_get_canonical_hostname(ssh, use_dns);
                    654:        ci.address = ssh_remote_ipaddr(ssh);
                    655:        ci.laddress = ssh_local_ipaddr(ssh);
                    656:        ci.lport = ssh_local_port(ssh);
1.226     dtucker   657:        return &ci;
                    658: }
                    659:
1.153     dtucker   660: /*
                    661:  * The strategy for the Match blocks is that the config file is parsed twice.
                    662:  *
                    663:  * The first time is at startup.  activep is initialized to 1 and the
                    664:  * directives in the global context are processed and acted on.  Hitting a
                    665:  * Match directive unsets activep and the directives inside the block are
                    666:  * checked for syntax only.
                    667:  *
                    668:  * The second time is after a connection has been established but before
                    669:  * authentication.  activep is initialized to 2 and global config directives
                    670:  * are ignored since they have already been processed.  If the criteria in a
                    671:  * Match block is met, activep is set and the subsequent directives
                    672:  * processed and actioned until EOF or another Match block unsets it.  Any
                    673:  * options set are copied into the main server config.
                    674:  *
                    675:  * Potential additions/improvements:
1.295     djm       676:  *  - Add Match support for pre-kex directives, eg. Ciphers.
1.153     dtucker   677:  *
                    678:  *  - Add a Tag directive (idea from David Leonard) ala pf, eg:
                    679:  *     Match Address 192.168.0.*
                    680:  *             Tag trusted
                    681:  *     Match Group wheel
                    682:  *             Tag trusted
                    683:  *     Match Tag trusted
                    684:  *             AllowTcpForwarding yes
                    685:  *             GatewayPorts clientspecified
                    686:  *             [...]
                    687:  *
                    688:  *  - Add a PermittedChannelRequests directive
                    689:  *     Match Group shell
                    690:  *             PermittedChannelRequests session,forwarded-tcpip
                    691:  */
                    692:
                    693: static int
1.165     dtucker   694: match_cfg_line_group(const char *grps, int line, const char *user)
                    695: {
                    696:        int result = 0;
                    697:        struct passwd *pw;
                    698:
                    699:        if (user == NULL)
                    700:                goto out;
                    701:
                    702:        if ((pw = getpwnam(user)) == NULL) {
                    703:                debug("Can't match group at line %d because user %.100s does "
                    704:                    "not exist", line, user);
                    705:        } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
                    706:                debug("Can't Match group because user %.100s not in any group "
                    707:                    "at line %d", user, line);
1.186     djm       708:        } else if (ga_match_pattern_list(grps) != 1) {
                    709:                debug("user %.100s does not match group list %.100s at line %d",
                    710:                    user, grps, line);
1.165     dtucker   711:        } else {
1.186     djm       712:                debug("user %.100s matched group list %.100s at line %d", user,
                    713:                    grps, line);
1.165     dtucker   714:                result = 1;
                    715:        }
                    716: out:
                    717:        ga_free();
                    718:        return result;
                    719: }
                    720:
1.226     dtucker   721: /*
1.230     dtucker   722:  * All of the attributes on a single Match line are ANDed together, so we need
1.242     dtucker   723:  * to check every attribute and set the result to zero if any attribute does
1.230     dtucker   724:  * not match.
1.226     dtucker   725:  */
1.165     dtucker   726: static int
1.226     dtucker   727: match_cfg_line(char **condition, int line, struct connection_info *ci)
1.153     dtucker   728: {
1.243     dtucker   729:        int result = 1, attributes = 0, port;
1.153     dtucker   730:        char *arg, *attrib, *cp = *condition;
                    731:
1.226     dtucker   732:        if (ci == NULL)
1.153     dtucker   733:                debug3("checking syntax for 'Match %s'", cp);
                    734:        else
1.226     dtucker   735:                debug3("checking match for '%s' user %s host %s addr %s "
                    736:                    "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
                    737:                    ci->host ? ci->host : "(null)",
                    738:                    ci->address ? ci->address : "(null)",
                    739:                    ci->laddress ? ci->laddress : "(null)", ci->lport);
1.153     dtucker   740:
                    741:        while ((attrib = strdelim(&cp)) && *attrib != '\0') {
1.243     dtucker   742:                attributes++;
                    743:                if (strcasecmp(attrib, "all") == 0) {
                    744:                        if (attributes != 1 ||
                    745:                            ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
                    746:                                error("'all' cannot be combined with other "
                    747:                                    "Match attributes");
                    748:                                return -1;
                    749:                        }
                    750:                        *condition = cp;
                    751:                        return 1;
                    752:                }
1.153     dtucker   753:                if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
                    754:                        error("Missing Match criteria for %s", attrib);
                    755:                        return -1;
                    756:                }
                    757:                if (strcasecmp(attrib, "user") == 0) {
1.226     dtucker   758:                        if (ci == NULL || ci->user == NULL) {
1.153     dtucker   759:                                result = 0;
                    760:                                continue;
                    761:                        }
1.269     djm       762:                        if (match_pattern_list(ci->user, arg, 0) != 1)
1.153     dtucker   763:                                result = 0;
                    764:                        else
                    765:                                debug("user %.100s matched 'User %.100s' at "
1.226     dtucker   766:                                    "line %d", ci->user, arg, line);
1.165     dtucker   767:                } else if (strcasecmp(attrib, "group") == 0) {
1.226     dtucker   768:                        if (ci == NULL || ci->user == NULL) {
                    769:                                result = 0;
                    770:                                continue;
                    771:                        }
                    772:                        switch (match_cfg_line_group(arg, line, ci->user)) {
1.165     dtucker   773:                        case -1:
                    774:                                return -1;
                    775:                        case 0:
                    776:                                result = 0;
                    777:                        }
1.153     dtucker   778:                } else if (strcasecmp(attrib, "host") == 0) {
1.226     dtucker   779:                        if (ci == NULL || ci->host == NULL) {
1.153     dtucker   780:                                result = 0;
                    781:                                continue;
                    782:                        }
1.269     djm       783:                        if (match_hostname(ci->host, arg) != 1)
1.153     dtucker   784:                                result = 0;
                    785:                        else
                    786:                                debug("connection from %.100s matched 'Host "
1.226     dtucker   787:                                    "%.100s' at line %d", ci->host, arg, line);
1.153     dtucker   788:                } else if (strcasecmp(attrib, "address") == 0) {
1.226     dtucker   789:                        if (ci == NULL || ci->address == NULL) {
                    790:                                result = 0;
                    791:                                continue;
                    792:                        }
                    793:                        switch (addr_match_list(ci->address, arg)) {
1.181     djm       794:                        case 1:
                    795:                                debug("connection from %.100s matched 'Address "
1.226     dtucker   796:                                    "%.100s' at line %d", ci->address, arg, line);
1.181     djm       797:                                break;
                    798:                        case 0:
1.183     djm       799:                        case -1:
1.153     dtucker   800:                                result = 0;
1.181     djm       801:                                break;
1.183     djm       802:                        case -2:
1.181     djm       803:                                return -1;
1.153     dtucker   804:                        }
1.226     dtucker   805:                } else if (strcasecmp(attrib, "localaddress") == 0){
                    806:                        if (ci == NULL || ci->laddress == NULL) {
                    807:                                result = 0;
                    808:                                continue;
                    809:                        }
                    810:                        switch (addr_match_list(ci->laddress, arg)) {
                    811:                        case 1:
                    812:                                debug("connection from %.100s matched "
                    813:                                    "'LocalAddress %.100s' at line %d",
                    814:                                    ci->laddress, arg, line);
                    815:                                break;
                    816:                        case 0:
                    817:                        case -1:
                    818:                                result = 0;
                    819:                                break;
                    820:                        case -2:
                    821:                                return -1;
                    822:                        }
                    823:                } else if (strcasecmp(attrib, "localport") == 0) {
                    824:                        if ((port = a2port(arg)) == -1) {
                    825:                                error("Invalid LocalPort '%s' on Match line",
                    826:                                    arg);
                    827:                                return -1;
                    828:                        }
                    829:                        if (ci == NULL || ci->lport == 0) {
                    830:                                result = 0;
                    831:                                continue;
                    832:                        }
                    833:                        /* TODO support port lists */
                    834:                        if (port == ci->lport)
                    835:                                debug("connection from %.100s matched "
                    836:                                    "'LocalPort %d' at line %d",
                    837:                                    ci->laddress, port, line);
                    838:                        else
                    839:                                result = 0;
1.153     dtucker   840:                } else {
                    841:                        error("Unsupported Match attribute %s", attrib);
                    842:                        return -1;
                    843:                }
1.243     dtucker   844:        }
                    845:        if (attributes == 0) {
                    846:                error("One or more attributes required for Match");
                    847:                return -1;
1.153     dtucker   848:        }
1.226     dtucker   849:        if (ci != NULL)
1.153     dtucker   850:                debug3("match %sfound", result ? "" : "not ");
                    851:        *condition = cp;
                    852:        return result;
                    853: }
                    854:
1.158     dtucker   855: #define WHITESPACE " \t\r\n"
                    856:
1.220     djm       857: /* Multistate option parsing */
                    858: struct multistate {
                    859:        char *key;
                    860:        int value;
                    861: };
                    862: static const struct multistate multistate_addressfamily[] = {
                    863:        { "inet",                       AF_INET },
                    864:        { "inet6",                      AF_INET6 },
                    865:        { "any",                        AF_UNSPEC },
                    866:        { NULL, -1 }
                    867: };
                    868: static const struct multistate multistate_permitrootlogin[] = {
                    869:        { "without-password",           PERMIT_NO_PASSWD },
1.280     deraadt   870:        { "prohibit-password",          PERMIT_NO_PASSWD },
1.220     djm       871:        { "forced-commands-only",       PERMIT_FORCED_ONLY },
                    872:        { "yes",                        PERMIT_YES },
                    873:        { "no",                         PERMIT_NO },
                    874:        { NULL, -1 }
                    875: };
                    876: static const struct multistate multistate_compression[] = {
1.297   ! djm       877:        { "yes",                        COMP_DELAYED },
1.220     djm       878:        { "delayed",                    COMP_DELAYED },
                    879:        { "no",                         COMP_NONE },
                    880:        { NULL, -1 }
                    881: };
                    882: static const struct multistate multistate_gatewayports[] = {
                    883:        { "clientspecified",            2 },
                    884:        { "yes",                        1 },
                    885:        { "no",                         0 },
                    886:        { NULL, -1 }
                    887: };
1.222     djm       888: static const struct multistate multistate_privsep[] = {
1.228     djm       889:        { "yes",                        PRIVSEP_NOSANDBOX },
                    890:        { "sandbox",                    PRIVSEP_ON },
                    891:        { "nosandbox",                  PRIVSEP_NOSANDBOX },
1.222     djm       892:        { "no",                         PRIVSEP_OFF },
                    893:        { NULL, -1 }
                    894: };
1.233     djm       895: static const struct multistate multistate_tcpfwd[] = {
                    896:        { "yes",                        FORWARD_ALLOW },
                    897:        { "all",                        FORWARD_ALLOW },
                    898:        { "no",                         FORWARD_DENY },
                    899:        { "remote",                     FORWARD_REMOTE },
                    900:        { "local",                      FORWARD_LOCAL },
                    901:        { NULL, -1 }
                    902: };
1.220     djm       903:
1.94      markus    904: int
                    905: process_server_config_line(ServerOptions *options, char *line,
1.226     dtucker   906:     const char *filename, int linenum, int *activep,
                    907:     struct connection_info *connectinfo)
1.1       deraadt   908: {
1.238     dtucker   909:        char *cp, **charptr, *arg, *p;
1.237     dtucker   910:        int cmdline = 0, *intptr, value, value2, n, port;
1.174     dtucker   911:        SyslogFacility *log_facility_ptr;
                    912:        LogLevel *log_level_ptr;
1.25      markus    913:        ServerOpCodes opcode;
1.153     dtucker   914:        u_int i, flags = 0;
1.151     djm       915:        size_t len;
1.237     dtucker   916:        long long val64;
1.220     djm       917:        const struct multistate *multistate_ptr;
1.25      markus    918:
1.94      markus    919:        cp = line;
1.148     dtucker   920:        if ((arg = strdelim(&cp)) == NULL)
1.147     djm       921:                return 0;
1.94      markus    922:        /* Ignore leading whitespace */
                    923:        if (*arg == '\0')
                    924:                arg = strdelim(&cp);
                    925:        if (!arg || !*arg || *arg == '#')
                    926:                return 0;
                    927:        intptr = NULL;
                    928:        charptr = NULL;
1.153     dtucker   929:        opcode = parse_token(arg, filename, linenum, &flags);
                    930:
                    931:        if (activep == NULL) { /* We are processing a command line directive */
                    932:                cmdline = 1;
                    933:                activep = &cmdline;
                    934:        }
                    935:        if (*activep && opcode != sMatch)
                    936:                debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
                    937:        if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
1.226     dtucker   938:                if (connectinfo == NULL) {
1.153     dtucker   939:                        fatal("%s line %d: Directive '%s' is not allowed "
                    940:                            "within a Match block", filename, linenum, arg);
                    941:                } else { /* this is a directive we have already processed */
                    942:                        while (arg)
                    943:                                arg = strdelim(&cp);
                    944:                        return 0;
                    945:                }
                    946:        }
                    947:
1.94      markus    948:        switch (opcode) {
                    949:        case sBadOption:
                    950:                return -1;
                    951:        case sPort:
                    952:                /* ignore ports from configfile if cmdline specifies ports */
                    953:                if (options->ports_from_cmdline)
                    954:                        return 0;
                    955:                if (options->num_ports >= MAX_PORTS)
                    956:                        fatal("%s line %d: too many ports.",
                    957:                            filename, linenum);
1.48      provos    958:                arg = strdelim(&cp);
1.94      markus    959:                if (!arg || *arg == '\0')
                    960:                        fatal("%s line %d: missing port number.",
                    961:                            filename, linenum);
                    962:                options->ports[options->num_ports++] = a2port(arg);
1.194     djm       963:                if (options->ports[options->num_ports-1] <= 0)
1.94      markus    964:                        fatal("%s line %d: Badly formatted port number.",
                    965:                            filename, linenum);
                    966:                break;
1.29      markus    967:
1.94      markus    968:        case sLoginGraceTime:
                    969:                intptr = &options->login_grace_time;
1.180     djm       970:  parse_time:
1.94      markus    971:                arg = strdelim(&cp);
                    972:                if (!arg || *arg == '\0')
                    973:                        fatal("%s line %d: missing time value.",
                    974:                            filename, linenum);
                    975:                if ((value = convtime(arg)) == -1)
                    976:                        fatal("%s line %d: invalid time value.",
                    977:                            filename, linenum);
1.268     djm       978:                if (*activep && *intptr == -1)
1.94      markus    979:                        *intptr = value;
                    980:                break;
                    981:
                    982:        case sListenAddress:
                    983:                arg = strdelim(&cp);
1.139     djm       984:                if (arg == NULL || *arg == '\0')
                    985:                        fatal("%s line %d: missing address",
1.94      markus    986:                            filename, linenum);
1.144     dtucker   987:                /* check for bare IPv6 address: no "[]" and 2 or more ":" */
                    988:                if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
                    989:                    && strchr(p+1, ':') != NULL) {
1.266     dtucker   990:                        queue_listen_addr(options, arg, 0);
1.144     dtucker   991:                        break;
                    992:                }
1.139     djm       993:                p = hpdelim(&arg);
                    994:                if (p == NULL)
                    995:                        fatal("%s line %d: bad address:port usage",
                    996:                            filename, linenum);
                    997:                p = cleanhostname(p);
                    998:                if (arg == NULL)
                    999:                        port = 0;
1.194     djm      1000:                else if ((port = a2port(arg)) <= 0)
1.139     djm      1001:                        fatal("%s line %d: bad port number", filename, linenum);
                   1002:
1.266     dtucker  1003:                queue_listen_addr(options, p, port);
1.25      markus   1004:
1.138     djm      1005:                break;
                   1006:
                   1007:        case sAddressFamily:
1.220     djm      1008:                intptr = &options->address_family;
                   1009:                multistate_ptr = multistate_addressfamily;
                   1010:  parse_multistate:
1.138     djm      1011:                arg = strdelim(&cp);
1.141     markus   1012:                if (!arg || *arg == '\0')
1.220     djm      1013:                        fatal("%s line %d: missing argument.",
1.141     markus   1014:                            filename, linenum);
1.220     djm      1015:                value = -1;
                   1016:                for (i = 0; multistate_ptr[i].key != NULL; i++) {
                   1017:                        if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
                   1018:                                value = multistate_ptr[i].value;
                   1019:                                break;
                   1020:                        }
                   1021:                }
                   1022:                if (value == -1)
                   1023:                        fatal("%s line %d: unsupported option \"%s\".",
1.138     djm      1024:                            filename, linenum, arg);
1.220     djm      1025:                if (*activep && *intptr == -1)
1.138     djm      1026:                        *intptr = value;
1.94      markus   1027:                break;
                   1028:
                   1029:        case sHostKeyFile:
                   1030:                intptr = &options->num_host_key_files;
                   1031:                if (*intptr >= MAX_HOSTKEYS)
                   1032:                        fatal("%s line %d: too many host keys specified (max %d).",
                   1033:                            filename, linenum, MAX_HOSTKEYS);
                   1034:                charptr = &options->host_key_files[*intptr];
1.180     djm      1035:  parse_filename:
1.94      markus   1036:                arg = strdelim(&cp);
                   1037:                if (!arg || *arg == '\0')
                   1038:                        fatal("%s line %d: missing file name.",
                   1039:                            filename, linenum);
1.153     dtucker  1040:                if (*activep && *charptr == NULL) {
1.202     djm      1041:                        *charptr = derelativise_path(arg);
1.94      markus   1042:                        /* increase optional counter */
                   1043:                        if (intptr != NULL)
                   1044:                                *intptr = *intptr + 1;
                   1045:                }
                   1046:                break;
1.76      stevesk  1047:
1.240     markus   1048:        case sHostKeyAgent:
                   1049:                charptr = &options->host_key_agent;
                   1050:                arg = strdelim(&cp);
                   1051:                if (!arg || *arg == '\0')
                   1052:                        fatal("%s line %d: missing socket name.",
                   1053:                            filename, linenum);
                   1054:                if (*activep && *charptr == NULL)
                   1055:                        *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
                   1056:                            xstrdup(arg) : derelativise_path(arg);
                   1057:                break;
                   1058:
1.203     djm      1059:        case sHostCertificate:
                   1060:                intptr = &options->num_host_cert_files;
                   1061:                if (*intptr >= MAX_HOSTKEYS)
                   1062:                        fatal("%s line %d: too many host certificates "
                   1063:                            "specified (max %d).", filename, linenum,
                   1064:                            MAX_HOSTCERTS);
                   1065:                charptr = &options->host_cert_files[*intptr];
                   1066:                goto parse_filename;
                   1067:                break;
                   1068:
1.94      markus   1069:        case sPidFile:
                   1070:                charptr = &options->pid_file;
                   1071:                goto parse_filename;
1.25      markus   1072:
1.94      markus   1073:        case sPermitRootLogin:
                   1074:                intptr = &options->permit_root_login;
1.220     djm      1075:                multistate_ptr = multistate_permitrootlogin;
                   1076:                goto parse_multistate;
1.36      markus   1077:
1.94      markus   1078:        case sIgnoreRhosts:
                   1079:                intptr = &options->ignore_rhosts;
1.180     djm      1080:  parse_flag:
1.94      markus   1081:                arg = strdelim(&cp);
                   1082:                if (!arg || *arg == '\0')
                   1083:                        fatal("%s line %d: missing yes/no argument.",
                   1084:                            filename, linenum);
                   1085:                value = 0;      /* silence compiler */
                   1086:                if (strcmp(arg, "yes") == 0)
                   1087:                        value = 1;
                   1088:                else if (strcmp(arg, "no") == 0)
                   1089:                        value = 0;
                   1090:                else
                   1091:                        fatal("%s line %d: Bad yes/no argument: %s",
                   1092:                                filename, linenum, arg);
1.153     dtucker  1093:                if (*activep && *intptr == -1)
1.94      markus   1094:                        *intptr = value;
                   1095:                break;
                   1096:
                   1097:        case sIgnoreUserKnownHosts:
                   1098:                intptr = &options->ignore_user_known_hosts;
                   1099:                goto parse_flag;
                   1100:
                   1101:        case sHostbasedAuthentication:
                   1102:                intptr = &options->hostbased_authentication;
                   1103:                goto parse_flag;
                   1104:
                   1105:        case sHostbasedUsesNameFromPacketOnly:
                   1106:                intptr = &options->hostbased_uses_name_from_packet_only;
                   1107:                goto parse_flag;
                   1108:
1.258     djm      1109:        case sHostbasedAcceptedKeyTypes:
                   1110:                charptr = &options->hostbased_key_types;
                   1111:  parse_keytypes:
                   1112:                arg = strdelim(&cp);
                   1113:                if (!arg || *arg == '\0')
                   1114:                        fatal("%s line %d: Missing argument.",
                   1115:                            filename, linenum);
1.277     djm      1116:                if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1.258     djm      1117:                        fatal("%s line %d: Bad key types '%s'.",
                   1118:                            filename, linenum, arg ? arg : "<NONE>");
                   1119:                if (*activep && *charptr == NULL)
                   1120:                        *charptr = xstrdup(arg);
                   1121:                break;
                   1122:
1.276     markus   1123:        case sHostKeyAlgorithms:
                   1124:                charptr = &options->hostkeyalgorithms;
                   1125:                goto parse_keytypes;
                   1126:
1.94      markus   1127:        case sPubkeyAuthentication:
                   1128:                intptr = &options->pubkey_authentication;
                   1129:                goto parse_flag;
1.119     jakob    1130:
1.258     djm      1131:        case sPubkeyAcceptedKeyTypes:
                   1132:                charptr = &options->pubkey_key_types;
                   1133:                goto parse_keytypes;
                   1134:
1.94      markus   1135:        case sKerberosAuthentication:
                   1136:                intptr = &options->kerberos_authentication;
                   1137:                goto parse_flag;
                   1138:
                   1139:        case sKerberosOrLocalPasswd:
                   1140:                intptr = &options->kerberos_or_local_passwd;
                   1141:                goto parse_flag;
                   1142:
                   1143:        case sKerberosTicketCleanup:
                   1144:                intptr = &options->kerberos_ticket_cleanup;
1.130     jakob    1145:                goto parse_flag;
                   1146:
                   1147:        case sKerberosGetAFSToken:
                   1148:                intptr = &options->kerberos_get_afs_token;
1.125     markus   1149:                goto parse_flag;
                   1150:
                   1151:        case sGssAuthentication:
                   1152:                intptr = &options->gss_authentication;
                   1153:                goto parse_flag;
                   1154:
                   1155:        case sGssCleanupCreds:
                   1156:                intptr = &options->gss_cleanup_creds;
1.271     djm      1157:                goto parse_flag;
                   1158:
                   1159:        case sGssStrictAcceptor:
                   1160:                intptr = &options->gss_strict_acceptor;
1.94      markus   1161:                goto parse_flag;
                   1162:
                   1163:        case sPasswordAuthentication:
                   1164:                intptr = &options->password_authentication;
                   1165:                goto parse_flag;
                   1166:
                   1167:        case sKbdInteractiveAuthentication:
                   1168:                intptr = &options->kbd_interactive_authentication;
                   1169:                goto parse_flag;
                   1170:
                   1171:        case sChallengeResponseAuthentication:
                   1172:                intptr = &options->challenge_response_authentication;
                   1173:                goto parse_flag;
                   1174:
                   1175:        case sPrintMotd:
                   1176:                intptr = &options->print_motd;
                   1177:                goto parse_flag;
                   1178:
                   1179:        case sPrintLastLog:
                   1180:                intptr = &options->print_lastlog;
                   1181:                goto parse_flag;
                   1182:
                   1183:        case sX11Forwarding:
                   1184:                intptr = &options->x11_forwarding;
                   1185:                goto parse_flag;
                   1186:
                   1187:        case sX11DisplayOffset:
                   1188:                intptr = &options->x11_display_offset;
1.293     naddy    1189:  parse_int:
                   1190:                arg = strdelim(&cp);
                   1191:                if (!arg || *arg == '\0')
                   1192:                        fatal("%s line %d: missing integer value.",
                   1193:                            filename, linenum);
                   1194:                value = atoi(arg);
                   1195:                if (*activep && *intptr == -1)
                   1196:                        *intptr = value;
                   1197:                break;
1.99      stevesk  1198:
                   1199:        case sX11UseLocalhost:
                   1200:                intptr = &options->x11_use_localhost;
                   1201:                goto parse_flag;
1.94      markus   1202:
                   1203:        case sXAuthLocation:
                   1204:                charptr = &options->xauth_location;
                   1205:                goto parse_filename;
                   1206:
1.244     djm      1207:        case sPermitTTY:
                   1208:                intptr = &options->permit_tty;
                   1209:                goto parse_flag;
                   1210:
1.250     djm      1211:        case sPermitUserRC:
                   1212:                intptr = &options->permit_user_rc;
                   1213:                goto parse_flag;
                   1214:
1.94      markus   1215:        case sStrictModes:
                   1216:                intptr = &options->strict_modes;
                   1217:                goto parse_flag;
                   1218:
1.129     markus   1219:        case sTCPKeepAlive:
                   1220:                intptr = &options->tcp_keep_alive;
1.94      markus   1221:                goto parse_flag;
                   1222:
                   1223:        case sEmptyPasswd:
                   1224:                intptr = &options->permit_empty_passwd;
1.113     markus   1225:                goto parse_flag;
                   1226:
                   1227:        case sPermitUserEnvironment:
                   1228:                intptr = &options->permit_user_env;
1.94      markus   1229:                goto parse_flag;
                   1230:
1.111     markus   1231:        case sCompression:
                   1232:                intptr = &options->compression;
1.220     djm      1233:                multistate_ptr = multistate_compression;
                   1234:                goto parse_multistate;
1.94      markus   1235:
1.235     dtucker  1236:        case sRekeyLimit:
                   1237:                arg = strdelim(&cp);
                   1238:                if (!arg || *arg == '\0')
                   1239:                        fatal("%.200s line %d: Missing argument.", filename,
                   1240:                            linenum);
                   1241:                if (strcmp(arg, "default") == 0) {
                   1242:                        val64 = 0;
                   1243:                } else {
1.236     dtucker  1244:                        if (scan_scaled(arg, &val64) == -1)
                   1245:                                fatal("%.200s line %d: Bad number '%s': %s",
                   1246:                                    filename, linenum, arg, strerror(errno));
1.235     dtucker  1247:                        if (val64 != 0 && val64 < 16)
                   1248:                                fatal("%.200s line %d: RekeyLimit too small",
                   1249:                                    filename, linenum);
                   1250:                }
                   1251:                if (*activep && options->rekey_limit == -1)
1.284     dtucker  1252:                        options->rekey_limit = val64;
1.235     dtucker  1253:                if (cp != NULL) { /* optional rekey interval present */
                   1254:                        if (strcmp(cp, "none") == 0) {
                   1255:                                (void)strdelim(&cp);    /* discard */
                   1256:                                break;
                   1257:                        }
                   1258:                        intptr = &options->rekey_interval;
                   1259:                        goto parse_time;
                   1260:                }
                   1261:                break;
                   1262:
1.94      markus   1263:        case sGatewayPorts:
1.251     millert  1264:                intptr = &options->fwd_opts.gateway_ports;
1.220     djm      1265:                multistate_ptr = multistate_gatewayports;
                   1266:                goto parse_multistate;
1.25      markus   1267:
1.122     markus   1268:        case sUseDNS:
                   1269:                intptr = &options->use_dns;
1.94      markus   1270:                goto parse_flag;
1.53      markus   1271:
1.94      markus   1272:        case sLogFacility:
1.174     dtucker  1273:                log_facility_ptr = &options->log_facility;
1.94      markus   1274:                arg = strdelim(&cp);
                   1275:                value = log_facility_number(arg);
1.101     markus   1276:                if (value == SYSLOG_FACILITY_NOT_SET)
1.94      markus   1277:                        fatal("%.200s line %d: unsupported log facility '%s'",
                   1278:                            filename, linenum, arg ? arg : "<NONE>");
1.174     dtucker  1279:                if (*log_facility_ptr == -1)
                   1280:                        *log_facility_ptr = (SyslogFacility) value;
1.94      markus   1281:                break;
1.25      markus   1282:
1.94      markus   1283:        case sLogLevel:
1.174     dtucker  1284:                log_level_ptr = &options->log_level;
1.94      markus   1285:                arg = strdelim(&cp);
                   1286:                value = log_level_number(arg);
1.101     markus   1287:                if (value == SYSLOG_LEVEL_NOT_SET)
1.94      markus   1288:                        fatal("%.200s line %d: unsupported log level '%s'",
                   1289:                            filename, linenum, arg ? arg : "<NONE>");
1.174     dtucker  1290:                if (*log_level_ptr == -1)
                   1291:                        *log_level_ptr = (LogLevel) value;
1.94      markus   1292:                break;
                   1293:
                   1294:        case sAllowTcpForwarding:
                   1295:                intptr = &options->allow_tcp_forwarding;
1.233     djm      1296:                multistate_ptr = multistate_tcpfwd;
                   1297:                goto parse_multistate;
1.102     provos   1298:
1.251     millert  1299:        case sAllowStreamLocalForwarding:
                   1300:                intptr = &options->allow_streamlocal_forwarding;
                   1301:                multistate_ptr = multistate_tcpfwd;
                   1302:                goto parse_multistate;
                   1303:
1.178     pyr      1304:        case sAllowAgentForwarding:
                   1305:                intptr = &options->allow_agent_forwarding;
                   1306:                goto parse_flag;
                   1307:
1.102     provos   1308:        case sUsePrivilegeSeparation:
                   1309:                intptr = &use_privsep;
1.222     djm      1310:                multistate_ptr = multistate_privsep;
                   1311:                goto parse_multistate;
1.94      markus   1312:
                   1313:        case sAllowUsers:
                   1314:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1315:                        if (options->num_allow_users >= MAX_ALLOW_USERS)
                   1316:                                fatal("%s line %d: too many allow users.",
                   1317:                                    filename, linenum);
1.227     markus   1318:                        if (!*activep)
                   1319:                                continue;
1.112     deraadt  1320:                        options->allow_users[options->num_allow_users++] =
                   1321:                            xstrdup(arg);
1.94      markus   1322:                }
                   1323:                break;
1.25      markus   1324:
1.94      markus   1325:        case sDenyUsers:
                   1326:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1327:                        if (options->num_deny_users >= MAX_DENY_USERS)
1.163     stevesk  1328:                                fatal("%s line %d: too many deny users.",
1.94      markus   1329:                                    filename, linenum);
1.227     markus   1330:                        if (!*activep)
                   1331:                                continue;
1.112     deraadt  1332:                        options->deny_users[options->num_deny_users++] =
                   1333:                            xstrdup(arg);
1.94      markus   1334:                }
                   1335:                break;
1.25      markus   1336:
1.94      markus   1337:        case sAllowGroups:
                   1338:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1339:                        if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
                   1340:                                fatal("%s line %d: too many allow groups.",
                   1341:                                    filename, linenum);
1.227     markus   1342:                        if (!*activep)
                   1343:                                continue;
1.112     deraadt  1344:                        options->allow_groups[options->num_allow_groups++] =
                   1345:                            xstrdup(arg);
1.94      markus   1346:                }
                   1347:                break;
1.33      markus   1348:
1.94      markus   1349:        case sDenyGroups:
                   1350:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1351:                        if (options->num_deny_groups >= MAX_DENY_GROUPS)
                   1352:                                fatal("%s line %d: too many deny groups.",
                   1353:                                    filename, linenum);
1.227     markus   1354:                        if (!*activep)
                   1355:                                continue;
                   1356:                        options->deny_groups[options->num_deny_groups++] =
                   1357:                            xstrdup(arg);
1.94      markus   1358:                }
                   1359:                break;
1.66      markus   1360:
1.94      markus   1361:        case sCiphers:
                   1362:                arg = strdelim(&cp);
                   1363:                if (!arg || *arg == '\0')
                   1364:                        fatal("%s line %d: Missing argument.", filename, linenum);
1.277     djm      1365:                if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
1.94      markus   1366:                        fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
                   1367:                            filename, linenum, arg ? arg : "<NONE>");
                   1368:                if (options->ciphers == NULL)
                   1369:                        options->ciphers = xstrdup(arg);
                   1370:                break;
1.33      markus   1371:
1.94      markus   1372:        case sMacs:
                   1373:                arg = strdelim(&cp);
                   1374:                if (!arg || *arg == '\0')
                   1375:                        fatal("%s line %d: Missing argument.", filename, linenum);
1.277     djm      1376:                if (!mac_valid(*arg == '+' ? arg + 1 : arg))
1.94      markus   1377:                        fatal("%s line %d: Bad SSH2 mac spec '%s'.",
                   1378:                            filename, linenum, arg ? arg : "<NONE>");
                   1379:                if (options->macs == NULL)
                   1380:                        options->macs = xstrdup(arg);
1.211     djm      1381:                break;
                   1382:
                   1383:        case sKexAlgorithms:
                   1384:                arg = strdelim(&cp);
                   1385:                if (!arg || *arg == '\0')
                   1386:                        fatal("%s line %d: Missing argument.",
                   1387:                            filename, linenum);
1.277     djm      1388:                if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
1.211     djm      1389:                        fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
                   1390:                            filename, linenum, arg ? arg : "<NONE>");
                   1391:                if (options->kex_algorithms == NULL)
                   1392:                        options->kex_algorithms = xstrdup(arg);
1.94      markus   1393:                break;
1.43      jakob    1394:
1.94      markus   1395:        case sSubsystem:
                   1396:                if (options->num_subsystems >= MAX_SUBSYSTEMS) {
                   1397:                        fatal("%s line %d: too many subsystems defined.",
1.95      deraadt  1398:                            filename, linenum);
1.94      markus   1399:                }
                   1400:                arg = strdelim(&cp);
                   1401:                if (!arg || *arg == '\0')
                   1402:                        fatal("%s line %d: Missing subsystem name.",
1.95      deraadt  1403:                            filename, linenum);
1.153     dtucker  1404:                if (!*activep) {
                   1405:                        arg = strdelim(&cp);
                   1406:                        break;
                   1407:                }
1.94      markus   1408:                for (i = 0; i < options->num_subsystems; i++)
                   1409:                        if (strcmp(arg, options->subsystem_name[i]) == 0)
                   1410:                                fatal("%s line %d: Subsystem '%s' already defined.",
1.95      deraadt  1411:                                    filename, linenum, arg);
1.94      markus   1412:                options->subsystem_name[options->num_subsystems] = xstrdup(arg);
                   1413:                arg = strdelim(&cp);
                   1414:                if (!arg || *arg == '\0')
                   1415:                        fatal("%s line %d: Missing subsystem command.",
1.95      deraadt  1416:                            filename, linenum);
1.94      markus   1417:                options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151     djm      1418:
                   1419:                /* Collect arguments (separate to executable) */
                   1420:                p = xstrdup(arg);
                   1421:                len = strlen(p) + 1;
                   1422:                while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
                   1423:                        len += 1 + strlen(arg);
1.264     deraadt  1424:                        p = xreallocarray(p, 1, len);
1.151     djm      1425:                        strlcat(p, " ", len);
                   1426:                        strlcat(p, arg, len);
                   1427:                }
                   1428:                options->subsystem_args[options->num_subsystems] = p;
1.94      markus   1429:                options->num_subsystems++;
                   1430:                break;
1.46      markus   1431:
1.94      markus   1432:        case sMaxStartups:
                   1433:                arg = strdelim(&cp);
                   1434:                if (!arg || *arg == '\0')
                   1435:                        fatal("%s line %d: Missing MaxStartups spec.",
1.95      deraadt  1436:                            filename, linenum);
1.94      markus   1437:                if ((n = sscanf(arg, "%d:%d:%d",
                   1438:                    &options->max_startups_begin,
                   1439:                    &options->max_startups_rate,
                   1440:                    &options->max_startups)) == 3) {
                   1441:                        if (options->max_startups_begin >
                   1442:                            options->max_startups ||
                   1443:                            options->max_startups_rate > 100 ||
                   1444:                            options->max_startups_rate < 1)
1.50      markus   1445:                                fatal("%s line %d: Illegal MaxStartups spec.",
1.87      stevesk  1446:                                    filename, linenum);
1.94      markus   1447:                } else if (n != 1)
                   1448:                        fatal("%s line %d: Illegal MaxStartups spec.",
                   1449:                            filename, linenum);
                   1450:                else
                   1451:                        options->max_startups = options->max_startups_begin;
                   1452:                break;
1.133     dtucker  1453:
                   1454:        case sMaxAuthTries:
                   1455:                intptr = &options->max_authtries;
                   1456:                goto parse_int;
1.94      markus   1457:
1.180     djm      1458:        case sMaxSessions:
                   1459:                intptr = &options->max_sessions;
                   1460:                goto parse_int;
                   1461:
1.94      markus   1462:        case sBanner:
                   1463:                charptr = &options->banner;
                   1464:                goto parse_filename;
1.176     djm      1465:
1.94      markus   1466:        /*
                   1467:         * These options can contain %X options expanded at
                   1468:         * connect time, so that you can specify paths like:
                   1469:         *
                   1470:         * AuthorizedKeysFile   /etc/ssh_keys/%u
                   1471:         */
                   1472:        case sAuthorizedKeysFile:
1.219     djm      1473:                if (*activep && options->num_authkeys_files == 0) {
                   1474:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1475:                                if (options->num_authkeys_files >=
                   1476:                                    MAX_AUTHKEYS_FILES)
                   1477:                                        fatal("%s line %d: "
                   1478:                                            "too many authorized keys files.",
                   1479:                                            filename, linenum);
                   1480:                                options->authorized_keys_files[
                   1481:                                    options->num_authkeys_files++] =
                   1482:                                    tilde_expand_filename(arg, getuid());
                   1483:                        }
                   1484:                }
                   1485:                return 0;
                   1486:
1.208     djm      1487:        case sAuthorizedPrincipalsFile:
                   1488:                charptr = &options->authorized_principals_file;
1.205     djm      1489:                arg = strdelim(&cp);
                   1490:                if (!arg || *arg == '\0')
                   1491:                        fatal("%s line %d: missing file name.",
                   1492:                            filename, linenum);
                   1493:                if (*activep && *charptr == NULL) {
1.206     markus   1494:                        *charptr = tilde_expand_filename(arg, getuid());
1.205     djm      1495:                        /* increase optional counter */
                   1496:                        if (intptr != NULL)
                   1497:                                *intptr = *intptr + 1;
                   1498:                }
                   1499:                break;
1.94      markus   1500:
                   1501:        case sClientAliveInterval:
                   1502:                intptr = &options->client_alive_interval;
                   1503:                goto parse_time;
                   1504:
                   1505:        case sClientAliveCountMax:
                   1506:                intptr = &options->client_alive_count_max;
                   1507:                goto parse_int;
1.131     djm      1508:
                   1509:        case sAcceptEnv:
                   1510:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1511:                        if (strchr(arg, '=') != NULL)
                   1512:                                fatal("%s line %d: Invalid environment name.",
                   1513:                                    filename, linenum);
                   1514:                        if (options->num_accept_env >= MAX_ACCEPT_ENV)
                   1515:                                fatal("%s line %d: too many allow env.",
                   1516:                                    filename, linenum);
1.153     dtucker  1517:                        if (!*activep)
1.227     markus   1518:                                continue;
1.131     djm      1519:                        options->accept_env[options->num_accept_env++] =
                   1520:                            xstrdup(arg);
                   1521:                }
                   1522:                break;
1.145     reyk     1523:
                   1524:        case sPermitTunnel:
                   1525:                intptr = &options->permit_tun;
1.146     reyk     1526:                arg = strdelim(&cp);
                   1527:                if (!arg || *arg == '\0')
                   1528:                        fatal("%s line %d: Missing yes/point-to-point/"
                   1529:                            "ethernet/no argument.", filename, linenum);
1.182     dtucker  1530:                value = -1;
                   1531:                for (i = 0; tunmode_desc[i].val != -1; i++)
                   1532:                        if (strcmp(tunmode_desc[i].text, arg) == 0) {
                   1533:                                value = tunmode_desc[i].val;
                   1534:                                break;
                   1535:                        }
                   1536:                if (value == -1)
1.146     reyk     1537:                        fatal("%s line %d: Bad yes/point-to-point/ethernet/"
                   1538:                            "no argument: %s", filename, linenum, arg);
1.268     djm      1539:                if (*activep && *intptr == -1)
1.146     reyk     1540:                        *intptr = value;
                   1541:                break;
1.94      markus   1542:
1.153     dtucker  1543:        case sMatch:
                   1544:                if (cmdline)
                   1545:                        fatal("Match directive not supported as a command-line "
                   1546:                           "option");
1.226     dtucker  1547:                value = match_cfg_line(&cp, linenum, connectinfo);
1.153     dtucker  1548:                if (value < 0)
                   1549:                        fatal("%s line %d: Bad Match condition", filename,
                   1550:                            linenum);
                   1551:                *activep = value;
1.156     dtucker  1552:                break;
                   1553:
                   1554:        case sPermitOpen:
                   1555:                arg = strdelim(&cp);
                   1556:                if (!arg || *arg == '\0')
                   1557:                        fatal("%s line %d: missing PermitOpen specification",
                   1558:                            filename, linenum);
1.167     dtucker  1559:                n = options->num_permitted_opens;       /* modified later */
1.156     dtucker  1560:                if (strcmp(arg, "any") == 0) {
1.167     dtucker  1561:                        if (*activep && n == -1) {
1.156     dtucker  1562:                                channel_clear_adm_permitted_opens();
1.159     dtucker  1563:                                options->num_permitted_opens = 0;
1.224     dtucker  1564:                        }
                   1565:                        break;
                   1566:                }
                   1567:                if (strcmp(arg, "none") == 0) {
                   1568:                        if (*activep && n == -1) {
                   1569:                                options->num_permitted_opens = 1;
                   1570:                                channel_disable_adm_local_opens();
1.159     dtucker  1571:                        }
1.156     dtucker  1572:                        break;
                   1573:                }
1.166     dtucker  1574:                if (*activep && n == -1)
                   1575:                        channel_clear_adm_permitted_opens();
1.159     dtucker  1576:                for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
                   1577:                        p = hpdelim(&arg);
                   1578:                        if (p == NULL)
                   1579:                                fatal("%s line %d: missing host in PermitOpen",
                   1580:                                    filename, linenum);
                   1581:                        p = cleanhostname(p);
1.223     dtucker  1582:                        if (arg == NULL || ((port = permitopen_port(arg)) < 0))
1.159     dtucker  1583:                                fatal("%s line %d: bad port number in "
                   1584:                                    "PermitOpen", filename, linenum);
1.166     dtucker  1585:                        if (*activep && n == -1)
1.159     dtucker  1586:                                options->num_permitted_opens =
                   1587:                                    channel_add_adm_permitted_opens(p, port);
                   1588:                }
1.153     dtucker  1589:                break;
                   1590:
1.158     dtucker  1591:        case sForceCommand:
1.262     dtucker  1592:                if (cp == NULL || *cp == '\0')
1.158     dtucker  1593:                        fatal("%.200s line %d: Missing argument.", filename,
                   1594:                            linenum);
                   1595:                len = strspn(cp, WHITESPACE);
                   1596:                if (*activep && options->adm_forced_command == NULL)
                   1597:                        options->adm_forced_command = xstrdup(cp + len);
                   1598:                return 0;
                   1599:
1.176     djm      1600:        case sChrootDirectory:
                   1601:                charptr = &options->chroot_directory;
1.177     djm      1602:
                   1603:                arg = strdelim(&cp);
                   1604:                if (!arg || *arg == '\0')
                   1605:                        fatal("%s line %d: missing file name.",
                   1606:                            filename, linenum);
                   1607:                if (*activep && *charptr == NULL)
                   1608:                        *charptr = xstrdup(arg);
                   1609:                break;
1.176     djm      1610:
1.204     djm      1611:        case sTrustedUserCAKeys:
                   1612:                charptr = &options->trusted_user_ca_keys;
                   1613:                goto parse_filename;
                   1614:
                   1615:        case sRevokedKeys:
                   1616:                charptr = &options->revoked_keys_file;
                   1617:                goto parse_filename;
                   1618:
1.213     djm      1619:        case sIPQoS:
                   1620:                arg = strdelim(&cp);
                   1621:                if ((value = parse_ipqos(arg)) == -1)
                   1622:                        fatal("%s line %d: Bad IPQoS value: %s",
                   1623:                            filename, linenum, arg);
                   1624:                arg = strdelim(&cp);
                   1625:                if (arg == NULL)
                   1626:                        value2 = value;
                   1627:                else if ((value2 = parse_ipqos(arg)) == -1)
                   1628:                        fatal("%s line %d: Bad IPQoS value: %s",
                   1629:                            filename, linenum, arg);
                   1630:                if (*activep) {
                   1631:                        options->ip_qos_interactive = value;
                   1632:                        options->ip_qos_bulk = value2;
                   1633:                }
                   1634:                break;
                   1635:
1.225     djm      1636:        case sVersionAddendum:
1.262     dtucker  1637:                if (cp == NULL || *cp == '\0')
1.225     djm      1638:                        fatal("%.200s line %d: Missing argument.", filename,
                   1639:                            linenum);
                   1640:                len = strspn(cp, WHITESPACE);
                   1641:                if (*activep && options->version_addendum == NULL) {
                   1642:                        if (strcasecmp(cp + len, "none") == 0)
                   1643:                                options->version_addendum = xstrdup("");
                   1644:                        else if (strchr(cp + len, '\r') != NULL)
                   1645:                                fatal("%.200s line %d: Invalid argument",
                   1646:                                    filename, linenum);
                   1647:                        else
                   1648:                                options->version_addendum = xstrdup(cp + len);
                   1649:                }
                   1650:                return 0;
                   1651:
1.231     djm      1652:        case sAuthorizedKeysCommand:
1.255     jsg      1653:                if (cp == NULL)
                   1654:                        fatal("%.200s line %d: Missing argument.", filename,
                   1655:                            linenum);
1.231     djm      1656:                len = strspn(cp, WHITESPACE);
                   1657:                if (*activep && options->authorized_keys_command == NULL) {
                   1658:                        if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
                   1659:                                fatal("%.200s line %d: AuthorizedKeysCommand "
                   1660:                                    "must be an absolute path",
                   1661:                                    filename, linenum);
                   1662:                        options->authorized_keys_command = xstrdup(cp + len);
                   1663:                }
                   1664:                return 0;
                   1665:
                   1666:        case sAuthorizedKeysCommandUser:
                   1667:                charptr = &options->authorized_keys_command_user;
                   1668:
                   1669:                arg = strdelim(&cp);
1.255     jsg      1670:                if (!arg || *arg == '\0')
                   1671:                        fatal("%s line %d: missing AuthorizedKeysCommandUser "
                   1672:                            "argument.", filename, linenum);
1.231     djm      1673:                if (*activep && *charptr == NULL)
                   1674:                        *charptr = xstrdup(arg);
                   1675:                break;
                   1676:
1.270     djm      1677:        case sAuthorizedPrincipalsCommand:
                   1678:                if (cp == NULL)
                   1679:                        fatal("%.200s line %d: Missing argument.", filename,
                   1680:                            linenum);
                   1681:                len = strspn(cp, WHITESPACE);
                   1682:                if (*activep &&
                   1683:                    options->authorized_principals_command == NULL) {
                   1684:                        if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
                   1685:                                fatal("%.200s line %d: "
                   1686:                                    "AuthorizedPrincipalsCommand must be "
                   1687:                                    "an absolute path", filename, linenum);
                   1688:                        options->authorized_principals_command =
                   1689:                            xstrdup(cp + len);
                   1690:                }
                   1691:                return 0;
                   1692:
                   1693:        case sAuthorizedPrincipalsCommandUser:
                   1694:                charptr = &options->authorized_principals_command_user;
                   1695:
                   1696:                arg = strdelim(&cp);
                   1697:                if (!arg || *arg == '\0')
                   1698:                        fatal("%s line %d: missing "
                   1699:                            "AuthorizedPrincipalsCommandUser argument.",
                   1700:                            filename, linenum);
                   1701:                if (*activep && *charptr == NULL)
                   1702:                        *charptr = xstrdup(arg);
                   1703:                break;
                   1704:
1.232     djm      1705:        case sAuthenticationMethods:
1.268     djm      1706:                if (options->num_auth_methods == 0) {
1.291     djm      1707:                        value = 0; /* seen "any" pseudo-method */
1.292     djm      1708:                        value2 = 0; /* sucessfully parsed any method */
1.232     djm      1709:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1710:                                if (options->num_auth_methods >=
                   1711:                                    MAX_AUTH_METHODS)
                   1712:                                        fatal("%s line %d: "
                   1713:                                            "too many authentication methods.",
                   1714:                                            filename, linenum);
1.291     djm      1715:                                if (strcmp(arg, "any") == 0) {
                   1716:                                        if (options->num_auth_methods > 0) {
                   1717:                                                fatal("%s line %d: \"any\" "
                   1718:                                                    "must appear alone in "
                   1719:                                                    "AuthenticationMethods",
                   1720:                                                    filename, linenum);
                   1721:                                        }
                   1722:                                        value = 1;
                   1723:                                } else if (value) {
                   1724:                                        fatal("%s line %d: \"any\" must appear "
                   1725:                                            "alone in AuthenticationMethods",
                   1726:                                            filename, linenum);
                   1727:                                } else if (auth2_methods_valid(arg, 0) != 0) {
1.232     djm      1728:                                        fatal("%s line %d: invalid "
                   1729:                                            "authentication method list.",
                   1730:                                            filename, linenum);
1.291     djm      1731:                                }
1.292     djm      1732:                                value2 = 1;
1.268     djm      1733:                                if (!*activep)
                   1734:                                        continue;
1.232     djm      1735:                                options->auth_methods[
                   1736:                                    options->num_auth_methods++] = xstrdup(arg);
                   1737:                        }
1.292     djm      1738:                        if (value2 == 0) {
1.291     djm      1739:                                fatal("%s line %d: no AuthenticationMethods "
                   1740:                                    "specified", filename, linenum);
                   1741:                        }
1.232     djm      1742:                }
                   1743:                return 0;
                   1744:
1.251     millert  1745:        case sStreamLocalBindMask:
                   1746:                arg = strdelim(&cp);
                   1747:                if (!arg || *arg == '\0')
1.268     djm      1748:                        fatal("%s line %d: missing StreamLocalBindMask "
                   1749:                            "argument.", filename, linenum);
1.251     millert  1750:                /* Parse mode in octal format */
                   1751:                value = strtol(arg, &p, 8);
                   1752:                if (arg == p || value < 0 || value > 0777)
                   1753:                        fatal("%s line %d: Bad mask.", filename, linenum);
1.268     djm      1754:                if (*activep)
                   1755:                        options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1.251     millert  1756:                break;
                   1757:
                   1758:        case sStreamLocalBindUnlink:
                   1759:                intptr = &options->fwd_opts.streamlocal_bind_unlink;
                   1760:                goto parse_flag;
                   1761:
1.256     djm      1762:        case sFingerprintHash:
                   1763:                arg = strdelim(&cp);
                   1764:                if (!arg || *arg == '\0')
                   1765:                        fatal("%.200s line %d: Missing argument.",
                   1766:                            filename, linenum);
                   1767:                if ((value = ssh_digest_alg_by_name(arg)) == -1)
                   1768:                        fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
                   1769:                            filename, linenum, arg);
                   1770:                if (*activep)
                   1771:                        options->fingerprint_hash = value;
                   1772:                break;
                   1773:
1.94      markus   1774:        case sDeprecated:
1.295     djm      1775:        case sIgnore:
1.121     jakob    1776:        case sUnsupported:
1.295     djm      1777:                do_log2(opcode == sIgnore ?
                   1778:                    SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
                   1779:                    "%s line %d: %s option %s", filename, linenum,
                   1780:                    opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
1.94      markus   1781:                while (arg)
                   1782:                    arg = strdelim(&cp);
                   1783:                break;
                   1784:
                   1785:        default:
                   1786:                fatal("%s line %d: Missing handler for opcode %s (%d)",
                   1787:                    filename, linenum, arg, opcode);
                   1788:        }
                   1789:        if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
                   1790:                fatal("%s line %d: garbage at end of line; \"%.200s\".",
                   1791:                    filename, linenum, arg);
                   1792:        return 0;
                   1793: }
                   1794:
                   1795: /* Reads the server configuration file. */
1.25      markus   1796:
1.94      markus   1797: void
1.134     djm      1798: load_server_config(const char *filename, Buffer *conf)
1.94      markus   1799: {
1.229     dtucker  1800:        char line[4096], *cp;
1.94      markus   1801:        FILE *f;
1.229     dtucker  1802:        int lineno = 0;
1.81      stevesk  1803:
1.134     djm      1804:        debug2("%s: filename %s", __func__, filename);
                   1805:        if ((f = fopen(filename, "r")) == NULL) {
1.94      markus   1806:                perror(filename);
                   1807:                exit(1);
                   1808:        }
1.134     djm      1809:        buffer_clear(conf);
                   1810:        while (fgets(line, sizeof(line), f)) {
1.229     dtucker  1811:                lineno++;
                   1812:                if (strlen(line) == sizeof(line) - 1)
                   1813:                        fatal("%s line %d too long", filename, lineno);
1.134     djm      1814:                /*
                   1815:                 * Trim out comments and strip whitespace
1.135     deraadt  1816:                 * NB - preserve newlines, they are needed to reproduce
1.134     djm      1817:                 * line numbers later for error messages
                   1818:                 */
                   1819:                if ((cp = strchr(line, '#')) != NULL)
                   1820:                        memcpy(cp, "\n", 2);
                   1821:                cp = line + strspn(line, " \t\r");
                   1822:
                   1823:                buffer_append(conf, cp, strlen(cp));
                   1824:        }
                   1825:        buffer_append(conf, "\0", 1);
                   1826:        fclose(f);
                   1827:        debug2("%s: done config len = %d", __func__, buffer_len(conf));
                   1828: }
                   1829:
                   1830: void
1.226     dtucker  1831: parse_server_match_config(ServerOptions *options,
                   1832:    struct connection_info *connectinfo)
1.153     dtucker  1833: {
                   1834:        ServerOptions mo;
                   1835:
                   1836:        initialize_server_options(&mo);
1.226     dtucker  1837:        parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
1.168     dtucker  1838:        copy_set_server_options(options, &mo, 0);
1.153     dtucker  1839: }
                   1840:
1.226     dtucker  1841: int parse_server_match_testspec(struct connection_info *ci, char *spec)
                   1842: {
                   1843:        char *p;
                   1844:
                   1845:        while ((p = strsep(&spec, ",")) && *p != '\0') {
                   1846:                if (strncmp(p, "addr=", 5) == 0) {
                   1847:                        ci->address = xstrdup(p + 5);
                   1848:                } else if (strncmp(p, "host=", 5) == 0) {
                   1849:                        ci->host = xstrdup(p + 5);
                   1850:                } else if (strncmp(p, "user=", 5) == 0) {
                   1851:                        ci->user = xstrdup(p + 5);
                   1852:                } else if (strncmp(p, "laddr=", 6) == 0) {
                   1853:                        ci->laddress = xstrdup(p + 6);
                   1854:                } else if (strncmp(p, "lport=", 6) == 0) {
                   1855:                        ci->lport = a2port(p + 6);
                   1856:                        if (ci->lport == -1) {
                   1857:                                fprintf(stderr, "Invalid port '%s' in test mode"
                   1858:                                   " specification %s\n", p+6, p);
                   1859:                                return -1;
                   1860:                        }
                   1861:                } else {
                   1862:                        fprintf(stderr, "Invalid test mode specification %s\n",
                   1863:                           p);
                   1864:                        return -1;
                   1865:                }
                   1866:        }
                   1867:        return 0;
                   1868: }
                   1869:
                   1870: /*
                   1871:  * returns 1 for a complete spec, 0 for partial spec and -1 for an
                   1872:  * empty spec.
                   1873:  */
                   1874: int server_match_spec_complete(struct connection_info *ci)
                   1875: {
                   1876:        if (ci->user && ci->host && ci->address)
                   1877:                return 1;       /* complete */
                   1878:        if (!ci->user && !ci->host && !ci->address)
                   1879:                return -1;      /* empty */
                   1880:        return 0;       /* partial */
                   1881: }
                   1882:
1.168     dtucker  1883: /*
                   1884:  * Copy any supported values that are set.
                   1885:  *
1.195     jj       1886:  * If the preauth flag is set, we do not bother copying the string or
1.168     dtucker  1887:  * array values that are not used pre-authentication, because any that we
                   1888:  * do use must be explictly sent in mm_getpwnamallow().
                   1889:  */
1.153     dtucker  1890: void
1.168     dtucker  1891: copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1.153     dtucker  1892: {
1.247     djm      1893: #define M_CP_INTOPT(n) do {\
                   1894:        if (src->n != -1) \
                   1895:                dst->n = src->n; \
                   1896: } while (0)
                   1897:
1.168     dtucker  1898:        M_CP_INTOPT(password_authentication);
                   1899:        M_CP_INTOPT(gss_authentication);
                   1900:        M_CP_INTOPT(pubkey_authentication);
                   1901:        M_CP_INTOPT(kerberos_authentication);
                   1902:        M_CP_INTOPT(hostbased_authentication);
1.209     djm      1903:        M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1.168     dtucker  1904:        M_CP_INTOPT(kbd_interactive_authentication);
1.175     dtucker  1905:        M_CP_INTOPT(permit_root_login);
1.188     djm      1906:        M_CP_INTOPT(permit_empty_passwd);
1.168     dtucker  1907:
                   1908:        M_CP_INTOPT(allow_tcp_forwarding);
1.251     millert  1909:        M_CP_INTOPT(allow_streamlocal_forwarding);
1.178     pyr      1910:        M_CP_INTOPT(allow_agent_forwarding);
1.209     djm      1911:        M_CP_INTOPT(permit_tun);
1.251     millert  1912:        M_CP_INTOPT(fwd_opts.gateway_ports);
1.289     djm      1913:        M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
1.168     dtucker  1914:        M_CP_INTOPT(x11_display_offset);
                   1915:        M_CP_INTOPT(x11_forwarding);
                   1916:        M_CP_INTOPT(x11_use_localhost);
1.244     djm      1917:        M_CP_INTOPT(permit_tty);
1.250     djm      1918:        M_CP_INTOPT(permit_user_rc);
1.180     djm      1919:        M_CP_INTOPT(max_sessions);
1.184     dtucker  1920:        M_CP_INTOPT(max_authtries);
1.213     djm      1921:        M_CP_INTOPT(ip_qos_interactive);
                   1922:        M_CP_INTOPT(ip_qos_bulk);
1.235     dtucker  1923:        M_CP_INTOPT(rekey_limit);
                   1924:        M_CP_INTOPT(rekey_interval);
1.289     djm      1925:
                   1926:        /*
                   1927:         * The bind_mask is a mode_t that may be unsigned, so we can't use
                   1928:         * M_CP_INTOPT - it does a signed comparison that causes compiler
                   1929:         * warnings.
                   1930:         */
1.290     dtucker  1931:        if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
1.289     djm      1932:                dst->fwd_opts.streamlocal_bind_mask =
                   1933:                    src->fwd_opts.streamlocal_bind_mask;
                   1934:        }
1.247     djm      1935:
                   1936:        /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
                   1937: #define M_CP_STROPT(n) do {\
                   1938:        if (src->n != NULL && dst->n != src->n) { \
                   1939:                free(dst->n); \
                   1940:                dst->n = src->n; \
                   1941:        } \
                   1942: } while(0)
                   1943: #define M_CP_STRARRAYOPT(n, num_n) do {\
                   1944:        if (src->num_n != 0) { \
                   1945:                for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
                   1946:                        dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
                   1947:        } \
                   1948: } while(0)
1.168     dtucker  1949:
1.218     djm      1950:        /* See comment in servconf.h */
                   1951:        COPY_MATCH_STRING_OPTS();
1.282     djm      1952:
                   1953:        /* Arguments that accept '+...' need to be expanded */
                   1954:        assemble_algorithms(dst);
1.216     djm      1955:
1.217     dtucker  1956:        /*
                   1957:         * The only things that should be below this point are string options
                   1958:         * which are only used after authentication.
                   1959:         */
1.168     dtucker  1960:        if (preauth)
                   1961:                return;
1.219     djm      1962:
1.283     djm      1963:        /* These options may be "none" to clear a global setting */
1.168     dtucker  1964:        M_CP_STROPT(adm_forced_command);
1.283     djm      1965:        if (option_clear_or_none(dst->adm_forced_command)) {
                   1966:                free(dst->adm_forced_command);
                   1967:                dst->adm_forced_command = NULL;
                   1968:        }
1.176     djm      1969:        M_CP_STROPT(chroot_directory);
1.283     djm      1970:        if (option_clear_or_none(dst->chroot_directory)) {
                   1971:                free(dst->chroot_directory);
                   1972:                dst->chroot_directory = NULL;
                   1973:        }
1.153     dtucker  1974: }
1.168     dtucker  1975:
                   1976: #undef M_CP_INTOPT
                   1977: #undef M_CP_STROPT
1.219     djm      1978: #undef M_CP_STRARRAYOPT
1.153     dtucker  1979:
                   1980: void
                   1981: parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1.226     dtucker  1982:     struct connection_info *connectinfo)
1.134     djm      1983: {
1.153     dtucker  1984:        int active, linenum, bad_options = 0;
1.136     dtucker  1985:        char *cp, *obuf, *cbuf;
1.134     djm      1986:
                   1987:        debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
                   1988:
1.287     djm      1989:        if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
                   1990:                fatal("%s: sshbuf_dup_string failed", __func__);
1.226     dtucker  1991:        active = connectinfo ? 0 : 1;
1.137     dtucker  1992:        linenum = 1;
1.140     deraadt  1993:        while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134     djm      1994:                if (process_server_config_line(options, cp, filename,
1.226     dtucker  1995:                    linenum++, &active, connectinfo) != 0)
1.94      markus   1996:                        bad_options++;
1.1       deraadt  1997:        }
1.239     djm      1998:        free(obuf);
1.78      stevesk  1999:        if (bad_options > 0)
                   2000:                fatal("%s: terminating, %d bad configuration options",
                   2001:                    filename, bad_options);
1.266     dtucker  2002:        process_queued_listen_addrs(options);
1.182     dtucker  2003: }
                   2004:
                   2005: static const char *
1.221     djm      2006: fmt_multistate_int(int val, const struct multistate *m)
                   2007: {
                   2008:        u_int i;
                   2009:
                   2010:        for (i = 0; m[i].key != NULL; i++) {
                   2011:                if (m[i].value == val)
                   2012:                        return m[i].key;
                   2013:        }
                   2014:        return "UNKNOWN";
                   2015: }
                   2016:
                   2017: static const char *
1.182     dtucker  2018: fmt_intarg(ServerOpCodes code, int val)
                   2019: {
1.221     djm      2020:        if (val == -1)
                   2021:                return "unset";
                   2022:        switch (code) {
                   2023:        case sAddressFamily:
                   2024:                return fmt_multistate_int(val, multistate_addressfamily);
                   2025:        case sPermitRootLogin:
                   2026:                return fmt_multistate_int(val, multistate_permitrootlogin);
                   2027:        case sGatewayPorts:
                   2028:                return fmt_multistate_int(val, multistate_gatewayports);
                   2029:        case sCompression:
                   2030:                return fmt_multistate_int(val, multistate_compression);
1.222     djm      2031:        case sUsePrivilegeSeparation:
                   2032:                return fmt_multistate_int(val, multistate_privsep);
1.233     djm      2033:        case sAllowTcpForwarding:
                   2034:                return fmt_multistate_int(val, multistate_tcpfwd);
1.251     millert  2035:        case sAllowStreamLocalForwarding:
                   2036:                return fmt_multistate_int(val, multistate_tcpfwd);
1.256     djm      2037:        case sFingerprintHash:
                   2038:                return ssh_digest_alg_name(val);
1.221     djm      2039:        default:
                   2040:                switch (val) {
                   2041:                case 0:
                   2042:                        return "no";
                   2043:                case 1:
                   2044:                        return "yes";
                   2045:                default:
                   2046:                        return "UNKNOWN";
                   2047:                }
1.182     dtucker  2048:        }
                   2049: }
                   2050:
                   2051: static const char *
                   2052: lookup_opcode_name(ServerOpCodes code)
                   2053: {
                   2054:        u_int i;
                   2055:
                   2056:        for (i = 0; keywords[i].name != NULL; i++)
                   2057:                if (keywords[i].opcode == code)
                   2058:                        return(keywords[i].name);
                   2059:        return "UNKNOWN";
                   2060: }
                   2061:
                   2062: static void
                   2063: dump_cfg_int(ServerOpCodes code, int val)
                   2064: {
                   2065:        printf("%s %d\n", lookup_opcode_name(code), val);
                   2066: }
                   2067:
                   2068: static void
1.263     dtucker  2069: dump_cfg_oct(ServerOpCodes code, int val)
                   2070: {
                   2071:        printf("%s 0%o\n", lookup_opcode_name(code), val);
                   2072: }
                   2073:
                   2074: static void
1.182     dtucker  2075: dump_cfg_fmtint(ServerOpCodes code, int val)
                   2076: {
                   2077:        printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
                   2078: }
                   2079:
                   2080: static void
                   2081: dump_cfg_string(ServerOpCodes code, const char *val)
                   2082: {
                   2083:        if (val == NULL)
                   2084:                return;
1.257     djm      2085:        printf("%s %s\n", lookup_opcode_name(code),
                   2086:            val == NULL ? "none" : val);
1.182     dtucker  2087: }
                   2088:
                   2089: static void
                   2090: dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
                   2091: {
                   2092:        u_int i;
                   2093:
                   2094:        for (i = 0; i < count; i++)
1.219     djm      2095:                printf("%s %s\n", lookup_opcode_name(code), vals[i]);
                   2096: }
                   2097:
                   2098: static void
                   2099: dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
                   2100: {
                   2101:        u_int i;
                   2102:
1.291     djm      2103:        if (count <= 0 && code != sAuthenticationMethods)
1.261     dtucker  2104:                return;
1.219     djm      2105:        printf("%s", lookup_opcode_name(code));
                   2106:        for (i = 0; i < count; i++)
                   2107:                printf(" %s",  vals[i]);
1.291     djm      2108:        if (code == sAuthenticationMethods && count == 0)
                   2109:                printf(" any");
1.219     djm      2110:        printf("\n");
1.182     dtucker  2111: }
                   2112:
                   2113: void
                   2114: dump_config(ServerOptions *o)
                   2115: {
                   2116:        u_int i;
                   2117:        int ret;
                   2118:        struct addrinfo *ai;
                   2119:        char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1.263     dtucker  2120:        char *laddr1 = xstrdup(""), *laddr2 = NULL;
1.182     dtucker  2121:
                   2122:        /* these are usually at the top of the config */
                   2123:        for (i = 0; i < o->num_ports; i++)
                   2124:                printf("port %d\n", o->ports[i]);
                   2125:        dump_cfg_fmtint(sAddressFamily, o->address_family);
                   2126:
1.263     dtucker  2127:        /*
                   2128:         * ListenAddress must be after Port.  add_one_listen_addr pushes
                   2129:         * addresses onto a stack, so to maintain ordering we need to
                   2130:         * print these in reverse order.
                   2131:         */
1.182     dtucker  2132:        for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
                   2133:                if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
                   2134:                    sizeof(addr), port, sizeof(port),
                   2135:                    NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
                   2136:                        error("getnameinfo failed: %.100s",
                   2137:                            (ret != EAI_SYSTEM) ? gai_strerror(ret) :
                   2138:                            strerror(errno));
                   2139:                } else {
1.263     dtucker  2140:                        laddr2 = laddr1;
1.182     dtucker  2141:                        if (ai->ai_family == AF_INET6)
1.263     dtucker  2142:                                xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
                   2143:                                    addr, port, laddr2);
1.182     dtucker  2144:                        else
1.263     dtucker  2145:                                xasprintf(&laddr1, "listenaddress %s:%s\n%s",
                   2146:                                    addr, port, laddr2);
                   2147:                        free(laddr2);
1.182     dtucker  2148:                }
                   2149:        }
1.263     dtucker  2150:        printf("%s", laddr1);
                   2151:        free(laddr1);
1.182     dtucker  2152:
                   2153:        /* integer arguments */
                   2154:        dump_cfg_int(sLoginGraceTime, o->login_grace_time);
                   2155:        dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
                   2156:        dump_cfg_int(sMaxAuthTries, o->max_authtries);
1.189     djm      2157:        dump_cfg_int(sMaxSessions, o->max_sessions);
1.182     dtucker  2158:        dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
                   2159:        dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1.263     dtucker  2160:        dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
1.182     dtucker  2161:
                   2162:        /* formatted integer arguments */
                   2163:        dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
                   2164:        dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
                   2165:        dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
                   2166:        dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
                   2167:        dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
                   2168:            o->hostbased_uses_name_from_packet_only);
                   2169:        dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
1.187     djm      2170: #ifdef KRB5
1.182     dtucker  2171:        dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
                   2172:        dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
                   2173:        dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
                   2174:        dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
1.187     djm      2175: #endif
                   2176: #ifdef GSSAPI
1.182     dtucker  2177:        dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
                   2178:        dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
1.187     djm      2179: #endif
1.182     dtucker  2180:        dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
                   2181:        dump_cfg_fmtint(sKbdInteractiveAuthentication,
                   2182:            o->kbd_interactive_authentication);
                   2183:        dump_cfg_fmtint(sChallengeResponseAuthentication,
                   2184:            o->challenge_response_authentication);
                   2185:        dump_cfg_fmtint(sPrintMotd, o->print_motd);
                   2186:        dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
                   2187:        dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
                   2188:        dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1.244     djm      2189:        dump_cfg_fmtint(sPermitTTY, o->permit_tty);
1.250     djm      2190:        dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
1.182     dtucker  2191:        dump_cfg_fmtint(sStrictModes, o->strict_modes);
                   2192:        dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
                   2193:        dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
                   2194:        dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
                   2195:        dump_cfg_fmtint(sCompression, o->compression);
1.251     millert  2196:        dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
1.182     dtucker  2197:        dump_cfg_fmtint(sUseDNS, o->use_dns);
                   2198:        dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1.261     dtucker  2199:        dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
1.251     millert  2200:        dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
1.288     djm      2201:        dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
1.182     dtucker  2202:        dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1.256     djm      2203:        dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
1.182     dtucker  2204:
                   2205:        /* string arguments */
                   2206:        dump_cfg_string(sPidFile, o->pid_file);
                   2207:        dump_cfg_string(sXAuthLocation, o->xauth_location);
1.252     djm      2208:        dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
                   2209:        dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
1.182     dtucker  2210:        dump_cfg_string(sBanner, o->banner);
                   2211:        dump_cfg_string(sForceCommand, o->adm_forced_command);
1.201     dtucker  2212:        dump_cfg_string(sChrootDirectory, o->chroot_directory);
1.204     djm      2213:        dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
                   2214:        dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
1.208     djm      2215:        dump_cfg_string(sAuthorizedPrincipalsFile,
                   2216:            o->authorized_principals_file);
1.261     dtucker  2217:        dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
                   2218:            ? "none" : o->version_addendum);
1.231     djm      2219:        dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
                   2220:        dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
1.270     djm      2221:        dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
                   2222:        dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
1.240     markus   2223:        dump_cfg_string(sHostKeyAgent, o->host_key_agent);
1.252     djm      2224:        dump_cfg_string(sKexAlgorithms,
1.253     djm      2225:            o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
1.258     djm      2226:        dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
                   2227:            o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
1.276     markus   2228:        dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
                   2229:            o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
1.258     djm      2230:        dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
                   2231:            o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
1.182     dtucker  2232:
                   2233:        /* string arguments requiring a lookup */
                   2234:        dump_cfg_string(sLogLevel, log_level_name(o->log_level));
                   2235:        dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
                   2236:
                   2237:        /* string array arguments */
1.219     djm      2238:        dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
                   2239:            o->authorized_keys_files);
1.182     dtucker  2240:        dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
                   2241:             o->host_key_files);
1.261     dtucker  2242:        dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
1.203     djm      2243:             o->host_cert_files);
1.182     dtucker  2244:        dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
                   2245:        dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
                   2246:        dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
                   2247:        dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
                   2248:        dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1.232     djm      2249:        dump_cfg_strarray_oneline(sAuthenticationMethods,
                   2250:            o->num_auth_methods, o->auth_methods);
1.182     dtucker  2251:
                   2252:        /* other arguments */
                   2253:        for (i = 0; i < o->num_subsystems; i++)
                   2254:                printf("subsystem %s %s\n", o->subsystem_name[i],
                   2255:                    o->subsystem_args[i]);
                   2256:
                   2257:        printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
                   2258:            o->max_startups_rate, o->max_startups);
                   2259:
                   2260:        for (i = 0; tunmode_desc[i].val != -1; i++)
                   2261:                if (tunmode_desc[i].val == o->permit_tun) {
                   2262:                        s = tunmode_desc[i].text;
                   2263:                        break;
                   2264:                }
                   2265:        dump_cfg_string(sPermitTunnel, s);
1.213     djm      2266:
1.214     stevesk  2267:        printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
                   2268:        printf("%s\n", iptos2str(o->ip_qos_bulk));
1.235     dtucker  2269:
1.284     dtucker  2270:        printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
1.241     djm      2271:            o->rekey_interval);
1.182     dtucker  2272:
                   2273:        channel_print_adm_permitted_opens();
1.1       deraadt  2274: }