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

1.358   ! dtucker     1: /* $OpenBSD: readconf.c,v 1.357 2021/06/08 22:06:12 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.312     deraadt    34: #include <stdarg.h>
1.156     stevesk    35: #include <unistd.h>
1.228     deraadt    36: #include <limits.h>
1.200     dtucker    37: #include <util.h>
1.221     djm        38: #include <vis.h>
1.1       deraadt    39:
1.159     deraadt    40: #include "xmalloc.h"
1.1       deraadt    41: #include "ssh.h"
1.297     djm        42: #include "ssherr.h"
1.25      markus     43: #include "compat.h"
1.58      markus     44: #include "cipher.h"
1.55      markus     45: #include "pathnames.h"
1.58      markus     46: #include "log.h"
1.227     djm        47: #include "sshkey.h"
1.220     millert    48: #include "misc.h"
1.58      markus     49: #include "readconf.h"
                     50: #include "match.h"
1.62      markus     51: #include "kex.h"
                     52: #include "mac.h"
1.206     djm        53: #include "uidswap.h"
1.221     djm        54: #include "myproposal.h"
1.224     djm        55: #include "digest.h"
1.1       deraadt    56:
                     57: /* Format of the configuration file:
                     58:
                     59:    # Configuration data is parsed as follows:
                     60:    #  1. command line options
                     61:    #  2. user-specific file
                     62:    #  3. system-wide file
                     63:    # Any configuration value is only changed the first time it is set.
                     64:    # Thus, host-specific definitions should be at the beginning of the
                     65:    # configuration file, and defaults at the end.
                     66:
                     67:    # Host-specific declarations.  These may override anything above.  A single
                     68:    # host may match multiple declarations; these are processed in the order
                     69:    # that they are given in.
                     70:
                     71:    Host *.ngs.fi ngs.fi
1.96      markus     72:      User foo
1.1       deraadt    73:
                     74:    Host fake.com
1.306     jmc        75:      Hostname another.host.name.real.org
1.1       deraadt    76:      User blaah
                     77:      Port 34289
                     78:      ForwardX11 no
                     79:      ForwardAgent no
                     80:
                     81:    Host books.com
                     82:      RemoteForward 9999 shadows.cs.hut.fi:9999
1.266     djm        83:      Ciphers 3des-cbc
1.1       deraadt    84:
                     85:    Host fascist.blob.com
                     86:      Port 23123
                     87:      User tylonen
                     88:      PasswordAuthentication no
                     89:
                     90:    Host puukko.hut.fi
                     91:      User t35124p
                     92:      ProxyCommand ssh-proxy %h %p
                     93:
                     94:    Host *.fr
1.96      markus     95:      PublicKeyAuthentication no
1.1       deraadt    96:
                     97:    Host *.su
1.266     djm        98:      Ciphers aes128-ctr
1.1       deraadt    99:      PasswordAuthentication no
                    100:
1.144     reyk      101:    Host vpn.fake.com
                    102:      Tunnel yes
                    103:      TunnelDevice 3
                    104:
1.1       deraadt   105:    # Defaults for various options
                    106:    Host *
                    107:      ForwardAgent no
1.50      markus    108:      ForwardX11 no
1.1       deraadt   109:      PasswordAuthentication 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,
1.302     djm       120:     int flags, int *activep, int *want_final_pass, int depth);
1.252     djm       121: static int process_config_line_depth(Options *options, struct passwd *pw,
                    122:     const char *host, const char *original_host, char *line,
1.302     djm       123:     const char *filename, int linenum, int *activep, int flags,
                    124:     int *want_final_pass, int depth);
1.252     djm       125:
1.1       deraadt   126: /* Keyword tokens. */
                    127:
1.17      markus    128: typedef enum {
                    129:        oBadOption,
1.252     djm       130:        oHost, oMatch, oInclude,
1.186     djm       131:        oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
                    132:        oGatewayPorts, oExitOnForwardFailure,
1.317     dtucker   133:        oPasswordAuthentication,
1.358   ! dtucker   134:        oXAuthLocation,
1.317     dtucker   135:        oIdentityFile, oHostname, oPort, oRemoteForward, oLocalForward,
1.351     markus    136:        oPermitRemoteOpen,
1.253     markus    137:        oCertificateFile, oAddKeysToAgent, oIdentityAgent,
1.317     dtucker   138:        oUser, oEscapeChar, oProxyCommand,
1.17      markus    139:        oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
                    140:        oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
1.317     dtucker   141:        oTCPKeepAlive, oNumberOfPasswordPrompts,
1.339     djm       142:        oLogFacility, oLogLevel, oLogVerbose, oCiphers, oMacs,
1.221     djm       143:        oPubkeyAuthentication,
1.67      markus    144:        oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
1.76      markus    145:        oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
1.282     djm       146:        oHostKeyAlgorithms, oBindAddress, oBindInterface, oPKCS11Provider,
1.96      markus    147:        oClearAllForwardings, oNoHostAuthenticationForLocalhost,
1.111     djm       148:        oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
1.118     markus    149:        oAddressFamily, oGssAuthentication, oGssDelegateCreds,
1.128     markus    150:        oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
1.290     djm       151:        oSendEnv, oSetEnv, oControlPath, oControlMaster, oControlPersist,
1.187     djm       152:        oHashKnownHosts,
1.277     bluhm     153:        oTunnel, oTunnelDevice,
                    154:        oLocalCommand, oPermitLocalCommand, oRemoteCommand,
1.248     markus    155:        oVisualHostKey,
1.205     djm       156:        oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,
1.209     djm       157:        oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
                    158:        oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,
1.223     djm       159:        oStreamLocalBindMask, oStreamLocalBindUnlink, oRevokedHostKeys,
1.350     dtucker   160:        oFingerprintHash, oUpdateHostkeys, oHostbasedAcceptedAlgorithms,
1.349     dtucker   161:        oPubkeyAcceptedAlgorithms, oCASignatureAlgorithms, oProxyJump,
1.346     djm       162:        oSecurityKeyProvider, oKnownHostsCommand,
1.273     djm       163:        oIgnore, oIgnoredUnknownOption, oDeprecated, oUnsupported
1.1       deraadt   164: } OpCodes;
                    165:
                    166: /* Textual representations of the tokens. */
                    167:
