[BACK]Return to readconf.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/readconf.c, Revision 1.276

1.276   ! djm         1: /* $OpenBSD: readconf.c,v 1.275 2017/04/30 23:18:22 djm Exp $ */
1.1       deraadt     2: /*
1.18      deraadt     3:  * Author: Tatu Ylonen <ylo@cs.hut.fi>
                      4:  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      5:  *                    All rights reserved
                      6:  * Functions for reading the configuration files.
1.26      markus      7:  *
1.46      deraadt     8:  * As far as I am concerned, the code I have written for this software
                      9:  * can be used freely for any purpose.  Any derived versions of this
                     10:  * software must be clearly marked as such, and if the derived work is
                     11:  * incompatible with the protocol description in the RFC file, it must be
                     12:  * called by a name other than "ssh" or "Secure Shell".
1.18      deraadt    13:  */
1.1       deraadt    14:
1.147     stevesk    15: #include <sys/types.h>
                     16: #include <sys/stat.h>
1.152     stevesk    17: #include <sys/socket.h>
1.206     djm        18: #include <sys/wait.h>
1.220     millert    19: #include <sys/un.h>
1.152     stevesk    20:
                     21: #include <netinet/in.h>
1.190     djm        22: #include <netinet/ip.h>
1.148     stevesk    23:
                     24: #include <ctype.h>
1.154     stevesk    25: #include <errno.h>
1.206     djm        26: #include <fcntl.h>
1.252     djm        27: #include <glob.h>
1.155     stevesk    28: #include <netdb.h>
1.206     djm        29: #include <paths.h>
                     30: #include <pwd.h>
1.159     deraadt    31: #include <signal.h>
1.158     stevesk    32: #include <stdio.h>
1.157     stevesk    33: #include <string.h>
1.156     stevesk    34: #include <unistd.h>
1.228     deraadt    35: #include <limits.h>
1.200     dtucker    36: #include <util.h>
1.221     djm        37: #include <vis.h>
1.1       deraadt    38:
1.159     deraadt    39: #include "xmalloc.h"
1.1       deraadt    40: #include "ssh.h"
1.25      markus     41: #include "compat.h"
1.58      markus     42: #include "cipher.h"
1.55      markus     43: #include "pathnames.h"
1.58      markus     44: #include "log.h"
1.227     djm        45: #include "sshkey.h"
1.220     millert    46: #include "misc.h"
1.58      markus     47: #include "readconf.h"
                     48: #include "match.h"
1.62      markus     49: #include "kex.h"
                     50: #include "mac.h"
1.206     djm        51: #include "uidswap.h"
1.221     djm        52: #include "myproposal.h"
1.224     djm        53: #include "digest.h"
1.1       deraadt    54:
                     55: /* Format of the configuration file:
                     56:
                     57:    # Configuration data is parsed as follows:
                     58:    #  1. command line options
                     59:    #  2. user-specific file
                     60:    #  3. system-wide file
                     61:    # Any configuration value is only changed the first time it is set.
                     62:    # Thus, host-specific definitions should be at the beginning of the
                     63:    # configuration file, and defaults at the end.
                     64:
                     65:    # Host-specific declarations.  These may override anything above.  A single
                     66:    # host may match multiple declarations; these are processed in the order
                     67:    # that they are given in.
                     68:
                     69:    Host *.ngs.fi ngs.fi
1.96      markus     70:      User foo
1.1       deraadt    71:
                     72:    Host fake.com
                     73:      HostName another.host.name.real.org
                     74:      User blaah
                     75:      Port 34289
                     76:      ForwardX11 no
                     77:      ForwardAgent no
                     78:
                     79:    Host books.com
                     80:      RemoteForward 9999 shadows.cs.hut.fi:9999
1.266     djm        81:      Ciphers 3des-cbc
1.1       deraadt    82:
                     83:    Host fascist.blob.com
                     84:      Port 23123
                     85:      User tylonen
                     86:      PasswordAuthentication no
                     87:
                     88:    Host puukko.hut.fi
                     89:      User t35124p
                     90:      ProxyCommand ssh-proxy %h %p
                     91:
                     92:    Host *.fr
1.96      markus     93:      PublicKeyAuthentication no
1.1       deraadt    94:
                     95:    Host *.su
1.266     djm        96:      Ciphers aes128-ctr
1.1       deraadt    97:      PasswordAuthentication no
                     98:
1.144     reyk       99:    Host vpn.fake.com
                    100:      Tunnel yes
                    101:      TunnelDevice 3
                    102:
1.1       deraadt   103:    # Defaults for various options
                    104:    Host *
                    105:      ForwardAgent no
1.50      markus    106:      ForwardX11 no
1.1       deraadt   107:      PasswordAuthentication yes
                    108:      RSAAuthentication yes
                    109:      RhostsRSAAuthentication yes
                    110:      StrictHostKeyChecking yes
1.126     markus    111:      TcpKeepAlive no
1.1       deraadt   112:      IdentityFile ~/.ssh/identity
                    113:      Port 22
                    114:      EscapeChar ~
                    115:
                    116: */
                    117:
1.252     djm       118: static int read_config_file_depth(const char *filename, struct passwd *pw,
                    119:     const char *host, const char *original_host, Options *options,
                    120:     int flags, int *activep, int depth);
                    121: static int process_config_line_depth(Options *options, struct passwd *pw,
                    122:     const char *host, const char *original_host, char *line,
                    123:     const char *filename, int linenum, int *activep, int flags, int depth);
                    124:
1.1       deraadt   125: /* Keyword tokens. */
                    126:
1.17      markus    127: typedef enum {
                    128:        oBadOption,
1.252     djm       129:        oHost, oMatch, oInclude,
1.186     djm       130:        oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
                    131:        oGatewayPorts, oExitOnForwardFailure,
1.100     deraadt   132:        oPasswordAuthentication, oRSAAuthentication,
1.59      markus    133:        oChallengeResponseAuthentication, oXAuthLocation,
1.17      markus    134:        oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
1.253     markus    135:        oCertificateFile, oAddKeysToAgent, oIdentityAgent,
1.206     djm       136:        oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
1.17      markus    137:        oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
                    138:        oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
1.126     markus    139:        oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
1.273     djm       140:        oUsePrivilegedPort, oLogFacility, oLogLevel, oCiphers, oMacs,
1.221     djm       141:        oPubkeyAuthentication,
1.67      markus    142:        oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
1.76      markus    143:        oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
1.183     markus    144:        oHostKeyAlgorithms, oBindAddress, oPKCS11Provider,
1.96      markus    145:        oClearAllForwardings, oNoHostAuthenticationForLocalhost,
1.111     djm       146:        oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
1.118     markus    147:        oAddressFamily, oGssAuthentication, oGssDelegateCreds,
1.128     markus    148:        oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
1.187     djm       149:        oSendEnv, oControlPath, oControlMaster, oControlPersist,
                    150:        oHashKnownHosts,
1.144     reyk      151:        oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
1.248     markus    152:        oVisualHostKey,
1.205     djm       153:        oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,
1.209     djm       154:        oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
                    155:        oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,
1.223     djm       156:        oStreamLocalBindMask, oStreamLocalBindUnlink, oRevokedHostKeys,
1.230     djm       157:        oFingerprintHash, oUpdateHostkeys, oHostbasedKeyTypes,
1.257     djm       158:        oPubkeyAcceptedKeyTypes, oProxyJump,
1.273     djm       159:        oIgnore, oIgnoredUnknownOption, oDeprecated, oUnsupported
1.1       deraadt   160: } OpCodes;
                    161:
                    162: /* Textual representations of the tokens. */
                    163:
