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