1.17      markus    168: static struct {
                    169:        const char *name;
                    170:        OpCodes opcode;
                    171: } keywords[] = {
1.266     djm       172:        /* Deprecated options */
1.273     djm       173:        { "protocol", oIgnore }, /* NB. silently ignored */
1.274     djm       174:        { "cipher", oDeprecated },
1.266     djm       175:        { "fallbacktorsh", oDeprecated },
                    176:        { "globalknownhostsfile2", oDeprecated },
                    177:        { "rhostsauthentication", oDeprecated },
                    178:        { "userknownhostsfile2", oDeprecated },
                    179:        { "useroaming", oDeprecated },
                    180:        { "usersh", oDeprecated },
1.294     dtucker   181:        { "useprivilegedport", oDeprecated },
1.266     djm       182:
                    183:        /* Unsupported options */
                    184:        { "afstokenpassing", oUnsupported },
                    185:        { "kerberosauthentication", oUnsupported },
                    186:        { "kerberostgtpassing", oUnsupported },
1.318     dtucker   187:        { "rsaauthentication", oUnsupported },
                    188:        { "rhostsrsaauthentication", oUnsupported },
                    189:        { "compressionlevel", oUnsupported },
1.266     djm       190:
                    191:        /* Sometimes-unsupported options */
                    192: #if defined(GSSAPI)
                    193:        { "gssapiauthentication", oGssAuthentication },
                    194:        { "gssapidelegatecredentials", oGssDelegateCreds },
                    195: # else
                    196:        { "gssapiauthentication", oUnsupported },
                    197:        { "gssapidelegatecredentials", oUnsupported },
                    198: #endif
                    199: #ifdef ENABLE_PKCS11
1.304     djm       200:        { "pkcs11provider", oPKCS11Provider },
1.266     djm       201:        { "smartcarddevice", oPKCS11Provider },
                    202: # else
                    203:        { "smartcarddevice", oUnsupported },
                    204:        { "pkcs11provider", oUnsupported },
                    205: #endif
                    206:
1.17      markus    207:        { "forwardagent", oForwardAgent },
                    208:        { "forwardx11", oForwardX11 },
1.123     markus    209:        { "forwardx11trusted", oForwardX11Trusted },
1.186     djm       210:        { "forwardx11timeout", oForwardX11Timeout },
1.153     markus    211:        { "exitonforwardfailure", oExitOnForwardFailure },
1.34      markus    212:        { "xauthlocation", oXAuthLocation },
1.17      markus    213:        { "gatewayports", oGatewayPorts },
                    214:        { "passwordauthentication", oPasswordAuthentication },
1.48      markus    215:        { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
                    216:        { "kbdinteractivedevices", oKbdInteractiveDevices },
1.358   ! dtucker   217:        { "challengeresponseauthentication", oKbdInteractiveAuthentication }, /* alias */
        !           218:        { "skeyauthentication", oKbdInteractiveAuthentication }, /* alias */
        !           219:        { "tisauthentication", oKbdInteractiveAuthentication },  /* alias */
1.50      markus    220:        { "pubkeyauthentication", oPubkeyAuthentication },
1.59      markus    221:        { "dsaauthentication", oPubkeyAuthentication },             /* alias */
1.73      markus    222:        { "hostbasedauthentication", oHostbasedAuthentication },
1.17      markus    223:        { "identityfile", oIdentityFile },
1.174     stevesk   224:        { "identityfile2", oIdentityFile },                     /* obsolete */
1.128     markus    225:        { "identitiesonly", oIdentitiesOnly },
1.241     djm       226:        { "certificatefile", oCertificateFile },
1.246     jcs       227:        { "addkeystoagent", oAddKeysToAgent },
1.253     markus    228:        { "identityagent", oIdentityAgent },
1.306     jmc       229:        { "hostname", oHostname },
1.52      markus    230:        { "hostkeyalias", oHostKeyAlias },
1.17      markus    231:        { "proxycommand", oProxyCommand },
                    232:        { "port", oPort },
1.25      markus    233:        { "ciphers", oCiphers },
1.62      markus    234:        { "macs", oMacs },
1.17      markus    235:        { "remoteforward", oRemoteForward },
                    236:        { "localforward", oLocalForward },
1.351     markus    237:        { "permitremoteopen", oPermitRemoteOpen },
1.17      markus    238:        { "user", oUser },
                    239:        { "host", oHost },
1.206     djm       240:        { "match", oMatch },
1.17      markus    241:        { "escapechar", oEscapeChar },
                    242:        { "globalknownhostsfile", oGlobalKnownHostsFile },
1.174     stevesk   243:        { "userknownhostsfile", oUserKnownHostsFile },
1.17      markus    244:        { "connectionattempts", oConnectionAttempts },
                    245:        { "batchmode", oBatchMode },
                    246:        { "checkhostip", oCheckHostIP },
                    247:        { "stricthostkeychecking", oStrictHostKeyChecking },
                    248:        { "compression", oCompression },
1.126     markus    249:        { "tcpkeepalive", oTCPKeepAlive },
                    250:        { "keepalive", oTCPKeepAlive },                         /* obsolete */
1.17      markus    251:        { "numberofpasswordprompts", oNumberOfPasswordPrompts },
1.271     dtucker   252:        { "syslogfacility", oLogFacility },
1.17      markus    253:        { "loglevel", oLogLevel },
1.339     djm       254:        { "logverbose", oLogVerbose },
1.71      markus    255:        { "dynamicforward", oDynamicForward },
1.67      markus    256:        { "preferredauthentications", oPreferredAuthentications },
1.76      markus    257:        { "hostkeyalgorithms", oHostKeyAlgorithms },
1.298     djm       258:        { "casignaturealgorithms", oCASignatureAlgorithms },
1.77      markus    259:        { "bindaddress", oBindAddress },
1.282     djm       260:        { "bindinterface", oBindInterface },
1.93      deraadt   261:        { "clearallforwardings", oClearAllForwardings },
1.101     markus    262:        { "enablesshkeysign", oEnableSSHKeysign },
1.107     jakob     263:        { "verifyhostkeydns", oVerifyHostKeyDNS },
1.93      deraadt   264:        { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
1.105     markus    265:        { "rekeylimit", oRekeyLimit },
1.111     djm       266:        { "connecttimeout", oConnectTimeout },
1.112     djm       267:        { "addressfamily", oAddressFamily },
1.127     markus    268:        { "serveraliveinterval", oServerAliveInterval },
                    269:        { "serveralivecountmax", oServerAliveCountMax },
1.130     djm       270:        { "sendenv", oSendEnv },
1.290     djm       271:        { "setenv", oSetEnv },
1.132     djm       272:        { "controlpath", oControlPath },
                    273:        { "controlmaster", oControlMaster },
1.187     djm       274:        { "controlpersist", oControlPersist },
1.136     djm       275:        { "hashknownhosts", oHashKnownHosts },
1.252     djm       276:        { "include", oInclude },
1.144     reyk      277:        { "tunnel", oTunnel },
                    278:        { "tunneldevice", oTunnelDevice },
                    279:        { "localcommand", oLocalCommand },
                    280:        { "permitlocalcommand", oPermitLocalCommand },
1.277     bluhm     281:        { "remotecommand", oRemoteCommand },
1.167     grunk     282:        { "visualhostkey", oVisualHostKey },
1.189     djm       283:        { "kexalgorithms", oKexAlgorithms },
1.190     djm       284:        { "ipqos", oIPQoS },
1.192     djm       285:        { "requesttty", oRequestTTY },
1.205     djm       286:        { "proxyusefdpass", oProxyUseFdpass },
1.208     djm       287:        { "canonicaldomains", oCanonicalDomains },
1.209     djm       288:        { "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
                    289:        { "canonicalizehostname", oCanonicalizeHostname },
                    290:        { "canonicalizemaxdots", oCanonicalizeMaxDots },
                    291:        { "canonicalizepermittedcnames", oCanonicalizePermittedCNAMEs },
1.220     millert   292:        { "streamlocalbindmask", oStreamLocalBindMask },
                    293:        { "streamlocalbindunlink", oStreamLocalBindUnlink },
1.223     djm       294:        { "revokedhostkeys", oRevokedHostKeys },
1.224     djm       295:        { "fingerprinthash", oFingerprintHash },
1.229     djm       296:        { "updatehostkeys", oUpdateHostkeys },
1.354     naddy     297:        { "hostbasedacceptedalgorithms", oHostbasedAcceptedAlgorithms },
1.350     dtucker   298:        { "hostbasedkeytypes", oHostbasedAcceptedAlgorithms }, /* obsolete */
1.352     dtucker   299:        { "pubkeyacceptedalgorithms", oPubkeyAcceptedAlgorithms },
1.349     dtucker   300:        { "pubkeyacceptedkeytypes", oPubkeyAcceptedAlgorithms }, /* obsolete */
1.199     djm       301:        { "ignoreunknown", oIgnoreUnknown },
1.257     djm       302:        { "proxyjump", oProxyJump },
1.318     dtucker   303:        { "securitykeyprovider", oSecurityKeyProvider },
1.346     djm       304:        { "knownhostscommand", oKnownHostsCommand },
1.171     djm       305:
1.92      stevesk   306:        { NULL, oBadOption }
1.13      markus    307: };
                    308:
1.351     markus    309: static const char *lookup_opcode_name(OpCodes code);
1.320     dtucker   310:
                    311: const char *
                    312: kex_default_pk_alg(void)
                    313: {
1.344     djm       314:        static char *pkalgs;
                    315:
                    316:        if (pkalgs == NULL) {
                    317:                char *all_key;
                    318:
                    319:                all_key = sshkey_alg_list(0, 0, 1, ',');
                    320:                pkalgs = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
                    321:                free(all_key);
                    322:        }
                    323:        return pkalgs;
1.320     dtucker   324: }
                    325:
1.327     dtucker   326: char *
                    327: ssh_connection_hash(const char *thishost, const char *host, const char *portstr,
                    328:     const char *user)
                    329: {
                    330:        struct ssh_digest_ctx *md;
                    331:        u_char conn_hash[SSH_DIGEST_MAX_LENGTH];
                    332:
                    333:        if ((md = ssh_digest_start(SSH_DIGEST_SHA1)) == NULL ||
                    334:            ssh_digest_update(md, thishost, strlen(thishost)) < 0 ||
                    335:            ssh_digest_update(md, host, strlen(host)) < 0 ||
                    336:            ssh_digest_update(md, portstr, strlen(portstr)) < 0 ||
                    337:            ssh_digest_update(md, user, strlen(user)) < 0 ||
                    338:            ssh_digest_final(md, conn_hash, sizeof(conn_hash)) < 0)
1.340     djm       339:                fatal_f("mux digest failed");
1.327     dtucker   340:        ssh_digest_free(md);
                    341:        return tohex(conn_hash, ssh_digest_bytes(SSH_DIGEST_SHA1));
                    342: }
                    343:
1.19      markus    344: /*
                    345:  * Adds a local TCP/IP port forward to options.  Never returns if there is an
                    346:  * error.
                    347:  */
1.1       deraadt   348:
1.26      markus    349: void
1.220     millert   350: add_local_forward(Options *options, const struct Forward *newfwd)
1.1       deraadt   351: {
1.220     millert   352:        struct Forward *fwd;
1.251     djm       353:        int i;
1.185     djm       354:
1.251     djm       355:        /* Don't add duplicates */
                    356:        for (i = 0; i < options->num_local_forwards; i++) {
                    357:                if (forward_equals(newfwd, options->local_forwards + i))
                    358:                        return;
                    359:        }
1.234     deraadt   360:        options->local_forwards = xreallocarray(options->local_forwards,
1.185     djm       361:            options->num_local_forwards + 1,
                    362:            sizeof(*options->local_forwards));
1.17      markus    363:        fwd = &options->local_forwards[options->num_local_forwards++];
1.135     djm       364:
1.172     stevesk   365:        fwd->listen_host = newfwd->listen_host;
1.135     djm       366:        fwd->listen_port = newfwd->listen_port;
1.220     millert   367:        fwd->listen_path = newfwd->listen_path;
1.172     stevesk   368:        fwd->connect_host = newfwd->connect_host;
1.135     djm       369:        fwd->connect_port = newfwd->connect_port;
1.220     millert   370:        fwd->connect_path = newfwd->connect_path;
1.1       deraadt   371: }
                    372:
1.19      markus    373: /*
                    374:  * Adds a remote TCP/IP port forward to options.  Never returns if there is
                    375:  * an error.
                    376:  */
1.1       deraadt   377:
1.26      markus    378: void
1.220     millert   379: add_remote_forward(Options *options, const struct Forward *newfwd)
1.1       deraadt   380: {
1.220     millert   381:        struct Forward *fwd;
1.251     djm       382:        int i;
1.185     djm       383:
1.251     djm       384:        /* Don't add duplicates */
                    385:        for (i = 0; i < options->num_remote_forwards; i++) {
                    386:                if (forward_equals(newfwd, options->remote_forwards + i))
                    387:                        return;
                    388:        }
1.234     deraadt   389:        options->remote_forwards = xreallocarray(options->remote_forwards,
1.185     djm       390:            options->num_remote_forwards + 1,
                    391:            sizeof(*options->remote_forwards));
1.17      markus    392:        fwd = &options->remote_forwards[options->num_remote_forwards++];
1.135     djm       393:
1.172     stevesk   394:        fwd->listen_host = newfwd->listen_host;
1.135     djm       395:        fwd->listen_port = newfwd->listen_port;
1.220     millert   396:        fwd->listen_path = newfwd->listen_path;
1.172     stevesk   397:        fwd->connect_host = newfwd->connect_host;
1.135     djm       398:        fwd->connect_port = newfwd->connect_port;
1.220     millert   399:        fwd->connect_path = newfwd->connect_path;
1.194     markus    400:        fwd->handle = newfwd->handle;
1.184     markus    401:        fwd->allocated_port = 0;
1.1       deraadt   402: }
                    403:
1.90      stevesk   404: static void
                    405: clear_forwardings(Options *options)
                    406: {
                    407:        int i;
                    408:
1.135     djm       409:        for (i = 0; i < options->num_local_forwards; i++) {
1.202     djm       410:                free(options->local_forwards[i].listen_host);
1.220     millert   411:                free(options->local_forwards[i].listen_path);
1.202     djm       412:                free(options->local_forwards[i].connect_host);
1.220     millert   413:                free(options->local_forwards[i].connect_path);
1.135     djm       414:        }
1.185     djm       415:        if (options->num_local_forwards > 0) {
1.202     djm       416:                free(options->local_forwards);
1.185     djm       417:                options->local_forwards = NULL;
                    418:        }
1.90      stevesk   419:        options->num_local_forwards = 0;
1.135     djm       420:        for (i = 0; i < options->num_remote_forwards; i++) {
1.202     djm       421:                free(options->remote_forwards[i].listen_host);
1.220     millert   422:                free(options->remote_forwards[i].listen_path);
1.202     djm       423:                free(options->remote_forwards[i].connect_host);
1.220     millert   424:                free(options->remote_forwards[i].connect_path);
1.135     djm       425:        }
1.185     djm       426:        if (options->num_remote_forwards > 0) {
1.202     djm       427:                free(options->remote_forwards);
1.185     djm       428:                options->remote_forwards = NULL;
                    429:        }
1.90      stevesk   430:        options->num_remote_forwards = 0;
1.145     reyk      431:        options->tun_open = SSH_TUNMODE_NO;
1.90      stevesk   432: }
                    433:
1.195     dtucker   434: void
1.241     djm       435: add_certificate_file(Options *options, const char *path, int userprovided)
                    436: {
                    437:        int i;
                    438:
                    439:        if (options->num_certificate_files >= SSH_MAX_CERTIFICATE_FILES)
                    440:                fatal("Too many certificate files specified (max %d)",
                    441:                    SSH_MAX_CERTIFICATE_FILES);
                    442:
                    443:        /* Avoid registering duplicates */
                    444:        for (i = 0; i < options->num_certificate_files; i++) {
                    445:                if (options->certificate_file_userprovided[i] == userprovided &&
                    446:                    strcmp(options->certificate_files[i], path) == 0) {
1.340     djm       447:                        debug2_f("ignoring duplicate key %s", path);
1.241     djm       448:                        return;
                    449:                }
                    450:        }
                    451:
                    452:        options->certificate_file_userprovided[options->num_certificate_files] =
                    453:            userprovided;
                    454:        options->certificate_files[options->num_certificate_files++] =
                    455:            xstrdup(path);
                    456: }
                    457:
                    458: void
1.195     dtucker   459: add_identity_file(Options *options, const char *dir, const char *filename,
                    460:     int userprovided)
                    461: {
                    462:        char *path;
1.219     djm       463:        int i;
1.195     dtucker   464:
                    465:        if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
                    466:                fatal("Too many identity files specified (max %d)",
                    467:                    SSH_MAX_IDENTITY_FILES);
                    468:
                    469:        if (dir == NULL) /* no dir, filename is absolute */
                    470:                path = xstrdup(filename);
1.276     djm       471:        else if (xasprintf(&path, "%s%s", dir, filename) >= PATH_MAX)
                    472:                fatal("Identity file path %s too long", path);
1.219     djm       473:
                    474:        /* Avoid registering duplicates */
                    475:        for (i = 0; i < options->num_identity_files; i++) {
                    476:                if (options->identity_file_userprovided[i] == userprovided &&
                    477:                    strcmp(options->identity_files[i], path) == 0) {
1.340     djm       478:                        debug2_f("ignoring duplicate key %s", path);
1.219     djm       479:                        free(path);
                    480:                        return;
                    481:                }
                    482:        }
1.195     dtucker   483:
                    484:        options->identity_file_userprovided[options->num_identity_files] =
                    485:            userprovided;
                    486:        options->identity_files[options->num_identity_files++] = path;
                    487: }
                    488:
1.206     djm       489: int
                    490: default_ssh_port(void)
                    491: {
                    492:        static int port;
                    493:        struct servent *sp;
                    494:
                    495:        if (port == 0) {
                    496:                sp = getservbyname(SSH_SERVICE_NAME, "tcp");
                    497:                port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
                    498:        }
                    499:        return port;
                    500: }
                    501:
                    502: /*
                    503:  * Execute a command in a shell.
                    504:  * Return its exit status or -1 on abnormal exit.
                    505:  */
                    506: static int
                    507: execute_in_shell(const char *cmd)
                    508: {
1.243     dtucker   509:        char *shell;
1.206     djm       510:        pid_t pid;
1.337     djm       511:        int status;
1.206     djm       512:
                    513:        if ((shell = getenv("SHELL")) == NULL)
                    514:                shell = _PATH_BSHELL;
1.308     djm       515:
                    516:        if (access(shell, X_OK) == -1) {
                    517:                fatal("Shell \"%s\" is not executable: %s",
                    518:                    shell, strerror(errno));
                    519:        }
1.206     djm       520:
                    521:        debug("Executing command: '%.500s'", cmd);
                    522:
                    523:        /* Fork and execute the command. */
                    524:        if ((pid = fork()) == 0) {
1.245     djm       525:                char *argv[4];
1.206     djm       526:
1.337     djm       527:                if (stdfd_devnull(1, 1, 0) == -1)
1.340     djm       528:                        fatal_f("stdfd_devnull failed");
1.206     djm       529:                closefrom(STDERR_FILENO + 1);
1.245     djm       530:
                    531:                argv[0] = shell;
                    532:                argv[1] = "-c";
                    533:                argv[2] = xstrdup(cmd);
                    534:                argv[3] = NULL;
1.206     djm       535:
                    536:                execv(argv[0], argv);
                    537:                error("Unable to execute '%.100s': %s", cmd, strerror(errno));
                    538:                /* Die with signal to make this error apparent to parent. */
1.321     dtucker   539:                ssh_signal(SIGTERM, SIG_DFL);
1.206     djm       540:                kill(getpid(), SIGTERM);
                    541:                _exit(1);
                    542:        }
                    543:        /* Parent. */
1.307     deraadt   544:        if (pid == -1)
1.340     djm       545:                fatal_f("fork: %.100s", strerror(errno));
1.206     djm       546:
                    547:        while (waitpid(pid, &status, 0) == -1) {
                    548:                if (errno != EINTR && errno != EAGAIN)
1.340     djm       549:                        fatal_f("waitpid: %s", strerror(errno));
1.206     djm       550:        }
                    551:        if (!WIFEXITED(status)) {
                    552:                error("command '%.100s' exited abnormally", cmd);
                    553:                return -1;
1.221     djm       554:        }
1.206     djm       555:        debug3("command returned status %d", WEXITSTATUS(status));
                    556:        return WEXITSTATUS(status);
                    557: }
                    558:
                    559: /*
                    560:  * Parse and execute a Match directive.
                    561:  */
                    562: static int
                    563: match_cfg_line(Options *options, char **condition, struct passwd *pw,
1.302     djm       564:     const char *host_arg, const char *original_host, int final_pass,
                    565:     int *want_final_pass, const char *filename, int linenum)
1.206     djm       566: {
1.221     djm       567:        char *arg, *oattrib, *attrib, *cmd, *cp = *condition, *host, *criteria;
1.211     djm       568:        const char *ruser;
1.221     djm       569:        int r, port, this_result, result = 1, attributes = 0, negate;
1.206     djm       570:        char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
1.288     djm       571:        char uidstr[32];
1.206     djm       572:
                    573:        /*
                    574:         * Configuration is likely to be incomplete at this point so we
                    575:         * must be prepared to use default values.
                    576:         */
                    577:        port = options->port <= 0 ? default_ssh_port() : options->port;
                    578:        ruser = options->user == NULL ? pw->pw_name : options->user;
1.302     djm       579:        if (final_pass) {
1.250     djm       580:                host = xstrdup(options->hostname);
                    581:        } else if (options->hostname != NULL) {
1.212     djm       582:                /* NB. Please keep in sync with ssh.c:main() */
1.211     djm       583:                host = percent_expand(options->hostname,
                    584:                    "h", host_arg, (char *)NULL);
1.250     djm       585:        } else {
1.211     djm       586:                host = xstrdup(host_arg);
1.250     djm       587:        }
1.206     djm       588:
1.221     djm       589:        debug2("checking match for '%s' host %s originally %s",
                    590:            cp, host, original_host);
                    591:        while ((oattrib = attrib = strdelim(&cp)) && *attrib != '\0') {
1.356     djm       592:                /* Terminate on comment */
                    593:                if (*attrib == '#') {
                    594:                        cp = NULL; /* mark all arguments consumed */
                    595:                        break;
                    596:                }
                    597:                arg = criteria = NULL;
1.221     djm       598:                this_result = 1;
                    599:                if ((negate = attrib[0] == '!'))
                    600:                        attrib++;
1.356     djm       601:                /* Criterion "all" has no argument and must appear alone */
1.213     dtucker   602:                if (strcasecmp(attrib, "all") == 0) {
1.356     djm       603:                        if (attributes > 1 || ((arg = strdelim(&cp)) != NULL &&
                    604:                            *arg != '\0' && *arg != '#')) {
1.221     djm       605:                                error("%.200s line %d: '%s' cannot be combined "
                    606:                                    "with other Match attributes",
                    607:                                    filename, linenum, oattrib);
1.213     dtucker   608:                                result = -1;
                    609:                                goto out;
                    610:                        }
1.356     djm       611:                        if (arg != NULL && *arg == '#')
                    612:                                cp = NULL; /* mark all arguments consumed */
1.221     djm       613:                        if (result)
                    614:                                result = negate ? 0 : 1;
1.213     dtucker   615:                        goto out;
                    616:                }
1.221     djm       617:                attributes++;
1.356     djm       618:                /* criteria "final" and "canonical" have no argument */
1.302     djm       619:                if (strcasecmp(attrib, "canonical") == 0 ||
                    620:                    strcasecmp(attrib, "final") == 0) {
                    621:                        /*
                    622:                         * If the config requests "Match final" then remember
                    623:                         * this so we can perform a second pass later.
                    624:                         */
                    625:                        if (strcasecmp(attrib, "final") == 0 &&
                    626:                            want_final_pass != NULL)
                    627:                                *want_final_pass = 1;
                    628:                        r = !!final_pass;  /* force bitmask member to boolean */
1.221     djm       629:                        if (r == (negate ? 1 : 0))
                    630:                                this_result = result = 0;
                    631:                        debug3("%.200s line %d: %smatched '%s'",
                    632:                            filename, linenum,
                    633:                            this_result ? "" : "not ", oattrib);
                    634:                        continue;
                    635:                }
                    636:                /* All other criteria require an argument */
1.356     djm       637:                if ((arg = strdelim(&cp)) == NULL ||
                    638:                    *arg == '\0' || *arg == '#') {
1.206     djm       639:                        error("Missing Match criteria for %s", attrib);
1.211     djm       640:                        result = -1;
                    641:                        goto out;
1.206     djm       642:                }
                    643:                if (strcasecmp(attrib, "host") == 0) {
1.221     djm       644:                        criteria = xstrdup(host);
1.235     djm       645:                        r = match_hostname(host, arg) == 1;
1.221     djm       646:                        if (r == (negate ? 1 : 0))
                    647:                                this_result = result = 0;
1.206     djm       648:                } else if (strcasecmp(attrib, "originalhost") == 0) {
1.221     djm       649:                        criteria = xstrdup(original_host);
1.235     djm       650:                        r = match_hostname(original_host, arg) == 1;
1.221     djm       651:                        if (r == (negate ? 1 : 0))
                    652:                                this_result = result = 0;
1.206     djm       653:                } else if (strcasecmp(attrib, "user") == 0) {
1.221     djm       654:                        criteria = xstrdup(ruser);
1.235     djm       655:                        r = match_pattern_list(ruser, arg, 0) == 1;
1.221     djm       656:                        if (r == (negate ? 1 : 0))
                    657:                                this_result = result = 0;
1.206     djm       658:                } else if (strcasecmp(attrib, "localuser") == 0) {
1.221     djm       659:                        criteria = xstrdup(pw->pw_name);
1.235     djm       660:                        r = match_pattern_list(pw->pw_name, arg, 0) == 1;
1.221     djm       661:                        if (r == (negate ? 1 : 0))
                    662:                                this_result = result = 0;
1.210     djm       663:                } else if (strcasecmp(attrib, "exec") == 0) {
1.333     dtucker   664:                        char *conn_hash_hex, *keyalias;
1.327     dtucker   665:
1.206     djm       666:                        if (gethostname(thishost, sizeof(thishost)) == -1)
                    667:                                fatal("gethostname: %s", strerror(errno));
                    668:                        strlcpy(shorthost, thishost, sizeof(shorthost));
                    669:                        shorthost[strcspn(thishost, ".")] = '\0';
                    670:                        snprintf(portstr, sizeof(portstr), "%d", port);
1.288     djm       671:                        snprintf(uidstr, sizeof(uidstr), "%llu",
                    672:                            (unsigned long long)pw->pw_uid);
1.327     dtucker   673:                        conn_hash_hex = ssh_connection_hash(thishost, host,
1.353     djm       674:                            portstr, ruser);
1.333     dtucker   675:                        keyalias = options->host_key_alias ?
                    676:                            options->host_key_alias : host;
1.206     djm       677:
                    678:                        cmd = percent_expand(arg,
1.327     dtucker   679:                            "C", conn_hash_hex,
1.206     djm       680:                            "L", shorthost,
                    681:                            "d", pw->pw_dir,
                    682:                            "h", host,
1.333     dtucker   683:                            "k", keyalias,
1.206     djm       684:                            "l", thishost,
1.221     djm       685:                            "n", original_host,
1.206     djm       686:                            "p", portstr,
                    687:                            "r", ruser,
                    688:                            "u", pw->pw_name,
1.288     djm       689:                            "i", uidstr,
1.206     djm       690:                            (char *)NULL);
1.327     dtucker   691:                        free(conn_hash_hex);
1.217     djm       692:                        if (result != 1) {
                    693:                                /* skip execution if prior predicate failed */
1.221     djm       694:                                debug3("%.200s line %d: skipped exec "
                    695:                                    "\"%.100s\"", filename, linenum, cmd);
                    696:                                free(cmd);
                    697:                                continue;
                    698:                        }
                    699:                        r = execute_in_shell(cmd);
                    700:                        if (r == -1) {
                    701:                                fatal("%.200s line %d: match exec "
                    702:                                    "'%.100s' error", filename,
                    703:                                    linenum, cmd);
1.217     djm       704:                        }
1.221     djm       705:                        criteria = xstrdup(cmd);
1.206     djm       706:                        free(cmd);
1.221     djm       707:                        /* Force exit status to boolean */
                    708:                        r = r == 0;
                    709:                        if (r == (negate ? 1 : 0))
                    710:                                this_result = result = 0;
1.206     djm       711:                } else {
                    712:                        error("Unsupported Match attribute %s", attrib);
1.211     djm       713:                        result = -1;
                    714:                        goto out;
1.206     djm       715:                }
1.221     djm       716:                debug3("%.200s line %d: %smatched '%s \"%.100s\"' ",
                    717:                    filename, linenum, this_result ? "": "not ",
                    718:                    oattrib, criteria);
                    719:                free(criteria);
1.213     dtucker   720:        }
                    721:        if (attributes == 0) {
                    722:                error("One or more attributes required for Match");
                    723:                result = -1;
                    724:                goto out;
1.206     djm       725:        }
1.221     djm       726:  out:
                    727:        if (result != -1)
                    728:                debug2("match %sfound", result ? "" : "not ");
1.206     djm       729:        *condition = cp;
1.211     djm       730:        free(host);
1.206     djm       731:        return result;
                    732: }
                    733:
1.286     djm       734: /* Remove environment variable by pattern */
                    735: static void
                    736: rm_env(Options *options, const char *arg, const char *filename, int linenum)
                    737: {
1.330     djm       738:        int i, j, onum_send_env = options->num_send_env;
1.286     djm       739:        char *cp;
                    740:
                    741:        /* Remove an environment variable */
                    742:        for (i = 0; i < options->num_send_env; ) {
                    743:                cp = xstrdup(options->send_env[i]);
                    744:                if (!match_pattern(cp, arg + 1)) {
                    745:                        free(cp);
                    746:                        i++;
                    747:                        continue;
                    748:                }
                    749:                debug3("%s line %d: removing environment %s",
                    750:                    filename, linenum, cp);
                    751:                free(cp);
                    752:                free(options->send_env[i]);
                    753:                options->send_env[i] = NULL;
                    754:                for (j = i; j < options->num_send_env - 1; j++) {
                    755:                        options->send_env[j] = options->send_env[j + 1];
                    756:                        options->send_env[j + 1] = NULL;
                    757:                }
                    758:                options->num_send_env--;
                    759:                /* NB. don't increment i */
1.330     djm       760:        }
                    761:        if (onum_send_env != options->num_send_env) {
                    762:                options->send_env = xrecallocarray(options->send_env,
                    763:                    onum_send_env, options->num_send_env,
                    764:                    sizeof(*options->send_env));
1.286     djm       765:        }
                    766: }
                    767:
1.19      markus    768: /*
1.70      stevesk   769:  * Returns the number of the token pointed to by cp or oBadOption.
1.19      markus    770:  */
1.26      markus    771: static OpCodes
1.199     djm       772: parse_token(const char *cp, const char *filename, int linenum,
                    773:     const char *ignored_unknown)
1.1       deraadt   774: {
1.199     djm       775:        int i;
1.1       deraadt   776:
1.17      markus    777:        for (i = 0; keywords[i].name; i++)
1.199     djm       778:                if (strcmp(cp, keywords[i].name) == 0)
1.17      markus    779:                        return keywords[i].opcode;
1.235     djm       780:        if (ignored_unknown != NULL &&
                    781:            match_pattern_list(cp, ignored_unknown, 1) == 1)
1.199     djm       782:                return oIgnoredUnknownOption;
1.75      stevesk   783:        error("%s: line %d: Bad configuration option: %s",
                    784:            filename, linenum, cp);
1.17      markus    785:        return oBadOption;
1.1       deraadt   786: }
                    787:
1.207     djm       788: /* Multistate option parsing */
                    789: struct multistate {
                    790:        char *key;
                    791:        int value;
                    792: };
                    793: static const struct multistate multistate_flag[] = {
                    794:        { "true",                       1 },
                    795:        { "false",                      0 },
                    796:        { "yes",                        1 },
                    797:        { "no",                         0 },
                    798:        { NULL, -1 }
                    799: };
                    800: static const struct multistate multistate_yesnoask[] = {
                    801:        { "true",                       1 },
                    802:        { "false",                      0 },
                    803:        { "yes",                        1 },
                    804:        { "no",                         0 },
                    805:        { "ask",                        2 },
                    806:        { NULL, -1 }
                    807: };
1.278     djm       808: static const struct multistate multistate_strict_hostkey[] = {
                    809:        { "true",                       SSH_STRICT_HOSTKEY_YES },
                    810:        { "false",                      SSH_STRICT_HOSTKEY_OFF },
                    811:        { "yes",                        SSH_STRICT_HOSTKEY_YES },
                    812:        { "no",                         SSH_STRICT_HOSTKEY_OFF },
                    813:        { "ask",                        SSH_STRICT_HOSTKEY_ASK },
                    814:        { "off",                        SSH_STRICT_HOSTKEY_OFF },
                    815:        { "accept-new",                 SSH_STRICT_HOSTKEY_NEW },
                    816:        { NULL, -1 }
                    817: };
1.246     jcs       818: static const struct multistate multistate_yesnoaskconfirm[] = {
                    819:        { "true",                       1 },
                    820:        { "false",                      0 },
                    821:        { "yes",                        1 },
                    822:        { "no",                         0 },
                    823:        { "ask",                        2 },
                    824:        { "confirm",                    3 },
                    825:        { NULL, -1 }
                    826: };
1.207     djm       827: static const struct multistate multistate_addressfamily[] = {
                    828:        { "inet",                       AF_INET },
                    829:        { "inet6",                      AF_INET6 },
                    830:        { "any",                        AF_UNSPEC },
                    831:        { NULL, -1 }
                    832: };
                    833: static const struct multistate multistate_controlmaster[] = {
                    834:        { "true",                       SSHCTL_MASTER_YES },
                    835:        { "yes",                        SSHCTL_MASTER_YES },
                    836:        { "false",                      SSHCTL_MASTER_NO },
                    837:        { "no",                         SSHCTL_MASTER_NO },
                    838:        { "auto",                       SSHCTL_MASTER_AUTO },
                    839:        { "ask",                        SSHCTL_MASTER_ASK },
                    840:        { "autoask",                    SSHCTL_MASTER_AUTO_ASK },
                    841:        { NULL, -1 }
                    842: };
                    843: static const struct multistate multistate_tunnel[] = {
                    844:        { "ethernet",                   SSH_TUNMODE_ETHERNET },
                    845:        { "point-to-point",             SSH_TUNMODE_POINTOPOINT },
                    846:        { "true",                       SSH_TUNMODE_DEFAULT },
                    847:        { "yes",                        SSH_TUNMODE_DEFAULT },
                    848:        { "false",                      SSH_TUNMODE_NO },
                    849:        { "no",                         SSH_TUNMODE_NO },
                    850:        { NULL, -1 }
                    851: };
                    852: static const struct multistate multistate_requesttty[] = {
                    853:        { "true",                       REQUEST_TTY_YES },
                    854:        { "yes",                        REQUEST_TTY_YES },
                    855:        { "false",                      REQUEST_TTY_NO },
                    856:        { "no",                         REQUEST_TTY_NO },
                    857:        { "force",                      REQUEST_TTY_FORCE },
                    858:        { "auto",                       REQUEST_TTY_AUTO },
                    859:        { NULL, -1 }
                    860: };
1.209     djm       861: static const struct multistate multistate_canonicalizehostname[] = {
1.208     djm       862:        { "true",                       SSH_CANONICALISE_YES },
                    863:        { "false",                      SSH_CANONICALISE_NO },
                    864:        { "yes",                        SSH_CANONICALISE_YES },
                    865:        { "no",                         SSH_CANONICALISE_NO },
                    866:        { "always",                     SSH_CANONICALISE_ALWAYS },
                    867:        { NULL, -1 }
                    868: };
1.322     dtucker   869: static const struct multistate multistate_compression[] = {
                    870: #ifdef WITH_ZLIB
                    871:        { "yes",                        COMP_ZLIB },
                    872: #endif
                    873:        { "no",                         COMP_NONE },
                    874:        { NULL, -1 }
                    875: };
1.207     djm       876:
1.334     djm       877: static int
                    878: parse_multistate_value(const char *arg, const char *filename, int linenum,
                    879:     const struct multistate *multistate_ptr)
                    880: {
                    881:        int i;
                    882:
1.344     djm       883:        if (!arg || *arg == '\0') {
                    884:                error("%s line %d: missing argument.", filename, linenum);
                    885:                return -1;
                    886:        }
1.334     djm       887:        for (i = 0; multistate_ptr[i].key != NULL; i++) {
                    888:                if (strcasecmp(arg, multistate_ptr[i].key) == 0)
                    889:                        return multistate_ptr[i].value;
                    890:        }
                    891:        return -1;
                    892: }
                    893:
1.19      markus    894: /*
                    895:  * Processes a single option line as used in the configuration files. This
                    896:  * only sets those values that have not already been set.
                    897:  */
1.14      markus    898: int
1.206     djm       899: process_config_line(Options *options, struct passwd *pw, const char *host,
1.221     djm       900:     const char *original_host, char *line, const char *filename,
                    901:     int linenum, int *activep, int flags)
1.1       deraadt   902: {
1.252     djm       903:        return process_config_line_depth(options, pw, host, original_host,
1.302     djm       904:            line, filename, linenum, activep, flags, NULL, 0);
1.252     djm       905: }
                    906:
                    907: #define WHITESPACE " \t\r\n"
                    908: static int
                    909: process_config_line_depth(Options *options, struct passwd *pw, const char *host,
                    910:     const char *original_host, char *line, const char *filename,
1.302     djm       911:     int linenum, int *activep, int flags, int *want_final_pass, int depth)
1.252     djm       912: {
1.356     djm       913:        char *str, **charptr, *endofnumber, *keyword, *arg, *arg2, *p, ch;
1.339     djm       914:        char **cpptr, ***cppptr, fwdarg[256];
1.351     markus    915:        u_int i, *uintptr, uvalue, max_entries = 0;
1.252     djm       916:        int r, oactive, negated, opcode, *intptr, value, value2, cmdline = 0;
1.279     markus    917:        int remotefwd, dynamicfwd;
1.164     dtucker   918:        LogLevel *log_level_ptr;
1.271     dtucker   919:        SyslogFacility *log_facility_ptr;
1.201     dtucker   920:        long long val64;
1.102     markus    921:        size_t len;
1.220     millert   922:        struct Forward fwd;
1.207     djm       923:        const struct multistate *multistate_ptr;
1.208     djm       924:        struct allowed_cname *cname;
1.252     djm       925:        glob_t gl;
1.281     dtucker   926:        const char *errstr;
1.356     djm       927:        char **oav = NULL, **av;
                    928:        int oac = 0, ac;
                    929:        int ret = -1;
1.106     djm       930:
1.206     djm       931:        if (activep == NULL) { /* We are processing a command line directive */
                    932:                cmdline = 1;
                    933:                activep = &cmdline;
                    934:        }
                    935:
1.267     djm       936:        /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1.233     djm       937:        if ((len = strlen(line)) == 0)
                    938:                return 0;
                    939:        for (len--; len > 0; len--) {
1.267     djm       940:                if (strchr(WHITESPACE "\f", line[len]) == NULL)
1.106     djm       941:                        break;
                    942:                line[len] = '\0';
                    943:        }
1.1       deraadt   944:
1.356     djm       945:        str = line;
1.42      provos    946:        /* Get the keyword. (Each line is supposed to begin with a keyword). */
1.356     djm       947:        if ((keyword = strdelim(&str)) == NULL)
1.149     djm       948:                return 0;
1.42      provos    949:        /* Ignore leading whitespace. */
                    950:        if (*keyword == '\0')
1.356     djm       951:                keyword = strdelim(&str);
1.56      deraadt   952:        if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
1.17      markus    953:                return 0;
1.199     djm       954:        /* Match lowercase keyword */
1.207     djm       955:        lowercase(keyword);
1.17      markus    956:
1.356     djm       957:        /* Prepare to parse remainder of line */
                    958:        if (str != NULL)
                    959:                str += strspn(str, WHITESPACE);
                    960:        if (str == NULL || *str == '\0') {
                    961:                error("%s line %d: no argument after keyword \"%s\"",
                    962:                    filename, linenum, keyword);
                    963:                return -1;
                    964:        }
1.199     djm       965:        opcode = parse_token(keyword, filename, linenum,
                    966:            options->ignored_unknown);
1.356     djm       967:        if (argv_split(str, &oac, &oav, 1) != 0) {
                    968:                error("%s line %d: invalid quotes", filename, linenum);
                    969:                return -1;
                    970:        }
                    971:        ac = oac;
                    972:        av = oav;
1.17      markus    973:
                    974:        switch (opcode) {
                    975:        case oBadOption:
1.19      markus    976:                /* don't panic, but count bad options */
1.356     djm       977:                goto out;
1.273     djm       978:        case oIgnore:
1.356     djm       979:                argv_consume(&ac);
                    980:                break;
1.199     djm       981:        case oIgnoredUnknownOption:
                    982:                debug("%s line %d: Ignored unknown option \"%s\"",
                    983:                    filename, linenum, keyword);
1.356     djm       984:                argv_consume(&ac);
                    985:                break;
1.111     djm       986:        case oConnectTimeout:
                    987:                intptr = &options->connection_timeout;
1.127     markus    988: parse_time:
1.356     djm       989:                arg = argv_next(&ac, &av);
1.344     djm       990:                if (!arg || *arg == '\0') {
                    991:                        error("%s line %d: missing time value.",
1.111     djm       992:                            filename, linenum);
1.356     djm       993:                        goto out;
1.344     djm       994:                }
1.221     djm       995:                if (strcmp(arg, "none") == 0)
                    996:                        value = -1;
1.344     djm       997:                else if ((value = convtime(arg)) == -1) {
                    998:                        error("%s line %d: invalid time value.",
1.111     djm       999:                            filename, linenum);
1.356     djm      1000:                        goto out;
1.344     djm      1001:                }
1.160     dtucker  1002:                if (*activep && *intptr == -1)
1.111     djm      1003:                        *intptr = value;
                   1004:                break;
                   1005:
1.17      markus   1006:        case oForwardAgent:
                   1007:                intptr = &options->forward_agent;
1.319     djm      1008:
1.356     djm      1009:                arg = argv_next(&ac, &av);
1.344     djm      1010:                if (!arg || *arg == '\0') {
                   1011:                        error("%s line %d: missing argument.",
1.319     djm      1012:                            filename, linenum);
1.356     djm      1013:                        goto out;
1.344     djm      1014:                }
1.319     djm      1015:
                   1016:                value = -1;
                   1017:                multistate_ptr = multistate_flag;
                   1018:                for (i = 0; multistate_ptr[i].key != NULL; i++) {
                   1019:                        if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
                   1020:                                value = multistate_ptr[i].value;
                   1021:                                break;
                   1022:                        }
                   1023:                }
                   1024:                if (value != -1) {
                   1025:                        if (*activep && *intptr == -1)
                   1026:                                *intptr = value;
                   1027:                        break;
                   1028:                }
                   1029:                /* ForwardAgent wasn't 'yes' or 'no', assume a path */
                   1030:                if (*activep && *intptr == -1)
                   1031:                        *intptr = 1;
                   1032:
                   1033:                charptr = &options->forward_agent_sock_path;
                   1034:                goto parse_agent_path;
                   1035:
                   1036:        case oForwardX11:
                   1037:                intptr = &options->forward_x11;
1.207     djm      1038:  parse_flag:
                   1039:                multistate_ptr = multistate_flag;
                   1040:  parse_multistate:
1.356     djm      1041:                arg = argv_next(&ac, &av);
1.334     djm      1042:                if ((value = parse_multistate_value(arg, filename, linenum,
1.353     djm      1043:                    multistate_ptr)) == -1) {
1.344     djm      1044:                        error("%s line %d: unsupported option \"%s\".",
1.207     djm      1045:                            filename, linenum, arg);
1.356     djm      1046:                        goto out;
1.334     djm      1047:                }
1.17      markus   1048:                if (*activep && *intptr == -1)
                   1049:                        *intptr = value;
                   1050:                break;
                   1051:
1.123     markus   1052:        case oForwardX11Trusted:
                   1053:                intptr = &options->forward_x11_trusted;
                   1054:                goto parse_flag;
1.221     djm      1055:
1.186     djm      1056:        case oForwardX11Timeout:
                   1057:                intptr = &options->forward_x11_timeout;
                   1058:                goto parse_time;
1.123     markus   1059:
1.17      markus   1060:        case oGatewayPorts:
1.220     millert  1061:                intptr = &options->fwd_opts.gateway_ports;
1.17      markus   1062:                goto parse_flag;
                   1063:
1.153     markus   1064:        case oExitOnForwardFailure:
                   1065:                intptr = &options->exit_on_forward_failure;
                   1066:                goto parse_flag;
                   1067:
1.17      markus   1068:        case oPasswordAuthentication:
                   1069:                intptr = &options->password_authentication;
                   1070:                goto parse_flag;
                   1071:
1.48      markus   1072:        case oKbdInteractiveAuthentication:
                   1073:                intptr = &options->kbd_interactive_authentication;
                   1074:                goto parse_flag;
                   1075:
                   1076:        case oKbdInteractiveDevices:
                   1077:                charptr = &options->kbd_interactive_devices;
                   1078:                goto parse_string;
                   1079:
1.50      markus   1080:        case oPubkeyAuthentication:
                   1081:                intptr = &options->pubkey_authentication;
1.30      markus   1082:                goto parse_flag;
                   1083:
1.72      markus   1084:        case oHostbasedAuthentication:
                   1085:                intptr = &options->hostbased_authentication;
                   1086:                goto parse_flag;
                   1087:
1.118     markus   1088:        case oGssAuthentication:
                   1089:                intptr = &options->gss_authentication;
                   1090:                goto parse_flag;
                   1091:
                   1092:        case oGssDelegateCreds:
                   1093:                intptr = &options->gss_deleg_creds;
                   1094:                goto parse_flag;
                   1095:
1.17      markus   1096:        case oBatchMode:
                   1097:                intptr = &options->batch_mode;
                   1098:                goto parse_flag;
                   1099:
                   1100:        case oCheckHostIP:
                   1101:                intptr = &options->check_host_ip;
1.167     grunk    1102:                goto parse_flag;
1.17      markus   1103:
1.107     jakob    1104:        case oVerifyHostKeyDNS:
                   1105:                intptr = &options->verify_host_key_dns;
1.207     djm      1106:                multistate_ptr = multistate_yesnoask;
                   1107:                goto parse_multistate;
1.107     jakob    1108:
1.17      markus   1109:        case oStrictHostKeyChecking:
                   1110:                intptr = &options->strict_host_key_checking;
1.278     djm      1111:                multistate_ptr = multistate_strict_hostkey;
1.207     djm      1112:                goto parse_multistate;
1.17      markus   1113:
                   1114:        case oCompression:
                   1115:                intptr = &options->compression;
1.322     dtucker  1116:                multistate_ptr = multistate_compression;
                   1117:                goto parse_multistate;
1.17      markus   1118:
1.126     markus   1119:        case oTCPKeepAlive:
                   1120:                intptr = &options->tcp_keep_alive;
1.17      markus   1121:                goto parse_flag;
                   1122:
1.91      markus   1123:        case oNoHostAuthenticationForLocalhost:
                   1124:                intptr = &options->no_host_authentication_for_localhost;
                   1125:                goto parse_flag;
                   1126:
1.17      markus   1127:        case oNumberOfPasswordPrompts:
                   1128:                intptr = &options->number_of_password_prompts;
                   1129:                goto parse_int;
                   1130:
1.105     markus   1131:        case oRekeyLimit:
1.356     djm      1132:                arg = argv_next(&ac, &av);
1.344     djm      1133:                if (!arg || *arg == '\0') {
                   1134:                        error("%.200s line %d: Missing argument.", filename,
1.198     dtucker  1135:                            linenum);
1.356     djm      1136:                        goto out;
1.344     djm      1137:                }
1.198     dtucker  1138:                if (strcmp(arg, "default") == 0) {
                   1139:                        val64 = 0;
                   1140:                } else {
1.344     djm      1141:                        if (scan_scaled(arg, &val64) == -1) {
                   1142:                                error("%.200s line %d: Bad number '%s': %s",
1.200     dtucker  1143:                                    filename, linenum, arg, strerror(errno));
1.356     djm      1144:                                goto out;
1.344     djm      1145:                        }
                   1146:                        if (val64 != 0 && val64 < 16) {
                   1147:                                error("%.200s line %d: RekeyLimit too small",
1.198     dtucker  1148:                                    filename, linenum);
1.356     djm      1149:                                goto out;
1.344     djm      1150:                        }
1.105     markus   1151:                }
1.165     djm      1152:                if (*activep && options->rekey_limit == -1)
1.249     dtucker  1153:                        options->rekey_limit = val64;
1.356     djm      1154:                if (ac != 0) { /* optional rekey interval present */
                   1155:                        if (strcmp(av[0], "none") == 0) {
                   1156:                                (void)argv_next(&ac, &av);      /* discard */
1.198     dtucker  1157:                                break;
                   1158:                        }
                   1159:                        intptr = &options->rekey_interval;
                   1160:                        goto parse_time;
                   1161:                }
1.105     markus   1162:                break;
                   1163:
1.17      markus   1164:        case oIdentityFile:
1.356     djm      1165:                arg = argv_next(&ac, &av);
1.344     djm      1166:                if (!arg || *arg == '\0') {
                   1167:                        error("%.200s line %d: Missing argument.",
                   1168:                            filename, linenum);
1.356     djm      1169:                        goto out;
1.344     djm      1170:                }
1.17      markus   1171:                if (*activep) {
1.50      markus   1172:                        intptr = &options->num_identity_files;
1.344     djm      1173:                        if (*intptr >= SSH_MAX_IDENTITY_FILES) {
                   1174:                                error("%.200s line %d: Too many identity files "
                   1175:                                    "specified (max %d).", filename, linenum,
                   1176:                                    SSH_MAX_IDENTITY_FILES);
1.356     djm      1177:                                goto out;
1.344     djm      1178:                        }
1.221     djm      1179:                        add_identity_file(options, NULL,
                   1180:                            arg, flags & SSHCONF_USERCONF);
1.17      markus   1181:                }
                   1182:                break;
                   1183:
1.241     djm      1184:        case oCertificateFile:
1.356     djm      1185:                arg = argv_next(&ac, &av);
1.344     djm      1186:                if (!arg || *arg == '\0') {
                   1187:                        error("%.200s line %d: Missing argument.",
1.241     djm      1188:                            filename, linenum);
1.356     djm      1189:                        goto out;
1.344     djm      1190:                }
1.241     djm      1191:                if (*activep) {
                   1192:                        intptr = &options->num_certificate_files;
                   1193:                        if (*intptr >= SSH_MAX_CERTIFICATE_FILES) {
1.344     djm      1194:                                error("%.200s line %d: Too many certificate "
1.241     djm      1195:                                    "files specified (max %d).",
                   1196:                                    filename, linenum,
                   1197:                                    SSH_MAX_CERTIFICATE_FILES);
1.356     djm      1198:                                goto out;
1.241     djm      1199:                        }
                   1200:                        add_certificate_file(options, arg,
                   1201:                            flags & SSHCONF_USERCONF);
                   1202:                }
                   1203:                break;
                   1204:
1.34      markus   1205:        case oXAuthLocation:
                   1206:                charptr=&options->xauth_location;
                   1207:                goto parse_string;
                   1208:
1.17      markus   1209:        case oUser:
                   1210:                charptr = &options->user;
                   1211: parse_string:
1.356     djm      1212:                arg = argv_next(&ac, &av);
1.344     djm      1213:                if (!arg || *arg == '\0') {
                   1214:                        error("%.200s line %d: Missing argument.",
1.193     djm      1215:                            filename, linenum);
1.356     djm      1216:                        goto out;
1.344     djm      1217:                }
1.17      markus   1218:                if (*activep && *charptr == NULL)
1.38      provos   1219:                        *charptr = xstrdup(arg);
1.17      markus   1220:                break;
                   1221:
                   1222:        case oGlobalKnownHostsFile:
1.193     djm      1223:                cpptr = (char **)&options->system_hostfiles;
                   1224:                uintptr = &options->num_system_hostfiles;
                   1225:                max_entries = SSH_MAX_HOSTS_FILES;
                   1226: parse_char_array:
1.356     djm      1227:                i = 0;
1.357     djm      1228:                value = *uintptr == 0; /* was array empty when we started? */
1.356     djm      1229:                while ((arg = argv_next(&ac, &av)) != NULL) {
                   1230:                        if (*arg == '\0') {
                   1231:                                error("%s line %d: keyword %s empty argument",
                   1232:                                    filename, linenum, keyword);
                   1233:                                goto out;
                   1234:                        }
                   1235:                        /* Allow "none" only in first position */
                   1236:                        if (strcasecmp(arg, "none") == 0) {
                   1237:                                if (i > 0 || ac > 0) {
                   1238:                                        error("%s line %d: keyword %s \"none\" "
                   1239:                                            "argument must appear alone.",
                   1240:                                            filename, linenum, keyword);
                   1241:                                        goto out;
                   1242:                                }
                   1243:                        }
                   1244:                        i++;
1.357     djm      1245:                        if (*activep && value) {
1.344     djm      1246:                                if ((*uintptr) >= max_entries) {
1.356     djm      1247:                                        error("%s line %d: too many %s "
                   1248:                                            "entries.", filename, linenum,
                   1249:                                            keyword);
                   1250:                                        goto out;
1.344     djm      1251:                                }
1.193     djm      1252:                                cpptr[(*uintptr)++] = xstrdup(arg);
                   1253:                        }
                   1254:                }
1.356     djm      1255:                break;
1.17      markus   1256:
                   1257:        case oUserKnownHostsFile:
1.193     djm      1258:                cpptr = (char **)&options->user_hostfiles;
                   1259:                uintptr = &options->num_user_hostfiles;
                   1260:                max_entries = SSH_MAX_HOSTS_FILES;
                   1261:                goto parse_char_array;
1.27      markus   1262:
1.306     jmc      1263:        case oHostname:
1.17      markus   1264:                charptr = &options->hostname;
                   1265:                goto parse_string;
                   1266:
1.52      markus   1267:        case oHostKeyAlias:
                   1268:                charptr = &options->host_key_alias;
                   1269:                goto parse_string;
                   1270:
1.67      markus   1271:        case oPreferredAuthentications:
                   1272:                charptr = &options->preferred_authentications;
                   1273:                goto parse_string;
                   1274:
1.77      markus   1275:        case oBindAddress:
                   1276:                charptr = &options->bind_address;
                   1277:                goto parse_string;
                   1278:
1.282     djm      1279:        case oBindInterface:
                   1280:                charptr = &options->bind_interface;
                   1281:                goto parse_string;
                   1282:
1.183     markus   1283:        case oPKCS11Provider:
                   1284:                charptr = &options->pkcs11_provider;
1.86      markus   1285:                goto parse_string;
1.85      jakob    1286:
1.310     djm      1287:        case oSecurityKeyProvider:
                   1288:                charptr = &options->sk_provider;
                   1289:                goto parse_string;
                   1290:
1.346     djm      1291:        case oKnownHostsCommand:
                   1292:                charptr = &options->known_hosts_command;
                   1293:                goto parse_command;
                   1294:
1.17      markus   1295:        case oProxyCommand:
1.144     reyk     1296:                charptr = &options->proxy_command;
1.257     djm      1297:                /* Ignore ProxyCommand if ProxyJump already specified */
                   1298:                if (options->jump_host != NULL)
                   1299:                        charptr = &options->jump_host; /* Skip below */
1.144     reyk     1300: parse_command:
1.356     djm      1301:                if (str == NULL) {
1.344     djm      1302:                        error("%.200s line %d: Missing argument.",
                   1303:                            filename, linenum);
1.356     djm      1304:                        goto out;
1.344     djm      1305:                }
1.356     djm      1306:                len = strspn(str, WHITESPACE "=");
1.17      markus   1307:                if (*activep && *charptr == NULL)
1.356     djm      1308:                        *charptr = xstrdup(str + len);
                   1309:                argv_consume(&ac);
                   1310:                break;
1.17      markus   1311:
1.257     djm      1312:        case oProxyJump:
1.356     djm      1313:                if (str == NULL) {
1.344     djm      1314:                        error("%.200s line %d: Missing argument.",
1.257     djm      1315:                            filename, linenum);
1.356     djm      1316:                        goto out;
1.257     djm      1317:                }
1.356     djm      1318:                len = strspn(str, WHITESPACE "=");
                   1319:                /* XXX use argv? */
                   1320:                if (parse_jump(str + len, options, *activep) == -1) {
1.344     djm      1321:                        error("%.200s line %d: Invalid ProxyJump \"%s\"",
1.356     djm      1322:                            filename, linenum, str + len);
                   1323:                        goto out;
1.257     djm      1324:                }
1.356     djm      1325:                argv_consume(&ac);
                   1326:                break;
1.257     djm      1327:
1.17      markus   1328:        case oPort:
1.356     djm      1329:                arg = argv_next(&ac, &av);
1.344     djm      1330:                if (!arg || *arg == '\0') {
                   1331:                        error("%.200s line %d: Missing argument.",
1.300     naddy    1332:                            filename, linenum);
1.356     djm      1333:                        goto out;
1.344     djm      1334:                }
1.300     naddy    1335:                value = a2port(arg);
1.344     djm      1336:                if (value <= 0) {
                   1337:                        error("%.200s line %d: Bad port '%s'.",
1.300     naddy    1338:                            filename, linenum, arg);
1.356     djm      1339:                        goto out;
1.344     djm      1340:                }
1.300     naddy    1341:                if (*activep && options->port == -1)
                   1342:                        options->port = value;
                   1343:                break;
                   1344:
                   1345:        case oConnectionAttempts:
                   1346:                intptr = &options->connection_attempts;
1.17      markus   1347: parse_int:
1.356     djm      1348:                arg = argv_next(&ac, &av);
1.344     djm      1349:                if ((errstr = atoi_err(arg, &value)) != NULL) {
                   1350:                        error("%s line %d: integer value %s.",
1.281     dtucker  1351:                            filename, linenum, errstr);
1.356     djm      1352:                        goto out;
1.344     djm      1353:                }
1.17      markus   1354:                if (*activep && *intptr == -1)
                   1355:                        *intptr = value;
                   1356:                break;
                   1357:
1.25      markus   1358:        case oCiphers:
1.356     djm      1359:                arg = argv_next(&ac, &av);
1.344     djm      1360:                if (!arg || *arg == '\0') {
                   1361:                        error("%.200s line %d: Missing argument.",
                   1362:                            filename, linenum);
1.356     djm      1363:                        goto out;
1.344     djm      1364:                }
1.309     naddy    1365:                if (*arg != '-' &&
1.344     djm      1366:                    !ciphers_valid(*arg == '+' || *arg == '^' ? arg + 1 : arg)){
                   1367:                        error("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.93      deraadt  1368:                            filename, linenum, arg ? arg : "<NONE>");
1.356     djm      1369:                        goto out;
1.344     djm      1370:                }
1.25      markus   1371:                if (*activep && options->ciphers == NULL)
1.38      provos   1372:                        options->ciphers = xstrdup(arg);
1.25      markus   1373:                break;
                   1374:
1.62      markus   1375:        case oMacs:
1.356     djm      1376:                arg = argv_next(&ac, &av);
1.344     djm      1377:                if (!arg || *arg == '\0') {
                   1378:                        error("%.200s line %d: Missing argument.",
                   1379:                            filename, linenum);
1.356     djm      1380:                        goto out;
1.344     djm      1381:                }
1.309     naddy    1382:                if (*arg != '-' &&
1.344     djm      1383:                    !mac_valid(*arg == '+' || *arg == '^' ? arg + 1 : arg)) {
                   1384:                        error("%.200s line %d: Bad SSH2 MAC spec '%s'.",
1.93      deraadt  1385:                            filename, linenum, arg ? arg : "<NONE>");
1.356     djm      1386:                        goto out;
1.344     djm      1387:                }
1.62      markus   1388:                if (*activep && options->macs == NULL)
                   1389:                        options->macs = xstrdup(arg);
                   1390:                break;
                   1391:
1.189     djm      1392:        case oKexAlgorithms:
1.356     djm      1393:                arg = argv_next(&ac, &av);
1.344     djm      1394:                if (!arg || *arg == '\0') {
                   1395:                        error("%.200s line %d: Missing argument.",
1.189     djm      1396:                            filename, linenum);
1.356     djm      1397:                        goto out;
1.344     djm      1398:                }
1.268     djm      1399:                if (*arg != '-' &&
1.309     naddy    1400:                    !kex_names_valid(*arg == '+' || *arg == '^' ?
1.344     djm      1401:                    arg + 1 : arg)) {
                   1402:                        error("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1.189     djm      1403:                            filename, linenum, arg ? arg : "<NONE>");
1.356     djm      1404:                        goto out;
1.344     djm      1405:                }
1.189     djm      1406:                if (*activep && options->kex_algorithms == NULL)
                   1407:                        options->kex_algorithms = xstrdup(arg);
                   1408:                break;
                   1409:
1.76      markus   1410:        case oHostKeyAlgorithms:
1.238     markus   1411:                charptr = &options->hostkeyalgorithms;
1.349     dtucker  1412: parse_pubkey_algos:
1.356     djm      1413:                arg = argv_next(&ac, &av);
1.344     djm      1414:                if (!arg || *arg == '\0') {
                   1415:                        error("%.200s line %d: Missing argument.",
1.238     markus   1416:                            filename, linenum);
1.356     djm      1417:                        goto out;
1.344     djm      1418:                }
1.268     djm      1419:                if (*arg != '-' &&
1.309     naddy    1420:                    !sshkey_names_valid2(*arg == '+' || *arg == '^' ?
1.344     djm      1421:                    arg + 1 : arg, 1)) {
                   1422:                        error("%s line %d: Bad key types '%s'.",
                   1423:                            filename, linenum, arg ? arg : "<NONE>");
1.356     djm      1424:                        goto out;
1.344     djm      1425:                }
1.238     markus   1426:                if (*activep && *charptr == NULL)
                   1427:                        *charptr = xstrdup(arg);
1.76      markus   1428:                break;
                   1429:
1.298     djm      1430:        case oCASignatureAlgorithms:
                   1431:                charptr = &options->ca_sign_algorithms;
1.349     dtucker  1432:                goto parse_pubkey_algos;
1.298     djm      1433:
1.17      markus   1434:        case oLogLevel:
1.164     dtucker  1435:                log_level_ptr = &options->log_level;
1.356     djm      1436:                arg = argv_next(&ac, &av);
1.38      provos   1437:                value = log_level_number(arg);
1.344     djm      1438:                if (value == SYSLOG_LEVEL_NOT_SET) {
                   1439:                        error("%.200s line %d: unsupported log level '%s'",
1.93      deraadt  1440:                            filename, linenum, arg ? arg : "<NONE>");
1.356     djm      1441:                        goto out;
1.344     djm      1442:                }
1.164     dtucker  1443:                if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
                   1444:                        *log_level_ptr = (LogLevel) value;
1.17      markus   1445:                break;
                   1446:
1.271     dtucker  1447:        case oLogFacility:
                   1448:                log_facility_ptr = &options->log_facility;
1.356     djm      1449:                arg = argv_next(&ac, &av);
1.271     dtucker  1450:                value = log_facility_number(arg);
1.344     djm      1451:                if (value == SYSLOG_FACILITY_NOT_SET) {
                   1452:                        error("%.200s line %d: unsupported log facility '%s'",
1.271     dtucker  1453:                            filename, linenum, arg ? arg : "<NONE>");
1.356     djm      1454:                        goto out;
1.344     djm      1455:                }
1.271     dtucker  1456:                if (*log_facility_ptr == -1)
                   1457:                        *log_facility_ptr = (SyslogFacility) value;
                   1458:                break;
                   1459:
1.339     djm      1460:        case oLogVerbose:
                   1461:                cppptr = &options->log_verbose;
                   1462:                uintptr = &options->num_log_verbose;
1.356     djm      1463:                i = 0;
                   1464:                while ((arg = argv_next(&ac, &av)) != NULL) {
                   1465:                        if (*arg == '\0') {
                   1466:                                error("%s line %d: keyword %s empty argument",
                   1467:                                    filename, linenum, keyword);
                   1468:                                goto out;
                   1469:                        }
                   1470:                        /* Allow "none" only in first position */
                   1471:                        if (strcasecmp(arg, "none") == 0) {
                   1472:                                if (i > 0 || ac > 0) {
                   1473:                                        error("%s line %d: keyword %s \"none\" "
                   1474:                                            "argument must appear alone.",
                   1475:                                            filename, linenum, keyword);
                   1476:                                        goto out;
                   1477:                                }
                   1478:                        }
                   1479:                        i++;
                   1480:                        if (*activep && *uintptr == 0) {
1.339     djm      1481:                                *cppptr = xrecallocarray(*cppptr, *uintptr,
                   1482:                                    *uintptr + 1, sizeof(**cppptr));
                   1483:                                (*cppptr)[(*uintptr)++] = xstrdup(arg);
                   1484:                        }
                   1485:                }
1.356     djm      1486:                break;
1.339     djm      1487:
1.88      stevesk  1488:        case oLocalForward:
1.17      markus   1489:        case oRemoteForward:
1.168     stevesk  1490:        case oDynamicForward:
1.356     djm      1491:                arg = argv_next(&ac, &av);
1.344     djm      1492:                if (!arg || *arg == '\0') {
                   1493:                        error("%.200s line %d: Missing argument.",
1.88      stevesk  1494:                            filename, linenum);
1.356     djm      1495:                        goto out;
1.344     djm      1496:                }
1.135     djm      1497:
1.279     markus   1498:                remotefwd = (opcode == oRemoteForward);
                   1499:                dynamicfwd = (opcode == oDynamicForward);
                   1500:
                   1501:                if (!dynamicfwd) {
1.356     djm      1502:                        arg2 = argv_next(&ac, &av);
1.279     markus   1503:                        if (arg2 == NULL || *arg2 == '\0') {
                   1504:                                if (remotefwd)
                   1505:                                        dynamicfwd = 1;
1.344     djm      1506:                                else {
                   1507:                                        error("%.200s line %d: Missing target "
1.279     markus   1508:                                            "argument.", filename, linenum);
1.356     djm      1509:                                        goto out;
1.344     djm      1510:                                }
1.279     markus   1511:                        } else {
                   1512:                                /* construct a string for parse_forward */
                   1513:                                snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg,
                   1514:                                    arg2);
                   1515:                        }
                   1516:                }
                   1517:                if (dynamicfwd)
1.168     stevesk  1518:                        strlcpy(fwdarg, arg, sizeof(fwdarg));
                   1519:
1.344     djm      1520:                if (parse_forward(&fwd, fwdarg, dynamicfwd, remotefwd) == 0) {
                   1521:                        error("%.200s line %d: Bad forwarding specification.",
1.88      stevesk  1522:                            filename, linenum);
1.356     djm      1523:                        goto out;
1.344     djm      1524:                }
1.135     djm      1525:
1.88      stevesk  1526:                if (*activep) {
1.279     markus   1527:                        if (remotefwd) {
                   1528:                                add_remote_forward(options, &fwd);
                   1529:                        } else {
1.135     djm      1530:                                add_local_forward(options, &fwd);
1.279     markus   1531:                        }
1.88      stevesk  1532:                }
1.17      markus   1533:                break;
1.71      markus   1534:
1.351     markus   1535:        case oPermitRemoteOpen:
                   1536:                uintptr = &options->num_permitted_remote_opens;
                   1537:                cppptr = &options->permitted_remote_opens;
1.356     djm      1538:                arg = argv_next(&ac, &av);
1.351     markus   1539:                if (!arg || *arg == '\0')
                   1540:                        fatal("%s line %d: missing %s specification",
                   1541:                            filename, linenum, lookup_opcode_name(opcode));
                   1542:                uvalue = *uintptr;      /* modified later */
                   1543:                if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
                   1544:                        if (*activep && uvalue == 0) {
                   1545:                                *uintptr = 1;
                   1546:                                *cppptr = xcalloc(1, sizeof(**cppptr));
                   1547:                                (*cppptr)[0] = xstrdup(arg);
                   1548:                        }
                   1549:                        break;
                   1550:                }
1.356     djm      1551:                while ((arg = argv_next(&ac, &av)) != NULL) {
1.351     markus   1552:                        arg2 = xstrdup(arg);
                   1553:                        ch = '\0';
                   1554:                        p = hpdelim2(&arg, &ch);
                   1555:                        if (p == NULL || ch == '/') {
                   1556:                                fatal("%s line %d: missing host in %s",
                   1557:                                    filename, linenum,
                   1558:                                    lookup_opcode_name(opcode));
                   1559:                        }
                   1560:                        p = cleanhostname(p);
                   1561:                        /*
                   1562:                         * don't want to use permitopen_port to avoid
                   1563:                         * dependency on channels.[ch] here.
                   1564:                         */
                   1565:                        if (arg == NULL ||
                   1566:                            (strcmp(arg, "*") != 0 && a2port(arg) <= 0)) {
                   1567:                                fatal("%s line %d: bad port number in %s",
                   1568:                                    filename, linenum,
                   1569:                                    lookup_opcode_name(opcode));
                   1570:                        }
                   1571:                        if (*activep && uvalue == 0) {
                   1572:                                opt_array_append(filename, linenum,
                   1573:                                    lookup_opcode_name(opcode),
                   1574:                                    cppptr, uintptr, arg2);
                   1575:                        }
                   1576:                        free(arg2);
                   1577:                }
                   1578:                break;
                   1579:
1.90      stevesk  1580:        case oClearAllForwardings:
                   1581:                intptr = &options->clear_forwardings;
                   1582:                goto parse_flag;
                   1583:
1.17      markus   1584:        case oHost:
1.344     djm      1585:                if (cmdline) {
                   1586:                        error("Host directive not supported as a command-line "
1.206     djm      1587:                            "option");
1.356     djm      1588:                        goto out;
1.344     djm      1589:                }
1.17      markus   1590:                *activep = 0;
1.191     djm      1591:                arg2 = NULL;
1.356     djm      1592:                while ((arg = argv_next(&ac, &av)) != NULL) {
                   1593:                        if (*arg == '\0') {
                   1594:                                error("%s line %d: keyword %s empty argument",
                   1595:                                    filename, linenum, keyword);
                   1596:                                goto out;
                   1597:                        }
                   1598:                        if ((flags & SSHCONF_NEVERMATCH) != 0) {
                   1599:                                argv_consume(&ac);
1.252     djm      1600:                                break;
1.356     djm      1601:                        }
1.191     djm      1602:                        negated = *arg == '!';
                   1603:                        if (negated)
                   1604:                                arg++;
1.38      provos   1605:                        if (match_pattern(host, arg)) {
1.191     djm      1606:                                if (negated) {
                   1607:                                        debug("%.200s line %d: Skipping Host "
                   1608:                                            "block because of negated match "
                   1609:                                            "for %.100s", filename, linenum,
                   1610:                                            arg);
                   1611:                                        *activep = 0;
1.356     djm      1612:                                        argv_consume(&ac);
1.191     djm      1613:                                        break;
                   1614:                                }
                   1615:                                if (!*activep)
                   1616:                                        arg2 = arg; /* logged below */
1.17      markus   1617:                                *activep = 1;
                   1618:                        }
1.191     djm      1619:                }
                   1620:                if (*activep)
                   1621:                        debug("%.200s line %d: Applying options for %.100s",
                   1622:                            filename, linenum, arg2);
1.356     djm      1623:                break;
1.17      markus   1624:
1.206     djm      1625:        case oMatch:
1.344     djm      1626:                if (cmdline) {
                   1627:                        error("Host directive not supported as a command-line "
1.206     djm      1628:                            "option");
1.356     djm      1629:                        goto out;
1.344     djm      1630:                }
1.356     djm      1631:                value = match_cfg_line(options, &str, pw, host, original_host,
1.302     djm      1632:                    flags & SSHCONF_FINAL, want_final_pass,
                   1633:                    filename, linenum);
1.344     djm      1634:                if (value < 0) {
                   1635:                        error("%.200s line %d: Bad Match condition", filename,
1.206     djm      1636:                            linenum);
1.356     djm      1637:                        goto out;
1.344     djm      1638:                }
1.252     djm      1639:                *activep = (flags & SSHCONF_NEVERMATCH) ? 0 : value;
1.356     djm      1640:                /*
                   1641:                 * If match_cfg_line() didn't consume all its arguments then
                   1642:                 * arrange for the extra arguments check below to fail.
                   1643:                 */
                   1644:
                   1645:                if (str == NULL || *str == '\0')
                   1646:                        argv_consume(&ac);
1.206     djm      1647:                break;
                   1648:
1.17      markus   1649:        case oEscapeChar:
                   1650:                intptr = &options->escape_char;
1.356     djm      1651:                arg = argv_next(&ac, &av);
1.344     djm      1652:                if (!arg || *arg == '\0') {
                   1653:                        error("%.200s line %d: Missing argument.",
                   1654:                            filename, linenum);
1.356     djm      1655:                        goto out;
1.344     djm      1656:                }
1.236     djm      1657:                if (strcmp(arg, "none") == 0)
                   1658:                        value = SSH_ESCAPECHAR_NONE;
                   1659:                else if (arg[1] == '\0')
                   1660:                        value = (u_char) arg[0];
                   1661:                else if (arg[0] == '^' && arg[2] == 0 &&
1.51      markus   1662:                    (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
                   1663:                        value = (u_char) arg[1] & 31;
1.17      markus   1664:                else {
1.344     djm      1665:                        error("%.200s line %d: Bad escape character.",
1.93      deraadt  1666:                            filename, linenum);
1.356     djm      1667:                        goto out;
1.17      markus   1668:                }
                   1669:                if (*activep && *intptr == -1)
                   1670:                        *intptr = value;
1.112     djm      1671:                break;
                   1672:
                   1673:        case oAddressFamily:
1.114     djm      1674:                intptr = &options->address_family;
1.207     djm      1675:                multistate_ptr = multistate_addressfamily;
                   1676:                goto parse_multistate;
1.17      markus   1677:
1.101     markus   1678:        case oEnableSSHKeysign:
                   1679:                intptr = &options->enable_ssh_keysign;
                   1680:                goto parse_flag;
                   1681:
1.128     markus   1682:        case oIdentitiesOnly:
                   1683:                intptr = &options->identities_only;
                   1684:                goto parse_flag;
                   1685:
1.127     markus   1686:        case oServerAliveInterval:
                   1687:                intptr = &options->server_alive_interval;
                   1688:                goto parse_time;
                   1689:
                   1690:        case oServerAliveCountMax:
                   1691:                intptr = &options->server_alive_count_max;
                   1692:                goto parse_int;
                   1693:
1.130     djm      1694:        case oSendEnv:
1.356     djm      1695:                while ((arg = argv_next(&ac, &av)) != NULL) {
                   1696:                        if (*arg == '\0' || strchr(arg, '=') != NULL) {
1.344     djm      1697:                                error("%s line %d: Invalid environment name.",
1.130     djm      1698:                                    filename, linenum);
1.356     djm      1699:                                goto out;
1.344     djm      1700:                        }
1.137     djm      1701:                        if (!*activep)
                   1702:                                continue;
1.286     djm      1703:                        if (*arg == '-') {
                   1704:                                /* Removing an env var */
                   1705:                                rm_env(options, arg, filename, linenum);
                   1706:                                continue;
                   1707:                        } else {
                   1708:                                /* Adding an env var */
1.344     djm      1709:                                if (options->num_send_env >= INT_MAX) {
                   1710:                                        error("%s line %d: too many send env.",
1.286     djm      1711:                                            filename, linenum);
1.356     djm      1712:                                        goto out;
1.344     djm      1713:                                }
1.290     djm      1714:                                options->send_env = xrecallocarray(
                   1715:                                    options->send_env, options->num_send_env,
1.291     djm      1716:                                    options->num_send_env + 1,
1.290     djm      1717:                                    sizeof(*options->send_env));
1.286     djm      1718:                                options->send_env[options->num_send_env++] =
                   1719:                                    xstrdup(arg);
                   1720:                        }
1.130     djm      1721:                }
                   1722:                break;
                   1723:
1.290     djm      1724:        case oSetEnv:
                   1725:                value = options->num_setenv;
1.356     djm      1726:                while ((arg = argv_next(&ac, &av)) != NULL) {
1.344     djm      1727:                        if (strchr(arg, '=') == NULL) {
                   1728:                                error("%s line %d: Invalid SetEnv.",
1.290     djm      1729:                                    filename, linenum);
1.356     djm      1730:                                goto out;
1.344     djm      1731:                        }
1.290     djm      1732:                        if (!*activep || value != 0)
                   1733:                                continue;
                   1734:                        /* Adding a setenv var */
1.344     djm      1735:                        if (options->num_setenv >= INT_MAX) {
                   1736:                                error("%s line %d: too many SetEnv.",
1.290     djm      1737:                                    filename, linenum);
1.356     djm      1738:                                goto out;
1.344     djm      1739:                        }
1.290     djm      1740:                        options->setenv = xrecallocarray(
                   1741:                            options->setenv, options->num_setenv,
                   1742:                            options->num_setenv + 1, sizeof(*options->setenv));
                   1743:                        options->setenv[options->num_setenv++] = xstrdup(arg);
                   1744:                }
                   1745:                break;
                   1746:
1.132     djm      1747:        case oControlPath:
                   1748:                charptr = &options->control_path;
                   1749:                goto parse_string;
                   1750:
                   1751:        case oControlMaster:
                   1752:                intptr = &options->control_master;
1.207     djm      1753:                multistate_ptr = multistate_controlmaster;
                   1754:                goto parse_multistate;
1.132     djm      1755:
1.187     djm      1756:        case oControlPersist:
                   1757:                /* no/false/yes/true, or a time spec */
                   1758:                intptr = &options->control_persist;
1.356     djm      1759:                arg = argv_next(&ac, &av);
1.344     djm      1760:                if (!arg || *arg == '\0') {
                   1761:                        error("%.200s line %d: Missing ControlPersist"
1.187     djm      1762:                            " argument.", filename, linenum);
1.356     djm      1763:                        goto out;
1.344     djm      1764:                }
1.187     djm      1765:                value = 0;
                   1766:                value2 = 0;     /* timeout */
                   1767:                if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
                   1768:                        value = 0;
                   1769:                else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
                   1770:                        value = 1;
                   1771:                else if ((value2 = convtime(arg)) >= 0)
                   1772:                        value = 1;
1.344     djm      1773:                else {
                   1774:                        error("%.200s line %d: Bad ControlPersist argument.",
1.187     djm      1775:                            filename, linenum);
1.356     djm      1776:                        goto out;
1.344     djm      1777:                }
1.187     djm      1778:                if (*activep && *intptr == -1) {
                   1779:                        *intptr = value;
                   1780:                        options->control_persist_timeout = value2;
                   1781:                }
                   1782:                break;
                   1783:
1.136     djm      1784:        case oHashKnownHosts:
                   1785:                intptr = &options->hash_known_hosts;
                   1786:                goto parse_flag;
                   1787:
1.144     reyk     1788:        case oTunnel:
                   1789:                intptr = &options->tun_open;
1.207     djm      1790:                multistate_ptr = multistate_tunnel;
                   1791:                goto parse_multistate;
1.144     reyk     1792:
                   1793:        case oTunnelDevice:
1.356     djm      1794:                arg = argv_next(&ac, &av);
1.344     djm      1795:                if (!arg || *arg == '\0') {
                   1796:                        error("%.200s line %d: Missing argument.",
                   1797:                            filename, linenum);
1.356     djm      1798:                        goto out;
1.344     djm      1799:                }
1.144     reyk     1800:                value = a2tun(arg, &value2);
1.344     djm      1801:                if (value == SSH_TUNID_ERR) {
                   1802:                        error("%.200s line %d: Bad tun device.",
                   1803:                            filename, linenum);
1.356     djm      1804:                        goto out;
1.344     djm      1805:                }
1.355     dtucker  1806:                if (*activep && options->tun_local == -1) {
1.144     reyk     1807:                        options->tun_local = value;
                   1808:                        options->tun_remote = value2;
                   1809:                }
                   1810:                break;
                   1811:
                   1812:        case oLocalCommand:
                   1813:                charptr = &options->local_command;
                   1814:                goto parse_command;
                   1815:
                   1816:        case oPermitLocalCommand:
                   1817:                intptr = &options->permit_local_command;
                   1818:                goto parse_flag;
                   1819:
1.277     bluhm    1820:        case oRemoteCommand:
                   1821:                charptr = &options->remote_command;
                   1822:                goto parse_command;
                   1823:
1.167     grunk    1824:        case oVisualHostKey:
                   1825:                intptr = &options->visual_host_key;
                   1826:                goto parse_flag;
                   1827:
1.252     djm      1828:        case oInclude:
1.344     djm      1829:                if (cmdline) {
                   1830:                        error("Include directive not supported as a "
1.252     djm      1831:                            "command-line option");
1.356     djm      1832:                        goto out;
1.344     djm      1833:                }
1.252     djm      1834:                value = 0;
1.356     djm      1835:                while ((arg = argv_next(&ac, &av)) != NULL) {
                   1836:                        if (*arg == '\0') {
                   1837:                                error("%s line %d: keyword %s empty argument",
                   1838:                                    filename, linenum, keyword);
                   1839:                                goto out;
                   1840:                        }
1.252     djm      1841:                        /*
                   1842:                         * Ensure all paths are anchored. User configuration
                   1843:                         * files may begin with '~/' but system configurations
                   1844:                         * must not. If the path is relative, then treat it
                   1845:                         * as living in ~/.ssh for user configurations or
                   1846:                         * /etc/ssh for system ones.
                   1847:                         */
1.344     djm      1848:                        if (*arg == '~' && (flags & SSHCONF_USERCONF) == 0) {
                   1849:                                error("%.200s line %d: bad include path %s.",
1.252     djm      1850:                                    filename, linenum, arg);
1.356     djm      1851:                                goto out;
1.344     djm      1852:                        }
1.301     djm      1853:                        if (!path_absolute(arg) && *arg != '~') {
1.252     djm      1854:                                xasprintf(&arg2, "%s/%s",
                   1855:                                    (flags & SSHCONF_USERCONF) ?
                   1856:                                    "~/" _PATH_SSH_USER_DIR : SSHDIR, arg);
                   1857:                        } else
                   1858:                                arg2 = xstrdup(arg);
                   1859:                        memset(&gl, 0, sizeof(gl));
                   1860:                        r = glob(arg2, GLOB_TILDE, NULL, &gl);
                   1861:                        if (r == GLOB_NOMATCH) {
                   1862:                                debug("%.200s line %d: include %s matched no "
                   1863:                                    "files",filename, linenum, arg2);
1.269     dtucker  1864:                                free(arg2);
1.252     djm      1865:                                continue;
1.344     djm      1866:                        } else if (r != 0) {
                   1867:                                error("%.200s line %d: glob failed for %s.",
1.252     djm      1868:                                    filename, linenum, arg2);
1.356     djm      1869:                                goto out;
1.344     djm      1870:                        }
1.252     djm      1871:                        free(arg2);
                   1872:                        oactive = *activep;
1.313     deraadt  1873:                        for (i = 0; i < gl.gl_pathc; i++) {
1.252     djm      1874:                                debug3("%.200s line %d: Including file %s "
                   1875:                                    "depth %d%s", filename, linenum,
                   1876:                                    gl.gl_pathv[i], depth,
                   1877:                                    oactive ? "" : " (parse only)");
                   1878:                                r = read_config_file_depth(gl.gl_pathv[i],
                   1879:                                    pw, host, original_host, options,
                   1880:                                    flags | SSHCONF_CHECKPERM |
                   1881:                                    (oactive ? 0 : SSHCONF_NEVERMATCH),
1.302     djm      1882:                                    activep, want_final_pass, depth + 1);
1.264     djm      1883:                                if (r != 1 && errno != ENOENT) {
1.344     djm      1884:                                        error("Can't open user config file "
1.263     djm      1885:                                            "%.100s: %.100s", gl.gl_pathv[i],
                   1886:                                            strerror(errno));
1.344     djm      1887:                                        globfree(&gl);
1.356     djm      1888:                                        goto out;
1.263     djm      1889:                                }
1.252     djm      1890:                                /*
                   1891:                                 * don't let Match in includes clobber the
                   1892:                                 * containing file's Match state.
                   1893:                                 */
                   1894:                                *activep = oactive;
                   1895:                                if (r != 1)
                   1896:                                        value = -1;
                   1897:                        }
                   1898:                        globfree(&gl);
                   1899:                }
                   1900:                if (value != 0)
1.356     djm      1901:                        ret = value;
1.252     djm      1902:                break;
                   1903:
1.190     djm      1904:        case oIPQoS:
1.356     djm      1905:                arg = argv_next(&ac, &av);
1.344     djm      1906:                if ((value = parse_ipqos(arg)) == -1) {
                   1907:                        error("%s line %d: Bad IPQoS value: %s",
1.190     djm      1908:                            filename, linenum, arg);
1.356     djm      1909:                        goto out;
1.344     djm      1910:                }
1.356     djm      1911:                arg = argv_next(&ac, &av);
1.190     djm      1912:                if (arg == NULL)
                   1913:                        value2 = value;
1.344     djm      1914:                else if ((value2 = parse_ipqos(arg)) == -1) {
                   1915:                        error("%s line %d: Bad IPQoS value: %s",
1.190     djm      1916:                            filename, linenum, arg);
1.356     djm      1917:                        goto out;
1.344     djm      1918:                }
1.355     dtucker  1919:                if (*activep && options->ip_qos_interactive == -1) {
1.190     djm      1920:                        options->ip_qos_interactive = value;
                   1921:                        options->ip_qos_bulk = value2;
                   1922:                }
                   1923:                break;
                   1924:
1.192     djm      1925:        case oRequestTTY:
                   1926:                intptr = &options->request_tty;
1.207     djm      1927:                multistate_ptr = multistate_requesttty;
                   1928:                goto parse_multistate;
1.192     djm      1929:
1.199     djm      1930:        case oIgnoreUnknown:
                   1931:                charptr = &options->ignored_unknown;
                   1932:                goto parse_string;
                   1933:
1.205     djm      1934:        case oProxyUseFdpass:
                   1935:                intptr = &options->proxy_use_fdpass;
                   1936:                goto parse_flag;
                   1937:
1.208     djm      1938:        case oCanonicalDomains:
                   1939:                value = options->num_canonical_domains != 0;
1.356     djm      1940:                i = 0;
                   1941:                while ((arg = argv_next(&ac, &av)) != NULL) {
                   1942:                        if (*arg == '\0') {
                   1943:                                error("%s line %d: keyword %s empty argument",
                   1944:                                    filename, linenum, keyword);
                   1945:                                goto out;
                   1946:                        }
                   1947:                        /* Allow "none" only in first position */
                   1948:                        if (strcasecmp(arg, "none") == 0) {
                   1949:                                if (i > 0 || ac > 0) {
                   1950:                                        error("%s line %d: keyword %s \"none\" "
                   1951:                                            "argument must appear alone.",
                   1952:                                            filename, linenum, keyword);
                   1953:                                        goto out;
                   1954:                                }
                   1955:                        }
                   1956:                        i++;
1.280     millert  1957:                        if (!valid_domain(arg, 1, &errstr)) {
1.344     djm      1958:                                error("%s line %d: %s", filename, linenum,
1.280     millert  1959:                                    errstr);
1.356     djm      1960:                                goto out;
1.280     millert  1961:                        }
1.208     djm      1962:                        if (!*activep || value)
                   1963:                                continue;
1.344     djm      1964:                        if (options->num_canonical_domains >=
                   1965:                            MAX_CANON_DOMAINS) {
                   1966:                                error("%s line %d: too many hostname suffixes.",
1.208     djm      1967:                                    filename, linenum);
1.356     djm      1968:                                goto out;
1.344     djm      1969:                        }
1.208     djm      1970:                        options->canonical_domains[
                   1971:                            options->num_canonical_domains++] = xstrdup(arg);
                   1972:                }
                   1973:                break;
                   1974:
1.209     djm      1975:        case oCanonicalizePermittedCNAMEs:
1.208     djm      1976:                value = options->num_permitted_cnames != 0;
1.356     djm      1977:                while ((arg = argv_next(&ac, &av)) != NULL) {
1.208     djm      1978:                        /* Either '*' for everything or 'list:list' */
                   1979:                        if (strcmp(arg, "*") == 0)
                   1980:                                arg2 = arg;
                   1981:                        else {
                   1982:                                lowercase(arg);
                   1983:                                if ((arg2 = strchr(arg, ':')) == NULL ||
                   1984:                                    arg2[1] == '\0') {
1.344     djm      1985:                                        error("%s line %d: "
1.208     djm      1986:                                            "Invalid permitted CNAME \"%s\"",
                   1987:                                            filename, linenum, arg);
1.356     djm      1988:                                        goto out;
1.208     djm      1989:                                }
                   1990:                                *arg2 = '\0';
                   1991:                                arg2++;
                   1992:                        }
                   1993:                        if (!*activep || value)
                   1994:                                continue;
1.344     djm      1995:                        if (options->num_permitted_cnames >=
                   1996:                            MAX_CANON_DOMAINS) {
                   1997:                                error("%s line %d: too many permitted CNAMEs.",
1.208     djm      1998:                                    filename, linenum);
1.356     djm      1999:                                goto out;
1.344     djm      2000:                        }
1.208     djm      2001:                        cname = options->permitted_cnames +
                   2002:                            options->num_permitted_cnames++;
                   2003:                        cname->source_list = xstrdup(arg);
                   2004:                        cname->target_list = xstrdup(arg2);
                   2005:                }
                   2006:                break;
                   2007:
1.209     djm      2008:        case oCanonicalizeHostname:
                   2009:                intptr = &options->canonicalize_hostname;
                   2010:                multistate_ptr = multistate_canonicalizehostname;
1.208     djm      2011:                goto parse_multistate;
                   2012:
1.209     djm      2013:        case oCanonicalizeMaxDots:
                   2014:                intptr = &options->canonicalize_max_dots;
1.208     djm      2015:                goto parse_int;
                   2016:
1.209     djm      2017:        case oCanonicalizeFallbackLocal:
                   2018:                intptr = &options->canonicalize_fallback_local;
1.208     djm      2019:                goto parse_flag;
                   2020:
1.220     millert  2021:        case oStreamLocalBindMask:
1.356     djm      2022:                arg = argv_next(&ac, &av);
1.344     djm      2023:                if (!arg || *arg == '\0') {
                   2024:                        error("%.200s line %d: Missing StreamLocalBindMask "
                   2025:                            "argument.", filename, linenum);
1.356     djm      2026:                        goto out;
1.344     djm      2027:                }
1.220     millert  2028:                /* Parse mode in octal format */
                   2029:                value = strtol(arg, &endofnumber, 8);
1.344     djm      2030:                if (arg == endofnumber || value < 0 || value > 0777) {
                   2031:                        error("%.200s line %d: Bad mask.", filename, linenum);
1.356     djm      2032:                        goto out;
1.344     djm      2033:                }
1.220     millert  2034:                options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
                   2035:                break;
                   2036:
                   2037:        case oStreamLocalBindUnlink:
                   2038:                intptr = &options->fwd_opts.streamlocal_bind_unlink;
                   2039:                goto parse_flag;
                   2040:
1.223     djm      2041:        case oRevokedHostKeys:
                   2042:                charptr = &options->revoked_host_keys;
                   2043:                goto parse_string;
                   2044:
1.224     djm      2045:        case oFingerprintHash:
1.225     djm      2046:                intptr = &options->fingerprint_hash;
1.356     djm      2047:                arg = argv_next(&ac, &av);
1.344     djm      2048:                if (!arg || *arg == '\0') {
                   2049:                        error("%.200s line %d: Missing argument.",
1.224     djm      2050:                            filename, linenum);
1.356     djm      2051:                        goto out;
1.344     djm      2052:                }
                   2053:                if ((value = ssh_digest_alg_by_name(arg)) == -1) {
                   2054:                        error("%.200s line %d: Invalid hash algorithm \"%s\".",
1.224     djm      2055:                            filename, linenum, arg);
1.356     djm      2056:                        goto out;
1.344     djm      2057:                }
1.225     djm      2058:                if (*activep && *intptr == -1)
                   2059:                        *intptr = value;
1.224     djm      2060:                break;
                   2061:
1.229     djm      2062:        case oUpdateHostkeys:
                   2063:                intptr = &options->update_hostkeys;
1.232     djm      2064:                multistate_ptr = multistate_yesnoask;
                   2065:                goto parse_multistate;
1.229     djm      2066:
1.350     dtucker  2067:        case oHostbasedAcceptedAlgorithms:
                   2068:                charptr = &options->hostbased_accepted_algos;
1.349     dtucker  2069:                goto parse_pubkey_algos;
1.238     markus   2070:
1.349     dtucker  2071:        case oPubkeyAcceptedAlgorithms:
                   2072:                charptr = &options->pubkey_accepted_algos;
                   2073:                goto parse_pubkey_algos;
1.230     djm      2074:
1.246     jcs      2075:        case oAddKeysToAgent:
1.356     djm      2076:                arg = argv_next(&ac, &av);
                   2077:                arg2 = argv_next(&ac, &av);
1.334     djm      2078:                value = parse_multistate_value(arg, filename, linenum,
1.353     djm      2079:                    multistate_yesnoaskconfirm);
1.334     djm      2080:                value2 = 0; /* unlimited lifespan by default */
                   2081:                if (value == 3 && arg2 != NULL) {
                   2082:                        /* allow "AddKeysToAgent confirm 5m" */
1.344     djm      2083:                        if ((value2 = convtime(arg2)) == -1 ||
                   2084:                            value2 > INT_MAX) {
                   2085:                                error("%s line %d: invalid time value.",
1.334     djm      2086:                                    filename, linenum);
1.356     djm      2087:                                goto out;
1.344     djm      2088:                        }
1.334     djm      2089:                } else if (value == -1 && arg2 == NULL) {
1.344     djm      2090:                        if ((value2 = convtime(arg)) == -1 ||
                   2091:                            value2 > INT_MAX) {
                   2092:                                error("%s line %d: unsupported option",
1.334     djm      2093:                                    filename, linenum);
1.356     djm      2094:                                goto out;
1.344     djm      2095:                        }
1.334     djm      2096:                        value = 1; /* yes */
                   2097:                } else if (value == -1 || arg2 != NULL) {
1.344     djm      2098:                        error("%s line %d: unsupported option",
1.334     djm      2099:                            filename, linenum);
1.356     djm      2100:                        goto out;
1.334     djm      2101:                }
                   2102:                if (*activep && options->add_keys_to_agent == -1) {
                   2103:                        options->add_keys_to_agent = value;
                   2104:                        options->add_keys_to_agent_lifespan = value2;
                   2105:                }
                   2106:                break;
1.246     jcs      2107:
1.253     markus   2108:        case oIdentityAgent:
                   2109:                charptr = &options->identity_agent;
1.356     djm      2110:                arg = argv_next(&ac, &av);
1.344     djm      2111:                if (!arg || *arg == '\0') {
                   2112:                        error("%.200s line %d: Missing argument.",
1.299     djm      2113:                            filename, linenum);
1.356     djm      2114:                        goto out;
1.344     djm      2115:                }
1.319     djm      2116:   parse_agent_path:
1.299     djm      2117:                /* Extra validation if the string represents an env var. */
1.344     djm      2118:                if ((arg2 = dollar_expand(&r, arg)) == NULL || r) {
                   2119:                        error("%.200s line %d: Invalid environment expansion "
1.331     dtucker  2120:                            "%s.", filename, linenum, arg);
1.356     djm      2121:                        goto out;
1.344     djm      2122:                }
1.331     dtucker  2123:                free(arg2);
                   2124:                /* check for legacy environment format */
1.344     djm      2125:                if (arg[0] == '$' && arg[1] != '{' &&
                   2126:                    !valid_env_name(arg + 1)) {
                   2127:                        error("%.200s line %d: Invalid environment name %s.",
1.299     djm      2128:                            filename, linenum, arg);
1.356     djm      2129:                        goto out;
1.299     djm      2130:                }
                   2131:                if (*activep && *charptr == NULL)
                   2132:                        *charptr = xstrdup(arg);
                   2133:                break;
1.253     markus   2134:
1.96      markus   2135:        case oDeprecated:
1.98      markus   2136:                debug("%s line %d: Deprecated option \"%s\"",
1.96      markus   2137:                    filename, linenum, keyword);
1.356     djm      2138:                argv_consume(&ac);
                   2139:                break;
1.96      markus   2140:
1.110     jakob    2141:        case oUnsupported:
                   2142:                error("%s line %d: Unsupported option \"%s\"",
                   2143:                    filename, linenum, keyword);
1.356     djm      2144:                argv_consume(&ac);
                   2145:                break;
1.110     jakob    2146:
1.17      markus   2147:        default:
1.344     djm      2148:                error("%s line %d: Unimplemented opcode %d",
                   2149:                    filename, linenum, opcode);
1.356     djm      2150:                goto out;
1.17      markus   2151:        }
                   2152:
                   2153:        /* Check that there is no garbage at end of line. */
1.356     djm      2154:        if (ac > 0) {
                   2155:                error("%.200s line %d: keyword %s extra arguments "
                   2156:                    "at end of line", filename, linenum, keyword);
                   2157:                goto out;
1.39      ho       2158:        }
1.356     djm      2159:
                   2160:        /* success */
                   2161:        ret = 0;
                   2162:  out:
                   2163:        argv_free(oav, oac);
                   2164:        return ret;
1.1       deraadt  2165: }
                   2166:
1.19      markus   2167: /*
                   2168:  * Reads the config file and modifies the options accordingly.  Options
                   2169:  * should already be initialized before this call.  This never returns if
1.89      stevesk  2170:  * there is an error.  If the file does not exist, this returns 0.
1.19      markus   2171:  */
1.89      stevesk  2172: int
1.206     djm      2173: read_config_file(const char *filename, struct passwd *pw, const char *host,
1.302     djm      2174:     const char *original_host, Options *options, int flags,
                   2175:     int *want_final_pass)
1.1       deraadt  2176: {
1.252     djm      2177:        int active = 1;
                   2178:
                   2179:        return read_config_file_depth(filename, pw, host, original_host,
1.302     djm      2180:            options, flags, &active, want_final_pass, 0);
1.252     djm      2181: }
                   2182:
                   2183: #define READCONF_MAX_DEPTH     16
                   2184: static int
                   2185: read_config_file_depth(const char *filename, struct passwd *pw,
                   2186:     const char *host, const char *original_host, Options *options,
1.302     djm      2187:     int flags, int *activep, int *want_final_pass, int depth)
1.252     djm      2188: {
1.17      markus   2189:        FILE *f;
1.356     djm      2190:        char *line = NULL;
1.289     markus   2191:        size_t linesize = 0;
1.252     djm      2192:        int linenum;
1.17      markus   2193:        int bad_options = 0;
                   2194:
1.252     djm      2195:        if (depth < 0 || depth > READCONF_MAX_DEPTH)
                   2196:                fatal("Too many recursive configuration includes");
                   2197:
1.129     djm      2198:        if ((f = fopen(filename, "r")) == NULL)
1.89      stevesk  2199:                return 0;
1.129     djm      2200:
1.196     dtucker  2201:        if (flags & SSHCONF_CHECKPERM) {
1.129     djm      2202:                struct stat sb;
1.134     deraadt  2203:
1.131     dtucker  2204:                if (fstat(fileno(f), &sb) == -1)
1.129     djm      2205:                        fatal("fstat %s: %s", filename, strerror(errno));
                   2206:                if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1.131     dtucker  2207:                    (sb.st_mode & 022) != 0))
1.129     djm      2208:                        fatal("Bad owner or permissions on %s", filename);
                   2209:        }
1.17      markus   2210:
                   2211:        debug("Reading configuration data %.200s", filename);
                   2212:
1.19      markus   2213:        /*
                   2214:         * Mark that we are now processing the options.  This flag is turned
                   2215:         * on/off by Host specifications.
                   2216:         */
1.17      markus   2217:        linenum = 0;
1.289     markus   2218:        while (getline(&line, &linesize, f) != -1) {
1.17      markus   2219:                /* Update line number counter. */
                   2220:                linenum++;
1.343     dtucker  2221:                /*
                   2222:                 * Trim out comments and strip whitespace.
                   2223:                 * NB - preserve newlines, they are needed to reproduce
                   2224:                 * line numbers later for error messages.
                   2225:                 */
1.252     djm      2226:                if (process_config_line_depth(options, pw, host, original_host,
1.302     djm      2227:                    line, filename, linenum, activep, flags, want_final_pass,
                   2228:                    depth) != 0)
1.17      markus   2229:                        bad_options++;
                   2230:        }
1.289     markus   2231:        free(line);
1.17      markus   2232:        fclose(f);
                   2233:        if (bad_options > 0)
1.64      millert  2234:                fatal("%s: terminating, %d bad configuration options",
1.93      deraadt  2235:                    filename, bad_options);
1.89      stevesk  2236:        return 1;
1.1       deraadt  2237: }
                   2238:
1.218     djm      2239: /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
                   2240: int
                   2241: option_clear_or_none(const char *o)
                   2242: {
                   2243:        return o == NULL || strcasecmp(o, "none") == 0;
                   2244: }
                   2245:
1.19      markus   2246: /*
                   2247:  * Initializes options to special values that indicate that they have not yet
                   2248:  * been set.  Read_config_file will only set options with this value. Options
                   2249:  * are processed in the following order: command line, user config file,
                   2250:  * system config file.  Last, fill_default_options is called.
                   2251:  */
1.1       deraadt  2252:
1.26      markus   2253: void
1.17      markus   2254: initialize_options(Options * options)
1.1       deraadt  2255: {
1.17      markus   2256:        memset(options, 'X', sizeof(*options));
                   2257:        options->forward_agent = -1;
1.319     djm      2258:        options->forward_agent_sock_path = NULL;
1.17      markus   2259:        options->forward_x11 = -1;
1.123     markus   2260:        options->forward_x11_trusted = -1;
1.186     djm      2261:        options->forward_x11_timeout = -1;
1.255     dtucker  2262:        options->stdio_forward_host = NULL;
                   2263:        options->stdio_forward_port = 0;
1.256     dtucker  2264:        options->clear_forwardings = -1;
1.153     markus   2265:        options->exit_on_forward_failure = -1;
1.34      markus   2266:        options->xauth_location = NULL;
1.220     millert  2267:        options->fwd_opts.gateway_ports = -1;
                   2268:        options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
                   2269:        options->fwd_opts.streamlocal_bind_unlink = -1;
1.50      markus   2270:        options->pubkey_authentication = -1;
1.118     markus   2271:        options->gss_authentication = -1;
                   2272:        options->gss_deleg_creds = -1;
1.17      markus   2273:        options->password_authentication = -1;
1.48      markus   2274:        options->kbd_interactive_authentication = -1;
                   2275:        options->kbd_interactive_devices = NULL;
1.72      markus   2276:        options->hostbased_authentication = -1;
1.17      markus   2277:        options->batch_mode = -1;
                   2278:        options->check_host_ip = -1;
                   2279:        options->strict_host_key_checking = -1;
                   2280:        options->compression = -1;
1.126     markus   2281:        options->tcp_keep_alive = -1;
1.17      markus   2282:        options->port = -1;
1.114     djm      2283:        options->address_family = -1;
1.17      markus   2284:        options->connection_attempts = -1;
1.111     djm      2285:        options->connection_timeout = -1;
1.17      markus   2286:        options->number_of_password_prompts = -1;
1.25      markus   2287:        options->ciphers = NULL;
1.62      markus   2288:        options->macs = NULL;
1.189     djm      2289:        options->kex_algorithms = NULL;
1.76      markus   2290:        options->hostkeyalgorithms = NULL;
1.298     djm      2291:        options->ca_sign_algorithms = NULL;
1.17      markus   2292:        options->num_identity_files = 0;
1.344     djm      2293:        memset(options->identity_keys, 0, sizeof(options->identity_keys));
1.241     djm      2294:        options->num_certificate_files = 0;
1.344     djm      2295:        memset(options->certificates, 0, sizeof(options->certificates));
1.17      markus   2296:        options->hostname = NULL;
1.52      markus   2297:        options->host_key_alias = NULL;
1.17      markus   2298:        options->proxy_command = NULL;
1.257     djm      2299:        options->jump_user = NULL;
                   2300:        options->jump_host = NULL;
                   2301:        options->jump_port = -1;
                   2302:        options->jump_extra = NULL;
1.17      markus   2303:        options->user = NULL;
                   2304:        options->escape_char = -1;
1.193     djm      2305:        options->num_system_hostfiles = 0;
                   2306:        options->num_user_hostfiles = 0;
1.185     djm      2307:        options->local_forwards = NULL;
1.17      markus   2308:        options->num_local_forwards = 0;
1.185     djm      2309:        options->remote_forwards = NULL;
1.17      markus   2310:        options->num_remote_forwards = 0;
1.351     markus   2311:        options->permitted_remote_opens = NULL;
                   2312:        options->num_permitted_remote_opens = 0;
1.271     dtucker  2313:        options->log_facility = SYSLOG_FACILITY_NOT_SET;
1.95      markus   2314:        options->log_level = SYSLOG_LEVEL_NOT_SET;
1.339     djm      2315:        options->num_log_verbose = 0;
                   2316:        options->log_verbose = NULL;
1.67      markus   2317:        options->preferred_authentications = NULL;
1.77      markus   2318:        options->bind_address = NULL;
1.282     djm      2319:        options->bind_interface = NULL;
1.183     markus   2320:        options->pkcs11_provider = NULL;
1.310     djm      2321:        options->sk_provider = NULL;
1.101     markus   2322:        options->enable_ssh_keysign = - 1;
1.91      markus   2323:        options->no_host_authentication_for_localhost = - 1;
1.128     markus   2324:        options->identities_only = - 1;
1.105     markus   2325:        options->rekey_limit = - 1;
1.198     dtucker  2326:        options->rekey_interval = -1;
1.107     jakob    2327:        options->verify_host_key_dns = -1;
1.127     markus   2328:        options->server_alive_interval = -1;
                   2329:        options->server_alive_count_max = -1;
1.290     djm      2330:        options->send_env = NULL;
1.130     djm      2331:        options->num_send_env = 0;
1.290     djm      2332:        options->setenv = NULL;
                   2333:        options->num_setenv = 0;
1.132     djm      2334:        options->control_path = NULL;
                   2335:        options->control_master = -1;
1.187     djm      2336:        options->control_persist = -1;
                   2337:        options->control_persist_timeout = 0;
1.136     djm      2338:        options->hash_known_hosts = -1;
1.144     reyk     2339:        options->tun_open = -1;
                   2340:        options->tun_local = -1;
                   2341:        options->tun_remote = -1;
                   2342:        options->local_command = NULL;
                   2343:        options->permit_local_command = -1;
1.277     bluhm    2344:        options->remote_command = NULL;
1.246     jcs      2345:        options->add_keys_to_agent = -1;
1.334     djm      2346:        options->add_keys_to_agent_lifespan = -1;
1.253     markus   2347:        options->identity_agent = NULL;
1.167     grunk    2348:        options->visual_host_key = -1;
1.190     djm      2349:        options->ip_qos_interactive = -1;
                   2350:        options->ip_qos_bulk = -1;
1.192     djm      2351:        options->request_tty = -1;
1.205     djm      2352:        options->proxy_use_fdpass = -1;
1.199     djm      2353:        options->ignored_unknown = NULL;
1.208     djm      2354:        options->num_canonical_domains = 0;
                   2355:        options->num_permitted_cnames = 0;
1.209     djm      2356:        options->canonicalize_max_dots = -1;
                   2357:        options->canonicalize_fallback_local = -1;
                   2358:        options->canonicalize_hostname = -1;
1.223     djm      2359:        options->revoked_host_keys = NULL;
1.224     djm      2360:        options->fingerprint_hash = -1;
1.229     djm      2361:        options->update_hostkeys = -1;
1.350     dtucker  2362:        options->hostbased_accepted_algos = NULL;
1.349     dtucker  2363:        options->pubkey_accepted_algos = NULL;
1.346     djm      2364:        options->known_hosts_command = NULL;
1.1       deraadt  2365: }
                   2366:
1.19      markus   2367: /*
1.218     djm      2368:  * A petite version of fill_default_options() that just fills the options
                   2369:  * needed for hostname canonicalization to proceed.
                   2370:  */
                   2371: void
                   2372: fill_default_options_for_canonicalization(Options *options)
                   2373: {
                   2374:        if (options->canonicalize_max_dots == -1)
                   2375:                options->canonicalize_max_dots = 1;
                   2376:        if (options->canonicalize_fallback_local == -1)
                   2377:                options->canonicalize_fallback_local = 1;
                   2378:        if (options->canonicalize_hostname == -1)
                   2379:                options->canonicalize_hostname = SSH_CANONICALISE_NO;
                   2380: }
                   2381:
                   2382: /*
1.19      markus   2383:  * Called after processing other sources of option data, this fills those
                   2384:  * options for which no value has been specified with their default values.
                   2385:  */
1.344     djm      2386: int
1.17      markus   2387: fill_default_options(Options * options)
1.1       deraadt  2388: {
1.298     djm      2389:        char *all_cipher, *all_mac, *all_kex, *all_key, *all_sig;
1.320     dtucker  2390:        char *def_cipher, *def_mac, *def_kex, *def_key, *def_sig;
1.344     djm      2391:        int ret = 0, r;
1.292     djm      2392:
1.17      markus   2393:        if (options->forward_agent == -1)
1.33      markus   2394:                options->forward_agent = 0;
1.17      markus   2395:        if (options->forward_x11 == -1)
1.23      markus   2396:                options->forward_x11 = 0;
1.123     markus   2397:        if (options->forward_x11_trusted == -1)
                   2398:                options->forward_x11_trusted = 0;
1.186     djm      2399:        if (options->forward_x11_timeout == -1)
                   2400:                options->forward_x11_timeout = 1200;
1.256     dtucker  2401:        /*
                   2402:         * stdio forwarding (-W) changes the default for these but we defer
                   2403:         * setting the values so they can be overridden.
                   2404:         */
1.153     markus   2405:        if (options->exit_on_forward_failure == -1)
1.256     dtucker  2406:                options->exit_on_forward_failure =
                   2407:                    options->stdio_forward_host != NULL ? 1 : 0;
                   2408:        if (options->clear_forwardings == -1)
                   2409:                options->clear_forwardings =
                   2410:                    options->stdio_forward_host != NULL ? 1 : 0;
                   2411:        if (options->clear_forwardings == 1)
                   2412:                clear_forwardings(options);
                   2413:
1.34      markus   2414:        if (options->xauth_location == NULL)
1.344     djm      2415:                options->xauth_location = xstrdup(_PATH_XAUTH);
1.220     millert  2416:        if (options->fwd_opts.gateway_ports == -1)
                   2417:                options->fwd_opts.gateway_ports = 0;
                   2418:        if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
                   2419:                options->fwd_opts.streamlocal_bind_mask = 0177;
                   2420:        if (options->fwd_opts.streamlocal_bind_unlink == -1)
                   2421:                options->fwd_opts.streamlocal_bind_unlink = 0;
1.50      markus   2422:        if (options->pubkey_authentication == -1)
                   2423:                options->pubkey_authentication = 1;
1.118     markus   2424:        if (options->gss_authentication == -1)
1.122     markus   2425:                options->gss_authentication = 0;
1.118     markus   2426:        if (options->gss_deleg_creds == -1)
                   2427:                options->gss_deleg_creds = 0;
1.17      markus   2428:        if (options->password_authentication == -1)
                   2429:                options->password_authentication = 1;
1.48      markus   2430:        if (options->kbd_interactive_authentication == -1)
1.59      markus   2431:                options->kbd_interactive_authentication = 1;
1.72      markus   2432:        if (options->hostbased_authentication == -1)
                   2433:                options->hostbased_authentication = 0;
1.17      markus   2434:        if (options->batch_mode == -1)
                   2435:                options->batch_mode = 0;
                   2436:        if (options->check_host_ip == -1)
1.348     djm      2437:                options->check_host_ip = 0;
1.17      markus   2438:        if (options->strict_host_key_checking == -1)
1.278     djm      2439:                options->strict_host_key_checking = SSH_STRICT_HOSTKEY_ASK;
1.17      markus   2440:        if (options->compression == -1)
                   2441:                options->compression = 0;
1.126     markus   2442:        if (options->tcp_keep_alive == -1)
                   2443:                options->tcp_keep_alive = 1;
1.17      markus   2444:        if (options->port == -1)
                   2445:                options->port = 0;      /* Filled in ssh_connect. */
1.114     djm      2446:        if (options->address_family == -1)
                   2447:                options->address_family = AF_UNSPEC;
1.17      markus   2448:        if (options->connection_attempts == -1)
1.84      markus   2449:                options->connection_attempts = 1;
1.17      markus   2450:        if (options->number_of_password_prompts == -1)
                   2451:                options->number_of_password_prompts = 3;
1.76      markus   2452:        /* options->hostkeyalgorithms, default set in myproposals.h */
1.334     djm      2453:        if (options->add_keys_to_agent == -1) {
1.246     jcs      2454:                options->add_keys_to_agent = 0;
1.334     djm      2455:                options->add_keys_to_agent_lifespan = 0;
                   2456:        }
1.17      markus   2457:        if (options->num_identity_files == 0) {
1.273     djm      2458:                add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_RSA, 0);
                   2459:                add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_DSA, 0);
                   2460:                add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_ECDSA, 0);
                   2461:                add_identity_file(options, "~/",
1.310     djm      2462:                    _PATH_SSH_CLIENT_ID_ECDSA_SK, 0);
                   2463:                add_identity_file(options, "~/",
1.273     djm      2464:                    _PATH_SSH_CLIENT_ID_ED25519, 0);
1.311     markus   2465:                add_identity_file(options, "~/",
                   2466:                    _PATH_SSH_CLIENT_ID_ED25519_SK, 0);
1.283     markus   2467:                add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_XMSS, 0);
1.27      markus   2468:        }
1.17      markus   2469:        if (options->escape_char == -1)
                   2470:                options->escape_char = '~';
