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