1.17      markus    164: static struct {
                    165:        const char *name;
                    166:        OpCodes opcode;
                    167: } keywords[] = {
1.266     djm       168:        /* Deprecated options */
1.273     djm       169:        { "protocol", oIgnore }, /* NB. silently ignored */
1.274     djm       170:        { "cipher", oDeprecated },
1.266     djm       171:        { "fallbacktorsh", oDeprecated },
                    172:        { "globalknownhostsfile2", oDeprecated },
                    173:        { "rhostsauthentication", oDeprecated },
                    174:        { "userknownhostsfile2", oDeprecated },
                    175:        { "useroaming", oDeprecated },
                    176:        { "usersh", oDeprecated },
                    177:
                    178:        /* Unsupported options */
                    179:        { "afstokenpassing", oUnsupported },
                    180:        { "kerberosauthentication", oUnsupported },
                    181:        { "kerberostgtpassing", oUnsupported },
                    182:
                    183:        /* Sometimes-unsupported options */
                    184: #if defined(GSSAPI)
                    185:        { "gssapiauthentication", oGssAuthentication },
                    186:        { "gssapidelegatecredentials", oGssDelegateCreds },
                    187: # else
                    188:        { "gssapiauthentication", oUnsupported },
                    189:        { "gssapidelegatecredentials", oUnsupported },
                    190: #endif
                    191: #ifdef ENABLE_PKCS11
                    192:        { "smartcarddevice", oPKCS11Provider },
                    193:        { "pkcs11provider", oPKCS11Provider },
                    194: # else
                    195:        { "smartcarddevice", oUnsupported },
                    196:        { "pkcs11provider", oUnsupported },
                    197: #endif
                    198:        { "rsaauthentication", oUnsupported },
                    199:        { "rhostsrsaauthentication", oUnsupported },
                    200:        { "compressionlevel", oUnsupported },
                    201:
1.17      markus    202:        { "forwardagent", oForwardAgent },
                    203:        { "forwardx11", oForwardX11 },
1.123     markus    204:        { "forwardx11trusted", oForwardX11Trusted },
1.186     djm       205:        { "forwardx11timeout", oForwardX11Timeout },
1.153     markus    206:        { "exitonforwardfailure", oExitOnForwardFailure },
1.34      markus    207:        { "xauthlocation", oXAuthLocation },
1.17      markus    208:        { "gatewayports", oGatewayPorts },
                    209:        { "useprivilegedport", oUsePrivilegedPort },
                    210:        { "passwordauthentication", oPasswordAuthentication },
1.48      markus    211:        { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
                    212:        { "kbdinteractivedevices", oKbdInteractiveDevices },
1.50      markus    213:        { "pubkeyauthentication", oPubkeyAuthentication },
1.59      markus    214:        { "dsaauthentication", oPubkeyAuthentication },             /* alias */
1.73      markus    215:        { "hostbasedauthentication", oHostbasedAuthentication },
1.59      markus    216:        { "challengeresponseauthentication", oChallengeResponseAuthentication },
                    217:        { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
                    218:        { "tisauthentication", oChallengeResponseAuthentication },  /* alias */
1.17      markus    219:        { "identityfile", oIdentityFile },
1.174     stevesk   220:        { "identityfile2", oIdentityFile },                     /* obsolete */
1.128     markus    221:        { "identitiesonly", oIdentitiesOnly },
1.241     djm       222:        { "certificatefile", oCertificateFile },
1.246     jcs       223:        { "addkeystoagent", oAddKeysToAgent },
1.253     markus    224:        { "identityagent", oIdentityAgent },
1.17      markus    225:        { "hostname", oHostName },
1.52      markus    226:        { "hostkeyalias", oHostKeyAlias },
1.17      markus    227:        { "proxycommand", oProxyCommand },
                    228:        { "port", oPort },
1.25      markus    229:        { "ciphers", oCiphers },
1.62      markus    230:        { "macs", oMacs },
1.17      markus    231:        { "remoteforward", oRemoteForward },
                    232:        { "localforward", oLocalForward },
                    233:        { "user", oUser },
                    234:        { "host", oHost },
1.206     djm       235:        { "match", oMatch },
1.17      markus    236:        { "escapechar", oEscapeChar },
                    237:        { "globalknownhostsfile", oGlobalKnownHostsFile },
1.174     stevesk   238:        { "userknownhostsfile", oUserKnownHostsFile },
1.17      markus    239:        { "connectionattempts", oConnectionAttempts },
                    240:        { "batchmode", oBatchMode },
                    241:        { "checkhostip", oCheckHostIP },
                    242:        { "stricthostkeychecking", oStrictHostKeyChecking },
                    243:        { "compression", oCompression },
1.126     markus    244:        { "tcpkeepalive", oTCPKeepAlive },
                    245:        { "keepalive", oTCPKeepAlive },                         /* obsolete */
1.17      markus    246:        { "numberofpasswordprompts", oNumberOfPasswordPrompts },
1.271     dtucker   247:        { "syslogfacility", oLogFacility },
1.17      markus    248:        { "loglevel", oLogLevel },
1.71      markus    249:        { "dynamicforward", oDynamicForward },
1.67      markus    250:        { "preferredauthentications", oPreferredAuthentications },
1.76      markus    251:        { "hostkeyalgorithms", oHostKeyAlgorithms },
1.77      markus    252:        { "bindaddress", oBindAddress },
1.93      deraadt   253:        { "clearallforwardings", oClearAllForwardings },
1.101     markus    254:        { "enablesshkeysign", oEnableSSHKeysign },
1.107     jakob     255:        { "verifyhostkeydns", oVerifyHostKeyDNS },
1.93      deraadt   256:        { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
1.105     markus    257:        { "rekeylimit", oRekeyLimit },
1.111     djm       258:        { "connecttimeout", oConnectTimeout },
1.112     djm       259:        { "addressfamily", oAddressFamily },
1.127     markus    260:        { "serveraliveinterval", oServerAliveInterval },
                    261:        { "serveralivecountmax", oServerAliveCountMax },
1.130     djm       262:        { "sendenv", oSendEnv },
1.132     djm       263:        { "controlpath", oControlPath },
                    264:        { "controlmaster", oControlMaster },
1.187     djm       265:        { "controlpersist", oControlPersist },
1.136     djm       266:        { "hashknownhosts", oHashKnownHosts },
1.252     djm       267:        { "include", oInclude },
1.144     reyk      268:        { "tunnel", oTunnel },
                    269:        { "tunneldevice", oTunnelDevice },
                    270:        { "localcommand", oLocalCommand },
                    271:        { "permitlocalcommand", oPermitLocalCommand },
1.167     grunk     272:        { "visualhostkey", oVisualHostKey },
1.189     djm       273:        { "kexalgorithms", oKexAlgorithms },
1.190     djm       274:        { "ipqos", oIPQoS },
1.192     djm       275:        { "requesttty", oRequestTTY },
1.205     djm       276:        { "proxyusefdpass", oProxyUseFdpass },
1.208     djm       277:        { "canonicaldomains", oCanonicalDomains },
1.209     djm       278:        { "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
                    279:        { "canonicalizehostname", oCanonicalizeHostname },
                    280:        { "canonicalizemaxdots", oCanonicalizeMaxDots },
                    281:        { "canonicalizepermittedcnames", oCanonicalizePermittedCNAMEs },
1.220     millert   282:        { "streamlocalbindmask", oStreamLocalBindMask },
                    283:        { "streamlocalbindunlink", oStreamLocalBindUnlink },
1.223     djm       284:        { "revokedhostkeys", oRevokedHostKeys },
1.224     djm       285:        { "fingerprinthash", oFingerprintHash },
1.229     djm       286:        { "updatehostkeys", oUpdateHostkeys },
1.230     djm       287:        { "hostbasedkeytypes", oHostbasedKeyTypes },
1.238     markus    288:        { "pubkeyacceptedkeytypes", oPubkeyAcceptedKeyTypes },
1.199     djm       289:        { "ignoreunknown", oIgnoreUnknown },
1.257     djm       290:        { "proxyjump", oProxyJump },
1.171     djm       291:
1.92      stevesk   292:        { NULL, oBadOption }
1.13      markus    293: };
                    294:
1.19      markus    295: /*
                    296:  * Adds a local TCP/IP port forward to options.  Never returns if there is an
                    297:  * error.
                    298:  */
1.1       deraadt   299:
1.26      markus    300: void
1.220     millert   301: add_local_forward(Options *options, const struct Forward *newfwd)
1.1       deraadt   302: {
1.220     millert   303:        struct Forward *fwd;
1.17      markus    304:        extern uid_t original_real_uid;
1.251     djm       305:        int i;
1.185     djm       306:
1.262     jsg       307:        if (!bind_permitted(newfwd->listen_port, original_real_uid) &&
1.220     millert   308:            newfwd->listen_path == NULL)
1.64      millert   309:                fatal("Privileged ports can only be forwarded by root.");
1.251     djm       310:        /* Don't add duplicates */
                    311:        for (i = 0; i < options->num_local_forwards; i++) {
                    312:                if (forward_equals(newfwd, options->local_forwards + i))
                    313:                        return;
                    314:        }
1.234     deraadt   315:        options->local_forwards = xreallocarray(options->local_forwards,
1.185     djm       316:            options->num_local_forwards + 1,
                    317:            sizeof(*options->local_forwards));
1.17      markus    318:        fwd = &options->local_forwards[options->num_local_forwards++];
1.135     djm       319:
1.172     stevesk   320:        fwd->listen_host = newfwd->listen_host;
1.135     djm       321:        fwd->listen_port = newfwd->listen_port;
1.220     millert   322:        fwd->listen_path = newfwd->listen_path;
1.172     stevesk   323:        fwd->connect_host = newfwd->connect_host;
1.135     djm       324:        fwd->connect_port = newfwd->connect_port;
1.220     millert   325:        fwd->connect_path = newfwd->connect_path;
1.1       deraadt   326: }
                    327:
1.19      markus    328: /*
                    329:  * Adds a remote TCP/IP port forward to options.  Never returns if there is
                    330:  * an error.
                    331:  */
1.1       deraadt   332:
1.26      markus    333: void
1.220     millert   334: add_remote_forward(Options *options, const struct Forward *newfwd)
1.1       deraadt   335: {
1.220     millert   336:        struct Forward *fwd;
1.251     djm       337:        int i;
1.185     djm       338:
1.251     djm       339:        /* Don't add duplicates */
                    340:        for (i = 0; i < options->num_remote_forwards; i++) {
                    341:                if (forward_equals(newfwd, options->remote_forwards + i))
                    342:                        return;
                    343:        }
1.234     deraadt   344:        options->remote_forwards = xreallocarray(options->remote_forwards,
1.185     djm       345:            options->num_remote_forwards + 1,
                    346:            sizeof(*options->remote_forwards));
1.17      markus    347:        fwd = &options->remote_forwards[options->num_remote_forwards++];
1.135     djm       348:
1.172     stevesk   349:        fwd->listen_host = newfwd->listen_host;
1.135     djm       350:        fwd->listen_port = newfwd->listen_port;
1.220     millert   351:        fwd->listen_path = newfwd->listen_path;
1.172     stevesk   352:        fwd->connect_host = newfwd->connect_host;
1.135     djm       353:        fwd->connect_port = newfwd->connect_port;
1.220     millert   354:        fwd->connect_path = newfwd->connect_path;
1.194     markus    355:        fwd->handle = newfwd->handle;
1.184     markus    356:        fwd->allocated_port = 0;
1.1       deraadt   357: }
                    358:
1.90      stevesk   359: static void
                    360: clear_forwardings(Options *options)
                    361: {
                    362:        int i;
                    363:
1.135     djm       364:        for (i = 0; i < options->num_local_forwards; i++) {
1.202     djm       365:                free(options->local_forwards[i].listen_host);
1.220     millert   366:                free(options->local_forwards[i].listen_path);
1.202     djm       367:                free(options->local_forwards[i].connect_host);
1.220     millert   368:                free(options->local_forwards[i].connect_path);
1.135     djm       369:        }
1.185     djm       370:        if (options->num_local_forwards > 0) {
1.202     djm       371:                free(options->local_forwards);
1.185     djm       372:                options->local_forwards = NULL;
                    373:        }
1.90      stevesk   374:        options->num_local_forwards = 0;
1.135     djm       375:        for (i = 0; i < options->num_remote_forwards; i++) {
1.202     djm       376:                free(options->remote_forwards[i].listen_host);
1.220     millert   377:                free(options->remote_forwards[i].listen_path);
1.202     djm       378:                free(options->remote_forwards[i].connect_host);
1.220     millert   379:                free(options->remote_forwards[i].connect_path);
1.135     djm       380:        }
1.185     djm       381:        if (options->num_remote_forwards > 0) {
1.202     djm       382:                free(options->remote_forwards);
1.185     djm       383:                options->remote_forwards = NULL;
                    384:        }
1.90      stevesk   385:        options->num_remote_forwards = 0;
1.145     reyk      386:        options->tun_open = SSH_TUNMODE_NO;
1.90      stevesk   387: }
                    388:
1.195     dtucker   389: void
1.241     djm       390: add_certificate_file(Options *options, const char *path, int userprovided)
                    391: {
                    392:        int i;
                    393:
                    394:        if (options->num_certificate_files >= SSH_MAX_CERTIFICATE_FILES)
                    395:                fatal("Too many certificate files specified (max %d)",
                    396:                    SSH_MAX_CERTIFICATE_FILES);
                    397:
                    398:        /* Avoid registering duplicates */
                    399:        for (i = 0; i < options->num_certificate_files; i++) {
                    400:                if (options->certificate_file_userprovided[i] == userprovided &&
                    401:                    strcmp(options->certificate_files[i], path) == 0) {
                    402:                        debug2("%s: ignoring duplicate key %s", __func__, path);
                    403:                        return;
                    404:                }
                    405:        }
                    406:
                    407:        options->certificate_file_userprovided[options->num_certificate_files] =
                    408:            userprovided;
                    409:        options->certificate_files[options->num_certificate_files++] =
                    410:            xstrdup(path);
                    411: }
                    412:
                    413: void
1.195     dtucker   414: add_identity_file(Options *options, const char *dir, const char *filename,
                    415:     int userprovided)
                    416: {
                    417:        char *path;
1.219     djm       418:        int i;
1.195     dtucker   419:
                    420:        if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
                    421:                fatal("Too many identity files specified (max %d)",
                    422:                    SSH_MAX_IDENTITY_FILES);
                    423:
                    424:        if (dir == NULL) /* no dir, filename is absolute */
                    425:                path = xstrdup(filename);
1.276   ! djm       426:        else if (xasprintf(&path, "%s%s", dir, filename) >= PATH_MAX)
        !           427:                fatal("Identity file path %s too long", path);
1.219     djm       428:
                    429:        /* Avoid registering duplicates */
                    430:        for (i = 0; i < options->num_identity_files; i++) {
                    431:                if (options->identity_file_userprovided[i] == userprovided &&
                    432:                    strcmp(options->identity_files[i], path) == 0) {
                    433:                        debug2("%s: ignoring duplicate key %s", __func__, path);
                    434:                        free(path);
                    435:                        return;
                    436:                }
                    437:        }
1.195     dtucker   438:
                    439:        options->identity_file_userprovided[options->num_identity_files] =
                    440:            userprovided;
                    441:        options->identity_files[options->num_identity_files++] = path;
                    442: }
                    443:
1.206     djm       444: int
                    445: default_ssh_port(void)
                    446: {
                    447:        static int port;
                    448:        struct servent *sp;
                    449:
                    450:        if (port == 0) {
                    451:                sp = getservbyname(SSH_SERVICE_NAME, "tcp");
                    452:                port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
                    453:        }
                    454:        return port;
                    455: }
                    456:
                    457: /*
                    458:  * Execute a command in a shell.
                    459:  * Return its exit status or -1 on abnormal exit.
                    460:  */
                    461: static int
                    462: execute_in_shell(const char *cmd)
                    463: {
1.243     dtucker   464:        char *shell;
1.206     djm       465:        pid_t pid;
                    466:        int devnull, status;
                    467:        extern uid_t original_real_uid;
                    468:
                    469:        if ((shell = getenv("SHELL")) == NULL)
                    470:                shell = _PATH_BSHELL;
                    471:
                    472:        /* Need this to redirect subprocess stdin/out */
                    473:        if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1)
                    474:                fatal("open(/dev/null): %s", strerror(errno));
                    475:
                    476:        debug("Executing command: '%.500s'", cmd);
                    477:
                    478:        /* Fork and execute the command. */
                    479:        if ((pid = fork()) == 0) {
1.245     djm       480:                char *argv[4];
1.206     djm       481:
                    482:                /* Child.  Permanently give up superuser privileges. */
                    483:                permanently_drop_suid(original_real_uid);
                    484:
                    485:                /* Redirect child stdin and stdout. Leave stderr */
                    486:                if (dup2(devnull, STDIN_FILENO) == -1)
                    487:                        fatal("dup2: %s", strerror(errno));
                    488:                if (dup2(devnull, STDOUT_FILENO) == -1)
                    489:                        fatal("dup2: %s", strerror(errno));
                    490:                if (devnull > STDERR_FILENO)
                    491:                        close(devnull);
                    492:                closefrom(STDERR_FILENO + 1);
1.245     djm       493:
                    494:                argv[0] = shell;
                    495:                argv[1] = "-c";
                    496:                argv[2] = xstrdup(cmd);
                    497:                argv[3] = NULL;
1.206     djm       498:
                    499:                execv(argv[0], argv);
                    500:                error("Unable to execute '%.100s': %s", cmd, strerror(errno));
                    501:                /* Die with signal to make this error apparent to parent. */
                    502:                signal(SIGTERM, SIG_DFL);
                    503:                kill(getpid(), SIGTERM);
                    504:                _exit(1);
                    505:        }
                    506:        /* Parent. */
                    507:        if (pid < 0)
                    508:                fatal("%s: fork: %.100s", __func__, strerror(errno));
                    509:
                    510:        close(devnull);
                    511:
                    512:        while (waitpid(pid, &status, 0) == -1) {
                    513:                if (errno != EINTR && errno != EAGAIN)
                    514:                        fatal("%s: waitpid: %s", __func__, strerror(errno));
                    515:        }
                    516:        if (!WIFEXITED(status)) {
                    517:                error("command '%.100s' exited abnormally", cmd);
                    518:                return -1;
1.221     djm       519:        }
1.206     djm       520:        debug3("command returned status %d", WEXITSTATUS(status));
                    521:        return WEXITSTATUS(status);
                    522: }
                    523:
                    524: /*
                    525:  * Parse and execute a Match directive.
                    526:  */
                    527: static int
                    528: match_cfg_line(Options *options, char **condition, struct passwd *pw,
1.221     djm       529:     const char *host_arg, const char *original_host, int post_canon,
                    530:     const char *filename, int linenum)
1.206     djm       531: {
1.221     djm       532:        char *arg, *oattrib, *attrib, *cmd, *cp = *condition, *host, *criteria;
1.211     djm       533:        const char *ruser;
1.221     djm       534:        int r, port, this_result, result = 1, attributes = 0, negate;
1.206     djm       535:        char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
                    536:
                    537:        /*
                    538:         * Configuration is likely to be incomplete at this point so we
                    539:         * must be prepared to use default values.
                    540:         */
                    541:        port = options->port <= 0 ? default_ssh_port() : options->port;
                    542:        ruser = options->user == NULL ? pw->pw_name : options->user;
1.250     djm       543:        if (post_canon) {
                    544:                host = xstrdup(options->hostname);
                    545:        } else if (options->hostname != NULL) {
1.212     djm       546:                /* NB. Please keep in sync with ssh.c:main() */
1.211     djm       547:                host = percent_expand(options->hostname,
                    548:                    "h", host_arg, (char *)NULL);
1.250     djm       549:        } else {
1.211     djm       550:                host = xstrdup(host_arg);
1.250     djm       551:        }
1.206     djm       552:
1.221     djm       553:        debug2("checking match for '%s' host %s originally %s",
                    554:            cp, host, original_host);
                    555:        while ((oattrib = attrib = strdelim(&cp)) && *attrib != '\0') {
                    556:                criteria = NULL;
                    557:                this_result = 1;
                    558:                if ((negate = attrib[0] == '!'))
                    559:                        attrib++;
                    560:                /* criteria "all" and "canonical" have no argument */
1.213     dtucker   561:                if (strcasecmp(attrib, "all") == 0) {
1.221     djm       562:                        if (attributes > 1 ||
1.213     dtucker   563:                            ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
1.221     djm       564:                                error("%.200s line %d: '%s' cannot be combined "
                    565:                                    "with other Match attributes",
                    566:                                    filename, linenum, oattrib);
1.213     dtucker   567:                                result = -1;
                    568:                                goto out;
                    569:                        }
1.221     djm       570:                        if (result)
                    571:                                result = negate ? 0 : 1;
1.213     dtucker   572:                        goto out;
                    573:                }
1.221     djm       574:                attributes++;
                    575:                if (strcasecmp(attrib, "canonical") == 0) {
                    576:                        r = !!post_canon;  /* force bitmask member to boolean */
                    577:                        if (r == (negate ? 1 : 0))
                    578:                                this_result = result = 0;
                    579:                        debug3("%.200s line %d: %smatched '%s'",
                    580:                            filename, linenum,
                    581:                            this_result ? "" : "not ", oattrib);
                    582:                        continue;
                    583:                }
                    584:                /* All other criteria require an argument */
1.206     djm       585:                if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
                    586:                        error("Missing Match criteria for %s", attrib);
1.211     djm       587:                        result = -1;
                    588:                        goto out;
1.206     djm       589:                }
                    590:                if (strcasecmp(attrib, "host") == 0) {
1.221     djm       591:                        criteria = xstrdup(host);
1.235     djm       592:                        r = match_hostname(host, arg) == 1;
1.221     djm       593:                        if (r == (negate ? 1 : 0))
                    594:                                this_result = result = 0;
1.206     djm       595:                } else if (strcasecmp(attrib, "originalhost") == 0) {
1.221     djm       596:                        criteria = xstrdup(original_host);
1.235     djm       597:                        r = match_hostname(original_host, arg) == 1;
1.221     djm       598:                        if (r == (negate ? 1 : 0))
                    599:                                this_result = result = 0;
1.206     djm       600:                } else if (strcasecmp(attrib, "user") == 0) {
1.221     djm       601:                        criteria = xstrdup(ruser);
1.235     djm       602:                        r = match_pattern_list(ruser, arg, 0) == 1;
1.221     djm       603:                        if (r == (negate ? 1 : 0))
                    604:                                this_result = result = 0;
1.206     djm       605:                } else if (strcasecmp(attrib, "localuser") == 0) {
1.221     djm       606:                        criteria = xstrdup(pw->pw_name);
1.235     djm       607:                        r = match_pattern_list(pw->pw_name, arg, 0) == 1;
1.221     djm       608:                        if (r == (negate ? 1 : 0))
                    609:                                this_result = result = 0;
1.210     djm       610:                } else if (strcasecmp(attrib, "exec") == 0) {
1.206     djm       611:                        if (gethostname(thishost, sizeof(thishost)) == -1)
                    612:                                fatal("gethostname: %s", strerror(errno));
                    613:                        strlcpy(shorthost, thishost, sizeof(shorthost));
                    614:                        shorthost[strcspn(thishost, ".")] = '\0';
                    615:                        snprintf(portstr, sizeof(portstr), "%d", port);
                    616:
                    617:                        cmd = percent_expand(arg,
                    618:                            "L", shorthost,
                    619:                            "d", pw->pw_dir,
                    620:                            "h", host,
                    621:                            "l", thishost,
1.221     djm       622:                            "n", original_host,
1.206     djm       623:                            "p", portstr,
                    624:                            "r", ruser,
                    625:                            "u", pw->pw_name,
                    626:                            (char *)NULL);
1.217     djm       627:                        if (result != 1) {
                    628:                                /* skip execution if prior predicate failed */
1.221     djm       629:                                debug3("%.200s line %d: skipped exec "
                    630:                                    "\"%.100s\"", filename, linenum, cmd);
                    631:                                free(cmd);
                    632:                                continue;
                    633:                        }
                    634:                        r = execute_in_shell(cmd);
                    635:                        if (r == -1) {
                    636:                                fatal("%.200s line %d: match exec "
                    637:                                    "'%.100s' error", filename,
                    638:                                    linenum, cmd);
1.217     djm       639:                        }
1.221     djm       640:                        criteria = xstrdup(cmd);
1.206     djm       641:                        free(cmd);
1.221     djm       642:                        /* Force exit status to boolean */
                    643:                        r = r == 0;
                    644:                        if (r == (negate ? 1 : 0))
                    645:                                this_result = result = 0;
1.206     djm       646:                } else {
                    647:                        error("Unsupported Match attribute %s", attrib);
1.211     djm       648:                        result = -1;
                    649:                        goto out;
1.206     djm       650:                }
1.221     djm       651:                debug3("%.200s line %d: %smatched '%s \"%.100s\"' ",
                    652:                    filename, linenum, this_result ? "": "not ",
                    653:                    oattrib, criteria);
                    654:                free(criteria);
1.213     dtucker   655:        }
                    656:        if (attributes == 0) {
                    657:                error("One or more attributes required for Match");
                    658:                result = -1;
                    659:                goto out;
1.206     djm       660:        }
1.221     djm       661:  out:
                    662:        if (result != -1)
                    663:                debug2("match %sfound", result ? "" : "not ");
1.206     djm       664:        *condition = cp;
1.211     djm       665:        free(host);
1.206     djm       666:        return result;
                    667: }
                    668:
1.208     djm       669: /* Check and prepare a domain name: removes trailing '.' and lowercases */
                    670: static void
                    671: valid_domain(char *name, const char *filename, int linenum)
                    672: {
                    673:        size_t i, l = strlen(name);
                    674:        u_char c, last = '\0';
                    675:
                    676:        if (l == 0)
                    677:                fatal("%s line %d: empty hostname suffix", filename, linenum);
                    678:        if (!isalpha((u_char)name[0]) && !isdigit((u_char)name[0]))
                    679:                fatal("%s line %d: hostname suffix \"%.100s\" "
                    680:                    "starts with invalid character", filename, linenum, name);
                    681:        for (i = 0; i < l; i++) {
                    682:                c = tolower((u_char)name[i]);
                    683:                name[i] = (char)c;
                    684:                if (last == '.' && c == '.')
                    685:                        fatal("%s line %d: hostname suffix \"%.100s\" contains "
                    686:                            "consecutive separators", filename, linenum, name);
                    687:                if (c != '.' && c != '-' && !isalnum(c) &&
                    688:                    c != '_') /* technically invalid, but common */
                    689:                        fatal("%s line %d: hostname suffix \"%.100s\" contains "
                    690:                            "invalid characters", filename, linenum, name);
                    691:                last = c;
                    692:        }
                    693:        if (name[l - 1] == '.')
                    694:                name[l - 1] = '\0';
                    695: }
                    696:
1.19      markus    697: /*
1.70      stevesk   698:  * Returns the number of the token pointed to by cp or oBadOption.
1.19      markus    699:  */
1.26      markus    700: static OpCodes
1.199     djm       701: parse_token(const char *cp, const char *filename, int linenum,
                    702:     const char *ignored_unknown)
1.1       deraadt   703: {
1.199     djm       704:        int i;
1.1       deraadt   705:
1.17      markus    706:        for (i = 0; keywords[i].name; i++)
1.199     djm       707:                if (strcmp(cp, keywords[i].name) == 0)
1.17      markus    708:                        return keywords[i].opcode;
1.235     djm       709:        if (ignored_unknown != NULL &&
                    710:            match_pattern_list(cp, ignored_unknown, 1) == 1)
1.199     djm       711:                return oIgnoredUnknownOption;
1.75      stevesk   712:        error("%s: line %d: Bad configuration option: %s",
                    713:            filename, linenum, cp);
1.17      markus    714:        return oBadOption;
1.1       deraadt   715: }
                    716:
1.207     djm       717: /* Multistate option parsing */
                    718: struct multistate {
                    719:        char *key;
                    720:        int value;
                    721: };
                    722: static const struct multistate multistate_flag[] = {
                    723:        { "true",                       1 },
                    724:        { "false",                      0 },
                    725:        { "yes",                        1 },
                    726:        { "no",                         0 },
                    727:        { NULL, -1 }
                    728: };
                    729: static const struct multistate multistate_yesnoask[] = {
                    730:        { "true",                       1 },
                    731:        { "false",                      0 },
                    732:        { "yes",                        1 },
                    733:        { "no",                         0 },
                    734:        { "ask",                        2 },
                    735:        { NULL, -1 }
                    736: };
1.246     jcs       737: static const struct multistate multistate_yesnoaskconfirm[] = {
                    738:        { "true",                       1 },
                    739:        { "false",                      0 },
                    740:        { "yes",                        1 },
                    741:        { "no",                         0 },
                    742:        { "ask",                        2 },
                    743:        { "confirm",                    3 },
                    744:        { NULL, -1 }
                    745: };
1.207     djm       746: static const struct multistate multistate_addressfamily[] = {
                    747:        { "inet",                       AF_INET },
                    748:        { "inet6",                      AF_INET6 },
                    749:        { "any",                        AF_UNSPEC },
                    750:        { NULL, -1 }
                    751: };
                    752: static const struct multistate multistate_controlmaster[] = {
                    753:        { "true",                       SSHCTL_MASTER_YES },
                    754:        { "yes",                        SSHCTL_MASTER_YES },
                    755:        { "false",                      SSHCTL_MASTER_NO },
                    756:        { "no",                         SSHCTL_MASTER_NO },
                    757:        { "auto",                       SSHCTL_MASTER_AUTO },
                    758:        { "ask",                        SSHCTL_MASTER_ASK },
                    759:        { "autoask",                    SSHCTL_MASTER_AUTO_ASK },
                    760:        { NULL, -1 }
                    761: };
                    762: static const struct multistate multistate_tunnel[] = {
                    763:        { "ethernet",                   SSH_TUNMODE_ETHERNET },
                    764:        { "point-to-point",             SSH_TUNMODE_POINTOPOINT },
                    765:        { "true",                       SSH_TUNMODE_DEFAULT },
                    766:        { "yes",                        SSH_TUNMODE_DEFAULT },
                    767:        { "false",                      SSH_TUNMODE_NO },
                    768:        { "no",                         SSH_TUNMODE_NO },
                    769:        { NULL, -1 }
                    770: };
                    771: static const struct multistate multistate_requesttty[] = {
                    772:        { "true",                       REQUEST_TTY_YES },
                    773:        { "yes",                        REQUEST_TTY_YES },
                    774:        { "false",                      REQUEST_TTY_NO },
                    775:        { "no",                         REQUEST_TTY_NO },
                    776:        { "force",                      REQUEST_TTY_FORCE },
                    777:        { "auto",                       REQUEST_TTY_AUTO },
                    778:        { NULL, -1 }
                    779: };
1.209     djm       780: static const struct multistate multistate_canonicalizehostname[] = {
1.208     djm       781:        { "true",                       SSH_CANONICALISE_YES },
                    782:        { "false",                      SSH_CANONICALISE_NO },
                    783:        { "yes",                        SSH_CANONICALISE_YES },
                    784:        { "no",                         SSH_CANONICALISE_NO },
                    785:        { "always",                     SSH_CANONICALISE_ALWAYS },
                    786:        { NULL, -1 }
                    787: };
1.207     djm       788:
1.19      markus    789: /*
                    790:  * Processes a single option line as used in the configuration files. This
                    791:  * only sets those values that have not already been set.
                    792:  */
1.14      markus    793: int
1.206     djm       794: process_config_line(Options *options, struct passwd *pw, const char *host,
1.221     djm       795:     const char *original_host, char *line, const char *filename,
                    796:     int linenum, int *activep, int flags)
1.1       deraadt   797: {
1.252     djm       798:        return process_config_line_depth(options, pw, host, original_host,
                    799:            line, filename, linenum, activep, flags, 0);
                    800: }
                    801:
                    802: #define WHITESPACE " \t\r\n"
                    803: static int
                    804: process_config_line_depth(Options *options, struct passwd *pw, const char *host,
                    805:     const char *original_host, char *line, const char *filename,
                    806:     int linenum, int *activep, int flags, int depth)
                    807: {
1.193     djm       808:        char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
                    809:        char **cpptr, fwdarg[256];
1.199     djm       810:        u_int i, *uintptr, max_entries = 0;
1.252     djm       811:        int r, oactive, negated, opcode, *intptr, value, value2, cmdline = 0;
1.164     dtucker   812:        LogLevel *log_level_ptr;
1.271     dtucker   813:        SyslogFacility *log_facility_ptr;
1.201     dtucker   814:        long long val64;
1.102     markus    815:        size_t len;
1.220     millert   816:        struct Forward fwd;
1.207     djm       817:        const struct multistate *multistate_ptr;
1.208     djm       818:        struct allowed_cname *cname;
1.252     djm       819:        glob_t gl;
1.106     djm       820:
1.206     djm       821:        if (activep == NULL) { /* We are processing a command line directive */
                    822:                cmdline = 1;
                    823:                activep = &cmdline;
                    824:        }
                    825:
1.267     djm       826:        /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1.233     djm       827:        if ((len = strlen(line)) == 0)
                    828:                return 0;
                    829:        for (len--; len > 0; len--) {
1.267     djm       830:                if (strchr(WHITESPACE "\f", line[len]) == NULL)
1.106     djm       831:                        break;
                    832:                line[len] = '\0';
                    833:        }
1.1       deraadt   834:
1.42      provos    835:        s = line;
                    836:        /* Get the keyword. (Each line is supposed to begin with a keyword). */
1.149     djm       837:        if ((keyword = strdelim(&s)) == NULL)
                    838:                return 0;
1.42      provos    839:        /* Ignore leading whitespace. */
                    840:        if (*keyword == '\0')
1.43      markus    841:                keyword = strdelim(&s);
1.56      deraadt   842:        if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
1.17      markus    843:                return 0;
1.199     djm       844:        /* Match lowercase keyword */
1.207     djm       845:        lowercase(keyword);
1.17      markus    846:
1.199     djm       847:        opcode = parse_token(keyword, filename, linenum,
                    848:            options->ignored_unknown);
1.17      markus    849:
                    850:        switch (opcode) {
                    851:        case oBadOption:
1.19      markus    852:                /* don't panic, but count bad options */
                    853:                return -1;
1.273     djm       854:        case oIgnore:
                    855:                return 0;
1.199     djm       856:        case oIgnoredUnknownOption:
                    857:                debug("%s line %d: Ignored unknown option \"%s\"",
                    858:                    filename, linenum, keyword);
                    859:                return 0;
1.111     djm       860:        case oConnectTimeout:
                    861:                intptr = &options->connection_timeout;
1.127     markus    862: parse_time:
1.111     djm       863:                arg = strdelim(&s);
                    864:                if (!arg || *arg == '\0')
                    865:                        fatal("%s line %d: missing time value.",
                    866:                            filename, linenum);
1.221     djm       867:                if (strcmp(arg, "none") == 0)
                    868:                        value = -1;
                    869:                else if ((value = convtime(arg)) == -1)
1.111     djm       870:                        fatal("%s line %d: invalid time value.",
                    871:                            filename, linenum);
1.160     dtucker   872:                if (*activep && *intptr == -1)
1.111     djm       873:                        *intptr = value;
                    874:                break;
                    875:
1.17      markus    876:        case oForwardAgent:
                    877:                intptr = &options->forward_agent;
1.207     djm       878:  parse_flag:
                    879:                multistate_ptr = multistate_flag;
                    880:  parse_multistate:
1.42      provos    881:                arg = strdelim(&s);
1.40      ho        882:                if (!arg || *arg == '\0')
1.207     djm       883:                        fatal("%s line %d: missing argument.",
                    884:                            filename, linenum);
                    885:                value = -1;
                    886:                for (i = 0; multistate_ptr[i].key != NULL; i++) {
                    887:                        if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
                    888:                                value = multistate_ptr[i].value;
                    889:                                break;
                    890:                        }
                    891:                }
                    892:                if (value == -1)
                    893:                        fatal("%s line %d: unsupported option \"%s\".",
                    894:                            filename, linenum, arg);
1.17      markus    895:                if (*activep && *intptr == -1)
                    896:                        *intptr = value;
                    897:                break;
                    898:
                    899:        case oForwardX11:
                    900:                intptr = &options->forward_x11;
                    901:                goto parse_flag;
                    902:
1.123     markus    903:        case oForwardX11Trusted:
                    904:                intptr = &options->forward_x11_trusted;
                    905:                goto parse_flag;
1.221     djm       906:
1.186     djm       907:        case oForwardX11Timeout:
                    908:                intptr = &options->forward_x11_timeout;
                    909:                goto parse_time;
1.123     markus    910:
1.17      markus    911:        case oGatewayPorts:
1.220     millert   912:                intptr = &options->fwd_opts.gateway_ports;
1.17      markus    913:                goto parse_flag;
                    914:
1.153     markus    915:        case oExitOnForwardFailure:
                    916:                intptr = &options->exit_on_forward_failure;
                    917:                goto parse_flag;
                    918:
1.17      markus    919:        case oUsePrivilegedPort:
                    920:                intptr = &options->use_privileged_port;
                    921:                goto parse_flag;
                    922:
                    923:        case oPasswordAuthentication:
                    924:                intptr = &options->password_authentication;
                    925:                goto parse_flag;
                    926:
1.48      markus    927:        case oKbdInteractiveAuthentication:
                    928:                intptr = &options->kbd_interactive_authentication;
                    929:                goto parse_flag;
                    930:
                    931:        case oKbdInteractiveDevices:
                    932:                charptr = &options->kbd_interactive_devices;
                    933:                goto parse_string;
                    934:
1.50      markus    935:        case oPubkeyAuthentication:
                    936:                intptr = &options->pubkey_authentication;
1.30      markus    937:                goto parse_flag;
                    938:
1.72      markus    939:        case oHostbasedAuthentication:
                    940:                intptr = &options->hostbased_authentication;
                    941:                goto parse_flag;
                    942:
1.59      markus    943:        case oChallengeResponseAuthentication:
1.78      markus    944:                intptr = &options->challenge_response_authentication;
1.17      markus    945:                goto parse_flag;
1.108     jakob     946:
1.118     markus    947:        case oGssAuthentication:
                    948:                intptr = &options->gss_authentication;
                    949:                goto parse_flag;
                    950:
                    951:        case oGssDelegateCreds:
                    952:                intptr = &options->gss_deleg_creds;
                    953:                goto parse_flag;
                    954:
1.17      markus    955:        case oBatchMode:
                    956:                intptr = &options->batch_mode;
                    957:                goto parse_flag;
                    958:
                    959:        case oCheckHostIP:
                    960:                intptr = &options->check_host_ip;
1.167     grunk     961:                goto parse_flag;
1.17      markus    962:
1.107     jakob     963:        case oVerifyHostKeyDNS:
                    964:                intptr = &options->verify_host_key_dns;
1.207     djm       965:                multistate_ptr = multistate_yesnoask;
                    966:                goto parse_multistate;
1.107     jakob     967:
1.17      markus    968:        case oStrictHostKeyChecking:
                    969:                intptr = &options->strict_host_key_checking;
1.207     djm       970:                multistate_ptr = multistate_yesnoask;
                    971:                goto parse_multistate;
1.17      markus    972:
                    973:        case oCompression:
                    974:                intptr = &options->compression;
                    975:                goto parse_flag;
                    976:
1.126     markus    977:        case oTCPKeepAlive:
                    978:                intptr = &options->tcp_keep_alive;
1.17      markus    979:                goto parse_flag;
                    980:
1.91      markus    981:        case oNoHostAuthenticationForLocalhost:
                    982:                intptr = &options->no_host_authentication_for_localhost;
                    983:                goto parse_flag;
                    984:
1.17      markus    985:        case oNumberOfPasswordPrompts:
                    986:                intptr = &options->number_of_password_prompts;
                    987:                goto parse_int;
                    988:
1.105     markus    989:        case oRekeyLimit:
                    990:                arg = strdelim(&s);
                    991:                if (!arg || *arg == '\0')
1.198     dtucker   992:                        fatal("%.200s line %d: Missing argument.", filename,
                    993:                            linenum);
                    994:                if (strcmp(arg, "default") == 0) {
                    995:                        val64 = 0;
                    996:                } else {
1.200     dtucker   997:                        if (scan_scaled(arg, &val64) == -1)
                    998:                                fatal("%.200s line %d: Bad number '%s': %s",
                    999:                                    filename, linenum, arg, strerror(errno));
1.198     dtucker  1000:                        if (val64 != 0 && val64 < 16)
                   1001:                                fatal("%.200s line %d: RekeyLimit too small",
                   1002:                                    filename, linenum);
1.105     markus   1003:                }
1.165     djm      1004:                if (*activep && options->rekey_limit == -1)
1.249     dtucker  1005:                        options->rekey_limit = val64;
1.198     dtucker  1006:                if (s != NULL) { /* optional rekey interval present */
                   1007:                        if (strcmp(s, "none") == 0) {
                   1008:                                (void)strdelim(&s);     /* discard */
                   1009:                                break;
                   1010:                        }
                   1011:                        intptr = &options->rekey_interval;
                   1012:                        goto parse_time;
                   1013:                }
1.105     markus   1014:                break;
                   1015:
1.17      markus   1016:        case oIdentityFile:
1.42      provos   1017:                arg = strdelim(&s);
1.40      ho       1018:                if (!arg || *arg == '\0')
1.17      markus   1019:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                   1020:                if (*activep) {
1.50      markus   1021:                        intptr = &options->num_identity_files;
1.27      markus   1022:                        if (*intptr >= SSH_MAX_IDENTITY_FILES)
1.17      markus   1023:                                fatal("%.200s line %d: Too many identity files specified (max %d).",
1.93      deraadt  1024:                                    filename, linenum, SSH_MAX_IDENTITY_FILES);
1.221     djm      1025:                        add_identity_file(options, NULL,
                   1026:                            arg, flags & SSHCONF_USERCONF);
1.17      markus   1027:                }
                   1028:                break;
                   1029:
1.241     djm      1030:        case oCertificateFile:
                   1031:                arg = strdelim(&s);
                   1032:                if (!arg || *arg == '\0')
                   1033:                        fatal("%.200s line %d: Missing argument.",
                   1034:                            filename, linenum);
                   1035:                if (*activep) {
                   1036:                        intptr = &options->num_certificate_files;
                   1037:                        if (*intptr >= SSH_MAX_CERTIFICATE_FILES) {
                   1038:                                fatal("%.200s line %d: Too many certificate "
                   1039:                                    "files specified (max %d).",
                   1040:                                    filename, linenum,
                   1041:                                    SSH_MAX_CERTIFICATE_FILES);
                   1042:                        }
                   1043:                        add_certificate_file(options, arg,
                   1044:                            flags & SSHCONF_USERCONF);
                   1045:                }
                   1046:                break;
                   1047:
1.34      markus   1048:        case oXAuthLocation:
                   1049:                charptr=&options->xauth_location;
                   1050:                goto parse_string;
                   1051:
1.17      markus   1052:        case oUser:
                   1053:                charptr = &options->user;
                   1054: parse_string:
1.42      provos   1055:                arg = strdelim(&s);
1.40      ho       1056:                if (!arg || *arg == '\0')
1.193     djm      1057:                        fatal("%.200s line %d: Missing argument.",
                   1058:                            filename, linenum);
1.17      markus   1059:                if (*activep && *charptr == NULL)
1.38      provos   1060:                        *charptr = xstrdup(arg);
1.17      markus   1061:                break;
                   1062:
                   1063:        case oGlobalKnownHostsFile:
1.193     djm      1064:                cpptr = (char **)&options->system_hostfiles;
                   1065:                uintptr = &options->num_system_hostfiles;
                   1066:                max_entries = SSH_MAX_HOSTS_FILES;
                   1067: parse_char_array:
                   1068:                if (*activep && *uintptr == 0) {
                   1069:                        while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
                   1070:                                if ((*uintptr) >= max_entries)
                   1071:                                        fatal("%s line %d: "
                   1072:                                            "too many authorized keys files.",
                   1073:                                            filename, linenum);
                   1074:                                cpptr[(*uintptr)++] = xstrdup(arg);
                   1075:                        }
                   1076:                }
                   1077:                return 0;
1.17      markus   1078:
                   1079:        case oUserKnownHostsFile:
1.193     djm      1080:                cpptr = (char **)&options->user_hostfiles;
                   1081:                uintptr = &options->num_user_hostfiles;
                   1082:                max_entries = SSH_MAX_HOSTS_FILES;
                   1083:                goto parse_char_array;
1.27      markus   1084:
1.17      markus   1085:        case oHostName:
                   1086:                charptr = &options->hostname;
                   1087:                goto parse_string;
                   1088:
1.52      markus   1089:        case oHostKeyAlias:
                   1090:                charptr = &options->host_key_alias;
                   1091:                goto parse_string;
                   1092:
1.67      markus   1093:        case oPreferredAuthentications:
                   1094:                charptr = &options->preferred_authentications;
                   1095:                goto parse_string;
                   1096:
1.77      markus   1097:        case oBindAddress:
                   1098:                charptr = &options->bind_address;
                   1099:                goto parse_string;
                   1100:
1.183     markus   1101:        case oPKCS11Provider:
                   1102:                charptr = &options->pkcs11_provider;
1.86      markus   1103:                goto parse_string;
1.85      jakob    1104:
1.17      markus   1105:        case oProxyCommand:
1.144     reyk     1106:                charptr = &options->proxy_command;
1.257     djm      1107:                /* Ignore ProxyCommand if ProxyJump already specified */
                   1108:                if (options->jump_host != NULL)
                   1109:                        charptr = &options->jump_host; /* Skip below */
1.144     reyk     1110: parse_command:
1.113     markus   1111:                if (s == NULL)
                   1112:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.102     markus   1113:                len = strspn(s, WHITESPACE "=");
1.17      markus   1114:                if (*activep && *charptr == NULL)
1.102     markus   1115:                        *charptr = xstrdup(s + len);
1.17      markus   1116:                return 0;
                   1117:
1.257     djm      1118:        case oProxyJump:
                   1119:                if (s == NULL) {
                   1120:                        fatal("%.200s line %d: Missing argument.",
                   1121:                            filename, linenum);
                   1122:                }
                   1123:                len = strspn(s, WHITESPACE "=");
                   1124:                if (parse_jump(s + len, options, *activep) == -1) {
                   1125:                        fatal("%.200s line %d: Invalid ProxyJump \"%s\"",
                   1126:                            filename, linenum, s + len);
                   1127:                }
                   1128:                return 0;
                   1129:
1.17      markus   1130:        case oPort:
                   1131:                intptr = &options->port;
                   1132: parse_int:
1.42      provos   1133:                arg = strdelim(&s);
1.40      ho       1134:                if (!arg || *arg == '\0')
1.17      markus   1135:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38      provos   1136:                if (arg[0] < '0' || arg[0] > '9')
1.17      markus   1137:                        fatal("%.200s line %d: Bad number.", filename, linenum);
1.21      markus   1138:
                   1139:                /* Octal, decimal, or hex format? */
1.38      provos   1140:                value = strtol(arg, &endofnumber, 0);
                   1141:                if (arg == endofnumber)
1.21      markus   1142:                        fatal("%.200s line %d: Bad number.", filename, linenum);
1.17      markus   1143:                if (*activep && *intptr == -1)
                   1144:                        *intptr = value;
                   1145:                break;
                   1146:
                   1147:        case oConnectionAttempts:
                   1148:                intptr = &options->connection_attempts;
                   1149:                goto parse_int;
                   1150:
1.25      markus   1151:        case oCiphers:
1.42      provos   1152:                arg = strdelim(&s);
1.40      ho       1153:                if (!arg || *arg == '\0')
1.32      markus   1154:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.268     djm      1155:                if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
1.31      markus   1156:                        fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.93      deraadt  1157:                            filename, linenum, arg ? arg : "<NONE>");
1.25      markus   1158:                if (*activep && options->ciphers == NULL)
1.38      provos   1159:                        options->ciphers = xstrdup(arg);
1.25      markus   1160:                break;
                   1161:
1.62      markus   1162:        case oMacs:
                   1163:                arg = strdelim(&s);
                   1164:                if (!arg || *arg == '\0')
                   1165:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.268     djm      1166:                if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
1.62      markus   1167:                        fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
1.93      deraadt  1168:                            filename, linenum, arg ? arg : "<NONE>");
1.62      markus   1169:                if (*activep && options->macs == NULL)
                   1170:                        options->macs = xstrdup(arg);
                   1171:                break;
                   1172:
1.189     djm      1173:        case oKexAlgorithms:
                   1174:                arg = strdelim(&s);
                   1175:                if (!arg || *arg == '\0')
                   1176:                        fatal("%.200s line %d: Missing argument.",
                   1177:                            filename, linenum);
1.268     djm      1178:                if (*arg != '-' &&
                   1179:                    !kex_names_valid(*arg == '+' ? arg + 1 : arg))
1.189     djm      1180:                        fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
                   1181:                            filename, linenum, arg ? arg : "<NONE>");
                   1182:                if (*activep && options->kex_algorithms == NULL)
                   1183:                        options->kex_algorithms = xstrdup(arg);
                   1184:                break;
                   1185:
1.76      markus   1186:        case oHostKeyAlgorithms:
1.238     markus   1187:                charptr = &options->hostkeyalgorithms;
                   1188: parse_keytypes:
1.76      markus   1189:                arg = strdelim(&s);
                   1190:                if (!arg || *arg == '\0')
1.238     markus   1191:                        fatal("%.200s line %d: Missing argument.",
                   1192:                            filename, linenum);
1.268     djm      1193:                if (*arg != '-' &&
                   1194:                    !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1.238     markus   1195:                        fatal("%s line %d: Bad key types '%s'.",
                   1196:                                filename, linenum, arg ? arg : "<NONE>");
                   1197:                if (*activep && *charptr == NULL)
                   1198:                        *charptr = xstrdup(arg);
1.76      markus   1199:                break;
                   1200:
1.17      markus   1201:        case oLogLevel:
1.164     dtucker  1202:                log_level_ptr = &options->log_level;
1.42      provos   1203:                arg = strdelim(&s);
1.38      provos   1204:                value = log_level_number(arg);
1.95      markus   1205:                if (value == SYSLOG_LEVEL_NOT_SET)
1.64      millert  1206:                        fatal("%.200s line %d: unsupported log level '%s'",
1.93      deraadt  1207:                            filename, linenum, arg ? arg : "<NONE>");
1.164     dtucker  1208:                if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
                   1209:                        *log_level_ptr = (LogLevel) value;
1.17      markus   1210:                break;
                   1211:
1.271     dtucker  1212:        case oLogFacility:
                   1213:                log_facility_ptr = &options->log_facility;
                   1214:                arg = strdelim(&s);
                   1215:                value = log_facility_number(arg);
                   1216:                if (value == SYSLOG_FACILITY_NOT_SET)
                   1217:                        fatal("%.200s line %d: unsupported log facility '%s'",
                   1218:                            filename, linenum, arg ? arg : "<NONE>");
                   1219:                if (*log_facility_ptr == -1)
                   1220:                        *log_facility_ptr = (SyslogFacility) value;
                   1221:                break;
                   1222:
1.88      stevesk  1223:        case oLocalForward:
1.17      markus   1224:        case oRemoteForward:
1.168     stevesk  1225:        case oDynamicForward:
1.42      provos   1226:                arg = strdelim(&s);
1.135     djm      1227:                if (arg == NULL || *arg == '\0')
1.88      stevesk  1228:                        fatal("%.200s line %d: Missing port argument.",
                   1229:                            filename, linenum);
1.135     djm      1230:
1.168     stevesk  1231:                if (opcode == oLocalForward ||
                   1232:                    opcode == oRemoteForward) {
                   1233:                        arg2 = strdelim(&s);
                   1234:                        if (arg2 == NULL || *arg2 == '\0')
                   1235:                                fatal("%.200s line %d: Missing target argument.",
                   1236:                                    filename, linenum);
1.135     djm      1237:
1.168     stevesk  1238:                        /* construct a string for parse_forward */
                   1239:                        snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
                   1240:                } else if (opcode == oDynamicForward) {
                   1241:                        strlcpy(fwdarg, arg, sizeof(fwdarg));
                   1242:                }
                   1243:
                   1244:                if (parse_forward(&fwd, fwdarg,
1.176     djm      1245:                    opcode == oDynamicForward ? 1 : 0,
                   1246:                    opcode == oRemoteForward ? 1 : 0) == 0)
1.88      stevesk  1247:                        fatal("%.200s line %d: Bad forwarding specification.",
                   1248:                            filename, linenum);
1.135     djm      1249:
1.88      stevesk  1250:                if (*activep) {
1.168     stevesk  1251:                        if (opcode == oLocalForward ||
                   1252:                            opcode == oDynamicForward)
1.135     djm      1253:                                add_local_forward(options, &fwd);
1.88      stevesk  1254:                        else if (opcode == oRemoteForward)
1.135     djm      1255:                                add_remote_forward(options, &fwd);
1.88      stevesk  1256:                }
1.17      markus   1257:                break;
1.71      markus   1258:
1.90      stevesk  1259:        case oClearAllForwardings:
                   1260:                intptr = &options->clear_forwardings;
                   1261:                goto parse_flag;
                   1262:
1.17      markus   1263:        case oHost:
1.206     djm      1264:                if (cmdline)
                   1265:                        fatal("Host directive not supported as a command-line "
                   1266:                            "option");
1.17      markus   1267:                *activep = 0;
1.191     djm      1268:                arg2 = NULL;
                   1269:                while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.252     djm      1270:                        if ((flags & SSHCONF_NEVERMATCH) != 0)
                   1271:                                break;
1.191     djm      1272:                        negated = *arg == '!';
                   1273:                        if (negated)
                   1274:                                arg++;
1.38      provos   1275:                        if (match_pattern(host, arg)) {
1.191     djm      1276:                                if (negated) {
                   1277:                                        debug("%.200s line %d: Skipping Host "
                   1278:                                            "block because of negated match "
                   1279:                                            "for %.100s", filename, linenum,
                   1280:                                            arg);
                   1281:                                        *activep = 0;
                   1282:                                        break;
                   1283:                                }
                   1284:                                if (!*activep)
                   1285:                                        arg2 = arg; /* logged below */
1.17      markus   1286:                                *activep = 1;
                   1287:                        }
1.191     djm      1288:                }
                   1289:                if (*activep)
                   1290:                        debug("%.200s line %d: Applying options for %.100s",
                   1291:                            filename, linenum, arg2);
