blob: a1042708612c7a40fd92cbe07b40098876617d0e [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 Millera5539d22003-04-09 20:50:06 +100015RCSID("$OpenBSD: readconf.c,v 1.105 2003/04/02 09:48:07 markus 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
60 RhostsAuthentication no
61 PasswordAuthentication no
62
63 Host puukko.hut.fi
64 User t35124p
65 ProxyCommand ssh-proxy %h %p
66
67 Host *.fr
Ben Lindstrom4daea862002-06-09 20:04:02 +000068 PublicKeyAuthentication no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100069
70 Host *.su
71 Cipher none
72 PasswordAuthentication no
73
74 # Defaults for various options
75 Host *
76 ForwardAgent no
Damien Miller0bc1bd82000-11-13 22:57:25 +110077 ForwardX11 no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100078 RhostsAuthentication yes
79 PasswordAuthentication yes
80 RSAAuthentication yes
81 RhostsRSAAuthentication yes
Damien Millerd4a8b7e1999-10-27 13:42:43 +100082 StrictHostKeyChecking yes
83 KeepAlives no
84 IdentityFile ~/.ssh/identity
85 Port 22
86 EscapeChar ~
87
88*/
89
90/* Keyword tokens. */
91
Damien Miller95def091999-11-25 00:26:21 +110092typedef enum {
93 oBadOption,
94 oForwardAgent, oForwardX11, oGatewayPorts, oRhostsAuthentication,
Ben Lindstromcb72e4f2002-06-21 00:41:51 +000095 oPasswordAuthentication, oRSAAuthentication,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000096 oChallengeResponseAuthentication, oXAuthLocation,
Ben Lindstromec95ed92001-07-04 04:21:14 +000097#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110098 oKerberosAuthentication,
Ben Lindstromec95ed92001-07-04 04:21:14 +000099#endif
100#if defined(AFS) || defined(KRB5)
101 oKerberosTgtPassing,
102#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000103#ifdef AFS
Ben Lindstromec95ed92001-07-04 04:21:14 +0000104 oAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000105#endif
Damien Miller95def091999-11-25 00:26:21 +1100106 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
107 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
108 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
109 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000110 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000111 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100112 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000113 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000114 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000115 oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000116 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
Damien Millera5539d22003-04-09 20:50:06 +1000117 oEnableSSHKeysign, oRekeyLimit,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000118 oDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000119} OpCodes;
120
121/* Textual representations of the tokens. */
122
Damien Miller95def091999-11-25 00:26:21 +1100123static struct {
124 const char *name;
125 OpCodes opcode;
126} keywords[] = {
127 { "forwardagent", oForwardAgent },
128 { "forwardx11", oForwardX11 },
Damien Millerd3a18572000-06-07 19:55:44 +1000129 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100130 { "gatewayports", oGatewayPorts },
131 { "useprivilegedport", oUsePrivilegedPort },
132 { "rhostsauthentication", oRhostsAuthentication },
133 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100134 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
135 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100136 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100137 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000138 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000139 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000140 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000141 { "challengeresponseauthentication", oChallengeResponseAuthentication },
142 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
143 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000144#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100145 { "kerberosauthentication", oKerberosAuthentication },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000146#endif
147#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100148 { "kerberostgtpassing", oKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000149#endif
150#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100151 { "afstokenpassing", oAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000152#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000153 { "fallbacktorsh", oDeprecated },
154 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100155 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100156 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100157 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000158 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100159 { "proxycommand", oProxyCommand },
160 { "port", oPort },
161 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000162 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000163 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000164 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100165 { "remoteforward", oRemoteForward },
166 { "localforward", oLocalForward },
167 { "user", oUser },
168 { "host", oHost },
169 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100170 { "globalknownhostsfile", oGlobalKnownHostsFile },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000171 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
Damien Millereba71ba2000-04-29 23:57:08 +1000172 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000173 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100174 { "connectionattempts", oConnectionAttempts },
175 { "batchmode", oBatchMode },
176 { "checkhostip", oCheckHostIP },
177 { "stricthostkeychecking", oStrictHostKeyChecking },
178 { "compression", oCompression },
179 { "compressionlevel", oCompressionLevel },
180 { "keepalive", oKeepAlives },
181 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100182 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000183 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000184 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000185 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000186 { "bindaddress", oBindAddress },
Ben Lindstromae996bf2001-08-06 21:27:53 +0000187 { "smartcarddevice", oSmartcardDevice },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100188 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000189 { "enablesshkeysign", oEnableSSHKeysign },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100190 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000191 { "rekeylimit", oRekeyLimit },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000192 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100193};
194
Damien Miller5428f641999-11-25 11:54:57 +1100195/*
196 * Adds a local TCP/IP port forward to options. Never returns if there is an
197 * error.
198 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000199
Damien Miller4af51302000-04-16 11:18:38 +1000200void
Damien Milleraae6c611999-12-06 11:47:28 +1100201add_local_forward(Options *options, u_short port, const char *host,
202 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000203{
Damien Miller95def091999-11-25 00:26:21 +1100204 Forward *fwd;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000205#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100206 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100207 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000208 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100209#endif
Damien Miller95def091999-11-25 00:26:21 +1100210 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
211 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
212 fwd = &options->local_forwards[options->num_local_forwards++];
213 fwd->port = port;
214 fwd->host = xstrdup(host);
215 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000216}
217
Damien Miller5428f641999-11-25 11:54:57 +1100218/*
219 * Adds a remote TCP/IP port forward to options. Never returns if there is
220 * an error.
221 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000222
Damien Miller4af51302000-04-16 11:18:38 +1000223void
Damien Milleraae6c611999-12-06 11:47:28 +1100224add_remote_forward(Options *options, u_short port, const char *host,
225 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000226{
Damien Miller95def091999-11-25 00:26:21 +1100227 Forward *fwd;
228 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
229 fatal("Too many remote forwards (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100230 SSH_MAX_FORWARDS_PER_DIRECTION);
Damien Miller95def091999-11-25 00:26:21 +1100231 fwd = &options->remote_forwards[options->num_remote_forwards++];
232 fwd->port = port;
233 fwd->host = xstrdup(host);
234 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000235}
236
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000237static void
238clear_forwardings(Options *options)
239{
240 int i;
241
242 for (i = 0; i < options->num_local_forwards; i++)
243 xfree(options->local_forwards[i].host);
244 options->num_local_forwards = 0;
245 for (i = 0; i < options->num_remote_forwards; i++)
246 xfree(options->remote_forwards[i].host);
247 options->num_remote_forwards = 0;
248}
249
Damien Miller5428f641999-11-25 11:54:57 +1100250/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000251 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100252 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000253
Damien Miller4af51302000-04-16 11:18:38 +1000254static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100255parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000256{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000257 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000258
Damien Miller95def091999-11-25 00:26:21 +1100259 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100260 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100261 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000262
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000263 error("%s: line %d: Bad configuration option: %s",
264 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100265 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000266}
267
Damien Miller5428f641999-11-25 11:54:57 +1100268/*
269 * Processes a single option line as used in the configuration files. This
270 * only sets those values that have not already been set.
271 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100272#define WHITESPACE " \t\r\n"
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000273
Damien Miller2ccf6611999-11-15 15:25:10 +1100274int
275process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100276 char *line, const char *filename, int linenum,
277 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000278{
Damien Miller61f08ac2003-02-24 11:56:27 +1100279 char buf[256], *s, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100280 int opcode, *intptr, value;
Damien Miller61f08ac2003-02-24 11:56:27 +1100281 size_t len;
Damien Milleraae6c611999-12-06 11:47:28 +1100282 u_short fwd_port, fwd_host_port;
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000283 char sfwd_host_port[6];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000284
Damien Millerbe484b52000-07-15 14:14:16 +1000285 s = line;
286 /* Get the keyword. (Each line is supposed to begin with a keyword). */
287 keyword = strdelim(&s);
288 /* Ignore leading whitespace. */
289 if (*keyword == '\0')
290 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000291 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100292 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000293
Damien Miller37023962000-07-11 17:31:38 +1000294 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000295
Damien Miller95def091999-11-25 00:26:21 +1100296 switch (opcode) {
297 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100298 /* don't panic, but count bad options */
299 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100300 /* NOTREACHED */
301 case oForwardAgent:
302 intptr = &options->forward_agent;
303parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000304 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000305 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100306 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
307 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000308 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100309 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000310 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100311 value = 0;
312 else
313 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
314 if (*activep && *intptr == -1)
315 *intptr = value;
316 break;
317
318 case oForwardX11:
319 intptr = &options->forward_x11;
320 goto parse_flag;
321
322 case oGatewayPorts:
323 intptr = &options->gateway_ports;
324 goto parse_flag;
325
326 case oUsePrivilegedPort:
327 intptr = &options->use_privileged_port;
328 goto parse_flag;
329
330 case oRhostsAuthentication:
331 intptr = &options->rhosts_authentication;
332 goto parse_flag;
333
334 case oPasswordAuthentication:
335 intptr = &options->password_authentication;
336 goto parse_flag;
337
Damien Miller874d77b2000-10-14 16:23:11 +1100338 case oKbdInteractiveAuthentication:
339 intptr = &options->kbd_interactive_authentication;
340 goto parse_flag;
341
342 case oKbdInteractiveDevices:
343 charptr = &options->kbd_interactive_devices;
344 goto parse_string;
345
Damien Miller0bc1bd82000-11-13 22:57:25 +1100346 case oPubkeyAuthentication:
347 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000348 goto parse_flag;
349
Damien Miller95def091999-11-25 00:26:21 +1100350 case oRSAAuthentication:
351 intptr = &options->rsa_authentication;
352 goto parse_flag;
353
354 case oRhostsRSAAuthentication:
355 intptr = &options->rhosts_rsa_authentication;
356 goto parse_flag;
357
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000358 case oHostbasedAuthentication:
359 intptr = &options->hostbased_authentication;
360 goto parse_flag;
361
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000362 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000363 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100364 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000365#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100366 case oKerberosAuthentication:
367 intptr = &options->kerberos_authentication;
368 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000369#endif
370#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100371 case oKerberosTgtPassing:
372 intptr = &options->kerberos_tgt_passing;
373 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000374#endif
375#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100376 case oAFSTokenPassing:
377 intptr = &options->afs_token_passing;
378 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000379#endif
Damien Miller95def091999-11-25 00:26:21 +1100380 case oBatchMode:
381 intptr = &options->batch_mode;
382 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000383
Damien Miller95def091999-11-25 00:26:21 +1100384 case oCheckHostIP:
385 intptr = &options->check_host_ip;
386 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000387
Damien Miller95def091999-11-25 00:26:21 +1100388 case oStrictHostKeyChecking:
389 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000390 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000391 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000392 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100393 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100394 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000395 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100396 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000397 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100398 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000399 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100400 value = 2;
401 else
402 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
403 if (*activep && *intptr == -1)
404 *intptr = value;
405 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000406
Damien Miller95def091999-11-25 00:26:21 +1100407 case oCompression:
408 intptr = &options->compression;
409 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000410
Damien Miller95def091999-11-25 00:26:21 +1100411 case oKeepAlives:
412 intptr = &options->keepalives;
413 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000414
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000415 case oNoHostAuthenticationForLocalhost:
416 intptr = &options->no_host_authentication_for_localhost;
417 goto parse_flag;
418
Damien Miller95def091999-11-25 00:26:21 +1100419 case oNumberOfPasswordPrompts:
420 intptr = &options->number_of_password_prompts;
421 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000422
Damien Miller95def091999-11-25 00:26:21 +1100423 case oCompressionLevel:
424 intptr = &options->compression_level;
425 goto parse_int;
426
Damien Millera5539d22003-04-09 20:50:06 +1000427 case oRekeyLimit:
428 intptr = &options->rekey_limit;
429 arg = strdelim(&s);
430 if (!arg || *arg == '\0')
431 fatal("%.200s line %d: Missing argument.", filename, linenum);
432 if (arg[0] < '0' || arg[0] > '9')
433 fatal("%.200s line %d: Bad number.", filename, linenum);
434 value = strtol(arg, &endofnumber, 10);
435 if (arg == endofnumber)
436 fatal("%.200s line %d: Bad number.", filename, linenum);
437 switch (toupper(*endofnumber)) {
438 case 'K':
439 value *= 1<<10;
440 break;
441 case 'M':
442 value *= 1<<20;
443 break;
444 case 'G':
445 value *= 1<<30;
446 break;
447 }
448 if (*activep && *intptr == -1)
449 *intptr = value;
450 break;
451
Damien Miller95def091999-11-25 00:26:21 +1100452 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000453 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000454 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100455 fatal("%.200s line %d: Missing argument.", filename, linenum);
456 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100457 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000458 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100459 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100460 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100461 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000462 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000463 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100464 }
465 break;
466
Damien Millerd3a18572000-06-07 19:55:44 +1000467 case oXAuthLocation:
468 charptr=&options->xauth_location;
469 goto parse_string;
470
Damien Miller95def091999-11-25 00:26:21 +1100471 case oUser:
472 charptr = &options->user;
473parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000474 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000475 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100476 fatal("%.200s line %d: Missing argument.", filename, linenum);
477 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000478 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100479 break;
480
481 case oGlobalKnownHostsFile:
482 charptr = &options->system_hostfile;
483 goto parse_string;
484
485 case oUserKnownHostsFile:
486 charptr = &options->user_hostfile;
487 goto parse_string;
488
Damien Millereba71ba2000-04-29 23:57:08 +1000489 case oGlobalKnownHostsFile2:
490 charptr = &options->system_hostfile2;
491 goto parse_string;
492
493 case oUserKnownHostsFile2:
494 charptr = &options->user_hostfile2;
495 goto parse_string;
496
Damien Miller95def091999-11-25 00:26:21 +1100497 case oHostName:
498 charptr = &options->hostname;
499 goto parse_string;
500
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000501 case oHostKeyAlias:
502 charptr = &options->host_key_alias;
503 goto parse_string;
504
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000505 case oPreferredAuthentications:
506 charptr = &options->preferred_authentications;
507 goto parse_string;
508
Ben Lindstrome0f88042001-04-30 13:06:24 +0000509 case oBindAddress:
510 charptr = &options->bind_address;
511 goto parse_string;
512
Ben Lindstromae996bf2001-08-06 21:27:53 +0000513 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000514 charptr = &options->smartcard_device;
515 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000516
Damien Miller95def091999-11-25 00:26:21 +1100517 case oProxyCommand:
518 charptr = &options->proxy_command;
Damien Miller61f08ac2003-02-24 11:56:27 +1100519 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +1100520 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +1100521 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +1100522 return 0;
523
524 case oPort:
525 intptr = &options->port;
526parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000527 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000528 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100529 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000530 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100531 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100532
533 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000534 value = strtol(arg, &endofnumber, 0);
535 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100536 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100537 if (*activep && *intptr == -1)
538 *intptr = value;
539 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000540
Damien Miller95def091999-11-25 00:26:21 +1100541 case oConnectionAttempts:
542 intptr = &options->connection_attempts;
543 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100544
Damien Miller95def091999-11-25 00:26:21 +1100545 case oCipher:
546 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000547 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000548 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000549 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000550 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100551 if (value == -1)
552 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100553 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100554 if (*activep && *intptr == -1)
555 *intptr = value;
556 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000557
Damien Miller78928792000-04-12 20:17:38 +1000558 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000559 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000560 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000561 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000562 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000563 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100564 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000565 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000566 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000567 break;
568
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000569 case oMacs:
570 arg = strdelim(&s);
571 if (!arg || *arg == '\0')
572 fatal("%.200s line %d: Missing argument.", filename, linenum);
573 if (!mac_valid(arg))
574 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100575 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000576 if (*activep && options->macs == NULL)
577 options->macs = xstrdup(arg);
578 break;
579
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000580 case oHostKeyAlgorithms:
581 arg = strdelim(&s);
582 if (!arg || *arg == '\0')
583 fatal("%.200s line %d: Missing argument.", filename, linenum);
584 if (!key_names_valid2(arg))
585 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100586 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000587 if (*activep && options->hostkeyalgorithms == NULL)
588 options->hostkeyalgorithms = xstrdup(arg);
589 break;
590
Damien Miller78928792000-04-12 20:17:38 +1000591 case oProtocol:
592 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000593 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000594 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000595 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000596 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000597 if (value == SSH_PROTO_UNKNOWN)
598 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100599 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000600 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
601 *intptr = value;
602 break;
603
Damien Miller95def091999-11-25 00:26:21 +1100604 case oLogLevel:
605 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000606 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000607 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100608 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000609 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100610 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100611 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100612 *intptr = (LogLevel) value;
613 break;
614
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000615 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100616 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000617 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000618 if (!arg || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000619 fatal("%.200s line %d: Missing port argument.",
620 filename, linenum);
621 if ((fwd_port = a2port(arg)) == 0)
622 fatal("%.200s line %d: Bad listen port.",
623 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000624 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000625 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100626 fatal("%.200s line %d: Missing second argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000627 filename, linenum);
628 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
629 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
630 fatal("%.200s line %d: Bad forwarding specification.",
631 filename, linenum);
632 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
633 fatal("%.200s line %d: Bad forwarding port.",
634 filename, linenum);
635 if (*activep) {
636 if (opcode == oLocalForward)
637 add_local_forward(options, fwd_port, buf,
638 fwd_host_port);
639 else if (opcode == oRemoteForward)
640 add_remote_forward(options, fwd_port, buf,
641 fwd_host_port);
642 }
Damien Miller95def091999-11-25 00:26:21 +1100643 break;
644
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000645 case oDynamicForward:
646 arg = strdelim(&s);
647 if (!arg || *arg == '\0')
648 fatal("%.200s line %d: Missing port argument.",
649 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000650 fwd_port = a2port(arg);
651 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000652 fatal("%.200s line %d: Badly formatted port number.",
653 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000654 if (*activep)
655 add_local_forward(options, fwd_port, "socks4", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000656 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000657
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000658 case oClearAllForwardings:
659 intptr = &options->clear_forwardings;
660 goto parse_flag;
661
Damien Miller95def091999-11-25 00:26:21 +1100662 case oHost:
663 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000664 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000665 if (match_pattern(host, arg)) {
666 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100667 *activep = 1;
668 break;
669 }
Damien Millerbe484b52000-07-15 14:14:16 +1000670 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100671 return 0;
672
673 case oEscapeChar:
674 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000675 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000676 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100677 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000678 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000679 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
680 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000681 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000682 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000683 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000684 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100685 else {
686 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100687 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100688 /* NOTREACHED */
689 value = 0; /* Avoid compiler warning. */
690 }
691 if (*activep && *intptr == -1)
692 *intptr = value;
693 break;
694
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000695 case oEnableSSHKeysign:
696 intptr = &options->enable_ssh_keysign;
697 goto parse_flag;
698
Ben Lindstrom4daea862002-06-09 20:04:02 +0000699 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000700 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +0000701 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000702 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +0000703
Damien Miller95def091999-11-25 00:26:21 +1100704 default:
705 fatal("process_config_line: Unimplemented opcode %d", opcode);
706 }
707
708 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000709 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000710 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100711 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000712 }
Damien Miller95def091999-11-25 00:26:21 +1100713 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000714}
715
716
Damien Miller5428f641999-11-25 11:54:57 +1100717/*
718 * Reads the config file and modifies the options accordingly. Options
719 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000720 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100721 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000722
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000723int
Damien Miller95def091999-11-25 00:26:21 +1100724read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000725{
Damien Miller95def091999-11-25 00:26:21 +1100726 FILE *f;
727 char line[1024];
728 int active, linenum;
729 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000730
Damien Miller95def091999-11-25 00:26:21 +1100731 /* Open the file. */
732 f = fopen(filename, "r");
733 if (!f)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000734 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000735
Damien Miller95def091999-11-25 00:26:21 +1100736 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000737
Damien Miller5428f641999-11-25 11:54:57 +1100738 /*
739 * Mark that we are now processing the options. This flag is turned
740 * on/off by Host specifications.
741 */
Damien Miller95def091999-11-25 00:26:21 +1100742 active = 1;
743 linenum = 0;
744 while (fgets(line, sizeof(line), f)) {
745 /* Update line number counter. */
746 linenum++;
747 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
748 bad_options++;
749 }
750 fclose(f);
751 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000752 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100753 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000754 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000755}
756
Damien Miller5428f641999-11-25 11:54:57 +1100757/*
758 * Initializes options to special values that indicate that they have not yet
759 * been set. Read_config_file will only set options with this value. Options
760 * are processed in the following order: command line, user config file,
761 * system config file. Last, fill_default_options is called.
762 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000763
Damien Miller4af51302000-04-16 11:18:38 +1000764void
Damien Miller95def091999-11-25 00:26:21 +1100765initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000766{
Damien Miller95def091999-11-25 00:26:21 +1100767 memset(options, 'X', sizeof(*options));
768 options->forward_agent = -1;
769 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000770 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100771 options->gateway_ports = -1;
772 options->use_privileged_port = -1;
773 options->rhosts_authentication = -1;
774 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100775 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000776 options->challenge_response_authentication = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000777#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100778 options->kerberos_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000779#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000780#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100781 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000782#endif
783#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100784 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000785#endif
Damien Miller95def091999-11-25 00:26:21 +1100786 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100787 options->kbd_interactive_authentication = -1;
788 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100789 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000790 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100791 options->batch_mode = -1;
792 options->check_host_ip = -1;
793 options->strict_host_key_checking = -1;
794 options->compression = -1;
795 options->keepalives = -1;
796 options->compression_level = -1;
797 options->port = -1;
798 options->connection_attempts = -1;
799 options->number_of_password_prompts = -1;
800 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000801 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000802 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000803 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000804 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100805 options->num_identity_files = 0;
806 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000807 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100808 options->proxy_command = NULL;
809 options->user = NULL;
810 options->escape_char = -1;
811 options->system_hostfile = NULL;
812 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000813 options->system_hostfile2 = NULL;
814 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100815 options->num_local_forwards = 0;
816 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000817 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100818 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000819 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000820 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000821 options->smartcard_device = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000822 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000823 options->no_host_authentication_for_localhost = - 1;
Damien Millera5539d22003-04-09 20:50:06 +1000824 options->rekey_limit = - 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000825}
826
Damien Miller5428f641999-11-25 11:54:57 +1100827/*
828 * Called after processing other sources of option data, this fills those
829 * options for which no value has been specified with their default values.
830 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000831
Damien Miller4af51302000-04-16 11:18:38 +1000832void
Damien Miller95def091999-11-25 00:26:21 +1100833fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000834{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000835 int len;
836
Damien Miller95def091999-11-25 00:26:21 +1100837 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000838 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100839 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100840 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000841 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000842 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100843 if (options->gateway_ports == -1)
844 options->gateway_ports = 0;
845 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000846 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100847 if (options->rhosts_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000848 options->rhosts_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100849 if (options->rsa_authentication == -1)
850 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100851 if (options->pubkey_authentication == -1)
852 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000853 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000854 options->challenge_response_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000855#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100856 if (options->kerberos_authentication == -1)
857 options->kerberos_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000858#endif
859#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100860 if (options->kerberos_tgt_passing == -1)
861 options->kerberos_tgt_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000862#endif
863#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100864 if (options->afs_token_passing == -1)
865 options->afs_token_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000866#endif
Damien Miller95def091999-11-25 00:26:21 +1100867 if (options->password_authentication == -1)
868 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100869 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000870 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100871 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000872 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000873 if (options->hostbased_authentication == -1)
874 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100875 if (options->batch_mode == -1)
876 options->batch_mode = 0;
877 if (options->check_host_ip == -1)
878 options->check_host_ip = 1;
879 if (options->strict_host_key_checking == -1)
880 options->strict_host_key_checking = 2; /* 2 is default */
881 if (options->compression == -1)
882 options->compression = 0;
883 if (options->keepalives == -1)
884 options->keepalives = 1;
885 if (options->compression_level == -1)
886 options->compression_level = 6;
887 if (options->port == -1)
888 options->port = 0; /* Filled in ssh_connect. */
889 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000890 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100891 if (options->number_of_password_prompts == -1)
892 options->number_of_password_prompts = 3;
893 /* Selected in ssh_login(). */
894 if (options->cipher == -1)
895 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000896 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000897 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000898 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000899 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000900 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100901 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100902 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000903 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100904 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000905 xmalloc(len);
906 snprintf(options->identity_files[options->num_identity_files++],
907 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100908 }
909 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000910 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
911 options->identity_files[options->num_identity_files] =
912 xmalloc(len);
913 snprintf(options->identity_files[options->num_identity_files++],
914 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
915
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000916 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100917 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000918 xmalloc(len);
919 snprintf(options->identity_files[options->num_identity_files++],
920 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100921 }
Damien Millereba71ba2000-04-29 23:57:08 +1000922 }
Damien Miller95def091999-11-25 00:26:21 +1100923 if (options->escape_char == -1)
924 options->escape_char = '~';
925 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000926 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100927 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000928 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000929 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000930 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000931 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000932 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +1100933 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000934 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000935 if (options->clear_forwardings == 1)
936 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000937 if (options->no_host_authentication_for_localhost == - 1)
938 options->no_host_authentication_for_localhost = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000939 if (options->enable_ssh_keysign == -1)
940 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +1000941 if (options->rekey_limit == -1)
942 options->rekey_limit = 0;
Damien Miller95def091999-11-25 00:26:21 +1100943 /* options->proxy_command should not be set by default */
944 /* options->user will be set in the main program if appropriate */
945 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000946 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000947 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000948}