1.193     djm      2471:        if (options->num_system_hostfiles == 0) {
                   2472:                options->system_hostfiles[options->num_system_hostfiles++] =
                   2473:                    xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
                   2474:                options->system_hostfiles[options->num_system_hostfiles++] =
                   2475:                    xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
                   2476:        }
1.336     djm      2477:        if (options->update_hostkeys == -1) {
1.338     djm      2478:                if (options->verify_host_key_dns <= 0 &&
                   2479:                    (options->num_user_hostfiles == 0 ||
1.336     djm      2480:                    (options->num_user_hostfiles == 1 && strcmp(options->
1.338     djm      2481:                    user_hostfiles[0], _PATH_SSH_USER_HOSTFILE) == 0)))
1.336     djm      2482:                        options->update_hostkeys = SSH_UPDATE_HOSTKEYS_YES;
                   2483:                else
1.325     djm      2484:                        options->update_hostkeys = SSH_UPDATE_HOSTKEYS_NO;
1.336     djm      2485:        }
1.193     djm      2486:        if (options->num_user_hostfiles == 0) {
                   2487:                options->user_hostfiles[options->num_user_hostfiles++] =
                   2488:                    xstrdup(_PATH_SSH_USER_HOSTFILE);
                   2489:                options->user_hostfiles[options->num_user_hostfiles++] =
                   2490:                    xstrdup(_PATH_SSH_USER_HOSTFILE2);
                   2491:        }
