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