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