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