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