blob: b9f1b7ddcc8b1b09f6b92dfa1c1a6890557bc23a [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 Lindstromb6df73b2002-11-09 15:52:31 +000015RCSID("$OpenBSD: readconf.c,v 1.101 2002/11/07 22:08: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,
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000117 oEnableSSHKeysign,
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 },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000191 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100192};
193
Damien Miller5428f641999-11-25 11:54:57 +1100194/*
195 * Adds a local TCP/IP port forward to options. Never returns if there is an
196 * error.
197 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000198
Damien Miller4af51302000-04-16 11:18:38 +1000199void
Damien Milleraae6c611999-12-06 11:47:28 +1100200add_local_forward(Options *options, u_short port, const char *host,
201 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000202{
Damien Miller95def091999-11-25 00:26:21 +1100203 Forward *fwd;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000204#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100205 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100206 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000207 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100208#endif
Damien Miller95def091999-11-25 00:26:21 +1100209 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
210 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
211 fwd = &options->local_forwards[options->num_local_forwards++];
212 fwd->port = port;
213 fwd->host = xstrdup(host);
214 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000215}
216
Damien Miller5428f641999-11-25 11:54:57 +1100217/*
218 * Adds a remote TCP/IP port forward to options. Never returns if there is
219 * an error.
220 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000221
Damien Miller4af51302000-04-16 11:18:38 +1000222void
Damien Milleraae6c611999-12-06 11:47:28 +1100223add_remote_forward(Options *options, u_short port, const char *host,
224 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000225{
Damien Miller95def091999-11-25 00:26:21 +1100226 Forward *fwd;
227 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
228 fatal("Too many remote forwards (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100229 SSH_MAX_FORWARDS_PER_DIRECTION);
Damien Miller95def091999-11-25 00:26:21 +1100230 fwd = &options->remote_forwards[options->num_remote_forwards++];
231 fwd->port = port;
232 fwd->host = xstrdup(host);
233 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000234}
235
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000236static void
237clear_forwardings(Options *options)
238{
239 int i;
240
241 for (i = 0; i < options->num_local_forwards; i++)
242 xfree(options->local_forwards[i].host);
243 options->num_local_forwards = 0;
244 for (i = 0; i < options->num_remote_forwards; i++)
245 xfree(options->remote_forwards[i].host);
246 options->num_remote_forwards = 0;
247}
248
Damien Miller5428f641999-11-25 11:54:57 +1100249/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000250 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100251 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000252
Damien Miller4af51302000-04-16 11:18:38 +1000253static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100254parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000255{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000256 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000257
Damien Miller95def091999-11-25 00:26:21 +1100258 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100259 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100260 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000261
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000262 error("%s: line %d: Bad configuration option: %s",
263 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100264 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000265}
266
Damien Miller5428f641999-11-25 11:54:57 +1100267/*
268 * Processes a single option line as used in the configuration files. This
269 * only sets those values that have not already been set.
270 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000271
Damien Miller2ccf6611999-11-15 15:25:10 +1100272int
273process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100274 char *line, const char *filename, int linenum,
275 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000276{
Ben Lindstromd0ff4082001-08-15 22:58:59 +0000277 char buf[256], *s, *string, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100278 int opcode, *intptr, value;
279 u_short fwd_port, fwd_host_port;
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000280 char sfwd_host_port[6];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000281
Damien Millerbe484b52000-07-15 14:14:16 +1000282 s = line;
283 /* Get the keyword. (Each line is supposed to begin with a keyword). */
284 keyword = strdelim(&s);
285 /* Ignore leading whitespace. */
286 if (*keyword == '\0')
287 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000288 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100289 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000290
Damien Miller37023962000-07-11 17:31:38 +1000291 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000292
Damien Miller95def091999-11-25 00:26:21 +1100293 switch (opcode) {
294 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100295 /* don't panic, but count bad options */
296 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100297 /* NOTREACHED */
298 case oForwardAgent:
299 intptr = &options->forward_agent;
300parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000301 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000302 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100303 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
304 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000305 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100306 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000307 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100308 value = 0;
309 else
310 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
311 if (*activep && *intptr == -1)
312 *intptr = value;
313 break;
314
315 case oForwardX11:
316 intptr = &options->forward_x11;
317 goto parse_flag;
318
319 case oGatewayPorts:
320 intptr = &options->gateway_ports;
321 goto parse_flag;
322
323 case oUsePrivilegedPort:
324 intptr = &options->use_privileged_port;
325 goto parse_flag;
326
327 case oRhostsAuthentication:
328 intptr = &options->rhosts_authentication;
329 goto parse_flag;
330
331 case oPasswordAuthentication:
332 intptr = &options->password_authentication;
333 goto parse_flag;
334
Damien Miller874d77b2000-10-14 16:23:11 +1100335 case oKbdInteractiveAuthentication:
336 intptr = &options->kbd_interactive_authentication;
337 goto parse_flag;
338
339 case oKbdInteractiveDevices:
340 charptr = &options->kbd_interactive_devices;
341 goto parse_string;
342
Damien Miller0bc1bd82000-11-13 22:57:25 +1100343 case oPubkeyAuthentication:
344 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000345 goto parse_flag;
346
Damien Miller95def091999-11-25 00:26:21 +1100347 case oRSAAuthentication:
348 intptr = &options->rsa_authentication;
349 goto parse_flag;
350
351 case oRhostsRSAAuthentication:
352 intptr = &options->rhosts_rsa_authentication;
353 goto parse_flag;
354
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000355 case oHostbasedAuthentication:
356 intptr = &options->hostbased_authentication;
357 goto parse_flag;
358
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000359 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000360 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100361 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000362#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100363 case oKerberosAuthentication:
364 intptr = &options->kerberos_authentication;
365 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000366#endif
367#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100368 case oKerberosTgtPassing:
369 intptr = &options->kerberos_tgt_passing;
370 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000371#endif
372#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100373 case oAFSTokenPassing:
374 intptr = &options->afs_token_passing;
375 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000376#endif
Damien Miller95def091999-11-25 00:26:21 +1100377 case oBatchMode:
378 intptr = &options->batch_mode;
379 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000380
Damien Miller95def091999-11-25 00:26:21 +1100381 case oCheckHostIP:
382 intptr = &options->check_host_ip;
383 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000384
Damien Miller95def091999-11-25 00:26:21 +1100385 case oStrictHostKeyChecking:
386 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000387 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000388 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000389 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100390 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100391 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000392 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100393 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000394 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100395 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000396 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100397 value = 2;
398 else
399 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
400 if (*activep && *intptr == -1)
401 *intptr = value;
402 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000403
Damien Miller95def091999-11-25 00:26:21 +1100404 case oCompression:
405 intptr = &options->compression;
406 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000407
Damien Miller95def091999-11-25 00:26:21 +1100408 case oKeepAlives:
409 intptr = &options->keepalives;
410 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000411
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000412 case oNoHostAuthenticationForLocalhost:
413 intptr = &options->no_host_authentication_for_localhost;
414 goto parse_flag;
415
Damien Miller95def091999-11-25 00:26:21 +1100416 case oNumberOfPasswordPrompts:
417 intptr = &options->number_of_password_prompts;
418 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000419
Damien Miller95def091999-11-25 00:26:21 +1100420 case oCompressionLevel:
421 intptr = &options->compression_level;
422 goto parse_int;
423
424 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000425 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000426 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100427 fatal("%.200s line %d: Missing argument.", filename, linenum);
428 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100429 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000430 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100431 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100432 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100433 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000434 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000435 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100436 }
437 break;
438
Damien Millerd3a18572000-06-07 19:55:44 +1000439 case oXAuthLocation:
440 charptr=&options->xauth_location;
441 goto parse_string;
442
Damien Miller95def091999-11-25 00:26:21 +1100443 case oUser:
444 charptr = &options->user;
445parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000446 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000447 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100448 fatal("%.200s line %d: Missing argument.", filename, linenum);
449 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000450 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100451 break;
452
453 case oGlobalKnownHostsFile:
454 charptr = &options->system_hostfile;
455 goto parse_string;
456
457 case oUserKnownHostsFile:
458 charptr = &options->user_hostfile;
459 goto parse_string;
460
Damien Millereba71ba2000-04-29 23:57:08 +1000461 case oGlobalKnownHostsFile2:
462 charptr = &options->system_hostfile2;
463 goto parse_string;
464
465 case oUserKnownHostsFile2:
466 charptr = &options->user_hostfile2;
467 goto parse_string;
468
Damien Miller95def091999-11-25 00:26:21 +1100469 case oHostName:
470 charptr = &options->hostname;
471 goto parse_string;
472
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000473 case oHostKeyAlias:
474 charptr = &options->host_key_alias;
475 goto parse_string;
476
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000477 case oPreferredAuthentications:
478 charptr = &options->preferred_authentications;
479 goto parse_string;
480
Ben Lindstrome0f88042001-04-30 13:06:24 +0000481 case oBindAddress:
482 charptr = &options->bind_address;
483 goto parse_string;
484
Ben Lindstromae996bf2001-08-06 21:27:53 +0000485 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000486 charptr = &options->smartcard_device;
487 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000488
Damien Miller95def091999-11-25 00:26:21 +1100489 case oProxyCommand:
490 charptr = &options->proxy_command;
Ben Lindstromd0ff4082001-08-15 22:58:59 +0000491 string = xstrdup("");
Damien Millerbe484b52000-07-15 14:14:16 +1000492 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000493 string = xrealloc(string, strlen(string) + strlen(arg) + 2);
Damien Miller95def091999-11-25 00:26:21 +1100494 strcat(string, " ");
Damien Miller37023962000-07-11 17:31:38 +1000495 strcat(string, arg);
Damien Miller95def091999-11-25 00:26:21 +1100496 }
497 if (*activep && *charptr == NULL)
498 *charptr = string;
499 else
500 xfree(string);
501 return 0;
502
503 case oPort:
504 intptr = &options->port;
505parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000506 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000507 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100508 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000509 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100510 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100511
512 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000513 value = strtol(arg, &endofnumber, 0);
514 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100515 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100516 if (*activep && *intptr == -1)
517 *intptr = value;
518 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000519
Damien Miller95def091999-11-25 00:26:21 +1100520 case oConnectionAttempts:
521 intptr = &options->connection_attempts;
522 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100523
Damien Miller95def091999-11-25 00:26:21 +1100524 case oCipher:
525 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000526 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000527 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000528 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000529 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100530 if (value == -1)
531 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100532 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100533 if (*activep && *intptr == -1)
534 *intptr = value;
535 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000536
Damien Miller78928792000-04-12 20:17:38 +1000537 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000538 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000539 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000540 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000541 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000542 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100543 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000544 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000545 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000546 break;
547
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000548 case oMacs:
549 arg = strdelim(&s);
550 if (!arg || *arg == '\0')
551 fatal("%.200s line %d: Missing argument.", filename, linenum);
552 if (!mac_valid(arg))
553 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100554 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000555 if (*activep && options->macs == NULL)
556 options->macs = xstrdup(arg);
557 break;
558
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000559 case oHostKeyAlgorithms:
560 arg = strdelim(&s);
561 if (!arg || *arg == '\0')
562 fatal("%.200s line %d: Missing argument.", filename, linenum);
563 if (!key_names_valid2(arg))
564 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100565 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000566 if (*activep && options->hostkeyalgorithms == NULL)
567 options->hostkeyalgorithms = xstrdup(arg);
568 break;
569
Damien Miller78928792000-04-12 20:17:38 +1000570 case oProtocol:
571 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000572 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000573 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000574 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000575 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000576 if (value == SSH_PROTO_UNKNOWN)
577 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100578 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000579 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
580 *intptr = value;
581 break;
582
Damien Miller95def091999-11-25 00:26:21 +1100583 case oLogLevel:
584 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000585 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000586 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100587 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000588 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100589 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100590 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100591 *intptr = (LogLevel) value;
592 break;
593
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000594 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100595 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000596 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000597 if (!arg || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000598 fatal("%.200s line %d: Missing port argument.",
599 filename, linenum);
600 if ((fwd_port = a2port(arg)) == 0)
601 fatal("%.200s line %d: Bad listen port.",
602 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000603 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000604 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100605 fatal("%.200s line %d: Missing second argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000606 filename, linenum);
607 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
608 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
609 fatal("%.200s line %d: Bad forwarding specification.",
610 filename, linenum);
611 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
612 fatal("%.200s line %d: Bad forwarding port.",
613 filename, linenum);
614 if (*activep) {
615 if (opcode == oLocalForward)
616 add_local_forward(options, fwd_port, buf,
617 fwd_host_port);
618 else if (opcode == oRemoteForward)
619 add_remote_forward(options, fwd_port, buf,
620 fwd_host_port);
621 }
Damien Miller95def091999-11-25 00:26:21 +1100622 break;
623
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000624 case oDynamicForward:
625 arg = strdelim(&s);
626 if (!arg || *arg == '\0')
627 fatal("%.200s line %d: Missing port argument.",
628 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000629 fwd_port = a2port(arg);
630 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000631 fatal("%.200s line %d: Badly formatted port number.",
632 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000633 if (*activep)
634 add_local_forward(options, fwd_port, "socks4", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000635 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000636
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000637 case oClearAllForwardings:
638 intptr = &options->clear_forwardings;
639 goto parse_flag;
640
Damien Miller95def091999-11-25 00:26:21 +1100641 case oHost:
642 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000643 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000644 if (match_pattern(host, arg)) {
645 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100646 *activep = 1;
647 break;
648 }
Damien Millerbe484b52000-07-15 14:14:16 +1000649 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100650 return 0;
651
652 case oEscapeChar:
653 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000654 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000655 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100656 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000657 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000658 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
659 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000660 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000661 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000662 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000663 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100664 else {
665 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100666 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100667 /* NOTREACHED */
668 value = 0; /* Avoid compiler warning. */
669 }
670 if (*activep && *intptr == -1)
671 *intptr = value;
672 break;
673
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000674 case oEnableSSHKeysign:
675 intptr = &options->enable_ssh_keysign;
676 goto parse_flag;
677
Ben Lindstrom4daea862002-06-09 20:04:02 +0000678 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000679 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +0000680 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000681 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +0000682
Damien Miller95def091999-11-25 00:26:21 +1100683 default:
684 fatal("process_config_line: Unimplemented opcode %d", opcode);
685 }
686
687 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000688 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000689 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100690 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000691 }
Damien Miller95def091999-11-25 00:26:21 +1100692 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000693}
694
695
Damien Miller5428f641999-11-25 11:54:57 +1100696/*
697 * Reads the config file and modifies the options accordingly. Options
698 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000699 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100700 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000701
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000702int
Damien Miller95def091999-11-25 00:26:21 +1100703read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000704{
Damien Miller95def091999-11-25 00:26:21 +1100705 FILE *f;
706 char line[1024];
707 int active, linenum;
708 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000709
Damien Miller95def091999-11-25 00:26:21 +1100710 /* Open the file. */
711 f = fopen(filename, "r");
712 if (!f)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000713 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000714
Damien Miller95def091999-11-25 00:26:21 +1100715 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000716
Damien Miller5428f641999-11-25 11:54:57 +1100717 /*
718 * Mark that we are now processing the options. This flag is turned
719 * on/off by Host specifications.
720 */
Damien Miller95def091999-11-25 00:26:21 +1100721 active = 1;
722 linenum = 0;
723 while (fgets(line, sizeof(line), f)) {
724 /* Update line number counter. */
725 linenum++;
726 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
727 bad_options++;
728 }
729 fclose(f);
730 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000731 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100732 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000733 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000734}
735
Damien Miller5428f641999-11-25 11:54:57 +1100736/*
737 * Initializes options to special values that indicate that they have not yet
738 * been set. Read_config_file will only set options with this value. Options
739 * are processed in the following order: command line, user config file,
740 * system config file. Last, fill_default_options is called.
741 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000742
Damien Miller4af51302000-04-16 11:18:38 +1000743void
Damien Miller95def091999-11-25 00:26:21 +1100744initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000745{
Damien Miller95def091999-11-25 00:26:21 +1100746 memset(options, 'X', sizeof(*options));
747 options->forward_agent = -1;
748 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000749 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100750 options->gateway_ports = -1;
751 options->use_privileged_port = -1;
752 options->rhosts_authentication = -1;
753 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100754 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000755 options->challenge_response_authentication = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000756#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100757 options->kerberos_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000758#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000759#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100760 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000761#endif
762#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100763 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000764#endif
Damien Miller95def091999-11-25 00:26:21 +1100765 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100766 options->kbd_interactive_authentication = -1;
767 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100768 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000769 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100770 options->batch_mode = -1;
771 options->check_host_ip = -1;
772 options->strict_host_key_checking = -1;
773 options->compression = -1;
774 options->keepalives = -1;
775 options->compression_level = -1;
776 options->port = -1;
777 options->connection_attempts = -1;
778 options->number_of_password_prompts = -1;
779 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000780 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000781 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000782 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000783 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100784 options->num_identity_files = 0;
785 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000786 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100787 options->proxy_command = NULL;
788 options->user = NULL;
789 options->escape_char = -1;
790 options->system_hostfile = NULL;
791 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000792 options->system_hostfile2 = NULL;
793 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100794 options->num_local_forwards = 0;
795 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000796 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100797 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000798 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000799 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000800 options->smartcard_device = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000801 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000802 options->no_host_authentication_for_localhost = - 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000803}
804
Damien Miller5428f641999-11-25 11:54:57 +1100805/*
806 * Called after processing other sources of option data, this fills those
807 * options for which no value has been specified with their default values.
808 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000809
Damien Miller4af51302000-04-16 11:18:38 +1000810void
Damien Miller95def091999-11-25 00:26:21 +1100811fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000812{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000813 int len;
814
Damien Miller95def091999-11-25 00:26:21 +1100815 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000816 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100817 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100818 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000819 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000820 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100821 if (options->gateway_ports == -1)
822 options->gateway_ports = 0;
823 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000824 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100825 if (options->rhosts_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000826 options->rhosts_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100827 if (options->rsa_authentication == -1)
828 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100829 if (options->pubkey_authentication == -1)
830 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000831 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000832 options->challenge_response_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000833#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100834 if (options->kerberos_authentication == -1)
835 options->kerberos_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000836#endif
837#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100838 if (options->kerberos_tgt_passing == -1)
839 options->kerberos_tgt_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000840#endif
841#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100842 if (options->afs_token_passing == -1)
843 options->afs_token_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000844#endif
Damien Miller95def091999-11-25 00:26:21 +1100845 if (options->password_authentication == -1)
846 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100847 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000848 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100849 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000850 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000851 if (options->hostbased_authentication == -1)
852 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100853 if (options->batch_mode == -1)
854 options->batch_mode = 0;
855 if (options->check_host_ip == -1)
856 options->check_host_ip = 1;
857 if (options->strict_host_key_checking == -1)
858 options->strict_host_key_checking = 2; /* 2 is default */
859 if (options->compression == -1)
860 options->compression = 0;
861 if (options->keepalives == -1)
862 options->keepalives = 1;
863 if (options->compression_level == -1)
864 options->compression_level = 6;
865 if (options->port == -1)
866 options->port = 0; /* Filled in ssh_connect. */
867 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000868 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100869 if (options->number_of_password_prompts == -1)
870 options->number_of_password_prompts = 3;
871 /* Selected in ssh_login(). */
872 if (options->cipher == -1)
873 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000874 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000875 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000876 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000877 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000878 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100879 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100880 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000881 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100882 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000883 xmalloc(len);
884 snprintf(options->identity_files[options->num_identity_files++],
885 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100886 }
887 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000888 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
889 options->identity_files[options->num_identity_files] =
890 xmalloc(len);
891 snprintf(options->identity_files[options->num_identity_files++],
892 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
893
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000894 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100895 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000896 xmalloc(len);
897 snprintf(options->identity_files[options->num_identity_files++],
898 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100899 }
Damien Millereba71ba2000-04-29 23:57:08 +1000900 }
Damien Miller95def091999-11-25 00:26:21 +1100901 if (options->escape_char == -1)
902 options->escape_char = '~';
903 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000904 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100905 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000906 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000907 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000908 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000909 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000910 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +1100911 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000912 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000913 if (options->clear_forwardings == 1)
914 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000915 if (options->no_host_authentication_for_localhost == - 1)
916 options->no_host_authentication_for_localhost = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000917 if (options->enable_ssh_keysign == -1)
918 options->enable_ssh_keysign = 0;
Damien Miller95def091999-11-25 00:26:21 +1100919 /* options->proxy_command should not be set by default */
920 /* options->user will be set in the main program if appropriate */
921 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000922 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000923 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000924}