1.95      markus   2492:        if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.54      markus   2493:                options->log_level = SYSLOG_LEVEL_INFO;
1.271     dtucker  2494:        if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
                   2495:                options->log_facility = SYSLOG_FACILITY_USER;
1.91      markus   2496:        if (options->no_host_authentication_for_localhost == - 1)
                   2497:                options->no_host_authentication_for_localhost = 0;
1.128     markus   2498:        if (options->identities_only == -1)
                   2499:                options->identities_only = 0;
1.101     markus   2500:        if (options->enable_ssh_keysign == -1)
                   2501:                options->enable_ssh_keysign = 0;
1.105     markus   2502:        if (options->rekey_limit == -1)
                   2503:                options->rekey_limit = 0;
1.198     dtucker  2504:        if (options->rekey_interval == -1)
                   2505:                options->rekey_interval = 0;
1.107     jakob    2506:        if (options->verify_host_key_dns == -1)
                   2507:                options->verify_host_key_dns = 0;
1.127     markus   2508:        if (options->server_alive_interval == -1)
                   2509:                options->server_alive_interval = 0;
                   2510:        if (options->server_alive_count_max == -1)
                   2511:                options->server_alive_count_max = 3;
1.132     djm      2512:        if (options->control_master == -1)
                   2513:                options->control_master = 0;
