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