blob: a0cf3d6873215efbb6e6d876f21892b22e35eb91 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11003 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11005 * Functions for reading the configuration files.
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerb78d5eb2003-05-16 11:39:04 +100015RCSID("$OpenBSD: readconf.c,v 1.111 2003/05/15 14:55:25 djm 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
Ben Lindstrom4daea862002-06-09 20:04:02 +000044 User foo
Damien Millerd4a8b7e1999-10-27 13:42:43 +100045
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
Ben Lindstrom4daea862002-06-09 20:04:02 +000068 PublicKeyAuthentication no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100069
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
Damien Millerd4a8b7e1999-10-27 13:42:43 +100082 StrictHostKeyChecking yes
83 KeepAlives no
84 IdentityFile ~/.ssh/identity
85 Port 22
86 EscapeChar ~
87
88*/
89
90/* Keyword tokens. */
91
Damien Miller95def091999-11-25 00:26:21 +110092typedef enum {
93 oBadOption,
94 oForwardAgent, oForwardX11, oGatewayPorts, oRhostsAuthentication,
Ben Lindstromcb72e4f2002-06-21 00:41:51 +000095 oPasswordAuthentication, oRSAAuthentication,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000096 oChallengeResponseAuthentication, oXAuthLocation,
Damien Miller2aa0ab42003-05-15 12:05:28 +100097 oKerberosAuthentication, oKerberosTgtPassing, oAFSTokenPassing,
Damien Miller95def091999-11-25 00:26:21 +110098 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
99 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
100 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
101 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000102 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000103 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100104 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000105 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000106 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000107 oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000108 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
Damien Millerb78d5eb2003-05-16 11:39:04 +1000109 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000110 oDeprecated, oUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000111} OpCodes;
112
113/* Textual representations of the tokens. */
114
Damien Miller95def091999-11-25 00:26:21 +1100115static struct {
116 const char *name;
117 OpCodes opcode;
118} keywords[] = {
119 { "forwardagent", oForwardAgent },
120 { "forwardx11", oForwardX11 },
Damien Millerd3a18572000-06-07 19:55:44 +1000121 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100122 { "gatewayports", oGatewayPorts },
123 { "useprivilegedport", oUsePrivilegedPort },
124 { "rhostsauthentication", oRhostsAuthentication },
125 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100126 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
127 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100128 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100129 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000130 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000131 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000132 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000133 { "challengeresponseauthentication", oChallengeResponseAuthentication },
134 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
135 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Millerf9b3feb2003-05-16 11:38:32 +1000136#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100137 { "kerberosauthentication", oKerberosAuthentication },
Damien Miller95def091999-11-25 00:26:21 +1100138 { "kerberostgtpassing", oKerberosTgtPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000139#else
140 { "kerberosauthentication", oUnsupported },
141 { "kerberostgtpassing", oUnsupported },
142#endif
143#if defined(AFS)
Damien Miller95def091999-11-25 00:26:21 +1100144 { "afstokenpassing", oAFSTokenPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000145#else
146 { "afstokenpassing", oUnsupported },
147#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000148 { "fallbacktorsh", oDeprecated },
149 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100150 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100151 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100152 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000153 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100154 { "proxycommand", oProxyCommand },
155 { "port", oPort },
156 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000157 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000158 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000159 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100160 { "remoteforward", oRemoteForward },
161 { "localforward", oLocalForward },
162 { "user", oUser },
163 { "host", oHost },
164 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100165 { "globalknownhostsfile", oGlobalKnownHostsFile },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000166 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
Damien Millereba71ba2000-04-29 23:57:08 +1000167 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000168 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100169 { "connectionattempts", oConnectionAttempts },
170 { "batchmode", oBatchMode },
171 { "checkhostip", oCheckHostIP },
172 { "stricthostkeychecking", oStrictHostKeyChecking },
173 { "compression", oCompression },
174 { "compressionlevel", oCompressionLevel },
175 { "keepalive", oKeepAlives },
176 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100177 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000178 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000179 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000180 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000181 { "bindaddress", oBindAddress },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000182#ifdef SMARTCARD
Ben Lindstromae996bf2001-08-06 21:27:53 +0000183 { "smartcarddevice", oSmartcardDevice },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000184#else
185 { "smartcarddevice", oUnsupported },
186#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100187 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000188 { "enablesshkeysign", oEnableSSHKeysign },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000189#ifdef DNS
Damien Miller37876e92003-05-15 10:19:46 +1000190 { "verifyhostkeydns", oVerifyHostKeyDNS },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000191#else
192 { "verifyhostkeydns", oUnsupported },
193#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100194 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000195 { "rekeylimit", oRekeyLimit },
Damien Millerb78d5eb2003-05-16 11:39:04 +1000196 { "connecttimeout", oConnectTimeout },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000197 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100198};
199
Damien Miller5428f641999-11-25 11:54:57 +1100200/*
201 * Adds a local TCP/IP port forward to options. Never returns if there is an
202 * 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_local_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;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000210#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100211 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100212 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000213 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100214#endif
Damien Miller95def091999-11-25 00:26:21 +1100215 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
216 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
217 fwd = &options->local_forwards[options->num_local_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/*
224 * Adds a remote TCP/IP port forward to options. Never returns if there is
225 * an error.
226 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000227
Damien Miller4af51302000-04-16 11:18:38 +1000228void
Damien Milleraae6c611999-12-06 11:47:28 +1100229add_remote_forward(Options *options, u_short port, const char *host,
230 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000231{
Damien Miller95def091999-11-25 00:26:21 +1100232 Forward *fwd;
233 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
234 fatal("Too many remote forwards (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100235 SSH_MAX_FORWARDS_PER_DIRECTION);
Damien Miller95def091999-11-25 00:26:21 +1100236 fwd = &options->remote_forwards[options->num_remote_forwards++];
237 fwd->port = port;
238 fwd->host = xstrdup(host);
239 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000240}
241
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000242static void
243clear_forwardings(Options *options)
244{
245 int i;
246
247 for (i = 0; i < options->num_local_forwards; i++)
248 xfree(options->local_forwards[i].host);
249 options->num_local_forwards = 0;
250 for (i = 0; i < options->num_remote_forwards; i++)
251 xfree(options->remote_forwards[i].host);
252 options->num_remote_forwards = 0;
253}
254
Damien Miller5428f641999-11-25 11:54:57 +1100255/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000256 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100257 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000258
Damien Miller4af51302000-04-16 11:18:38 +1000259static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100260parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000261{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000262 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000263
Damien Miller95def091999-11-25 00:26:21 +1100264 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100265 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100266 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000267
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000268 error("%s: line %d: Bad configuration option: %s",
269 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100270 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000271}
272
Damien Miller5428f641999-11-25 11:54:57 +1100273/*
274 * Processes a single option line as used in the configuration files. This
275 * only sets those values that have not already been set.
276 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100277#define WHITESPACE " \t\r\n"
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000278
Damien Miller2ccf6611999-11-15 15:25:10 +1100279int
280process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100281 char *line, const char *filename, int linenum,
282 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000283{
Damien Miller61f08ac2003-02-24 11:56:27 +1100284 char buf[256], *s, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100285 int opcode, *intptr, value;
Damien Miller61f08ac2003-02-24 11:56:27 +1100286 size_t len;
Damien Milleraae6c611999-12-06 11:47:28 +1100287 u_short fwd_port, fwd_host_port;
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000288 char sfwd_host_port[6];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000289
Damien Millerc652cac2003-05-14 13:40:54 +1000290 /* Strip trailing whitespace */
291 for(len = strlen(line) - 1; len > 0; len--) {
292 if (strchr(WHITESPACE, line[len]) == NULL)
293 break;
294 line[len] = '\0';
295 }
296
Damien Millerbe484b52000-07-15 14:14:16 +1000297 s = line;
298 /* Get the keyword. (Each line is supposed to begin with a keyword). */
299 keyword = strdelim(&s);
300 /* Ignore leading whitespace. */
301 if (*keyword == '\0')
302 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000303 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100304 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000305
Damien Miller37023962000-07-11 17:31:38 +1000306 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000307
Damien Miller95def091999-11-25 00:26:21 +1100308 switch (opcode) {
309 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100310 /* don't panic, but count bad options */
311 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100312 /* NOTREACHED */
Damien Millerb78d5eb2003-05-16 11:39:04 +1000313 case oConnectTimeout:
314 intptr = &options->connection_timeout;
315/* parse_time: */
316 arg = strdelim(&s);
317 if (!arg || *arg == '\0')
318 fatal("%s line %d: missing time value.",
319 filename, linenum);
320 if ((value = convtime(arg)) == -1)
321 fatal("%s line %d: invalid time value.",
322 filename, linenum);
323 if (*intptr == -1)
324 *intptr = value;
325 break;
326
Damien Miller95def091999-11-25 00:26:21 +1100327 case oForwardAgent:
328 intptr = &options->forward_agent;
329parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000330 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000331 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100332 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
333 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000334 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100335 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000336 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100337 value = 0;
338 else
339 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
340 if (*activep && *intptr == -1)
341 *intptr = value;
342 break;
343
344 case oForwardX11:
345 intptr = &options->forward_x11;
346 goto parse_flag;
347
348 case oGatewayPorts:
349 intptr = &options->gateway_ports;
350 goto parse_flag;
351
352 case oUsePrivilegedPort:
353 intptr = &options->use_privileged_port;
354 goto parse_flag;
355
356 case oRhostsAuthentication:
357 intptr = &options->rhosts_authentication;
358 goto parse_flag;
359
360 case oPasswordAuthentication:
361 intptr = &options->password_authentication;
362 goto parse_flag;
363
Damien Miller874d77b2000-10-14 16:23:11 +1100364 case oKbdInteractiveAuthentication:
365 intptr = &options->kbd_interactive_authentication;
366 goto parse_flag;
367
368 case oKbdInteractiveDevices:
369 charptr = &options->kbd_interactive_devices;
370 goto parse_string;
371
Damien Miller0bc1bd82000-11-13 22:57:25 +1100372 case oPubkeyAuthentication:
373 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000374 goto parse_flag;
375
Damien Miller95def091999-11-25 00:26:21 +1100376 case oRSAAuthentication:
377 intptr = &options->rsa_authentication;
378 goto parse_flag;
379
380 case oRhostsRSAAuthentication:
381 intptr = &options->rhosts_rsa_authentication;
382 goto parse_flag;
383
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000384 case oHostbasedAuthentication:
385 intptr = &options->hostbased_authentication;
386 goto parse_flag;
387
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000388 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000389 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100390 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000391
Damien Miller95def091999-11-25 00:26:21 +1100392 case oKerberosAuthentication:
393 intptr = &options->kerberos_authentication;
394 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000395
Damien Miller95def091999-11-25 00:26:21 +1100396 case oKerberosTgtPassing:
397 intptr = &options->kerberos_tgt_passing;
398 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000399
Damien Miller95def091999-11-25 00:26:21 +1100400 case oAFSTokenPassing:
401 intptr = &options->afs_token_passing;
402 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000403
Damien Miller95def091999-11-25 00:26:21 +1100404 case oBatchMode:
405 intptr = &options->batch_mode;
406 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000407
Damien Miller95def091999-11-25 00:26:21 +1100408 case oCheckHostIP:
409 intptr = &options->check_host_ip;
410 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000411
Damien Miller37876e92003-05-15 10:19:46 +1000412 case oVerifyHostKeyDNS:
413 intptr = &options->verify_host_key_dns;
414 goto parse_flag;
415
Damien Miller95def091999-11-25 00:26:21 +1100416 case oStrictHostKeyChecking:
417 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000418 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000419 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000420 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100421 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100422 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000423 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100424 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000425 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100426 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000427 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100428 value = 2;
429 else
430 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
431 if (*activep && *intptr == -1)
432 *intptr = value;
433 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000434
Damien Miller95def091999-11-25 00:26:21 +1100435 case oCompression:
436 intptr = &options->compression;
437 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000438
Damien Miller95def091999-11-25 00:26:21 +1100439 case oKeepAlives:
440 intptr = &options->keepalives;
441 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000442
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000443 case oNoHostAuthenticationForLocalhost:
444 intptr = &options->no_host_authentication_for_localhost;
445 goto parse_flag;
446
Damien Miller95def091999-11-25 00:26:21 +1100447 case oNumberOfPasswordPrompts:
448 intptr = &options->number_of_password_prompts;
449 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000450
Damien Miller95def091999-11-25 00:26:21 +1100451 case oCompressionLevel:
452 intptr = &options->compression_level;
453 goto parse_int;
454
Damien Millera5539d22003-04-09 20:50:06 +1000455 case oRekeyLimit:
456 intptr = &options->rekey_limit;
457 arg = strdelim(&s);
458 if (!arg || *arg == '\0')
459 fatal("%.200s line %d: Missing argument.", filename, linenum);
460 if (arg[0] < '0' || arg[0] > '9')
461 fatal("%.200s line %d: Bad number.", filename, linenum);
462 value = strtol(arg, &endofnumber, 10);
463 if (arg == endofnumber)
464 fatal("%.200s line %d: Bad number.", filename, linenum);
465 switch (toupper(*endofnumber)) {
466 case 'K':
467 value *= 1<<10;
468 break;
469 case 'M':
470 value *= 1<<20;
471 break;
472 case 'G':
473 value *= 1<<30;
474 break;
475 }
476 if (*activep && *intptr == -1)
477 *intptr = value;
478 break;
479
Damien Miller95def091999-11-25 00:26:21 +1100480 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000481 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000482 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100483 fatal("%.200s line %d: Missing argument.", filename, linenum);
484 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100485 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000486 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100487 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100488 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100489 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000490 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000491 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100492 }
493 break;
494
Damien Millerd3a18572000-06-07 19:55:44 +1000495 case oXAuthLocation:
496 charptr=&options->xauth_location;
497 goto parse_string;
498
Damien Miller95def091999-11-25 00:26:21 +1100499 case oUser:
500 charptr = &options->user;
501parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000502 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000503 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100504 fatal("%.200s line %d: Missing argument.", filename, linenum);
505 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000506 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100507 break;
508
509 case oGlobalKnownHostsFile:
510 charptr = &options->system_hostfile;
511 goto parse_string;
512
513 case oUserKnownHostsFile:
514 charptr = &options->user_hostfile;
515 goto parse_string;
516
Damien Millereba71ba2000-04-29 23:57:08 +1000517 case oGlobalKnownHostsFile2:
518 charptr = &options->system_hostfile2;
519 goto parse_string;
520
521 case oUserKnownHostsFile2:
522 charptr = &options->user_hostfile2;
523 goto parse_string;
524
Damien Miller95def091999-11-25 00:26:21 +1100525 case oHostName:
526 charptr = &options->hostname;
527 goto parse_string;
528
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000529 case oHostKeyAlias:
530 charptr = &options->host_key_alias;
531 goto parse_string;
532
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000533 case oPreferredAuthentications:
534 charptr = &options->preferred_authentications;
535 goto parse_string;
536
Ben Lindstrome0f88042001-04-30 13:06:24 +0000537 case oBindAddress:
538 charptr = &options->bind_address;
539 goto parse_string;
540
Ben Lindstromae996bf2001-08-06 21:27:53 +0000541 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000542 charptr = &options->smartcard_device;
543 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000544
Damien Miller95def091999-11-25 00:26:21 +1100545 case oProxyCommand:
546 charptr = &options->proxy_command;
Damien Miller61f08ac2003-02-24 11:56:27 +1100547 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +1100548 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +1100549 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +1100550 return 0;
551
552 case oPort:
553 intptr = &options->port;
554parse_int:
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: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100560
561 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000562 value = strtol(arg, &endofnumber, 0);
563 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100564 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100565 if (*activep && *intptr == -1)
566 *intptr = value;
567 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000568
Damien Miller95def091999-11-25 00:26:21 +1100569 case oConnectionAttempts:
570 intptr = &options->connection_attempts;
571 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100572
Damien Miller95def091999-11-25 00:26:21 +1100573 case oCipher:
574 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000575 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000576 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000577 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000578 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100579 if (value == -1)
580 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100581 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100582 if (*activep && *intptr == -1)
583 *intptr = value;
584 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000585
Damien Miller78928792000-04-12 20:17:38 +1000586 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000587 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000588 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000589 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000590 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000591 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100592 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000593 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000594 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000595 break;
596
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000597 case oMacs:
598 arg = strdelim(&s);
599 if (!arg || *arg == '\0')
600 fatal("%.200s line %d: Missing argument.", filename, linenum);
601 if (!mac_valid(arg))
602 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100603 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000604 if (*activep && options->macs == NULL)
605 options->macs = xstrdup(arg);
606 break;
607
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000608 case oHostKeyAlgorithms:
609 arg = strdelim(&s);
610 if (!arg || *arg == '\0')
611 fatal("%.200s line %d: Missing argument.", filename, linenum);
612 if (!key_names_valid2(arg))
613 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100614 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000615 if (*activep && options->hostkeyalgorithms == NULL)
616 options->hostkeyalgorithms = xstrdup(arg);
617 break;
618
Damien Miller78928792000-04-12 20:17:38 +1000619 case oProtocol:
620 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000621 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000622 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000623 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000624 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000625 if (value == SSH_PROTO_UNKNOWN)
626 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100627 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000628 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
629 *intptr = value;
630 break;
631
Damien Miller95def091999-11-25 00:26:21 +1100632 case oLogLevel:
633 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000634 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000635 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100636 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000637 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100638 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100639 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100640 *intptr = (LogLevel) value;
641 break;
642
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000643 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100644 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000645 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000646 if (!arg || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000647 fatal("%.200s line %d: Missing port argument.",
648 filename, linenum);
649 if ((fwd_port = a2port(arg)) == 0)
650 fatal("%.200s line %d: Bad listen port.",
651 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000652 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000653 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100654 fatal("%.200s line %d: Missing second argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000655 filename, linenum);
656 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
657 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
658 fatal("%.200s line %d: Bad forwarding specification.",
659 filename, linenum);
660 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
661 fatal("%.200s line %d: Bad forwarding port.",
662 filename, linenum);
663 if (*activep) {
664 if (opcode == oLocalForward)
665 add_local_forward(options, fwd_port, buf,
666 fwd_host_port);
667 else if (opcode == oRemoteForward)
668 add_remote_forward(options, fwd_port, buf,
669 fwd_host_port);
670 }
Damien Miller95def091999-11-25 00:26:21 +1100671 break;
672
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000673 case oDynamicForward:
674 arg = strdelim(&s);
675 if (!arg || *arg == '\0')
676 fatal("%.200s line %d: Missing port argument.",
677 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000678 fwd_port = a2port(arg);
679 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000680 fatal("%.200s line %d: Badly formatted port number.",
681 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000682 if (*activep)
683 add_local_forward(options, fwd_port, "socks4", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000684 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000685
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000686 case oClearAllForwardings:
687 intptr = &options->clear_forwardings;
688 goto parse_flag;
689
Damien Miller95def091999-11-25 00:26:21 +1100690 case oHost:
691 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000692 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000693 if (match_pattern(host, arg)) {
694 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100695 *activep = 1;
696 break;
697 }
Damien Millerbe484b52000-07-15 14:14:16 +1000698 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100699 return 0;
700
701 case oEscapeChar:
702 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000703 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000704 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100705 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000706 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000707 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
708 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000709 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000710 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000711 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000712 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100713 else {
714 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100715 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100716 /* NOTREACHED */
717 value = 0; /* Avoid compiler warning. */
718 }
719 if (*activep && *intptr == -1)
720 *intptr = value;
721 break;
722
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000723 case oEnableSSHKeysign:
724 intptr = &options->enable_ssh_keysign;
725 goto parse_flag;
726
Ben Lindstrom4daea862002-06-09 20:04:02 +0000727 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000728 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +0000729 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000730 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +0000731
Damien Millerf9b3feb2003-05-16 11:38:32 +1000732 case oUnsupported:
733 error("%s line %d: Unsupported option \"%s\"",
734 filename, linenum, keyword);
735 return 0;
736
Damien Miller95def091999-11-25 00:26:21 +1100737 default:
738 fatal("process_config_line: Unimplemented opcode %d", opcode);
739 }
740
741 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000742 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000743 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100744 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000745 }
Damien Miller95def091999-11-25 00:26:21 +1100746 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000747}
748
749
Damien Miller5428f641999-11-25 11:54:57 +1100750/*
751 * Reads the config file and modifies the options accordingly. Options
752 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000753 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100754 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000755
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000756int
Damien Miller95def091999-11-25 00:26:21 +1100757read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000758{
Damien Miller95def091999-11-25 00:26:21 +1100759 FILE *f;
760 char line[1024];
761 int active, linenum;
762 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000763
Damien Miller95def091999-11-25 00:26:21 +1100764 /* Open the file. */
765 f = fopen(filename, "r");
766 if (!f)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000767 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000768
Damien Miller95def091999-11-25 00:26:21 +1100769 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000770
Damien Miller5428f641999-11-25 11:54:57 +1100771 /*
772 * Mark that we are now processing the options. This flag is turned
773 * on/off by Host specifications.
774 */
Damien Miller95def091999-11-25 00:26:21 +1100775 active = 1;
776 linenum = 0;
777 while (fgets(line, sizeof(line), f)) {
778 /* Update line number counter. */
779 linenum++;
780 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
781 bad_options++;
782 }
783 fclose(f);
784 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000785 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100786 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000787 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000788}
789
Damien Miller5428f641999-11-25 11:54:57 +1100790/*
791 * Initializes options to special values that indicate that they have not yet
792 * been set. Read_config_file will only set options with this value. Options
793 * are processed in the following order: command line, user config file,
794 * system config file. Last, fill_default_options is called.
795 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000796
Damien Miller4af51302000-04-16 11:18:38 +1000797void
Damien Miller95def091999-11-25 00:26:21 +1100798initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000799{
Damien Miller95def091999-11-25 00:26:21 +1100800 memset(options, 'X', sizeof(*options));
801 options->forward_agent = -1;
802 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000803 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100804 options->gateway_ports = -1;
805 options->use_privileged_port = -1;
806 options->rhosts_authentication = -1;
807 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100808 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000809 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100810 options->kerberos_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100811 options->kerberos_tgt_passing = -1;
812 options->afs_token_passing = -1;
Damien Miller95def091999-11-25 00:26:21 +1100813 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100814 options->kbd_interactive_authentication = -1;
815 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100816 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000817 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100818 options->batch_mode = -1;
819 options->check_host_ip = -1;
820 options->strict_host_key_checking = -1;
821 options->compression = -1;
822 options->keepalives = -1;
823 options->compression_level = -1;
824 options->port = -1;
825 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000826 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +1100827 options->number_of_password_prompts = -1;
828 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000829 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000830 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000831 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000832 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100833 options->num_identity_files = 0;
834 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000835 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100836 options->proxy_command = NULL;
837 options->user = NULL;
838 options->escape_char = -1;
839 options->system_hostfile = NULL;
840 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000841 options->system_hostfile2 = NULL;
842 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100843 options->num_local_forwards = 0;
844 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000845 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100846 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000847 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000848 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000849 options->smartcard_device = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000850 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000851 options->no_host_authentication_for_localhost = - 1;
Damien Millera5539d22003-04-09 20:50:06 +1000852 options->rekey_limit = - 1;
Damien Miller37876e92003-05-15 10:19:46 +1000853 options->verify_host_key_dns = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000854}
855
Damien Miller5428f641999-11-25 11:54:57 +1100856/*
857 * Called after processing other sources of option data, this fills those
858 * options for which no value has been specified with their default values.
859 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000860
Damien Miller4af51302000-04-16 11:18:38 +1000861void
Damien Miller95def091999-11-25 00:26:21 +1100862fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000863{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000864 int len;
865
Damien Miller95def091999-11-25 00:26:21 +1100866 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000867 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100868 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100869 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000870 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000871 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100872 if (options->gateway_ports == -1)
873 options->gateway_ports = 0;
874 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000875 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100876 if (options->rhosts_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000877 options->rhosts_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100878 if (options->rsa_authentication == -1)
879 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100880 if (options->pubkey_authentication == -1)
881 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000882 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000883 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100884 if (options->kerberos_authentication == -1)
885 options->kerberos_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100886 if (options->kerberos_tgt_passing == -1)
887 options->kerberos_tgt_passing = 1;
888 if (options->afs_token_passing == -1)
889 options->afs_token_passing = 1;
Damien Miller95def091999-11-25 00:26:21 +1100890 if (options->password_authentication == -1)
891 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100892 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000893 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100894 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000895 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000896 if (options->hostbased_authentication == -1)
897 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100898 if (options->batch_mode == -1)
899 options->batch_mode = 0;
900 if (options->check_host_ip == -1)
901 options->check_host_ip = 1;
902 if (options->strict_host_key_checking == -1)
903 options->strict_host_key_checking = 2; /* 2 is default */
904 if (options->compression == -1)
905 options->compression = 0;
906 if (options->keepalives == -1)
907 options->keepalives = 1;
908 if (options->compression_level == -1)
909 options->compression_level = 6;
910 if (options->port == -1)
911 options->port = 0; /* Filled in ssh_connect. */
912 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000913 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100914 if (options->number_of_password_prompts == -1)
915 options->number_of_password_prompts = 3;
916 /* Selected in ssh_login(). */
917 if (options->cipher == -1)
918 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000919 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000920 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000921 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000922 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000923 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100924 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100925 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000926 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100927 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000928 xmalloc(len);
929 snprintf(options->identity_files[options->num_identity_files++],
930 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100931 }
932 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000933 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
934 options->identity_files[options->num_identity_files] =
935 xmalloc(len);
936 snprintf(options->identity_files[options->num_identity_files++],
937 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
938
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000939 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100940 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000941 xmalloc(len);
942 snprintf(options->identity_files[options->num_identity_files++],
943 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100944 }
Damien Millereba71ba2000-04-29 23:57:08 +1000945 }
Damien Miller95def091999-11-25 00:26:21 +1100946 if (options->escape_char == -1)
947 options->escape_char = '~';
948 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000949 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100950 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000951 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000952 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000953 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000954 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000955 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +1100956 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000957 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000958 if (options->clear_forwardings == 1)
959 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000960 if (options->no_host_authentication_for_localhost == - 1)
961 options->no_host_authentication_for_localhost = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000962 if (options->enable_ssh_keysign == -1)
963 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +1000964 if (options->rekey_limit == -1)
965 options->rekey_limit = 0;
Damien Miller37876e92003-05-15 10:19:46 +1000966 if (options->verify_host_key_dns == -1)
967 options->verify_host_key_dns = 0;
Damien Miller95def091999-11-25 00:26:21 +1100968 /* options->proxy_command should not be set by default */
969 /* options->user will be set in the main program if appropriate */
970 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000971 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000972 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000973}