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