1.187     djm      2514:        if (options->control_persist == -1) {
                   2515:                options->control_persist = 0;
                   2516:                options->control_persist_timeout = 0;
                   2517:        }
1.136     djm      2518:        if (options->hash_known_hosts == -1)
                   2519:                options->hash_known_hosts = 0;
1.144     reyk     2520:        if (options->tun_open == -1)
1.145     reyk     2521:                options->tun_open = SSH_TUNMODE_NO;
                   2522:        if (options->tun_local == -1)
                   2523:                options->tun_local = SSH_TUNID_ANY;
                   2524:        if (options->tun_remote == -1)
                   2525:                options->tun_remote = SSH_TUNID_ANY;
1.144     reyk     2526:        if (options->permit_local_command == -1)
                   2527:                options->permit_local_command = 0;
1.167     grunk    2528:        if (options->visual_host_key == -1)
                   2529:                options->visual_host_key = 0;
1.190     djm      2530:        if (options->ip_qos_interactive == -1)
1.284     job      2531:                options->ip_qos_interactive = IPTOS_DSCP_AF21;
1.190     djm      2532:        if (options->ip_qos_bulk == -1)
1.284     job      2533:                options->ip_qos_bulk = IPTOS_DSCP_CS1;
1.192     djm      2534:        if (options->request_tty == -1)
                   2535:                options->request_tty = REQUEST_TTY_AUTO;
