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