1.42      provos   1292:                /* Avoid garbage check below, as strdelim is done. */
1.17      markus   1293:                return 0;
                   1294:
1.206     djm      1295:        case oMatch:
                   1296:                if (cmdline)
                   1297:                        fatal("Host directive not supported as a command-line "
                   1298:                            "option");
1.221     djm      1299:                value = match_cfg_line(options, &s, pw, host, original_host,
                   1300:                    flags & SSHCONF_POSTCANON, filename, linenum);
1.206     djm      1301:                if (value < 0)
                   1302:                        fatal("%.200s line %d: Bad Match condition", filename,
                   1303:                            linenum);
1.252     djm      1304:                *activep = (flags & SSHCONF_NEVERMATCH) ? 0 : value;
1.206     djm      1305:                break;
                   1306:
1.17      markus   1307:        case oEscapeChar:
                   1308:                intptr = &options->escape_char;
1.42      provos   1309:                arg = strdelim(&s);
1.40      ho       1310:                if (!arg || *arg == '\0')
1.17      markus   1311:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.236     djm      1312:                if (strcmp(arg, "none") == 0)
                   1313:                        value = SSH_ESCAPECHAR_NONE;
                   1314:                else if (arg[1] == '\0')
                   1315:                        value = (u_char) arg[0];
                   1316:                else if (arg[0] == '^' && arg[2] == 0 &&
1.51      markus   1317:                    (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
                   1318:                        value = (u_char) arg[1] & 31;
1.17      markus   1319:                else {
                   1320:                        fatal("%.200s line %d: Bad escape character.",
1.93      deraadt  1321:                            filename, linenum);
1.17      markus   1322:                        /* NOTREACHED */
                   1323:                        value = 0;      /* Avoid compiler warning. */
                   1324:                }
                   1325:                if (*activep && *intptr == -1)
                   1326:                        *intptr = value;
1.112     djm      1327:                break;
                   1328:
                   1329:        case oAddressFamily:
1.114     djm      1330:                intptr = &options->address_family;
1.207     djm      1331:                multistate_ptr = multistate_addressfamily;
                   1332:                goto parse_multistate;
1.17      markus   1333:
1.101     markus   1334:        case oEnableSSHKeysign:
                   1335:                intptr = &options->enable_ssh_keysign;
                   1336:                goto parse_flag;
                   1337:
1.128     markus   1338:        case oIdentitiesOnly:
                   1339:                intptr = &options->identities_only;
                   1340:                goto parse_flag;
                   1341:
1.127     markus   1342:        case oServerAliveInterval:
                   1343:                intptr = &options->server_alive_interval;
                   1344:                goto parse_time;
                   1345:
                   1346:        case oServerAliveCountMax:
                   1347:                intptr = &options->server_alive_count_max;
                   1348:                goto parse_int;
                   1349:
1.130     djm      1350:        case oSendEnv:
                   1351:                while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
                   1352:                        if (strchr(arg, '=') != NULL)
                   1353:                                fatal("%s line %d: Invalid environment name.",
                   1354:                                    filename, linenum);
1.137     djm      1355:                        if (!*activep)
                   1356:                                continue;
1.130     djm      1357:                        if (options->num_send_env >= MAX_SEND_ENV)
                   1358:                                fatal("%s line %d: too many send env.",
                   1359:                                    filename, linenum);
                   1360:                        options->send_env[options->num_send_env++] =
                   1361:                            xstrdup(arg);
                   1362:                }
                   1363:                break;
                   1364:
1.132     djm      1365:        case oControlPath:
                   1366:                charptr = &options->control_path;
                   1367:                goto parse_string;
                   1368:
                   1369:        case oControlMaster:
                   1370:                intptr = &options->control_master;
1.207     djm      1371:                multistate_ptr = multistate_controlmaster;
                   1372:                goto parse_multistate;
1.132     djm      1373:
1.187     djm      1374:        case oControlPersist:
                   1375:                /* no/false/yes/true, or a time spec */
                   1376:                intptr = &options->control_persist;
                   1377:                arg = strdelim(&s);
                   1378:                if (!arg || *arg == '\0')
                   1379:                        fatal("%.200s line %d: Missing ControlPersist"
                   1380:                            " argument.", filename, linenum);
                   1381:                value = 0;
                   1382:                value2 = 0;     /* timeout */
                   1383:                if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
                   1384:                        value = 0;
                   1385:                else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
                   1386:                        value = 1;
                   1387:                else if ((value2 = convtime(arg)) >= 0)
                   1388:                        value = 1;
                   1389:                else
                   1390:                        fatal("%.200s line %d: Bad ControlPersist argument.",
                   1391:                            filename, linenum);
                   1392:                if (*activep && *intptr == -1) {
                   1393:                        *intptr = value;
                   1394:                        options->control_persist_timeout = value2;
                   1395:                }
                   1396:                break;
                   1397:
1.136     djm      1398:        case oHashKnownHosts:
                   1399:                intptr = &options->hash_known_hosts;
                   1400:                goto parse_flag;
                   1401:
1.144     reyk     1402:        case oTunnel:
                   1403:                intptr = &options->tun_open;
1.207     djm      1404:                multistate_ptr = multistate_tunnel;
                   1405:                goto parse_multistate;
1.144     reyk     1406:
                   1407:        case oTunnelDevice:
                   1408:                arg = strdelim(&s);
                   1409:                if (!arg || *arg == '\0')
                   1410:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                   1411:                value = a2tun(arg, &value2);
1.145     reyk     1412:                if (value == SSH_TUNID_ERR)
1.144     reyk     1413:                        fatal("%.200s line %d: Bad tun device.", filename, linenum);
                   1414:                if (*activep) {
                   1415:                        options->tun_local = value;
                   1416:                        options->tun_remote = value2;
                   1417:                }
                   1418:                break;
                   1419:
                   1420:        case oLocalCommand:
                   1421:                charptr = &options->local_command;
                   1422:                goto parse_command;
                   1423:
                   1424:        case oPermitLocalCommand:
                   1425:                intptr = &options->permit_local_command;
                   1426:                goto parse_flag;
                   1427:
1.167     grunk    1428:        case oVisualHostKey:
                   1429:                intptr = &options->visual_host_key;
                   1430:                goto parse_flag;
                   1431:
1.252     djm      1432:        case oInclude:
                   1433:                if (cmdline)
                   1434:                        fatal("Include directive not supported as a "
                   1435:                            "command-line option");
                   1436:                value = 0;
                   1437:                while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
                   1438:                        /*
                   1439:                         * Ensure all paths are anchored. User configuration
                   1440:                         * files may begin with '~/' but system configurations
                   1441:                         * must not. If the path is relative, then treat it
                   1442:                         * as living in ~/.ssh for user configurations or
                   1443:                         * /etc/ssh for system ones.
                   1444:                         */
                   1445:                        if (*arg == '~' && (flags & SSHCONF_USERCONF) == 0)
                   1446:                                fatal("%.200s line %d: bad include path %s.",
                   1447:                                    filename, linenum, arg);
                   1448:                        if (*arg != '/' && *arg != '~') {
                   1449:                                xasprintf(&arg2, "%s/%s",
                   1450:                                    (flags & SSHCONF_USERCONF) ?
                   1451:                                    "~/" _PATH_SSH_USER_DIR : SSHDIR, arg);
                   1452:                        } else
                   1453:                                arg2 = xstrdup(arg);
                   1454:                        memset(&gl, 0, sizeof(gl));
                   1455:                        r = glob(arg2, GLOB_TILDE, NULL, &gl);
                   1456:                        if (r == GLOB_NOMATCH) {
                   1457:                                debug("%.200s line %d: include %s matched no "
                   1458:                                    "files",filename, linenum, arg2);
1.269     dtucker  1459:                                free(arg2);
1.252     djm      1460:                                continue;
                   1461:                        } else if (r != 0 || gl.gl_pathc < 0)
                   1462:                                fatal("%.200s line %d: glob failed for %s.",
                   1463:                                    filename, linenum, arg2);
                   1464:                        free(arg2);
                   1465:                        oactive = *activep;
                   1466:                        for (i = 0; i < (u_int)gl.gl_pathc; i++) {
                   1467:                                debug3("%.200s line %d: Including file %s "
                   1468:                                    "depth %d%s", filename, linenum,
                   1469:                                    gl.gl_pathv[i], depth,
                   1470:                                    oactive ? "" : " (parse only)");
                   1471:                                r = read_config_file_depth(gl.gl_pathv[i],
                   1472:                                    pw, host, original_host, options,
                   1473:                                    flags | SSHCONF_CHECKPERM |
                   1474:                                    (oactive ? 0 : SSHCONF_NEVERMATCH),
                   1475:                                    activep, depth + 1);
1.264     djm      1476:                                if (r != 1 && errno != ENOENT) {
1.263     djm      1477:                                        fatal("Can't open user config file "
                   1478:                                            "%.100s: %.100s", gl.gl_pathv[i],
                   1479:                                            strerror(errno));
                   1480:                                }
1.252     djm      1481:                                /*
                   1482:                                 * don't let Match in includes clobber the
                   1483:                                 * containing file's Match state.
                   1484:                                 */
                   1485:                                *activep = oactive;
                   1486:                                if (r != 1)
                   1487:                                        value = -1;
                   1488:                        }
                   1489:                        globfree(&gl);
                   1490:                }
                   1491:                if (value != 0)
                   1492:                        return value;
                   1493:                break;
                   1494:
