blob: acdf128f63c63f88eecbd0e6a61a87a540785df6 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11003 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11005 * Functions for reading the configuration files.
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerc652cac2003-05-14 13:40:54 +100015RCSID("$OpenBSD: readconf.c,v 1.106 2003/04/09 12:00:37 djm Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016
17#include "ssh.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100018#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100019#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000020#include "cipher.h"
21#include "pathnames.h"
22#include "log.h"
23#include "readconf.h"
24#include "match.h"
25#include "misc.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000026#include "kex.h"
27#include "mac.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100028
29/* Format of the configuration file:
30
31 # Configuration data is parsed as follows:
32 # 1. command line options
33 # 2. user-specific file
34 # 3. system-wide file
35 # Any configuration value is only changed the first time it is set.
36 # Thus, host-specific definitions should be at the beginning of the
37 # configuration file, and defaults at the end.
38
39 # Host-specific declarations. These may override anything above. A single
40 # host may match multiple declarations; these are processed in the order
41 # that they are given in.
42
43 Host *.ngs.fi ngs.fi
Ben Lindstrom4daea862002-06-09 20:04:02 +000044 User foo
Damien Millerd4a8b7e1999-10-27 13:42:43 +100045
46 Host fake.com
47 HostName another.host.name.real.org
48 User blaah
49 Port 34289
50 ForwardX11 no
51 ForwardAgent no
52
53 Host books.com
54 RemoteForward 9999 shadows.cs.hut.fi:9999
55 Cipher 3des
56
57 Host fascist.blob.com
58 Port 23123
59 User tylonen
60 RhostsAuthentication no
61 PasswordAuthentication no
62
63 Host puukko.hut.fi
64 User t35124p
65 ProxyCommand ssh-proxy %h %p
66
67 Host *.fr
Ben Lindstrom4daea862002-06-09 20:04:02 +000068 PublicKeyAuthentication no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100069
70 Host *.su
71 Cipher none
72 PasswordAuthentication no
73
74 # Defaults for various options
75 Host *
76 ForwardAgent no
Damien Miller0bc1bd82000-11-13 22:57:25 +110077 ForwardX11 no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100078 RhostsAuthentication yes
79 PasswordAuthentication yes
80 RSAAuthentication yes
81 RhostsRSAAuthentication yes
Damien Millerd4a8b7e1999-10-27 13:42:43 +100082 StrictHostKeyChecking yes
83 KeepAlives no
84 IdentityFile ~/.ssh/identity
85 Port 22
86 EscapeChar ~
87
88*/
89
90/* Keyword tokens. */
91
Damien Miller95def091999-11-25 00:26:21 +110092typedef enum {
93 oBadOption,
94 oForwardAgent, oForwardX11, oGatewayPorts, oRhostsAuthentication,
Ben Lindstromcb72e4f2002-06-21 00:41:51 +000095 oPasswordAuthentication, oRSAAuthentication,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000096 oChallengeResponseAuthentication, oXAuthLocation,
Ben Lindstromec95ed92001-07-04 04:21:14 +000097#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110098 oKerberosAuthentication,
Ben Lindstromec95ed92001-07-04 04:21:14 +000099#endif
100#if defined(AFS) || defined(KRB5)
101 oKerberosTgtPassing,
102#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000103#ifdef AFS
Ben Lindstromec95ed92001-07-04 04:21:14 +0000104 oAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000105#endif
Damien Miller95def091999-11-25 00:26:21 +1100106 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
107 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
108 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
109 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000110 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000111 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100112 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000113 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000114 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000115 oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000116 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
Damien Millera5539d22003-04-09 20:50:06 +1000117 oEnableSSHKeysign, oRekeyLimit,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000118 oDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000119} OpCodes;
120
121/* Textual representations of the tokens. */
122
Damien Miller95def091999-11-25 00:26:21 +1100123static struct {
124 const char *name;
125 OpCodes opcode;
126} keywords[] = {
127 { "forwardagent", oForwardAgent },
128 { "forwardx11", oForwardX11 },
Damien Millerd3a18572000-06-07 19:55:44 +1000129 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100130 { "gatewayports", oGatewayPorts },
131 { "useprivilegedport", oUsePrivilegedPort },
132 { "rhostsauthentication", oRhostsAuthentication },
133 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100134 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
135 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100136 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100137 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000138 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000139 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000140 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000141 { "challengeresponseauthentication", oChallengeResponseAuthentication },
142 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
143 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000144#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100145 { "kerberosauthentication", oKerberosAuthentication },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000146#endif
147#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100148 { "kerberostgtpassing", oKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000149#endif
150#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100151 { "afstokenpassing", oAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000152#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000153 { "fallbacktorsh", oDeprecated },
154 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100155 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100156 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100157 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000158 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100159 { "proxycommand", oProxyCommand },
160 { "port", oPort },
161 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000162 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000163 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000164 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100165 { "remoteforward", oRemoteForward },
166 { "localforward", oLocalForward },
167 { "user", oUser },
168 { "host", oHost },
169 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100170 { "globalknownhostsfile", oGlobalKnownHostsFile },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000171 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
Damien Millereba71ba2000-04-29 23:57:08 +1000172 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000173 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100174 { "connectionattempts", oConnectionAttempts },
175 { "batchmode", oBatchMode },
176 { "checkhostip", oCheckHostIP },
177 { "stricthostkeychecking", oStrictHostKeyChecking },
178 { "compression", oCompression },
179 { "compressionlevel", oCompressionLevel },
180 { "keepalive", oKeepAlives },
181 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100182 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000183 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000184 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000185 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000186 { "bindaddress", oBindAddress },
Ben Lindstromae996bf2001-08-06 21:27:53 +0000187 { "smartcarddevice", oSmartcardDevice },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100188 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000189 { "enablesshkeysign", oEnableSSHKeysign },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100190 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000191 { "rekeylimit", oRekeyLimit },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000192 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100193};
194
Damien Miller5428f641999-11-25 11:54:57 +1100195/*
196 * Adds a local TCP/IP port forward to options. Never returns if there is an
197 * error.
198 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000199
Damien Miller4af51302000-04-16 11:18:38 +1000200void
Damien Milleraae6c611999-12-06 11:47:28 +1100201add_local_forward(Options *options, u_short port, const char *host,
202 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000203{
Damien Miller95def091999-11-25 00:26:21 +1100204 Forward *fwd;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000205#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100206 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100207 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000208 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100209#endif
Damien Miller95def091999-11-25 00:26:21 +1100210 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
211 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
212 fwd = &options->local_forwards[options->num_local_forwards++];
213 fwd->port = port;
214 fwd->host = xstrdup(host);
215 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000216}
217
Damien Miller5428f641999-11-25 11:54:57 +1100218/*
219 * Adds a remote TCP/IP port forward to options. Never returns if there is
220 * an error.
221 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000222
Damien Miller4af51302000-04-16 11:18:38 +1000223void
Damien Milleraae6c611999-12-06 11:47:28 +1100224add_remote_forward(Options *options, u_short port, const char *host,
225 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000226{
Damien Miller95def091999-11-25 00:26:21 +1100227 Forward *fwd;
228 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
229 fatal("Too many remote forwards (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100230 SSH_MAX_FORWARDS_PER_DIRECTION);
Damien Miller95def091999-11-25 00:26:21 +1100231 fwd = &options->remote_forwards[options->num_remote_forwards++];
232 fwd->port = port;
233 fwd->host = xstrdup(host);
234 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000235}
236
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000237static void
238clear_forwardings(Options *options)
239{
240 int i;
241
242 for (i = 0; i < options->num_local_forwards; i++)
243 xfree(options->local_forwards[i].host);
244 options->num_local_forwards = 0;
245 for (i = 0; i < options->num_remote_forwards; i++)
246 xfree(options->remote_forwards[i].host);
247 options->num_remote_forwards = 0;
248}
249
Damien Miller5428f641999-11-25 11:54:57 +1100250/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000251 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100252 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000253
Damien Miller4af51302000-04-16 11:18:38 +1000254static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100255parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000256{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000257 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000258
Damien Miller95def091999-11-25 00:26:21 +1100259 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100260 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100261 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000262
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000263 error("%s: line %d: Bad configuration option: %s",
264 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100265 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000266}
267
Damien Miller5428f641999-11-25 11:54:57 +1100268/*
269 * Processes a single option line as used in the configuration files. This
270 * only sets those values that have not already been set.
271 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100272#define WHITESPACE " \t\r\n"
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000273
Damien Miller2ccf6611999-11-15 15:25:10 +1100274int
275process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100276 char *line, const char *filename, int linenum,
277 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000278{
Damien Miller61f08ac2003-02-24 11:56:27 +1100279 char buf[256], *s, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100280 int opcode, *intptr, value;
Damien Miller61f08ac2003-02-24 11:56:27 +1100281 size_t len;
Damien Milleraae6c611999-12-06 11:47:28 +1100282 u_short fwd_port, fwd_host_port;
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000283 char sfwd_host_port[6];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000284
Damien Millerc652cac2003-05-14 13:40:54 +1000285 /* Strip trailing whitespace */
286 for(len = strlen(line) - 1; len > 0; len--) {
287 if (strchr(WHITESPACE, line[len]) == NULL)
288 break;
289 line[len] = '\0';
290 }
291
Damien Millerbe484b52000-07-15 14:14:16 +1000292 s = line;
293 /* Get the keyword. (Each line is supposed to begin with a keyword). */
294 keyword = strdelim(&s);
295 /* Ignore leading whitespace. */
296 if (*keyword == '\0')
297 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000298 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100299 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000300
Damien Miller37023962000-07-11 17:31:38 +1000301 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000302
Damien Miller95def091999-11-25 00:26:21 +1100303 switch (opcode) {
304 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100305 /* don't panic, but count bad options */
306 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100307 /* NOTREACHED */
308 case oForwardAgent:
309 intptr = &options->forward_agent;
310parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000311 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000312 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100313 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
314 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000315 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100316 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000317 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100318 value = 0;
319 else
320 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
321 if (*activep && *intptr == -1)
322 *intptr = value;
323 break;
324
325 case oForwardX11:
326 intptr = &options->forward_x11;
327 goto parse_flag;
328
329 case oGatewayPorts:
330 intptr = &options->gateway_ports;
331 goto parse_flag;
332
333 case oUsePrivilegedPort:
334 intptr = &options->use_privileged_port;
335 goto parse_flag;
336
337 case oRhostsAuthentication:
338 intptr = &options->rhosts_authentication;
339 goto parse_flag;
340
341 case oPasswordAuthentication:
342 intptr = &options->password_authentication;
343 goto parse_flag;
344
Damien Miller874d77b2000-10-14 16:23:11 +1100345 case oKbdInteractiveAuthentication:
346 intptr = &options->kbd_interactive_authentication;
347 goto parse_flag;
348
349 case oKbdInteractiveDevices:
350 charptr = &options->kbd_interactive_devices;
351 goto parse_string;
352
Damien Miller0bc1bd82000-11-13 22:57:25 +1100353 case oPubkeyAuthentication:
354 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000355 goto parse_flag;
356
Damien Miller95def091999-11-25 00:26:21 +1100357 case oRSAAuthentication:
358 intptr = &options->rsa_authentication;
359 goto parse_flag;
360
361 case oRhostsRSAAuthentication:
362 intptr = &options->rhosts_rsa_authentication;
363 goto parse_flag;
364
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000365 case oHostbasedAuthentication:
366 intptr = &options->hostbased_authentication;
367 goto parse_flag;
368
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000369 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000370 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100371 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000372#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100373 case oKerberosAuthentication:
374 intptr = &options->kerberos_authentication;
375 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000376#endif
377#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100378 case oKerberosTgtPassing:
379 intptr = &options->kerberos_tgt_passing;
380 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000381#endif
382#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100383 case oAFSTokenPassing:
384 intptr = &options->afs_token_passing;
385 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000386#endif
Damien Miller95def091999-11-25 00:26:21 +1100387 case oBatchMode:
388 intptr = &options->batch_mode;
389 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000390
Damien Miller95def091999-11-25 00:26:21 +1100391 case oCheckHostIP:
392 intptr = &options->check_host_ip;
393 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000394
Damien Miller95def091999-11-25 00:26:21 +1100395 case oStrictHostKeyChecking:
396 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000397 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000398 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000399 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100400 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100401 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000402 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100403 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000404 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100405 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000406 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100407 value = 2;
408 else
409 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
410 if (*activep && *intptr == -1)
411 *intptr = value;
412 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000413
Damien Miller95def091999-11-25 00:26:21 +1100414 case oCompression:
415 intptr = &options->compression;
416 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000417
Damien Miller95def091999-11-25 00:26:21 +1100418 case oKeepAlives:
419 intptr = &options->keepalives;
420 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000421
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000422 case oNoHostAuthenticationForLocalhost:
423 intptr = &options->no_host_authentication_for_localhost;
424 goto parse_flag;
425
Damien Miller95def091999-11-25 00:26:21 +1100426 case oNumberOfPasswordPrompts:
427 intptr = &options->number_of_password_prompts;
428 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000429
Damien Miller95def091999-11-25 00:26:21 +1100430 case oCompressionLevel:
431 intptr = &options->compression_level;
432 goto parse_int;
433
Damien Millera5539d22003-04-09 20:50:06 +1000434 case oRekeyLimit:
435 intptr = &options->rekey_limit;
436 arg = strdelim(&s);
437 if (!arg || *arg == '\0')
438 fatal("%.200s line %d: Missing argument.", filename, linenum);
439 if (arg[0] < '0' || arg[0] > '9')
440 fatal("%.200s line %d: Bad number.", filename, linenum);
441 value = strtol(arg, &endofnumber, 10);
442 if (arg == endofnumber)
443 fatal("%.200s line %d: Bad number.", filename, linenum);
444 switch (toupper(*endofnumber)) {
445 case 'K':
446 value *= 1<<10;
447 break;
448 case 'M':
449 value *= 1<<20;
450 break;
451 case 'G':
452 value *= 1<<30;
453 break;
454 }
455 if (*activep && *intptr == -1)
456 *intptr = value;
457 break;
458
Damien Miller95def091999-11-25 00:26:21 +1100459 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000460 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000461 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100462 fatal("%.200s line %d: Missing argument.", filename, linenum);
463 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100464 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000465 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100466 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100467 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100468 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000469 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000470 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100471 }
472 break;
473
Damien Millerd3a18572000-06-07 19:55:44 +1000474 case oXAuthLocation:
475 charptr=&options->xauth_location;
476 goto parse_string;
477
Damien Miller95def091999-11-25 00:26:21 +1100478 case oUser:
479 charptr = &options->user;
480parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000481 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000482 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100483 fatal("%.200s line %d: Missing argument.", filename, linenum);
484 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000485 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100486 break;
487
488 case oGlobalKnownHostsFile:
489 charptr = &options->system_hostfile;
490 goto parse_string;
491
492 case oUserKnownHostsFile:
493 charptr = &options->user_hostfile;
494 goto parse_string;
495
Damien Millereba71ba2000-04-29 23:57:08 +1000496 case oGlobalKnownHostsFile2:
497 charptr = &options->system_hostfile2;
498 goto parse_string;
499
500 case oUserKnownHostsFile2:
501 charptr = &options->user_hostfile2;
502 goto parse_string;
503
Damien Miller95def091999-11-25 00:26:21 +1100504 case oHostName:
505 charptr = &options->hostname;
506 goto parse_string;
507
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000508 case oHostKeyAlias:
509 charptr = &options->host_key_alias;
510 goto parse_string;
511
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000512 case oPreferredAuthentications:
513 charptr = &options->preferred_authentications;
514 goto parse_string;
515
Ben Lindstrome0f88042001-04-30 13:06:24 +0000516 case oBindAddress:
517 charptr = &options->bind_address;
518 goto parse_string;
519
Ben Lindstromae996bf2001-08-06 21:27:53 +0000520 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000521 charptr = &options->smartcard_device;
522 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000523
Damien Miller95def091999-11-25 00:26:21 +1100524 case oProxyCommand:
525 charptr = &options->proxy_command;
Damien Miller61f08ac2003-02-24 11:56:27 +1100526 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +1100527 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +1100528 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +1100529 return 0;
530
531 case oPort:
532 intptr = &options->port;
533parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000534 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000535 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100536 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000537 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100538 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100539
540 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000541 value = strtol(arg, &endofnumber, 0);
542 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100543 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100544 if (*activep && *intptr == -1)
545 *intptr = value;
546 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000547
Damien Miller95def091999-11-25 00:26:21 +1100548 case oConnectionAttempts:
549 intptr = &options->connection_attempts;
550 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100551
Damien Miller95def091999-11-25 00:26:21 +1100552 case oCipher:
553 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000554 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000555 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000556 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000557 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100558 if (value == -1)
559 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100560 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100561 if (*activep && *intptr == -1)
562 *intptr = value;
563 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000564
Damien Miller78928792000-04-12 20:17:38 +1000565 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000566 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000567 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000568 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000569 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000570 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100571 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000572 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000573 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000574 break;
575
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000576 case oMacs:
577 arg = strdelim(&s);
578 if (!arg || *arg == '\0')
579 fatal("%.200s line %d: Missing argument.", filename, linenum);
580 if (!mac_valid(arg))
581 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100582 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000583 if (*activep && options->macs == NULL)
584 options->macs = xstrdup(arg);
585 break;
586
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000587 case oHostKeyAlgorithms:
588 arg = strdelim(&s);
589 if (!arg || *arg == '\0')
590 fatal("%.200s line %d: Missing argument.", filename, linenum);
591 if (!key_names_valid2(arg))
592 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100593 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000594 if (*activep && options->hostkeyalgorithms == NULL)
595 options->hostkeyalgorithms = xstrdup(arg);
596 break;
597
Damien Miller78928792000-04-12 20:17:38 +1000598 case oProtocol:
599 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000600 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000601 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000602 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000603 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000604 if (value == SSH_PROTO_UNKNOWN)
605 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100606 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000607 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
608 *intptr = value;
609 break;
610
Damien Miller95def091999-11-25 00:26:21 +1100611 case oLogLevel:
612 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000613 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000614 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100615 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000616 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100617 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100618 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100619 *intptr = (LogLevel) value;
620 break;
621
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000622 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100623 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000624 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000625 if (!arg || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000626 fatal("%.200s line %d: Missing port argument.",
627 filename, linenum);
628 if ((fwd_port = a2port(arg)) == 0)
629 fatal("%.200s line %d: Bad listen port.",
630 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000631 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000632 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100633 fatal("%.200s line %d: Missing second argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000634 filename, linenum);
635 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
636 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
637 fatal("%.200s line %d: Bad forwarding specification.",
638 filename, linenum);
639 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
640 fatal("%.200s line %d: Bad forwarding port.",
641 filename, linenum);
642 if (*activep) {
643 if (opcode == oLocalForward)
644 add_local_forward(options, fwd_port, buf,
645 fwd_host_port);
646 else if (opcode == oRemoteForward)
647 add_remote_forward(options, fwd_port, buf,
648 fwd_host_port);
649 }
Damien Miller95def091999-11-25 00:26:21 +1100650 break;
651
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000652 case oDynamicForward:
653 arg = strdelim(&s);
654 if (!arg || *arg == '\0')
655 fatal("%.200s line %d: Missing port argument.",
656 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000657 fwd_port = a2port(arg);
658 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000659 fatal("%.200s line %d: Badly formatted port number.",
660 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000661 if (*activep)
662 add_local_forward(options, fwd_port, "socks4", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000663 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000664
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000665 case oClearAllForwardings:
666 intptr = &options->clear_forwardings;
667 goto parse_flag;
668
Damien Miller95def091999-11-25 00:26:21 +1100669 case oHost:
670 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000671 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000672 if (match_pattern(host, arg)) {
673 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100674 *activep = 1;
675 break;
676 }
Damien Millerbe484b52000-07-15 14:14:16 +1000677 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100678 return 0;
679
680 case oEscapeChar:
681 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000682 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000683 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100684 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000685 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000686 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
687 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000688 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000689 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000690 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000691 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100692 else {
693 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100694 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100695 /* NOTREACHED */
696 value = 0; /* Avoid compiler warning. */
697 }
698 if (*activep && *intptr == -1)
699 *intptr = value;
700 break;
701
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000702 case oEnableSSHKeysign:
703 intptr = &options->enable_ssh_keysign;
704 goto parse_flag;
705
Ben Lindstrom4daea862002-06-09 20:04:02 +0000706 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000707 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +0000708 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000709 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +0000710
Damien Miller95def091999-11-25 00:26:21 +1100711 default:
712 fatal("process_config_line: Unimplemented opcode %d", opcode);
713 }
714
715 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000716 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000717 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100718 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000719 }
Damien Miller95def091999-11-25 00:26:21 +1100720 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000721}
722
723
Damien Miller5428f641999-11-25 11:54:57 +1100724/*
725 * Reads the config file and modifies the options accordingly. Options
726 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000727 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100728 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000729
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000730int
Damien Miller95def091999-11-25 00:26:21 +1100731read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000732{
Damien Miller95def091999-11-25 00:26:21 +1100733 FILE *f;
734 char line[1024];
735 int active, linenum;
736 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000737
Damien Miller95def091999-11-25 00:26:21 +1100738 /* Open the file. */
739 f = fopen(filename, "r");
740 if (!f)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000741 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000742
Damien Miller95def091999-11-25 00:26:21 +1100743 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000744
Damien Miller5428f641999-11-25 11:54:57 +1100745 /*
746 * Mark that we are now processing the options. This flag is turned
747 * on/off by Host specifications.
748 */
Damien Miller95def091999-11-25 00:26:21 +1100749 active = 1;
750 linenum = 0;
751 while (fgets(line, sizeof(line), f)) {
752 /* Update line number counter. */
753 linenum++;
754 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
755 bad_options++;
756 }
757 fclose(f);
758 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000759 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100760 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000761 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000762}
763
Damien Miller5428f641999-11-25 11:54:57 +1100764/*
765 * Initializes options to special values that indicate that they have not yet
766 * been set. Read_config_file will only set options with this value. Options
767 * are processed in the following order: command line, user config file,
768 * system config file. Last, fill_default_options is called.
769 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000770
Damien Miller4af51302000-04-16 11:18:38 +1000771void
Damien Miller95def091999-11-25 00:26:21 +1100772initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000773{
Damien Miller95def091999-11-25 00:26:21 +1100774 memset(options, 'X', sizeof(*options));
775 options->forward_agent = -1;
776 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000777 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100778 options->gateway_ports = -1;
779 options->use_privileged_port = -1;
780 options->rhosts_authentication = -1;
781 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100782 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000783 options->challenge_response_authentication = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000784#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100785 options->kerberos_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000786#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000787#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100788 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000789#endif
790#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100791 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000792#endif
Damien Miller95def091999-11-25 00:26:21 +1100793 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100794 options->kbd_interactive_authentication = -1;
795 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100796 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000797 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100798 options->batch_mode = -1;
799 options->check_host_ip = -1;
800 options->strict_host_key_checking = -1;
801 options->compression = -1;
802 options->keepalives = -1;
803 options->compression_level = -1;
804 options->port = -1;
805 options->connection_attempts = -1;
806 options->number_of_password_prompts = -1;
807 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000808 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000809 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000810 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000811 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100812 options->num_identity_files = 0;
813 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000814 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100815 options->proxy_command = NULL;
816 options->user = NULL;
817 options->escape_char = -1;
818 options->system_hostfile = NULL;
819 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000820 options->system_hostfile2 = NULL;
821 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100822 options->num_local_forwards = 0;
823 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000824 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100825 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000826 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000827 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000828 options->smartcard_device = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000829 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000830 options->no_host_authentication_for_localhost = - 1;
Damien Millera5539d22003-04-09 20:50:06 +1000831 options->rekey_limit = - 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000832}
833
Damien Miller5428f641999-11-25 11:54:57 +1100834/*
835 * Called after processing other sources of option data, this fills those
836 * options for which no value has been specified with their default values.
837 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000838
Damien Miller4af51302000-04-16 11:18:38 +1000839void
Damien Miller95def091999-11-25 00:26:21 +1100840fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000841{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000842 int len;
843
Damien Miller95def091999-11-25 00:26:21 +1100844 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000845 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100846 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100847 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000848 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000849 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100850 if (options->gateway_ports == -1)
851 options->gateway_ports = 0;
852 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000853 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100854 if (options->rhosts_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000855 options->rhosts_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100856 if (options->rsa_authentication == -1)
857 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100858 if (options->pubkey_authentication == -1)
859 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000860 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000861 options->challenge_response_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000862#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100863 if (options->kerberos_authentication == -1)
864 options->kerberos_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000865#endif
866#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100867 if (options->kerberos_tgt_passing == -1)
868 options->kerberos_tgt_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000869#endif
870#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100871 if (options->afs_token_passing == -1)
872 options->afs_token_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000873#endif
Damien Miller95def091999-11-25 00:26:21 +1100874 if (options->password_authentication == -1)
875 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100876 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000877 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100878 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000879 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000880 if (options->hostbased_authentication == -1)
881 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100882 if (options->batch_mode == -1)
883 options->batch_mode = 0;
884 if (options->check_host_ip == -1)
885 options->check_host_ip = 1;
886 if (options->strict_host_key_checking == -1)
887 options->strict_host_key_checking = 2; /* 2 is default */
888 if (options->compression == -1)
889 options->compression = 0;
890 if (options->keepalives == -1)
891 options->keepalives = 1;
892 if (options->compression_level == -1)
893 options->compression_level = 6;
894 if (options->port == -1)
895 options->port = 0; /* Filled in ssh_connect. */
896 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000897 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100898 if (options->number_of_password_prompts == -1)
899 options->number_of_password_prompts = 3;
900 /* Selected in ssh_login(). */
901 if (options->cipher == -1)
902 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000903 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000904 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000905 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000906 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000907 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100908 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100909 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000910 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100911 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000912 xmalloc(len);
913 snprintf(options->identity_files[options->num_identity_files++],
914 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100915 }
916 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000917 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
918 options->identity_files[options->num_identity_files] =
919 xmalloc(len);
920 snprintf(options->identity_files[options->num_identity_files++],
921 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
922
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000923 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100924 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000925 xmalloc(len);
926 snprintf(options->identity_files[options->num_identity_files++],
927 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100928 }
Damien Millereba71ba2000-04-29 23:57:08 +1000929 }
Damien Miller95def091999-11-25 00:26:21 +1100930 if (options->escape_char == -1)
931 options->escape_char = '~';
932 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000933 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100934 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000935 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000936 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000937 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000938 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000939 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +1100940 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000941 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000942 if (options->clear_forwardings == 1)
943 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000944 if (options->no_host_authentication_for_localhost == - 1)
945 options->no_host_authentication_for_localhost = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000946 if (options->enable_ssh_keysign == -1)
947 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +1000948 if (options->rekey_limit == -1)
949 options->rekey_limit = 0;
Damien Miller95def091999-11-25 00:26:21 +1100950 /* options->proxy_command should not be set by default */
951 /* options->user will be set in the main program if appropriate */
952 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000953 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000954 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000955}