blob: cf27a9f4107e842b4c642f587fbda3d101631465 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11003 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11005 * Functions for reading the configuration files.
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Miller43f6db62005-08-12 22:11:18 +100015RCSID("$OpenBSD: readconf.c,v 1.143 2005/07/30 02:03:47 djm Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016
17#include "ssh.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100018#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100019#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000020#include "cipher.h"
21#include "pathnames.h"
22#include "log.h"
23#include "readconf.h"
24#include "match.h"
25#include "misc.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000026#include "kex.h"
27#include "mac.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100028
29/* Format of the configuration file:
30
31 # Configuration data is parsed as follows:
32 # 1. command line options
33 # 2. user-specific file
34 # 3. system-wide file
35 # Any configuration value is only changed the first time it is set.
36 # Thus, host-specific definitions should be at the beginning of the
37 # configuration file, and defaults at the end.
38
39 # Host-specific declarations. These may override anything above. A single
40 # host may match multiple declarations; these are processed in the order
41 # that they are given in.
42
43 Host *.ngs.fi ngs.fi
Ben Lindstrom4daea862002-06-09 20:04:02 +000044 User foo
Damien Millerd4a8b7e1999-10-27 13:42:43 +100045
46 Host fake.com
47 HostName another.host.name.real.org
48 User blaah
49 Port 34289
50 ForwardX11 no
51 ForwardAgent no
52
53 Host books.com
54 RemoteForward 9999 shadows.cs.hut.fi:9999
55 Cipher 3des
56
57 Host fascist.blob.com
58 Port 23123
59 User tylonen
Damien Millerd4a8b7e1999-10-27 13:42:43 +100060 PasswordAuthentication no
61
62 Host puukko.hut.fi
63 User t35124p
64 ProxyCommand ssh-proxy %h %p
65
66 Host *.fr
Ben Lindstrom4daea862002-06-09 20:04:02 +000067 PublicKeyAuthentication no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068
69 Host *.su
70 Cipher none
71 PasswordAuthentication no
72
73 # Defaults for various options
74 Host *
75 ForwardAgent no
Damien Miller0bc1bd82000-11-13 22:57:25 +110076 ForwardX11 no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100077 PasswordAuthentication yes
78 RSAAuthentication yes
79 RhostsRSAAuthentication yes
Damien Millerd4a8b7e1999-10-27 13:42:43 +100080 StrictHostKeyChecking yes
Damien Miller12c150e2003-12-17 16:31:10 +110081 TcpKeepAlive no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100082 IdentityFile ~/.ssh/identity
83 Port 22
84 EscapeChar ~
85
86*/
87
88/* Keyword tokens. */
89
Damien Miller95def091999-11-25 00:26:21 +110090typedef enum {
91 oBadOption,
Darren Tucker0a118da2003-10-15 15:54:32 +100092 oForwardAgent, oForwardX11, oForwardX11Trusted, oGatewayPorts,
Ben Lindstromcb72e4f2002-06-21 00:41:51 +000093 oPasswordAuthentication, oRSAAuthentication,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000094 oChallengeResponseAuthentication, oXAuthLocation,
Damien Miller95def091999-11-25 00:26:21 +110095 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
96 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
97 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
98 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Damien Miller12c150e2003-12-17 16:31:10 +110099 oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000100 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100101 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000102 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000103 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000104 oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000105 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
Damien Millerb78d5eb2003-05-16 11:39:04 +1000106 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
Darren Tucker0efd1552003-08-26 11:49:55 +1000107 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
Damien Millerbd394c32004-03-08 23:12:36 +1100108 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
Damien Millere1776152005-03-01 21:47:37 +1100109 oSendEnv, oControlPath, oControlMaster, oHashKnownHosts,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000110 oDeprecated, oUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000111} OpCodes;
112
113/* Textual representations of the tokens. */
114
Damien Miller95def091999-11-25 00:26:21 +1100115static struct {
116 const char *name;
117 OpCodes opcode;
118} keywords[] = {
119 { "forwardagent", oForwardAgent },
120 { "forwardx11", oForwardX11 },
Darren Tucker0a118da2003-10-15 15:54:32 +1000121 { "forwardx11trusted", oForwardX11Trusted },
Damien Millerd3a18572000-06-07 19:55:44 +1000122 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100123 { "gatewayports", oGatewayPorts },
124 { "useprivilegedport", oUsePrivilegedPort },
Darren Tuckerec960f22003-08-13 20:37:05 +1000125 { "rhostsauthentication", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100126 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100127 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
128 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100129 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100130 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000131 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000132 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000133 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000134 { "challengeresponseauthentication", oChallengeResponseAuthentication },
135 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
136 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Millerf9b3feb2003-05-16 11:38:32 +1000137 { "kerberosauthentication", oUnsupported },
138 { "kerberostgtpassing", oUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000139 { "afstokenpassing", oUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000140#if defined(GSSAPI)
141 { "gssapiauthentication", oGssAuthentication },
Darren Tucker0efd1552003-08-26 11:49:55 +1000142 { "gssapidelegatecredentials", oGssDelegateCreds },
143#else
144 { "gssapiauthentication", oUnsupported },
145 { "gssapidelegatecredentials", oUnsupported },
146#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000147 { "fallbacktorsh", oDeprecated },
148 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100149 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100150 { "identityfile2", oIdentityFile }, /* alias */
Damien Millerbd394c32004-03-08 23:12:36 +1100151 { "identitiesonly", oIdentitiesOnly },
Damien Miller95def091999-11-25 00:26:21 +1100152 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000153 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100154 { "proxycommand", oProxyCommand },
155 { "port", oPort },
156 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000157 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000158 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000159 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100160 { "remoteforward", oRemoteForward },
161 { "localforward", oLocalForward },
162 { "user", oUser },
163 { "host", oHost },
164 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100165 { "globalknownhostsfile", oGlobalKnownHostsFile },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000166 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
Damien Millereba71ba2000-04-29 23:57:08 +1000167 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000168 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100169 { "connectionattempts", oConnectionAttempts },
170 { "batchmode", oBatchMode },
171 { "checkhostip", oCheckHostIP },
172 { "stricthostkeychecking", oStrictHostKeyChecking },
173 { "compression", oCompression },
174 { "compressionlevel", oCompressionLevel },
Damien Miller12c150e2003-12-17 16:31:10 +1100175 { "tcpkeepalive", oTCPKeepAlive },
176 { "keepalive", oTCPKeepAlive }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100177 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100178 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000179 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000180 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000181 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000182 { "bindaddress", oBindAddress },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000183#ifdef SMARTCARD
Ben Lindstromae996bf2001-08-06 21:27:53 +0000184 { "smartcarddevice", oSmartcardDevice },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000185#else
186 { "smartcarddevice", oUnsupported },
187#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100188 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000189 { "enablesshkeysign", oEnableSSHKeysign },
Damien Miller37876e92003-05-15 10:19:46 +1000190 { "verifyhostkeydns", oVerifyHostKeyDNS },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100191 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000192 { "rekeylimit", oRekeyLimit },
Damien Millerb78d5eb2003-05-16 11:39:04 +1000193 { "connecttimeout", oConnectTimeout },
Damien Miller20a8f972003-05-18 20:50:30 +1000194 { "addressfamily", oAddressFamily },
Damien Miller509b0102003-12-17 16:33:10 +1100195 { "serveraliveinterval", oServerAliveInterval },
196 { "serveralivecountmax", oServerAliveCountMax },
Darren Tucker46bc0752004-05-02 22:11:30 +1000197 { "sendenv", oSendEnv },
Damien Miller0e220db2004-06-15 10:34:08 +1000198 { "controlpath", oControlPath },
199 { "controlmaster", oControlMaster },
Damien Millere1776152005-03-01 21:47:37 +1100200 { "hashknownhosts", oHashKnownHosts },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000201 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100202};
203
Damien Miller5428f641999-11-25 11:54:57 +1100204/*
205 * Adds a local TCP/IP port forward to options. Never returns if there is an
206 * error.
207 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000208
Damien Miller4af51302000-04-16 11:18:38 +1000209void
Damien Millerf91ee4c2005-03-01 21:24:33 +1100210add_local_forward(Options *options, const Forward *newfwd)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000211{
Damien Miller95def091999-11-25 00:26:21 +1100212 Forward *fwd;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000213#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100214 extern uid_t original_real_uid;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100215 if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000216 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100217#endif
Damien Miller95def091999-11-25 00:26:21 +1100218 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
219 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
220 fwd = &options->local_forwards[options->num_local_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100221
222 fwd->listen_host = (newfwd->listen_host == NULL) ?
223 NULL : xstrdup(newfwd->listen_host);
224 fwd->listen_port = newfwd->listen_port;
225 fwd->connect_host = xstrdup(newfwd->connect_host);
226 fwd->connect_port = newfwd->connect_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000227}
228
Damien Miller5428f641999-11-25 11:54:57 +1100229/*
230 * Adds a remote TCP/IP port forward to options. Never returns if there is
231 * an error.
232 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000233
Damien Miller4af51302000-04-16 11:18:38 +1000234void
Damien Millerf91ee4c2005-03-01 21:24:33 +1100235add_remote_forward(Options *options, const Forward *newfwd)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000236{
Damien Miller95def091999-11-25 00:26:21 +1100237 Forward *fwd;
238 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
239 fatal("Too many remote forwards (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100240 SSH_MAX_FORWARDS_PER_DIRECTION);
Damien Miller95def091999-11-25 00:26:21 +1100241 fwd = &options->remote_forwards[options->num_remote_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100242
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;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000248}
249
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000250static void
251clear_forwardings(Options *options)
252{
253 int i;
254
Damien Millerf91ee4c2005-03-01 21:24:33 +1100255 for (i = 0; i < options->num_local_forwards; i++) {
Darren Tucker1d55ca72005-03-14 22:58:40 +1100256 if (options->local_forwards[i].listen_host != NULL)
257 xfree(options->local_forwards[i].listen_host);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100258 xfree(options->local_forwards[i].connect_host);
259 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000260 options->num_local_forwards = 0;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100261 for (i = 0; i < options->num_remote_forwards; i++) {
Darren Tucker1d55ca72005-03-14 22:58:40 +1100262 if (options->remote_forwards[i].listen_host != NULL)
263 xfree(options->remote_forwards[i].listen_host);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100264 xfree(options->remote_forwards[i].connect_host);
265 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000266 options->num_remote_forwards = 0;
267}
268
Damien Miller5428f641999-11-25 11:54:57 +1100269/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000270 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100271 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000272
Damien Miller4af51302000-04-16 11:18:38 +1000273static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100274parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000275{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000276 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000277
Damien Miller95def091999-11-25 00:26:21 +1100278 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100279 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100280 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000281
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000282 error("%s: line %d: Bad configuration option: %s",
283 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100284 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000285}
286
Damien Miller5428f641999-11-25 11:54:57 +1100287/*
288 * Processes a single option line as used in the configuration files. This
289 * only sets those values that have not already been set.
290 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100291#define WHITESPACE " \t\r\n"
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000292
Damien Miller2ccf6611999-11-15 15:25:10 +1100293int
294process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100295 char *line, const char *filename, int linenum,
296 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000297{
Damien Millerf91ee4c2005-03-01 21:24:33 +1100298 char *s, **charptr, *endofnumber, *keyword, *arg, *arg2, fwdarg[256];
Damien Milleraae6c611999-12-06 11:47:28 +1100299 int opcode, *intptr, value;
Damien Miller61f08ac2003-02-24 11:56:27 +1100300 size_t len;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100301 Forward fwd;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000302
Damien Millerc652cac2003-05-14 13:40:54 +1000303 /* Strip trailing whitespace */
Darren Tucker47eede72005-03-14 23:08:12 +1100304 for (len = strlen(line) - 1; len > 0; len--) {
Damien Millerc652cac2003-05-14 13:40:54 +1000305 if (strchr(WHITESPACE, line[len]) == NULL)
306 break;
307 line[len] = '\0';
308 }
309
Damien Millerbe484b52000-07-15 14:14:16 +1000310 s = line;
311 /* Get the keyword. (Each line is supposed to begin with a keyword). */
312 keyword = strdelim(&s);
313 /* Ignore leading whitespace. */
314 if (*keyword == '\0')
315 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000316 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100317 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000318
Damien Miller37023962000-07-11 17:31:38 +1000319 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000320
Damien Miller95def091999-11-25 00:26:21 +1100321 switch (opcode) {
322 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100323 /* don't panic, but count bad options */
324 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100325 /* NOTREACHED */
Damien Millerb78d5eb2003-05-16 11:39:04 +1000326 case oConnectTimeout:
327 intptr = &options->connection_timeout;
Damien Miller509b0102003-12-17 16:33:10 +1100328parse_time:
Damien Millerb78d5eb2003-05-16 11:39:04 +1000329 arg = strdelim(&s);
330 if (!arg || *arg == '\0')
331 fatal("%s line %d: missing time value.",
332 filename, linenum);
333 if ((value = convtime(arg)) == -1)
334 fatal("%s line %d: invalid time value.",
335 filename, linenum);
336 if (*intptr == -1)
337 *intptr = value;
338 break;
339
Damien Miller95def091999-11-25 00:26:21 +1100340 case oForwardAgent:
341 intptr = &options->forward_agent;
342parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000343 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000344 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100345 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
346 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000347 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100348 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000349 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100350 value = 0;
351 else
352 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
353 if (*activep && *intptr == -1)
354 *intptr = value;
355 break;
356
357 case oForwardX11:
358 intptr = &options->forward_x11;
359 goto parse_flag;
360
Darren Tucker0a118da2003-10-15 15:54:32 +1000361 case oForwardX11Trusted:
362 intptr = &options->forward_x11_trusted;
363 goto parse_flag;
364
Damien Miller95def091999-11-25 00:26:21 +1100365 case oGatewayPorts:
366 intptr = &options->gateway_ports;
367 goto parse_flag;
368
369 case oUsePrivilegedPort:
370 intptr = &options->use_privileged_port;
371 goto parse_flag;
372
Damien Miller95def091999-11-25 00:26:21 +1100373 case oPasswordAuthentication:
374 intptr = &options->password_authentication;
375 goto parse_flag;
376
Damien Miller874d77b2000-10-14 16:23:11 +1100377 case oKbdInteractiveAuthentication:
378 intptr = &options->kbd_interactive_authentication;
379 goto parse_flag;
380
381 case oKbdInteractiveDevices:
382 charptr = &options->kbd_interactive_devices;
383 goto parse_string;
384
Damien Miller0bc1bd82000-11-13 22:57:25 +1100385 case oPubkeyAuthentication:
386 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000387 goto parse_flag;
388
Damien Miller95def091999-11-25 00:26:21 +1100389 case oRSAAuthentication:
390 intptr = &options->rsa_authentication;
391 goto parse_flag;
392
393 case oRhostsRSAAuthentication:
394 intptr = &options->rhosts_rsa_authentication;
395 goto parse_flag;
396
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000397 case oHostbasedAuthentication:
398 intptr = &options->hostbased_authentication;
399 goto parse_flag;
400
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000401 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000402 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100403 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000404
Darren Tucker0efd1552003-08-26 11:49:55 +1000405 case oGssAuthentication:
406 intptr = &options->gss_authentication;
407 goto parse_flag;
408
409 case oGssDelegateCreds:
410 intptr = &options->gss_deleg_creds;
411 goto parse_flag;
412
Damien Miller95def091999-11-25 00:26:21 +1100413 case oBatchMode:
414 intptr = &options->batch_mode;
415 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000416
Damien Miller95def091999-11-25 00:26:21 +1100417 case oCheckHostIP:
418 intptr = &options->check_host_ip;
419 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000420
Damien Miller37876e92003-05-15 10:19:46 +1000421 case oVerifyHostKeyDNS:
422 intptr = &options->verify_host_key_dns;
Damien Miller150b5572003-11-17 21:19:29 +1100423 goto parse_yesnoask;
Damien Miller37876e92003-05-15 10:19:46 +1000424
Damien Miller95def091999-11-25 00:26:21 +1100425 case oStrictHostKeyChecking:
426 intptr = &options->strict_host_key_checking;
Damien Miller150b5572003-11-17 21:19:29 +1100427parse_yesnoask:
Damien Millerbe484b52000-07-15 14:14:16 +1000428 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000429 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000430 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100431 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100432 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000433 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100434 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000435 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100436 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000437 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100438 value = 2;
439 else
440 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
441 if (*activep && *intptr == -1)
442 *intptr = value;
443 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000444
Damien Miller95def091999-11-25 00:26:21 +1100445 case oCompression:
446 intptr = &options->compression;
447 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000448
Damien Miller12c150e2003-12-17 16:31:10 +1100449 case oTCPKeepAlive:
450 intptr = &options->tcp_keep_alive;
Damien Miller95def091999-11-25 00:26:21 +1100451 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000452
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000453 case oNoHostAuthenticationForLocalhost:
454 intptr = &options->no_host_authentication_for_localhost;
455 goto parse_flag;
456
Damien Miller95def091999-11-25 00:26:21 +1100457 case oNumberOfPasswordPrompts:
458 intptr = &options->number_of_password_prompts;
459 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000460
Damien Miller95def091999-11-25 00:26:21 +1100461 case oCompressionLevel:
462 intptr = &options->compression_level;
463 goto parse_int;
464
Damien Millera5539d22003-04-09 20:50:06 +1000465 case oRekeyLimit:
466 intptr = &options->rekey_limit;
467 arg = strdelim(&s);
468 if (!arg || *arg == '\0')
469 fatal("%.200s line %d: Missing argument.", filename, linenum);
470 if (arg[0] < '0' || arg[0] > '9')
471 fatal("%.200s line %d: Bad number.", filename, linenum);
472 value = strtol(arg, &endofnumber, 10);
473 if (arg == endofnumber)
474 fatal("%.200s line %d: Bad number.", filename, linenum);
475 switch (toupper(*endofnumber)) {
476 case 'K':
477 value *= 1<<10;
478 break;
479 case 'M':
480 value *= 1<<20;
481 break;
482 case 'G':
483 value *= 1<<30;
484 break;
485 }
486 if (*activep && *intptr == -1)
487 *intptr = value;
488 break;
489
Damien Miller95def091999-11-25 00:26:21 +1100490 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000491 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000492 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100493 fatal("%.200s line %d: Missing argument.", filename, linenum);
494 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100495 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000496 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100497 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100498 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100499 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000500 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000501 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100502 }
503 break;
504
Damien Millerd3a18572000-06-07 19:55:44 +1000505 case oXAuthLocation:
506 charptr=&options->xauth_location;
507 goto parse_string;
508
Damien Miller95def091999-11-25 00:26:21 +1100509 case oUser:
510 charptr = &options->user;
511parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000512 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000513 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100514 fatal("%.200s line %d: Missing argument.", filename, linenum);
515 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000516 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100517 break;
518
519 case oGlobalKnownHostsFile:
520 charptr = &options->system_hostfile;
521 goto parse_string;
522
523 case oUserKnownHostsFile:
524 charptr = &options->user_hostfile;
525 goto parse_string;
526
Damien Millereba71ba2000-04-29 23:57:08 +1000527 case oGlobalKnownHostsFile2:
528 charptr = &options->system_hostfile2;
529 goto parse_string;
530
531 case oUserKnownHostsFile2:
532 charptr = &options->user_hostfile2;
533 goto parse_string;
534
Damien Miller95def091999-11-25 00:26:21 +1100535 case oHostName:
536 charptr = &options->hostname;
537 goto parse_string;
538
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000539 case oHostKeyAlias:
540 charptr = &options->host_key_alias;
541 goto parse_string;
542
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000543 case oPreferredAuthentications:
544 charptr = &options->preferred_authentications;
545 goto parse_string;
546
Ben Lindstrome0f88042001-04-30 13:06:24 +0000547 case oBindAddress:
548 charptr = &options->bind_address;
549 goto parse_string;
550
Ben Lindstromae996bf2001-08-06 21:27:53 +0000551 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000552 charptr = &options->smartcard_device;
553 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000554
Damien Miller95def091999-11-25 00:26:21 +1100555 case oProxyCommand:
Darren Tuckera99c1b72003-06-28 12:40:12 +1000556 if (s == NULL)
557 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100558 charptr = &options->proxy_command;
Damien Miller61f08ac2003-02-24 11:56:27 +1100559 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +1100560 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +1100561 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +1100562 return 0;
563
564 case oPort:
565 intptr = &options->port;
566parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000567 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000568 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100569 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000570 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100571 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100572
573 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000574 value = strtol(arg, &endofnumber, 0);
575 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100576 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100577 if (*activep && *intptr == -1)
578 *intptr = value;
579 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000580
Damien Miller95def091999-11-25 00:26:21 +1100581 case oConnectionAttempts:
582 intptr = &options->connection_attempts;
583 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100584
Damien Miller95def091999-11-25 00:26:21 +1100585 case oCipher:
586 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000587 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000588 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000589 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000590 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100591 if (value == -1)
592 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100593 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100594 if (*activep && *intptr == -1)
595 *intptr = value;
596 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000597
Damien Miller78928792000-04-12 20:17:38 +1000598 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000599 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000600 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000601 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000602 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000603 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100604 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000605 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000606 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000607 break;
608
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000609 case oMacs:
610 arg = strdelim(&s);
611 if (!arg || *arg == '\0')
612 fatal("%.200s line %d: Missing argument.", filename, linenum);
613 if (!mac_valid(arg))
614 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100615 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000616 if (*activep && options->macs == NULL)
617 options->macs = xstrdup(arg);
618 break;
619
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000620 case oHostKeyAlgorithms:
621 arg = strdelim(&s);
622 if (!arg || *arg == '\0')
623 fatal("%.200s line %d: Missing argument.", filename, linenum);
624 if (!key_names_valid2(arg))
625 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100626 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000627 if (*activep && options->hostkeyalgorithms == NULL)
628 options->hostkeyalgorithms = xstrdup(arg);
629 break;
630
Damien Miller78928792000-04-12 20:17:38 +1000631 case oProtocol:
632 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000633 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000634 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000635 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000636 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000637 if (value == SSH_PROTO_UNKNOWN)
638 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100639 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000640 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
641 *intptr = value;
642 break;
643
Damien Miller95def091999-11-25 00:26:21 +1100644 case oLogLevel:
645 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000646 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000647 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100648 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000649 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100650 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100651 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100652 *intptr = (LogLevel) value;
653 break;
654
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000655 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100656 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000657 arg = strdelim(&s);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100658 if (arg == NULL || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000659 fatal("%.200s line %d: Missing port argument.",
660 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100661 arg2 = strdelim(&s);
662 if (arg2 == NULL || *arg2 == '\0')
663 fatal("%.200s line %d: Missing target argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000664 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100665
666 /* construct a string for parse_forward */
667 snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
668
669 if (parse_forward(&fwd, fwdarg) == 0)
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000670 fatal("%.200s line %d: Bad forwarding specification.",
671 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100672
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000673 if (*activep) {
674 if (opcode == oLocalForward)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100675 add_local_forward(options, &fwd);
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000676 else if (opcode == oRemoteForward)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100677 add_remote_forward(options, &fwd);
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000678 }
Damien Miller95def091999-11-25 00:26:21 +1100679 break;
680
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000681 case oDynamicForward:
682 arg = strdelim(&s);
683 if (!arg || *arg == '\0')
684 fatal("%.200s line %d: Missing port argument.",
685 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100686 memset(&fwd, '\0', sizeof(fwd));
687 fwd.connect_host = "socks";
688 fwd.listen_host = hpdelim(&arg);
689 if (fwd.listen_host == NULL ||
690 strlen(fwd.listen_host) >= NI_MAXHOST)
691 fatal("%.200s line %d: Bad forwarding specification.",
692 filename, linenum);
693 if (arg) {
694 fwd.listen_port = a2port(arg);
695 fwd.listen_host = cleanhostname(fwd.listen_host);
696 } else {
697 fwd.listen_port = a2port(fwd.listen_host);
Damien Miller43f6db62005-08-12 22:11:18 +1000698 fwd.listen_host = NULL;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100699 }
700 if (fwd.listen_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000701 fatal("%.200s line %d: Badly formatted port number.",
702 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000703 if (*activep)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100704 add_local_forward(options, &fwd);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000705 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000706
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000707 case oClearAllForwardings:
708 intptr = &options->clear_forwardings;
709 goto parse_flag;
710
Damien Miller95def091999-11-25 00:26:21 +1100711 case oHost:
712 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000713 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000714 if (match_pattern(host, arg)) {
715 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100716 *activep = 1;
717 break;
718 }
Damien Millerbe484b52000-07-15 14:14:16 +1000719 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100720 return 0;
721
722 case oEscapeChar:
723 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000724 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000725 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100726 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000727 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000728 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
729 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000730 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000731 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000732 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000733 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100734 else {
735 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100736 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100737 /* NOTREACHED */
738 value = 0; /* Avoid compiler warning. */
739 }
740 if (*activep && *intptr == -1)
741 *intptr = value;
742 break;
743
Damien Miller20a8f972003-05-18 20:50:30 +1000744 case oAddressFamily:
745 arg = strdelim(&s);
Damien Miller17b23d82005-05-26 12:11:56 +1000746 if (!arg || *arg == '\0')
747 fatal("%s line %d: missing address family.",
748 filename, linenum);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000749 intptr = &options->address_family;
Damien Miller20a8f972003-05-18 20:50:30 +1000750 if (strcasecmp(arg, "inet") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000751 value = AF_INET;
Damien Miller20a8f972003-05-18 20:50:30 +1000752 else if (strcasecmp(arg, "inet6") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000753 value = AF_INET6;
Damien Miller20a8f972003-05-18 20:50:30 +1000754 else if (strcasecmp(arg, "any") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000755 value = AF_UNSPEC;
Damien Miller20a8f972003-05-18 20:50:30 +1000756 else
757 fatal("Unsupported AddressFamily \"%s\"", arg);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000758 if (*activep && *intptr == -1)
759 *intptr = value;
Damien Miller20a8f972003-05-18 20:50:30 +1000760 break;
761
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000762 case oEnableSSHKeysign:
763 intptr = &options->enable_ssh_keysign;
764 goto parse_flag;
765
Damien Millerbd394c32004-03-08 23:12:36 +1100766 case oIdentitiesOnly:
767 intptr = &options->identities_only;
768 goto parse_flag;
769
Damien Miller509b0102003-12-17 16:33:10 +1100770 case oServerAliveInterval:
771 intptr = &options->server_alive_interval;
772 goto parse_time;
773
774 case oServerAliveCountMax:
775 intptr = &options->server_alive_count_max;
776 goto parse_int;
777
Darren Tucker46bc0752004-05-02 22:11:30 +1000778 case oSendEnv:
779 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
780 if (strchr(arg, '=') != NULL)
781 fatal("%s line %d: Invalid environment name.",
782 filename, linenum);
Damien Millerf8e7acc2005-03-05 11:22:50 +1100783 if (!*activep)
784 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +1000785 if (options->num_send_env >= MAX_SEND_ENV)
786 fatal("%s line %d: too many send env.",
787 filename, linenum);
788 options->send_env[options->num_send_env++] =
789 xstrdup(arg);
790 }
791 break;
792
Damien Miller0e220db2004-06-15 10:34:08 +1000793 case oControlPath:
794 charptr = &options->control_path;
795 goto parse_string;
796
797 case oControlMaster:
798 intptr = &options->control_master;
Damien Millerd14b1e72005-06-16 13:19:41 +1000799 arg = strdelim(&s);
800 if (!arg || *arg == '\0')
801 fatal("%.200s line %d: Missing ControlMaster argument.",
802 filename, linenum);
803 value = 0; /* To avoid compiler warning... */
804 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
805 value = SSHCTL_MASTER_YES;
806 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
807 value = SSHCTL_MASTER_NO;
808 else if (strcmp(arg, "auto") == 0)
809 value = SSHCTL_MASTER_AUTO;
810 else if (strcmp(arg, "ask") == 0)
811 value = SSHCTL_MASTER_ASK;
812 else if (strcmp(arg, "autoask") == 0)
813 value = SSHCTL_MASTER_AUTO_ASK;
814 else
815 fatal("%.200s line %d: Bad ControlMaster argument.",
816 filename, linenum);
817 if (*activep && *intptr == -1)
818 *intptr = value;
819 break;
Damien Miller0e220db2004-06-15 10:34:08 +1000820
Damien Millere1776152005-03-01 21:47:37 +1100821 case oHashKnownHosts:
822 intptr = &options->hash_known_hosts;
823 goto parse_flag;
824
Ben Lindstrom4daea862002-06-09 20:04:02 +0000825 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000826 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +0000827 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000828 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +0000829
Damien Millerf9b3feb2003-05-16 11:38:32 +1000830 case oUnsupported:
831 error("%s line %d: Unsupported option \"%s\"",
832 filename, linenum, keyword);
833 return 0;
834
Damien Miller95def091999-11-25 00:26:21 +1100835 default:
836 fatal("process_config_line: Unimplemented opcode %d", opcode);
837 }
838
839 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000840 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000841 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller0dc1bef2005-07-17 17:22:45 +1000842 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000843 }
Damien Miller95def091999-11-25 00:26:21 +1100844 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000845}
846
847
Damien Miller5428f641999-11-25 11:54:57 +1100848/*
849 * Reads the config file and modifies the options accordingly. Options
850 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000851 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100852 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000853
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000854int
Darren Tuckerfc959702004-07-17 16:12:08 +1000855read_config_file(const char *filename, const char *host, Options *options,
Damien Miller57a44762004-04-20 20:11:57 +1000856 int checkperm)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000857{
Damien Miller95def091999-11-25 00:26:21 +1100858 FILE *f;
859 char line[1024];
860 int active, linenum;
861 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000862
Damien Miller95def091999-11-25 00:26:21 +1100863 /* Open the file. */
Damien Miller57a44762004-04-20 20:11:57 +1000864 if ((f = fopen(filename, "r")) == NULL)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000865 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000866
Damien Miller57a44762004-04-20 20:11:57 +1000867 if (checkperm) {
868 struct stat sb;
Darren Tuckerfc959702004-07-17 16:12:08 +1000869
Damien Miller33793852004-06-15 10:27:55 +1000870 if (fstat(fileno(f), &sb) == -1)
Damien Miller57a44762004-04-20 20:11:57 +1000871 fatal("fstat %s: %s", filename, strerror(errno));
Damien Miller57a44762004-04-20 20:11:57 +1000872 if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
Damien Miller33793852004-06-15 10:27:55 +1000873 (sb.st_mode & 022) != 0))
Damien Miller57a44762004-04-20 20:11:57 +1000874 fatal("Bad owner or permissions on %s", filename);
Damien Miller57a44762004-04-20 20:11:57 +1000875 }
876
Damien Miller95def091999-11-25 00:26:21 +1100877 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000878
Damien Miller5428f641999-11-25 11:54:57 +1100879 /*
880 * Mark that we are now processing the options. This flag is turned
881 * on/off by Host specifications.
882 */
Damien Miller95def091999-11-25 00:26:21 +1100883 active = 1;
884 linenum = 0;
885 while (fgets(line, sizeof(line), f)) {
886 /* Update line number counter. */
887 linenum++;
888 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
889 bad_options++;
890 }
891 fclose(f);
892 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000893 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100894 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000895 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000896}
897
Damien Miller5428f641999-11-25 11:54:57 +1100898/*
899 * Initializes options to special values that indicate that they have not yet
900 * been set. Read_config_file will only set options with this value. Options
901 * are processed in the following order: command line, user config file,
902 * system config file. Last, fill_default_options is called.
903 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000904
Damien Miller4af51302000-04-16 11:18:38 +1000905void
Damien Miller95def091999-11-25 00:26:21 +1100906initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000907{
Damien Miller95def091999-11-25 00:26:21 +1100908 memset(options, 'X', sizeof(*options));
909 options->forward_agent = -1;
910 options->forward_x11 = -1;
Darren Tucker0a118da2003-10-15 15:54:32 +1000911 options->forward_x11_trusted = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000912 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100913 options->gateway_ports = -1;
914 options->use_privileged_port = -1;
Damien Miller95def091999-11-25 00:26:21 +1100915 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100916 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000917 options->challenge_response_authentication = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000918 options->gss_authentication = -1;
919 options->gss_deleg_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100920 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100921 options->kbd_interactive_authentication = -1;
922 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100923 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000924 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100925 options->batch_mode = -1;
926 options->check_host_ip = -1;
927 options->strict_host_key_checking = -1;
928 options->compression = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100929 options->tcp_keep_alive = -1;
Damien Miller95def091999-11-25 00:26:21 +1100930 options->compression_level = -1;
931 options->port = -1;
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000932 options->address_family = -1;
Damien Miller95def091999-11-25 00:26:21 +1100933 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000934 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +1100935 options->number_of_password_prompts = -1;
936 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000937 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000938 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000939 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000940 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100941 options->num_identity_files = 0;
942 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000943 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100944 options->proxy_command = NULL;
945 options->user = NULL;
946 options->escape_char = -1;
947 options->system_hostfile = NULL;
948 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000949 options->system_hostfile2 = NULL;
950 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100951 options->num_local_forwards = 0;
952 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000953 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100954 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000955 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000956 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000957 options->smartcard_device = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000958 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000959 options->no_host_authentication_for_localhost = - 1;
Damien Millerbd394c32004-03-08 23:12:36 +1100960 options->identities_only = - 1;
Damien Millera5539d22003-04-09 20:50:06 +1000961 options->rekey_limit = - 1;
Damien Miller37876e92003-05-15 10:19:46 +1000962 options->verify_host_key_dns = -1;
Damien Miller509b0102003-12-17 16:33:10 +1100963 options->server_alive_interval = -1;
964 options->server_alive_count_max = -1;
Darren Tucker46bc0752004-05-02 22:11:30 +1000965 options->num_send_env = 0;
Damien Miller0e220db2004-06-15 10:34:08 +1000966 options->control_path = NULL;
967 options->control_master = -1;
Damien Millere1776152005-03-01 21:47:37 +1100968 options->hash_known_hosts = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000969}
970
Damien Miller5428f641999-11-25 11:54:57 +1100971/*
972 * Called after processing other sources of option data, this fills those
973 * options for which no value has been specified with their default values.
974 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000975
Damien Miller4af51302000-04-16 11:18:38 +1000976void
Damien Miller95def091999-11-25 00:26:21 +1100977fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000978{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000979 int len;
980
Damien Miller95def091999-11-25 00:26:21 +1100981 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000982 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100983 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100984 options->forward_x11 = 0;
Darren Tucker0a118da2003-10-15 15:54:32 +1000985 if (options->forward_x11_trusted == -1)
986 options->forward_x11_trusted = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000987 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000988 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100989 if (options->gateway_ports == -1)
990 options->gateway_ports = 0;
991 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000992 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100993 if (options->rsa_authentication == -1)
994 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100995 if (options->pubkey_authentication == -1)
996 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000997 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000998 options->challenge_response_authentication = 1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000999 if (options->gss_authentication == -1)
Darren Tuckera044f472003-10-15 15:52:03 +10001000 options->gss_authentication = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +10001001 if (options->gss_deleg_creds == -1)
1002 options->gss_deleg_creds = 0;
Damien Miller95def091999-11-25 00:26:21 +11001003 if (options->password_authentication == -1)
1004 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +11001005 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +00001006 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +11001007 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +00001008 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +00001009 if (options->hostbased_authentication == -1)
1010 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +11001011 if (options->batch_mode == -1)
1012 options->batch_mode = 0;
1013 if (options->check_host_ip == -1)
1014 options->check_host_ip = 1;
1015 if (options->strict_host_key_checking == -1)
1016 options->strict_host_key_checking = 2; /* 2 is default */
1017 if (options->compression == -1)
1018 options->compression = 0;
Damien Miller12c150e2003-12-17 16:31:10 +11001019 if (options->tcp_keep_alive == -1)
1020 options->tcp_keep_alive = 1;
Damien Miller95def091999-11-25 00:26:21 +11001021 if (options->compression_level == -1)
1022 options->compression_level = 6;
1023 if (options->port == -1)
1024 options->port = 0; /* Filled in ssh_connect. */
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001025 if (options->address_family == -1)
1026 options->address_family = AF_UNSPEC;
Damien Miller95def091999-11-25 00:26:21 +11001027 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +00001028 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +11001029 if (options->number_of_password_prompts == -1)
1030 options->number_of_password_prompts = 3;
1031 /* Selected in ssh_login(). */
1032 if (options->cipher == -1)
1033 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +10001034 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001035 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001036 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +10001037 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +00001038 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +11001039 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +11001040 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +00001041 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001042 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +00001043 xmalloc(len);
1044 snprintf(options->identity_files[options->num_identity_files++],
1045 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +11001046 }
1047 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +00001048 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
1049 options->identity_files[options->num_identity_files] =
1050 xmalloc(len);
1051 snprintf(options->identity_files[options->num_identity_files++],
1052 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
1053
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +00001054 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001055 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +00001056 xmalloc(len);
1057 snprintf(options->identity_files[options->num_identity_files++],
1058 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +11001059 }
Damien Millereba71ba2000-04-29 23:57:08 +10001060 }
Damien Miller95def091999-11-25 00:26:21 +11001061 if (options->escape_char == -1)
1062 options->escape_char = '~';
1063 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +00001064 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +11001065 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +00001066 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +10001067 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +00001068 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +10001069 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +00001070 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +11001071 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +00001072 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001073 if (options->clear_forwardings == 1)
1074 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00001075 if (options->no_host_authentication_for_localhost == - 1)
1076 options->no_host_authentication_for_localhost = 0;
Damien Millerbd394c32004-03-08 23:12:36 +11001077 if (options->identities_only == -1)
1078 options->identities_only = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001079 if (options->enable_ssh_keysign == -1)
1080 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +10001081 if (options->rekey_limit == -1)
1082 options->rekey_limit = 0;
Damien Miller37876e92003-05-15 10:19:46 +10001083 if (options->verify_host_key_dns == -1)
1084 options->verify_host_key_dns = 0;
Damien Miller509b0102003-12-17 16:33:10 +11001085 if (options->server_alive_interval == -1)
1086 options->server_alive_interval = 0;
1087 if (options->server_alive_count_max == -1)
1088 options->server_alive_count_max = 3;
Damien Miller0e220db2004-06-15 10:34:08 +10001089 if (options->control_master == -1)
1090 options->control_master = 0;
Damien Millere1776152005-03-01 21:47:37 +11001091 if (options->hash_known_hosts == -1)
1092 options->hash_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +11001093 /* options->proxy_command should not be set by default */
1094 /* options->user will be set in the main program if appropriate */
1095 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001096 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001097 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001098}
Damien Millerf91ee4c2005-03-01 21:24:33 +11001099
1100/*
1101 * parse_forward
1102 * parses a string containing a port forwarding specification of the form:
1103 * [listenhost:]listenport:connecthost:connectport
1104 * returns number of arguments parsed or zero on error
1105 */
1106int
1107parse_forward(Forward *fwd, const char *fwdspec)
1108{
1109 int i;
1110 char *p, *cp, *fwdarg[4];
1111
1112 memset(fwd, '\0', sizeof(*fwd));
1113
1114 cp = p = xstrdup(fwdspec);
1115
1116 /* skip leading spaces */
1117 while (*cp && isspace(*cp))
1118 cp++;
1119
1120 for (i = 0; i < 4; ++i)
1121 if ((fwdarg[i] = hpdelim(&cp)) == NULL)
1122 break;
1123
1124 /* Check for trailing garbage in 4-arg case*/
1125 if (cp != NULL)
1126 i = 0; /* failure */
1127
1128 switch (i) {
1129 case 3:
1130 fwd->listen_host = NULL;
1131 fwd->listen_port = a2port(fwdarg[0]);
1132 fwd->connect_host = xstrdup(cleanhostname(fwdarg[1]));
1133 fwd->connect_port = a2port(fwdarg[2]);
1134 break;
1135
1136 case 4:
1137 fwd->listen_host = xstrdup(cleanhostname(fwdarg[0]));
1138 fwd->listen_port = a2port(fwdarg[1]);
1139 fwd->connect_host = xstrdup(cleanhostname(fwdarg[2]));
1140 fwd->connect_port = a2port(fwdarg[3]);
1141 break;
1142 default:
1143 i = 0; /* failure */
1144 }
1145
1146 xfree(p);
1147
1148 if (fwd->listen_port == 0 && fwd->connect_port == 0)
1149 goto fail_free;
1150
1151 if (fwd->connect_host != NULL &&
1152 strlen(fwd->connect_host) >= NI_MAXHOST)
1153 goto fail_free;
1154
1155 return (i);
1156
1157 fail_free:
1158 if (fwd->connect_host != NULL)
1159 xfree(fwd->connect_host);
1160 if (fwd->listen_host != NULL)
1161 xfree(fwd->listen_host);
1162 return (0);
1163}