Annotation of src/usr.bin/ssh/readconf.c, Revision 1.154
1.154 ! stevesk 1: /* $OpenBSD: readconf.c,v 1.153 2006/07/11 18:50:48 markus Exp $ */
1.1 deraadt 2: /*
1.18 deraadt 3: * Author: Tatu Ylonen <ylo@cs.hut.fi>
4: * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5: * All rights reserved
6: * Functions for reading the configuration files.
1.26 markus 7: *
1.46 deraadt 8: * As far as I am concerned, the code I have written for this software
9: * can be used freely for any purpose. Any derived versions of this
10: * software must be clearly marked as such, and if the derived work is
11: * incompatible with the protocol description in the RFC file, it must be
12: * called by a name other than "ssh" or "Secure Shell".
1.18 deraadt 13: */
1.1 deraadt 14:
15: #include "includes.h"
1.147 stevesk 16:
17: #include <sys/types.h>
18: #include <sys/stat.h>
1.152 stevesk 19: #include <sys/socket.h>
20:
21: #include <netinet/in.h>
1.148 stevesk 22:
23: #include <ctype.h>
1.154 ! stevesk 24: #include <errno.h>
1.1 deraadt 25:
26: #include "ssh.h"
27: #include "xmalloc.h"
1.25 markus 28: #include "compat.h"
1.58 markus 29: #include "cipher.h"
1.55 markus 30: #include "pathnames.h"
1.58 markus 31: #include "log.h"
32: #include "readconf.h"
33: #include "match.h"
34: #include "misc.h"
1.62 markus 35: #include "kex.h"
36: #include "mac.h"
1.1 deraadt 37:
38: /* Format of the configuration file:
39:
40: # Configuration data is parsed as follows:
41: # 1. command line options
42: # 2. user-specific file
43: # 3. system-wide file
44: # Any configuration value is only changed the first time it is set.
45: # Thus, host-specific definitions should be at the beginning of the
46: # configuration file, and defaults at the end.
47:
48: # Host-specific declarations. These may override anything above. A single
49: # host may match multiple declarations; these are processed in the order
50: # that they are given in.
51:
52: Host *.ngs.fi ngs.fi
1.96 markus 53: User foo
1.1 deraadt 54:
55: Host fake.com
56: HostName another.host.name.real.org
57: User blaah
58: Port 34289
59: ForwardX11 no
60: ForwardAgent no
61:
62: Host books.com
63: RemoteForward 9999 shadows.cs.hut.fi:9999
64: Cipher 3des
65:
66: Host fascist.blob.com
67: Port 23123
68: User tylonen
69: PasswordAuthentication no
70:
71: Host puukko.hut.fi
72: User t35124p
73: ProxyCommand ssh-proxy %h %p
74:
75: Host *.fr
1.96 markus 76: PublicKeyAuthentication no
1.1 deraadt 77:
78: Host *.su
79: Cipher none
80: PasswordAuthentication no
81:
1.144 reyk 82: Host vpn.fake.com
83: Tunnel yes
84: TunnelDevice 3
85:
1.1 deraadt 86: # Defaults for various options
87: Host *
88: ForwardAgent no
1.50 markus 89: ForwardX11 no
1.1 deraadt 90: PasswordAuthentication yes
91: RSAAuthentication yes
92: RhostsRSAAuthentication yes
93: StrictHostKeyChecking yes
1.126 markus 94: TcpKeepAlive no
1.1 deraadt 95: IdentityFile ~/.ssh/identity
96: Port 22
97: EscapeChar ~
98:
99: */
100:
101: /* Keyword tokens. */
102:
1.17 markus 103: typedef enum {
104: oBadOption,
1.123 markus 105: oForwardAgent, oForwardX11, oForwardX11Trusted, oGatewayPorts,
1.153 markus 106: oExitOnForwardFailure,
1.100 deraadt 107: oPasswordAuthentication, oRSAAuthentication,
1.59 markus 108: oChallengeResponseAuthentication, oXAuthLocation,
1.17 markus 109: oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
110: oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
111: oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
112: oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
1.126 markus 113: oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
1.62 markus 114: oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
1.50 markus 115: oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
1.67 markus 116: oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
1.76 markus 117: oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
1.90 stevesk 118: oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
1.96 markus 119: oClearAllForwardings, oNoHostAuthenticationForLocalhost,
1.111 djm 120: oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
1.118 markus 121: oAddressFamily, oGssAuthentication, oGssDelegateCreds,
1.128 markus 122: oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
1.136 djm 123: oSendEnv, oControlPath, oControlMaster, oHashKnownHosts,
1.144 reyk 124: oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
1.110 jakob 125: oDeprecated, oUnsupported
1.1 deraadt 126: } OpCodes;
127:
128: /* Textual representations of the tokens. */
129:
1.17 markus 130: static struct {
131: const char *name;
132: OpCodes opcode;
133: } keywords[] = {
134: { "forwardagent", oForwardAgent },
135: { "forwardx11", oForwardX11 },
1.123 markus 136: { "forwardx11trusted", oForwardX11Trusted },
1.153 markus 137: { "exitonforwardfailure", oExitOnForwardFailure },
1.34 markus 138: { "xauthlocation", oXAuthLocation },
1.17 markus 139: { "gatewayports", oGatewayPorts },
140: { "useprivilegedport", oUsePrivilegedPort },
1.116 markus 141: { "rhostsauthentication", oDeprecated },
1.17 markus 142: { "passwordauthentication", oPasswordAuthentication },
1.48 markus 143: { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
144: { "kbdinteractivedevices", oKbdInteractiveDevices },
1.17 markus 145: { "rsaauthentication", oRSAAuthentication },
1.50 markus 146: { "pubkeyauthentication", oPubkeyAuthentication },
1.59 markus 147: { "dsaauthentication", oPubkeyAuthentication }, /* alias */
1.72 markus 148: { "rhostsrsaauthentication", oRhostsRSAAuthentication },
1.73 markus 149: { "hostbasedauthentication", oHostbasedAuthentication },
1.59 markus 150: { "challengeresponseauthentication", oChallengeResponseAuthentication },
151: { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
152: { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
1.110 jakob 153: { "kerberosauthentication", oUnsupported },
154: { "kerberostgtpassing", oUnsupported },
155: { "afstokenpassing", oUnsupported },
1.118 markus 156: #if defined(GSSAPI)
157: { "gssapiauthentication", oGssAuthentication },
158: { "gssapidelegatecredentials", oGssDelegateCreds },
159: #else
160: { "gssapiauthentication", oUnsupported },
161: { "gssapidelegatecredentials", oUnsupported },
162: #endif
1.96 markus 163: { "fallbacktorsh", oDeprecated },
164: { "usersh", oDeprecated },
1.17 markus 165: { "identityfile", oIdentityFile },
1.50 markus 166: { "identityfile2", oIdentityFile }, /* alias */
1.128 markus 167: { "identitiesonly", oIdentitiesOnly },
1.17 markus 168: { "hostname", oHostName },
1.52 markus 169: { "hostkeyalias", oHostKeyAlias },
1.17 markus 170: { "proxycommand", oProxyCommand },
171: { "port", oPort },
172: { "cipher", oCipher },
1.25 markus 173: { "ciphers", oCiphers },
1.62 markus 174: { "macs", oMacs },
1.25 markus 175: { "protocol", oProtocol },
1.17 markus 176: { "remoteforward", oRemoteForward },
177: { "localforward", oLocalForward },
178: { "user", oUser },
179: { "host", oHost },
180: { "escapechar", oEscapeChar },
181: { "globalknownhostsfile", oGlobalKnownHostsFile },
1.81 markus 182: { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
1.27 markus 183: { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
1.81 markus 184: { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
1.17 markus 185: { "connectionattempts", oConnectionAttempts },
186: { "batchmode", oBatchMode },
187: { "checkhostip", oCheckHostIP },
188: { "stricthostkeychecking", oStrictHostKeyChecking },
189: { "compression", oCompression },
190: { "compressionlevel", oCompressionLevel },
1.126 markus 191: { "tcpkeepalive", oTCPKeepAlive },
192: { "keepalive", oTCPKeepAlive }, /* obsolete */
1.17 markus 193: { "numberofpasswordprompts", oNumberOfPasswordPrompts },
194: { "loglevel", oLogLevel },
1.71 markus 195: { "dynamicforward", oDynamicForward },
1.67 markus 196: { "preferredauthentications", oPreferredAuthentications },
1.76 markus 197: { "hostkeyalgorithms", oHostKeyAlgorithms },
1.77 markus 198: { "bindaddress", oBindAddress },
1.110 jakob 199: #ifdef SMARTCARD
1.85 jakob 200: { "smartcarddevice", oSmartcardDevice },
1.110 jakob 201: #else
202: { "smartcarddevice", oUnsupported },
203: #endif
1.93 deraadt 204: { "clearallforwardings", oClearAllForwardings },
1.101 markus 205: { "enablesshkeysign", oEnableSSHKeysign },
1.107 jakob 206: { "verifyhostkeydns", oVerifyHostKeyDNS },
1.93 deraadt 207: { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
1.105 markus 208: { "rekeylimit", oRekeyLimit },
1.111 djm 209: { "connecttimeout", oConnectTimeout },
1.112 djm 210: { "addressfamily", oAddressFamily },
1.127 markus 211: { "serveraliveinterval", oServerAliveInterval },
212: { "serveralivecountmax", oServerAliveCountMax },
1.130 djm 213: { "sendenv", oSendEnv },
1.132 djm 214: { "controlpath", oControlPath },
215: { "controlmaster", oControlMaster },
1.136 djm 216: { "hashknownhosts", oHashKnownHosts },
1.144 reyk 217: { "tunnel", oTunnel },
218: { "tunneldevice", oTunnelDevice },
219: { "localcommand", oLocalCommand },
220: { "permitlocalcommand", oPermitLocalCommand },
1.92 stevesk 221: { NULL, oBadOption }
1.13 markus 222: };
223:
1.19 markus 224: /*
225: * Adds a local TCP/IP port forward to options. Never returns if there is an
226: * error.
227: */
1.1 deraadt 228:
1.26 markus 229: void
1.135 djm 230: add_local_forward(Options *options, const Forward *newfwd)
1.1 deraadt 231: {
1.17 markus 232: Forward *fwd;
233: extern uid_t original_real_uid;
1.135 djm 234: if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0)
1.64 millert 235: fatal("Privileged ports can only be forwarded by root.");
1.17 markus 236: if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
237: fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
238: fwd = &options->local_forwards[options->num_local_forwards++];
1.135 djm 239:
240: fwd->listen_host = (newfwd->listen_host == NULL) ?
241: NULL : xstrdup(newfwd->listen_host);
242: fwd->listen_port = newfwd->listen_port;
243: fwd->connect_host = xstrdup(newfwd->connect_host);
244: fwd->connect_port = newfwd->connect_port;
1.1 deraadt 245: }
246:
1.19 markus 247: /*
248: * Adds a remote TCP/IP port forward to options. Never returns if there is
249: * an error.
250: */
1.1 deraadt 251:
1.26 markus 252: void
1.135 djm 253: add_remote_forward(Options *options, const Forward *newfwd)
1.1 deraadt 254: {
1.17 markus 255: Forward *fwd;
256: if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
257: fatal("Too many remote forwards (max %d).",
1.93 deraadt 258: SSH_MAX_FORWARDS_PER_DIRECTION);
1.17 markus 259: fwd = &options->remote_forwards[options->num_remote_forwards++];
1.135 djm 260:
261: fwd->listen_host = (newfwd->listen_host == NULL) ?
262: NULL : xstrdup(newfwd->listen_host);
263: fwd->listen_port = newfwd->listen_port;
264: fwd->connect_host = xstrdup(newfwd->connect_host);
265: fwd->connect_port = newfwd->connect_port;
1.1 deraadt 266: }
267:
1.90 stevesk 268: static void
269: clear_forwardings(Options *options)
270: {
271: int i;
272:
1.135 djm 273: for (i = 0; i < options->num_local_forwards; i++) {
1.138 dtucker 274: if (options->local_forwards[i].listen_host != NULL)
275: xfree(options->local_forwards[i].listen_host);
1.135 djm 276: xfree(options->local_forwards[i].connect_host);
277: }
1.90 stevesk 278: options->num_local_forwards = 0;
1.135 djm 279: for (i = 0; i < options->num_remote_forwards; i++) {
1.138 dtucker 280: if (options->remote_forwards[i].listen_host != NULL)
281: xfree(options->remote_forwards[i].listen_host);
1.135 djm 282: xfree(options->remote_forwards[i].connect_host);
283: }
1.90 stevesk 284: options->num_remote_forwards = 0;
1.145 reyk 285: options->tun_open = SSH_TUNMODE_NO;
1.90 stevesk 286: }
287:
1.19 markus 288: /*
1.70 stevesk 289: * Returns the number of the token pointed to by cp or oBadOption.
1.19 markus 290: */
1.1 deraadt 291:
1.26 markus 292: static OpCodes
1.17 markus 293: parse_token(const char *cp, const char *filename, int linenum)
1.1 deraadt 294: {
1.51 markus 295: u_int i;
1.1 deraadt 296:
1.17 markus 297: for (i = 0; keywords[i].name; i++)
1.20 markus 298: if (strcasecmp(cp, keywords[i].name) == 0)
1.17 markus 299: return keywords[i].opcode;
300:
1.75 stevesk 301: error("%s: line %d: Bad configuration option: %s",
302: filename, linenum, cp);
1.17 markus 303: return oBadOption;
1.1 deraadt 304: }
305:
1.19 markus 306: /*
307: * Processes a single option line as used in the configuration files. This
308: * only sets those values that have not already been set.
309: */
1.102 markus 310: #define WHITESPACE " \t\r\n"
1.1 deraadt 311:
1.14 markus 312: int
313: process_config_line(Options *options, const char *host,
1.17 markus 314: char *line, const char *filename, int linenum,
315: int *activep)
1.1 deraadt 316: {
1.135 djm 317: char *s, **charptr, *endofnumber, *keyword, *arg, *arg2, fwdarg[256];
1.146 djm 318: int opcode, *intptr, value, value2, scale;
319: long long orig, val64;
1.102 markus 320: size_t len;
1.135 djm 321: Forward fwd;
1.106 djm 322:
323: /* Strip trailing whitespace */
1.139 deraadt 324: for (len = strlen(line) - 1; len > 0; len--) {
1.106 djm 325: if (strchr(WHITESPACE, line[len]) == NULL)
326: break;
327: line[len] = '\0';
328: }
1.1 deraadt 329:
1.42 provos 330: s = line;
331: /* Get the keyword. (Each line is supposed to begin with a keyword). */
1.149 djm 332: if ((keyword = strdelim(&s)) == NULL)
333: return 0;
1.42 provos 334: /* Ignore leading whitespace. */
335: if (*keyword == '\0')
1.43 markus 336: keyword = strdelim(&s);
1.56 deraadt 337: if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
1.17 markus 338: return 0;
339:
1.38 provos 340: opcode = parse_token(keyword, filename, linenum);
1.17 markus 341:
342: switch (opcode) {
343: case oBadOption:
1.19 markus 344: /* don't panic, but count bad options */
345: return -1;
1.17 markus 346: /* NOTREACHED */
1.111 djm 347: case oConnectTimeout:
348: intptr = &options->connection_timeout;
1.127 markus 349: parse_time:
1.111 djm 350: arg = strdelim(&s);
351: if (!arg || *arg == '\0')
352: fatal("%s line %d: missing time value.",
353: filename, linenum);
354: if ((value = convtime(arg)) == -1)
355: fatal("%s line %d: invalid time value.",
356: filename, linenum);
357: if (*intptr == -1)
358: *intptr = value;
359: break;
360:
1.17 markus 361: case oForwardAgent:
362: intptr = &options->forward_agent;
363: parse_flag:
1.42 provos 364: arg = strdelim(&s);
1.40 ho 365: if (!arg || *arg == '\0')
1.17 markus 366: fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
367: value = 0; /* To avoid compiler warning... */
1.38 provos 368: if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1.17 markus 369: value = 1;
1.38 provos 370: else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1.17 markus 371: value = 0;
372: else
373: fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
374: if (*activep && *intptr == -1)
375: *intptr = value;
376: break;
377:
378: case oForwardX11:
379: intptr = &options->forward_x11;
380: goto parse_flag;
381:
1.123 markus 382: case oForwardX11Trusted:
383: intptr = &options->forward_x11_trusted;
384: goto parse_flag;
385:
1.17 markus 386: case oGatewayPorts:
387: intptr = &options->gateway_ports;
388: goto parse_flag;
389:
1.153 markus 390: case oExitOnForwardFailure:
391: intptr = &options->exit_on_forward_failure;
392: goto parse_flag;
393:
1.17 markus 394: case oUsePrivilegedPort:
395: intptr = &options->use_privileged_port;
396: goto parse_flag;
397:
398: case oPasswordAuthentication:
399: intptr = &options->password_authentication;
400: goto parse_flag;
401:
1.48 markus 402: case oKbdInteractiveAuthentication:
403: intptr = &options->kbd_interactive_authentication;
404: goto parse_flag;
405:
406: case oKbdInteractiveDevices:
407: charptr = &options->kbd_interactive_devices;
408: goto parse_string;
409:
1.50 markus 410: case oPubkeyAuthentication:
411: intptr = &options->pubkey_authentication;
1.30 markus 412: goto parse_flag;
413:
1.17 markus 414: case oRSAAuthentication:
415: intptr = &options->rsa_authentication;
416: goto parse_flag;
417:
418: case oRhostsRSAAuthentication:
419: intptr = &options->rhosts_rsa_authentication;
420: goto parse_flag;
421:
1.72 markus 422: case oHostbasedAuthentication:
423: intptr = &options->hostbased_authentication;
424: goto parse_flag;
425:
1.59 markus 426: case oChallengeResponseAuthentication:
1.78 markus 427: intptr = &options->challenge_response_authentication;
1.17 markus 428: goto parse_flag;
1.108 jakob 429:
1.118 markus 430: case oGssAuthentication:
431: intptr = &options->gss_authentication;
432: goto parse_flag;
433:
434: case oGssDelegateCreds:
435: intptr = &options->gss_deleg_creds;
436: goto parse_flag;
437:
1.17 markus 438: case oBatchMode:
439: intptr = &options->batch_mode;
440: goto parse_flag;
441:
442: case oCheckHostIP:
443: intptr = &options->check_host_ip;
444: goto parse_flag;
445:
1.107 jakob 446: case oVerifyHostKeyDNS:
447: intptr = &options->verify_host_key_dns;
1.125 jakob 448: goto parse_yesnoask;
1.107 jakob 449:
1.17 markus 450: case oStrictHostKeyChecking:
451: intptr = &options->strict_host_key_checking;
1.125 jakob 452: parse_yesnoask:
1.42 provos 453: arg = strdelim(&s);
1.40 ho 454: if (!arg || *arg == '\0')
1.60 stevesk 455: fatal("%.200s line %d: Missing yes/no/ask argument.",
1.93 deraadt 456: filename, linenum);
1.17 markus 457: value = 0; /* To avoid compiler warning... */
1.38 provos 458: if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1.17 markus 459: value = 1;
1.38 provos 460: else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1.17 markus 461: value = 0;
1.38 provos 462: else if (strcmp(arg, "ask") == 0)
1.17 markus 463: value = 2;
464: else
465: fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
466: if (*activep && *intptr == -1)
467: *intptr = value;
468: break;
469:
470: case oCompression:
471: intptr = &options->compression;
472: goto parse_flag;
473:
1.126 markus 474: case oTCPKeepAlive:
475: intptr = &options->tcp_keep_alive;
1.17 markus 476: goto parse_flag;
477:
1.91 markus 478: case oNoHostAuthenticationForLocalhost:
479: intptr = &options->no_host_authentication_for_localhost;
480: goto parse_flag;
481:
1.17 markus 482: case oNumberOfPasswordPrompts:
483: intptr = &options->number_of_password_prompts;
484: goto parse_int;
485:
486: case oCompressionLevel:
487: intptr = &options->compression_level;
488: goto parse_int;
489:
1.105 markus 490: case oRekeyLimit:
491: intptr = &options->rekey_limit;
492: arg = strdelim(&s);
493: if (!arg || *arg == '\0')
494: fatal("%.200s line %d: Missing argument.", filename, linenum);
495: if (arg[0] < '0' || arg[0] > '9')
496: fatal("%.200s line %d: Bad number.", filename, linenum);
1.146 djm 497: orig = val64 = strtoll(arg, &endofnumber, 10);
1.105 markus 498: if (arg == endofnumber)
499: fatal("%.200s line %d: Bad number.", filename, linenum);
500: switch (toupper(*endofnumber)) {
1.146 djm 501: case '\0':
502: scale = 1;
503: break;
1.105 markus 504: case 'K':
1.146 djm 505: scale = 1<<10;
1.105 markus 506: break;
507: case 'M':
1.146 djm 508: scale = 1<<20;
1.105 markus 509: break;
510: case 'G':
1.146 djm 511: scale = 1<<30;
1.105 markus 512: break;
1.146 djm 513: default:
514: fatal("%.200s line %d: Invalid RekeyLimit suffix",
515: filename, linenum);
1.105 markus 516: }
1.146 djm 517: val64 *= scale;
518: /* detect integer wrap and too-large limits */
519: if ((val64 / scale) != orig || val64 > INT_MAX)
520: fatal("%.200s line %d: RekeyLimit too large",
521: filename, linenum);
522: if (val64 < 16)
523: fatal("%.200s line %d: RekeyLimit too small",
524: filename, linenum);
1.105 markus 525: if (*activep && *intptr == -1)
1.146 djm 526: *intptr = (int)val64;
1.105 markus 527: break;
528:
1.17 markus 529: case oIdentityFile:
1.42 provos 530: arg = strdelim(&s);
1.40 ho 531: if (!arg || *arg == '\0')
1.17 markus 532: fatal("%.200s line %d: Missing argument.", filename, linenum);
533: if (*activep) {
1.50 markus 534: intptr = &options->num_identity_files;
1.27 markus 535: if (*intptr >= SSH_MAX_IDENTITY_FILES)
1.17 markus 536: fatal("%.200s line %d: Too many identity files specified (max %d).",
1.93 deraadt 537: filename, linenum, SSH_MAX_IDENTITY_FILES);
1.50 markus 538: charptr = &options->identity_files[*intptr];
1.38 provos 539: *charptr = xstrdup(arg);
1.27 markus 540: *intptr = *intptr + 1;
1.17 markus 541: }
542: break;
543:
1.34 markus 544: case oXAuthLocation:
545: charptr=&options->xauth_location;
546: goto parse_string;
547:
1.17 markus 548: case oUser:
549: charptr = &options->user;
550: parse_string:
1.42 provos 551: arg = strdelim(&s);
1.40 ho 552: if (!arg || *arg == '\0')
1.17 markus 553: fatal("%.200s line %d: Missing argument.", filename, linenum);
554: if (*activep && *charptr == NULL)
1.38 provos 555: *charptr = xstrdup(arg);
1.17 markus 556: break;
557:
558: case oGlobalKnownHostsFile:
559: charptr = &options->system_hostfile;
560: goto parse_string;
561:
562: case oUserKnownHostsFile:
563: charptr = &options->user_hostfile;
564: goto parse_string;
565:
1.27 markus 566: case oGlobalKnownHostsFile2:
567: charptr = &options->system_hostfile2;
568: goto parse_string;
569:
570: case oUserKnownHostsFile2:
571: charptr = &options->user_hostfile2;
572: goto parse_string;
573:
1.17 markus 574: case oHostName:
575: charptr = &options->hostname;
576: goto parse_string;
577:
1.52 markus 578: case oHostKeyAlias:
579: charptr = &options->host_key_alias;
580: goto parse_string;
581:
1.67 markus 582: case oPreferredAuthentications:
583: charptr = &options->preferred_authentications;
584: goto parse_string;
585:
1.77 markus 586: case oBindAddress:
587: charptr = &options->bind_address;
588: goto parse_string;
589:
1.85 jakob 590: case oSmartcardDevice:
1.86 markus 591: charptr = &options->smartcard_device;
592: goto parse_string;
1.85 jakob 593:
1.17 markus 594: case oProxyCommand:
1.144 reyk 595: charptr = &options->proxy_command;
596: parse_command:
1.113 markus 597: if (s == NULL)
598: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.102 markus 599: len = strspn(s, WHITESPACE "=");
1.17 markus 600: if (*activep && *charptr == NULL)
1.102 markus 601: *charptr = xstrdup(s + len);
1.17 markus 602: return 0;
603:
604: case oPort:
605: intptr = &options->port;
606: parse_int:
1.42 provos 607: arg = strdelim(&s);
1.40 ho 608: if (!arg || *arg == '\0')
1.17 markus 609: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 610: if (arg[0] < '0' || arg[0] > '9')
1.17 markus 611: fatal("%.200s line %d: Bad number.", filename, linenum);
1.21 markus 612:
613: /* Octal, decimal, or hex format? */
1.38 provos 614: value = strtol(arg, &endofnumber, 0);
615: if (arg == endofnumber)
1.21 markus 616: fatal("%.200s line %d: Bad number.", filename, linenum);
1.17 markus 617: if (*activep && *intptr == -1)
618: *intptr = value;
619: break;
620:
621: case oConnectionAttempts:
622: intptr = &options->connection_attempts;
623: goto parse_int;
624:
625: case oCipher:
626: intptr = &options->cipher;
1.42 provos 627: arg = strdelim(&s);
1.40 ho 628: if (!arg || *arg == '\0')
1.32 markus 629: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 630: value = cipher_number(arg);
1.17 markus 631: if (value == -1)
632: fatal("%.200s line %d: Bad cipher '%s'.",
1.93 deraadt 633: filename, linenum, arg ? arg : "<NONE>");
1.17 markus 634: if (*activep && *intptr == -1)
635: *intptr = value;
636: break;
637:
1.25 markus 638: case oCiphers:
1.42 provos 639: arg = strdelim(&s);
1.40 ho 640: if (!arg || *arg == '\0')
1.32 markus 641: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 642: if (!ciphers_valid(arg))
1.31 markus 643: fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.93 deraadt 644: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 645: if (*activep && options->ciphers == NULL)
1.38 provos 646: options->ciphers = xstrdup(arg);
1.25 markus 647: break;
648:
1.62 markus 649: case oMacs:
650: arg = strdelim(&s);
651: if (!arg || *arg == '\0')
652: fatal("%.200s line %d: Missing argument.", filename, linenum);
653: if (!mac_valid(arg))
654: fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
1.93 deraadt 655: filename, linenum, arg ? arg : "<NONE>");
1.62 markus 656: if (*activep && options->macs == NULL)
657: options->macs = xstrdup(arg);
658: break;
659:
1.76 markus 660: case oHostKeyAlgorithms:
661: arg = strdelim(&s);
662: if (!arg || *arg == '\0')
663: fatal("%.200s line %d: Missing argument.", filename, linenum);
664: if (!key_names_valid2(arg))
665: fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
1.93 deraadt 666: filename, linenum, arg ? arg : "<NONE>");
1.76 markus 667: if (*activep && options->hostkeyalgorithms == NULL)
668: options->hostkeyalgorithms = xstrdup(arg);
669: break;
670:
1.25 markus 671: case oProtocol:
672: intptr = &options->protocol;
1.42 provos 673: arg = strdelim(&s);
1.40 ho 674: if (!arg || *arg == '\0')
1.32 markus 675: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 676: value = proto_spec(arg);
1.25 markus 677: if (value == SSH_PROTO_UNKNOWN)
678: fatal("%.200s line %d: Bad protocol spec '%s'.",
1.93 deraadt 679: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 680: if (*activep && *intptr == SSH_PROTO_UNKNOWN)
681: *intptr = value;
682: break;
683:
1.17 markus 684: case oLogLevel:
685: intptr = (int *) &options->log_level;
1.42 provos 686: arg = strdelim(&s);
1.38 provos 687: value = log_level_number(arg);
1.95 markus 688: if (value == SYSLOG_LEVEL_NOT_SET)
1.64 millert 689: fatal("%.200s line %d: unsupported log level '%s'",
1.93 deraadt 690: filename, linenum, arg ? arg : "<NONE>");
1.95 markus 691: if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
1.17 markus 692: *intptr = (LogLevel) value;
693: break;
694:
1.88 stevesk 695: case oLocalForward:
1.17 markus 696: case oRemoteForward:
1.42 provos 697: arg = strdelim(&s);
1.135 djm 698: if (arg == NULL || *arg == '\0')
1.88 stevesk 699: fatal("%.200s line %d: Missing port argument.",
700: filename, linenum);
1.135 djm 701: arg2 = strdelim(&s);
702: if (arg2 == NULL || *arg2 == '\0')
703: fatal("%.200s line %d: Missing target argument.",
1.88 stevesk 704: filename, linenum);
1.135 djm 705:
706: /* construct a string for parse_forward */
707: snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
708:
709: if (parse_forward(&fwd, fwdarg) == 0)
1.88 stevesk 710: fatal("%.200s line %d: Bad forwarding specification.",
711: filename, linenum);
1.135 djm 712:
1.88 stevesk 713: if (*activep) {
714: if (opcode == oLocalForward)
1.135 djm 715: add_local_forward(options, &fwd);
1.88 stevesk 716: else if (opcode == oRemoteForward)
1.135 djm 717: add_remote_forward(options, &fwd);
1.88 stevesk 718: }
1.17 markus 719: break;
1.71 markus 720:
721: case oDynamicForward:
722: arg = strdelim(&s);
723: if (!arg || *arg == '\0')
724: fatal("%.200s line %d: Missing port argument.",
725: filename, linenum);
1.135 djm 726: memset(&fwd, '\0', sizeof(fwd));
727: fwd.connect_host = "socks";
728: fwd.listen_host = hpdelim(&arg);
729: if (fwd.listen_host == NULL ||
730: strlen(fwd.listen_host) >= NI_MAXHOST)
731: fatal("%.200s line %d: Bad forwarding specification.",
732: filename, linenum);
733: if (arg) {
734: fwd.listen_port = a2port(arg);
735: fwd.listen_host = cleanhostname(fwd.listen_host);
736: } else {
737: fwd.listen_port = a2port(fwd.listen_host);
1.143 djm 738: fwd.listen_host = NULL;
1.135 djm 739: }
740: if (fwd.listen_port == 0)
1.71 markus 741: fatal("%.200s line %d: Badly formatted port number.",
742: filename, linenum);
1.87 markus 743: if (*activep)
1.135 djm 744: add_local_forward(options, &fwd);
1.72 markus 745: break;
1.17 markus 746:
1.90 stevesk 747: case oClearAllForwardings:
748: intptr = &options->clear_forwardings;
749: goto parse_flag;
750:
1.17 markus 751: case oHost:
752: *activep = 0;
1.42 provos 753: while ((arg = strdelim(&s)) != NULL && *arg != '\0')
1.38 provos 754: if (match_pattern(host, arg)) {
755: debug("Applying options for %.100s", arg);
1.17 markus 756: *activep = 1;
757: break;
758: }
1.42 provos 759: /* Avoid garbage check below, as strdelim is done. */
1.17 markus 760: return 0;
761:
762: case oEscapeChar:
763: intptr = &options->escape_char;
1.42 provos 764: arg = strdelim(&s);
1.40 ho 765: if (!arg || *arg == '\0')
1.17 markus 766: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 767: if (arg[0] == '^' && arg[2] == 0 &&
1.51 markus 768: (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
769: value = (u_char) arg[1] & 31;
1.38 provos 770: else if (strlen(arg) == 1)
1.51 markus 771: value = (u_char) arg[0];
1.38 provos 772: else if (strcmp(arg, "none") == 0)
1.79 stevesk 773: value = SSH_ESCAPECHAR_NONE;
1.17 markus 774: else {
775: fatal("%.200s line %d: Bad escape character.",
1.93 deraadt 776: filename, linenum);
1.17 markus 777: /* NOTREACHED */
778: value = 0; /* Avoid compiler warning. */
779: }
780: if (*activep && *intptr == -1)
781: *intptr = value;
1.112 djm 782: break;
783:
784: case oAddressFamily:
785: arg = strdelim(&s);
1.140 markus 786: if (!arg || *arg == '\0')
787: fatal("%s line %d: missing address family.",
788: filename, linenum);
1.114 djm 789: intptr = &options->address_family;
1.112 djm 790: if (strcasecmp(arg, "inet") == 0)
1.114 djm 791: value = AF_INET;
1.112 djm 792: else if (strcasecmp(arg, "inet6") == 0)
1.114 djm 793: value = AF_INET6;
1.112 djm 794: else if (strcasecmp(arg, "any") == 0)
1.114 djm 795: value = AF_UNSPEC;
1.112 djm 796: else
797: fatal("Unsupported AddressFamily \"%s\"", arg);
1.114 djm 798: if (*activep && *intptr == -1)
799: *intptr = value;
1.17 markus 800: break;
801:
1.101 markus 802: case oEnableSSHKeysign:
803: intptr = &options->enable_ssh_keysign;
804: goto parse_flag;
805:
1.128 markus 806: case oIdentitiesOnly:
807: intptr = &options->identities_only;
808: goto parse_flag;
809:
1.127 markus 810: case oServerAliveInterval:
811: intptr = &options->server_alive_interval;
812: goto parse_time;
813:
814: case oServerAliveCountMax:
815: intptr = &options->server_alive_count_max;
816: goto parse_int;
817:
1.130 djm 818: case oSendEnv:
819: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
820: if (strchr(arg, '=') != NULL)
821: fatal("%s line %d: Invalid environment name.",
822: filename, linenum);
1.137 djm 823: if (!*activep)
824: continue;
1.130 djm 825: if (options->num_send_env >= MAX_SEND_ENV)
826: fatal("%s line %d: too many send env.",
827: filename, linenum);
828: options->send_env[options->num_send_env++] =
829: xstrdup(arg);
830: }
831: break;
832:
1.132 djm 833: case oControlPath:
834: charptr = &options->control_path;
835: goto parse_string;
836:
837: case oControlMaster:
838: intptr = &options->control_master;
1.141 djm 839: arg = strdelim(&s);
840: if (!arg || *arg == '\0')
841: fatal("%.200s line %d: Missing ControlMaster argument.",
842: filename, linenum);
843: value = 0; /* To avoid compiler warning... */
844: if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
845: value = SSHCTL_MASTER_YES;
846: else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
847: value = SSHCTL_MASTER_NO;
848: else if (strcmp(arg, "auto") == 0)
849: value = SSHCTL_MASTER_AUTO;
850: else if (strcmp(arg, "ask") == 0)
851: value = SSHCTL_MASTER_ASK;
852: else if (strcmp(arg, "autoask") == 0)
853: value = SSHCTL_MASTER_AUTO_ASK;
854: else
855: fatal("%.200s line %d: Bad ControlMaster argument.",
856: filename, linenum);
857: if (*activep && *intptr == -1)
858: *intptr = value;
859: break;
1.132 djm 860:
1.136 djm 861: case oHashKnownHosts:
862: intptr = &options->hash_known_hosts;
863: goto parse_flag;
864:
1.144 reyk 865: case oTunnel:
866: intptr = &options->tun_open;
1.145 reyk 867: arg = strdelim(&s);
868: if (!arg || *arg == '\0')
869: fatal("%s line %d: Missing yes/point-to-point/"
870: "ethernet/no argument.", filename, linenum);
871: value = 0; /* silence compiler */
872: if (strcasecmp(arg, "ethernet") == 0)
873: value = SSH_TUNMODE_ETHERNET;
874: else if (strcasecmp(arg, "point-to-point") == 0)
875: value = SSH_TUNMODE_POINTOPOINT;
876: else if (strcasecmp(arg, "yes") == 0)
877: value = SSH_TUNMODE_DEFAULT;
878: else if (strcasecmp(arg, "no") == 0)
879: value = SSH_TUNMODE_NO;
880: else
881: fatal("%s line %d: Bad yes/point-to-point/ethernet/"
882: "no argument: %s", filename, linenum, arg);
883: if (*activep)
884: *intptr = value;
885: break;
1.144 reyk 886:
887: case oTunnelDevice:
888: arg = strdelim(&s);
889: if (!arg || *arg == '\0')
890: fatal("%.200s line %d: Missing argument.", filename, linenum);
891: value = a2tun(arg, &value2);
1.145 reyk 892: if (value == SSH_TUNID_ERR)
1.144 reyk 893: fatal("%.200s line %d: Bad tun device.", filename, linenum);
894: if (*activep) {
895: options->tun_local = value;
896: options->tun_remote = value2;
897: }
898: break;
899:
900: case oLocalCommand:
901: charptr = &options->local_command;
902: goto parse_command;
903:
904: case oPermitLocalCommand:
905: intptr = &options->permit_local_command;
906: goto parse_flag;
907:
1.96 markus 908: case oDeprecated:
1.98 markus 909: debug("%s line %d: Deprecated option \"%s\"",
1.96 markus 910: filename, linenum, keyword);
1.98 markus 911: return 0;
1.96 markus 912:
1.110 jakob 913: case oUnsupported:
914: error("%s line %d: Unsupported option \"%s\"",
915: filename, linenum, keyword);
916: return 0;
917:
1.17 markus 918: default:
919: fatal("process_config_line: Unimplemented opcode %d", opcode);
920: }
921:
922: /* Check that there is no garbage at end of line. */
1.57 djm 923: if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.39 ho 924: fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
1.142 djm 925: filename, linenum, arg);
1.39 ho 926: }
1.17 markus 927: return 0;
1.1 deraadt 928: }
929:
930:
1.19 markus 931: /*
932: * Reads the config file and modifies the options accordingly. Options
933: * should already be initialized before this call. This never returns if
1.89 stevesk 934: * there is an error. If the file does not exist, this returns 0.
1.19 markus 935: */
1.1 deraadt 936:
1.89 stevesk 937: int
1.134 deraadt 938: read_config_file(const char *filename, const char *host, Options *options,
1.129 djm 939: int checkperm)
1.1 deraadt 940: {
1.17 markus 941: FILE *f;
942: char line[1024];
943: int active, linenum;
944: int bad_options = 0;
945:
946: /* Open the file. */
1.129 djm 947: if ((f = fopen(filename, "r")) == NULL)
1.89 stevesk 948: return 0;
1.129 djm 949:
950: if (checkperm) {
951: struct stat sb;
1.134 deraadt 952:
1.131 dtucker 953: if (fstat(fileno(f), &sb) == -1)
1.129 djm 954: fatal("fstat %s: %s", filename, strerror(errno));
955: if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1.131 dtucker 956: (sb.st_mode & 022) != 0))
1.129 djm 957: fatal("Bad owner or permissions on %s", filename);
958: }
1.17 markus 959:
960: debug("Reading configuration data %.200s", filename);
961:
1.19 markus 962: /*
963: * Mark that we are now processing the options. This flag is turned
964: * on/off by Host specifications.
965: */
1.17 markus 966: active = 1;
967: linenum = 0;
968: while (fgets(line, sizeof(line), f)) {
969: /* Update line number counter. */
970: linenum++;
971: if (process_config_line(options, host, line, filename, linenum, &active) != 0)
972: bad_options++;
973: }
974: fclose(f);
975: if (bad_options > 0)
1.64 millert 976: fatal("%s: terminating, %d bad configuration options",
1.93 deraadt 977: filename, bad_options);
1.89 stevesk 978: return 1;
1.1 deraadt 979: }
980:
1.19 markus 981: /*
982: * Initializes options to special values that indicate that they have not yet
983: * been set. Read_config_file will only set options with this value. Options
984: * are processed in the following order: command line, user config file,
985: * system config file. Last, fill_default_options is called.
986: */
1.1 deraadt 987:
1.26 markus 988: void
1.17 markus 989: initialize_options(Options * options)
1.1 deraadt 990: {
1.17 markus 991: memset(options, 'X', sizeof(*options));
992: options->forward_agent = -1;
993: options->forward_x11 = -1;
1.123 markus 994: options->forward_x11_trusted = -1;
1.153 markus 995: options->exit_on_forward_failure = -1;
1.34 markus 996: options->xauth_location = NULL;
1.17 markus 997: options->gateway_ports = -1;
998: options->use_privileged_port = -1;
999: options->rsa_authentication = -1;
1.50 markus 1000: options->pubkey_authentication = -1;
1.78 markus 1001: options->challenge_response_authentication = -1;
1.118 markus 1002: options->gss_authentication = -1;
1003: options->gss_deleg_creds = -1;
1.17 markus 1004: options->password_authentication = -1;
1.48 markus 1005: options->kbd_interactive_authentication = -1;
1006: options->kbd_interactive_devices = NULL;
1.17 markus 1007: options->rhosts_rsa_authentication = -1;
1.72 markus 1008: options->hostbased_authentication = -1;
1.17 markus 1009: options->batch_mode = -1;
1010: options->check_host_ip = -1;
1011: options->strict_host_key_checking = -1;
1012: options->compression = -1;
1.126 markus 1013: options->tcp_keep_alive = -1;
1.17 markus 1014: options->compression_level = -1;
1015: options->port = -1;
1.114 djm 1016: options->address_family = -1;
1.17 markus 1017: options->connection_attempts = -1;
1.111 djm 1018: options->connection_timeout = -1;
1.17 markus 1019: options->number_of_password_prompts = -1;
1020: options->cipher = -1;
1.25 markus 1021: options->ciphers = NULL;
1.62 markus 1022: options->macs = NULL;
1.76 markus 1023: options->hostkeyalgorithms = NULL;
1.25 markus 1024: options->protocol = SSH_PROTO_UNKNOWN;
1.17 markus 1025: options->num_identity_files = 0;
1026: options->hostname = NULL;
1.52 markus 1027: options->host_key_alias = NULL;
1.17 markus 1028: options->proxy_command = NULL;
1029: options->user = NULL;
1030: options->escape_char = -1;
1031: options->system_hostfile = NULL;
1032: options->user_hostfile = NULL;
1.27 markus 1033: options->system_hostfile2 = NULL;
1034: options->user_hostfile2 = NULL;
1.17 markus 1035: options->num_local_forwards = 0;
1036: options->num_remote_forwards = 0;
1.90 stevesk 1037: options->clear_forwardings = -1;
1.95 markus 1038: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.67 markus 1039: options->preferred_authentications = NULL;
1.77 markus 1040: options->bind_address = NULL;
1.86 markus 1041: options->smartcard_device = NULL;
1.101 markus 1042: options->enable_ssh_keysign = - 1;
1.91 markus 1043: options->no_host_authentication_for_localhost = - 1;
1.128 markus 1044: options->identities_only = - 1;
1.105 markus 1045: options->rekey_limit = - 1;
1.107 jakob 1046: options->verify_host_key_dns = -1;
1.127 markus 1047: options->server_alive_interval = -1;
1048: options->server_alive_count_max = -1;
1.130 djm 1049: options->num_send_env = 0;
1.132 djm 1050: options->control_path = NULL;
1051: options->control_master = -1;
1.136 djm 1052: options->hash_known_hosts = -1;
1.144 reyk 1053: options->tun_open = -1;
1054: options->tun_local = -1;
1055: options->tun_remote = -1;
1056: options->local_command = NULL;
1057: options->permit_local_command = -1;
1.1 deraadt 1058: }
1059:
1.19 markus 1060: /*
1061: * Called after processing other sources of option data, this fills those
1062: * options for which no value has been specified with their default values.
1063: */
1.1 deraadt 1064:
1.26 markus 1065: void
1.17 markus 1066: fill_default_options(Options * options)
1.1 deraadt 1067: {
1.61 deraadt 1068: int len;
1069:
1.17 markus 1070: if (options->forward_agent == -1)
1.33 markus 1071: options->forward_agent = 0;
1.17 markus 1072: if (options->forward_x11 == -1)
1.23 markus 1073: options->forward_x11 = 0;
1.123 markus 1074: if (options->forward_x11_trusted == -1)
1075: options->forward_x11_trusted = 0;
1.153 markus 1076: if (options->exit_on_forward_failure == -1)
1077: options->exit_on_forward_failure = 0;
1.34 markus 1078: if (options->xauth_location == NULL)
1.80 markus 1079: options->xauth_location = _PATH_XAUTH;
1.17 markus 1080: if (options->gateway_ports == -1)
1081: options->gateway_ports = 0;
1082: if (options->use_privileged_port == -1)
1.65 markus 1083: options->use_privileged_port = 0;
1.17 markus 1084: if (options->rsa_authentication == -1)
1085: options->rsa_authentication = 1;
1.50 markus 1086: if (options->pubkey_authentication == -1)
1087: options->pubkey_authentication = 1;
1.78 markus 1088: if (options->challenge_response_authentication == -1)
1.83 markus 1089: options->challenge_response_authentication = 1;
1.118 markus 1090: if (options->gss_authentication == -1)
1.122 markus 1091: options->gss_authentication = 0;
1.118 markus 1092: if (options->gss_deleg_creds == -1)
1093: options->gss_deleg_creds = 0;
1.17 markus 1094: if (options->password_authentication == -1)
1095: options->password_authentication = 1;
1.48 markus 1096: if (options->kbd_interactive_authentication == -1)
1.59 markus 1097: options->kbd_interactive_authentication = 1;
1.17 markus 1098: if (options->rhosts_rsa_authentication == -1)
1.99 stevesk 1099: options->rhosts_rsa_authentication = 0;
1.72 markus 1100: if (options->hostbased_authentication == -1)
1101: options->hostbased_authentication = 0;
1.17 markus 1102: if (options->batch_mode == -1)
1103: options->batch_mode = 0;
1104: if (options->check_host_ip == -1)
1105: options->check_host_ip = 1;
1106: if (options->strict_host_key_checking == -1)
1107: options->strict_host_key_checking = 2; /* 2 is default */
1108: if (options->compression == -1)
1109: options->compression = 0;
1.126 markus 1110: if (options->tcp_keep_alive == -1)
1111: options->tcp_keep_alive = 1;
1.17 markus 1112: if (options->compression_level == -1)
1113: options->compression_level = 6;
1114: if (options->port == -1)
1115: options->port = 0; /* Filled in ssh_connect. */
1.114 djm 1116: if (options->address_family == -1)
1117: options->address_family = AF_UNSPEC;
1.17 markus 1118: if (options->connection_attempts == -1)
1.84 markus 1119: options->connection_attempts = 1;
1.17 markus 1120: if (options->number_of_password_prompts == -1)
1121: options->number_of_password_prompts = 3;
1122: /* Selected in ssh_login(). */
1123: if (options->cipher == -1)
1124: options->cipher = SSH_CIPHER_NOT_SET;
1.31 markus 1125: /* options->ciphers, default set in myproposals.h */
1.62 markus 1126: /* options->macs, default set in myproposals.h */
1.76 markus 1127: /* options->hostkeyalgorithms, default set in myproposals.h */
1.25 markus 1128: if (options->protocol == SSH_PROTO_UNKNOWN)
1.69 markus 1129: options->protocol = SSH_PROTO_1|SSH_PROTO_2;
1.17 markus 1130: if (options->num_identity_files == 0) {
1.50 markus 1131: if (options->protocol & SSH_PROTO_1) {
1.61 deraadt 1132: len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
1.50 markus 1133: options->identity_files[options->num_identity_files] =
1.61 deraadt 1134: xmalloc(len);
1135: snprintf(options->identity_files[options->num_identity_files++],
1136: len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
1.50 markus 1137: }
1138: if (options->protocol & SSH_PROTO_2) {
1.63 deraadt 1139: len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
1140: options->identity_files[options->num_identity_files] =
1141: xmalloc(len);
1142: snprintf(options->identity_files[options->num_identity_files++],
1143: len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
1144:
1.61 deraadt 1145: len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
1.50 markus 1146: options->identity_files[options->num_identity_files] =
1.61 deraadt 1147: xmalloc(len);
1148: snprintf(options->identity_files[options->num_identity_files++],
1149: len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
1.50 markus 1150: }
1.27 markus 1151: }
1.17 markus 1152: if (options->escape_char == -1)
1153: options->escape_char = '~';
1154: if (options->system_hostfile == NULL)
1.55 markus 1155: options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
1.17 markus 1156: if (options->user_hostfile == NULL)
1.55 markus 1157: options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
1.27 markus 1158: if (options->system_hostfile2 == NULL)
1.55 markus 1159: options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
1.27 markus 1160: if (options->user_hostfile2 == NULL)
1.55 markus 1161: options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
1.95 markus 1162: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.54 markus 1163: options->log_level = SYSLOG_LEVEL_INFO;
1.90 stevesk 1164: if (options->clear_forwardings == 1)
1165: clear_forwardings(options);
1.91 markus 1166: if (options->no_host_authentication_for_localhost == - 1)
1167: options->no_host_authentication_for_localhost = 0;
1.128 markus 1168: if (options->identities_only == -1)
1169: options->identities_only = 0;
1.101 markus 1170: if (options->enable_ssh_keysign == -1)
1171: options->enable_ssh_keysign = 0;
1.105 markus 1172: if (options->rekey_limit == -1)
1173: options->rekey_limit = 0;
1.107 jakob 1174: if (options->verify_host_key_dns == -1)
1175: options->verify_host_key_dns = 0;
1.127 markus 1176: if (options->server_alive_interval == -1)
1177: options->server_alive_interval = 0;
1178: if (options->server_alive_count_max == -1)
1179: options->server_alive_count_max = 3;
1.132 djm 1180: if (options->control_master == -1)
1181: options->control_master = 0;
1.136 djm 1182: if (options->hash_known_hosts == -1)
1183: options->hash_known_hosts = 0;
1.144 reyk 1184: if (options->tun_open == -1)
1.145 reyk 1185: options->tun_open = SSH_TUNMODE_NO;
1186: if (options->tun_local == -1)
1187: options->tun_local = SSH_TUNID_ANY;
1188: if (options->tun_remote == -1)
1189: options->tun_remote = SSH_TUNID_ANY;
1.144 reyk 1190: if (options->permit_local_command == -1)
1191: options->permit_local_command = 0;
1192: /* options->local_command should not be set by default */
1.17 markus 1193: /* options->proxy_command should not be set by default */
1194: /* options->user will be set in the main program if appropriate */
1195: /* options->hostname will be set in the main program if appropriate */
1.52 markus 1196: /* options->host_key_alias should not be set by default */
1.67 markus 1197: /* options->preferred_authentications will be set in ssh */
1.135 djm 1198: }
1199:
1200: /*
1201: * parse_forward
1202: * parses a string containing a port forwarding specification of the form:
1203: * [listenhost:]listenport:connecthost:connectport
1204: * returns number of arguments parsed or zero on error
1205: */
1206: int
1207: parse_forward(Forward *fwd, const char *fwdspec)
1208: {
1209: int i;
1210: char *p, *cp, *fwdarg[4];
1211:
1212: memset(fwd, '\0', sizeof(*fwd));
1213:
1214: cp = p = xstrdup(fwdspec);
1215:
1216: /* skip leading spaces */
1217: while (*cp && isspace(*cp))
1218: cp++;
1219:
1220: for (i = 0; i < 4; ++i)
1221: if ((fwdarg[i] = hpdelim(&cp)) == NULL)
1222: break;
1223:
1224: /* Check for trailing garbage in 4-arg case*/
1225: if (cp != NULL)
1226: i = 0; /* failure */
1227:
1228: switch (i) {
1229: case 3:
1230: fwd->listen_host = NULL;
1231: fwd->listen_port = a2port(fwdarg[0]);
1232: fwd->connect_host = xstrdup(cleanhostname(fwdarg[1]));
1233: fwd->connect_port = a2port(fwdarg[2]);
1234: break;
1235:
1236: case 4:
1237: fwd->listen_host = xstrdup(cleanhostname(fwdarg[0]));
1238: fwd->listen_port = a2port(fwdarg[1]);
1239: fwd->connect_host = xstrdup(cleanhostname(fwdarg[2]));
1240: fwd->connect_port = a2port(fwdarg[3]);
1241: break;
1242: default:
1243: i = 0; /* failure */
1244: }
1245:
1246: xfree(p);
1247:
1248: if (fwd->listen_port == 0 && fwd->connect_port == 0)
1249: goto fail_free;
1250:
1251: if (fwd->connect_host != NULL &&
1252: strlen(fwd->connect_host) >= NI_MAXHOST)
1253: goto fail_free;
1254:
1255: return (i);
1256:
1257: fail_free:
1258: if (fwd->connect_host != NULL)
1259: xfree(fwd->connect_host);
1260: if (fwd->listen_host != NULL)
1261: xfree(fwd->listen_host);
1262: return (0);
1.1 deraadt 1263: }