blob: 12b431d59d781381ef38f04d872befa26cf47237 [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 Lindstrom5eabda32001-04-12 23:34:34 +000015RCSID("$OpenBSD: readconf.c,v 1.72 2001/04/12 19: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,
Damien Millerd4a8b7e1999-10-27 13:42:43 +100099#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100100 oKerberosAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000101#endif /* KRB4 */
102#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100103 oKerberosTgtPassing, oAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000104#endif
Damien Miller95def091999-11-25 00:26:21 +1100105 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
106 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
107 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
108 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000109 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000110 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100111 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000112 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000113 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000114} OpCodes;
115
116/* Textual representations of the tokens. */
117
Damien Miller95def091999-11-25 00:26:21 +1100118static struct {
119 const char *name;
120 OpCodes opcode;
121} keywords[] = {
122 { "forwardagent", oForwardAgent },
123 { "forwardx11", oForwardX11 },
Damien Millerd3a18572000-06-07 19:55:44 +1000124 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100125 { "gatewayports", oGatewayPorts },
126 { "useprivilegedport", oUsePrivilegedPort },
127 { "rhostsauthentication", oRhostsAuthentication },
128 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100129 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
130 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100131 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100132 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000133 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000134 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
135 { "hostbaedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000136 { "challengeresponseauthentication", oChallengeResponseAuthentication },
137 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
138 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000139#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100140 { "kerberosauthentication", oKerberosAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000141#endif /* KRB4 */
142#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100143 { "kerberostgtpassing", oKerberosTgtPassing },
144 { "afstokenpassing", oAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000145#endif
Damien Miller95def091999-11-25 00:26:21 +1100146 { "fallbacktorsh", oFallBackToRsh },
147 { "usersh", oUseRsh },
148 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100149 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100150 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000151 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100152 { "proxycommand", oProxyCommand },
153 { "port", oPort },
154 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000155 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000156 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000157 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100158 { "remoteforward", oRemoteForward },
159 { "localforward", oLocalForward },
160 { "user", oUser },
161 { "host", oHost },
162 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100163 { "globalknownhostsfile", oGlobalKnownHostsFile },
164 { "userknownhostsfile", oUserKnownHostsFile },
Damien Millereba71ba2000-04-29 23:57:08 +1000165 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
166 { "userknownhostsfile2", oUserKnownHostsFile2 },
Damien Miller95def091999-11-25 00:26:21 +1100167 { "connectionattempts", oConnectionAttempts },
168 { "batchmode", oBatchMode },
169 { "checkhostip", oCheckHostIP },
170 { "stricthostkeychecking", oStrictHostKeyChecking },
171 { "compression", oCompression },
172 { "compressionlevel", oCompressionLevel },
173 { "keepalive", oKeepAlives },
174 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100175 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000176 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000177 { "preferredauthentications", oPreferredAuthentications },
Damien Miller95def091999-11-25 00:26:21 +1100178 { NULL, 0 }
Damien Miller5ce662a1999-11-11 17:57:39 +1100179};
180
Damien Miller5428f641999-11-25 11:54:57 +1100181/*
182 * Adds a local TCP/IP port forward to options. Never returns if there is an
183 * error.
184 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000185
Damien Miller4af51302000-04-16 11:18:38 +1000186void
Damien Milleraae6c611999-12-06 11:47:28 +1100187add_local_forward(Options *options, u_short port, const char *host,
188 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000189{
Damien Miller95def091999-11-25 00:26:21 +1100190 Forward *fwd;
Damien Millerbac2d8a2000-09-05 16:13:06 +1100191#ifndef HAVE_CYGWIN
Damien Miller95def091999-11-25 00:26:21 +1100192 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100193 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000194 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100195#endif
Damien Miller95def091999-11-25 00:26:21 +1100196 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
197 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
198 fwd = &options->local_forwards[options->num_local_forwards++];
199 fwd->port = port;
200 fwd->host = xstrdup(host);
201 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000202}
203
Damien Miller5428f641999-11-25 11:54:57 +1100204/*
205 * Adds a remote TCP/IP port forward to options. Never returns if there is
206 * an error.
207 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000208
Damien Miller4af51302000-04-16 11:18:38 +1000209void
Damien Milleraae6c611999-12-06 11:47:28 +1100210add_remote_forward(Options *options, u_short port, const char *host,
211 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000212{
Damien Miller95def091999-11-25 00:26:21 +1100213 Forward *fwd;
214 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
215 fatal("Too many remote forwards (max %d).",
216 SSH_MAX_FORWARDS_PER_DIRECTION);
217 fwd = &options->remote_forwards[options->num_remote_forwards++];
218 fwd->port = port;
219 fwd->host = xstrdup(host);
220 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000221}
222
Damien Miller5428f641999-11-25 11:54:57 +1100223/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000224 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100225 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000226
Damien Miller4af51302000-04-16 11:18:38 +1000227static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100228parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000229{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000230 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000231
Damien Miller95def091999-11-25 00:26:21 +1100232 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100233 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100234 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000235
Damien Miller95def091999-11-25 00:26:21 +1100236 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
237 filename, linenum, cp);
238 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000239}
240
Damien Miller5428f641999-11-25 11:54:57 +1100241/*
242 * Processes a single option line as used in the configuration files. This
243 * only sets those values that have not already been set.
244 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000245
Damien Miller2ccf6611999-11-15 15:25:10 +1100246int
247process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100248 char *line, const char *filename, int linenum,
249 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000250{
Damien Miller37023962000-07-11 17:31:38 +1000251 char buf[256], *s, *string, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100252 int opcode, *intptr, value;
253 u_short fwd_port, fwd_host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000254
Damien Millerbe484b52000-07-15 14:14:16 +1000255 s = line;
256 /* Get the keyword. (Each line is supposed to begin with a keyword). */
257 keyword = strdelim(&s);
258 /* Ignore leading whitespace. */
259 if (*keyword == '\0')
260 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000261 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100262 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000263
Damien Miller37023962000-07-11 17:31:38 +1000264 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000265
Damien Miller95def091999-11-25 00:26:21 +1100266 switch (opcode) {
267 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100268 /* don't panic, but count bad options */
269 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100270 /* NOTREACHED */
271 case oForwardAgent:
272 intptr = &options->forward_agent;
273parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000274 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000275 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100276 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
277 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000278 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100279 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000280 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100281 value = 0;
282 else
283 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
284 if (*activep && *intptr == -1)
285 *intptr = value;
286 break;
287
288 case oForwardX11:
289 intptr = &options->forward_x11;
290 goto parse_flag;
291
292 case oGatewayPorts:
293 intptr = &options->gateway_ports;
294 goto parse_flag;
295
296 case oUsePrivilegedPort:
297 intptr = &options->use_privileged_port;
298 goto parse_flag;
299
300 case oRhostsAuthentication:
301 intptr = &options->rhosts_authentication;
302 goto parse_flag;
303
304 case oPasswordAuthentication:
305 intptr = &options->password_authentication;
306 goto parse_flag;
307
Damien Miller874d77b2000-10-14 16:23:11 +1100308 case oKbdInteractiveAuthentication:
309 intptr = &options->kbd_interactive_authentication;
310 goto parse_flag;
311
312 case oKbdInteractiveDevices:
313 charptr = &options->kbd_interactive_devices;
314 goto parse_string;
315
Damien Miller0bc1bd82000-11-13 22:57:25 +1100316 case oPubkeyAuthentication:
317 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000318 goto parse_flag;
319
Damien Miller95def091999-11-25 00:26:21 +1100320 case oRSAAuthentication:
321 intptr = &options->rsa_authentication;
322 goto parse_flag;
323
324 case oRhostsRSAAuthentication:
325 intptr = &options->rhosts_rsa_authentication;
326 goto parse_flag;
327
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000328 case oHostbasedAuthentication:
329 intptr = &options->hostbased_authentication;
330 goto parse_flag;
331
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000332 case oChallengeResponseAuthentication:
333 intptr = &options->challenge_reponse_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100334 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000335
336#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100337 case oKerberosAuthentication:
338 intptr = &options->kerberos_authentication;
339 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000340#endif /* KRB4 */
341
342#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100343 case oKerberosTgtPassing:
344 intptr = &options->kerberos_tgt_passing;
345 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000346
Damien Miller95def091999-11-25 00:26:21 +1100347 case oAFSTokenPassing:
348 intptr = &options->afs_token_passing;
349 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000350#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000351
Damien Miller95def091999-11-25 00:26:21 +1100352 case oFallBackToRsh:
353 intptr = &options->fallback_to_rsh;
354 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000355
Damien Miller95def091999-11-25 00:26:21 +1100356 case oUseRsh:
357 intptr = &options->use_rsh;
358 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000359
Damien Miller95def091999-11-25 00:26:21 +1100360 case oBatchMode:
361 intptr = &options->batch_mode;
362 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000363
Damien Miller95def091999-11-25 00:26:21 +1100364 case oCheckHostIP:
365 intptr = &options->check_host_ip;
366 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000367
Damien Miller95def091999-11-25 00:26:21 +1100368 case oStrictHostKeyChecking:
369 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000370 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000371 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000372 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller95def091999-11-25 00:26:21 +1100373 filename, linenum);
374 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000375 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100376 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000377 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100378 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000379 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100380 value = 2;
381 else
382 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
383 if (*activep && *intptr == -1)
384 *intptr = value;
385 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000386
Damien Miller95def091999-11-25 00:26:21 +1100387 case oCompression:
388 intptr = &options->compression;
389 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000390
Damien Miller95def091999-11-25 00:26:21 +1100391 case oKeepAlives:
392 intptr = &options->keepalives;
393 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000394
Damien Miller95def091999-11-25 00:26:21 +1100395 case oNumberOfPasswordPrompts:
396 intptr = &options->number_of_password_prompts;
397 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000398
Damien Miller95def091999-11-25 00:26:21 +1100399 case oCompressionLevel:
400 intptr = &options->compression_level;
401 goto parse_int;
402
403 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000404 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000405 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100406 fatal("%.200s line %d: Missing argument.", filename, linenum);
407 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100408 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000409 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100410 fatal("%.200s line %d: Too many identity files specified (max %d).",
411 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100412 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000413 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000414 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100415 }
416 break;
417
Damien Millerd3a18572000-06-07 19:55:44 +1000418 case oXAuthLocation:
419 charptr=&options->xauth_location;
420 goto parse_string;
421
Damien Miller95def091999-11-25 00:26:21 +1100422 case oUser:
423 charptr = &options->user;
424parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000425 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000426 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100427 fatal("%.200s line %d: Missing argument.", filename, linenum);
428 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000429 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100430 break;
431
432 case oGlobalKnownHostsFile:
433 charptr = &options->system_hostfile;
434 goto parse_string;
435
436 case oUserKnownHostsFile:
437 charptr = &options->user_hostfile;
438 goto parse_string;
439
Damien Millereba71ba2000-04-29 23:57:08 +1000440 case oGlobalKnownHostsFile2:
441 charptr = &options->system_hostfile2;
442 goto parse_string;
443
444 case oUserKnownHostsFile2:
445 charptr = &options->user_hostfile2;
446 goto parse_string;
447
Damien Miller95def091999-11-25 00:26:21 +1100448 case oHostName:
449 charptr = &options->hostname;
450 goto parse_string;
451
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000452 case oHostKeyAlias:
453 charptr = &options->host_key_alias;
454 goto parse_string;
455
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000456 case oPreferredAuthentications:
457 charptr = &options->preferred_authentications;
458 goto parse_string;
459
Damien Miller95def091999-11-25 00:26:21 +1100460 case oProxyCommand:
461 charptr = &options->proxy_command;
462 string = xstrdup("");
Damien Millerbe484b52000-07-15 14:14:16 +1000463 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000464 string = xrealloc(string, strlen(string) + strlen(arg) + 2);
Damien Miller95def091999-11-25 00:26:21 +1100465 strcat(string, " ");
Damien Miller37023962000-07-11 17:31:38 +1000466 strcat(string, arg);
Damien Miller95def091999-11-25 00:26:21 +1100467 }
468 if (*activep && *charptr == NULL)
469 *charptr = string;
470 else
471 xfree(string);
472 return 0;
473
474 case oPort:
475 intptr = &options->port;
476parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000477 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000478 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100479 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000480 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100481 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100482
483 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000484 value = strtol(arg, &endofnumber, 0);
485 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100486 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100487 if (*activep && *intptr == -1)
488 *intptr = value;
489 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000490
Damien Miller95def091999-11-25 00:26:21 +1100491 case oConnectionAttempts:
492 intptr = &options->connection_attempts;
493 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100494
Damien Miller95def091999-11-25 00:26:21 +1100495 case oCipher:
496 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000497 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000498 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000499 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000500 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100501 if (value == -1)
502 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000503 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100504 if (*activep && *intptr == -1)
505 *intptr = value;
506 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000507
Damien Miller78928792000-04-12 20:17:38 +1000508 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000509 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000510 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000511 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000512 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000513 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000514 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000515 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000516 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000517 break;
518
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000519 case oMacs:
520 arg = strdelim(&s);
521 if (!arg || *arg == '\0')
522 fatal("%.200s line %d: Missing argument.", filename, linenum);
523 if (!mac_valid(arg))
524 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
525 filename, linenum, arg ? arg : "<NONE>");
526 if (*activep && options->macs == NULL)
527 options->macs = xstrdup(arg);
528 break;
529
Damien Miller78928792000-04-12 20:17:38 +1000530 case oProtocol:
531 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000532 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000533 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000534 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000535 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000536 if (value == SSH_PROTO_UNKNOWN)
537 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000538 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000539 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
540 *intptr = value;
541 break;
542
Damien Miller95def091999-11-25 00:26:21 +1100543 case oLogLevel:
544 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000545 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000546 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100547 if (value == (LogLevel) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000548 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000549 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100550 if (*activep && (LogLevel) * intptr == -1)
551 *intptr = (LogLevel) value;
552 break;
553
554 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000555 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000556 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100557 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000558 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100559 fatal("%.200s line %d: Badly formatted port number.",
560 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000561 fwd_port = atoi(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000562 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000563 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100564 fatal("%.200s line %d: Missing second argument.",
565 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000566 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
Damien Miller95def091999-11-25 00:26:21 +1100567 fatal("%.200s line %d: Badly formatted host:port.",
568 filename, linenum);
569 if (*activep)
570 add_remote_forward(options, fwd_port, buf, fwd_host_port);
571 break;
572
573 case oLocalForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000574 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000575 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100576 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000577 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100578 fatal("%.200s line %d: Badly formatted port number.",
579 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000580 fwd_port = atoi(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000581 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000582 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100583 fatal("%.200s line %d: Missing second argument.",
584 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000585 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
Damien Miller95def091999-11-25 00:26:21 +1100586 fatal("%.200s line %d: Badly formatted host:port.",
587 filename, linenum);
588 if (*activep)
589 add_local_forward(options, fwd_port, buf, fwd_host_port);
590 break;
591
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000592 case oDynamicForward:
593 arg = strdelim(&s);
594 if (!arg || *arg == '\0')
595 fatal("%.200s line %d: Missing port argument.",
596 filename, linenum);
597 if (arg[0] < '0' || arg[0] > '9')
598 fatal("%.200s line %d: Badly formatted port number.",
599 filename, linenum);
600 fwd_port = atoi(arg);
601 add_local_forward(options, fwd_port, "socks4", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000602 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000603
Damien Miller95def091999-11-25 00:26:21 +1100604 case oHost:
605 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000606 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000607 if (match_pattern(host, arg)) {
608 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100609 *activep = 1;
610 break;
611 }
Damien Millerbe484b52000-07-15 14:14:16 +1000612 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100613 return 0;
614
615 case oEscapeChar:
616 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000617 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000618 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100619 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000620 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000621 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
622 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000623 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000624 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000625 else if (strcmp(arg, "none") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100626 value = -2;
627 else {
628 fatal("%.200s line %d: Bad escape character.",
629 filename, linenum);
630 /* NOTREACHED */
631 value = 0; /* Avoid compiler warning. */
632 }
633 if (*activep && *intptr == -1)
634 *intptr = value;
635 break;
636
637 default:
638 fatal("process_config_line: Unimplemented opcode %d", opcode);
639 }
640
641 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000642 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000643 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
644 filename, linenum, arg);
645 }
Damien Miller95def091999-11-25 00:26:21 +1100646 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000647}
648
649
Damien Miller5428f641999-11-25 11:54:57 +1100650/*
651 * Reads the config file and modifies the options accordingly. Options
652 * should already be initialized before this call. This never returns if
653 * there is an error. If the file does not exist, this returns immediately.
654 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000655
Damien Miller4af51302000-04-16 11:18:38 +1000656void
Damien Miller95def091999-11-25 00:26:21 +1100657read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000658{
Damien Miller95def091999-11-25 00:26:21 +1100659 FILE *f;
660 char line[1024];
661 int active, linenum;
662 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000663
Damien Miller95def091999-11-25 00:26:21 +1100664 /* Open the file. */
665 f = fopen(filename, "r");
666 if (!f)
667 return;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000668
Damien Miller95def091999-11-25 00:26:21 +1100669 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000670
Damien Miller5428f641999-11-25 11:54:57 +1100671 /*
672 * Mark that we are now processing the options. This flag is turned
673 * on/off by Host specifications.
674 */
Damien Miller95def091999-11-25 00:26:21 +1100675 active = 1;
676 linenum = 0;
677 while (fgets(line, sizeof(line), f)) {
678 /* Update line number counter. */
679 linenum++;
680 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
681 bad_options++;
682 }
683 fclose(f);
684 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000685 fatal("%s: terminating, %d bad configuration options",
Damien Miller95def091999-11-25 00:26:21 +1100686 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000687}
688
Damien Miller5428f641999-11-25 11:54:57 +1100689/*
690 * Initializes options to special values that indicate that they have not yet
691 * been set. Read_config_file will only set options with this value. Options
692 * are processed in the following order: command line, user config file,
693 * system config file. Last, fill_default_options is called.
694 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000695
Damien Miller4af51302000-04-16 11:18:38 +1000696void
Damien Miller95def091999-11-25 00:26:21 +1100697initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000698{
Damien Miller95def091999-11-25 00:26:21 +1100699 memset(options, 'X', sizeof(*options));
700 options->forward_agent = -1;
701 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000702 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100703 options->gateway_ports = -1;
704 options->use_privileged_port = -1;
705 options->rhosts_authentication = -1;
706 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100707 options->pubkey_authentication = -1;
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000708 options->challenge_reponse_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000709#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100710 options->kerberos_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000711#endif
712#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100713 options->kerberos_tgt_passing = -1;
714 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000715#endif
Damien Miller95def091999-11-25 00:26:21 +1100716 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100717 options->kbd_interactive_authentication = -1;
718 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100719 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000720 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100721 options->fallback_to_rsh = -1;
722 options->use_rsh = -1;
723 options->batch_mode = -1;
724 options->check_host_ip = -1;
725 options->strict_host_key_checking = -1;
726 options->compression = -1;
727 options->keepalives = -1;
728 options->compression_level = -1;
729 options->port = -1;
730 options->connection_attempts = -1;
731 options->number_of_password_prompts = -1;
732 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000733 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000734 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000735 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100736 options->num_identity_files = 0;
737 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000738 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100739 options->proxy_command = NULL;
740 options->user = NULL;
741 options->escape_char = -1;
742 options->system_hostfile = NULL;
743 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000744 options->system_hostfile2 = NULL;
745 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100746 options->num_local_forwards = 0;
747 options->num_remote_forwards = 0;
748 options->log_level = (LogLevel) - 1;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000749 options->preferred_authentications = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000750}
751
Damien Miller5428f641999-11-25 11:54:57 +1100752/*
753 * Called after processing other sources of option data, this fills those
754 * options for which no value has been specified with their default values.
755 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000756
Damien Miller4af51302000-04-16 11:18:38 +1000757void
Damien Miller95def091999-11-25 00:26:21 +1100758fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000759{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000760 int len;
761
Damien Miller95def091999-11-25 00:26:21 +1100762 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000763 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100764 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100765 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000766#ifdef XAUTH_PATH
767 if (options->xauth_location == NULL)
768 options->xauth_location = XAUTH_PATH;
769#endif /* XAUTH_PATH */
Damien Miller95def091999-11-25 00:26:21 +1100770 if (options->gateway_ports == -1)
771 options->gateway_ports = 0;
772 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000773 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100774 if (options->rhosts_authentication == -1)
775 options->rhosts_authentication = 1;
776 if (options->rsa_authentication == -1)
777 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100778 if (options->pubkey_authentication == -1)
779 options->pubkey_authentication = 1;
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000780 if (options->challenge_reponse_authentication == -1)
781 options->challenge_reponse_authentication = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000782#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100783 if (options->kerberos_authentication == -1)
784 options->kerberos_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000785#endif /* KRB4 */
786#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100787 if (options->kerberos_tgt_passing == -1)
788 options->kerberos_tgt_passing = 1;
789 if (options->afs_token_passing == -1)
790 options->afs_token_passing = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000791#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100792 if (options->password_authentication == -1)
793 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100794 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000795 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100796 if (options->rhosts_rsa_authentication == -1)
797 options->rhosts_rsa_authentication = 1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000798 if (options->hostbased_authentication == -1)
799 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100800 if (options->fallback_to_rsh == -1)
Damien Miller182ee6e2000-07-12 09:45:27 +1000801 options->fallback_to_rsh = 0;
Damien Miller95def091999-11-25 00:26:21 +1100802 if (options->use_rsh == -1)
803 options->use_rsh = 0;
804 if (options->batch_mode == -1)
805 options->batch_mode = 0;
806 if (options->check_host_ip == -1)
807 options->check_host_ip = 1;
808 if (options->strict_host_key_checking == -1)
809 options->strict_host_key_checking = 2; /* 2 is default */
810 if (options->compression == -1)
811 options->compression = 0;
812 if (options->keepalives == -1)
813 options->keepalives = 1;
814 if (options->compression_level == -1)
815 options->compression_level = 6;
816 if (options->port == -1)
817 options->port = 0; /* Filled in ssh_connect. */
818 if (options->connection_attempts == -1)
819 options->connection_attempts = 4;
820 if (options->number_of_password_prompts == -1)
821 options->number_of_password_prompts = 3;
822 /* Selected in ssh_login(). */
823 if (options->cipher == -1)
824 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000825 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000826 /* options->macs, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000827 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000828 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100829 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100830 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000831 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100832 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000833 xmalloc(len);
834 snprintf(options->identity_files[options->num_identity_files++],
835 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100836 }
837 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000838 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
839 options->identity_files[options->num_identity_files] =
840 xmalloc(len);
841 snprintf(options->identity_files[options->num_identity_files++],
842 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
843
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000844 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100845 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000846 xmalloc(len);
847 snprintf(options->identity_files[options->num_identity_files++],
848 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100849 }
Damien Millereba71ba2000-04-29 23:57:08 +1000850 }
Damien Miller95def091999-11-25 00:26:21 +1100851 if (options->escape_char == -1)
852 options->escape_char = '~';
853 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000854 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100855 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000856 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000857 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000858 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000859 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000860 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Miller95def091999-11-25 00:26:21 +1100861 if (options->log_level == (LogLevel) - 1)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000862 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100863 /* options->proxy_command should not be set by default */
864 /* options->user will be set in the main program if appropriate */
865 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000866 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000867 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000868}