blob: 7920ac86da3ffc05f312e11a151a9379865a7656 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11003 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11005 * Functions for reading the configuration files.
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerfcd93202002-02-05 12:26:34 +110015RCSID("$OpenBSD: readconf.c,v 1.95 2002/02/04 12:15:25 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 Lindstrom2b7a0e92001-09-20 00:57:55 +0000117 oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100118 oClearAllForwardings, oNoHostAuthenticationForLocalhost
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000119} OpCodes;
120
121/* Textual representations of the tokens. */
122
Damien Miller95def091999-11-25 00:26:21 +1100123static struct {
124 const char *name;
125 OpCodes opcode;
126} keywords[] = {
127 { "forwardagent", oForwardAgent },
128 { "forwardx11", oForwardX11 },
Damien Millerd3a18572000-06-07 19:55:44 +1000129 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100130 { "gatewayports", oGatewayPorts },
131 { "useprivilegedport", oUsePrivilegedPort },
132 { "rhostsauthentication", oRhostsAuthentication },
133 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100134 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
135 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100136 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100137 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000138 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000139 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000140 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000141 { "challengeresponseauthentication", oChallengeResponseAuthentication },
142 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
143 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000144#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100145 { "kerberosauthentication", oKerberosAuthentication },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000146#endif
147#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100148 { "kerberostgtpassing", oKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000149#endif
150#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100151 { "afstokenpassing", oAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000152#endif
Damien Miller95def091999-11-25 00:26:21 +1100153 { "fallbacktorsh", oFallBackToRsh },
154 { "usersh", oUseRsh },
155 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100156 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100157 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000158 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100159 { "proxycommand", oProxyCommand },
160 { "port", oPort },
161 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000162 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000163 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000164 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100165 { "remoteforward", oRemoteForward },
166 { "localforward", oLocalForward },
167 { "user", oUser },
168 { "host", oHost },
169 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100170 { "globalknownhostsfile", oGlobalKnownHostsFile },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000171 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
Damien Millereba71ba2000-04-29 23:57:08 +1000172 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000173 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100174 { "connectionattempts", oConnectionAttempts },
175 { "batchmode", oBatchMode },
176 { "checkhostip", oCheckHostIP },
177 { "stricthostkeychecking", oStrictHostKeyChecking },
178 { "compression", oCompression },
179 { "compressionlevel", oCompressionLevel },
180 { "keepalive", oKeepAlives },
181 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100182 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000183 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000184 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000185 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000186 { "bindaddress", oBindAddress },
Ben Lindstromae996bf2001-08-06 21:27:53 +0000187 { "smartcarddevice", oSmartcardDevice },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100188 { "clearallforwardings", oClearAllForwardings },
189 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000190 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100191};
192
Damien Miller5428f641999-11-25 11:54:57 +1100193/*
194 * Adds a local TCP/IP port forward to options. Never returns if there is an
195 * error.
196 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000197
Damien Miller4af51302000-04-16 11:18:38 +1000198void
Damien Milleraae6c611999-12-06 11:47:28 +1100199add_local_forward(Options *options, u_short port, const char *host,
200 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000201{
Damien Miller95def091999-11-25 00:26:21 +1100202 Forward *fwd;
Damien Millerbac2d8a2000-09-05 16:13:06 +1100203#ifndef HAVE_CYGWIN
Damien Miller95def091999-11-25 00:26:21 +1100204 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100205 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000206 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100207#endif
Damien Miller95def091999-11-25 00:26:21 +1100208 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
209 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
210 fwd = &options->local_forwards[options->num_local_forwards++];
211 fwd->port = port;
212 fwd->host = xstrdup(host);
213 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000214}
215
Damien Miller5428f641999-11-25 11:54:57 +1100216/*
217 * Adds a remote TCP/IP port forward to options. Never returns if there is
218 * an error.
219 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000220
Damien Miller4af51302000-04-16 11:18:38 +1000221void
Damien Milleraae6c611999-12-06 11:47:28 +1100222add_remote_forward(Options *options, u_short port, const char *host,
223 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000224{
Damien Miller95def091999-11-25 00:26:21 +1100225 Forward *fwd;
226 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
227 fatal("Too many remote forwards (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100228 SSH_MAX_FORWARDS_PER_DIRECTION);
Damien Miller95def091999-11-25 00:26:21 +1100229 fwd = &options->remote_forwards[options->num_remote_forwards++];
230 fwd->port = port;
231 fwd->host = xstrdup(host);
232 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000233}
234
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000235static void
236clear_forwardings(Options *options)
237{
238 int i;
239
240 for (i = 0; i < options->num_local_forwards; i++)
241 xfree(options->local_forwards[i].host);
242 options->num_local_forwards = 0;
243 for (i = 0; i < options->num_remote_forwards; i++)
244 xfree(options->remote_forwards[i].host);
245 options->num_remote_forwards = 0;
246}
247
Damien Miller5428f641999-11-25 11:54:57 +1100248/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000249 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100250 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000251
Damien Miller4af51302000-04-16 11:18:38 +1000252static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100253parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000254{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000255 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000256
Damien Miller95def091999-11-25 00:26:21 +1100257 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100258 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100259 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000260
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000261 error("%s: line %d: Bad configuration option: %s",
262 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100263 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000264}
265
Damien Miller5428f641999-11-25 11:54:57 +1100266/*
267 * Processes a single option line as used in the configuration files. This
268 * only sets those values that have not already been set.
269 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000270
Damien Miller2ccf6611999-11-15 15:25:10 +1100271int
272process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100273 char *line, const char *filename, int linenum,
274 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000275{
Ben Lindstromd0ff4082001-08-15 22:58:59 +0000276 char buf[256], *s, *string, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100277 int opcode, *intptr, value;
278 u_short fwd_port, fwd_host_port;
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000279 char sfwd_host_port[6];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000280
Damien Millerbe484b52000-07-15 14:14:16 +1000281 s = line;
282 /* Get the keyword. (Each line is supposed to begin with a keyword). */
283 keyword = strdelim(&s);
284 /* Ignore leading whitespace. */
285 if (*keyword == '\0')
286 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000287 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100288 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000289
Damien Miller37023962000-07-11 17:31:38 +1000290 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000291
Damien Miller95def091999-11-25 00:26:21 +1100292 switch (opcode) {
293 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100294 /* don't panic, but count bad options */
295 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100296 /* NOTREACHED */
297 case oForwardAgent:
298 intptr = &options->forward_agent;
299parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000300 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000301 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100302 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
303 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000304 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100305 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000306 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100307 value = 0;
308 else
309 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
310 if (*activep && *intptr == -1)
311 *intptr = value;
312 break;
313
314 case oForwardX11:
315 intptr = &options->forward_x11;
316 goto parse_flag;
317
318 case oGatewayPorts:
319 intptr = &options->gateway_ports;
320 goto parse_flag;
321
322 case oUsePrivilegedPort:
323 intptr = &options->use_privileged_port;
324 goto parse_flag;
325
326 case oRhostsAuthentication:
327 intptr = &options->rhosts_authentication;
328 goto parse_flag;
329
330 case oPasswordAuthentication:
331 intptr = &options->password_authentication;
332 goto parse_flag;
333
Damien Miller874d77b2000-10-14 16:23:11 +1100334 case oKbdInteractiveAuthentication:
335 intptr = &options->kbd_interactive_authentication;
336 goto parse_flag;
337
338 case oKbdInteractiveDevices:
339 charptr = &options->kbd_interactive_devices;
340 goto parse_string;
341
Damien Miller0bc1bd82000-11-13 22:57:25 +1100342 case oPubkeyAuthentication:
343 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000344 goto parse_flag;
345
Damien Miller95def091999-11-25 00:26:21 +1100346 case oRSAAuthentication:
347 intptr = &options->rsa_authentication;
348 goto parse_flag;
349
350 case oRhostsRSAAuthentication:
351 intptr = &options->rhosts_rsa_authentication;
352 goto parse_flag;
353
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000354 case oHostbasedAuthentication:
355 intptr = &options->hostbased_authentication;
356 goto parse_flag;
357
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000358 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000359 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100360 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000361#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100362 case oKerberosAuthentication:
363 intptr = &options->kerberos_authentication;
364 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000365#endif
366#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100367 case oKerberosTgtPassing:
368 intptr = &options->kerberos_tgt_passing;
369 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000370#endif
371#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100372 case oAFSTokenPassing:
373 intptr = &options->afs_token_passing;
374 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000375#endif
Damien Miller95def091999-11-25 00:26:21 +1100376 case oFallBackToRsh:
377 intptr = &options->fallback_to_rsh;
378 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000379
Damien Miller95def091999-11-25 00:26:21 +1100380 case oUseRsh:
381 intptr = &options->use_rsh;
382 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000383
Damien Miller95def091999-11-25 00:26:21 +1100384 case oBatchMode:
385 intptr = &options->batch_mode;
386 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000387
Damien Miller95def091999-11-25 00:26:21 +1100388 case oCheckHostIP:
389 intptr = &options->check_host_ip;
390 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000391
Damien Miller95def091999-11-25 00:26:21 +1100392 case oStrictHostKeyChecking:
393 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000394 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000395 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000396 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100397 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100398 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000399 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100400 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000401 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100402 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000403 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100404 value = 2;
405 else
406 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
407 if (*activep && *intptr == -1)
408 *intptr = value;
409 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000410
Damien Miller95def091999-11-25 00:26:21 +1100411 case oCompression:
412 intptr = &options->compression;
413 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000414
Damien Miller95def091999-11-25 00:26:21 +1100415 case oKeepAlives:
416 intptr = &options->keepalives;
417 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000418
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000419 case oNoHostAuthenticationForLocalhost:
420 intptr = &options->no_host_authentication_for_localhost;
421 goto parse_flag;
422
Damien Miller95def091999-11-25 00:26:21 +1100423 case oNumberOfPasswordPrompts:
424 intptr = &options->number_of_password_prompts;
425 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000426
Damien Miller95def091999-11-25 00:26:21 +1100427 case oCompressionLevel:
428 intptr = &options->compression_level;
429 goto parse_int;
430
431 case oIdentityFile:
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) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100436 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000437 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100438 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100439 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100440 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000441 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000442 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100443 }
444 break;
445
Damien Millerd3a18572000-06-07 19:55:44 +1000446 case oXAuthLocation:
447 charptr=&options->xauth_location;
448 goto parse_string;
449
Damien Miller95def091999-11-25 00:26:21 +1100450 case oUser:
451 charptr = &options->user;
452parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000453 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000454 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100455 fatal("%.200s line %d: Missing argument.", filename, linenum);
456 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000457 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100458 break;
459
460 case oGlobalKnownHostsFile:
461 charptr = &options->system_hostfile;
462 goto parse_string;
463
464 case oUserKnownHostsFile:
465 charptr = &options->user_hostfile;
466 goto parse_string;
467
Damien Millereba71ba2000-04-29 23:57:08 +1000468 case oGlobalKnownHostsFile2:
469 charptr = &options->system_hostfile2;
470 goto parse_string;
471
472 case oUserKnownHostsFile2:
473 charptr = &options->user_hostfile2;
474 goto parse_string;
475
Damien Miller95def091999-11-25 00:26:21 +1100476 case oHostName:
477 charptr = &options->hostname;
478 goto parse_string;
479
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000480 case oHostKeyAlias:
481 charptr = &options->host_key_alias;
482 goto parse_string;
483
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000484 case oPreferredAuthentications:
485 charptr = &options->preferred_authentications;
486 goto parse_string;
487
Ben Lindstrome0f88042001-04-30 13:06:24 +0000488 case oBindAddress:
489 charptr = &options->bind_address;
490 goto parse_string;
491
Ben Lindstromae996bf2001-08-06 21:27:53 +0000492 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000493 charptr = &options->smartcard_device;
494 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000495
Damien Miller95def091999-11-25 00:26:21 +1100496 case oProxyCommand:
497 charptr = &options->proxy_command;
Ben Lindstromd0ff4082001-08-15 22:58:59 +0000498 string = xstrdup("");
Damien Millerbe484b52000-07-15 14:14:16 +1000499 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000500 string = xrealloc(string, strlen(string) + strlen(arg) + 2);
Damien Miller95def091999-11-25 00:26:21 +1100501 strcat(string, " ");
Damien Miller37023962000-07-11 17:31:38 +1000502 strcat(string, arg);
Damien Miller95def091999-11-25 00:26:21 +1100503 }
504 if (*activep && *charptr == NULL)
505 *charptr = string;
506 else
507 xfree(string);
508 return 0;
509
510 case oPort:
511 intptr = &options->port;
512parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000513 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000514 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100515 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000516 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100517 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100518
519 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000520 value = strtol(arg, &endofnumber, 0);
521 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100522 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100523 if (*activep && *intptr == -1)
524 *intptr = value;
525 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000526
Damien Miller95def091999-11-25 00:26:21 +1100527 case oConnectionAttempts:
528 intptr = &options->connection_attempts;
529 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100530
Damien Miller95def091999-11-25 00:26:21 +1100531 case oCipher:
532 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000533 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000534 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000535 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000536 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100537 if (value == -1)
538 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100539 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100540 if (*activep && *intptr == -1)
541 *intptr = value;
542 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000543
Damien Miller78928792000-04-12 20:17:38 +1000544 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000545 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000546 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000547 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000548 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000549 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100550 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000551 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000552 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000553 break;
554
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000555 case oMacs:
556 arg = strdelim(&s);
557 if (!arg || *arg == '\0')
558 fatal("%.200s line %d: Missing argument.", filename, linenum);
559 if (!mac_valid(arg))
560 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100561 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000562 if (*activep && options->macs == NULL)
563 options->macs = xstrdup(arg);
564 break;
565
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000566 case oHostKeyAlgorithms:
567 arg = strdelim(&s);
568 if (!arg || *arg == '\0')
569 fatal("%.200s line %d: Missing argument.", filename, linenum);
570 if (!key_names_valid2(arg))
571 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100572 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000573 if (*activep && options->hostkeyalgorithms == NULL)
574 options->hostkeyalgorithms = xstrdup(arg);
575 break;
576
Damien Miller78928792000-04-12 20:17:38 +1000577 case oProtocol:
578 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000579 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000580 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000581 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000582 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000583 if (value == SSH_PROTO_UNKNOWN)
584 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100585 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000586 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
587 *intptr = value;
588 break;
589
Damien Miller95def091999-11-25 00:26:21 +1100590 case oLogLevel:
591 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000592 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000593 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100594 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000595 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100596 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100597 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100598 *intptr = (LogLevel) value;
599 break;
600
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000601 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100602 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000603 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000604 if (!arg || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000605 fatal("%.200s line %d: Missing port argument.",
606 filename, linenum);
607 if ((fwd_port = a2port(arg)) == 0)
608 fatal("%.200s line %d: Bad listen port.",
609 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000610 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000611 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100612 fatal("%.200s line %d: Missing second argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000613 filename, linenum);
614 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
615 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
616 fatal("%.200s line %d: Bad forwarding specification.",
617 filename, linenum);
618 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
619 fatal("%.200s line %d: Bad forwarding port.",
620 filename, linenum);
621 if (*activep) {
622 if (opcode == oLocalForward)
623 add_local_forward(options, fwd_port, buf,
624 fwd_host_port);
625 else if (opcode == oRemoteForward)
626 add_remote_forward(options, fwd_port, buf,
627 fwd_host_port);
628 }
Damien Miller95def091999-11-25 00:26:21 +1100629 break;
630
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000631 case oDynamicForward:
632 arg = strdelim(&s);
633 if (!arg || *arg == '\0')
634 fatal("%.200s line %d: Missing port argument.",
635 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000636 fwd_port = a2port(arg);
637 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000638 fatal("%.200s line %d: Badly formatted port number.",
639 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000640 if (*activep)
641 add_local_forward(options, fwd_port, "socks4", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000642 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000643
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000644 case oClearAllForwardings:
645 intptr = &options->clear_forwardings;
646 goto parse_flag;
647
Damien Miller95def091999-11-25 00:26:21 +1100648 case oHost:
649 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000650 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000651 if (match_pattern(host, arg)) {
652 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100653 *activep = 1;
654 break;
655 }
Damien Millerbe484b52000-07-15 14:14:16 +1000656 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100657 return 0;
658
659 case oEscapeChar:
660 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000661 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000662 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100663 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000664 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000665 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
666 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000667 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000668 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000669 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000670 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100671 else {
672 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100673 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100674 /* NOTREACHED */
675 value = 0; /* Avoid compiler warning. */
676 }
677 if (*activep && *intptr == -1)
678 *intptr = value;
679 break;
680
681 default:
682 fatal("process_config_line: Unimplemented opcode %d", opcode);
683 }
684
685 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000686 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000687 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100688 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000689 }
Damien Miller95def091999-11-25 00:26:21 +1100690 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000691}
692
693
Damien Miller5428f641999-11-25 11:54:57 +1100694/*
695 * Reads the config file and modifies the options accordingly. Options
696 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000697 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100698 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000699
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000700int
Damien Miller95def091999-11-25 00:26:21 +1100701read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000702{
Damien Miller95def091999-11-25 00:26:21 +1100703 FILE *f;
704 char line[1024];
705 int active, linenum;
706 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000707
Damien Miller95def091999-11-25 00:26:21 +1100708 /* Open the file. */
709 f = fopen(filename, "r");
710 if (!f)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000711 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000712
Damien Miller95def091999-11-25 00:26:21 +1100713 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000714
Damien Miller5428f641999-11-25 11:54:57 +1100715 /*
716 * Mark that we are now processing the options. This flag is turned
717 * on/off by Host specifications.
718 */
Damien Miller95def091999-11-25 00:26:21 +1100719 active = 1;
720 linenum = 0;
721 while (fgets(line, sizeof(line), f)) {
722 /* Update line number counter. */
723 linenum++;
724 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
725 bad_options++;
726 }
727 fclose(f);
728 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000729 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100730 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000731 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000732}
733
Damien Miller5428f641999-11-25 11:54:57 +1100734/*
735 * Initializes options to special values that indicate that they have not yet
736 * been set. Read_config_file will only set options with this value. Options
737 * are processed in the following order: command line, user config file,
738 * system config file. Last, fill_default_options is called.
739 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000740
Damien Miller4af51302000-04-16 11:18:38 +1000741void
Damien Miller95def091999-11-25 00:26:21 +1100742initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000743{
Damien Miller95def091999-11-25 00:26:21 +1100744 memset(options, 'X', sizeof(*options));
745 options->forward_agent = -1;
746 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000747 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100748 options->gateway_ports = -1;
749 options->use_privileged_port = -1;
750 options->rhosts_authentication = -1;
751 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100752 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000753 options->challenge_response_authentication = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000754#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100755 options->kerberos_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000756#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000757#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100758 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000759#endif
760#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100761 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000762#endif
Damien Miller95def091999-11-25 00:26:21 +1100763 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100764 options->kbd_interactive_authentication = -1;
765 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100766 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000767 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100768 options->fallback_to_rsh = -1;
769 options->use_rsh = -1;
770 options->batch_mode = -1;
771 options->check_host_ip = -1;
772 options->strict_host_key_checking = -1;
773 options->compression = -1;
774 options->keepalives = -1;
775 options->compression_level = -1;
776 options->port = -1;
777 options->connection_attempts = -1;
778 options->number_of_password_prompts = -1;
779 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000780 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000781 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000782 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000783 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100784 options->num_identity_files = 0;
785 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000786 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100787 options->proxy_command = NULL;
788 options->user = NULL;
789 options->escape_char = -1;
790 options->system_hostfile = NULL;
791 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000792 options->system_hostfile2 = NULL;
793 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100794 options->num_local_forwards = 0;
795 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000796 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100797 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000798 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000799 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000800 options->smartcard_device = NULL;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000801 options->no_host_authentication_for_localhost = - 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000802}
803
Damien Miller5428f641999-11-25 11:54:57 +1100804/*
805 * Called after processing other sources of option data, this fills those
806 * options for which no value has been specified with their default values.
807 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000808
Damien Miller4af51302000-04-16 11:18:38 +1000809void
Damien Miller95def091999-11-25 00:26:21 +1100810fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000811{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000812 int len;
813
Damien Miller95def091999-11-25 00:26:21 +1100814 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000815 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100816 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100817 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000818 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000819 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100820 if (options->gateway_ports == -1)
821 options->gateway_ports = 0;
822 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000823 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100824 if (options->rhosts_authentication == -1)
825 options->rhosts_authentication = 1;
826 if (options->rsa_authentication == -1)
827 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100828 if (options->pubkey_authentication == -1)
829 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000830 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000831 options->challenge_response_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000832#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100833 if (options->kerberos_authentication == -1)
834 options->kerberos_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000835#endif
836#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100837 if (options->kerberos_tgt_passing == -1)
838 options->kerberos_tgt_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000839#endif
840#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100841 if (options->afs_token_passing == -1)
842 options->afs_token_passing = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000843#endif
Damien Miller95def091999-11-25 00:26:21 +1100844 if (options->password_authentication == -1)
845 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100846 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000847 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100848 if (options->rhosts_rsa_authentication == -1)
849 options->rhosts_rsa_authentication = 1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000850 if (options->hostbased_authentication == -1)
851 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100852 if (options->fallback_to_rsh == -1)
Damien Miller182ee6e2000-07-12 09:45:27 +1000853 options->fallback_to_rsh = 0;
Damien Miller95def091999-11-25 00:26:21 +1100854 if (options->use_rsh == -1)
855 options->use_rsh = 0;
856 if (options->batch_mode == -1)
857 options->batch_mode = 0;
858 if (options->check_host_ip == -1)
859 options->check_host_ip = 1;
860 if (options->strict_host_key_checking == -1)
861 options->strict_host_key_checking = 2; /* 2 is default */
862 if (options->compression == -1)
863 options->compression = 0;
864 if (options->keepalives == -1)
865 options->keepalives = 1;
866 if (options->compression_level == -1)
867 options->compression_level = 6;
868 if (options->port == -1)
869 options->port = 0; /* Filled in ssh_connect. */
870 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000871 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100872 if (options->number_of_password_prompts == -1)
873 options->number_of_password_prompts = 3;
874 /* Selected in ssh_login(). */
875 if (options->cipher == -1)
876 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000877 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000878 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000879 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000880 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000881 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100882 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100883 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000884 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100885 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000886 xmalloc(len);
887 snprintf(options->identity_files[options->num_identity_files++],
888 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100889 }
890 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000891 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
892 options->identity_files[options->num_identity_files] =
893 xmalloc(len);
894 snprintf(options->identity_files[options->num_identity_files++],
895 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
896
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000897 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100898 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000899 xmalloc(len);
900 snprintf(options->identity_files[options->num_identity_files++],
901 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100902 }
Damien Millereba71ba2000-04-29 23:57:08 +1000903 }
Damien Miller95def091999-11-25 00:26:21 +1100904 if (options->escape_char == -1)
905 options->escape_char = '~';
906 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000907 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100908 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000909 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000910 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000911 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000912 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000913 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +1100914 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000915 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000916 if (options->clear_forwardings == 1)
917 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000918 if (options->no_host_authentication_for_localhost == - 1)
919 options->no_host_authentication_for_localhost = 0;
Damien Miller95def091999-11-25 00:26:21 +1100920 /* options->proxy_command should not be set by default */
921 /* options->user will be set in the main program if appropriate */
922 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000923 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000924 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000925}