1.190     djm      1495:        case oIPQoS:
                   1496:                arg = strdelim(&s);
                   1497:                if ((value = parse_ipqos(arg)) == -1)
                   1498:                        fatal("%s line %d: Bad IPQoS value: %s",
                   1499:                            filename, linenum, arg);
                   1500:                arg = strdelim(&s);
                   1501:                if (arg == NULL)
                   1502:                        value2 = value;
                   1503:                else if ((value2 = parse_ipqos(arg)) == -1)
                   1504:                        fatal("%s line %d: Bad IPQoS value: %s",
                   1505:                            filename, linenum, arg);
                   1506:                if (*activep) {
                   1507:                        options->ip_qos_interactive = value;
                   1508:                        options->ip_qos_bulk = value2;
                   1509:                }
                   1510:                break;
                   1511:
1.192     djm      1512:        case oRequestTTY:
                   1513:                intptr = &options->request_tty;
1.207     djm      1514:                multistate_ptr = multistate_requesttty;
                   1515:                goto parse_multistate;
1.192     djm      1516:
1.199     djm      1517:        case oIgnoreUnknown:
                   1518:                charptr = &options->ignored_unknown;
                   1519:                goto parse_string;
                   1520:
1.205     djm      1521:        case oProxyUseFdpass:
                   1522:                intptr = &options->proxy_use_fdpass;
                   1523:                goto parse_flag;
                   1524:
1.208     djm      1525:        case oCanonicalDomains:
                   1526:                value = options->num_canonical_domains != 0;
                   1527:                while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
                   1528:                        valid_domain(arg, filename, linenum);
                   1529:                        if (!*activep || value)
                   1530:                                continue;
                   1531:                        if (options->num_canonical_domains >= MAX_CANON_DOMAINS)
                   1532:                                fatal("%s line %d: too many hostname suffixes.",
                   1533:                                    filename, linenum);
                   1534:                        options->canonical_domains[
                   1535:                            options->num_canonical_domains++] = xstrdup(arg);
                   1536:                }
                   1537:                break;
                   1538:
1.209     djm      1539:        case oCanonicalizePermittedCNAMEs:
1.208     djm      1540:                value = options->num_permitted_cnames != 0;
                   1541:                while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
                   1542:                        /* Either '*' for everything or 'list:list' */
                   1543:                        if (strcmp(arg, "*") == 0)
                   1544:                                arg2 = arg;
                   1545:                        else {
                   1546:                                lowercase(arg);
                   1547:                                if ((arg2 = strchr(arg, ':')) == NULL ||
                   1548:                                    arg2[1] == '\0') {
                   1549:                                        fatal("%s line %d: "
                   1550:                                            "Invalid permitted CNAME \"%s\"",
                   1551:                                            filename, linenum, arg);
                   1552:                                }
                   1553:                                *arg2 = '\0';
                   1554:                                arg2++;
                   1555:                        }
                   1556:                        if (!*activep || value)
                   1557:                                continue;
                   1558:                        if (options->num_permitted_cnames >= MAX_CANON_DOMAINS)
                   1559:                                fatal("%s line %d: too many permitted CNAMEs.",
                   1560:                                    filename, linenum);
                   1561:                        cname = options->permitted_cnames +
                   1562:                            options->num_permitted_cnames++;
                   1563:                        cname->source_list = xstrdup(arg);
                   1564:                        cname->target_list = xstrdup(arg2);
                   1565:                }
                   1566:                break;
                   1567:
1.209     djm      1568:        case oCanonicalizeHostname:
                   1569:                intptr = &options->canonicalize_hostname;
                   1570:                multistate_ptr = multistate_canonicalizehostname;
1.208     djm      1571:                goto parse_multistate;
                   1572:
1.209     djm      1573:        case oCanonicalizeMaxDots:
                   1574:                intptr = &options->canonicalize_max_dots;
1.208     djm      1575:                goto parse_int;
                   1576:
1.209     djm      1577:        case oCanonicalizeFallbackLocal:
                   1578:                intptr = &options->canonicalize_fallback_local;
1.208     djm      1579:                goto parse_flag;
                   1580:
1.220     millert  1581:        case oStreamLocalBindMask:
                   1582:                arg = strdelim(&s);
                   1583:                if (!arg || *arg == '\0')
                   1584:                        fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum);
                   1585:                /* Parse mode in octal format */
                   1586:                value = strtol(arg, &endofnumber, 8);
                   1587:                if (arg == endofnumber || value < 0 || value > 0777)
                   1588:                        fatal("%.200s line %d: Bad mask.", filename, linenum);
                   1589:                options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
                   1590:                break;
                   1591:
                   1592:        case oStreamLocalBindUnlink:
                   1593:                intptr = &options->fwd_opts.streamlocal_bind_unlink;
                   1594:                goto parse_flag;
                   1595:
1.223     djm      1596:        case oRevokedHostKeys:
                   1597:                charptr = &options->revoked_host_keys;
                   1598:                goto parse_string;
                   1599:
1.224     djm      1600:        case oFingerprintHash:
1.225     djm      1601:                intptr = &options->fingerprint_hash;
1.224     djm      1602:                arg = strdelim(&s);
                   1603:                if (!arg || *arg == '\0')
                   1604:                        fatal("%.200s line %d: Missing argument.",
                   1605:                            filename, linenum);
                   1606:                if ((value = ssh_digest_alg_by_name(arg)) == -1)
                   1607:                        fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
                   1608:                            filename, linenum, arg);
1.225     djm      1609:                if (*activep && *intptr == -1)
                   1610:                        *intptr = value;
1.224     djm      1611:                break;
                   1612:
1.229     djm      1613:        case oUpdateHostkeys:
                   1614:                intptr = &options->update_hostkeys;
1.232     djm      1615:                multistate_ptr = multistate_yesnoask;
                   1616:                goto parse_multistate;
1.229     djm      1617:
1.230     djm      1618:        case oHostbasedKeyTypes:
                   1619:                charptr = &options->hostbased_key_types;
1.238     markus   1620:                goto parse_keytypes;
                   1621:
                   1622:        case oPubkeyAcceptedKeyTypes:
                   1623:                charptr = &options->pubkey_key_types;
                   1624:                goto parse_keytypes;
1.230     djm      1625:
1.246     jcs      1626:        case oAddKeysToAgent:
                   1627:                intptr = &options->add_keys_to_agent;
                   1628:                multistate_ptr = multistate_yesnoaskconfirm;
                   1629:                goto parse_multistate;
                   1630:
1.253     markus   1631:        case oIdentityAgent:
                   1632:                charptr = &options->identity_agent;
                   1633:                goto parse_string;
                   1634:
1.96      markus   1635:        case oDeprecated:
1.98      markus   1636:                debug("%s line %d: Deprecated option \"%s\"",
1.96      markus   1637:                    filename, linenum, keyword);
1.98      markus   1638:                return 0;
1.96      markus   1639:
1.110     jakob    1640:        case oUnsupported:
                   1641:                error("%s line %d: Unsupported option \"%s\"",
                   1642:                    filename, linenum, keyword);
                   1643:                return 0;
                   1644:
1.17      markus   1645:        default:
1.221     djm      1646:                fatal("%s: Unimplemented opcode %d", __func__, opcode);
1.17      markus   1647:        }
                   1648:
                   1649:        /* Check that there is no garbage at end of line. */
1.57      djm      1650:        if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.39      ho       1651:                fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
1.142     djm      1652:                    filename, linenum, arg);
1.39      ho       1653:        }
1.17      markus   1654:        return 0;
1.1       deraadt  1655: }
                   1656:
1.19      markus   1657: /*
                   1658:  * Reads the config file and modifies the options accordingly.  Options
                   1659:  * should already be initialized before this call.  This never returns if
1.89      stevesk  1660:  * there is an error.  If the file does not exist, this returns 0.
1.19      markus   1661:  */
1.89      stevesk  1662: int
1.206     djm      1663: read_config_file(const char *filename, struct passwd *pw, const char *host,
1.221     djm      1664:     const char *original_host, Options *options, int flags)
1.1       deraadt  1665: {
1.252     djm      1666:        int active = 1;
                   1667:
                   1668:        return read_config_file_depth(filename, pw, host, original_host,
                   1669:            options, flags, &active, 0);
                   1670: }
                   1671:
                   1672: #define READCONF_MAX_DEPTH     16
                   1673: static int
                   1674: read_config_file_depth(const char *filename, struct passwd *pw,
                   1675:     const char *host, const char *original_host, Options *options,
                   1676:     int flags, int *activep, int depth)
                   1677: {
1.17      markus   1678:        FILE *f;
1.270     djm      1679:        char line[4096];
1.252     djm      1680:        int linenum;
1.17      markus   1681:        int bad_options = 0;
                   1682:
1.252     djm      1683:        if (depth < 0 || depth > READCONF_MAX_DEPTH)
                   1684:                fatal("Too many recursive configuration includes");
                   1685:
1.129     djm      1686:        if ((f = fopen(filename, "r")) == NULL)
1.89      stevesk  1687:                return 0;
1.129     djm      1688:
1.196     dtucker  1689:        if (flags & SSHCONF_CHECKPERM) {
1.129     djm      1690:                struct stat sb;
1.134     deraadt  1691:
1.131     dtucker  1692:                if (fstat(fileno(f), &sb) == -1)
1.129     djm      1693:                        fatal("fstat %s: %s", filename, strerror(errno));
                   1694:                if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1.131     dtucker  1695:                    (sb.st_mode & 022) != 0))
1.129     djm      1696:                        fatal("Bad owner or permissions on %s", filename);
                   1697:        }
1.17      markus   1698:
                   1699:        debug("Reading configuration data %.200s", filename);
                   1700:
1.19      markus   1701:        /*
                   1702:         * Mark that we are now processing the options.  This flag is turned
                   1703:         * on/off by Host specifications.
                   1704:         */
1.17      markus   1705:        linenum = 0;
                   1706:        while (fgets(line, sizeof(line), f)) {
                   1707:                /* Update line number counter. */
                   1708:                linenum++;
1.270     djm      1709:                if (strlen(line) == sizeof(line) - 1)
                   1710:                        fatal("%s line %d too long", filename, linenum);
1.252     djm      1711:                if (process_config_line_depth(options, pw, host, original_host,
                   1712:                    line, filename, linenum, activep, flags, depth) != 0)
1.17      markus   1713:                        bad_options++;
                   1714:        }
                   1715:        fclose(f);
                   1716:        if (bad_options > 0)
1.64      millert  1717:                fatal("%s: terminating, %d bad configuration options",
1.93      deraadt  1718:                    filename, bad_options);
1.89      stevesk  1719:        return 1;
1.1       deraadt  1720: }
                   1721:
1.218     djm      1722: /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
                   1723: int
                   1724: option_clear_or_none(const char *o)
                   1725: {
                   1726:        return o == NULL || strcasecmp(o, "none") == 0;
                   1727: }
                   1728:
1.19      markus   1729: /*
                   1730:  * Initializes options to special values that indicate that they have not yet
                   1731:  * been set.  Read_config_file will only set options with this value. Options
                   1732:  * are processed in the following order: command line, user config file,
                   1733:  * system config file.  Last, fill_default_options is called.
                   1734:  */
1.1       deraadt  1735:
1.26      markus   1736: void
1.17      markus   1737: initialize_options(Options * options)
1.1       deraadt  1738: {
1.17      markus   1739:        memset(options, 'X', sizeof(*options));
                   1740:        options->forward_agent = -1;
                   1741:        options->forward_x11 = -1;
1.123     markus   1742:        options->forward_x11_trusted = -1;
1.186     djm      1743:        options->forward_x11_timeout = -1;
1.255     dtucker  1744:        options->stdio_forward_host = NULL;
                   1745:        options->stdio_forward_port = 0;
1.256     dtucker  1746:        options->clear_forwardings = -1;
1.153     markus   1747:        options->exit_on_forward_failure = -1;
1.34      markus   1748:        options->xauth_location = NULL;
1.220     millert  1749:        options->fwd_opts.gateway_ports = -1;
                   1750:        options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
                   1751:        options->fwd_opts.streamlocal_bind_unlink = -1;
1.17      markus   1752:        options->use_privileged_port = -1;
1.50      markus   1753:        options->pubkey_authentication = -1;
1.78      markus   1754:        options->challenge_response_authentication = -1;
1.118     markus   1755:        options->gss_authentication = -1;
                   1756:        options->gss_deleg_creds = -1;
1.17      markus   1757:        options->password_authentication = -1;
1.48      markus   1758:        options->kbd_interactive_authentication = -1;
                   1759:        options->kbd_interactive_devices = NULL;
1.72      markus   1760:        options->hostbased_authentication = -1;
1.17      markus   1761:        options->batch_mode = -1;
                   1762:        options->check_host_ip = -1;
                   1763:        options->strict_host_key_checking = -1;
                   1764:        options->compression = -1;
1.126     markus   1765:        options->tcp_keep_alive = -1;
1.17      markus   1766:        options->port = -1;
1.114     djm      1767:        options->address_family = -1;
1.17      markus   1768:        options->connection_attempts = -1;
1.111     djm      1769:        options->connection_timeout = -1;
1.17      markus   1770:        options->number_of_password_prompts = -1;
1.25      markus   1771:        options->ciphers = NULL;
1.62      markus   1772:        options->macs = NULL;
1.189     djm      1773:        options->kex_algorithms = NULL;
1.76      markus   1774:        options->hostkeyalgorithms = NULL;
1.17      markus   1775:        options->num_identity_files = 0;
1.241     djm      1776:        options->num_certificate_files = 0;
1.17      markus   1777:        options->hostname = NULL;
1.52      markus   1778:        options->host_key_alias = NULL;
1.17      markus   1779:        options->proxy_command = NULL;
1.257     djm      1780:        options->jump_user = NULL;
                   1781:        options->jump_host = NULL;
                   1782:        options->jump_port = -1;
                   1783:        options->jump_extra = NULL;
1.17      markus   1784:        options->user = NULL;
                   1785:        options->escape_char = -1;
1.193     djm      1786:        options->num_system_hostfiles = 0;
                   1787:        options->num_user_hostfiles = 0;
1.185     djm      1788:        options->local_forwards = NULL;
1.17      markus   1789:        options->num_local_forwards = 0;
1.185     djm      1790:        options->remote_forwards = NULL;
1.17      markus   1791:        options->num_remote_forwards = 0;
1.271     dtucker  1792:        options->log_facility = SYSLOG_FACILITY_NOT_SET;
1.95      markus   1793:        options->log_level = SYSLOG_LEVEL_NOT_SET;
1.67      markus   1794:        options->preferred_authentications = NULL;
1.77      markus   1795:        options->bind_address = NULL;
1.183     markus   1796:        options->pkcs11_provider = NULL;
1.101     markus   1797:        options->enable_ssh_keysign = - 1;
1.91      markus   1798:        options->no_host_authentication_for_localhost = - 1;
1.128     markus   1799:        options->identities_only = - 1;
1.105     markus   1800:        options->rekey_limit = - 1;
1.198     dtucker  1801:        options->rekey_interval = -1;
1.107     jakob    1802:        options->verify_host_key_dns = -1;
1.127     markus   1803:        options->server_alive_interval = -1;
                   1804:        options->server_alive_count_max = -1;
1.130     djm      1805:        options->num_send_env = 0;
1.132     djm      1806:        options->control_path = NULL;
                   1807:        options->control_master = -1;
1.187     djm      1808:        options->control_persist = -1;
                   1809:        options->control_persist_timeout = 0;
1.136     djm      1810:        options->hash_known_hosts = -1;
1.144     reyk     1811:        options->tun_open = -1;
                   1812:        options->tun_local = -1;
                   1813:        options->tun_remote = -1;
                   1814:        options->local_command = NULL;
                   1815:        options->permit_local_command = -1;
1.246     jcs      1816:        options->add_keys_to_agent = -1;
1.253     markus   1817:        options->identity_agent = NULL;
1.167     grunk    1818:        options->visual_host_key = -1;
1.190     djm      1819:        options->ip_qos_interactive = -1;
                   1820:        options->ip_qos_bulk = -1;
1.192     djm      1821:        options->request_tty = -1;
1.205     djm      1822:        options->proxy_use_fdpass = -1;
1.199     djm      1823:        options->ignored_unknown = NULL;
1.208     djm      1824:        options->num_canonical_domains = 0;
                   1825:        options->num_permitted_cnames = 0;
1.209     djm      1826:        options->canonicalize_max_dots = -1;
                   1827:        options->canonicalize_fallback_local = -1;
                   1828:        options->canonicalize_hostname = -1;
1.223     djm      1829:        options->revoked_host_keys = NULL;
1.224     djm      1830:        options->fingerprint_hash = -1;
1.229     djm      1831:        options->update_hostkeys = -1;
1.230     djm      1832:        options->hostbased_key_types = NULL;
1.238     markus   1833:        options->pubkey_key_types = NULL;
1.1       deraadt  1834: }
                   1835:
1.19      markus   1836: /*
1.218     djm      1837:  * A petite version of fill_default_options() that just fills the options
                   1838:  * needed for hostname canonicalization to proceed.
                   1839:  */
                   1840: void
                   1841: fill_default_options_for_canonicalization(Options *options)
                   1842: {
                   1843:        if (options->canonicalize_max_dots == -1)
                   1844:                options->canonicalize_max_dots = 1;
                   1845:        if (options->canonicalize_fallback_local == -1)
                   1846:                options->canonicalize_fallback_local = 1;
                   1847:        if (options->canonicalize_hostname == -1)
                   1848:                options->canonicalize_hostname = SSH_CANONICALISE_NO;
                   1849: }
                   1850:
                   1851: /*
1.19      markus   1852:  * Called after processing other sources of option data, this fills those
                   1853:  * options for which no value has been specified with their default values.
                   1854:  */
1.26      markus   1855: void
1.17      markus   1856: fill_default_options(Options * options)
1.1       deraadt  1857: {
1.17      markus   1858:        if (options->forward_agent == -1)
1.33      markus   1859:                options->forward_agent = 0;
1.17      markus   1860:        if (options->forward_x11 == -1)
1.23      markus   1861:                options->forward_x11 = 0;
1.123     markus   1862:        if (options->forward_x11_trusted == -1)
                   1863:                options->forward_x11_trusted = 0;
1.186     djm      1864:        if (options->forward_x11_timeout == -1)
                   1865:                options->forward_x11_timeout = 1200;
1.256     dtucker  1866:        /*
                   1867:         * stdio forwarding (-W) changes the default for these but we defer
                   1868:         * setting the values so they can be overridden.
                   1869:         */
1.153     markus   1870:        if (options->exit_on_forward_failure == -1)
1.256     dtucker  1871:                options->exit_on_forward_failure =
                   1872:                    options->stdio_forward_host != NULL ? 1 : 0;
                   1873:        if (options->clear_forwardings == -1)
                   1874:                options->clear_forwardings =
                   1875:                    options->stdio_forward_host != NULL ? 1 : 0;
                   1876:        if (options->clear_forwardings == 1)
                   1877:                clear_forwardings(options);
                   1878:
1.34      markus   1879:        if (options->xauth_location == NULL)
1.80      markus   1880:                options->xauth_location = _PATH_XAUTH;
1.220     millert  1881:        if (options->fwd_opts.gateway_ports == -1)
                   1882:                options->fwd_opts.gateway_ports = 0;
                   1883:        if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
                   1884:                options->fwd_opts.streamlocal_bind_mask = 0177;
                   1885:        if (options->fwd_opts.streamlocal_bind_unlink == -1)
                   1886:                options->fwd_opts.streamlocal_bind_unlink = 0;
1.17      markus   1887:        if (options->use_privileged_port == -1)
1.65      markus   1888:                options->use_privileged_port = 0;
1.50      markus   1889:        if (options->pubkey_authentication == -1)
                   1890:                options->pubkey_authentication = 1;
1.78      markus   1891:        if (options->challenge_response_authentication == -1)
1.83      markus   1892:                options->challenge_response_authentication = 1;
1.118     markus   1893:        if (options->gss_authentication == -1)
1.122     markus   1894:                options->gss_authentication = 0;
1.118     markus   1895:        if (options->gss_deleg_creds == -1)
                   1896:                options->gss_deleg_creds = 0;
1.17      markus   1897:        if (options->password_authentication == -1)
                   1898:                options->password_authentication = 1;
1.48      markus   1899:        if (options->kbd_interactive_authentication == -1)
1.59      markus   1900:                options->kbd_interactive_authentication = 1;
1.72      markus   1901:        if (options->hostbased_authentication == -1)
                   1902:                options->hostbased_authentication = 0;
1.17      markus   1903:        if (options->batch_mode == -1)
                   1904:                options->batch_mode = 0;
                   1905:        if (options->check_host_ip == -1)
                   1906:                options->check_host_ip = 1;
                   1907:        if (options->strict_host_key_checking == -1)
                   1908:                options->strict_host_key_checking = 2;  /* 2 is default */
                   1909:        if (options->compression == -1)
                   1910:                options->compression = 0;
1.126     markus   1911:        if (options->tcp_keep_alive == -1)
                   1912:                options->tcp_keep_alive = 1;
1.17      markus   1913:        if (options->port == -1)
                   1914:                options->port = 0;      /* Filled in ssh_connect. */
1.114     djm      1915:        if (options->address_family == -1)
                   1916:                options->address_family = AF_UNSPEC;
1.17      markus   1917:        if (options->connection_attempts == -1)
1.84      markus   1918:                options->connection_attempts = 1;
1.17      markus   1919:        if (options->number_of_password_prompts == -1)
                   1920:                options->number_of_password_prompts = 3;
1.76      markus   1921:        /* options->hostkeyalgorithms, default set in myproposals.h */
1.246     jcs      1922:        if (options->add_keys_to_agent == -1)
                   1923:                options->add_keys_to_agent = 0;
1.17      markus   1924:        if (options->num_identity_files == 0) {
1.273     djm      1925:                add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_RSA, 0);
                   1926:                add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_DSA, 0);
                   1927:                add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_ECDSA, 0);
                   1928:                add_identity_file(options, "~/",
                   1929:                    _PATH_SSH_CLIENT_ID_ED25519, 0);
