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