blob: 79c27ae15e6f9fcab833f1f68177905569bbf01a [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"
Ben Lindstrom2e17b082002-06-09 20:13:27 +000015RCSID("$OpenBSD: readconf.c,v 1.98 2002/06/08 12:46:14 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 Lindstrom4daea862002-06-09 20:04:02 +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,
117 oDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000118} OpCodes;
119
120/* Textual representations of the tokens. */
121
Damien Miller95def091999-11-25 00:26:21 +1100122static struct {
123 const char *name;
124 OpCodes opcode;
125} keywords[] = {
126 { "forwardagent", oForwardAgent },
127 { "forwardx11", oForwardX11 },
Damien Millerd3a18572000-06-07 19:55:44 +1000128 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100129 { "gatewayports", oGatewayPorts },
130 { "useprivilegedport", oUsePrivilegedPort },
131 { "rhostsauthentication", oRhostsAuthentication },
132 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100133 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
134 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100135 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100136 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000137 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000138 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000139 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000140 { "challengeresponseauthentication", oChallengeResponseAuthentication },
141 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
142 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000143#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100144 { "kerberosauthentication", oKerberosAuthentication },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000145#endif
146#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100147 { "kerberostgtpassing", oKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000148#endif
149#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100150 { "afstokenpassing", oAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000151#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000152 { "fallbacktorsh", oDeprecated },
153 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100154 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100155 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100156 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000157 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100158 { "proxycommand", oProxyCommand },
159 { "port", oPort },
160 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000161 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000162 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000163 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100164 { "remoteforward", oRemoteForward },
165 { "localforward", oLocalForward },
166 { "user", oUser },
167 { "host", oHost },
168 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100169 { "globalknownhostsfile", oGlobalKnownHostsFile },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000170 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
Damien Millereba71ba2000-04-29 23:57:08 +1000171 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000172 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100173 { "connectionattempts", oConnectionAttempts },
174 { "batchmode", oBatchMode },
175 { "checkhostip", oCheckHostIP },
176 { "stricthostkeychecking", oStrictHostKeyChecking },
177 { "compression", oCompression },
178 { "compressionlevel", oCompressionLevel },
179 { "keepalive", oKeepAlives },
180 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100181 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000182 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000183 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000184 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000185 { "bindaddress", oBindAddress },
Ben Lindstromae996bf2001-08-06 21:27:53 +0000186 { "smartcarddevice", oSmartcardDevice },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100187 { "clearallforwardings", oClearAllForwardings },
188 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000189 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100190};
191
Damien Miller5428f641999-11-25 11:54:57 +1100192/*
193 * Adds a local TCP/IP port forward to options. Never returns if there is an
194 * error.
195 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000196
Damien Miller4af51302000-04-16 11:18:38 +1000197void
Damien Milleraae6c611999-12-06 11:47:28 +1100198add_local_forward(Options *options, u_short port, const char *host,
199 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000200{
Damien Miller95def091999-11-25 00:26:21 +1100201 Forward *fwd;
Damien Millerbac2d8a2000-09-05 16:13:06 +1100202#ifndef HAVE_CYGWIN
Damien Miller95def091999-11-25 00:26:21 +1100203 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100204 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000205 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100206#endif
Damien Miller95def091999-11-25 00:26:21 +1100207 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
208 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
209 fwd = &options->local_forwards[options->num_local_forwards++];
210 fwd->port = port;
211 fwd->host = xstrdup(host);
212 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000213}
214
Damien Miller5428f641999-11-25 11:54:57 +1100215/*
216 * Adds a remote TCP/IP port forward to options. Never returns if there is
217 * an error.
218 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000219
Damien Miller4af51302000-04-16 11:18:38 +1000220void
Damien Milleraae6c611999-12-06 11:47:28 +1100221add_remote_forward(Options *options, u_short port, const char *host,
222 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223{
Damien Miller95def091999-11-25 00:26:21 +1100224 Forward *fwd;
225 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
226 fatal("Too many remote forwards (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100227 SSH_MAX_FORWARDS_PER_DIRECTION);
Damien Miller95def091999-11-25 00:26:21 +1100228 fwd = &options->remote_forwards[options->num_remote_forwards++];
229 fwd->port = port;
230 fwd->host = xstrdup(host);
231 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000232}
233
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000234static void
235clear_forwardings(Options *options)
236{
237 int i;
238
239 for (i = 0; i < options->num_local_forwards; i++)
240 xfree(options->local_forwards[i].host);
241 options->num_local_forwards = 0;
242 for (i = 0; i < options->num_remote_forwards; i++)
243 xfree(options->remote_forwards[i].host);
244 options->num_remote_forwards = 0;
245}
246
Damien Miller5428f641999-11-25 11:54:57 +1100247/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000248 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100249 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000250
Damien Miller4af51302000-04-16 11:18:38 +1000251static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100252parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000253{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000254 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000255
Damien Miller95def091999-11-25 00:26:21 +1100256 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100257 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100258 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000259
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000260 error("%s: line %d: Bad configuration option: %s",
261 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100262 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000263}
264
Damien Miller5428f641999-11-25 11:54:57 +1100265/*
266 * Processes a single option line as used in the configuration files. This
267 * only sets those values that have not already been set.
268 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000269
Damien Miller2ccf6611999-11-15 15:25:10 +1100270int
271process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100272 char *line, const char *filename, int linenum,
273 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000274{
Ben Lindstromd0ff4082001-08-15 22:58:59 +0000275 char buf[256], *s, *string, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100276 int opcode, *intptr, value;
277 u_short fwd_port, fwd_host_port;
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000278 char sfwd_host_port[6];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000279
Damien Millerbe484b52000-07-15 14:14:16 +1000280 s = line;
281 /* Get the keyword. (Each line is supposed to begin with a keyword). */
282 keyword = strdelim(&s);
283 /* Ignore leading whitespace. */
284 if (*keyword == '\0')
285 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000286 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100287 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000288
Damien Miller37023962000-07-11 17:31:38 +1000289 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000290
Damien Miller95def091999-11-25 00:26:21 +1100291 switch (opcode) {
292 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100293 /* don't panic, but count bad options */
294 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100295 /* NOTREACHED */
296 case oForwardAgent:
297 intptr = &options->forward_agent;
298parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000299 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000300 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100301 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
302 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000303 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100304 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000305 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100306 value = 0;
307 else
308 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
309 if (*activep && *intptr == -1)
310 *intptr = value;
311 break;
312
313 case oForwardX11:
314 intptr = &options->forward_x11;
315 goto parse_flag;
316
317 case oGatewayPorts:
318 intptr = &options->gateway_ports;
319 goto parse_flag;
320
321 case oUsePrivilegedPort:
322 intptr = &options->use_privileged_port;
323 goto parse_flag;
324
325 case oRhostsAuthentication:
326 intptr = &options->rhosts_authentication;
327 goto parse_flag;
328
329 case oPasswordAuthentication:
330 intptr = &options->password_authentication;
331 goto parse_flag;
332
Damien Miller874d77b2000-10-14 16:23:11 +1100333 case oKbdInteractiveAuthentication:
334 intptr = &options->kbd_interactive_authentication;
335 goto parse_flag;
336
337 case oKbdInteractiveDevices:
338 charptr = &options->kbd_interactive_devices;
339 goto parse_string;
340
Damien Miller0bc1bd82000-11-13 22:57:25 +1100341 case oPubkeyAuthentication:
342 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000343 goto parse_flag;
344
Damien Miller95def091999-11-25 00:26:21 +1100345 case oRSAAuthentication:
346 intptr = &options->rsa_authentication;
347 goto parse_flag;
348
349 case oRhostsRSAAuthentication:
350 intptr = &options->rhosts_rsa_authentication;
351 goto parse_flag;
352
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000353 case oHostbasedAuthentication:
354 intptr = &options->hostbased_authentication;
355 goto parse_flag;
356
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000357 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000358 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100359 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000360#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100361 case oKerberosAuthentication:
362 intptr = &options->kerberos_authentication;
363 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000364#endif
365#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100366 case oKerberosTgtPassing:
367 intptr = &options->kerberos_tgt_passing;
368 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000369#endif
370#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100371 case oAFSTokenPassing:
372 intptr = &options->afs_token_passing;
373 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000374#endif
Damien Miller95def091999-11-25 00:26:21 +1100375 case oBatchMode:
376 intptr = &options->batch_mode;
377 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000378
Damien Miller95def091999-11-25 00:26:21 +1100379 case oCheckHostIP:
380 intptr = &options->check_host_ip;
381 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000382
Damien Miller95def091999-11-25 00:26:21 +1100383 case oStrictHostKeyChecking:
384 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000385 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000386 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000387 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100388 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100389 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000390 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100391 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000392 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100393 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000394 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100395 value = 2;
396 else
397 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
398 if (*activep && *intptr == -1)
399 *intptr = value;
400 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000401
Damien Miller95def091999-11-25 00:26:21 +1100402 case oCompression:
403 intptr = &options->compression;
404 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000405
Damien Miller95def091999-11-25 00:26:21 +1100406 case oKeepAlives:
407 intptr = &options->keepalives;
408 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000409
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000410 case oNoHostAuthenticationForLocalhost:
411 intptr = &options->no_host_authentication_for_localhost;
412 goto parse_flag;
413
Damien Miller95def091999-11-25 00:26:21 +1100414 case oNumberOfPasswordPrompts:
415 intptr = &options->number_of_password_prompts;
416 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000417
Damien Miller95def091999-11-25 00:26:21 +1100418 case oCompressionLevel:
419 intptr = &options->compression_level;
420 goto parse_int;
421
422 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000423 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000424 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100425 fatal("%.200s line %d: Missing argument.", filename, linenum);
426 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100427 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000428 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100429 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100430 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100431 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000432 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000433 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100434 }
435 break;
436
Damien Millerd3a18572000-06-07 19:55:44 +1000437 case oXAuthLocation:
438 charptr=&options->xauth_location;
439 goto parse_string;
440
Damien Miller95def091999-11-25 00:26:21 +1100441 case oUser:
442 charptr = &options->user;
443parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000444 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000445 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100446 fatal("%.200s line %d: Missing argument.", filename, linenum);
447 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000448 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100449 break;
450
451 case oGlobalKnownHostsFile:
452 charptr = &options->system_hostfile;
453 goto parse_string;
454
455 case oUserKnownHostsFile:
456 charptr = &options->user_hostfile;
457 goto parse_string;
458
Damien Millereba71ba2000-04-29 23:57:08 +1000459 case oGlobalKnownHostsFile2:
460 charptr = &options->system_hostfile2;
461 goto parse_string;
462
463 case oUserKnownHostsFile2:
464 charptr = &options->user_hostfile2;
465 goto parse_string;
466
Damien Miller95def091999-11-25 00:26:21 +1100467 case oHostName:
468 charptr = &options->hostname;
469 goto parse_string;
470
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000471 case oHostKeyAlias:
472 charptr = &options->host_key_alias;
473 goto parse_string;
474
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000475 case oPreferredAuthentications:
476 charptr = &options->preferred_authentications;
477 goto parse_string;
478
Ben Lindstrome0f88042001-04-30 13:06:24 +0000479 case oBindAddress:
480 charptr = &options->bind_address;
481 goto parse_string;
482
Ben Lindstromae996bf2001-08-06 21:27:53 +0000483 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000484 charptr = &options->smartcard_device;
485 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000486
Damien Miller95def091999-11-25 00:26:21 +1100487 case oProxyCommand:
488 charptr = &options->proxy_command;
Ben Lindstromd0ff4082001-08-15 22:58:59 +0000489 string = xstrdup("");
Damien Millerbe484b52000-07-15 14:14:16 +1000490 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000491 string = xrealloc(string, strlen(string) + strlen(arg) + 2);
Damien Miller95def091999-11-25 00:26:21 +1100492 strcat(string, " ");
Damien Miller37023962000-07-11 17:31:38 +1000493 strcat(string, arg);
Damien Miller95def091999-11-25 00:26:21 +1100494 }
495 if (*activep && *charptr == NULL)
496 *charptr = string;
497 else
498 xfree(string);
499 return 0;
500
501 case oPort:
502 intptr = &options->port;
503parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000504 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000505 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100506 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000507 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100508 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100509
510 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000511 value = strtol(arg, &endofnumber, 0);
512 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100513 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100514 if (*activep && *intptr == -1)
515 *intptr = value;
516 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000517
Damien Miller95def091999-11-25 00:26:21 +1100518 case oConnectionAttempts:
519 intptr = &options->connection_attempts;
520 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100521
Damien Miller95def091999-11-25 00:26:21 +1100522 case oCipher:
523 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000524 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000525 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000526 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000527 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100528 if (value == -1)
529 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100530 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100531 if (*activep && *intptr == -1)
532 *intptr = value;
533 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000534
Damien Miller78928792000-04-12 20:17:38 +1000535 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000536 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000537 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000538 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000539 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000540 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100541 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000542 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000543 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000544 break;
545
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000546 case oMacs:
547 arg = strdelim(&s);
548 if (!arg || *arg == '\0')
549 fatal("%.200s line %d: Missing argument.", filename, linenum);
550 if (!mac_valid(arg))
551 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100552 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000553 if (*activep && options->macs == NULL)
554 options->macs = xstrdup(arg);
555 break;
556
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000557 case oHostKeyAlgorithms:
558 arg = strdelim(&s);
559 if (!arg || *arg == '\0')
560 fatal("%.200s line %d: Missing argument.", filename, linenum);
561 if (!key_names_valid2(arg))
562 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100563 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000564 if (*activep && options->hostkeyalgorithms == NULL)
565 options->hostkeyalgorithms = xstrdup(arg);
566 break;
567
Damien Miller78928792000-04-12 20:17:38 +1000568 case oProtocol:
569 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000570 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000571 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000572 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000573 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000574 if (value == SSH_PROTO_UNKNOWN)
575 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100576 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000577 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
578 *intptr = value;
579 break;
580
Damien Miller95def091999-11-25 00:26:21 +1100581 case oLogLevel:
582 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000583 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000584 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100585 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000586 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100587 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100588 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100589 *intptr = (LogLevel) value;
590 break;
591
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000592 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100593 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000594 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000595 if (!arg || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000596 fatal("%.200s line %d: Missing port argument.",
597 filename, linenum);
598 if ((fwd_port = a2port(arg)) == 0)
599 fatal("%.200s line %d: Bad listen port.",
600 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000601 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000602 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100603 fatal("%.200s line %d: Missing second argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000604 filename, linenum);
605 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
606 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
607 fatal("%.200s line %d: Bad forwarding specification.",
608 filename, linenum);
609 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
610 fatal("%.200s line %d: Bad forwarding port.",
611 filename, linenum);
612 if (*activep) {
613 if (opcode == oLocalForward)
614 add_local_forward(options, fwd_port, buf,
615 fwd_host_port);
616 else if (opcode == oRemoteForward)
617 add_remote_forward(options, fwd_port, buf,
618 fwd_host_port);
619 }
Damien Miller95def091999-11-25 00:26:21 +1100620 break;
621
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000622 case oDynamicForward:
623 arg = strdelim(&s);
624 if (!arg || *arg == '\0')
625 fatal("%.200s line %d: Missing port argument.",
626 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000627 fwd_port = a2port(arg);
628 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000629 fatal("%.200s line %d: Badly formatted port number.",
630 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000631 if (*activep)
632 add_local_forward(options, fwd_port, "socks4", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000633 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000634
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000635 case oClearAllForwardings:
636 intptr = &options->clear_forwardings;
637 goto parse_flag;
638
Damien Miller95def091999-11-25 00:26:21 +1100639 case oHost:
640 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000641 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000642 if (match_pattern(host, arg)) {
643 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100644 *activep = 1;
645 break;
646 }
Damien Millerbe484b52000-07-15 14:14:16 +1000647 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100648 return 0;
649
650 case oEscapeChar:
651 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000652 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000653 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100654 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000655 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000656 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
657 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000658 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000659 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000660 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000661 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100662 else {
663 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100664 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100665 /* NOTREACHED */
666 value = 0; /* Avoid compiler warning. */
667 }
668 if (*activep && *intptr == -1)
669 *intptr = value;
670 break;
671
Ben Lindstrom4daea862002-06-09 20:04:02 +0000672 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000673 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +0000674 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000675 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +0000676
Damien Miller95def091999-11-25 00:26:21 +1100677 default:
678 fatal("process_config_line: Unimplemented opcode %d", opcode);
679 }
680
681 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000682 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000683 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100684 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000685 }
Damien Miller95def091999-11-25 00:26:21 +1100686 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000687}
688
689
Damien Miller5428f641999-11-25 11:54:57 +1100690/*
691 * Reads the config file and modifies the options accordingly. Options
692 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000693 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100694 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000695
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000696int
Damien Miller95def091999-11-25 00:26:21 +1100697read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000698{
Damien Miller95def091999-11-25 00:26:21 +1100699 FILE *f;
700 char line[1024];
701 int active, linenum;
702 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000703
Damien Miller95def091999-11-25 00:26:21 +1100704 /* Open the file. */
705 f = fopen(filename, "r");
706 if (!f)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000707 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000708
Damien Miller95def091999-11-25 00:26:21 +1100709 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000710
Damien Miller5428f641999-11-25 11:54:57 +1100711 /*
712 * Mark that we are now processing the options. This flag is turned
713 * on/off by Host specifications.
714 */
Damien Miller95def091999-11-25 00:26:21 +1100715 active = 1;
716 linenum = 0;
717 while (fgets(line, sizeof(line), f)) {
718 /* Update line number counter. */
719 linenum++;
720 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
721 bad_options++;
722 }
723 fclose(f);
724 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000725 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100726 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000727 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000728}
729
Damien Miller5428f641999-11-25 11:54:57 +1100730/*
731 * Initializes options to special values that indicate that they have not yet
732 * been set. Read_config_file will only set options with this value. Options
733 * are processed in the following order: command line, user config file,
734 * system config file. Last, fill_default_options is called.
735 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000736
Damien Miller4af51302000-04-16 11:18:38 +1000737void
Damien Miller95def091999-11-25 00:26:21 +1100738initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000739{
Damien Miller95def091999-11-25 00:26:21 +1100740 memset(options, 'X', sizeof(*options));
741 options->forward_agent = -1;
742 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000743 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100744 options->gateway_ports = -1;
745 options->use_privileged_port = -1;
746 options->rhosts_authentication = -1;
747 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100748 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000749 options->challenge_response_authentication = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000750#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100751 options->kerberos_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000752#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000753#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100754 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000755#endif
756#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100757 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000758#endif
Damien Miller95def091999-11-25 00:26:21 +1100759 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100760 options->kbd_interactive_authentication = -1;
761 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100762 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000763 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100764 options->batch_mode = -1;
765 options->check_host_ip = -1;
766 options->strict_host_key_checking = -1;
767 options->compression = -1;
768 options->keepalives = -1;
769 options->compression_level = -1;
770 options->port = -1;
771 options->connection_attempts = -1;
772 options->number_of_password_prompts = -1;
773 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000774 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000775 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000776 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000777 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100778 options->num_identity_files = 0;
779 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000780 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100781 options->proxy_command = NULL;
782 options->user = NULL;
783 options->escape_char = -1;
784 options->system_hostfile = NULL;
785 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000786 options->system_hostfile2 = NULL;
787 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100788 options->num_local_forwards = 0;
789 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000790 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100791 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000792 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000793 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000794 options->smartcard_device = NULL;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000795 options->no_host_authentication_for_localhost = - 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000796}
797
Damien Miller5428f641999-11-25 11:54:57 +1100798/*
799 * Called after processing other sources of option data, this fills those
800 * options for which no value has been specified with their default values.
801 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000802
Damien Miller4af51302000-04-16 11:18:38 +1000803void
Damien Miller95def091999-11-25 00:26:21 +1100804fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000805{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000806 int len;
807
Damien Miller95def091999-11-25 00:26:21 +1100808 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000809 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100810 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100811 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000812 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000813 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100814 if (options->gateway_ports == -1)
815 options->gateway_ports = 0;
816 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000817 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100818 if (options->rhosts_authentication == -1)
819 options->rhosts_authentication = 1;
820 if (options->rsa_authentication == -1)
821 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100822 if (options->pubkey_authentication == -1)
823 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000824 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000825 options->challenge_response_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000826#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100827 if (options->kerberos_authentication == -1)
828 options->kerberos_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000829#endif
830#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100831 if (options->kerberos_tgt_passing == -1)
832 options->kerberos_tgt_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000833#endif
834#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100835 if (options->afs_token_passing == -1)
836 options->afs_token_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000837#endif
Damien Miller95def091999-11-25 00:26:21 +1100838 if (options->password_authentication == -1)
839 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100840 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000841 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100842 if (options->rhosts_rsa_authentication == -1)
843 options->rhosts_rsa_authentication = 1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000844 if (options->hostbased_authentication == -1)
845 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100846 if (options->batch_mode == -1)
847 options->batch_mode = 0;
848 if (options->check_host_ip == -1)
849 options->check_host_ip = 1;
850 if (options->strict_host_key_checking == -1)
851 options->strict_host_key_checking = 2; /* 2 is default */
852 if (options->compression == -1)
853 options->compression = 0;
854 if (options->keepalives == -1)
855 options->keepalives = 1;
856 if (options->compression_level == -1)
857 options->compression_level = 6;
858 if (options->port == -1)
859 options->port = 0; /* Filled in ssh_connect. */
860 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000861 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100862 if (options->number_of_password_prompts == -1)
863 options->number_of_password_prompts = 3;
864 /* Selected in ssh_login(). */
865 if (options->cipher == -1)
866 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000867 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000868 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000869 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000870 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000871 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100872 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100873 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000874 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100875 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000876 xmalloc(len);
877 snprintf(options->identity_files[options->num_identity_files++],
878 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100879 }
880 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000881 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
882 options->identity_files[options->num_identity_files] =
883 xmalloc(len);
884 snprintf(options->identity_files[options->num_identity_files++],
885 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
886
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000887 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100888 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000889 xmalloc(len);
890 snprintf(options->identity_files[options->num_identity_files++],
891 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100892 }
Damien Millereba71ba2000-04-29 23:57:08 +1000893 }
Damien Miller95def091999-11-25 00:26:21 +1100894 if (options->escape_char == -1)
895 options->escape_char = '~';
896 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000897 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100898 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000899 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000900 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000901 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000902 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000903 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +1100904 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000905 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000906 if (options->clear_forwardings == 1)
907 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000908 if (options->no_host_authentication_for_localhost == - 1)
909 options->no_host_authentication_for_localhost = 0;
Damien Miller95def091999-11-25 00:26:21 +1100910 /* options->proxy_command should not be set by default */
911 /* options->user will be set in the main program if appropriate */
912 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000913 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000914 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000915}