1.27      markus   1930:        }
1.17      markus   1931:        if (options->escape_char == -1)
                   1932:                options->escape_char = '~';
1.193     djm      1933:        if (options->num_system_hostfiles == 0) {
                   1934:                options->system_hostfiles[options->num_system_hostfiles++] =
                   1935:                    xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
                   1936:                options->system_hostfiles[options->num_system_hostfiles++] =
                   1937:                    xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
                   1938:        }
                   1939:        if (options->num_user_hostfiles == 0) {
                   1940:                options->user_hostfiles[options->num_user_hostfiles++] =
                   1941:                    xstrdup(_PATH_SSH_USER_HOSTFILE);
                   1942:                options->user_hostfiles[options->num_user_hostfiles++] =
                   1943:                    xstrdup(_PATH_SSH_USER_HOSTFILE2);
                   1944:        }
1.95      markus   1945:        if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.54      markus   1946:                options->log_level = SYSLOG_LEVEL_INFO;
1.271     dtucker  1947:        if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
                   1948:                options->log_facility = SYSLOG_FACILITY_USER;
1.91      markus   1949:        if (options->no_host_authentication_for_localhost == - 1)
                   1950:                options->no_host_authentication_for_localhost = 0;
1.128     markus   1951:        if (options->identities_only == -1)
                   1952:                options->identities_only = 0;
1.101     markus   1953:        if (options->enable_ssh_keysign == -1)
                   1954:                options->enable_ssh_keysign = 0;
1.105     markus   1955:        if (options->rekey_limit == -1)
                   1956:                options->rekey_limit = 0;
1.198     dtucker  1957:        if (options->rekey_interval == -1)
                   1958:                options->rekey_interval = 0;
1.107     jakob    1959:        if (options->verify_host_key_dns == -1)
                   1960:                options->verify_host_key_dns = 0;
1.127     markus   1961:        if (options->server_alive_interval == -1)
                   1962:                options->server_alive_interval = 0;
                   1963:        if (options->server_alive_count_max == -1)
                   1964:                options->server_alive_count_max = 3;
1.132     djm      1965:        if (options->control_master == -1)
                   1966:                options->control_master = 0;
1.187     djm      1967:        if (options->control_persist == -1) {
                   1968:                options->control_persist = 0;
                   1969:                options->control_persist_timeout = 0;
                   1970:        }
1.136     djm      1971:        if (options->hash_known_hosts == -1)
                   1972:                options->hash_known_hosts = 0;
1.144     reyk     1973:        if (options->tun_open == -1)
1.145     reyk     1974:                options->tun_open = SSH_TUNMODE_NO;
                   1975:        if (options->tun_local == -1)
                   1976:                options->tun_local = SSH_TUNID_ANY;
                   1977:        if (options->tun_remote == -1)
                   1978:                options->tun_remote = SSH_TUNID_ANY;
1.144     reyk     1979:        if (options->permit_local_command == -1)
                   1980:                options->permit_local_command = 0;
1.167     grunk    1981:        if (options->visual_host_key == -1)
                   1982:                options->visual_host_key = 0;
1.190     djm      1983:        if (options->ip_qos_interactive == -1)
                   1984:                options->ip_qos_interactive = IPTOS_LOWDELAY;
                   1985:        if (options->ip_qos_bulk == -1)
                   1986:                options->ip_qos_bulk = IPTOS_THROUGHPUT;
1.192     djm      1987:        if (options->request_tty == -1)
                   1988:                options->request_tty = REQUEST_TTY_AUTO;
1.205     djm      1989:        if (options->proxy_use_fdpass == -1)
                   1990:                options->proxy_use_fdpass = 0;
1.209     djm      1991:        if (options->canonicalize_max_dots == -1)
                   1992:                options->canonicalize_max_dots = 1;
                   1993:        if (options->canonicalize_fallback_local == -1)
                   1994:                options->canonicalize_fallback_local = 1;
                   1995:        if (options->canonicalize_hostname == -1)
                   1996:                options->canonicalize_hostname = SSH_CANONICALISE_NO;
1.224     djm      1997:        if (options->fingerprint_hash == -1)
                   1998:                options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
1.229     djm      1999:        if (options->update_hostkeys == -1)
1.231     djm      2000:                options->update_hostkeys = 0;
1.239     djm      2001:        if (kex_assemble_names(KEX_CLIENT_ENCRYPT, &options->ciphers) != 0 ||
                   2002:            kex_assemble_names(KEX_CLIENT_MAC, &options->macs) != 0 ||
                   2003:            kex_assemble_names(KEX_CLIENT_KEX, &options->kex_algorithms) != 0 ||
                   2004:            kex_assemble_names(KEX_DEFAULT_PK_ALG,
                   2005:            &options->hostbased_key_types) != 0 ||
                   2006:            kex_assemble_names(KEX_DEFAULT_PK_ALG,
                   2007:            &options->pubkey_key_types) != 0)
                   2008:                fatal("%s: kex_assemble_names failed", __func__);
1.224     djm      2009:
1.207     djm      2010: #define CLEAR_ON_NONE(v) \
                   2011:        do { \
1.218     djm      2012:                if (option_clear_or_none(v)) { \
1.207     djm      2013:                        free(v); \
                   2014:                        v = NULL; \
                   2015:                } \
                   2016:        } while(0)
                   2017:        CLEAR_ON_NONE(options->local_command);
                   2018:        CLEAR_ON_NONE(options->proxy_command);
                   2019:        CLEAR_ON_NONE(options->control_path);
1.223     djm      2020:        CLEAR_ON_NONE(options->revoked_host_keys);
1.254     markus   2021:        /* options->identity_agent distinguishes NULL from 'none' */
1.17      markus   2022:        /* options->user will be set in the main program if appropriate */
                   2023:        /* options->hostname will be set in the main program if appropriate */
1.52      markus   2024:        /* options->host_key_alias should not be set by default */
1.67      markus   2025:        /* options->preferred_authentications will be set in ssh */
1.135     djm      2026: }
                   2027:
1.220     millert  2028: struct fwdarg {
                   2029:        char *arg;
                   2030:        int ispath;
                   2031: };
                   2032:
                   2033: /*
                   2034:  * parse_fwd_field
                   2035:  * parses the next field in a port forwarding specification.
                   2036:  * sets fwd to the parsed field and advances p past the colon
                   2037:  * or sets it to NULL at end of string.
                   2038:  * returns 0 on success, else non-zero.
                   2039:  */
                   2040: static int
                   2041: parse_fwd_field(char **p, struct fwdarg *fwd)
                   2042: {
                   2043:        char *ep, *cp = *p;
                   2044:        int ispath = 0;
                   2045:
                   2046:        if (*cp == '\0') {
                   2047:                *p = NULL;
                   2048:                return -1;      /* end of string */
                   2049:        }
                   2050:
                   2051:        /*
                   2052:         * A field escaped with square brackets is used literally.
                   2053:         * XXX - allow ']' to be escaped via backslash?
                   2054:         */
                   2055:        if (*cp == '[') {
                   2056:                /* find matching ']' */
                   2057:                for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
                   2058:                        if (*ep == '/')
                   2059:                                ispath = 1;
                   2060:                }
                   2061:                /* no matching ']' or not at end of field. */
                   2062:                if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
                   2063:                        return -1;
                   2064:                /* NUL terminate the field and advance p past the colon */
                   2065:                *ep++ = '\0';
                   2066:                if (*ep != '\0')
                   2067:                        *ep++ = '\0';
                   2068:                fwd->arg = cp + 1;
                   2069:                fwd->ispath = ispath;
                   2070:                *p = ep;
                   2071:                return 0;
                   2072:        }
                   2073:
                   2074:        for (cp = *p; *cp != '\0'; cp++) {
                   2075:                switch (*cp) {
                   2076:                case '\\':
                   2077:                        memmove(cp, cp + 1, strlen(cp + 1) + 1);
1.237     djm      2078:                        if (*cp == '\0')
                   2079:                                return -1;
1.220     millert  2080:                        break;
                   2081:                case '/':
                   2082:                        ispath = 1;
                   2083:                        break;
                   2084:                case ':':
                   2085:                        *cp++ = '\0';
                   2086:                        goto done;
                   2087:                }
                   2088:        }
                   2089: done:
                   2090:        fwd->arg = *p;
                   2091:        fwd->ispath = ispath;
                   2092:        *p = cp;
                   2093:        return 0;
                   2094: }
                   2095:
1.135     djm      2096: /*
                   2097:  * parse_forward
                   2098:  * parses a string containing a port forwarding specification of the form:
1.168     stevesk  2099:  *   dynamicfwd == 0
1.220     millert  2100:  *     [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
                   2101:  *     listenpath:connectpath
1.168     stevesk  2102:  *   dynamicfwd == 1
                   2103:  *     [listenhost:]listenport
1.135     djm      2104:  * returns number of arguments parsed or zero on error
                   2105:  */
                   2106: int
1.220     millert  2107: parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
1.135     djm      2108: {
1.220     millert  2109:        struct fwdarg fwdargs[4];
                   2110:        char *p, *cp;
1.135     djm      2111:        int i;
                   2112:
1.220     millert  2113:        memset(fwd, 0, sizeof(*fwd));
                   2114:        memset(fwdargs, 0, sizeof(fwdargs));
1.135     djm      2115:
                   2116:        cp = p = xstrdup(fwdspec);
                   2117:
                   2118:        /* skip leading spaces */
1.214     deraadt  2119:        while (isspace((u_char)*cp))
1.135     djm      2120:                cp++;
                   2121:
1.220     millert  2122:        for (i = 0; i < 4; ++i) {
                   2123:                if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
1.135     djm      2124:                        break;
1.220     millert  2125:        }
1.135     djm      2126:
1.170     stevesk  2127:        /* Check for trailing garbage */
1.220     millert  2128:        if (cp != NULL && *cp != '\0') {
1.135     djm      2129:                i = 0;  /* failure */
1.220     millert  2130:        }
1.135     djm      2131:
                   2132:        switch (i) {
1.168     stevesk  2133:        case 1:
1.220     millert  2134:                if (fwdargs[0].ispath) {
                   2135:                        fwd->listen_path = xstrdup(fwdargs[0].arg);
                   2136:                        fwd->listen_port = PORT_STREAMLOCAL;
                   2137:                } else {
                   2138:                        fwd->listen_host = NULL;
                   2139:                        fwd->listen_port = a2port(fwdargs[0].arg);
                   2140:                }
1.168     stevesk  2141:                fwd->connect_host = xstrdup("socks");
                   2142:                break;
                   2143:
                   2144:        case 2:
1.220     millert  2145:                if (fwdargs[0].ispath && fwdargs[1].ispath) {
                   2146:                        fwd->listen_path = xstrdup(fwdargs[0].arg);
                   2147:                        fwd->listen_port = PORT_STREAMLOCAL;
                   2148:                        fwd->connect_path = xstrdup(fwdargs[1].arg);
                   2149:                        fwd->connect_port = PORT_STREAMLOCAL;
                   2150:                } else if (fwdargs[1].ispath) {
                   2151:                        fwd->listen_host = NULL;
                   2152:                        fwd->listen_port = a2port(fwdargs[0].arg);
                   2153:                        fwd->connect_path = xstrdup(fwdargs[1].arg);
                   2154:                        fwd->connect_port = PORT_STREAMLOCAL;
                   2155:                } else {
                   2156:                        fwd->listen_host = xstrdup(fwdargs[0].arg);
                   2157:                        fwd->listen_port = a2port(fwdargs[1].arg);
                   2158:                        fwd->connect_host = xstrdup("socks");
                   2159:                }
1.168     stevesk  2160:                break;
                   2161:
1.135     djm      2162:        case 3:
1.220     millert  2163:                if (fwdargs[0].ispath) {
                   2164:                        fwd->listen_path = xstrdup(fwdargs[0].arg);
                   2165:                        fwd->listen_port = PORT_STREAMLOCAL;
                   2166:                        fwd->connect_host = xstrdup(fwdargs[1].arg);
                   2167:                        fwd->connect_port = a2port(fwdargs[2].arg);
                   2168:                } else if (fwdargs[2].ispath) {
                   2169:                        fwd->listen_host = xstrdup(fwdargs[0].arg);
                   2170:                        fwd->listen_port = a2port(fwdargs[1].arg);
                   2171:                        fwd->connect_path = xstrdup(fwdargs[2].arg);
                   2172:                        fwd->connect_port = PORT_STREAMLOCAL;
                   2173:                } else {
                   2174:                        fwd->listen_host = NULL;
                   2175:                        fwd->listen_port = a2port(fwdargs[0].arg);
                   2176:                        fwd->connect_host = xstrdup(fwdargs[1].arg);
                   2177:                        fwd->connect_port = a2port(fwdargs[2].arg);
                   2178:                }
1.135     djm      2179:                break;
                   2180:
                   2181:        case 4:
1.220     millert  2182:                fwd->listen_host = xstrdup(fwdargs[0].arg);
                   2183:                fwd->listen_port = a2port(fwdargs[1].arg);
                   2184:                fwd->connect_host = xstrdup(fwdargs[2].arg);
                   2185:                fwd->connect_port = a2port(fwdargs[3].arg);
1.135     djm      2186:                break;
                   2187:        default:
                   2188:                i = 0; /* failure */
                   2189:        }
                   2190:
1.202     djm      2191:        free(p);
1.135     djm      2192:
1.168     stevesk  2193:        if (dynamicfwd) {
                   2194:                if (!(i == 1 || i == 2))
                   2195:                        goto fail_free;
                   2196:        } else {
1.220     millert  2197:                if (!(i == 3 || i == 4)) {
                   2198:                        if (fwd->connect_path == NULL &&
                   2199:                            fwd->listen_path == NULL)
                   2200:                                goto fail_free;
                   2201:                }
                   2202:                if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
1.168     stevesk  2203:                        goto fail_free;
                   2204:        }
                   2205:
1.220     millert  2206:        if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
                   2207:            (!remotefwd && fwd->listen_port == 0))
1.135     djm      2208:                goto fail_free;
                   2209:        if (fwd->connect_host != NULL &&
                   2210:            strlen(fwd->connect_host) >= NI_MAXHOST)
                   2211:                goto fail_free;
1.220     millert  2212:        /* XXX - if connecting to a remote socket, max sun len may not match this host */
                   2213:        if (fwd->connect_path != NULL &&
                   2214:            strlen(fwd->connect_path) >= PATH_MAX_SUN)
                   2215:                goto fail_free;
1.176     djm      2216:        if (fwd->listen_host != NULL &&
                   2217:            strlen(fwd->listen_host) >= NI_MAXHOST)
                   2218:                goto fail_free;
1.220     millert  2219:        if (fwd->listen_path != NULL &&
                   2220:            strlen(fwd->listen_path) >= PATH_MAX_SUN)
                   2221:                goto fail_free;
1.135     djm      2222:
                   2223:        return (i);
                   2224:
                   2225:  fail_free:
1.202     djm      2226:        free(fwd->connect_host);
                   2227:        fwd->connect_host = NULL;
1.220     millert  2228:        free(fwd->connect_path);
                   2229:        fwd->connect_path = NULL;
1.202     djm      2230:        free(fwd->listen_host);
                   2231:        fwd->listen_host = NULL;
1.220     millert  2232:        free(fwd->listen_path);
                   2233:        fwd->listen_path = NULL;
1.135     djm      2234:        return (0);
1.221     djm      2235: }
                   2236:
