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