1.205     djm      2536:        if (options->proxy_use_fdpass == -1)
                   2537:                options->proxy_use_fdpass = 0;
1.209     djm      2538:        if (options->canonicalize_max_dots == -1)
                   2539:                options->canonicalize_max_dots = 1;
                   2540:        if (options->canonicalize_fallback_local == -1)
                   2541:                options->canonicalize_fallback_local = 1;
                   2542:        if (options->canonicalize_hostname == -1)
                   2543:                options->canonicalize_hostname = SSH_CANONICALISE_NO;
1.224     djm      2544:        if (options->fingerprint_hash == -1)
                   2545:                options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
1.310     djm      2546:        if (options->sk_provider == NULL)
1.314     djm      2547:                options->sk_provider = xstrdup("internal");
1.292     djm      2548:
                   2549:        /* Expand KEX name lists */
                   2550:        all_cipher = cipher_alg_list(',', 0);
                   2551:        all_mac = mac_alg_list(',');
                   2552:        all_kex = kex_alg_list(',');
                   2553:        all_key = sshkey_alg_list(0, 0, 1, ',');
1.298     djm      2554:        all_sig = sshkey_alg_list(0, 1, 1, ',');
1.320     dtucker  2555:        /* remove unsupported algos from default lists */
1.332     djm      2556:        def_cipher = match_filter_allowlist(KEX_CLIENT_ENCRYPT, all_cipher);
                   2557:        def_mac = match_filter_allowlist(KEX_CLIENT_MAC, all_mac);
                   2558:        def_kex = match_filter_allowlist(KEX_CLIENT_KEX, all_kex);
                   2559:        def_key = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
                   2560:        def_sig = match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS, all_sig);