1.257     djm      2237: int
                   2238: parse_jump(const char *s, Options *o, int active)
                   2239: {
                   2240:        char *orig, *sdup, *cp;
                   2241:        char *host = NULL, *user = NULL;
1.258     naddy    2242:        int ret = -1, port = -1, first;
1.257     djm      2243:
                   2244:        active &= o->proxy_command == NULL && o->jump_host == NULL;
                   2245:
                   2246:        orig = sdup = xstrdup(s);
1.258     naddy    2247:        first = active;
1.259     djm      2248:        do {
                   2249:                if ((cp = strrchr(sdup, ',')) == NULL)
                   2250:                        cp = sdup; /* last */
                   2251:                else
                   2252:                        *cp++ = '\0';
                   2253:
1.258     naddy    2254:                if (first) {
1.257     djm      2255:                        /* First argument and configuration is active */
                   2256:                        if (parse_user_host_port(cp, &user, &host, &port) != 0)
                   2257:                                goto out;
                   2258:                } else {
                   2259:                        /* Subsequent argument or inactive configuration */
                   2260:                        if (parse_user_host_port(cp, NULL, NULL, NULL) != 0)
                   2261:                                goto out;
                   2262:                }
1.258     naddy    2263:                first = 0; /* only check syntax for subsequent hosts */
1.259     djm      2264:        } while (cp != sdup);
1.257     djm      2265:        /* success */
1.258     naddy    2266:        if (active) {
                   2267:                o->jump_user = user;
                   2268:                o->jump_host = host;
                   2269:                o->jump_port = port;
                   2270:                o->proxy_command = xstrdup("none");
                   2271:                user = host = NULL;
1.259     djm      2272:                if ((cp = strrchr(s, ',')) != NULL && cp != s) {
                   2273:                        o->jump_extra = xstrdup(s);
                   2274:                        o->jump_extra[cp - s] = '\0';
                   2275:                }
1.258     naddy    2276:        }
1.257     djm      2277:        ret = 0;
                   2278:  out:
1.258     naddy    2279:        free(orig);
1.257     djm      2280:        free(user);
                   2281:        free(host);
                   2282:        return ret;
                   2283: }
                   2284:
1.221     djm      2285: /* XXX the following is a near-vebatim copy from servconf.c; refactor */
                   2286: static const char *
                   2287: fmt_multistate_int(int val, const struct multistate *m)
                   2288: {
                   2289:        u_int i;
                   2290:
                   2291:        for (i = 0; m[i].key != NULL; i++) {
                   2292:                if (m[i].value == val)
                   2293:                        return m[i].key;
                   2294:        }
                   2295:        return "UNKNOWN";
                   2296: }
                   2297:
                   2298: static const char *
                   2299: fmt_intarg(OpCodes code, int val)
                   2300: {
                   2301:        if (val == -1)
                   2302:                return "unset";
                   2303:        switch (code) {
                   2304:        case oAddressFamily:
                   2305:                return fmt_multistate_int(val, multistate_addressfamily);
                   2306:        case oVerifyHostKeyDNS:
                   2307:        case oStrictHostKeyChecking:
1.232     djm      2308:        case oUpdateHostkeys:
1.221     djm      2309:                return fmt_multistate_int(val, multistate_yesnoask);
                   2310:        case oControlMaster:
                   2311:                return fmt_multistate_int(val, multistate_controlmaster);
                   2312:        case oTunnel:
                   2313:                return fmt_multistate_int(val, multistate_tunnel);
                   2314:        case oRequestTTY:
                   2315:                return fmt_multistate_int(val, multistate_requesttty);
                   2316:        case oCanonicalizeHostname:
                   2317:                return fmt_multistate_int(val, multistate_canonicalizehostname);
1.224     djm      2318:        case oFingerprintHash:
                   2319:                return ssh_digest_alg_name(val);
1.221     djm      2320:        default:
                   2321:                switch (val) {
                   2322:                case 0:
                   2323:                        return "no";
                   2324:                case 1:
                   2325:                        return "yes";
                   2326:                default:
                   2327:                        return "UNKNOWN";
                   2328:                }
                   2329:        }
                   2330: }
                   2331:
                   2332: static const char *
                   2333: lookup_opcode_name(OpCodes code)
                   2334: {
                   2335:        u_int i;
                   2336:
                   2337:        for (i = 0; keywords[i].name != NULL; i++)
                   2338:                if (keywords[i].opcode == code)
                   2339:                        return(keywords[i].name);
                   2340:        return "UNKNOWN";
                   2341: }
                   2342:
                   2343: static void
                   2344: dump_cfg_int(OpCodes code, int val)
                   2345: {
                   2346:        printf("%s %d\n", lookup_opcode_name(code), val);
                   2347: }
                   2348:
                   2349: static void
                   2350: dump_cfg_fmtint(OpCodes code, int val)
                   2351: {
                   2352:        printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
                   2353: }
                   2354:
                   2355: static void
                   2356: dump_cfg_string(OpCodes code, const char *val)
                   2357: {
                   2358:        if (val == NULL)
                   2359:                return;
                   2360:        printf("%s %s\n", lookup_opcode_name(code), val);
                   2361: }
                   2362:
                   2363: static void
                   2364: dump_cfg_strarray(OpCodes code, u_int count, char **vals)
                   2365: {
                   2366:        u_int i;
                   2367:
                   2368:        for (i = 0; i < count; i++)
                   2369:                printf("%s %s\n", lookup_opcode_name(code), vals[i]);
                   2370: }
                   2371:
                   2372: static void
                   2373: dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
                   2374: {
                   2375:        u_int i;
                   2376:
                   2377:        printf("%s", lookup_opcode_name(code));
                   2378:        for (i = 0; i < count; i++)
                   2379:                printf(" %s",  vals[i]);
                   2380:        printf("\n");
                   2381: }
                   2382:
                   2383: static void
                   2384: dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
                   2385: {
                   2386:        const struct Forward *fwd;
                   2387:        u_int i;
                   2388:
                   2389:        /* oDynamicForward */
                   2390:        for (i = 0; i < count; i++) {
                   2391:                fwd = &fwds[i];
1.265     djm      2392:                if (code == oDynamicForward && fwd->connect_host != NULL &&
1.221     djm      2393:                    strcmp(fwd->connect_host, "socks") != 0)
                   2394:                        continue;
1.265     djm      2395:                if (code == oLocalForward && fwd->connect_host != NULL &&
1.221     djm      2396:                    strcmp(fwd->connect_host, "socks") == 0)
                   2397:                        continue;
                   2398:                printf("%s", lookup_opcode_name(code));
                   2399:                if (fwd->listen_port == PORT_STREAMLOCAL)
                   2400:                        printf(" %s", fwd->listen_path);
                   2401:                else if (fwd->listen_host == NULL)
                   2402:                        printf(" %d", fwd->listen_port);
                   2403:                else {
                   2404:                        printf(" [%s]:%d",
                   2405:                            fwd->listen_host, fwd->listen_port);
                   2406:                }
                   2407:                if (code != oDynamicForward) {
                   2408:                        if (fwd->connect_port == PORT_STREAMLOCAL)
                   2409:                                printf(" %s", fwd->connect_path);
                   2410:                        else if (fwd->connect_host == NULL)
                   2411:                                printf(" %d", fwd->connect_port);
                   2412:                        else {
                   2413:                                printf(" [%s]:%d",
                   2414:                                    fwd->connect_host, fwd->connect_port);
                   2415:                        }
                   2416:                }
                   2417:                printf("\n");
                   2418:        }
                   2419: }
                   2420:
                   2421: void
                   2422: dump_client_config(Options *o, const char *host)
                   2423: {
                   2424:        int i;
1.257     djm      2425:        char buf[8];
1.221     djm      2426:
1.240     djm      2427:        /* This is normally prepared in ssh_kex2 */
                   2428:        if (kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->hostkeyalgorithms) != 0)
                   2429:                fatal("%s: kex_assemble_names failed", __func__);
                   2430:
1.221     djm      2431:        /* Most interesting options first: user, host, port */
                   2432:        dump_cfg_string(oUser, o->user);
                   2433:        dump_cfg_string(oHostName, host);
                   2434:        dump_cfg_int(oPort, o->port);
                   2435:
                   2436:        /* Flag options */
                   2437:        dump_cfg_fmtint(oAddressFamily, o->address_family);
                   2438:        dump_cfg_fmtint(oBatchMode, o->batch_mode);
                   2439:        dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
                   2440:        dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
                   2441:        dump_cfg_fmtint(oChallengeResponseAuthentication, o->challenge_response_authentication);
                   2442:        dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
                   2443:        dump_cfg_fmtint(oCompression, o->compression);
                   2444:        dump_cfg_fmtint(oControlMaster, o->control_master);
                   2445:        dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
1.256     dtucker  2446:        dump_cfg_fmtint(oClearAllForwardings, o->clear_forwardings);
1.221     djm      2447:        dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
1.224     djm      2448:        dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
1.221     djm      2449:        dump_cfg_fmtint(oForwardAgent, o->forward_agent);
                   2450:        dump_cfg_fmtint(oForwardX11, o->forward_x11);
                   2451:        dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
                   2452:        dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
                   2453: #ifdef GSSAPI
                   2454:        dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
                   2455:        dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
                   2456: #endif /* GSSAPI */
                   2457:        dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
                   2458:        dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
                   2459:        dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
                   2460:        dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
                   2461:        dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
                   2462:        dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
                   2463:        dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
                   2464:        dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
                   2465:        dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
                   2466:        dump_cfg_fmtint(oRequestTTY, o->request_tty);
                   2467:        dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
                   2468:        dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
                   2469:        dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
                   2470:        dump_cfg_fmtint(oTunnel, o->tun_open);
                   2471:        dump_cfg_fmtint(oUsePrivilegedPort, o->use_privileged_port);
                   2472:        dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
                   2473:        dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
1.229     djm      2474:        dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
1.221     djm      2475:
                   2476:        /* Integer options */
                   2477:        dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
                   2478:        dump_cfg_int(oConnectionAttempts, o->connection_attempts);
                   2479:        dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
                   2480:        dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
                   2481:        dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
                   2482:        dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
                   2483:
                   2484:        /* String options */
                   2485:        dump_cfg_string(oBindAddress, o->bind_address);
                   2486:        dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
                   2487:        dump_cfg_string(oControlPath, o->control_path);
1.240     djm      2488:        dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
1.221     djm      2489:        dump_cfg_string(oHostKeyAlias, o->host_key_alias);
1.230     djm      2490:        dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
1.253     markus   2491:        dump_cfg_string(oIdentityAgent, o->identity_agent);
1.221     djm      2492:        dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
                   2493:        dump_cfg_string(oKexAlgorithms, o->kex_algorithms ? o->kex_algorithms : KEX_CLIENT_KEX);
                   2494:        dump_cfg_string(oLocalCommand, o->local_command);
                   2495:        dump_cfg_string(oLogLevel, log_level_name(o->log_level));
                   2496:        dump_cfg_string(oMacs, o->macs ? o->macs : KEX_CLIENT_MAC);
1.266     djm      2497: #ifdef ENABLE_PKCS11
1.221     djm      2498:        dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
1.266     djm      2499: #endif
1.221     djm      2500:        dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
1.242     djm      2501:        dump_cfg_string(oPubkeyAcceptedKeyTypes, o->pubkey_key_types);
1.230     djm      2502:        dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
1.221     djm      2503:        dump_cfg_string(oXAuthLocation, o->xauth_location);
                   2504:
1.230     djm      2505:        /* Forwards */
1.221     djm      2506:        dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
                   2507:        dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
                   2508:        dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
                   2509:
                   2510:        /* String array options */
                   2511:        dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
                   2512:        dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
                   2513:        dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
                   2514:        dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
                   2515:        dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
                   2516:
                   2517:        /* Special cases */
                   2518:
                   2519:        /* oConnectTimeout */
                   2520:        if (o->connection_timeout == -1)
                   2521:                printf("connecttimeout none\n");
                   2522:        else
                   2523:                dump_cfg_int(oConnectTimeout, o->connection_timeout);
                   2524:
                   2525:        /* oTunnelDevice */
                   2526:        printf("tunneldevice");
                   2527:        if (o->tun_local == SSH_TUNID_ANY)
                   2528:                printf(" any");
                   2529:        else
                   2530:                printf(" %d", o->tun_local);
                   2531:        if (o->tun_remote == SSH_TUNID_ANY)
                   2532:                printf(":any");
                   2533:        else
                   2534:                printf(":%d", o->tun_remote);
                   2535:        printf("\n");
                   2536:
                   2537:        /* oCanonicalizePermittedCNAMEs */
                   2538:        if ( o->num_permitted_cnames > 0) {
                   2539:                printf("canonicalizePermittedcnames");
                   2540:                for (i = 0; i < o->num_permitted_cnames; i++) {
                   2541:                        printf(" %s:%s", o->permitted_cnames[i].source_list,
                   2542:                            o->permitted_cnames[i].target_list);
                   2543:                }
                   2544:                printf("\n");
                   2545:        }
                   2546:
                   2547:        /* oControlPersist */
                   2548:        if (o->control_persist == 0 || o->control_persist_timeout == 0)
                   2549:                dump_cfg_fmtint(oControlPersist, o->control_persist);
                   2550:        else
                   2551:                dump_cfg_int(oControlPersist, o->control_persist_timeout);
                   2552:
                   2553:        /* oEscapeChar */
                   2554:        if (o->escape_char == SSH_ESCAPECHAR_NONE)
                   2555:                printf("escapechar none\n");
                   2556:        else {
1.257     djm      2557:                vis(buf, o->escape_char, VIS_WHITE, 0);
                   2558:                printf("escapechar %s\n", buf);
1.221     djm      2559:        }
                   2560:
                   2561:        /* oIPQoS */
                   2562:        printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
                   2563:        printf("%s\n", iptos2str(o->ip_qos_bulk));
                   2564:
                   2565:        /* oRekeyLimit */
1.249     dtucker  2566:        printf("rekeylimit %llu %d\n",
                   2567:            (unsigned long long)o->rekey_limit, o->rekey_interval);
1.221     djm      2568:
                   2569:        /* oStreamLocalBindMask */
                   2570:        printf("streamlocalbindmask 0%o\n",
                   2571:            o->fwd_opts.streamlocal_bind_mask);
1.257     djm      2572:
                   2573:        /* oProxyCommand / oProxyJump */
                   2574:        if (o->jump_host == NULL)
                   2575:                dump_cfg_string(oProxyCommand, o->proxy_command);
                   2576:        else {
                   2577:                /* Check for numeric addresses */
                   2578:                i = strchr(o->jump_host, ':') != NULL ||
                   2579:                    strspn(o->jump_host, "1234567890.") == strlen(o->jump_host);
                   2580:                snprintf(buf, sizeof(buf), "%d", o->jump_port);
                   2581:                printf("proxyjump %s%s%s%s%s%s%s%s%s\n",
1.259     djm      2582:                    /* optional additional jump spec */
                   2583:                    o->jump_extra == NULL ? "" : o->jump_extra,
                   2584:                    o->jump_extra == NULL ? "" : ",",
1.257     djm      2585:                    /* optional user */
                   2586:                    o->jump_user == NULL ? "" : o->jump_user,
                   2587:                    o->jump_user == NULL ? "" : "@",
                   2588:                    /* opening [ if hostname is numeric */
                   2589:                    i ? "[" : "",
                   2590:                    /* mandatory hostname */
                   2591:                    o->jump_host,
                   2592:                    /* closing ] if hostname is numeric */
                   2593:                    i ? "]" : "",
                   2594:                    /* optional port number */
                   2595:                    o->jump_port <= 0 ? "" : ":",
1.259     djm      2596:                    o->jump_port <= 0 ? "" : buf);
1.257     djm      2597:        }
1.1       deraadt  2598: }