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

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