1.297     djm      2561: #define ASSEMBLE(what, defaults, all) \
                   2562:        do { \
                   2563:                if ((r = kex_assemble_names(&options->what, \
1.344     djm      2564:                    defaults, all)) != 0) { \
                   2565:                        error_fr(r, "%s", #what); \
                   2566:                        goto fail; \
                   2567:                } \
1.297     djm      2568:        } while (0)
1.320     dtucker  2569:        ASSEMBLE(ciphers, def_cipher, all_cipher);
                   2570:        ASSEMBLE(macs, def_mac, all_mac);
                   2571:        ASSEMBLE(kex_algorithms, def_kex, all_kex);
1.350     dtucker  2572:        ASSEMBLE(hostbased_accepted_algos, def_key, all_key);
1.349     dtucker  2573:        ASSEMBLE(pubkey_accepted_algos, def_key, all_key);
1.320     dtucker  2574:        ASSEMBLE(ca_sign_algorithms, def_sig, all_sig);
1.297     djm      2575: #undef ASSEMBLE
1.224     djm      2576:
1.207     djm      2577: #define CLEAR_ON_NONE(v) \
                   2578:        do { \
1.218     djm      2579:                if (option_clear_or_none(v)) { \
1.207     djm      2580:                        free(v); \
                   2581:                        v = NULL; \
                   2582:                } \
                   2583:        } while(0)
                   2584:        CLEAR_ON_NONE(options->local_command);
1.277     bluhm    2585:        CLEAR_ON_NONE(options->remote_command);
1.207     djm      2586:        CLEAR_ON_NONE(options->proxy_command);
                   2587:        CLEAR_ON_NONE(options->control_path);
1.223     djm      2588:        CLEAR_ON_NONE(options->revoked_host_keys);
1.304     djm      2589:        CLEAR_ON_NONE(options->pkcs11_provider);
1.310     djm      2590:        CLEAR_ON_NONE(options->sk_provider);
1.346     djm      2591:        CLEAR_ON_NONE(options->known_hosts_command);
1.287     djm      2592:        if (options->jump_host != NULL &&
                   2593:            strcmp(options->jump_host, "none") == 0 &&
                   2594:            options->jump_port == 0 && options->jump_user == NULL) {
                   2595:                free(options->jump_host);
                   2596:                options->jump_host = NULL;
                   2597:        }
1.254     markus   2598:        /* options->identity_agent distinguishes NULL from 'none' */
1.17      markus   2599:        /* options->user will be set in the main program if appropriate */
                   2600:        /* options->hostname will be set in the main program if appropriate */
1.52      markus   2601:        /* options->host_key_alias should not be set by default */
1.67      markus   2602:        /* options->preferred_authentications will be set in ssh */
1.344     djm      2603:
                   2604:        /* success */
                   2605:        ret = 0;
                   2606:  fail:
                   2607:        free(all_cipher);
                   2608:        free(all_mac);
                   2609:        free(all_kex);
                   2610:        free(all_key);
                   2611:        free(all_sig);
                   2612:        free(def_cipher);
                   2613:        free(def_mac);
                   2614:        free(def_kex);
                   2615:        free(def_key);
                   2616:        free(def_sig);
                   2617:        return ret;
                   2618: }
                   2619:
                   2620: void
                   2621: free_options(Options *o)
                   2622: {
                   2623:        int i;
                   2624:
                   2625:        if (o == NULL)
                   2626:                return;
                   2627:
                   2628: #define FREE_ARRAY(type, n, a) \
                   2629:        do { \
                   2630:                type _i; \
                   2631:                for (_i = 0; _i < (n); _i++) \
                   2632:                        free((a)[_i]); \
                   2633:        } while (0)
                   2634:
                   2635:        free(o->forward_agent_sock_path);
                   2636:        free(o->xauth_location);
                   2637:        FREE_ARRAY(u_int, o->num_log_verbose, o->log_verbose);
                   2638:        free(o->log_verbose);
                   2639:        free(o->ciphers);
                   2640:        free(o->macs);
                   2641:        free(o->hostkeyalgorithms);
                   2642:        free(o->kex_algorithms);
                   2643:        free(o->ca_sign_algorithms);
                   2644:        free(o->hostname);
                   2645:        free(o->host_key_alias);
                   2646:        free(o->proxy_command);
                   2647:        free(o->user);
                   2648:        FREE_ARRAY(u_int, o->num_system_hostfiles, o->system_hostfiles);
                   2649:        FREE_ARRAY(u_int, o->num_user_hostfiles, o->user_hostfiles);
                   2650:        free(o->preferred_authentications);
                   2651:        free(o->bind_address);
                   2652:        free(o->bind_interface);
                   2653:        free(o->pkcs11_provider);
                   2654:        free(o->sk_provider);
                   2655:        for (i = 0; i < o->num_identity_files; i++) {
                   2656:                free(o->identity_files[i]);
                   2657:                sshkey_free(o->identity_keys[i]);
                   2658:        }
                   2659:        for (i = 0; i < o->num_certificate_files; i++) {
                   2660:                free(o->certificate_files[i]);
                   2661:                sshkey_free(o->certificates[i]);
                   2662:        }
                   2663:        free(o->identity_agent);
                   2664:        for (i = 0; i < o->num_local_forwards; i++) {
                   2665:                free(o->local_forwards[i].listen_host);
                   2666:                free(o->local_forwards[i].listen_path);
                   2667:                free(o->local_forwards[i].connect_host);
                   2668:                free(o->local_forwards[i].connect_path);
                   2669:        }
                   2670:        free(o->local_forwards);
                   2671:        for (i = 0; i < o->num_remote_forwards; i++) {
                   2672:                free(o->remote_forwards[i].listen_host);
                   2673:                free(o->remote_forwards[i].listen_path);
                   2674:                free(o->remote_forwards[i].connect_host);
                   2675:                free(o->remote_forwards[i].connect_path);
                   2676:        }
                   2677:        free(o->remote_forwards);
                   2678:        free(o->stdio_forward_host);
                   2679:        FREE_ARRAY(int, o->num_send_env, o->send_env);
                   2680:        free(o->send_env);
                   2681:        FREE_ARRAY(int, o->num_setenv, o->setenv);
                   2682:        free(o->setenv);
                   2683:        free(o->control_path);
                   2684:        free(o->local_command);
                   2685:        free(o->remote_command);
                   2686:        FREE_ARRAY(int, o->num_canonical_domains, o->canonical_domains);
                   2687:        for (i = 0; i < o->num_permitted_cnames; i++) {
                   2688:                free(o->permitted_cnames[i].source_list);
                   2689:                free(o->permitted_cnames[i].target_list);
                   2690:        }
                   2691:        free(o->revoked_host_keys);
1.350     dtucker  2692:        free(o->hostbased_accepted_algos);
1.349     dtucker  2693:        free(o->pubkey_accepted_algos);
1.344     djm      2694:        free(o->jump_user);
                   2695:        free(o->jump_host);
                   2696:        free(o->jump_extra);
                   2697:        free(o->ignored_unknown);
                   2698:        explicit_bzero(o, sizeof(*o));
                   2699: #undef FREE_ARRAY
1.135     djm      2700: }
                   2701:
1.220     millert  2702: struct fwdarg {
                   2703:        char *arg;
                   2704:        int ispath;
                   2705: };
                   2706:
                   2707: /*
                   2708:  * parse_fwd_field
                   2709:  * parses the next field in a port forwarding specification.
                   2710:  * sets fwd to the parsed field and advances p past the colon
                   2711:  * or sets it to NULL at end of string.
                   2712:  * returns 0 on success, else non-zero.
                   2713:  */
                   2714: static int
                   2715: parse_fwd_field(char **p, struct fwdarg *fwd)
                   2716: {
                   2717:        char *ep, *cp = *p;
                   2718:        int ispath = 0;
                   2719:
                   2720:        if (*cp == '\0') {
                   2721:                *p = NULL;
                   2722:                return -1;      /* end of string */
                   2723:        }
                   2724:
                   2725:        /*
                   2726:         * A field escaped with square brackets is used literally.
                   2727:         * XXX - allow ']' to be escaped via backslash?
                   2728:         */
                   2729:        if (*cp == '[') {
                   2730:                /* find matching ']' */
                   2731:                for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
                   2732:                        if (*ep == '/')
                   2733:                                ispath = 1;
                   2734:                }
                   2735:                /* no matching ']' or not at end of field. */
                   2736:                if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
                   2737:                        return -1;
                   2738:                /* NUL terminate the field and advance p past the colon */
                   2739:                *ep++ = '\0';
                   2740:                if (*ep != '\0')
                   2741:                        *ep++ = '\0';
                   2742:                fwd->arg = cp + 1;
                   2743:                fwd->ispath = ispath;
                   2744:                *p = ep;
                   2745:                return 0;
                   2746:        }
                   2747:
                   2748:        for (cp = *p; *cp != '\0'; cp++) {
                   2749:                switch (*cp) {
                   2750:                case '\\':
                   2751:                        memmove(cp, cp + 1, strlen(cp + 1) + 1);
1.237     djm      2752:                        if (*cp == '\0')
                   2753:                                return -1;
1.220     millert  2754:                        break;
                   2755:                case '/':
                   2756:                        ispath = 1;
                   2757:                        break;
                   2758:                case ':':
                   2759:                        *cp++ = '\0';
                   2760:                        goto done;
                   2761:                }
                   2762:        }
                   2763: done:
                   2764:        fwd->arg = *p;
                   2765:        fwd->ispath = ispath;
                   2766:        *p = cp;
                   2767:        return 0;
                   2768: }
                   2769:
1.135     djm      2770: /*
                   2771:  * parse_forward
                   2772:  * parses a string containing a port forwarding specification of the form:
1.168     stevesk  2773:  *   dynamicfwd == 0
1.220     millert  2774:  *     [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
                   2775:  *     listenpath:connectpath
1.168     stevesk  2776:  *   dynamicfwd == 1
                   2777:  *     [listenhost:]listenport
1.135     djm      2778:  * returns number of arguments parsed or zero on error
                   2779:  */
                   2780: int
1.220     millert  2781: parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
1.135     djm      2782: {
1.220     millert  2783:        struct fwdarg fwdargs[4];
                   2784:        char *p, *cp;
1.331     dtucker  2785:        int i, err;
1.135     djm      2786:
1.220     millert  2787:        memset(fwd, 0, sizeof(*fwd));
                   2788:        memset(fwdargs, 0, sizeof(fwdargs));
1.135     djm      2789:
1.331     dtucker  2790:        /*
                   2791:         * We expand environment variables before checking if we think they're
                   2792:         * paths so that if ${VAR} expands to a fully qualified path it is
                   2793:         * treated as a path.
                   2794:         */
                   2795:        cp = p = dollar_expand(&err, fwdspec);
                   2796:        if (p == NULL || err)
                   2797:                return 0;
1.135     djm      2798:
                   2799:        /* skip leading spaces */
1.214     deraadt  2800:        while (isspace((u_char)*cp))
1.135     djm      2801:                cp++;
                   2802:
1.220     millert  2803:        for (i = 0; i < 4; ++i) {
                   2804:                if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
1.135     djm      2805:                        break;
1.220     millert  2806:        }
1.135     djm      2807:
1.170     stevesk  2808:        /* Check for trailing garbage */
1.220     millert  2809:        if (cp != NULL && *cp != '\0') {
1.135     djm      2810:                i = 0;  /* failure */
1.220     millert  2811:        }
1.135     djm      2812:
                   2813:        switch (i) {
1.168     stevesk  2814:        case 1:
1.220     millert  2815:                if (fwdargs[0].ispath) {
                   2816:                        fwd->listen_path = xstrdup(fwdargs[0].arg);
                   2817:                        fwd->listen_port = PORT_STREAMLOCAL;
                   2818:                } else {
                   2819:                        fwd->listen_host = NULL;
                   2820:                        fwd->listen_port = a2port(fwdargs[0].arg);
                   2821:                }
1.168     stevesk  2822:                fwd->connect_host = xstrdup("socks");
                   2823:                break;
                   2824:
                   2825:        case 2:
1.220     millert  2826:                if (fwdargs[0].ispath && fwdargs[1].ispath) {
                   2827:                        fwd->listen_path = xstrdup(fwdargs[0].arg);
                   2828:                        fwd->listen_port = PORT_STREAMLOCAL;
                   2829:                        fwd->connect_path = xstrdup(fwdargs[1].arg);
                   2830:                        fwd->connect_port = PORT_STREAMLOCAL;
                   2831:                } else if (fwdargs[1].ispath) {
                   2832:                        fwd->listen_host = NULL;
                   2833:                        fwd->listen_port = a2port(fwdargs[0].arg);
                   2834:                        fwd->connect_path = xstrdup(fwdargs[1].arg);
                   2835:                        fwd->connect_port = PORT_STREAMLOCAL;
                   2836:                } else {
                   2837:                        fwd->listen_host = xstrdup(fwdargs[0].arg);
                   2838:                        fwd->listen_port = a2port(fwdargs[1].arg);
                   2839:                        fwd->connect_host = xstrdup("socks");
                   2840:                }
1.168     stevesk  2841:                break;
                   2842:
1.135     djm      2843:        case 3:
1.220     millert  2844:                if (fwdargs[0].ispath) {
                   2845:                        fwd->listen_path = xstrdup(fwdargs[0].arg);
                   2846:                        fwd->listen_port = PORT_STREAMLOCAL;
                   2847:                        fwd->connect_host = xstrdup(fwdargs[1].arg);
                   2848:                        fwd->connect_port = a2port(fwdargs[2].arg);
                   2849:                } else if (fwdargs[2].ispath) {
                   2850:                        fwd->listen_host = xstrdup(fwdargs[0].arg);
                   2851:                        fwd->listen_port = a2port(fwdargs[1].arg);
                   2852:                        fwd->connect_path = xstrdup(fwdargs[2].arg);
                   2853:                        fwd->connect_port = PORT_STREAMLOCAL;
                   2854:                } else {
                   2855:                        fwd->listen_host = NULL;
                   2856:                        fwd->listen_port = a2port(fwdargs[0].arg);
                   2857:                        fwd->connect_host = xstrdup(fwdargs[1].arg);
                   2858:                        fwd->connect_port = a2port(fwdargs[2].arg);
                   2859:                }
1.135     djm      2860:                break;
                   2861:
                   2862:        case 4:
1.220     millert  2863:                fwd->listen_host = xstrdup(fwdargs[0].arg);
                   2864:                fwd->listen_port = a2port(fwdargs[1].arg);
                   2865:                fwd->connect_host = xstrdup(fwdargs[2].arg);
                   2866:                fwd->connect_port = a2port(fwdargs[3].arg);
1.135     djm      2867:                break;
                   2868:        default:
                   2869:                i = 0; /* failure */
                   2870:        }
                   2871:
1.202     djm      2872:        free(p);
1.135     djm      2873:
1.168     stevesk  2874:        if (dynamicfwd) {
                   2875:                if (!(i == 1 || i == 2))
                   2876:                        goto fail_free;
                   2877:        } else {
1.220     millert  2878:                if (!(i == 3 || i == 4)) {
                   2879:                        if (fwd->connect_path == NULL &&
                   2880:                            fwd->listen_path == NULL)
                   2881:                                goto fail_free;
                   2882:                }
                   2883:                if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
1.168     stevesk  2884:                        goto fail_free;
                   2885:        }
                   2886:
1.220     millert  2887:        if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
                   2888:            (!remotefwd && fwd->listen_port == 0))
1.135     djm      2889:                goto fail_free;
                   2890:        if (fwd->connect_host != NULL &&
                   2891:            strlen(fwd->connect_host) >= NI_MAXHOST)
                   2892:                goto fail_free;
1.356     djm      2893:        /*
                   2894:         * XXX - if connecting to a remote socket, max sun len may not
                   2895:         * match this host
                   2896:         */
1.220     millert  2897:        if (fwd->connect_path != NULL &&
                   2898:            strlen(fwd->connect_path) >= PATH_MAX_SUN)
                   2899:                goto fail_free;
1.176     djm      2900:        if (fwd->listen_host != NULL &&
                   2901:            strlen(fwd->listen_host) >= NI_MAXHOST)
                   2902:                goto fail_free;
1.220     millert  2903:        if (fwd->listen_path != NULL &&
                   2904:            strlen(fwd->listen_path) >= PATH_MAX_SUN)
                   2905:                goto fail_free;
1.135     djm      2906:
                   2907:        return (i);
                   2908:
                   2909:  fail_free:
1.202     djm      2910:        free(fwd->connect_host);
                   2911:        fwd->connect_host = NULL;
1.220     millert  2912:        free(fwd->connect_path);
                   2913:        fwd->connect_path = NULL;
1.202     djm      2914:        free(fwd->listen_host);
                   2915:        fwd->listen_host = NULL;
1.220     millert  2916:        free(fwd->listen_path);
                   2917:        fwd->listen_path = NULL;
1.135     djm      2918:        return (0);
1.221     djm      2919: }
                   2920:
1.257     djm      2921: int
                   2922: parse_jump(const char *s, Options *o, int active)
                   2923: {
                   2924:        char *orig, *sdup, *cp;
                   2925:        char *host = NULL, *user = NULL;
1.345     djm      2926:        int r, ret = -1, port = -1, first;
1.257     djm      2927:
                   2928:        active &= o->proxy_command == NULL && o->jump_host == NULL;
                   2929:
                   2930:        orig = sdup = xstrdup(s);
1.356     djm      2931:
                   2932:        /* Remove comment and trailing whitespace */
                   2933:        if ((cp = strchr(orig, '#')) != NULL)
                   2934:                *cp = '\0';
                   2935:        rtrim(orig);
                   2936:
1.258     naddy    2937:        first = active;
1.259     djm      2938:        do {
1.287     djm      2939:                if (strcasecmp(s, "none") == 0)
                   2940:                        break;
1.259     djm      2941:                if ((cp = strrchr(sdup, ',')) == NULL)
                   2942:                        cp = sdup; /* last */
                   2943:                else
                   2944:                        *cp++ = '\0';
                   2945:
1.258     naddy    2946:                if (first) {
1.257     djm      2947:                        /* First argument and configuration is active */
1.345     djm      2948:                        r = parse_ssh_uri(cp, &user, &host, &port);
                   2949:                        if (r == -1 || (r == 1 &&
                   2950:                            parse_user_host_port(cp, &user, &host, &port) != 0))
1.257     djm      2951:                                goto out;
                   2952:                } else {
                   2953:                        /* Subsequent argument or inactive configuration */
1.345     djm      2954:                        r = parse_ssh_uri(cp, NULL, NULL, NULL);
                   2955:                        if (r == -1 || (r == 1 &&
                   2956:                            parse_user_host_port(cp, NULL, NULL, NULL) != 0))
1.257     djm      2957:                                goto out;
                   2958:                }
1.258     naddy    2959:                first = 0; /* only check syntax for subsequent hosts */
1.259     djm      2960:        } while (cp != sdup);
1.257     djm      2961:        /* success */
1.258     naddy    2962:        if (active) {
1.287     djm      2963:                if (strcasecmp(s, "none") == 0) {
                   2964:                        o->jump_host = xstrdup("none");
                   2965:                        o->jump_port = 0;
                   2966:                } else {
                   2967:                        o->jump_user = user;
                   2968:                        o->jump_host = host;
                   2969:                        o->jump_port = port;
                   2970:                        o->proxy_command = xstrdup("none");
                   2971:                        user = host = NULL;
                   2972:                        if ((cp = strrchr(s, ',')) != NULL && cp != s) {
                   2973:                                o->jump_extra = xstrdup(s);
                   2974:                                o->jump_extra[cp - s] = '\0';
                   2975:                        }
1.259     djm      2976:                }
1.258     naddy    2977:        }
1.257     djm      2978:        ret = 0;
                   2979:  out:
1.258     naddy    2980:        free(orig);
1.257     djm      2981:        free(user);
                   2982:        free(host);
                   2983:        return ret;
1.280     millert  2984: }
                   2985:
                   2986: int
                   2987: parse_ssh_uri(const char *uri, char **userp, char **hostp, int *portp)
                   2988: {
1.344     djm      2989:        char *user = NULL, *host = NULL, *path = NULL;
                   2990:        int r, port;
1.280     millert  2991:
1.344     djm      2992:        r = parse_uri("ssh", uri, &user, &host, &port, &path);
1.280     millert  2993:        if (r == 0 && path != NULL)
                   2994:                r = -1;         /* path not allowed */
1.344     djm      2995:        if (r == 0) {
                   2996:                if (userp != NULL) {
                   2997:                        *userp = user;
                   2998:                        user = NULL;
                   2999:                }
                   3000:                if (hostp != NULL) {
                   3001:                        *hostp = host;
                   3002:                        host = NULL;
                   3003:                }
                   3004:                if (portp != NULL)
                   3005:                        *portp = port;
                   3006:        }
                   3007:        free(user);
                   3008:        free(host);
                   3009:        free(path);
1.280     millert  3010:        return r;
1.257     djm      3011: }
                   3012:
1.221     djm      3013: /* XXX the following is a near-vebatim copy from servconf.c; refactor */
                   3014: static const char *
                   3015: fmt_multistate_int(int val, const struct multistate *m)
                   3016: {
                   3017:        u_int i;
                   3018:
                   3019:        for (i = 0; m[i].key != NULL; i++) {
                   3020:                if (m[i].value == val)
                   3021:                        return m[i].key;
                   3022:        }
                   3023:        return "UNKNOWN";
                   3024: }
                   3025:
                   3026: static const char *
                   3027: fmt_intarg(OpCodes code, int val)
                   3028: {
                   3029:        if (val == -1)
                   3030:                return "unset";
                   3031:        switch (code) {
                   3032:        case oAddressFamily:
                   3033:                return fmt_multistate_int(val, multistate_addressfamily);
                   3034:        case oVerifyHostKeyDNS:
1.232     djm      3035:        case oUpdateHostkeys:
1.221     djm      3036:                return fmt_multistate_int(val, multistate_yesnoask);
1.278     djm      3037:        case oStrictHostKeyChecking:
                   3038:                return fmt_multistate_int(val, multistate_strict_hostkey);
1.221     djm      3039:        case oControlMaster:
                   3040:                return fmt_multistate_int(val, multistate_controlmaster);
                   3041:        case oTunnel:
                   3042:                return fmt_multistate_int(val, multistate_tunnel);
                   3043:        case oRequestTTY:
                   3044:                return fmt_multistate_int(val, multistate_requesttty);
                   3045:        case oCanonicalizeHostname:
                   3046:                return fmt_multistate_int(val, multistate_canonicalizehostname);
1.285     djm      3047:        case oAddKeysToAgent:
                   3048:                return fmt_multistate_int(val, multistate_yesnoaskconfirm);
1.224     djm      3049:        case oFingerprintHash:
                   3050:                return ssh_digest_alg_name(val);
1.221     djm      3051:        default:
                   3052:                switch (val) {
                   3053:                case 0:
                   3054:                        return "no";
                   3055:                case 1:
                   3056:                        return "yes";
                   3057:                default:
                   3058:                        return "UNKNOWN";
                   3059:                }
                   3060:        }
                   3061: }
                   3062:
                   3063: static const char *
                   3064: lookup_opcode_name(OpCodes code)
                   3065: {
                   3066:        u_int i;
                   3067:
                   3068:        for (i = 0; keywords[i].name != NULL; i++)
                   3069:                if (keywords[i].opcode == code)
                   3070:                        return(keywords[i].name);
                   3071:        return "UNKNOWN";
                   3072: }
                   3073:
                   3074: static void
                   3075: dump_cfg_int(OpCodes code, int val)
                   3076: {
                   3077:        printf("%s %d\n", lookup_opcode_name(code), val);
                   3078: }
                   3079:
                   3080: static void
                   3081: dump_cfg_fmtint(OpCodes code, int val)
                   3082: {
                   3083:        printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
                   3084: }
                   3085:
                   3086: static void
                   3087: dump_cfg_string(OpCodes code, const char *val)
                   3088: {
                   3089:        if (val == NULL)
                   3090:                return;
                   3091:        printf("%s %s\n", lookup_opcode_name(code), val);
                   3092: }
                   3093:
                   3094: static void
                   3095: dump_cfg_strarray(OpCodes code, u_int count, char **vals)
                   3096: {
                   3097:        u_int i;
                   3098:
                   3099:        for (i = 0; i < count; i++)
                   3100:                printf("%s %s\n", lookup_opcode_name(code), vals[i]);
                   3101: }
                   3102:
                   3103: static void
                   3104: dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
                   3105: {
                   3106:        u_int i;
                   3107:
                   3108:        printf("%s", lookup_opcode_name(code));
1.356     djm      3109:        if (count == 0)
                   3110:                printf(" none");
1.221     djm      3111:        for (i = 0; i < count; i++)
                   3112:                printf(" %s",  vals[i]);
                   3113:        printf("\n");
                   3114: }
                   3115:
                   3116: static void
                   3117: dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
                   3118: {
                   3119:        const struct Forward *fwd;
                   3120:        u_int i;
                   3121:
                   3122:        /* oDynamicForward */
                   3123:        for (i = 0; i < count; i++) {
                   3124:                fwd = &fwds[i];
1.265     djm      3125:                if (code == oDynamicForward && fwd->connect_host != NULL &&
1.221     djm      3126:                    strcmp(fwd->connect_host, "socks") != 0)
                   3127:                        continue;
1.265     djm      3128:                if (code == oLocalForward && fwd->connect_host != NULL &&
1.221     djm      3129:                    strcmp(fwd->connect_host, "socks") == 0)
                   3130:                        continue;
                   3131:                printf("%s", lookup_opcode_name(code));
                   3132:                if (fwd->listen_port == PORT_STREAMLOCAL)
                   3133:                        printf(" %s", fwd->listen_path);
                   3134:                else if (fwd->listen_host == NULL)
                   3135:                        printf(" %d", fwd->listen_port);
                   3136:                else {
                   3137:                        printf(" [%s]:%d",
                   3138:                            fwd->listen_host, fwd->listen_port);
                   3139:                }
                   3140:                if (code != oDynamicForward) {
                   3141:                        if (fwd->connect_port == PORT_STREAMLOCAL)
                   3142:                                printf(" %s", fwd->connect_path);
                   3143:                        else if (fwd->connect_host == NULL)
                   3144:                                printf(" %d", fwd->connect_port);
                   3145:                        else {
                   3146:                                printf(" [%s]:%d",
                   3147:                                    fwd->connect_host, fwd->connect_port);
                   3148:                        }
                   3149:                }
                   3150:                printf("\n");
                   3151:        }
                   3152: }
                   3153:
                   3154: void
                   3155: dump_client_config(Options *o, const char *host)
                   3156: {
1.326     djm      3157:        int i, r;
                   3158:        char buf[8], *all_key;
                   3159:
                   3160:        /*
                   3161:         * Expand HostKeyAlgorithms name lists. This isn't handled in
                   3162:         * fill_default_options() like the other algorithm lists because
                   3163:         * the host key algorithms are by default dynamically chosen based
                   3164:         * on the host's keys found in known_hosts.
                   3165:         */
                   3166:        all_key = sshkey_alg_list(0, 0, 1, ',');
                   3167:        if ((r = kex_assemble_names(&o->hostkeyalgorithms, kex_default_pk_alg(),
                   3168:            all_key)) != 0)
1.340     djm      3169:                fatal_fr(r, "expand HostKeyAlgorithms");
1.326     djm      3170:        free(all_key);
1.240     djm      3171:
1.221     djm      3172:        /* Most interesting options first: user, host, port */
                   3173:        dump_cfg_string(oUser, o->user);
1.306     jmc      3174:        dump_cfg_string(oHostname, host);
1.221     djm      3175:        dump_cfg_int(oPort, o->port);
                   3176:
                   3177:        /* Flag options */
                   3178:        dump_cfg_fmtint(oAddressFamily, o->address_family);
                   3179:        dump_cfg_fmtint(oBatchMode, o->batch_mode);
                   3180:        dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
                   3181:        dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
                   3182:        dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
                   3183:        dump_cfg_fmtint(oCompression, o->compression);
                   3184:        dump_cfg_fmtint(oControlMaster, o->control_master);
                   3185:        dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
1.256     dtucker  3186:        dump_cfg_fmtint(oClearAllForwardings, o->clear_forwardings);
1.221     djm      3187:        dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
1.224     djm      3188:        dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
1.221     djm      3189:        dump_cfg_fmtint(oForwardX11, o->forward_x11);
                   3190:        dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
                   3191:        dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
                   3192: #ifdef GSSAPI
                   3193:        dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
                   3194:        dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
                   3195: #endif /* GSSAPI */
                   3196:        dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
                   3197:        dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
                   3198:        dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
                   3199:        dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
                   3200:        dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
                   3201:        dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
                   3202:        dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
                   3203:        dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
                   3204:        dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
                   3205:        dump_cfg_fmtint(oRequestTTY, o->request_tty);
                   3206:        dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
                   3207:        dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
                   3208:        dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
                   3209:        dump_cfg_fmtint(oTunnel, o->tun_open);
                   3210:        dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
                   3211:        dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
1.229     djm      3212:        dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
1.221     djm      3213:
                   3214:        /* Integer options */
                   3215:        dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
                   3216:        dump_cfg_int(oConnectionAttempts, o->connection_attempts);
                   3217:        dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
                   3218:        dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
                   3219:        dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
                   3220:        dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
                   3221:
                   3222:        /* String options */
                   3223:        dump_cfg_string(oBindAddress, o->bind_address);
1.282     djm      3224:        dump_cfg_string(oBindInterface, o->bind_interface);
1.320     dtucker  3225:        dump_cfg_string(oCiphers, o->ciphers);
1.221     djm      3226:        dump_cfg_string(oControlPath, o->control_path);
1.240     djm      3227:        dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
1.221     djm      3228:        dump_cfg_string(oHostKeyAlias, o->host_key_alias);
1.350     dtucker  3229:        dump_cfg_string(oHostbasedAcceptedAlgorithms, o->hostbased_accepted_algos);
1.253     markus   3230:        dump_cfg_string(oIdentityAgent, o->identity_agent);
1.285     djm      3231:        dump_cfg_string(oIgnoreUnknown, o->ignored_unknown);
1.221     djm      3232:        dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
1.320     dtucker  3233:        dump_cfg_string(oKexAlgorithms, o->kex_algorithms);
                   3234:        dump_cfg_string(oCASignatureAlgorithms, o->ca_sign_algorithms);
1.221     djm      3235:        dump_cfg_string(oLocalCommand, o->local_command);
1.277     bluhm    3236:        dump_cfg_string(oRemoteCommand, o->remote_command);
1.221     djm      3237:        dump_cfg_string(oLogLevel, log_level_name(o->log_level));
1.320     dtucker  3238:        dump_cfg_string(oMacs, o->macs);
1.266     djm      3239: #ifdef ENABLE_PKCS11
1.221     djm      3240:        dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
1.266     djm      3241: #endif
1.310     djm      3242:        dump_cfg_string(oSecurityKeyProvider, o->sk_provider);
1.221     djm      3243:        dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
1.349     dtucker  3244:        dump_cfg_string(oPubkeyAcceptedAlgorithms, o->pubkey_accepted_algos);
1.230     djm      3245:        dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
1.221     djm      3246:        dump_cfg_string(oXAuthLocation, o->xauth_location);
1.346     djm      3247:        dump_cfg_string(oKnownHostsCommand, o->known_hosts_command);
1.221     djm      3248:
1.230     djm      3249:        /* Forwards */
1.221     djm      3250:        dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
                   3251:        dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
                   3252:        dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
                   3253:
                   3254:        /* String array options */
                   3255:        dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
                   3256:        dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
1.285     djm      3257:        dump_cfg_strarray(oCertificateFile, o->num_certificate_files, o->certificate_files);
1.221     djm      3258:        dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
                   3259:        dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
                   3260:        dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
1.290     djm      3261:        dump_cfg_strarray(oSetEnv, o->num_setenv, o->setenv);
1.339     djm      3262:        dump_cfg_strarray_oneline(oLogVerbose,
                   3263:            o->num_log_verbose, o->log_verbose);
1.221     djm      3264:
                   3265:        /* Special cases */
1.351     markus   3266:
                   3267:        /* PermitRemoteOpen */
                   3268:        if (o->num_permitted_remote_opens == 0)
                   3269:                printf("%s any\n", lookup_opcode_name(oPermitRemoteOpen));
                   3270:        else
                   3271:                dump_cfg_strarray_oneline(oPermitRemoteOpen,
                   3272:                    o->num_permitted_remote_opens, o->permitted_remote_opens);
1.334     djm      3273:
                   3274:        /* AddKeysToAgent */
                   3275:        if (o->add_keys_to_agent_lifespan <= 0)
                   3276:                dump_cfg_fmtint(oAddKeysToAgent, o->add_keys_to_agent);
                   3277:        else {
                   3278:                printf("addkeystoagent%s %d\n",
                   3279:                    o->add_keys_to_agent == 3 ? " confirm" : "",
                   3280:                    o->add_keys_to_agent_lifespan);
                   3281:        }
1.319     djm      3282:
                   3283:        /* oForwardAgent */
                   3284:        if (o->forward_agent_sock_path == NULL)
                   3285:                dump_cfg_fmtint(oForwardAgent, o->forward_agent);
                   3286:        else
                   3287:                dump_cfg_string(oForwardAgent, o->forward_agent_sock_path);
1.221     djm      3288:
                   3289:        /* oConnectTimeout */
                   3290:        if (o->connection_timeout == -1)
                   3291:                printf("connecttimeout none\n");
                   3292:        else
                   3293:                dump_cfg_int(oConnectTimeout, o->connection_timeout);
                   3294:
                   3295:        /* oTunnelDevice */
                   3296:        printf("tunneldevice");
                   3297:        if (o->tun_local == SSH_TUNID_ANY)
                   3298:                printf(" any");
                   3299:        else
                   3300:                printf(" %d", o->tun_local);
                   3301:        if (o->tun_remote == SSH_TUNID_ANY)
                   3302:                printf(":any");
                   3303:        else
                   3304:                printf(":%d", o->tun_remote);
                   3305:        printf("\n");
                   3306:
                   3307:        /* oCanonicalizePermittedCNAMEs */
                   3308:        if ( o->num_permitted_cnames > 0) {
                   3309:                printf("canonicalizePermittedcnames");
                   3310:                for (i = 0; i < o->num_permitted_cnames; i++) {
                   3311:                        printf(" %s:%s", o->permitted_cnames[i].source_list,
                   3312:                            o->permitted_cnames[i].target_list);
                   3313:                }
                   3314:                printf("\n");
                   3315:        }
                   3316:
                   3317:        /* oControlPersist */
                   3318:        if (o->control_persist == 0 || o->control_persist_timeout == 0)
                   3319:                dump_cfg_fmtint(oControlPersist, o->control_persist);
                   3320:        else
                   3321:                dump_cfg_int(oControlPersist, o->control_persist_timeout);
                   3322:
                   3323:        /* oEscapeChar */
                   3324:        if (o->escape_char == SSH_ESCAPECHAR_NONE)
                   3325:                printf("escapechar none\n");
                   3326:        else {
1.257     djm      3327:                vis(buf, o->escape_char, VIS_WHITE, 0);
                   3328:                printf("escapechar %s\n", buf);
1.221     djm      3329:        }
                   3330:
                   3331:        /* oIPQoS */
                   3332:        printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
                   3333:        printf("%s\n", iptos2str(o->ip_qos_bulk));
                   3334:
                   3335:        /* oRekeyLimit */
1.249     dtucker  3336:        printf("rekeylimit %llu %d\n",
                   3337:            (unsigned long long)o->rekey_limit, o->rekey_interval);
1.221     djm      3338:
                   3339:        /* oStreamLocalBindMask */
                   3340:        printf("streamlocalbindmask 0%o\n",
                   3341:            o->fwd_opts.streamlocal_bind_mask);
1.285     djm      3342:
                   3343:        /* oLogFacility */
                   3344:        printf("syslogfacility %s\n", log_facility_name(o->log_facility));
1.257     djm      3345:
                   3346:        /* oProxyCommand / oProxyJump */
                   3347:        if (o->jump_host == NULL)
                   3348:                dump_cfg_string(oProxyCommand, o->proxy_command);
                   3349:        else {
                   3350:                /* Check for numeric addresses */
                   3351:                i = strchr(o->jump_host, ':') != NULL ||
                   3352:                    strspn(o->jump_host, "1234567890.") == strlen(o->jump_host);
                   3353:                snprintf(buf, sizeof(buf), "%d", o->jump_port);
                   3354:                printf("proxyjump %s%s%s%s%s%s%s%s%s\n",
1.259     djm      3355:                    /* optional additional jump spec */
                   3356:                    o->jump_extra == NULL ? "" : o->jump_extra,
                   3357:                    o->jump_extra == NULL ? "" : ",",
1.257     djm      3358:                    /* optional user */
                   3359:                    o->jump_user == NULL ? "" : o->jump_user,
                   3360:                    o->jump_user == NULL ? "" : "@",
                   3361:                    /* opening [ if hostname is numeric */
                   3362:                    i ? "[" : "",
                   3363:                    /* mandatory hostname */
                   3364:                    o->jump_host,
                   3365:                    /* closing ] if hostname is numeric */
                   3366:                    i ? "]" : "",
                   3367:                    /* optional port number */
                   3368:                    o->jump_port <= 0 ? "" : ":",
1.259     djm      3369:                    o->jump_port <= 0 ? "" : buf);
1.257     djm      3370:        }
1.1       deraadt  3371: }