Annotation of src/usr.bin/ssh/readconf.c, Revision 1.247
1.247 ! deraadt 1: /* $OpenBSD: readconf.c,v 1.246 2015/11/15 22:26:49 jcs 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.216 djm 144: oVisualHostKey, oUseRoaming,
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.177 andreas 255: { "useroaming", oUseRoaming },
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));
967: /* check for too-large or too-small limits */
968: if (val64 > UINT_MAX)
1.198 dtucker 969: fatal("%.200s line %d: RekeyLimit too large",
970: filename, linenum);
971: if (val64 != 0 && val64 < 16)
972: fatal("%.200s line %d: RekeyLimit too small",
973: filename, linenum);
1.105 markus 974: }
1.165 djm 975: if (*activep && options->rekey_limit == -1)
976: options->rekey_limit = (u_int32_t)val64;
1.198 dtucker 977: if (s != NULL) { /* optional rekey interval present */
978: if (strcmp(s, "none") == 0) {
979: (void)strdelim(&s); /* discard */
980: break;
981: }
982: intptr = &options->rekey_interval;
983: goto parse_time;
984: }
1.105 markus 985: break;
986:
1.17 markus 987: case oIdentityFile:
1.42 provos 988: arg = strdelim(&s);
1.40 ho 989: if (!arg || *arg == '\0')
1.17 markus 990: fatal("%.200s line %d: Missing argument.", filename, linenum);
991: if (*activep) {
1.50 markus 992: intptr = &options->num_identity_files;
1.27 markus 993: if (*intptr >= SSH_MAX_IDENTITY_FILES)
1.17 markus 994: fatal("%.200s line %d: Too many identity files specified (max %d).",
1.93 deraadt 995: filename, linenum, SSH_MAX_IDENTITY_FILES);
1.221 djm 996: add_identity_file(options, NULL,
997: arg, flags & SSHCONF_USERCONF);
1.17 markus 998: }
999: break;
1000:
1.241 djm 1001: case oCertificateFile:
1002: arg = strdelim(&s);
1003: if (!arg || *arg == '\0')
1004: fatal("%.200s line %d: Missing argument.",
1005: filename, linenum);
1006: if (*activep) {
1007: intptr = &options->num_certificate_files;
1008: if (*intptr >= SSH_MAX_CERTIFICATE_FILES) {
1009: fatal("%.200s line %d: Too many certificate "
1010: "files specified (max %d).",
1011: filename, linenum,
1012: SSH_MAX_CERTIFICATE_FILES);
1013: }
1014: add_certificate_file(options, arg,
1015: flags & SSHCONF_USERCONF);
1016: }
1017: break;
1018:
1.34 markus 1019: case oXAuthLocation:
1020: charptr=&options->xauth_location;
1021: goto parse_string;
1022:
1.17 markus 1023: case oUser:
1024: charptr = &options->user;
1025: parse_string:
1.42 provos 1026: arg = strdelim(&s);
1.40 ho 1027: if (!arg || *arg == '\0')
1.193 djm 1028: fatal("%.200s line %d: Missing argument.",
1029: filename, linenum);
1.17 markus 1030: if (*activep && *charptr == NULL)
1.38 provos 1031: *charptr = xstrdup(arg);
1.17 markus 1032: break;
1033:
1034: case oGlobalKnownHostsFile:
1.193 djm 1035: cpptr = (char **)&options->system_hostfiles;
1036: uintptr = &options->num_system_hostfiles;
1037: max_entries = SSH_MAX_HOSTS_FILES;
1038: parse_char_array:
1039: if (*activep && *uintptr == 0) {
1040: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1041: if ((*uintptr) >= max_entries)
1042: fatal("%s line %d: "
1043: "too many authorized keys files.",
1044: filename, linenum);
1045: cpptr[(*uintptr)++] = xstrdup(arg);
1046: }
1047: }
1048: return 0;
1.17 markus 1049:
1050: case oUserKnownHostsFile:
1.193 djm 1051: cpptr = (char **)&options->user_hostfiles;
1052: uintptr = &options->num_user_hostfiles;
1053: max_entries = SSH_MAX_HOSTS_FILES;
1054: goto parse_char_array;
1.27 markus 1055:
1.17 markus 1056: case oHostName:
1057: charptr = &options->hostname;
1058: goto parse_string;
1059:
1.52 markus 1060: case oHostKeyAlias:
1061: charptr = &options->host_key_alias;
1062: goto parse_string;
1063:
1.67 markus 1064: case oPreferredAuthentications:
1065: charptr = &options->preferred_authentications;
1066: goto parse_string;
1067:
1.77 markus 1068: case oBindAddress:
1069: charptr = &options->bind_address;
1070: goto parse_string;
1071:
1.183 markus 1072: case oPKCS11Provider:
1073: charptr = &options->pkcs11_provider;
1.86 markus 1074: goto parse_string;
1.85 jakob 1075:
1.17 markus 1076: case oProxyCommand:
1.144 reyk 1077: charptr = &options->proxy_command;
1078: parse_command:
1.113 markus 1079: if (s == NULL)
1080: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.102 markus 1081: len = strspn(s, WHITESPACE "=");
1.17 markus 1082: if (*activep && *charptr == NULL)
1.102 markus 1083: *charptr = xstrdup(s + len);
1.17 markus 1084: return 0;
1085:
1086: case oPort:
1087: intptr = &options->port;
1088: parse_int:
1.42 provos 1089: arg = strdelim(&s);
1.40 ho 1090: if (!arg || *arg == '\0')
1.17 markus 1091: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 1092: if (arg[0] < '0' || arg[0] > '9')
1.17 markus 1093: fatal("%.200s line %d: Bad number.", filename, linenum);
1.21 markus 1094:
1095: /* Octal, decimal, or hex format? */
1.38 provos 1096: value = strtol(arg, &endofnumber, 0);
1097: if (arg == endofnumber)
1.21 markus 1098: fatal("%.200s line %d: Bad number.", filename, linenum);
1.17 markus 1099: if (*activep && *intptr == -1)
1100: *intptr = value;
1101: break;
1102:
1103: case oConnectionAttempts:
1104: intptr = &options->connection_attempts;
1105: goto parse_int;
1106:
1107: case oCipher:
1108: intptr = &options->cipher;
1.42 provos 1109: arg = strdelim(&s);
1.40 ho 1110: if (!arg || *arg == '\0')
1.32 markus 1111: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 1112: value = cipher_number(arg);
1.17 markus 1113: if (value == -1)
1114: fatal("%.200s line %d: Bad cipher '%s'.",
1.93 deraadt 1115: filename, linenum, arg ? arg : "<NONE>");
1.17 markus 1116: if (*activep && *intptr == -1)
1117: *intptr = value;
1118: break;
1119:
1.25 markus 1120: case oCiphers:
1.42 provos 1121: arg = strdelim(&s);
1.40 ho 1122: if (!arg || *arg == '\0')
1.32 markus 1123: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.239 djm 1124: if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
1.31 markus 1125: fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.93 deraadt 1126: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 1127: if (*activep && options->ciphers == NULL)
1.38 provos 1128: options->ciphers = xstrdup(arg);
1.25 markus 1129: break;
1130:
1.62 markus 1131: case oMacs:
1132: arg = strdelim(&s);
1133: if (!arg || *arg == '\0')
1134: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.239 djm 1135: if (!mac_valid(*arg == '+' ? arg + 1 : arg))
1.62 markus 1136: fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
1.93 deraadt 1137: filename, linenum, arg ? arg : "<NONE>");
1.62 markus 1138: if (*activep && options->macs == NULL)
1139: options->macs = xstrdup(arg);
1140: break;
1141:
1.189 djm 1142: case oKexAlgorithms:
1143: arg = strdelim(&s);
1144: if (!arg || *arg == '\0')
1145: fatal("%.200s line %d: Missing argument.",
1146: filename, linenum);
1.239 djm 1147: if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
1.189 djm 1148: fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1149: filename, linenum, arg ? arg : "<NONE>");
1150: if (*activep && options->kex_algorithms == NULL)
1151: options->kex_algorithms = xstrdup(arg);
1152: break;
1153:
1.76 markus 1154: case oHostKeyAlgorithms:
1.238 markus 1155: charptr = &options->hostkeyalgorithms;
1156: parse_keytypes:
1.76 markus 1157: arg = strdelim(&s);
1158: if (!arg || *arg == '\0')
1.238 markus 1159: fatal("%.200s line %d: Missing argument.",
1160: filename, linenum);
1.239 djm 1161: if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1.238 markus 1162: fatal("%s line %d: Bad key types '%s'.",
1163: filename, linenum, arg ? arg : "<NONE>");
1164: if (*activep && *charptr == NULL)
1165: *charptr = xstrdup(arg);
1.76 markus 1166: break;
1167:
1.25 markus 1168: case oProtocol:
1169: intptr = &options->protocol;
1.42 provos 1170: arg = strdelim(&s);
1.40 ho 1171: if (!arg || *arg == '\0')
1.32 markus 1172: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 1173: value = proto_spec(arg);
1.25 markus 1174: if (value == SSH_PROTO_UNKNOWN)
1175: fatal("%.200s line %d: Bad protocol spec '%s'.",
1.93 deraadt 1176: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 1177: if (*activep && *intptr == SSH_PROTO_UNKNOWN)
1178: *intptr = value;
1179: break;
1180:
1.17 markus 1181: case oLogLevel:
1.164 dtucker 1182: log_level_ptr = &options->log_level;
1.42 provos 1183: arg = strdelim(&s);
1.38 provos 1184: value = log_level_number(arg);
1.95 markus 1185: if (value == SYSLOG_LEVEL_NOT_SET)
1.64 millert 1186: fatal("%.200s line %d: unsupported log level '%s'",
1.93 deraadt 1187: filename, linenum, arg ? arg : "<NONE>");
1.164 dtucker 1188: if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
1189: *log_level_ptr = (LogLevel) value;
1.17 markus 1190: break;
1191:
1.88 stevesk 1192: case oLocalForward:
1.17 markus 1193: case oRemoteForward:
1.168 stevesk 1194: case oDynamicForward:
1.42 provos 1195: arg = strdelim(&s);
1.135 djm 1196: if (arg == NULL || *arg == '\0')
1.88 stevesk 1197: fatal("%.200s line %d: Missing port argument.",
1198: filename, linenum);
1.135 djm 1199:
1.168 stevesk 1200: if (opcode == oLocalForward ||
1201: opcode == oRemoteForward) {
1202: arg2 = strdelim(&s);
1203: if (arg2 == NULL || *arg2 == '\0')
1204: fatal("%.200s line %d: Missing target argument.",
1205: filename, linenum);
1.135 djm 1206:
1.168 stevesk 1207: /* construct a string for parse_forward */
1208: snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
1209: } else if (opcode == oDynamicForward) {
1210: strlcpy(fwdarg, arg, sizeof(fwdarg));
1211: }
1212:
1213: if (parse_forward(&fwd, fwdarg,
1.176 djm 1214: opcode == oDynamicForward ? 1 : 0,
1215: opcode == oRemoteForward ? 1 : 0) == 0)
1.88 stevesk 1216: fatal("%.200s line %d: Bad forwarding specification.",
1217: filename, linenum);
1.135 djm 1218:
1.88 stevesk 1219: if (*activep) {
1.168 stevesk 1220: if (opcode == oLocalForward ||
1221: opcode == oDynamicForward)
1.135 djm 1222: add_local_forward(options, &fwd);
1.88 stevesk 1223: else if (opcode == oRemoteForward)
1.135 djm 1224: add_remote_forward(options, &fwd);
1.88 stevesk 1225: }
1.17 markus 1226: break;
1.71 markus 1227:
1.90 stevesk 1228: case oClearAllForwardings:
1229: intptr = &options->clear_forwardings;
1230: goto parse_flag;
1231:
1.17 markus 1232: case oHost:
1.206 djm 1233: if (cmdline)
1234: fatal("Host directive not supported as a command-line "
1235: "option");
1.17 markus 1236: *activep = 0;
1.191 djm 1237: arg2 = NULL;
1238: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1239: negated = *arg == '!';
1240: if (negated)
1241: arg++;
1.38 provos 1242: if (match_pattern(host, arg)) {
1.191 djm 1243: if (negated) {
1244: debug("%.200s line %d: Skipping Host "
1245: "block because of negated match "
1246: "for %.100s", filename, linenum,
1247: arg);
1248: *activep = 0;
1249: break;
1250: }
1251: if (!*activep)
1252: arg2 = arg; /* logged below */
1.17 markus 1253: *activep = 1;
1254: }
1.191 djm 1255: }
1256: if (*activep)
1257: debug("%.200s line %d: Applying options for %.100s",
1258: filename, linenum, arg2);
1.42 provos 1259: /* Avoid garbage check below, as strdelim is done. */
1.17 markus 1260: return 0;
1261:
1.206 djm 1262: case oMatch:
1263: if (cmdline)
1264: fatal("Host directive not supported as a command-line "
1265: "option");
1.221 djm 1266: value = match_cfg_line(options, &s, pw, host, original_host,
1267: flags & SSHCONF_POSTCANON, filename, linenum);
1.206 djm 1268: if (value < 0)
1269: fatal("%.200s line %d: Bad Match condition", filename,
1270: linenum);
1271: *activep = value;
1272: break;
1273:
1.17 markus 1274: case oEscapeChar:
1275: intptr = &options->escape_char;
1.42 provos 1276: arg = strdelim(&s);
1.40 ho 1277: if (!arg || *arg == '\0')
1.17 markus 1278: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.236 djm 1279: if (strcmp(arg, "none") == 0)
1280: value = SSH_ESCAPECHAR_NONE;
1281: else if (arg[1] == '\0')
1282: value = (u_char) arg[0];
1283: else if (arg[0] == '^' && arg[2] == 0 &&
1.51 markus 1284: (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
1285: value = (u_char) arg[1] & 31;
1.17 markus 1286: else {
1287: fatal("%.200s line %d: Bad escape character.",
1.93 deraadt 1288: filename, linenum);
1.17 markus 1289: /* NOTREACHED */
1290: value = 0; /* Avoid compiler warning. */
1291: }
1292: if (*activep && *intptr == -1)
1293: *intptr = value;
1.112 djm 1294: break;
1295:
1296: case oAddressFamily:
1.114 djm 1297: intptr = &options->address_family;
1.207 djm 1298: multistate_ptr = multistate_addressfamily;
1299: goto parse_multistate;
1.17 markus 1300:
1.101 markus 1301: case oEnableSSHKeysign:
1302: intptr = &options->enable_ssh_keysign;
1303: goto parse_flag;
1304:
1.128 markus 1305: case oIdentitiesOnly:
1306: intptr = &options->identities_only;
1307: goto parse_flag;
1308:
1.127 markus 1309: case oServerAliveInterval:
1310: intptr = &options->server_alive_interval;
1311: goto parse_time;
1312:
1313: case oServerAliveCountMax:
1314: intptr = &options->server_alive_count_max;
1315: goto parse_int;
1316:
1.130 djm 1317: case oSendEnv:
1318: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1319: if (strchr(arg, '=') != NULL)
1320: fatal("%s line %d: Invalid environment name.",
1321: filename, linenum);
1.137 djm 1322: if (!*activep)
1323: continue;
1.130 djm 1324: if (options->num_send_env >= MAX_SEND_ENV)
1325: fatal("%s line %d: too many send env.",
1326: filename, linenum);
1327: options->send_env[options->num_send_env++] =
1328: xstrdup(arg);
1329: }
1330: break;
1331:
1.132 djm 1332: case oControlPath:
1333: charptr = &options->control_path;
1334: goto parse_string;
1335:
1336: case oControlMaster:
1337: intptr = &options->control_master;
1.207 djm 1338: multistate_ptr = multistate_controlmaster;
1339: goto parse_multistate;
1.132 djm 1340:
1.187 djm 1341: case oControlPersist:
1342: /* no/false/yes/true, or a time spec */
1343: intptr = &options->control_persist;
1344: arg = strdelim(&s);
1345: if (!arg || *arg == '\0')
1346: fatal("%.200s line %d: Missing ControlPersist"
1347: " argument.", filename, linenum);
1348: value = 0;
1349: value2 = 0; /* timeout */
1350: if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1351: value = 0;
1352: else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1353: value = 1;
1354: else if ((value2 = convtime(arg)) >= 0)
1355: value = 1;
1356: else
1357: fatal("%.200s line %d: Bad ControlPersist argument.",
1358: filename, linenum);
1359: if (*activep && *intptr == -1) {
1360: *intptr = value;
1361: options->control_persist_timeout = value2;
1362: }
1363: break;
1364:
1.136 djm 1365: case oHashKnownHosts:
1366: intptr = &options->hash_known_hosts;
1367: goto parse_flag;
1368:
1.144 reyk 1369: case oTunnel:
1370: intptr = &options->tun_open;
1.207 djm 1371: multistate_ptr = multistate_tunnel;
1372: goto parse_multistate;
1.144 reyk 1373:
1374: case oTunnelDevice:
1375: arg = strdelim(&s);
1376: if (!arg || *arg == '\0')
1377: fatal("%.200s line %d: Missing argument.", filename, linenum);
1378: value = a2tun(arg, &value2);
1.145 reyk 1379: if (value == SSH_TUNID_ERR)
1.144 reyk 1380: fatal("%.200s line %d: Bad tun device.", filename, linenum);
1381: if (*activep) {
1382: options->tun_local = value;
1383: options->tun_remote = value2;
1384: }
1385: break;
1386:
1387: case oLocalCommand:
1388: charptr = &options->local_command;
1389: goto parse_command;
1390:
1391: case oPermitLocalCommand:
1392: intptr = &options->permit_local_command;
1393: goto parse_flag;
1394:
1.167 grunk 1395: case oVisualHostKey:
1396: intptr = &options->visual_host_key;
1397: goto parse_flag;
1398:
1.190 djm 1399: case oIPQoS:
1400: arg = strdelim(&s);
1401: if ((value = parse_ipqos(arg)) == -1)
1402: fatal("%s line %d: Bad IPQoS value: %s",
1403: filename, linenum, arg);
1404: arg = strdelim(&s);
1405: if (arg == NULL)
1406: value2 = value;
1407: else if ((value2 = parse_ipqos(arg)) == -1)
1408: fatal("%s line %d: Bad IPQoS value: %s",
1409: filename, linenum, arg);
1410: if (*activep) {
1411: options->ip_qos_interactive = value;
1412: options->ip_qos_bulk = value2;
1413: }
1414: break;
1415:
1.177 andreas 1416: case oUseRoaming:
1417: intptr = &options->use_roaming;
1418: goto parse_flag;
1419:
1.192 djm 1420: case oRequestTTY:
1421: intptr = &options->request_tty;
1.207 djm 1422: multistate_ptr = multistate_requesttty;
1423: goto parse_multistate;
1.192 djm 1424:
1.199 djm 1425: case oIgnoreUnknown:
1426: charptr = &options->ignored_unknown;
1427: goto parse_string;
1428:
1.205 djm 1429: case oProxyUseFdpass:
1430: intptr = &options->proxy_use_fdpass;
1431: goto parse_flag;
1432:
1.208 djm 1433: case oCanonicalDomains:
1434: value = options->num_canonical_domains != 0;
1435: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1436: valid_domain(arg, filename, linenum);
1437: if (!*activep || value)
1438: continue;
1439: if (options->num_canonical_domains >= MAX_CANON_DOMAINS)
1440: fatal("%s line %d: too many hostname suffixes.",
1441: filename, linenum);
1442: options->canonical_domains[
1443: options->num_canonical_domains++] = xstrdup(arg);
1444: }
1445: break;
1446:
1.209 djm 1447: case oCanonicalizePermittedCNAMEs:
1.208 djm 1448: value = options->num_permitted_cnames != 0;
1449: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1450: /* Either '*' for everything or 'list:list' */
1451: if (strcmp(arg, "*") == 0)
1452: arg2 = arg;
1453: else {
1454: lowercase(arg);
1455: if ((arg2 = strchr(arg, ':')) == NULL ||
1456: arg2[1] == '\0') {
1457: fatal("%s line %d: "
1458: "Invalid permitted CNAME \"%s\"",
1459: filename, linenum, arg);
1460: }
1461: *arg2 = '\0';
1462: arg2++;
1463: }
1464: if (!*activep || value)
1465: continue;
1466: if (options->num_permitted_cnames >= MAX_CANON_DOMAINS)
1467: fatal("%s line %d: too many permitted CNAMEs.",
1468: filename, linenum);
1469: cname = options->permitted_cnames +
1470: options->num_permitted_cnames++;
1471: cname->source_list = xstrdup(arg);
1472: cname->target_list = xstrdup(arg2);
1473: }
1474: break;
1475:
1.209 djm 1476: case oCanonicalizeHostname:
1477: intptr = &options->canonicalize_hostname;
1478: multistate_ptr = multistate_canonicalizehostname;
1.208 djm 1479: goto parse_multistate;
1480:
1.209 djm 1481: case oCanonicalizeMaxDots:
1482: intptr = &options->canonicalize_max_dots;
1.208 djm 1483: goto parse_int;
1484:
1.209 djm 1485: case oCanonicalizeFallbackLocal:
1486: intptr = &options->canonicalize_fallback_local;
1.208 djm 1487: goto parse_flag;
1488:
1.220 millert 1489: case oStreamLocalBindMask:
1490: arg = strdelim(&s);
1491: if (!arg || *arg == '\0')
1492: fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum);
1493: /* Parse mode in octal format */
1494: value = strtol(arg, &endofnumber, 8);
1495: if (arg == endofnumber || value < 0 || value > 0777)
1496: fatal("%.200s line %d: Bad mask.", filename, linenum);
1497: options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1498: break;
1499:
1500: case oStreamLocalBindUnlink:
1501: intptr = &options->fwd_opts.streamlocal_bind_unlink;
1502: goto parse_flag;
1503:
1.223 djm 1504: case oRevokedHostKeys:
1505: charptr = &options->revoked_host_keys;
1506: goto parse_string;
1507:
1.224 djm 1508: case oFingerprintHash:
1.225 djm 1509: intptr = &options->fingerprint_hash;
1.224 djm 1510: arg = strdelim(&s);
1511: if (!arg || *arg == '\0')
1512: fatal("%.200s line %d: Missing argument.",
1513: filename, linenum);
1514: if ((value = ssh_digest_alg_by_name(arg)) == -1)
1515: fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1516: filename, linenum, arg);
1.225 djm 1517: if (*activep && *intptr == -1)
1518: *intptr = value;
1.224 djm 1519: break;
1520:
1.229 djm 1521: case oUpdateHostkeys:
1522: intptr = &options->update_hostkeys;
1.232 djm 1523: multistate_ptr = multistate_yesnoask;
1524: goto parse_multistate;
1.229 djm 1525:
1.230 djm 1526: case oHostbasedKeyTypes:
1527: charptr = &options->hostbased_key_types;
1.238 markus 1528: goto parse_keytypes;
1529:
1530: case oPubkeyAcceptedKeyTypes:
1531: charptr = &options->pubkey_key_types;
1532: goto parse_keytypes;
1.230 djm 1533:
1.246 jcs 1534: case oAddKeysToAgent:
1535: intptr = &options->add_keys_to_agent;
1536: multistate_ptr = multistate_yesnoaskconfirm;
1537: goto parse_multistate;
1538:
1.96 markus 1539: case oDeprecated:
1.98 markus 1540: debug("%s line %d: Deprecated option \"%s\"",
1.96 markus 1541: filename, linenum, keyword);
1.98 markus 1542: return 0;
1.96 markus 1543:
1.110 jakob 1544: case oUnsupported:
1545: error("%s line %d: Unsupported option \"%s\"",
1546: filename, linenum, keyword);
1547: return 0;
1548:
1.17 markus 1549: default:
1.221 djm 1550: fatal("%s: Unimplemented opcode %d", __func__, opcode);
1.17 markus 1551: }
1552:
1553: /* Check that there is no garbage at end of line. */
1.57 djm 1554: if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.39 ho 1555: fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
1.142 djm 1556: filename, linenum, arg);
1.39 ho 1557: }
1.17 markus 1558: return 0;
1.1 deraadt 1559: }
1560:
1561:
1.19 markus 1562: /*
1563: * Reads the config file and modifies the options accordingly. Options
1564: * should already be initialized before this call. This never returns if
1.89 stevesk 1565: * there is an error. If the file does not exist, this returns 0.
1.19 markus 1566: */
1.1 deraadt 1567:
1.89 stevesk 1568: int
1.206 djm 1569: read_config_file(const char *filename, struct passwd *pw, const char *host,
1.221 djm 1570: const char *original_host, Options *options, int flags)
1.1 deraadt 1571: {
1.17 markus 1572: FILE *f;
1573: char line[1024];
1574: int active, linenum;
1575: int bad_options = 0;
1576:
1.129 djm 1577: if ((f = fopen(filename, "r")) == NULL)
1.89 stevesk 1578: return 0;
1.129 djm 1579:
1.196 dtucker 1580: if (flags & SSHCONF_CHECKPERM) {
1.129 djm 1581: struct stat sb;
1.134 deraadt 1582:
1.131 dtucker 1583: if (fstat(fileno(f), &sb) == -1)
1.129 djm 1584: fatal("fstat %s: %s", filename, strerror(errno));
1585: if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1.131 dtucker 1586: (sb.st_mode & 022) != 0))
1.129 djm 1587: fatal("Bad owner or permissions on %s", filename);
1588: }
1.17 markus 1589:
1590: debug("Reading configuration data %.200s", filename);
1591:
1.19 markus 1592: /*
1593: * Mark that we are now processing the options. This flag is turned
1594: * on/off by Host specifications.
1595: */
1.17 markus 1596: active = 1;
1597: linenum = 0;
1598: while (fgets(line, sizeof(line), f)) {
1599: /* Update line number counter. */
1600: linenum++;
1.221 djm 1601: if (process_config_line(options, pw, host, original_host,
1602: line, filename, linenum, &active, flags) != 0)
1.17 markus 1603: bad_options++;
1604: }
1605: fclose(f);
1606: if (bad_options > 0)
1.64 millert 1607: fatal("%s: terminating, %d bad configuration options",
1.93 deraadt 1608: filename, bad_options);
1.89 stevesk 1609: return 1;
1.1 deraadt 1610: }
1611:
1.218 djm 1612: /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
1613: int
1614: option_clear_or_none(const char *o)
1615: {
1616: return o == NULL || strcasecmp(o, "none") == 0;
1617: }
1618:
1.19 markus 1619: /*
1620: * Initializes options to special values that indicate that they have not yet
1621: * been set. Read_config_file will only set options with this value. Options
1622: * are processed in the following order: command line, user config file,
1623: * system config file. Last, fill_default_options is called.
1624: */
1.1 deraadt 1625:
1.26 markus 1626: void
1.17 markus 1627: initialize_options(Options * options)
1.1 deraadt 1628: {
1.17 markus 1629: memset(options, 'X', sizeof(*options));
1630: options->forward_agent = -1;
1631: options->forward_x11 = -1;
1.123 markus 1632: options->forward_x11_trusted = -1;
1.186 djm 1633: options->forward_x11_timeout = -1;
1.153 markus 1634: options->exit_on_forward_failure = -1;
1.34 markus 1635: options->xauth_location = NULL;
1.220 millert 1636: options->fwd_opts.gateway_ports = -1;
1637: options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
1638: options->fwd_opts.streamlocal_bind_unlink = -1;
1.17 markus 1639: options->use_privileged_port = -1;
1640: options->rsa_authentication = -1;
1.50 markus 1641: options->pubkey_authentication = -1;
1.78 markus 1642: options->challenge_response_authentication = -1;
1.118 markus 1643: options->gss_authentication = -1;
1644: options->gss_deleg_creds = -1;
1.17 markus 1645: options->password_authentication = -1;
1.48 markus 1646: options->kbd_interactive_authentication = -1;
1647: options->kbd_interactive_devices = NULL;
1.17 markus 1648: options->rhosts_rsa_authentication = -1;
1.72 markus 1649: options->hostbased_authentication = -1;
1.17 markus 1650: options->batch_mode = -1;
1651: options->check_host_ip = -1;
1652: options->strict_host_key_checking = -1;
1653: options->compression = -1;
1.126 markus 1654: options->tcp_keep_alive = -1;
1.17 markus 1655: options->compression_level = -1;
1656: options->port = -1;
1.114 djm 1657: options->address_family = -1;
1.17 markus 1658: options->connection_attempts = -1;
1.111 djm 1659: options->connection_timeout = -1;
1.17 markus 1660: options->number_of_password_prompts = -1;
1661: options->cipher = -1;
1.25 markus 1662: options->ciphers = NULL;
1.62 markus 1663: options->macs = NULL;
1.189 djm 1664: options->kex_algorithms = NULL;
1.76 markus 1665: options->hostkeyalgorithms = NULL;
1.25 markus 1666: options->protocol = SSH_PROTO_UNKNOWN;
1.17 markus 1667: options->num_identity_files = 0;
1.241 djm 1668: options->num_certificate_files = 0;
1.17 markus 1669: options->hostname = NULL;
1.52 markus 1670: options->host_key_alias = NULL;
1.17 markus 1671: options->proxy_command = NULL;
1672: options->user = NULL;
1673: options->escape_char = -1;
1.193 djm 1674: options->num_system_hostfiles = 0;
1675: options->num_user_hostfiles = 0;
1.185 djm 1676: options->local_forwards = NULL;
1.17 markus 1677: options->num_local_forwards = 0;
1.185 djm 1678: options->remote_forwards = NULL;
1.17 markus 1679: options->num_remote_forwards = 0;
1.90 stevesk 1680: options->clear_forwardings = -1;
1.95 markus 1681: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.67 markus 1682: options->preferred_authentications = NULL;
1.77 markus 1683: options->bind_address = NULL;
1.183 markus 1684: options->pkcs11_provider = NULL;
1.101 markus 1685: options->enable_ssh_keysign = - 1;
1.91 markus 1686: options->no_host_authentication_for_localhost = - 1;
1.128 markus 1687: options->identities_only = - 1;
1.105 markus 1688: options->rekey_limit = - 1;
1.198 dtucker 1689: options->rekey_interval = -1;
1.107 jakob 1690: options->verify_host_key_dns = -1;
1.127 markus 1691: options->server_alive_interval = -1;
1692: options->server_alive_count_max = -1;
1.130 djm 1693: options->num_send_env = 0;
1.132 djm 1694: options->control_path = NULL;
1695: options->control_master = -1;
1.187 djm 1696: options->control_persist = -1;
1697: options->control_persist_timeout = 0;
1.136 djm 1698: options->hash_known_hosts = -1;
1.144 reyk 1699: options->tun_open = -1;
1700: options->tun_local = -1;
1701: options->tun_remote = -1;
1702: options->local_command = NULL;
1703: options->permit_local_command = -1;
1.247 ! deraadt 1704: options->use_roaming = 0;
1.246 jcs 1705: options->add_keys_to_agent = -1;
1.167 grunk 1706: options->visual_host_key = -1;
1.190 djm 1707: options->ip_qos_interactive = -1;
1708: options->ip_qos_bulk = -1;
1.192 djm 1709: options->request_tty = -1;
1.205 djm 1710: options->proxy_use_fdpass = -1;
1.199 djm 1711: options->ignored_unknown = NULL;
1.208 djm 1712: options->num_canonical_domains = 0;
1713: options->num_permitted_cnames = 0;
1.209 djm 1714: options->canonicalize_max_dots = -1;
1715: options->canonicalize_fallback_local = -1;
1716: options->canonicalize_hostname = -1;
1.223 djm 1717: options->revoked_host_keys = NULL;
1.224 djm 1718: options->fingerprint_hash = -1;
1.229 djm 1719: options->update_hostkeys = -1;
1.230 djm 1720: options->hostbased_key_types = NULL;
1.238 markus 1721: options->pubkey_key_types = NULL;
1.1 deraadt 1722: }
1723:
1.19 markus 1724: /*
1.218 djm 1725: * A petite version of fill_default_options() that just fills the options
1726: * needed for hostname canonicalization to proceed.
1727: */
1728: void
1729: fill_default_options_for_canonicalization(Options *options)
1730: {
1731: if (options->canonicalize_max_dots == -1)
1732: options->canonicalize_max_dots = 1;
1733: if (options->canonicalize_fallback_local == -1)
1734: options->canonicalize_fallback_local = 1;
1735: if (options->canonicalize_hostname == -1)
1736: options->canonicalize_hostname = SSH_CANONICALISE_NO;
1737: }
1738:
1739: /*
1.19 markus 1740: * Called after processing other sources of option data, this fills those
1741: * options for which no value has been specified with their default values.
1742: */
1.26 markus 1743: void
1.17 markus 1744: fill_default_options(Options * options)
1.1 deraadt 1745: {
1.17 markus 1746: if (options->forward_agent == -1)
1.33 markus 1747: options->forward_agent = 0;
1.17 markus 1748: if (options->forward_x11 == -1)
1.23 markus 1749: options->forward_x11 = 0;
1.123 markus 1750: if (options->forward_x11_trusted == -1)
1751: options->forward_x11_trusted = 0;
1.186 djm 1752: if (options->forward_x11_timeout == -1)
1753: options->forward_x11_timeout = 1200;
1.153 markus 1754: if (options->exit_on_forward_failure == -1)
1755: options->exit_on_forward_failure = 0;
1.34 markus 1756: if (options->xauth_location == NULL)
1.80 markus 1757: options->xauth_location = _PATH_XAUTH;
1.220 millert 1758: if (options->fwd_opts.gateway_ports == -1)
1759: options->fwd_opts.gateway_ports = 0;
1760: if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
1761: options->fwd_opts.streamlocal_bind_mask = 0177;
1762: if (options->fwd_opts.streamlocal_bind_unlink == -1)
1763: options->fwd_opts.streamlocal_bind_unlink = 0;
1.17 markus 1764: if (options->use_privileged_port == -1)
1.65 markus 1765: options->use_privileged_port = 0;
1.17 markus 1766: if (options->rsa_authentication == -1)
1767: options->rsa_authentication = 1;
1.50 markus 1768: if (options->pubkey_authentication == -1)
1769: options->pubkey_authentication = 1;
1.78 markus 1770: if (options->challenge_response_authentication == -1)
1.83 markus 1771: options->challenge_response_authentication = 1;
1.118 markus 1772: if (options->gss_authentication == -1)
1.122 markus 1773: options->gss_authentication = 0;
1.118 markus 1774: if (options->gss_deleg_creds == -1)
1775: options->gss_deleg_creds = 0;
1.17 markus 1776: if (options->password_authentication == -1)
1777: options->password_authentication = 1;
1.48 markus 1778: if (options->kbd_interactive_authentication == -1)
1.59 markus 1779: options->kbd_interactive_authentication = 1;
1.17 markus 1780: if (options->rhosts_rsa_authentication == -1)
1.99 stevesk 1781: options->rhosts_rsa_authentication = 0;
1.72 markus 1782: if (options->hostbased_authentication == -1)
1783: options->hostbased_authentication = 0;
1.17 markus 1784: if (options->batch_mode == -1)
1785: options->batch_mode = 0;
1786: if (options->check_host_ip == -1)
1787: options->check_host_ip = 1;
1788: if (options->strict_host_key_checking == -1)
1789: options->strict_host_key_checking = 2; /* 2 is default */
1790: if (options->compression == -1)
1791: options->compression = 0;
1.126 markus 1792: if (options->tcp_keep_alive == -1)
1793: options->tcp_keep_alive = 1;
1.17 markus 1794: if (options->compression_level == -1)
1795: options->compression_level = 6;
1796: if (options->port == -1)
1797: options->port = 0; /* Filled in ssh_connect. */
1.114 djm 1798: if (options->address_family == -1)
1799: options->address_family = AF_UNSPEC;
1.17 markus 1800: if (options->connection_attempts == -1)
1.84 markus 1801: options->connection_attempts = 1;
1.17 markus 1802: if (options->number_of_password_prompts == -1)
1803: options->number_of_password_prompts = 3;
1804: /* Selected in ssh_login(). */
1805: if (options->cipher == -1)
1806: options->cipher = SSH_CIPHER_NOT_SET;
1.76 markus 1807: /* options->hostkeyalgorithms, default set in myproposals.h */
1.25 markus 1808: if (options->protocol == SSH_PROTO_UNKNOWN)
1.178 markus 1809: options->protocol = SSH_PROTO_2;
1.246 jcs 1810: if (options->add_keys_to_agent == -1)
1811: options->add_keys_to_agent = 0;
1.17 markus 1812: if (options->num_identity_files == 0) {
1.50 markus 1813: if (options->protocol & SSH_PROTO_1) {
1.195 dtucker 1814: add_identity_file(options, "~/",
1815: _PATH_SSH_CLIENT_IDENTITY, 0);
1.50 markus 1816: }
1817: if (options->protocol & SSH_PROTO_2) {
1.195 dtucker 1818: add_identity_file(options, "~/",
1819: _PATH_SSH_CLIENT_ID_RSA, 0);
1820: add_identity_file(options, "~/",
1821: _PATH_SSH_CLIENT_ID_DSA, 0);
1822: add_identity_file(options, "~/",
1823: _PATH_SSH_CLIENT_ID_ECDSA, 0);
1.215 markus 1824: add_identity_file(options, "~/",
1825: _PATH_SSH_CLIENT_ID_ED25519, 0);
1.50 markus 1826: }
1.27 markus 1827: }
1.17 markus 1828: if (options->escape_char == -1)
1829: options->escape_char = '~';
1.193 djm 1830: if (options->num_system_hostfiles == 0) {
1831: options->system_hostfiles[options->num_system_hostfiles++] =
1832: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
1833: options->system_hostfiles[options->num_system_hostfiles++] =
1834: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
1835: }
1836: if (options->num_user_hostfiles == 0) {
1837: options->user_hostfiles[options->num_user_hostfiles++] =
1838: xstrdup(_PATH_SSH_USER_HOSTFILE);
1839: options->user_hostfiles[options->num_user_hostfiles++] =
1840: xstrdup(_PATH_SSH_USER_HOSTFILE2);
1841: }
1.95 markus 1842: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.54 markus 1843: options->log_level = SYSLOG_LEVEL_INFO;
1.90 stevesk 1844: if (options->clear_forwardings == 1)
1845: clear_forwardings(options);
1.91 markus 1846: if (options->no_host_authentication_for_localhost == - 1)
1847: options->no_host_authentication_for_localhost = 0;
1.128 markus 1848: if (options->identities_only == -1)
1849: options->identities_only = 0;
1.101 markus 1850: if (options->enable_ssh_keysign == -1)
1851: options->enable_ssh_keysign = 0;
1.105 markus 1852: if (options->rekey_limit == -1)
1853: options->rekey_limit = 0;
1.198 dtucker 1854: if (options->rekey_interval == -1)
1855: options->rekey_interval = 0;
1.107 jakob 1856: if (options->verify_host_key_dns == -1)
1857: options->verify_host_key_dns = 0;
1.127 markus 1858: if (options->server_alive_interval == -1)
1859: options->server_alive_interval = 0;
1860: if (options->server_alive_count_max == -1)
1861: options->server_alive_count_max = 3;
1.132 djm 1862: if (options->control_master == -1)
1863: options->control_master = 0;
1.187 djm 1864: if (options->control_persist == -1) {
1865: options->control_persist = 0;
1866: options->control_persist_timeout = 0;
1867: }
1.136 djm 1868: if (options->hash_known_hosts == -1)
1869: options->hash_known_hosts = 0;
1.144 reyk 1870: if (options->tun_open == -1)
1.145 reyk 1871: options->tun_open = SSH_TUNMODE_NO;
1872: if (options->tun_local == -1)
1873: options->tun_local = SSH_TUNID_ANY;
1874: if (options->tun_remote == -1)
1875: options->tun_remote = SSH_TUNID_ANY;
1.144 reyk 1876: if (options->permit_local_command == -1)
1877: options->permit_local_command = 0;
1.247 ! deraadt 1878: options->use_roaming = 0;
1.167 grunk 1879: if (options->visual_host_key == -1)
1880: options->visual_host_key = 0;
1.190 djm 1881: if (options->ip_qos_interactive == -1)
1882: options->ip_qos_interactive = IPTOS_LOWDELAY;
1883: if (options->ip_qos_bulk == -1)
1884: options->ip_qos_bulk = IPTOS_THROUGHPUT;
1.192 djm 1885: if (options->request_tty == -1)
1886: options->request_tty = REQUEST_TTY_AUTO;
1.205 djm 1887: if (options->proxy_use_fdpass == -1)
1888: options->proxy_use_fdpass = 0;
1.209 djm 1889: if (options->canonicalize_max_dots == -1)
1890: options->canonicalize_max_dots = 1;
1891: if (options->canonicalize_fallback_local == -1)
1892: options->canonicalize_fallback_local = 1;
1893: if (options->canonicalize_hostname == -1)
1894: options->canonicalize_hostname = SSH_CANONICALISE_NO;
1.224 djm 1895: if (options->fingerprint_hash == -1)
1896: options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
1.229 djm 1897: if (options->update_hostkeys == -1)
1.231 djm 1898: options->update_hostkeys = 0;
1.239 djm 1899: if (kex_assemble_names(KEX_CLIENT_ENCRYPT, &options->ciphers) != 0 ||
1900: kex_assemble_names(KEX_CLIENT_MAC, &options->macs) != 0 ||
1901: kex_assemble_names(KEX_CLIENT_KEX, &options->kex_algorithms) != 0 ||
1902: kex_assemble_names(KEX_DEFAULT_PK_ALG,
1903: &options->hostbased_key_types) != 0 ||
1904: kex_assemble_names(KEX_DEFAULT_PK_ALG,
1905: &options->pubkey_key_types) != 0)
1906: fatal("%s: kex_assemble_names failed", __func__);
1.224 djm 1907:
1.207 djm 1908: #define CLEAR_ON_NONE(v) \
1909: do { \
1.218 djm 1910: if (option_clear_or_none(v)) { \
1.207 djm 1911: free(v); \
1912: v = NULL; \
1913: } \
1914: } while(0)
1915: CLEAR_ON_NONE(options->local_command);
1916: CLEAR_ON_NONE(options->proxy_command);
1917: CLEAR_ON_NONE(options->control_path);
1.223 djm 1918: CLEAR_ON_NONE(options->revoked_host_keys);
1.17 markus 1919: /* options->user will be set in the main program if appropriate */
1920: /* options->hostname will be set in the main program if appropriate */
1.52 markus 1921: /* options->host_key_alias should not be set by default */
1.67 markus 1922: /* options->preferred_authentications will be set in ssh */
1.135 djm 1923: }
1924:
1.220 millert 1925: struct fwdarg {
1926: char *arg;
1927: int ispath;
1928: };
1929:
1930: /*
1931: * parse_fwd_field
1932: * parses the next field in a port forwarding specification.
1933: * sets fwd to the parsed field and advances p past the colon
1934: * or sets it to NULL at end of string.
1935: * returns 0 on success, else non-zero.
1936: */
1937: static int
1938: parse_fwd_field(char **p, struct fwdarg *fwd)
1939: {
1940: char *ep, *cp = *p;
1941: int ispath = 0;
1942:
1943: if (*cp == '\0') {
1944: *p = NULL;
1945: return -1; /* end of string */
1946: }
1947:
1948: /*
1949: * A field escaped with square brackets is used literally.
1950: * XXX - allow ']' to be escaped via backslash?
1951: */
1952: if (*cp == '[') {
1953: /* find matching ']' */
1954: for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
1955: if (*ep == '/')
1956: ispath = 1;
1957: }
1958: /* no matching ']' or not at end of field. */
1959: if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
1960: return -1;
1961: /* NUL terminate the field and advance p past the colon */
1962: *ep++ = '\0';
1963: if (*ep != '\0')
1964: *ep++ = '\0';
1965: fwd->arg = cp + 1;
1966: fwd->ispath = ispath;
1967: *p = ep;
1968: return 0;
1969: }
1970:
1971: for (cp = *p; *cp != '\0'; cp++) {
1972: switch (*cp) {
1973: case '\\':
1974: memmove(cp, cp + 1, strlen(cp + 1) + 1);
1.237 djm 1975: if (*cp == '\0')
1976: return -1;
1.220 millert 1977: break;
1978: case '/':
1979: ispath = 1;
1980: break;
1981: case ':':
1982: *cp++ = '\0';
1983: goto done;
1984: }
1985: }
1986: done:
1987: fwd->arg = *p;
1988: fwd->ispath = ispath;
1989: *p = cp;
1990: return 0;
1991: }
1992:
1.135 djm 1993: /*
1994: * parse_forward
1995: * parses a string containing a port forwarding specification of the form:
1.168 stevesk 1996: * dynamicfwd == 0
1.220 millert 1997: * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
1998: * listenpath:connectpath
1.168 stevesk 1999: * dynamicfwd == 1
2000: * [listenhost:]listenport
1.135 djm 2001: * returns number of arguments parsed or zero on error
2002: */
2003: int
1.220 millert 2004: parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
1.135 djm 2005: {
1.220 millert 2006: struct fwdarg fwdargs[4];
2007: char *p, *cp;
1.135 djm 2008: int i;
2009:
1.220 millert 2010: memset(fwd, 0, sizeof(*fwd));
2011: memset(fwdargs, 0, sizeof(fwdargs));
1.135 djm 2012:
2013: cp = p = xstrdup(fwdspec);
2014:
2015: /* skip leading spaces */
1.214 deraadt 2016: while (isspace((u_char)*cp))
1.135 djm 2017: cp++;
2018:
1.220 millert 2019: for (i = 0; i < 4; ++i) {
2020: if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
1.135 djm 2021: break;
1.220 millert 2022: }
1.135 djm 2023:
1.170 stevesk 2024: /* Check for trailing garbage */
1.220 millert 2025: if (cp != NULL && *cp != '\0') {
1.135 djm 2026: i = 0; /* failure */
1.220 millert 2027: }
1.135 djm 2028:
2029: switch (i) {
1.168 stevesk 2030: case 1:
1.220 millert 2031: if (fwdargs[0].ispath) {
2032: fwd->listen_path = xstrdup(fwdargs[0].arg);
2033: fwd->listen_port = PORT_STREAMLOCAL;
2034: } else {
2035: fwd->listen_host = NULL;
2036: fwd->listen_port = a2port(fwdargs[0].arg);
2037: }
1.168 stevesk 2038: fwd->connect_host = xstrdup("socks");
2039: break;
2040:
2041: case 2:
1.220 millert 2042: if (fwdargs[0].ispath && fwdargs[1].ispath) {
2043: fwd->listen_path = xstrdup(fwdargs[0].arg);
2044: fwd->listen_port = PORT_STREAMLOCAL;
2045: fwd->connect_path = xstrdup(fwdargs[1].arg);
2046: fwd->connect_port = PORT_STREAMLOCAL;
2047: } else if (fwdargs[1].ispath) {
2048: fwd->listen_host = NULL;
2049: fwd->listen_port = a2port(fwdargs[0].arg);
2050: fwd->connect_path = xstrdup(fwdargs[1].arg);
2051: fwd->connect_port = PORT_STREAMLOCAL;
2052: } else {
2053: fwd->listen_host = xstrdup(fwdargs[0].arg);
2054: fwd->listen_port = a2port(fwdargs[1].arg);
2055: fwd->connect_host = xstrdup("socks");
2056: }
1.168 stevesk 2057: break;
2058:
1.135 djm 2059: case 3:
1.220 millert 2060: if (fwdargs[0].ispath) {
2061: fwd->listen_path = xstrdup(fwdargs[0].arg);
2062: fwd->listen_port = PORT_STREAMLOCAL;
2063: fwd->connect_host = xstrdup(fwdargs[1].arg);
2064: fwd->connect_port = a2port(fwdargs[2].arg);
2065: } else if (fwdargs[2].ispath) {
2066: fwd->listen_host = xstrdup(fwdargs[0].arg);
2067: fwd->listen_port = a2port(fwdargs[1].arg);
2068: fwd->connect_path = xstrdup(fwdargs[2].arg);
2069: fwd->connect_port = PORT_STREAMLOCAL;
2070: } else {
2071: fwd->listen_host = NULL;
2072: fwd->listen_port = a2port(fwdargs[0].arg);
2073: fwd->connect_host = xstrdup(fwdargs[1].arg);
2074: fwd->connect_port = a2port(fwdargs[2].arg);
2075: }
1.135 djm 2076: break;
2077:
2078: case 4:
1.220 millert 2079: fwd->listen_host = xstrdup(fwdargs[0].arg);
2080: fwd->listen_port = a2port(fwdargs[1].arg);
2081: fwd->connect_host = xstrdup(fwdargs[2].arg);
2082: fwd->connect_port = a2port(fwdargs[3].arg);
1.135 djm 2083: break;
2084: default:
2085: i = 0; /* failure */
2086: }
2087:
1.202 djm 2088: free(p);
1.135 djm 2089:
1.168 stevesk 2090: if (dynamicfwd) {
2091: if (!(i == 1 || i == 2))
2092: goto fail_free;
2093: } else {
1.220 millert 2094: if (!(i == 3 || i == 4)) {
2095: if (fwd->connect_path == NULL &&
2096: fwd->listen_path == NULL)
2097: goto fail_free;
2098: }
2099: if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
1.168 stevesk 2100: goto fail_free;
2101: }
2102:
1.220 millert 2103: if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
2104: (!remotefwd && fwd->listen_port == 0))
1.135 djm 2105: goto fail_free;
2106: if (fwd->connect_host != NULL &&
2107: strlen(fwd->connect_host) >= NI_MAXHOST)
2108: goto fail_free;
1.220 millert 2109: /* XXX - if connecting to a remote socket, max sun len may not match this host */
2110: if (fwd->connect_path != NULL &&
2111: strlen(fwd->connect_path) >= PATH_MAX_SUN)
2112: goto fail_free;
1.176 djm 2113: if (fwd->listen_host != NULL &&
2114: strlen(fwd->listen_host) >= NI_MAXHOST)
2115: goto fail_free;
1.220 millert 2116: if (fwd->listen_path != NULL &&
2117: strlen(fwd->listen_path) >= PATH_MAX_SUN)
2118: goto fail_free;
1.135 djm 2119:
2120: return (i);
2121:
2122: fail_free:
1.202 djm 2123: free(fwd->connect_host);
2124: fwd->connect_host = NULL;
1.220 millert 2125: free(fwd->connect_path);
2126: fwd->connect_path = NULL;
1.202 djm 2127: free(fwd->listen_host);
2128: fwd->listen_host = NULL;
1.220 millert 2129: free(fwd->listen_path);
2130: fwd->listen_path = NULL;
1.135 djm 2131: return (0);
1.221 djm 2132: }
2133:
2134: /* XXX the following is a near-vebatim copy from servconf.c; refactor */
2135: static const char *
2136: fmt_multistate_int(int val, const struct multistate *m)
2137: {
2138: u_int i;
2139:
2140: for (i = 0; m[i].key != NULL; i++) {
2141: if (m[i].value == val)
2142: return m[i].key;
2143: }
2144: return "UNKNOWN";
2145: }
2146:
2147: static const char *
2148: fmt_intarg(OpCodes code, int val)
2149: {
2150: if (val == -1)
2151: return "unset";
2152: switch (code) {
2153: case oAddressFamily:
2154: return fmt_multistate_int(val, multistate_addressfamily);
2155: case oVerifyHostKeyDNS:
2156: case oStrictHostKeyChecking:
1.232 djm 2157: case oUpdateHostkeys:
1.221 djm 2158: return fmt_multistate_int(val, multistate_yesnoask);
2159: case oControlMaster:
2160: return fmt_multistate_int(val, multistate_controlmaster);
2161: case oTunnel:
2162: return fmt_multistate_int(val, multistate_tunnel);
2163: case oRequestTTY:
2164: return fmt_multistate_int(val, multistate_requesttty);
2165: case oCanonicalizeHostname:
2166: return fmt_multistate_int(val, multistate_canonicalizehostname);
1.224 djm 2167: case oFingerprintHash:
2168: return ssh_digest_alg_name(val);
1.221 djm 2169: case oProtocol:
2170: switch (val) {
2171: case SSH_PROTO_1:
2172: return "1";
2173: case SSH_PROTO_2:
2174: return "2";
2175: case (SSH_PROTO_1|SSH_PROTO_2):
2176: return "2,1";
2177: default:
2178: return "UNKNOWN";
2179: }
2180: default:
2181: switch (val) {
2182: case 0:
2183: return "no";
2184: case 1:
2185: return "yes";
2186: default:
2187: return "UNKNOWN";
2188: }
2189: }
2190: }
2191:
2192: static const char *
2193: lookup_opcode_name(OpCodes code)
2194: {
2195: u_int i;
2196:
2197: for (i = 0; keywords[i].name != NULL; i++)
2198: if (keywords[i].opcode == code)
2199: return(keywords[i].name);
2200: return "UNKNOWN";
2201: }
2202:
2203: static void
2204: dump_cfg_int(OpCodes code, int val)
2205: {
2206: printf("%s %d\n", lookup_opcode_name(code), val);
2207: }
2208:
2209: static void
2210: dump_cfg_fmtint(OpCodes code, int val)
2211: {
2212: printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2213: }
2214:
2215: static void
2216: dump_cfg_string(OpCodes code, const char *val)
2217: {
2218: if (val == NULL)
2219: return;
2220: printf("%s %s\n", lookup_opcode_name(code), val);
2221: }
2222:
2223: static void
2224: dump_cfg_strarray(OpCodes code, u_int count, char **vals)
2225: {
2226: u_int i;
2227:
2228: for (i = 0; i < count; i++)
2229: printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2230: }
2231:
2232: static void
2233: dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
2234: {
2235: u_int i;
2236:
2237: printf("%s", lookup_opcode_name(code));
2238: for (i = 0; i < count; i++)
2239: printf(" %s", vals[i]);
2240: printf("\n");
2241: }
2242:
2243: static void
2244: dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
2245: {
2246: const struct Forward *fwd;
2247: u_int i;
2248:
2249: /* oDynamicForward */
2250: for (i = 0; i < count; i++) {
2251: fwd = &fwds[i];
2252: if (code == oDynamicForward &&
2253: strcmp(fwd->connect_host, "socks") != 0)
2254: continue;
2255: if (code == oLocalForward &&
2256: strcmp(fwd->connect_host, "socks") == 0)
2257: continue;
2258: printf("%s", lookup_opcode_name(code));
2259: if (fwd->listen_port == PORT_STREAMLOCAL)
2260: printf(" %s", fwd->listen_path);
2261: else if (fwd->listen_host == NULL)
2262: printf(" %d", fwd->listen_port);
2263: else {
2264: printf(" [%s]:%d",
2265: fwd->listen_host, fwd->listen_port);
2266: }
2267: if (code != oDynamicForward) {
2268: if (fwd->connect_port == PORT_STREAMLOCAL)
2269: printf(" %s", fwd->connect_path);
2270: else if (fwd->connect_host == NULL)
2271: printf(" %d", fwd->connect_port);
2272: else {
2273: printf(" [%s]:%d",
2274: fwd->connect_host, fwd->connect_port);
2275: }
2276: }
2277: printf("\n");
2278: }
2279: }
2280:
2281: void
2282: dump_client_config(Options *o, const char *host)
2283: {
2284: int i;
2285: char vbuf[5];
2286:
1.240 djm 2287: /* This is normally prepared in ssh_kex2 */
2288: if (kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->hostkeyalgorithms) != 0)
2289: fatal("%s: kex_assemble_names failed", __func__);
2290:
1.221 djm 2291: /* Most interesting options first: user, host, port */
2292: dump_cfg_string(oUser, o->user);
2293: dump_cfg_string(oHostName, host);
2294: dump_cfg_int(oPort, o->port);
2295:
2296: /* Flag options */
2297: dump_cfg_fmtint(oAddressFamily, o->address_family);
2298: dump_cfg_fmtint(oBatchMode, o->batch_mode);
2299: dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
2300: dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
2301: dump_cfg_fmtint(oChallengeResponseAuthentication, o->challenge_response_authentication);
2302: dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
2303: dump_cfg_fmtint(oCompression, o->compression);
2304: dump_cfg_fmtint(oControlMaster, o->control_master);
2305: dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
2306: dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
1.224 djm 2307: dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
1.221 djm 2308: dump_cfg_fmtint(oForwardAgent, o->forward_agent);
2309: dump_cfg_fmtint(oForwardX11, o->forward_x11);
2310: dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
2311: dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
2312: #ifdef GSSAPI
2313: dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
2314: dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
2315: #endif /* GSSAPI */
2316: dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
2317: dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
2318: dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
2319: dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
2320: dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
2321: dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
2322: dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
2323: dump_cfg_fmtint(oProtocol, o->protocol);
2324: dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
2325: dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
2326: dump_cfg_fmtint(oRequestTTY, o->request_tty);
2327: dump_cfg_fmtint(oRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2328: dump_cfg_fmtint(oRSAAuthentication, o->rsa_authentication);
2329: dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
2330: dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
2331: dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
2332: dump_cfg_fmtint(oTunnel, o->tun_open);
2333: dump_cfg_fmtint(oUsePrivilegedPort, o->use_privileged_port);
2334: dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
2335: dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
1.229 djm 2336: dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
1.221 djm 2337:
2338: /* Integer options */
2339: dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
2340: dump_cfg_int(oCompressionLevel, o->compression_level);
2341: dump_cfg_int(oConnectionAttempts, o->connection_attempts);
2342: dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
2343: dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
2344: dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
2345: dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
2346:
2347: /* String options */
2348: dump_cfg_string(oBindAddress, o->bind_address);
2349: dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
2350: dump_cfg_string(oControlPath, o->control_path);
1.240 djm 2351: dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
1.221 djm 2352: dump_cfg_string(oHostKeyAlias, o->host_key_alias);
1.230 djm 2353: dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
1.221 djm 2354: dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
2355: dump_cfg_string(oKexAlgorithms, o->kex_algorithms ? o->kex_algorithms : KEX_CLIENT_KEX);
2356: dump_cfg_string(oLocalCommand, o->local_command);
2357: dump_cfg_string(oLogLevel, log_level_name(o->log_level));
2358: dump_cfg_string(oMacs, o->macs ? o->macs : KEX_CLIENT_MAC);
2359: dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
2360: dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
2361: dump_cfg_string(oProxyCommand, o->proxy_command);
1.242 djm 2362: dump_cfg_string(oPubkeyAcceptedKeyTypes, o->pubkey_key_types);
1.230 djm 2363: dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
1.221 djm 2364: dump_cfg_string(oXAuthLocation, o->xauth_location);
2365:
1.230 djm 2366: /* Forwards */
1.221 djm 2367: dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
2368: dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
2369: dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
2370:
2371: /* String array options */
2372: dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
2373: dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
2374: dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
2375: dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
2376: dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
2377:
2378: /* Special cases */
2379:
2380: /* oConnectTimeout */
2381: if (o->connection_timeout == -1)
2382: printf("connecttimeout none\n");
2383: else
2384: dump_cfg_int(oConnectTimeout, o->connection_timeout);
2385:
2386: /* oTunnelDevice */
2387: printf("tunneldevice");
2388: if (o->tun_local == SSH_TUNID_ANY)
2389: printf(" any");
2390: else
2391: printf(" %d", o->tun_local);
2392: if (o->tun_remote == SSH_TUNID_ANY)
2393: printf(":any");
2394: else
2395: printf(":%d", o->tun_remote);
2396: printf("\n");
2397:
2398: /* oCanonicalizePermittedCNAMEs */
2399: if ( o->num_permitted_cnames > 0) {
2400: printf("canonicalizePermittedcnames");
2401: for (i = 0; i < o->num_permitted_cnames; i++) {
2402: printf(" %s:%s", o->permitted_cnames[i].source_list,
2403: o->permitted_cnames[i].target_list);
2404: }
2405: printf("\n");
2406: }
2407:
2408: /* oCipher */
2409: if (o->cipher != SSH_CIPHER_NOT_SET)
2410: printf("Cipher %s\n", cipher_name(o->cipher));
2411:
2412: /* oControlPersist */
2413: if (o->control_persist == 0 || o->control_persist_timeout == 0)
2414: dump_cfg_fmtint(oControlPersist, o->control_persist);
2415: else
2416: dump_cfg_int(oControlPersist, o->control_persist_timeout);
2417:
2418: /* oEscapeChar */
2419: if (o->escape_char == SSH_ESCAPECHAR_NONE)
2420: printf("escapechar none\n");
2421: else {
2422: vis(vbuf, o->escape_char, VIS_WHITE, 0);
2423: printf("escapechar %s\n", vbuf);
2424: }
2425:
2426: /* oIPQoS */
2427: printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2428: printf("%s\n", iptos2str(o->ip_qos_bulk));
2429:
2430: /* oRekeyLimit */
2431: printf("rekeylimit %lld %d\n",
2432: (long long)o->rekey_limit, o->rekey_interval);
2433:
2434: /* oStreamLocalBindMask */
2435: printf("streamlocalbindmask 0%o\n",
2436: o->fwd_opts.streamlocal_bind_mask);
1.1 deraadt 2437: }