blob: 33649a8d54f39b2a4a1c7ecd8cc07a1fc42d1276 [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 Lindstrom6df8ef42001-03-05 07:47:23 +000015RCSID("$OpenBSD: readconf.c,v 1.64 2001/03/04 17:42:28 millert 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 Lindstrom4dccfa52000-12-28 16:40:05 +0000112 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000113} OpCodes;
114
115/* Textual representations of the tokens. */
116
Damien Miller95def091999-11-25 00:26:21 +1100117static struct {
118 const char *name;
119 OpCodes opcode;
120} keywords[] = {
121 { "forwardagent", oForwardAgent },
122 { "forwardx11", oForwardX11 },
Damien Millerd3a18572000-06-07 19:55:44 +1000123 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100124 { "gatewayports", oGatewayPorts },
125 { "useprivilegedport", oUsePrivilegedPort },
126 { "rhostsauthentication", oRhostsAuthentication },
127 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100128 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
129 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100130 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100131 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000132 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
133 { "challengeresponseauthentication", oChallengeResponseAuthentication },
134 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
135 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000136#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100137 { "kerberosauthentication", oKerberosAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000138#endif /* KRB4 */
139#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100140 { "kerberostgtpassing", oKerberosTgtPassing },
141 { "afstokenpassing", oAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000142#endif
Damien Miller95def091999-11-25 00:26:21 +1100143 { "fallbacktorsh", oFallBackToRsh },
144 { "usersh", oUseRsh },
145 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100146 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100147 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000148 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100149 { "proxycommand", oProxyCommand },
150 { "port", oPort },
151 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000152 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000153 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000154 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100155 { "remoteforward", oRemoteForward },
156 { "localforward", oLocalForward },
157 { "user", oUser },
158 { "host", oHost },
159 { "escapechar", oEscapeChar },
160 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
161 { "globalknownhostsfile", oGlobalKnownHostsFile },
162 { "userknownhostsfile", oUserKnownHostsFile },
Damien Millereba71ba2000-04-29 23:57:08 +1000163 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
164 { "userknownhostsfile2", oUserKnownHostsFile2 },
Damien Miller95def091999-11-25 00:26:21 +1100165 { "connectionattempts", oConnectionAttempts },
166 { "batchmode", oBatchMode },
167 { "checkhostip", oCheckHostIP },
168 { "stricthostkeychecking", oStrictHostKeyChecking },
169 { "compression", oCompression },
170 { "compressionlevel", oCompressionLevel },
171 { "keepalive", oKeepAlives },
172 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100173 { "loglevel", oLogLevel },
174 { NULL, 0 }
Damien Miller5ce662a1999-11-11 17:57:39 +1100175};
176
Damien Miller5428f641999-11-25 11:54:57 +1100177/*
178 * Adds a local TCP/IP port forward to options. Never returns if there is an
179 * error.
180 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000181
Damien Miller4af51302000-04-16 11:18:38 +1000182void
Damien Milleraae6c611999-12-06 11:47:28 +1100183add_local_forward(Options *options, u_short port, const char *host,
184 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000185{
Damien Miller95def091999-11-25 00:26:21 +1100186 Forward *fwd;
Damien Millerbac2d8a2000-09-05 16:13:06 +1100187#ifndef HAVE_CYGWIN
Damien Miller95def091999-11-25 00:26:21 +1100188 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100189 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000190 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100191#endif
Damien Miller95def091999-11-25 00:26:21 +1100192 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
193 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
194 fwd = &options->local_forwards[options->num_local_forwards++];
195 fwd->port = port;
196 fwd->host = xstrdup(host);
197 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000198}
199
Damien Miller5428f641999-11-25 11:54:57 +1100200/*
201 * Adds a remote TCP/IP port forward to options. Never returns if there is
202 * an error.
203 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000204
Damien Miller4af51302000-04-16 11:18:38 +1000205void
Damien Milleraae6c611999-12-06 11:47:28 +1100206add_remote_forward(Options *options, u_short port, const char *host,
207 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000208{
Damien Miller95def091999-11-25 00:26:21 +1100209 Forward *fwd;
210 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
211 fatal("Too many remote forwards (max %d).",
212 SSH_MAX_FORWARDS_PER_DIRECTION);
213 fwd = &options->remote_forwards[options->num_remote_forwards++];
214 fwd->port = port;
215 fwd->host = xstrdup(host);
216 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000217}
218
Damien Miller5428f641999-11-25 11:54:57 +1100219/*
220 * Returns the number of the token pointed to by cp of length len. Never
221 * returns if the token is not known.
222 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223
Damien Miller4af51302000-04-16 11:18:38 +1000224static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100225parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000226{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000227 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000228
Damien Miller95def091999-11-25 00:26:21 +1100229 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100230 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100231 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000232
Damien Miller95def091999-11-25 00:26:21 +1100233 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
234 filename, linenum, cp);
235 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000236}
237
Damien Miller5428f641999-11-25 11:54:57 +1100238/*
239 * Processes a single option line as used in the configuration files. This
240 * only sets those values that have not already been set.
241 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000242
Damien Miller2ccf6611999-11-15 15:25:10 +1100243int
244process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100245 char *line, const char *filename, int linenum,
246 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000247{
Damien Miller37023962000-07-11 17:31:38 +1000248 char buf[256], *s, *string, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100249 int opcode, *intptr, value;
250 u_short fwd_port, fwd_host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000251
Damien Millerbe484b52000-07-15 14:14:16 +1000252 s = line;
253 /* Get the keyword. (Each line is supposed to begin with a keyword). */
254 keyword = strdelim(&s);
255 /* Ignore leading whitespace. */
256 if (*keyword == '\0')
257 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000258 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100259 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000260
Damien Miller37023962000-07-11 17:31:38 +1000261 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000262
Damien Miller95def091999-11-25 00:26:21 +1100263 switch (opcode) {
264 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100265 /* don't panic, but count bad options */
266 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100267 /* NOTREACHED */
268 case oForwardAgent:
269 intptr = &options->forward_agent;
270parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000271 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000272 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100273 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
274 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000275 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100276 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000277 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100278 value = 0;
279 else
280 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
281 if (*activep && *intptr == -1)
282 *intptr = value;
283 break;
284
285 case oForwardX11:
286 intptr = &options->forward_x11;
287 goto parse_flag;
288
289 case oGatewayPorts:
290 intptr = &options->gateway_ports;
291 goto parse_flag;
292
293 case oUsePrivilegedPort:
294 intptr = &options->use_privileged_port;
295 goto parse_flag;
296
297 case oRhostsAuthentication:
298 intptr = &options->rhosts_authentication;
299 goto parse_flag;
300
301 case oPasswordAuthentication:
302 intptr = &options->password_authentication;
303 goto parse_flag;
304
Damien Miller874d77b2000-10-14 16:23:11 +1100305 case oKbdInteractiveAuthentication:
306 intptr = &options->kbd_interactive_authentication;
307 goto parse_flag;
308
309 case oKbdInteractiveDevices:
310 charptr = &options->kbd_interactive_devices;
311 goto parse_string;
312
Damien Miller0bc1bd82000-11-13 22:57:25 +1100313 case oPubkeyAuthentication:
314 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000315 goto parse_flag;
316
Damien Miller95def091999-11-25 00:26:21 +1100317 case oRSAAuthentication:
318 intptr = &options->rsa_authentication;
319 goto parse_flag;
320
321 case oRhostsRSAAuthentication:
322 intptr = &options->rhosts_rsa_authentication;
323 goto parse_flag;
324
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000325 case oChallengeResponseAuthentication:
326 intptr = &options->challenge_reponse_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100327 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000328
329#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100330 case oKerberosAuthentication:
331 intptr = &options->kerberos_authentication;
332 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000333#endif /* KRB4 */
334
335#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100336 case oKerberosTgtPassing:
337 intptr = &options->kerberos_tgt_passing;
338 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000339
Damien Miller95def091999-11-25 00:26:21 +1100340 case oAFSTokenPassing:
341 intptr = &options->afs_token_passing;
342 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000343#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000344
Damien Miller95def091999-11-25 00:26:21 +1100345 case oFallBackToRsh:
346 intptr = &options->fallback_to_rsh;
347 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000348
Damien Miller95def091999-11-25 00:26:21 +1100349 case oUseRsh:
350 intptr = &options->use_rsh;
351 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000352
Damien Miller95def091999-11-25 00:26:21 +1100353 case oBatchMode:
354 intptr = &options->batch_mode;
355 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000356
Damien Miller95def091999-11-25 00:26:21 +1100357 case oCheckHostIP:
358 intptr = &options->check_host_ip;
359 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000360
Damien Miller95def091999-11-25 00:26:21 +1100361 case oStrictHostKeyChecking:
362 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000363 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000364 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000365 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller95def091999-11-25 00:26:21 +1100366 filename, linenum);
367 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000368 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100369 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000370 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100371 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000372 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100373 value = 2;
374 else
375 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
376 if (*activep && *intptr == -1)
377 *intptr = value;
378 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000379
Damien Miller95def091999-11-25 00:26:21 +1100380 case oCompression:
381 intptr = &options->compression;
382 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000383
Damien Miller95def091999-11-25 00:26:21 +1100384 case oKeepAlives:
385 intptr = &options->keepalives;
386 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000387
Damien Miller95def091999-11-25 00:26:21 +1100388 case oNumberOfPasswordPrompts:
389 intptr = &options->number_of_password_prompts;
390 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000391
Damien Miller95def091999-11-25 00:26:21 +1100392 case oCompressionLevel:
393 intptr = &options->compression_level;
394 goto parse_int;
395
396 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000397 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000398 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100399 fatal("%.200s line %d: Missing argument.", filename, linenum);
400 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100401 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000402 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100403 fatal("%.200s line %d: Too many identity files specified (max %d).",
404 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100405 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000406 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000407 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100408 }
409 break;
410
Damien Millerd3a18572000-06-07 19:55:44 +1000411 case oXAuthLocation:
412 charptr=&options->xauth_location;
413 goto parse_string;
414
Damien Miller95def091999-11-25 00:26:21 +1100415 case oUser:
416 charptr = &options->user;
417parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000418 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000419 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100420 fatal("%.200s line %d: Missing argument.", filename, linenum);
421 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000422 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100423 break;
424
425 case oGlobalKnownHostsFile:
426 charptr = &options->system_hostfile;
427 goto parse_string;
428
429 case oUserKnownHostsFile:
430 charptr = &options->user_hostfile;
431 goto parse_string;
432
Damien Millereba71ba2000-04-29 23:57:08 +1000433 case oGlobalKnownHostsFile2:
434 charptr = &options->system_hostfile2;
435 goto parse_string;
436
437 case oUserKnownHostsFile2:
438 charptr = &options->user_hostfile2;
439 goto parse_string;
440
Damien Miller95def091999-11-25 00:26:21 +1100441 case oHostName:
442 charptr = &options->hostname;
443 goto parse_string;
444
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000445 case oHostKeyAlias:
446 charptr = &options->host_key_alias;
447 goto parse_string;
448
Damien Miller95def091999-11-25 00:26:21 +1100449 case oProxyCommand:
450 charptr = &options->proxy_command;
451 string = xstrdup("");
Damien Millerbe484b52000-07-15 14:14:16 +1000452 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000453 string = xrealloc(string, strlen(string) + strlen(arg) + 2);
Damien Miller95def091999-11-25 00:26:21 +1100454 strcat(string, " ");
Damien Miller37023962000-07-11 17:31:38 +1000455 strcat(string, arg);
Damien Miller95def091999-11-25 00:26:21 +1100456 }
457 if (*activep && *charptr == NULL)
458 *charptr = string;
459 else
460 xfree(string);
461 return 0;
462
463 case oPort:
464 intptr = &options->port;
465parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000466 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000467 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100468 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000469 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100470 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100471
472 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000473 value = strtol(arg, &endofnumber, 0);
474 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100475 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100476 if (*activep && *intptr == -1)
477 *intptr = value;
478 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000479
Damien Miller95def091999-11-25 00:26:21 +1100480 case oConnectionAttempts:
481 intptr = &options->connection_attempts;
482 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100483
Damien Miller95def091999-11-25 00:26:21 +1100484 case oCipher:
485 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000486 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000487 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000488 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000489 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100490 if (value == -1)
491 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000492 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100493 if (*activep && *intptr == -1)
494 *intptr = value;
495 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000496
Damien Miller78928792000-04-12 20:17:38 +1000497 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000498 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000499 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000500 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000501 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000502 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000503 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000504 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000505 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000506 break;
507
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000508 case oMacs:
509 arg = strdelim(&s);
510 if (!arg || *arg == '\0')
511 fatal("%.200s line %d: Missing argument.", filename, linenum);
512 if (!mac_valid(arg))
513 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
514 filename, linenum, arg ? arg : "<NONE>");
515 if (*activep && options->macs == NULL)
516 options->macs = xstrdup(arg);
517 break;
518
Damien Miller78928792000-04-12 20:17:38 +1000519 case oProtocol:
520 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000521 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000522 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000523 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000524 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000525 if (value == SSH_PROTO_UNKNOWN)
526 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000527 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000528 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
529 *intptr = value;
530 break;
531
Damien Miller95def091999-11-25 00:26:21 +1100532 case oLogLevel:
533 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000534 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000535 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100536 if (value == (LogLevel) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000537 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000538 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100539 if (*activep && (LogLevel) * intptr == -1)
540 *intptr = (LogLevel) value;
541 break;
542
543 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000544 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000545 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100546 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000547 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100548 fatal("%.200s line %d: Badly formatted port number.",
549 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000550 fwd_port = atoi(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000551 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000552 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100553 fatal("%.200s line %d: Missing second argument.",
554 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000555 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
Damien Miller95def091999-11-25 00:26:21 +1100556 fatal("%.200s line %d: Badly formatted host:port.",
557 filename, linenum);
558 if (*activep)
559 add_remote_forward(options, fwd_port, buf, fwd_host_port);
560 break;
561
562 case oLocalForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000563 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000564 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100565 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000566 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100567 fatal("%.200s line %d: Badly formatted port number.",
568 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000569 fwd_port = atoi(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000570 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000571 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100572 fatal("%.200s line %d: Missing second argument.",
573 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000574 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
Damien Miller95def091999-11-25 00:26:21 +1100575 fatal("%.200s line %d: Badly formatted host:port.",
576 filename, linenum);
577 if (*activep)
578 add_local_forward(options, fwd_port, buf, fwd_host_port);
579 break;
580
581 case oHost:
582 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000583 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000584 if (match_pattern(host, arg)) {
585 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100586 *activep = 1;
587 break;
588 }
Damien Millerbe484b52000-07-15 14:14:16 +1000589 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100590 return 0;
591
592 case oEscapeChar:
593 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000594 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000595 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100596 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000597 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000598 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
599 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000600 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000601 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000602 else if (strcmp(arg, "none") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100603 value = -2;
604 else {
605 fatal("%.200s line %d: Bad escape character.",
606 filename, linenum);
607 /* NOTREACHED */
608 value = 0; /* Avoid compiler warning. */
609 }
610 if (*activep && *intptr == -1)
611 *intptr = value;
612 break;
613
614 default:
615 fatal("process_config_line: Unimplemented opcode %d", opcode);
616 }
617
618 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000619 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000620 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
621 filename, linenum, arg);
622 }
Damien Miller95def091999-11-25 00:26:21 +1100623 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000624}
625
626
Damien Miller5428f641999-11-25 11:54:57 +1100627/*
628 * Reads the config file and modifies the options accordingly. Options
629 * should already be initialized before this call. This never returns if
630 * there is an error. If the file does not exist, this returns immediately.
631 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000632
Damien Miller4af51302000-04-16 11:18:38 +1000633void
Damien Miller95def091999-11-25 00:26:21 +1100634read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000635{
Damien Miller95def091999-11-25 00:26:21 +1100636 FILE *f;
637 char line[1024];
638 int active, linenum;
639 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000640
Damien Miller95def091999-11-25 00:26:21 +1100641 /* Open the file. */
642 f = fopen(filename, "r");
643 if (!f)
644 return;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000645
Damien Miller95def091999-11-25 00:26:21 +1100646 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000647
Damien Miller5428f641999-11-25 11:54:57 +1100648 /*
649 * Mark that we are now processing the options. This flag is turned
650 * on/off by Host specifications.
651 */
Damien Miller95def091999-11-25 00:26:21 +1100652 active = 1;
653 linenum = 0;
654 while (fgets(line, sizeof(line), f)) {
655 /* Update line number counter. */
656 linenum++;
657 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
658 bad_options++;
659 }
660 fclose(f);
661 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000662 fatal("%s: terminating, %d bad configuration options",
Damien Miller95def091999-11-25 00:26:21 +1100663 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000664}
665
Damien Miller5428f641999-11-25 11:54:57 +1100666/*
667 * Initializes options to special values that indicate that they have not yet
668 * been set. Read_config_file will only set options with this value. Options
669 * are processed in the following order: command line, user config file,
670 * system config file. Last, fill_default_options is called.
671 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000672
Damien Miller4af51302000-04-16 11:18:38 +1000673void
Damien Miller95def091999-11-25 00:26:21 +1100674initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000675{
Damien Miller95def091999-11-25 00:26:21 +1100676 memset(options, 'X', sizeof(*options));
677 options->forward_agent = -1;
678 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000679 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100680 options->gateway_ports = -1;
681 options->use_privileged_port = -1;
682 options->rhosts_authentication = -1;
683 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100684 options->pubkey_authentication = -1;
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000685 options->challenge_reponse_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000686#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100687 options->kerberos_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000688#endif
689#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100690 options->kerberos_tgt_passing = -1;
691 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000692#endif
Damien Miller95def091999-11-25 00:26:21 +1100693 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100694 options->kbd_interactive_authentication = -1;
695 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100696 options->rhosts_rsa_authentication = -1;
697 options->fallback_to_rsh = -1;
698 options->use_rsh = -1;
699 options->batch_mode = -1;
700 options->check_host_ip = -1;
701 options->strict_host_key_checking = -1;
702 options->compression = -1;
703 options->keepalives = -1;
704 options->compression_level = -1;
705 options->port = -1;
706 options->connection_attempts = -1;
707 options->number_of_password_prompts = -1;
708 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000709 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000710 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000711 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100712 options->num_identity_files = 0;
713 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000714 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100715 options->proxy_command = NULL;
716 options->user = NULL;
717 options->escape_char = -1;
718 options->system_hostfile = NULL;
719 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000720 options->system_hostfile2 = NULL;
721 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100722 options->num_local_forwards = 0;
723 options->num_remote_forwards = 0;
724 options->log_level = (LogLevel) - 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000725}
726
Damien Miller5428f641999-11-25 11:54:57 +1100727/*
728 * Called after processing other sources of option data, this fills those
729 * options for which no value has been specified with their default values.
730 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000731
Damien Miller4af51302000-04-16 11:18:38 +1000732void
Damien Miller95def091999-11-25 00:26:21 +1100733fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000734{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000735 int len;
736
Damien Miller95def091999-11-25 00:26:21 +1100737 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000738 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100739 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100740 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000741#ifdef XAUTH_PATH
742 if (options->xauth_location == NULL)
743 options->xauth_location = XAUTH_PATH;
744#endif /* XAUTH_PATH */
Damien Miller95def091999-11-25 00:26:21 +1100745 if (options->gateway_ports == -1)
746 options->gateway_ports = 0;
747 if (options->use_privileged_port == -1)
748 options->use_privileged_port = 1;
749 if (options->rhosts_authentication == -1)
750 options->rhosts_authentication = 1;
751 if (options->rsa_authentication == -1)
752 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100753 if (options->pubkey_authentication == -1)
754 options->pubkey_authentication = 1;
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000755 if (options->challenge_reponse_authentication == -1)
756 options->challenge_reponse_authentication = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000757#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100758 if (options->kerberos_authentication == -1)
759 options->kerberos_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000760#endif /* KRB4 */
761#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100762 if (options->kerberos_tgt_passing == -1)
763 options->kerberos_tgt_passing = 1;
764 if (options->afs_token_passing == -1)
765 options->afs_token_passing = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000766#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100767 if (options->password_authentication == -1)
768 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100769 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000770 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100771 if (options->rhosts_rsa_authentication == -1)
772 options->rhosts_rsa_authentication = 1;
773 if (options->fallback_to_rsh == -1)
Damien Miller182ee6e2000-07-12 09:45:27 +1000774 options->fallback_to_rsh = 0;
Damien Miller95def091999-11-25 00:26:21 +1100775 if (options->use_rsh == -1)
776 options->use_rsh = 0;
777 if (options->batch_mode == -1)
778 options->batch_mode = 0;
779 if (options->check_host_ip == -1)
780 options->check_host_ip = 1;
781 if (options->strict_host_key_checking == -1)
782 options->strict_host_key_checking = 2; /* 2 is default */
783 if (options->compression == -1)
784 options->compression = 0;
785 if (options->keepalives == -1)
786 options->keepalives = 1;
787 if (options->compression_level == -1)
788 options->compression_level = 6;
789 if (options->port == -1)
790 options->port = 0; /* Filled in ssh_connect. */
791 if (options->connection_attempts == -1)
792 options->connection_attempts = 4;
793 if (options->number_of_password_prompts == -1)
794 options->number_of_password_prompts = 3;
795 /* Selected in ssh_login(). */
796 if (options->cipher == -1)
797 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000798 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000799 /* options->macs, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000800 if (options->protocol == SSH_PROTO_UNKNOWN)
Damien Millereba71ba2000-04-29 23:57:08 +1000801 options->protocol = SSH_PROTO_1|SSH_PROTO_2|SSH_PROTO_1_PREFERRED;
Damien Miller95def091999-11-25 00:26:21 +1100802 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100803 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000804 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100805 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000806 xmalloc(len);
807 snprintf(options->identity_files[options->num_identity_files++],
808 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100809 }
810 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000811 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
812 options->identity_files[options->num_identity_files] =
813 xmalloc(len);
814 snprintf(options->identity_files[options->num_identity_files++],
815 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
816
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000817 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100818 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000819 xmalloc(len);
820 snprintf(options->identity_files[options->num_identity_files++],
821 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100822 }
Damien Millereba71ba2000-04-29 23:57:08 +1000823 }
Damien Miller95def091999-11-25 00:26:21 +1100824 if (options->escape_char == -1)
825 options->escape_char = '~';
826 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000827 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100828 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000829 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000830 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000831 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000832 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000833 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Miller95def091999-11-25 00:26:21 +1100834 if (options->log_level == (LogLevel) - 1)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000835 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100836 /* options->proxy_command should not be set by default */
837 /* options->user will be set in the main program if appropriate */
838 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000839 /* options->host_key_alias should not be set by default */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000840}