blob: e9aa1818af2a9993b29374e26f06cc92e0d67aae [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 Lindstrom2b1f71b2001-06-05 20:32:21 +000015RCSID("$OpenBSD: readconf.c,v 1.79 2001/05/24 18:57:53 stevesk 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
44 FallBackToRsh no
45
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
68 UseRsh yes
69
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
82 FallBackToRsh no
83 UseRsh no
84 StrictHostKeyChecking yes
85 KeepAlives no
86 IdentityFile ~/.ssh/identity
87 Port 22
88 EscapeChar ~
89
90*/
91
92/* Keyword tokens. */
93
Damien Miller95def091999-11-25 00:26:21 +110094typedef enum {
95 oBadOption,
96 oForwardAgent, oForwardX11, oGatewayPorts, oRhostsAuthentication,
97 oPasswordAuthentication, oRSAAuthentication, oFallBackToRsh, oUseRsh,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000098 oChallengeResponseAuthentication, oXAuthLocation,
Damien Millerd4a8b7e1999-10-27 13:42:43 +100099#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100100 oKerberosAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000101#endif /* KRB4 */
102#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100103 oKerberosTgtPassing, oAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000104#endif
Damien Miller95def091999-11-25 00:26:21 +1100105 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
106 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
107 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
108 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000109 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000110 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100111 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000112 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000113 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
Ben Lindstrome0f88042001-04-30 13:06:24 +0000114 oHostKeyAlgorithms, oBindAddress
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000115} OpCodes;
116
117/* Textual representations of the tokens. */
118
Damien Miller95def091999-11-25 00:26:21 +1100119static struct {
120 const char *name;
121 OpCodes opcode;
122} keywords[] = {
123 { "forwardagent", oForwardAgent },
124 { "forwardx11", oForwardX11 },
Damien Millerd3a18572000-06-07 19:55:44 +1000125 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100126 { "gatewayports", oGatewayPorts },
127 { "useprivilegedport", oUsePrivilegedPort },
128 { "rhostsauthentication", oRhostsAuthentication },
129 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100130 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
131 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100132 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100133 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000134 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000135 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000136 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000137 { "challengeresponseauthentication", oChallengeResponseAuthentication },
138 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
139 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000140#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100141 { "kerberosauthentication", oKerberosAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000142#endif /* KRB4 */
143#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100144 { "kerberostgtpassing", oKerberosTgtPassing },
145 { "afstokenpassing", oAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000146#endif
Damien Miller95def091999-11-25 00:26:21 +1100147 { "fallbacktorsh", oFallBackToRsh },
148 { "usersh", oUseRsh },
149 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100150 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100151 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000152 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100153 { "proxycommand", oProxyCommand },
154 { "port", oPort },
155 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000156 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000157 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000158 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100159 { "remoteforward", oRemoteForward },
160 { "localforward", oLocalForward },
161 { "user", oUser },
162 { "host", oHost },
163 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100164 { "globalknownhostsfile", oGlobalKnownHostsFile },
165 { "userknownhostsfile", oUserKnownHostsFile },
Damien Millereba71ba2000-04-29 23:57:08 +1000166 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
167 { "userknownhostsfile2", oUserKnownHostsFile2 },
Damien Miller95def091999-11-25 00:26:21 +1100168 { "connectionattempts", oConnectionAttempts },
169 { "batchmode", oBatchMode },
170 { "checkhostip", oCheckHostIP },
171 { "stricthostkeychecking", oStrictHostKeyChecking },
172 { "compression", oCompression },
173 { "compressionlevel", oCompressionLevel },
174 { "keepalive", oKeepAlives },
175 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100176 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000177 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000178 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000179 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000180 { "bindaddress", oBindAddress },
Damien Miller95def091999-11-25 00:26:21 +1100181 { NULL, 0 }
Damien Miller5ce662a1999-11-11 17:57:39 +1100182};
183
Damien Miller5428f641999-11-25 11:54:57 +1100184/*
185 * Adds a local TCP/IP port forward to options. Never returns if there is an
186 * error.
187 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000188
Damien Miller4af51302000-04-16 11:18:38 +1000189void
Damien Milleraae6c611999-12-06 11:47:28 +1100190add_local_forward(Options *options, u_short port, const char *host,
191 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000192{
Damien Miller95def091999-11-25 00:26:21 +1100193 Forward *fwd;
Damien Millerbac2d8a2000-09-05 16:13:06 +1100194#ifndef HAVE_CYGWIN
Damien Miller95def091999-11-25 00:26:21 +1100195 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100196 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000197 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100198#endif
Damien Miller95def091999-11-25 00:26:21 +1100199 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
200 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
201 fwd = &options->local_forwards[options->num_local_forwards++];
202 fwd->port = port;
203 fwd->host = xstrdup(host);
204 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000205}
206
Damien Miller5428f641999-11-25 11:54:57 +1100207/*
208 * Adds a remote TCP/IP port forward to options. Never returns if there is
209 * an error.
210 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000211
Damien Miller4af51302000-04-16 11:18:38 +1000212void
Damien Milleraae6c611999-12-06 11:47:28 +1100213add_remote_forward(Options *options, u_short port, const char *host,
214 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000215{
Damien Miller95def091999-11-25 00:26:21 +1100216 Forward *fwd;
217 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
218 fatal("Too many remote forwards (max %d).",
219 SSH_MAX_FORWARDS_PER_DIRECTION);
220 fwd = &options->remote_forwards[options->num_remote_forwards++];
221 fwd->port = port;
222 fwd->host = xstrdup(host);
223 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000224}
225
Damien Miller5428f641999-11-25 11:54:57 +1100226/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000227 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100228 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000229
Damien Miller4af51302000-04-16 11:18:38 +1000230static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100231parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000232{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000233 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000234
Damien Miller95def091999-11-25 00:26:21 +1100235 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100236 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100237 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000238
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000239 error("%s: line %d: Bad configuration option: %s",
240 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100241 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000242}
243
Damien Miller5428f641999-11-25 11:54:57 +1100244/*
245 * Processes a single option line as used in the configuration files. This
246 * only sets those values that have not already been set.
247 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000248
Damien Miller2ccf6611999-11-15 15:25:10 +1100249int
250process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100251 char *line, const char *filename, int linenum,
252 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000253{
Damien Miller37023962000-07-11 17:31:38 +1000254 char buf[256], *s, *string, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100255 int opcode, *intptr, value;
256 u_short fwd_port, fwd_host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000257
Damien Millerbe484b52000-07-15 14:14:16 +1000258 s = line;
259 /* Get the keyword. (Each line is supposed to begin with a keyword). */
260 keyword = strdelim(&s);
261 /* Ignore leading whitespace. */
262 if (*keyword == '\0')
263 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000264 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100265 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000266
Damien Miller37023962000-07-11 17:31:38 +1000267 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000268
Damien Miller95def091999-11-25 00:26:21 +1100269 switch (opcode) {
270 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100271 /* don't panic, but count bad options */
272 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100273 /* NOTREACHED */
274 case oForwardAgent:
275 intptr = &options->forward_agent;
276parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000277 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000278 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100279 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
280 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000281 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100282 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000283 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100284 value = 0;
285 else
286 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
287 if (*activep && *intptr == -1)
288 *intptr = value;
289 break;
290
291 case oForwardX11:
292 intptr = &options->forward_x11;
293 goto parse_flag;
294
295 case oGatewayPorts:
296 intptr = &options->gateway_ports;
297 goto parse_flag;
298
299 case oUsePrivilegedPort:
300 intptr = &options->use_privileged_port;
301 goto parse_flag;
302
303 case oRhostsAuthentication:
304 intptr = &options->rhosts_authentication;
305 goto parse_flag;
306
307 case oPasswordAuthentication:
308 intptr = &options->password_authentication;
309 goto parse_flag;
310
Damien Miller874d77b2000-10-14 16:23:11 +1100311 case oKbdInteractiveAuthentication:
312 intptr = &options->kbd_interactive_authentication;
313 goto parse_flag;
314
315 case oKbdInteractiveDevices:
316 charptr = &options->kbd_interactive_devices;
317 goto parse_string;
318
Damien Miller0bc1bd82000-11-13 22:57:25 +1100319 case oPubkeyAuthentication:
320 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000321 goto parse_flag;
322
Damien Miller95def091999-11-25 00:26:21 +1100323 case oRSAAuthentication:
324 intptr = &options->rsa_authentication;
325 goto parse_flag;
326
327 case oRhostsRSAAuthentication:
328 intptr = &options->rhosts_rsa_authentication;
329 goto parse_flag;
330
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000331 case oHostbasedAuthentication:
332 intptr = &options->hostbased_authentication;
333 goto parse_flag;
334
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000335 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000336 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100337 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000338
339#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100340 case oKerberosAuthentication:
341 intptr = &options->kerberos_authentication;
342 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000343#endif /* KRB4 */
344
345#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100346 case oKerberosTgtPassing:
347 intptr = &options->kerberos_tgt_passing;
348 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000349
Damien Miller95def091999-11-25 00:26:21 +1100350 case oAFSTokenPassing:
351 intptr = &options->afs_token_passing;
352 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000353#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000354
Damien Miller95def091999-11-25 00:26:21 +1100355 case oFallBackToRsh:
356 intptr = &options->fallback_to_rsh;
357 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000358
Damien Miller95def091999-11-25 00:26:21 +1100359 case oUseRsh:
360 intptr = &options->use_rsh;
361 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000362
Damien Miller95def091999-11-25 00:26:21 +1100363 case oBatchMode:
364 intptr = &options->batch_mode;
365 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000366
Damien Miller95def091999-11-25 00:26:21 +1100367 case oCheckHostIP:
368 intptr = &options->check_host_ip;
369 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000370
Damien Miller95def091999-11-25 00:26:21 +1100371 case oStrictHostKeyChecking:
372 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000373 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000374 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000375 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller95def091999-11-25 00:26:21 +1100376 filename, linenum);
377 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000378 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100379 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000380 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100381 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000382 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100383 value = 2;
384 else
385 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
386 if (*activep && *intptr == -1)
387 *intptr = value;
388 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000389
Damien Miller95def091999-11-25 00:26:21 +1100390 case oCompression:
391 intptr = &options->compression;
392 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000393
Damien Miller95def091999-11-25 00:26:21 +1100394 case oKeepAlives:
395 intptr = &options->keepalives;
396 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000397
Damien Miller95def091999-11-25 00:26:21 +1100398 case oNumberOfPasswordPrompts:
399 intptr = &options->number_of_password_prompts;
400 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000401
Damien Miller95def091999-11-25 00:26:21 +1100402 case oCompressionLevel:
403 intptr = &options->compression_level;
404 goto parse_int;
405
406 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000407 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000408 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100409 fatal("%.200s line %d: Missing argument.", filename, linenum);
410 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100411 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000412 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100413 fatal("%.200s line %d: Too many identity files specified (max %d).",
414 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100415 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000416 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000417 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100418 }
419 break;
420
Damien Millerd3a18572000-06-07 19:55:44 +1000421 case oXAuthLocation:
422 charptr=&options->xauth_location;
423 goto parse_string;
424
Damien Miller95def091999-11-25 00:26:21 +1100425 case oUser:
426 charptr = &options->user;
427parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000428 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000429 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100430 fatal("%.200s line %d: Missing argument.", filename, linenum);
431 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000432 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100433 break;
434
435 case oGlobalKnownHostsFile:
436 charptr = &options->system_hostfile;
437 goto parse_string;
438
439 case oUserKnownHostsFile:
440 charptr = &options->user_hostfile;
441 goto parse_string;
442
Damien Millereba71ba2000-04-29 23:57:08 +1000443 case oGlobalKnownHostsFile2:
444 charptr = &options->system_hostfile2;
445 goto parse_string;
446
447 case oUserKnownHostsFile2:
448 charptr = &options->user_hostfile2;
449 goto parse_string;
450
Damien Miller95def091999-11-25 00:26:21 +1100451 case oHostName:
452 charptr = &options->hostname;
453 goto parse_string;
454
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000455 case oHostKeyAlias:
456 charptr = &options->host_key_alias;
457 goto parse_string;
458
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000459 case oPreferredAuthentications:
460 charptr = &options->preferred_authentications;
461 goto parse_string;
462
Ben Lindstrome0f88042001-04-30 13:06:24 +0000463 case oBindAddress:
464 charptr = &options->bind_address;
465 goto parse_string;
466
Damien Miller95def091999-11-25 00:26:21 +1100467 case oProxyCommand:
468 charptr = &options->proxy_command;
469 string = xstrdup("");
Damien Millerbe484b52000-07-15 14:14:16 +1000470 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000471 string = xrealloc(string, strlen(string) + strlen(arg) + 2);
Damien Miller95def091999-11-25 00:26:21 +1100472 strcat(string, " ");
Damien Miller37023962000-07-11 17:31:38 +1000473 strcat(string, arg);
Damien Miller95def091999-11-25 00:26:21 +1100474 }
475 if (*activep && *charptr == NULL)
476 *charptr = string;
477 else
478 xfree(string);
479 return 0;
480
481 case oPort:
482 intptr = &options->port;
483parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000484 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000485 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100486 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000487 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100488 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100489
490 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000491 value = strtol(arg, &endofnumber, 0);
492 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100493 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100494 if (*activep && *intptr == -1)
495 *intptr = value;
496 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000497
Damien Miller95def091999-11-25 00:26:21 +1100498 case oConnectionAttempts:
499 intptr = &options->connection_attempts;
500 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100501
Damien Miller95def091999-11-25 00:26:21 +1100502 case oCipher:
503 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000504 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000505 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000506 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000507 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100508 if (value == -1)
509 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000510 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100511 if (*activep && *intptr == -1)
512 *intptr = value;
513 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000514
Damien Miller78928792000-04-12 20:17:38 +1000515 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000516 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000517 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000518 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000519 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000520 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000521 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000522 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000523 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000524 break;
525
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000526 case oMacs:
527 arg = strdelim(&s);
528 if (!arg || *arg == '\0')
529 fatal("%.200s line %d: Missing argument.", filename, linenum);
530 if (!mac_valid(arg))
531 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
532 filename, linenum, arg ? arg : "<NONE>");
533 if (*activep && options->macs == NULL)
534 options->macs = xstrdup(arg);
535 break;
536
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000537 case oHostKeyAlgorithms:
538 arg = strdelim(&s);
539 if (!arg || *arg == '\0')
540 fatal("%.200s line %d: Missing argument.", filename, linenum);
541 if (!key_names_valid2(arg))
542 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
543 filename, linenum, arg ? arg : "<NONE>");
544 if (*activep && options->hostkeyalgorithms == NULL)
545 options->hostkeyalgorithms = xstrdup(arg);
546 break;
547
Damien Miller78928792000-04-12 20:17:38 +1000548 case oProtocol:
549 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000550 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000551 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000552 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000553 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000554 if (value == SSH_PROTO_UNKNOWN)
555 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000556 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000557 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
558 *intptr = value;
559 break;
560
Damien Miller95def091999-11-25 00:26:21 +1100561 case oLogLevel:
562 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000563 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000564 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100565 if (value == (LogLevel) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000566 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000567 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100568 if (*activep && (LogLevel) * intptr == -1)
569 *intptr = (LogLevel) value;
570 break;
571
572 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000573 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000574 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100575 fatal("%.200s line %d: Missing argument.", filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000576 fwd_port = a2port(arg);
577 if (fwd_port == 0)
Damien Miller95def091999-11-25 00:26:21 +1100578 fatal("%.200s line %d: Badly formatted port number.",
579 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000580 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000581 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100582 fatal("%.200s line %d: Missing second argument.",
583 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000584 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
Damien Miller95def091999-11-25 00:26:21 +1100585 fatal("%.200s line %d: Badly formatted host:port.",
586 filename, linenum);
587 if (*activep)
588 add_remote_forward(options, fwd_port, buf, fwd_host_port);
589 break;
590
591 case oLocalForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000592 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000593 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100594 fatal("%.200s line %d: Missing argument.", filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000595 fwd_port = a2port(arg);
596 if (fwd_port == 0)
Damien Miller95def091999-11-25 00:26:21 +1100597 fatal("%.200s line %d: Badly formatted port number.",
598 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000599 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000600 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100601 fatal("%.200s line %d: Missing second argument.",
602 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000603 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
Damien Miller95def091999-11-25 00:26:21 +1100604 fatal("%.200s line %d: Badly formatted host:port.",
605 filename, linenum);
606 if (*activep)
607 add_local_forward(options, fwd_port, buf, fwd_host_port);
608 break;
609
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000610 case oDynamicForward:
611 arg = strdelim(&s);
612 if (!arg || *arg == '\0')
613 fatal("%.200s line %d: Missing port argument.",
614 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000615 fwd_port = a2port(arg);
616 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000617 fatal("%.200s line %d: Badly formatted port number.",
618 filename, linenum);
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000619 add_local_forward(options, fwd_port, "socks4", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000620 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000621
Damien Miller95def091999-11-25 00:26:21 +1100622 case oHost:
623 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000624 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000625 if (match_pattern(host, arg)) {
626 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100627 *activep = 1;
628 break;
629 }
Damien Millerbe484b52000-07-15 14:14:16 +1000630 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100631 return 0;
632
633 case oEscapeChar:
634 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000635 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000636 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100637 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000638 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000639 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
640 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000641 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000642 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000643 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000644 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100645 else {
646 fatal("%.200s line %d: Bad escape character.",
647 filename, linenum);
648 /* NOTREACHED */
649 value = 0; /* Avoid compiler warning. */
650 }
651 if (*activep && *intptr == -1)
652 *intptr = value;
653 break;
654
655 default:
656 fatal("process_config_line: Unimplemented opcode %d", opcode);
657 }
658
659 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000660 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000661 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
662 filename, linenum, arg);
663 }
Damien Miller95def091999-11-25 00:26:21 +1100664 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000665}
666
667
Damien Miller5428f641999-11-25 11:54:57 +1100668/*
669 * Reads the config file and modifies the options accordingly. Options
670 * should already be initialized before this call. This never returns if
671 * there is an error. If the file does not exist, this returns immediately.
672 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000673
Damien Miller4af51302000-04-16 11:18:38 +1000674void
Damien Miller95def091999-11-25 00:26:21 +1100675read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000676{
Damien Miller95def091999-11-25 00:26:21 +1100677 FILE *f;
678 char line[1024];
679 int active, linenum;
680 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000681
Damien Miller95def091999-11-25 00:26:21 +1100682 /* Open the file. */
683 f = fopen(filename, "r");
684 if (!f)
685 return;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000686
Damien Miller95def091999-11-25 00:26:21 +1100687 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000688
Damien Miller5428f641999-11-25 11:54:57 +1100689 /*
690 * Mark that we are now processing the options. This flag is turned
691 * on/off by Host specifications.
692 */
Damien Miller95def091999-11-25 00:26:21 +1100693 active = 1;
694 linenum = 0;
695 while (fgets(line, sizeof(line), f)) {
696 /* Update line number counter. */
697 linenum++;
698 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
699 bad_options++;
700 }
701 fclose(f);
702 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000703 fatal("%s: terminating, %d bad configuration options",
Damien Miller95def091999-11-25 00:26:21 +1100704 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000705}
706
Damien Miller5428f641999-11-25 11:54:57 +1100707/*
708 * Initializes options to special values that indicate that they have not yet
709 * been set. Read_config_file will only set options with this value. Options
710 * are processed in the following order: command line, user config file,
711 * system config file. Last, fill_default_options is called.
712 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000713
Damien Miller4af51302000-04-16 11:18:38 +1000714void
Damien Miller95def091999-11-25 00:26:21 +1100715initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000716{
Damien Miller95def091999-11-25 00:26:21 +1100717 memset(options, 'X', sizeof(*options));
718 options->forward_agent = -1;
719 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000720 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100721 options->gateway_ports = -1;
722 options->use_privileged_port = -1;
723 options->rhosts_authentication = -1;
724 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100725 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000726 options->challenge_response_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000727#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100728 options->kerberos_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000729#endif
730#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100731 options->kerberos_tgt_passing = -1;
732 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000733#endif
Damien Miller95def091999-11-25 00:26:21 +1100734 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100735 options->kbd_interactive_authentication = -1;
736 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100737 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000738 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100739 options->fallback_to_rsh = -1;
740 options->use_rsh = -1;
741 options->batch_mode = -1;
742 options->check_host_ip = -1;
743 options->strict_host_key_checking = -1;
744 options->compression = -1;
745 options->keepalives = -1;
746 options->compression_level = -1;
747 options->port = -1;
748 options->connection_attempts = -1;
749 options->number_of_password_prompts = -1;
750 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000751 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000752 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000753 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000754 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100755 options->num_identity_files = 0;
756 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000757 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100758 options->proxy_command = NULL;
759 options->user = NULL;
760 options->escape_char = -1;
761 options->system_hostfile = NULL;
762 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000763 options->system_hostfile2 = NULL;
764 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100765 options->num_local_forwards = 0;
766 options->num_remote_forwards = 0;
767 options->log_level = (LogLevel) - 1;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000768 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000769 options->bind_address = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000770}
771
Damien Miller5428f641999-11-25 11:54:57 +1100772/*
773 * Called after processing other sources of option data, this fills those
774 * options for which no value has been specified with their default values.
775 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000776
Damien Miller4af51302000-04-16 11:18:38 +1000777void
Damien Miller95def091999-11-25 00:26:21 +1100778fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000779{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000780 int len;
781
Damien Miller95def091999-11-25 00:26:21 +1100782 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000783 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100784 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100785 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000786#ifdef XAUTH_PATH
787 if (options->xauth_location == NULL)
788 options->xauth_location = XAUTH_PATH;
789#endif /* XAUTH_PATH */
Damien Miller95def091999-11-25 00:26:21 +1100790 if (options->gateway_ports == -1)
791 options->gateway_ports = 0;
792 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000793 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100794 if (options->rhosts_authentication == -1)
795 options->rhosts_authentication = 1;
796 if (options->rsa_authentication == -1)
797 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100798 if (options->pubkey_authentication == -1)
799 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000800 if (options->challenge_response_authentication == -1)
801 options->challenge_response_authentication = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000802#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100803 if (options->kerberos_authentication == -1)
804 options->kerberos_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000805#endif /* KRB4 */
806#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100807 if (options->kerberos_tgt_passing == -1)
808 options->kerberos_tgt_passing = 1;
809 if (options->afs_token_passing == -1)
810 options->afs_token_passing = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000811#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100812 if (options->password_authentication == -1)
813 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100814 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000815 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100816 if (options->rhosts_rsa_authentication == -1)
817 options->rhosts_rsa_authentication = 1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000818 if (options->hostbased_authentication == -1)
819 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100820 if (options->fallback_to_rsh == -1)
Damien Miller182ee6e2000-07-12 09:45:27 +1000821 options->fallback_to_rsh = 0;
Damien Miller95def091999-11-25 00:26:21 +1100822 if (options->use_rsh == -1)
823 options->use_rsh = 0;
824 if (options->batch_mode == -1)
825 options->batch_mode = 0;
826 if (options->check_host_ip == -1)
827 options->check_host_ip = 1;
828 if (options->strict_host_key_checking == -1)
829 options->strict_host_key_checking = 2; /* 2 is default */
830 if (options->compression == -1)
831 options->compression = 0;
832 if (options->keepalives == -1)
833 options->keepalives = 1;
834 if (options->compression_level == -1)
835 options->compression_level = 6;
836 if (options->port == -1)
837 options->port = 0; /* Filled in ssh_connect. */
838 if (options->connection_attempts == -1)
839 options->connection_attempts = 4;
840 if (options->number_of_password_prompts == -1)
841 options->number_of_password_prompts = 3;
842 /* Selected in ssh_login(). */
843 if (options->cipher == -1)
844 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000845 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000846 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000847 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000848 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000849 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100850 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100851 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000852 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100853 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000854 xmalloc(len);
855 snprintf(options->identity_files[options->num_identity_files++],
856 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100857 }
858 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000859 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
860 options->identity_files[options->num_identity_files] =
861 xmalloc(len);
862 snprintf(options->identity_files[options->num_identity_files++],
863 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
864
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000865 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100866 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000867 xmalloc(len);
868 snprintf(options->identity_files[options->num_identity_files++],
869 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100870 }
Damien Millereba71ba2000-04-29 23:57:08 +1000871 }
Damien Miller95def091999-11-25 00:26:21 +1100872 if (options->escape_char == -1)
873 options->escape_char = '~';
874 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000875 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100876 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000877 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000878 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000879 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000880 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000881 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Miller95def091999-11-25 00:26:21 +1100882 if (options->log_level == (LogLevel) - 1)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000883 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100884 /* options->proxy_command should not be set by default */
885 /* options->user will be set in the main program if appropriate */
886 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000887 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000888 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000889}