blob: 365f67eb0068fcaeb42e27bbea2ac6d42ccc2505 [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 Lindstrom3704c262001-04-02 18:20:03 +000015RCSID("$OpenBSD: readconf.c,v 1.70 2001/04/02 14:20:23 stevesk Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016
17#include "ssh.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100018#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100019#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000020#include "cipher.h"
21#include "pathnames.h"
22#include "log.h"
23#include "readconf.h"
24#include "match.h"
25#include "misc.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000026#include "kex.h"
27#include "mac.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100028
29/* Format of the configuration file:
30
31 # Configuration data is parsed as follows:
32 # 1. command line options
33 # 2. user-specific file
34 # 3. system-wide file
35 # Any configuration value is only changed the first time it is set.
36 # Thus, host-specific definitions should be at the beginning of the
37 # configuration file, and defaults at the end.
38
39 # Host-specific declarations. These may override anything above. A single
40 # host may match multiple declarations; these are processed in the order
41 # that they are given in.
42
43 Host *.ngs.fi ngs.fi
44 FallBackToRsh no
45
46 Host fake.com
47 HostName another.host.name.real.org
48 User blaah
49 Port 34289
50 ForwardX11 no
51 ForwardAgent no
52
53 Host books.com
54 RemoteForward 9999 shadows.cs.hut.fi:9999
55 Cipher 3des
56
57 Host fascist.blob.com
58 Port 23123
59 User tylonen
60 RhostsAuthentication no
61 PasswordAuthentication no
62
63 Host puukko.hut.fi
64 User t35124p
65 ProxyCommand ssh-proxy %h %p
66
67 Host *.fr
68 UseRsh yes
69
70 Host *.su
71 Cipher none
72 PasswordAuthentication no
73
74 # Defaults for various options
75 Host *
76 ForwardAgent no
Damien Miller0bc1bd82000-11-13 22:57:25 +110077 ForwardX11 no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100078 RhostsAuthentication yes
79 PasswordAuthentication yes
80 RSAAuthentication yes
81 RhostsRSAAuthentication yes
82 FallBackToRsh no
83 UseRsh no
84 StrictHostKeyChecking yes
85 KeepAlives no
86 IdentityFile ~/.ssh/identity
87 Port 22
88 EscapeChar ~
89
90*/
91
92/* Keyword tokens. */
93
Damien Miller95def091999-11-25 00:26:21 +110094typedef enum {
95 oBadOption,
96 oForwardAgent, oForwardX11, oGatewayPorts, oRhostsAuthentication,
97 oPasswordAuthentication, oRSAAuthentication, oFallBackToRsh, oUseRsh,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000098 oChallengeResponseAuthentication, oXAuthLocation,
Damien Millerd4a8b7e1999-10-27 13:42:43 +100099#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100100 oKerberosAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000101#endif /* KRB4 */
102#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100103 oKerberosTgtPassing, oAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000104#endif
Damien Miller95def091999-11-25 00:26:21 +1100105 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
106 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
107 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
108 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000109 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000110 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100111 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000112 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
113 oPreferredAuthentications
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 */
134 { "challengeresponseauthentication", oChallengeResponseAuthentication },
135 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
136 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000137#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100138 { "kerberosauthentication", oKerberosAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000139#endif /* KRB4 */
140#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100141 { "kerberostgtpassing", oKerberosTgtPassing },
142 { "afstokenpassing", oAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000143#endif
Damien Miller95def091999-11-25 00:26:21 +1100144 { "fallbacktorsh", oFallBackToRsh },
145 { "usersh", oUseRsh },
146 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100147 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100148 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000149 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100150 { "proxycommand", oProxyCommand },
151 { "port", oPort },
152 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000153 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000154 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000155 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100156 { "remoteforward", oRemoteForward },
157 { "localforward", oLocalForward },
158 { "user", oUser },
159 { "host", oHost },
160 { "escapechar", oEscapeChar },
161 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
162 { "globalknownhostsfile", oGlobalKnownHostsFile },
163 { "userknownhostsfile", oUserKnownHostsFile },
Damien Millereba71ba2000-04-29 23:57:08 +1000164 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
165 { "userknownhostsfile2", oUserKnownHostsFile2 },
Damien Miller95def091999-11-25 00:26:21 +1100166 { "connectionattempts", oConnectionAttempts },
167 { "batchmode", oBatchMode },
168 { "checkhostip", oCheckHostIP },
169 { "stricthostkeychecking", oStrictHostKeyChecking },
170 { "compression", oCompression },
171 { "compressionlevel", oCompressionLevel },
172 { "keepalive", oKeepAlives },
173 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100174 { "loglevel", oLogLevel },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000175 { "preferredauthentications", oPreferredAuthentications },
Damien Miller95def091999-11-25 00:26:21 +1100176 { NULL, 0 }
Damien Miller5ce662a1999-11-11 17:57:39 +1100177};
178
Damien Miller5428f641999-11-25 11:54:57 +1100179/*
180 * Adds a local TCP/IP port forward to options. Never returns if there is an
181 * error.
182 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000183
Damien Miller4af51302000-04-16 11:18:38 +1000184void
Damien Milleraae6c611999-12-06 11:47:28 +1100185add_local_forward(Options *options, u_short port, const char *host,
186 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000187{
Damien Miller95def091999-11-25 00:26:21 +1100188 Forward *fwd;
Damien Millerbac2d8a2000-09-05 16:13:06 +1100189#ifndef HAVE_CYGWIN
Damien Miller95def091999-11-25 00:26:21 +1100190 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100191 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000192 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100193#endif
Damien Miller95def091999-11-25 00:26:21 +1100194 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
195 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
196 fwd = &options->local_forwards[options->num_local_forwards++];
197 fwd->port = port;
198 fwd->host = xstrdup(host);
199 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000200}
201
Damien Miller5428f641999-11-25 11:54:57 +1100202/*
203 * Adds a remote TCP/IP port forward to options. Never returns if there is
204 * an error.
205 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000206
Damien Miller4af51302000-04-16 11:18:38 +1000207void
Damien Milleraae6c611999-12-06 11:47:28 +1100208add_remote_forward(Options *options, u_short port, const char *host,
209 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000210{
Damien Miller95def091999-11-25 00:26:21 +1100211 Forward *fwd;
212 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
213 fatal("Too many remote forwards (max %d).",
214 SSH_MAX_FORWARDS_PER_DIRECTION);
215 fwd = &options->remote_forwards[options->num_remote_forwards++];
216 fwd->port = port;
217 fwd->host = xstrdup(host);
218 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000219}
220
Damien Miller5428f641999-11-25 11:54:57 +1100221/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000222 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100223 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000224
Damien Miller4af51302000-04-16 11:18:38 +1000225static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100226parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000227{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000228 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000229
Damien Miller95def091999-11-25 00:26:21 +1100230 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100231 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100232 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000233
Damien Miller95def091999-11-25 00:26:21 +1100234 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
235 filename, linenum, cp);
236 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000237}
238
Damien Miller5428f641999-11-25 11:54:57 +1100239/*
240 * Processes a single option line as used in the configuration files. This
241 * only sets those values that have not already been set.
242 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000243
Damien Miller2ccf6611999-11-15 15:25:10 +1100244int
245process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100246 char *line, const char *filename, int linenum,
247 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000248{
Damien Miller37023962000-07-11 17:31:38 +1000249 char buf[256], *s, *string, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100250 int opcode, *intptr, value;
251 u_short fwd_port, fwd_host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000252
Damien Millerbe484b52000-07-15 14:14:16 +1000253 s = line;
254 /* Get the keyword. (Each line is supposed to begin with a keyword). */
255 keyword = strdelim(&s);
256 /* Ignore leading whitespace. */
257 if (*keyword == '\0')
258 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000259 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100260 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000261
Damien Miller37023962000-07-11 17:31:38 +1000262 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000263
Damien Miller95def091999-11-25 00:26:21 +1100264 switch (opcode) {
265 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100266 /* don't panic, but count bad options */
267 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100268 /* NOTREACHED */
269 case oForwardAgent:
270 intptr = &options->forward_agent;
271parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000272 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000273 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100274 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
275 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000276 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100277 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000278 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100279 value = 0;
280 else
281 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
282 if (*activep && *intptr == -1)
283 *intptr = value;
284 break;
285
286 case oForwardX11:
287 intptr = &options->forward_x11;
288 goto parse_flag;
289
290 case oGatewayPorts:
291 intptr = &options->gateway_ports;
292 goto parse_flag;
293
294 case oUsePrivilegedPort:
295 intptr = &options->use_privileged_port;
296 goto parse_flag;
297
298 case oRhostsAuthentication:
299 intptr = &options->rhosts_authentication;
300 goto parse_flag;
301
302 case oPasswordAuthentication:
303 intptr = &options->password_authentication;
304 goto parse_flag;
305
Damien Miller874d77b2000-10-14 16:23:11 +1100306 case oKbdInteractiveAuthentication:
307 intptr = &options->kbd_interactive_authentication;
308 goto parse_flag;
309
310 case oKbdInteractiveDevices:
311 charptr = &options->kbd_interactive_devices;
312 goto parse_string;
313
Damien Miller0bc1bd82000-11-13 22:57:25 +1100314 case oPubkeyAuthentication:
315 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000316 goto parse_flag;
317
Damien Miller95def091999-11-25 00:26:21 +1100318 case oRSAAuthentication:
319 intptr = &options->rsa_authentication;
320 goto parse_flag;
321
322 case oRhostsRSAAuthentication:
323 intptr = &options->rhosts_rsa_authentication;
324 goto parse_flag;
325
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000326 case oChallengeResponseAuthentication:
327 intptr = &options->challenge_reponse_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100328 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000329
330#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100331 case oKerberosAuthentication:
332 intptr = &options->kerberos_authentication;
333 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000334#endif /* KRB4 */
335
336#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100337 case oKerberosTgtPassing:
338 intptr = &options->kerberos_tgt_passing;
339 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000340
Damien Miller95def091999-11-25 00:26:21 +1100341 case oAFSTokenPassing:
342 intptr = &options->afs_token_passing;
343 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000344#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000345
Damien Miller95def091999-11-25 00:26:21 +1100346 case oFallBackToRsh:
347 intptr = &options->fallback_to_rsh;
348 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000349
Damien Miller95def091999-11-25 00:26:21 +1100350 case oUseRsh:
351 intptr = &options->use_rsh;
352 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000353
Damien Miller95def091999-11-25 00:26:21 +1100354 case oBatchMode:
355 intptr = &options->batch_mode;
356 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000357
Damien Miller95def091999-11-25 00:26:21 +1100358 case oCheckHostIP:
359 intptr = &options->check_host_ip;
360 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000361
Damien Miller95def091999-11-25 00:26:21 +1100362 case oStrictHostKeyChecking:
363 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000364 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000365 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000366 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller95def091999-11-25 00:26:21 +1100367 filename, linenum);
368 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000369 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100370 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000371 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100372 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000373 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100374 value = 2;
375 else
376 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
377 if (*activep && *intptr == -1)
378 *intptr = value;
379 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000380
Damien Miller95def091999-11-25 00:26:21 +1100381 case oCompression:
382 intptr = &options->compression;
383 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000384
Damien Miller95def091999-11-25 00:26:21 +1100385 case oKeepAlives:
386 intptr = &options->keepalives;
387 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000388
Damien Miller95def091999-11-25 00:26:21 +1100389 case oNumberOfPasswordPrompts:
390 intptr = &options->number_of_password_prompts;
391 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000392
Damien Miller95def091999-11-25 00:26:21 +1100393 case oCompressionLevel:
394 intptr = &options->compression_level;
395 goto parse_int;
396
397 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000398 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000399 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100400 fatal("%.200s line %d: Missing argument.", filename, linenum);
401 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100402 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000403 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100404 fatal("%.200s line %d: Too many identity files specified (max %d).",
405 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100406 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000407 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000408 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100409 }
410 break;
411
Damien Millerd3a18572000-06-07 19:55:44 +1000412 case oXAuthLocation:
413 charptr=&options->xauth_location;
414 goto parse_string;
415
Damien Miller95def091999-11-25 00:26:21 +1100416 case oUser:
417 charptr = &options->user;
418parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000419 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000420 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100421 fatal("%.200s line %d: Missing argument.", filename, linenum);
422 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000423 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100424 break;
425
426 case oGlobalKnownHostsFile:
427 charptr = &options->system_hostfile;
428 goto parse_string;
429
430 case oUserKnownHostsFile:
431 charptr = &options->user_hostfile;
432 goto parse_string;
433
Damien Millereba71ba2000-04-29 23:57:08 +1000434 case oGlobalKnownHostsFile2:
435 charptr = &options->system_hostfile2;
436 goto parse_string;
437
438 case oUserKnownHostsFile2:
439 charptr = &options->user_hostfile2;
440 goto parse_string;
441
Damien Miller95def091999-11-25 00:26:21 +1100442 case oHostName:
443 charptr = &options->hostname;
444 goto parse_string;
445
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000446 case oHostKeyAlias:
447 charptr = &options->host_key_alias;
448 goto parse_string;
449
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000450 case oPreferredAuthentications:
451 charptr = &options->preferred_authentications;
452 goto parse_string;
453
Damien Miller95def091999-11-25 00:26:21 +1100454 case oProxyCommand:
455 charptr = &options->proxy_command;
456 string = xstrdup("");
Damien Millerbe484b52000-07-15 14:14:16 +1000457 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000458 string = xrealloc(string, strlen(string) + strlen(arg) + 2);
Damien Miller95def091999-11-25 00:26:21 +1100459 strcat(string, " ");
Damien Miller37023962000-07-11 17:31:38 +1000460 strcat(string, arg);
Damien Miller95def091999-11-25 00:26:21 +1100461 }
462 if (*activep && *charptr == NULL)
463 *charptr = string;
464 else
465 xfree(string);
466 return 0;
467
468 case oPort:
469 intptr = &options->port;
470parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000471 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000472 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100473 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000474 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100475 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100476
477 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000478 value = strtol(arg, &endofnumber, 0);
479 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100480 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100481 if (*activep && *intptr == -1)
482 *intptr = value;
483 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000484
Damien Miller95def091999-11-25 00:26:21 +1100485 case oConnectionAttempts:
486 intptr = &options->connection_attempts;
487 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100488
Damien Miller95def091999-11-25 00:26:21 +1100489 case oCipher:
490 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000491 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000492 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000493 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000494 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100495 if (value == -1)
496 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000497 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100498 if (*activep && *intptr == -1)
499 *intptr = value;
500 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000501
Damien Miller78928792000-04-12 20:17:38 +1000502 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000503 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000504 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000505 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000506 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000507 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000508 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000509 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000510 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000511 break;
512
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000513 case oMacs:
514 arg = strdelim(&s);
515 if (!arg || *arg == '\0')
516 fatal("%.200s line %d: Missing argument.", filename, linenum);
517 if (!mac_valid(arg))
518 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
519 filename, linenum, arg ? arg : "<NONE>");
520 if (*activep && options->macs == NULL)
521 options->macs = xstrdup(arg);
522 break;
523
Damien Miller78928792000-04-12 20:17:38 +1000524 case oProtocol:
525 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000526 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000527 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000528 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000529 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000530 if (value == SSH_PROTO_UNKNOWN)
531 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000532 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000533 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
534 *intptr = value;
535 break;
536
Damien Miller95def091999-11-25 00:26:21 +1100537 case oLogLevel:
538 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000539 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000540 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100541 if (value == (LogLevel) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000542 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000543 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100544 if (*activep && (LogLevel) * intptr == -1)
545 *intptr = (LogLevel) value;
546 break;
547
548 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000549 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000550 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100551 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000552 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100553 fatal("%.200s line %d: Badly formatted port number.",
554 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000555 fwd_port = atoi(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000556 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000557 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100558 fatal("%.200s line %d: Missing second argument.",
559 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000560 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
Damien Miller95def091999-11-25 00:26:21 +1100561 fatal("%.200s line %d: Badly formatted host:port.",
562 filename, linenum);
563 if (*activep)
564 add_remote_forward(options, fwd_port, buf, fwd_host_port);
565 break;
566
567 case oLocalForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000568 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000569 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100570 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000571 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100572 fatal("%.200s line %d: Badly formatted port number.",
573 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000574 fwd_port = atoi(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000575 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000576 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100577 fatal("%.200s line %d: Missing second argument.",
578 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000579 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
Damien Miller95def091999-11-25 00:26:21 +1100580 fatal("%.200s line %d: Badly formatted host:port.",
581 filename, linenum);
582 if (*activep)
583 add_local_forward(options, fwd_port, buf, fwd_host_port);
584 break;
585
586 case oHost:
587 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000588 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000589 if (match_pattern(host, arg)) {
590 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100591 *activep = 1;
592 break;
593 }
Damien Millerbe484b52000-07-15 14:14:16 +1000594 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100595 return 0;
596
597 case oEscapeChar:
598 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000599 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000600 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100601 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000602 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000603 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
604 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000605 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000606 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000607 else if (strcmp(arg, "none") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100608 value = -2;
609 else {
610 fatal("%.200s line %d: Bad escape character.",
611 filename, linenum);
612 /* NOTREACHED */
613 value = 0; /* Avoid compiler warning. */
614 }
615 if (*activep && *intptr == -1)
616 *intptr = value;
617 break;
618
619 default:
620 fatal("process_config_line: Unimplemented opcode %d", opcode);
621 }
622
623 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000624 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000625 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
626 filename, linenum, arg);
627 }
Damien Miller95def091999-11-25 00:26:21 +1100628 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000629}
630
631
Damien Miller5428f641999-11-25 11:54:57 +1100632/*
633 * Reads the config file and modifies the options accordingly. Options
634 * should already be initialized before this call. This never returns if
635 * there is an error. If the file does not exist, this returns immediately.
636 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000637
Damien Miller4af51302000-04-16 11:18:38 +1000638void
Damien Miller95def091999-11-25 00:26:21 +1100639read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000640{
Damien Miller95def091999-11-25 00:26:21 +1100641 FILE *f;
642 char line[1024];
643 int active, linenum;
644 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000645
Damien Miller95def091999-11-25 00:26:21 +1100646 /* Open the file. */
647 f = fopen(filename, "r");
648 if (!f)
649 return;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000650
Damien Miller95def091999-11-25 00:26:21 +1100651 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000652
Damien Miller5428f641999-11-25 11:54:57 +1100653 /*
654 * Mark that we are now processing the options. This flag is turned
655 * on/off by Host specifications.
656 */
Damien Miller95def091999-11-25 00:26:21 +1100657 active = 1;
658 linenum = 0;
659 while (fgets(line, sizeof(line), f)) {
660 /* Update line number counter. */
661 linenum++;
662 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
663 bad_options++;
664 }
665 fclose(f);
666 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000667 fatal("%s: terminating, %d bad configuration options",
Damien Miller95def091999-11-25 00:26:21 +1100668 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000669}
670
Damien Miller5428f641999-11-25 11:54:57 +1100671/*
672 * Initializes options to special values that indicate that they have not yet
673 * been set. Read_config_file will only set options with this value. Options
674 * are processed in the following order: command line, user config file,
675 * system config file. Last, fill_default_options is called.
676 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000677
Damien Miller4af51302000-04-16 11:18:38 +1000678void
Damien Miller95def091999-11-25 00:26:21 +1100679initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000680{
Damien Miller95def091999-11-25 00:26:21 +1100681 memset(options, 'X', sizeof(*options));
682 options->forward_agent = -1;
683 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000684 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100685 options->gateway_ports = -1;
686 options->use_privileged_port = -1;
687 options->rhosts_authentication = -1;
688 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100689 options->pubkey_authentication = -1;
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000690 options->challenge_reponse_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000691#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100692 options->kerberos_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000693#endif
694#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100695 options->kerberos_tgt_passing = -1;
696 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000697#endif
Damien Miller95def091999-11-25 00:26:21 +1100698 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100699 options->kbd_interactive_authentication = -1;
700 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100701 options->rhosts_rsa_authentication = -1;
702 options->fallback_to_rsh = -1;
703 options->use_rsh = -1;
704 options->batch_mode = -1;
705 options->check_host_ip = -1;
706 options->strict_host_key_checking = -1;
707 options->compression = -1;
708 options->keepalives = -1;
709 options->compression_level = -1;
710 options->port = -1;
711 options->connection_attempts = -1;
712 options->number_of_password_prompts = -1;
713 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000714 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000715 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000716 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100717 options->num_identity_files = 0;
718 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000719 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100720 options->proxy_command = NULL;
721 options->user = NULL;
722 options->escape_char = -1;
723 options->system_hostfile = NULL;
724 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000725 options->system_hostfile2 = NULL;
726 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100727 options->num_local_forwards = 0;
728 options->num_remote_forwards = 0;
729 options->log_level = (LogLevel) - 1;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000730 options->preferred_authentications = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000731}
732
Damien Miller5428f641999-11-25 11:54:57 +1100733/*
734 * Called after processing other sources of option data, this fills those
735 * options for which no value has been specified with their default values.
736 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000737
Damien Miller4af51302000-04-16 11:18:38 +1000738void
Damien Miller95def091999-11-25 00:26:21 +1100739fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000740{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000741 int len;
742
Damien Miller95def091999-11-25 00:26:21 +1100743 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000744 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100745 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100746 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000747#ifdef XAUTH_PATH
748 if (options->xauth_location == NULL)
749 options->xauth_location = XAUTH_PATH;
750#endif /* XAUTH_PATH */
Damien Miller95def091999-11-25 00:26:21 +1100751 if (options->gateway_ports == -1)
752 options->gateway_ports = 0;
753 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000754 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100755 if (options->rhosts_authentication == -1)
756 options->rhosts_authentication = 1;
757 if (options->rsa_authentication == -1)
758 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100759 if (options->pubkey_authentication == -1)
760 options->pubkey_authentication = 1;
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000761 if (options->challenge_reponse_authentication == -1)
762 options->challenge_reponse_authentication = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000763#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100764 if (options->kerberos_authentication == -1)
765 options->kerberos_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000766#endif /* KRB4 */
767#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100768 if (options->kerberos_tgt_passing == -1)
769 options->kerberos_tgt_passing = 1;
770 if (options->afs_token_passing == -1)
771 options->afs_token_passing = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000772#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100773 if (options->password_authentication == -1)
774 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100775 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000776 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100777 if (options->rhosts_rsa_authentication == -1)
778 options->rhosts_rsa_authentication = 1;
779 if (options->fallback_to_rsh == -1)
Damien Miller182ee6e2000-07-12 09:45:27 +1000780 options->fallback_to_rsh = 0;
Damien Miller95def091999-11-25 00:26:21 +1100781 if (options->use_rsh == -1)
782 options->use_rsh = 0;
783 if (options->batch_mode == -1)
784 options->batch_mode = 0;
785 if (options->check_host_ip == -1)
786 options->check_host_ip = 1;
787 if (options->strict_host_key_checking == -1)
788 options->strict_host_key_checking = 2; /* 2 is default */
789 if (options->compression == -1)
790 options->compression = 0;
791 if (options->keepalives == -1)
792 options->keepalives = 1;
793 if (options->compression_level == -1)
794 options->compression_level = 6;
795 if (options->port == -1)
796 options->port = 0; /* Filled in ssh_connect. */
797 if (options->connection_attempts == -1)
798 options->connection_attempts = 4;
799 if (options->number_of_password_prompts == -1)
800 options->number_of_password_prompts = 3;
801 /* Selected in ssh_login(). */
802 if (options->cipher == -1)
803 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000804 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000805 /* options->macs, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000806 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000807 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100808 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100809 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000810 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100811 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000812 xmalloc(len);
813 snprintf(options->identity_files[options->num_identity_files++],
814 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100815 }
816 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000817 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
818 options->identity_files[options->num_identity_files] =
819 xmalloc(len);
820 snprintf(options->identity_files[options->num_identity_files++],
821 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
822
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000823 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100824 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000825 xmalloc(len);
826 snprintf(options->identity_files[options->num_identity_files++],
827 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100828 }
Damien Millereba71ba2000-04-29 23:57:08 +1000829 }
Damien Miller95def091999-11-25 00:26:21 +1100830 if (options->escape_char == -1)
831 options->escape_char = '~';
832 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000833 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100834 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000835 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000836 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000837 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000838 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000839 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Miller95def091999-11-25 00:26:21 +1100840 if (options->log_level == (LogLevel) - 1)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000841 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100842 /* options->proxy_command should not be set by default */
843 /* options->user will be set in the main program if appropriate */
844 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000845 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000846 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000847}