blob: 6519ec667adbebaa86fc7b14899b6e20e02cb620 [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 Lindstromf9cedb92001-08-06 21:07:11 +000015RCSID("$OpenBSD: readconf.c,v 1.84 2001/07/25 14:35:18 markus Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016
17#include "ssh.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100018#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100019#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000020#include "cipher.h"
21#include "pathnames.h"
22#include "log.h"
23#include "readconf.h"
24#include "match.h"
25#include "misc.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000026#include "kex.h"
27#include "mac.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100028
29/* Format of the configuration file:
30
31 # Configuration data is parsed as follows:
32 # 1. command line options
33 # 2. user-specific file
34 # 3. system-wide file
35 # Any configuration value is only changed the first time it is set.
36 # Thus, host-specific definitions should be at the beginning of the
37 # configuration file, and defaults at the end.
38
39 # Host-specific declarations. These may override anything above. A single
40 # host may match multiple declarations; these are processed in the order
41 # that they are given in.
42
43 Host *.ngs.fi ngs.fi
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,
Ben Lindstromec95ed92001-07-04 04:21:14 +000099#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100100 oKerberosAuthentication,
Ben Lindstromec95ed92001-07-04 04:21:14 +0000101#endif
102#if defined(AFS) || defined(KRB5)
103 oKerberosTgtPassing,
104#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000105#ifdef AFS
Ben Lindstromec95ed92001-07-04 04:21:14 +0000106 oAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000107#endif
Damien Miller95def091999-11-25 00:26:21 +1100108 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
109 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
110 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
111 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000112 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000113 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100114 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000115 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000116 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
Ben Lindstrome0f88042001-04-30 13:06:24 +0000117 oHostKeyAlgorithms, oBindAddress
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000118} OpCodes;
119
120/* Textual representations of the tokens. */
121
Damien Miller95def091999-11-25 00:26:21 +1100122static struct {
123 const char *name;
124 OpCodes opcode;
125} keywords[] = {
126 { "forwardagent", oForwardAgent },
127 { "forwardx11", oForwardX11 },
Damien Millerd3a18572000-06-07 19:55:44 +1000128 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100129 { "gatewayports", oGatewayPorts },
130 { "useprivilegedport", oUsePrivilegedPort },
131 { "rhostsauthentication", oRhostsAuthentication },
132 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100133 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
134 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100135 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100136 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000137 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000138 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000139 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000140 { "challengeresponseauthentication", oChallengeResponseAuthentication },
141 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
142 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000143#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100144 { "kerberosauthentication", oKerberosAuthentication },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000145#endif
146#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100147 { "kerberostgtpassing", oKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000148#endif
149#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100150 { "afstokenpassing", oAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000151#endif
Damien Miller95def091999-11-25 00:26:21 +1100152 { "fallbacktorsh", oFallBackToRsh },
153 { "usersh", oUseRsh },
154 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100155 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100156 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000157 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100158 { "proxycommand", oProxyCommand },
159 { "port", oPort },
160 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000161 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000162 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000163 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100164 { "remoteforward", oRemoteForward },
165 { "localforward", oLocalForward },
166 { "user", oUser },
167 { "host", oHost },
168 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100169 { "globalknownhostsfile", oGlobalKnownHostsFile },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000170 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
Damien Millereba71ba2000-04-29 23:57:08 +1000171 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000172 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100173 { "connectionattempts", oConnectionAttempts },
174 { "batchmode", oBatchMode },
175 { "checkhostip", oCheckHostIP },
176 { "stricthostkeychecking", oStrictHostKeyChecking },
177 { "compression", oCompression },
178 { "compressionlevel", oCompressionLevel },
179 { "keepalive", oKeepAlives },
180 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100181 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000182 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000183 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000184 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000185 { "bindaddress", oBindAddress },
Damien Miller95def091999-11-25 00:26:21 +1100186 { NULL, 0 }
Damien Miller5ce662a1999-11-11 17:57:39 +1100187};
188
Damien Miller5428f641999-11-25 11:54:57 +1100189/*
190 * Adds a local TCP/IP port forward to options. Never returns if there is an
191 * error.
192 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000193
Damien Miller4af51302000-04-16 11:18:38 +1000194void
Damien Milleraae6c611999-12-06 11:47:28 +1100195add_local_forward(Options *options, u_short port, const char *host,
196 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000197{
Damien Miller95def091999-11-25 00:26:21 +1100198 Forward *fwd;
Damien Millerbac2d8a2000-09-05 16:13:06 +1100199#ifndef HAVE_CYGWIN
Damien Miller95def091999-11-25 00:26:21 +1100200 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100201 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000202 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100203#endif
Damien Miller95def091999-11-25 00:26:21 +1100204 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
205 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
206 fwd = &options->local_forwards[options->num_local_forwards++];
207 fwd->port = port;
208 fwd->host = xstrdup(host);
209 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000210}
211
Damien Miller5428f641999-11-25 11:54:57 +1100212/*
213 * Adds a remote TCP/IP port forward to options. Never returns if there is
214 * an error.
215 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000216
Damien Miller4af51302000-04-16 11:18:38 +1000217void
Damien Milleraae6c611999-12-06 11:47:28 +1100218add_remote_forward(Options *options, u_short port, const char *host,
219 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000220{
Damien Miller95def091999-11-25 00:26:21 +1100221 Forward *fwd;
222 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
223 fatal("Too many remote forwards (max %d).",
224 SSH_MAX_FORWARDS_PER_DIRECTION);
225 fwd = &options->remote_forwards[options->num_remote_forwards++];
226 fwd->port = port;
227 fwd->host = xstrdup(host);
228 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000229}
230
Damien Miller5428f641999-11-25 11:54:57 +1100231/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000232 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100233 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000234
Damien Miller4af51302000-04-16 11:18:38 +1000235static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100236parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000237{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000238 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000239
Damien Miller95def091999-11-25 00:26:21 +1100240 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100241 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100242 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000243
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000244 error("%s: line %d: Bad configuration option: %s",
245 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100246 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000247}
248
Damien Miller5428f641999-11-25 11:54:57 +1100249/*
250 * Processes a single option line as used in the configuration files. This
251 * only sets those values that have not already been set.
252 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000253
Damien Miller2ccf6611999-11-15 15:25:10 +1100254int
255process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100256 char *line, const char *filename, int linenum,
257 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000258{
Ben Lindstromc88785e2001-08-06 20:47:23 +0000259 char buf[256], *s, *string = NULL, **charptr, *endofnumber, *keyword,
260 *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100261 int opcode, *intptr, value;
262 u_short fwd_port, fwd_host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000263
Damien Millerbe484b52000-07-15 14:14:16 +1000264 s = line;
265 /* Get the keyword. (Each line is supposed to begin with a keyword). */
266 keyword = strdelim(&s);
267 /* Ignore leading whitespace. */
268 if (*keyword == '\0')
269 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000270 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100271 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000272
Damien Miller37023962000-07-11 17:31:38 +1000273 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000274
Damien Miller95def091999-11-25 00:26:21 +1100275 switch (opcode) {
276 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100277 /* don't panic, but count bad options */
278 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100279 /* NOTREACHED */
280 case oForwardAgent:
281 intptr = &options->forward_agent;
282parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000283 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000284 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100285 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
286 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000287 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100288 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000289 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100290 value = 0;
291 else
292 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
293 if (*activep && *intptr == -1)
294 *intptr = value;
295 break;
296
297 case oForwardX11:
298 intptr = &options->forward_x11;
299 goto parse_flag;
300
301 case oGatewayPorts:
302 intptr = &options->gateway_ports;
303 goto parse_flag;
304
305 case oUsePrivilegedPort:
306 intptr = &options->use_privileged_port;
307 goto parse_flag;
308
309 case oRhostsAuthentication:
310 intptr = &options->rhosts_authentication;
311 goto parse_flag;
312
313 case oPasswordAuthentication:
314 intptr = &options->password_authentication;
315 goto parse_flag;
316
Damien Miller874d77b2000-10-14 16:23:11 +1100317 case oKbdInteractiveAuthentication:
318 intptr = &options->kbd_interactive_authentication;
319 goto parse_flag;
320
321 case oKbdInteractiveDevices:
322 charptr = &options->kbd_interactive_devices;
323 goto parse_string;
324
Damien Miller0bc1bd82000-11-13 22:57:25 +1100325 case oPubkeyAuthentication:
326 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000327 goto parse_flag;
328
Damien Miller95def091999-11-25 00:26:21 +1100329 case oRSAAuthentication:
330 intptr = &options->rsa_authentication;
331 goto parse_flag;
332
333 case oRhostsRSAAuthentication:
334 intptr = &options->rhosts_rsa_authentication;
335 goto parse_flag;
336
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000337 case oHostbasedAuthentication:
338 intptr = &options->hostbased_authentication;
339 goto parse_flag;
340
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000341 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000342 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100343 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000344#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100345 case oKerberosAuthentication:
346 intptr = &options->kerberos_authentication;
347 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000348#endif
349#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100350 case oKerberosTgtPassing:
351 intptr = &options->kerberos_tgt_passing;
352 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000353#endif
354#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100355 case oAFSTokenPassing:
356 intptr = &options->afs_token_passing;
357 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000358#endif
Damien Miller95def091999-11-25 00:26:21 +1100359 case oFallBackToRsh:
360 intptr = &options->fallback_to_rsh;
361 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000362
Damien Miller95def091999-11-25 00:26:21 +1100363 case oUseRsh:
364 intptr = &options->use_rsh;
365 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000366
Damien Miller95def091999-11-25 00:26:21 +1100367 case oBatchMode:
368 intptr = &options->batch_mode;
369 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000370
Damien Miller95def091999-11-25 00:26:21 +1100371 case oCheckHostIP:
372 intptr = &options->check_host_ip;
373 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000374
Damien Miller95def091999-11-25 00:26:21 +1100375 case oStrictHostKeyChecking:
376 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000377 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000378 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000379 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller95def091999-11-25 00:26:21 +1100380 filename, linenum);
381 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000382 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100383 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000384 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100385 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000386 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100387 value = 2;
388 else
389 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
390 if (*activep && *intptr == -1)
391 *intptr = value;
392 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000393
Damien Miller95def091999-11-25 00:26:21 +1100394 case oCompression:
395 intptr = &options->compression;
396 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000397
Damien Miller95def091999-11-25 00:26:21 +1100398 case oKeepAlives:
399 intptr = &options->keepalives;
400 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000401
Damien Miller95def091999-11-25 00:26:21 +1100402 case oNumberOfPasswordPrompts:
403 intptr = &options->number_of_password_prompts;
404 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000405
Damien Miller95def091999-11-25 00:26:21 +1100406 case oCompressionLevel:
407 intptr = &options->compression_level;
408 goto parse_int;
409
410 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000411 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000412 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100413 fatal("%.200s line %d: Missing argument.", filename, linenum);
414 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100415 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000416 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100417 fatal("%.200s line %d: Too many identity files specified (max %d).",
418 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100419 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000420 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000421 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100422 }
423 break;
424
Damien Millerd3a18572000-06-07 19:55:44 +1000425 case oXAuthLocation:
426 charptr=&options->xauth_location;
427 goto parse_string;
428
Damien Miller95def091999-11-25 00:26:21 +1100429 case oUser:
430 charptr = &options->user;
431parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000432 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000433 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100434 fatal("%.200s line %d: Missing argument.", filename, linenum);
435 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000436 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100437 break;
438
439 case oGlobalKnownHostsFile:
440 charptr = &options->system_hostfile;
441 goto parse_string;
442
443 case oUserKnownHostsFile:
444 charptr = &options->user_hostfile;
445 goto parse_string;
446
Damien Millereba71ba2000-04-29 23:57:08 +1000447 case oGlobalKnownHostsFile2:
448 charptr = &options->system_hostfile2;
449 goto parse_string;
450
451 case oUserKnownHostsFile2:
452 charptr = &options->user_hostfile2;
453 goto parse_string;
454
Damien Miller95def091999-11-25 00:26:21 +1100455 case oHostName:
456 charptr = &options->hostname;
457 goto parse_string;
458
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000459 case oHostKeyAlias:
460 charptr = &options->host_key_alias;
461 goto parse_string;
462
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000463 case oPreferredAuthentications:
464 charptr = &options->preferred_authentications;
465 goto parse_string;
466
Ben Lindstrome0f88042001-04-30 13:06:24 +0000467 case oBindAddress:
468 charptr = &options->bind_address;
469 goto parse_string;
470
Damien Miller95def091999-11-25 00:26:21 +1100471 case oProxyCommand:
472 charptr = &options->proxy_command;
Damien Millerbe484b52000-07-15 14:14:16 +1000473 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000474 string = xrealloc(string, strlen(string) + strlen(arg) + 2);
Damien Miller95def091999-11-25 00:26:21 +1100475 strcat(string, " ");
Damien Miller37023962000-07-11 17:31:38 +1000476 strcat(string, arg);
Damien Miller95def091999-11-25 00:26:21 +1100477 }
478 if (*activep && *charptr == NULL)
479 *charptr = string;
480 else
481 xfree(string);
482 return 0;
483
484 case oPort:
485 intptr = &options->port;
486parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000487 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000488 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100489 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000490 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100491 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100492
493 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000494 value = strtol(arg, &endofnumber, 0);
495 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100496 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100497 if (*activep && *intptr == -1)
498 *intptr = value;
499 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000500
Damien Miller95def091999-11-25 00:26:21 +1100501 case oConnectionAttempts:
502 intptr = &options->connection_attempts;
503 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100504
Damien Miller95def091999-11-25 00:26:21 +1100505 case oCipher:
506 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000507 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000508 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000509 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000510 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100511 if (value == -1)
512 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000513 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100514 if (*activep && *intptr == -1)
515 *intptr = value;
516 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000517
Damien Miller78928792000-04-12 20:17:38 +1000518 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000519 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000520 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000521 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000522 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000523 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000524 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000525 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000526 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000527 break;
528
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000529 case oMacs:
530 arg = strdelim(&s);
531 if (!arg || *arg == '\0')
532 fatal("%.200s line %d: Missing argument.", filename, linenum);
533 if (!mac_valid(arg))
534 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
535 filename, linenum, arg ? arg : "<NONE>");
536 if (*activep && options->macs == NULL)
537 options->macs = xstrdup(arg);
538 break;
539
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000540 case oHostKeyAlgorithms:
541 arg = strdelim(&s);
542 if (!arg || *arg == '\0')
543 fatal("%.200s line %d: Missing argument.", filename, linenum);
544 if (!key_names_valid2(arg))
545 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
546 filename, linenum, arg ? arg : "<NONE>");
547 if (*activep && options->hostkeyalgorithms == NULL)
548 options->hostkeyalgorithms = xstrdup(arg);
549 break;
550
Damien Miller78928792000-04-12 20:17:38 +1000551 case oProtocol:
552 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000553 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000554 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000555 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000556 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000557 if (value == SSH_PROTO_UNKNOWN)
558 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000559 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000560 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
561 *intptr = value;
562 break;
563
Damien Miller95def091999-11-25 00:26:21 +1100564 case oLogLevel:
565 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000566 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000567 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100568 if (value == (LogLevel) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000569 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000570 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100571 if (*activep && (LogLevel) * intptr == -1)
572 *intptr = (LogLevel) value;
573 break;
574
575 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000576 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000577 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100578 fatal("%.200s line %d: Missing argument.", filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000579 fwd_port = a2port(arg);
580 if (fwd_port == 0)
Damien Miller95def091999-11-25 00:26:21 +1100581 fatal("%.200s line %d: Badly formatted port number.",
582 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000583 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000584 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100585 fatal("%.200s line %d: Missing second argument.",
586 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000587 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
Damien Miller95def091999-11-25 00:26:21 +1100588 fatal("%.200s line %d: Badly formatted host:port.",
589 filename, linenum);
590 if (*activep)
591 add_remote_forward(options, fwd_port, buf, fwd_host_port);
592 break;
593
594 case oLocalForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000595 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000596 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100597 fatal("%.200s line %d: Missing argument.", filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000598 fwd_port = a2port(arg);
599 if (fwd_port == 0)
Damien Miller95def091999-11-25 00:26:21 +1100600 fatal("%.200s line %d: Badly formatted port number.",
601 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000602 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000603 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100604 fatal("%.200s line %d: Missing second argument.",
605 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000606 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
Damien Miller95def091999-11-25 00:26:21 +1100607 fatal("%.200s line %d: Badly formatted host:port.",
608 filename, linenum);
609 if (*activep)
610 add_local_forward(options, fwd_port, buf, fwd_host_port);
611 break;
612
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000613 case oDynamicForward:
614 arg = strdelim(&s);
615 if (!arg || *arg == '\0')
616 fatal("%.200s line %d: Missing port argument.",
617 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000618 fwd_port = a2port(arg);
619 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000620 fatal("%.200s line %d: Badly formatted port number.",
621 filename, linenum);
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000622 add_local_forward(options, fwd_port, "socks4", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000623 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000624
Damien Miller95def091999-11-25 00:26:21 +1100625 case oHost:
626 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000627 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000628 if (match_pattern(host, arg)) {
629 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100630 *activep = 1;
631 break;
632 }
Damien Millerbe484b52000-07-15 14:14:16 +1000633 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100634 return 0;
635
636 case oEscapeChar:
637 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000638 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000639 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100640 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000641 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000642 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
643 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000644 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000645 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000646 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000647 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100648 else {
649 fatal("%.200s line %d: Bad escape character.",
650 filename, linenum);
651 /* NOTREACHED */
652 value = 0; /* Avoid compiler warning. */
653 }
654 if (*activep && *intptr == -1)
655 *intptr = value;
656 break;
657
658 default:
659 fatal("process_config_line: Unimplemented opcode %d", opcode);
660 }
661
662 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000663 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000664 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
665 filename, linenum, arg);
666 }
Damien Miller95def091999-11-25 00:26:21 +1100667 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000668}
669
670
Damien Miller5428f641999-11-25 11:54:57 +1100671/*
672 * Reads the config file and modifies the options accordingly. Options
673 * should already be initialized before this call. This never returns if
674 * there is an error. If the file does not exist, this returns immediately.
675 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000676
Damien Miller4af51302000-04-16 11:18:38 +1000677void
Damien Miller95def091999-11-25 00:26:21 +1100678read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000679{
Damien Miller95def091999-11-25 00:26:21 +1100680 FILE *f;
681 char line[1024];
682 int active, linenum;
683 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000684
Damien Miller95def091999-11-25 00:26:21 +1100685 /* Open the file. */
686 f = fopen(filename, "r");
687 if (!f)
688 return;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000689
Damien Miller95def091999-11-25 00:26:21 +1100690 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000691
Damien Miller5428f641999-11-25 11:54:57 +1100692 /*
693 * Mark that we are now processing the options. This flag is turned
694 * on/off by Host specifications.
695 */
Damien Miller95def091999-11-25 00:26:21 +1100696 active = 1;
697 linenum = 0;
698 while (fgets(line, sizeof(line), f)) {
699 /* Update line number counter. */
700 linenum++;
701 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
702 bad_options++;
703 }
704 fclose(f);
705 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000706 fatal("%s: terminating, %d bad configuration options",
Damien Miller95def091999-11-25 00:26:21 +1100707 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000708}
709
Damien Miller5428f641999-11-25 11:54:57 +1100710/*
711 * Initializes options to special values that indicate that they have not yet
712 * been set. Read_config_file will only set options with this value. Options
713 * are processed in the following order: command line, user config file,
714 * system config file. Last, fill_default_options is called.
715 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000716
Damien Miller4af51302000-04-16 11:18:38 +1000717void
Damien Miller95def091999-11-25 00:26:21 +1100718initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000719{
Damien Miller95def091999-11-25 00:26:21 +1100720 memset(options, 'X', sizeof(*options));
721 options->forward_agent = -1;
722 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000723 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100724 options->gateway_ports = -1;
725 options->use_privileged_port = -1;
726 options->rhosts_authentication = -1;
727 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100728 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000729 options->challenge_response_authentication = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000730#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100731 options->kerberos_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000732#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000733#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100734 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000735#endif
736#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100737 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000738#endif
Damien Miller95def091999-11-25 00:26:21 +1100739 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100740 options->kbd_interactive_authentication = -1;
741 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100742 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000743 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100744 options->fallback_to_rsh = -1;
745 options->use_rsh = -1;
746 options->batch_mode = -1;
747 options->check_host_ip = -1;
748 options->strict_host_key_checking = -1;
749 options->compression = -1;
750 options->keepalives = -1;
751 options->compression_level = -1;
752 options->port = -1;
753 options->connection_attempts = -1;
754 options->number_of_password_prompts = -1;
755 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000756 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000757 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000758 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000759 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100760 options->num_identity_files = 0;
761 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000762 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100763 options->proxy_command = NULL;
764 options->user = NULL;
765 options->escape_char = -1;
766 options->system_hostfile = NULL;
767 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000768 options->system_hostfile2 = NULL;
769 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100770 options->num_local_forwards = 0;
771 options->num_remote_forwards = 0;
772 options->log_level = (LogLevel) - 1;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000773 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000774 options->bind_address = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000775}
776
Damien Miller5428f641999-11-25 11:54:57 +1100777/*
778 * Called after processing other sources of option data, this fills those
779 * options for which no value has been specified with their default values.
780 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000781
Damien Miller4af51302000-04-16 11:18:38 +1000782void
Damien Miller95def091999-11-25 00:26:21 +1100783fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000784{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000785 int len;
786
Damien Miller95def091999-11-25 00:26:21 +1100787 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000788 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100789 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100790 options->forward_x11 = 0;
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000791#ifdef _PATH_XAUTH
Damien Millerd3a18572000-06-07 19:55:44 +1000792 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000793 options->xauth_location = _PATH_XAUTH;
794#endif
Damien Miller95def091999-11-25 00:26:21 +1100795 if (options->gateway_ports == -1)
796 options->gateway_ports = 0;
797 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000798 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100799 if (options->rhosts_authentication == -1)
800 options->rhosts_authentication = 1;
801 if (options->rsa_authentication == -1)
802 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100803 if (options->pubkey_authentication == -1)
804 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000805 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000806 options->challenge_response_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000807#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100808 if (options->kerberos_authentication == -1)
809 options->kerberos_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000810#endif
811#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100812 if (options->kerberos_tgt_passing == -1)
813 options->kerberos_tgt_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000814#endif
815#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100816 if (options->afs_token_passing == -1)
817 options->afs_token_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000818#endif
Damien Miller95def091999-11-25 00:26:21 +1100819 if (options->password_authentication == -1)
820 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100821 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000822 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100823 if (options->rhosts_rsa_authentication == -1)
824 options->rhosts_rsa_authentication = 1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000825 if (options->hostbased_authentication == -1)
826 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100827 if (options->fallback_to_rsh == -1)
Damien Miller182ee6e2000-07-12 09:45:27 +1000828 options->fallback_to_rsh = 0;
Damien Miller95def091999-11-25 00:26:21 +1100829 if (options->use_rsh == -1)
830 options->use_rsh = 0;
831 if (options->batch_mode == -1)
832 options->batch_mode = 0;
833 if (options->check_host_ip == -1)
834 options->check_host_ip = 1;
835 if (options->strict_host_key_checking == -1)
836 options->strict_host_key_checking = 2; /* 2 is default */
837 if (options->compression == -1)
838 options->compression = 0;
839 if (options->keepalives == -1)
840 options->keepalives = 1;
841 if (options->compression_level == -1)
842 options->compression_level = 6;
843 if (options->port == -1)
844 options->port = 0; /* Filled in ssh_connect. */
845 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000846 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100847 if (options->number_of_password_prompts == -1)
848 options->number_of_password_prompts = 3;
849 /* Selected in ssh_login(). */
850 if (options->cipher == -1)
851 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000852 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000853 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000854 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000855 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000856 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100857 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100858 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000859 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100860 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000861 xmalloc(len);
862 snprintf(options->identity_files[options->num_identity_files++],
863 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100864 }
865 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000866 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
867 options->identity_files[options->num_identity_files] =
868 xmalloc(len);
869 snprintf(options->identity_files[options->num_identity_files++],
870 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
871
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000872 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100873 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000874 xmalloc(len);
875 snprintf(options->identity_files[options->num_identity_files++],
876 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100877 }
Damien Millereba71ba2000-04-29 23:57:08 +1000878 }
Damien Miller95def091999-11-25 00:26:21 +1100879 if (options->escape_char == -1)
880 options->escape_char = '~';
881 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000882 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100883 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000884 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000885 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000886 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000887 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000888 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Miller95def091999-11-25 00:26:21 +1100889 if (options->log_level == (LogLevel) - 1)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000890 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100891 /* options->proxy_command should not be set by default */
892 /* options->user will be set in the main program if appropriate */
893 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000894 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000895 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000896}