blob: 3c08f7638d79535bdd166be5e15d8ac91a9467a8 [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"
Darren Tucker0a4f04b2003-07-03 20:37:47 +100015RCSID("$OpenBSD: readconf.c,v 1.114 2003/07/03 08:09:05 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 Miller20a8f972003-05-18 20:50:30 +1000110 oAddressFamily,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000111 oDeprecated, oUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000112} OpCodes;
113
114/* Textual representations of the tokens. */
115
Damien Miller95def091999-11-25 00:26:21 +1100116static struct {
117 const char *name;
118 OpCodes opcode;
119} keywords[] = {
120 { "forwardagent", oForwardAgent },
121 { "forwardx11", oForwardX11 },
Damien Millerd3a18572000-06-07 19:55:44 +1000122 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100123 { "gatewayports", oGatewayPorts },
124 { "useprivilegedport", oUsePrivilegedPort },
125 { "rhostsauthentication", oRhostsAuthentication },
126 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100127 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
128 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100129 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100130 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000131 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000132 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000133 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000134 { "challengeresponseauthentication", oChallengeResponseAuthentication },
135 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
136 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Millerf9b3feb2003-05-16 11:38:32 +1000137#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100138 { "kerberosauthentication", oKerberosAuthentication },
Damien Miller95def091999-11-25 00:26:21 +1100139 { "kerberostgtpassing", oKerberosTgtPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000140#else
141 { "kerberosauthentication", oUnsupported },
142 { "kerberostgtpassing", oUnsupported },
143#endif
144#if defined(AFS)
Damien Miller95def091999-11-25 00:26:21 +1100145 { "afstokenpassing", oAFSTokenPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000146#else
147 { "afstokenpassing", oUnsupported },
148#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000149 { "fallbacktorsh", oDeprecated },
150 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100151 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100152 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100153 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000154 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100155 { "proxycommand", oProxyCommand },
156 { "port", oPort },
157 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000158 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000159 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000160 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100161 { "remoteforward", oRemoteForward },
162 { "localforward", oLocalForward },
163 { "user", oUser },
164 { "host", oHost },
165 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100166 { "globalknownhostsfile", oGlobalKnownHostsFile },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000167 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
Damien Millereba71ba2000-04-29 23:57:08 +1000168 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000169 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100170 { "connectionattempts", oConnectionAttempts },
171 { "batchmode", oBatchMode },
172 { "checkhostip", oCheckHostIP },
173 { "stricthostkeychecking", oStrictHostKeyChecking },
174 { "compression", oCompression },
175 { "compressionlevel", oCompressionLevel },
176 { "keepalive", oKeepAlives },
177 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100178 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000179 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000180 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000181 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000182 { "bindaddress", oBindAddress },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000183#ifdef SMARTCARD
Ben Lindstromae996bf2001-08-06 21:27:53 +0000184 { "smartcarddevice", oSmartcardDevice },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000185#else
186 { "smartcarddevice", oUnsupported },
187#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100188 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000189 { "enablesshkeysign", oEnableSSHKeysign },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000190#ifdef DNS
Damien Miller37876e92003-05-15 10:19:46 +1000191 { "verifyhostkeydns", oVerifyHostKeyDNS },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000192#else
193 { "verifyhostkeydns", oUnsupported },
194#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100195 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000196 { "rekeylimit", oRekeyLimit },
Damien Millerb78d5eb2003-05-16 11:39:04 +1000197 { "connecttimeout", oConnectTimeout },
Damien Miller20a8f972003-05-18 20:50:30 +1000198 { "addressfamily", oAddressFamily },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000199 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100200};
201
Damien Miller5428f641999-11-25 11:54:57 +1100202/*
203 * Adds a local TCP/IP port forward to options. Never returns if there is an
204 * error.
205 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000206
Damien Miller4af51302000-04-16 11:18:38 +1000207void
Damien Milleraae6c611999-12-06 11:47:28 +1100208add_local_forward(Options *options, u_short port, const char *host,
209 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000210{
Damien Miller95def091999-11-25 00:26:21 +1100211 Forward *fwd;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000212#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100213 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100214 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000215 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100216#endif
Damien Miller95def091999-11-25 00:26:21 +1100217 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
218 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
219 fwd = &options->local_forwards[options->num_local_forwards++];
220 fwd->port = port;
221 fwd->host = xstrdup(host);
222 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223}
224
Damien Miller5428f641999-11-25 11:54:57 +1100225/*
226 * Adds a remote TCP/IP port forward to options. Never returns if there is
227 * an error.
228 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000229
Damien Miller4af51302000-04-16 11:18:38 +1000230void
Damien Milleraae6c611999-12-06 11:47:28 +1100231add_remote_forward(Options *options, u_short port, const char *host,
232 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000233{
Damien Miller95def091999-11-25 00:26:21 +1100234 Forward *fwd;
235 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
236 fatal("Too many remote forwards (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100237 SSH_MAX_FORWARDS_PER_DIRECTION);
Damien Miller95def091999-11-25 00:26:21 +1100238 fwd = &options->remote_forwards[options->num_remote_forwards++];
239 fwd->port = port;
240 fwd->host = xstrdup(host);
241 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000242}
243
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000244static void
245clear_forwardings(Options *options)
246{
247 int i;
248
249 for (i = 0; i < options->num_local_forwards; i++)
250 xfree(options->local_forwards[i].host);
251 options->num_local_forwards = 0;
252 for (i = 0; i < options->num_remote_forwards; i++)
253 xfree(options->remote_forwards[i].host);
254 options->num_remote_forwards = 0;
255}
256
Damien Miller5428f641999-11-25 11:54:57 +1100257/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000258 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100259 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000260
Damien Miller4af51302000-04-16 11:18:38 +1000261static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100262parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000263{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000264 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000265
Damien Miller95def091999-11-25 00:26:21 +1100266 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100267 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100268 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000269
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000270 error("%s: line %d: Bad configuration option: %s",
271 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100272 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000273}
274
Damien Miller5428f641999-11-25 11:54:57 +1100275/*
276 * Processes a single option line as used in the configuration files. This
277 * only sets those values that have not already been set.
278 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100279#define WHITESPACE " \t\r\n"
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000280
Damien Miller2ccf6611999-11-15 15:25:10 +1100281int
282process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100283 char *line, const char *filename, int linenum,
284 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000285{
Damien Miller61f08ac2003-02-24 11:56:27 +1100286 char buf[256], *s, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100287 int opcode, *intptr, value;
Damien Miller61f08ac2003-02-24 11:56:27 +1100288 size_t len;
Damien Milleraae6c611999-12-06 11:47:28 +1100289 u_short fwd_port, fwd_host_port;
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000290 char sfwd_host_port[6];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000291
Damien Millerc652cac2003-05-14 13:40:54 +1000292 /* Strip trailing whitespace */
293 for(len = strlen(line) - 1; len > 0; len--) {
294 if (strchr(WHITESPACE, line[len]) == NULL)
295 break;
296 line[len] = '\0';
297 }
298
Damien Millerbe484b52000-07-15 14:14:16 +1000299 s = line;
300 /* Get the keyword. (Each line is supposed to begin with a keyword). */
301 keyword = strdelim(&s);
302 /* Ignore leading whitespace. */
303 if (*keyword == '\0')
304 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000305 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100306 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000307
Damien Miller37023962000-07-11 17:31:38 +1000308 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000309
Damien Miller95def091999-11-25 00:26:21 +1100310 switch (opcode) {
311 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100312 /* don't panic, but count bad options */
313 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100314 /* NOTREACHED */
Damien Millerb78d5eb2003-05-16 11:39:04 +1000315 case oConnectTimeout:
316 intptr = &options->connection_timeout;
317/* parse_time: */
318 arg = strdelim(&s);
319 if (!arg || *arg == '\0')
320 fatal("%s line %d: missing time value.",
321 filename, linenum);
322 if ((value = convtime(arg)) == -1)
323 fatal("%s line %d: invalid time value.",
324 filename, linenum);
325 if (*intptr == -1)
326 *intptr = value;
327 break;
328
Damien Miller95def091999-11-25 00:26:21 +1100329 case oForwardAgent:
330 intptr = &options->forward_agent;
331parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000332 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000333 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100334 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
335 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000336 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100337 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000338 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100339 value = 0;
340 else
341 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
342 if (*activep && *intptr == -1)
343 *intptr = value;
344 break;
345
346 case oForwardX11:
347 intptr = &options->forward_x11;
348 goto parse_flag;
349
350 case oGatewayPorts:
351 intptr = &options->gateway_ports;
352 goto parse_flag;
353
354 case oUsePrivilegedPort:
355 intptr = &options->use_privileged_port;
356 goto parse_flag;
357
358 case oRhostsAuthentication:
359 intptr = &options->rhosts_authentication;
360 goto parse_flag;
361
362 case oPasswordAuthentication:
363 intptr = &options->password_authentication;
364 goto parse_flag;
365
Damien Miller874d77b2000-10-14 16:23:11 +1100366 case oKbdInteractiveAuthentication:
367 intptr = &options->kbd_interactive_authentication;
368 goto parse_flag;
369
370 case oKbdInteractiveDevices:
371 charptr = &options->kbd_interactive_devices;
372 goto parse_string;
373
Damien Miller0bc1bd82000-11-13 22:57:25 +1100374 case oPubkeyAuthentication:
375 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000376 goto parse_flag;
377
Damien Miller95def091999-11-25 00:26:21 +1100378 case oRSAAuthentication:
379 intptr = &options->rsa_authentication;
380 goto parse_flag;
381
382 case oRhostsRSAAuthentication:
383 intptr = &options->rhosts_rsa_authentication;
384 goto parse_flag;
385
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000386 case oHostbasedAuthentication:
387 intptr = &options->hostbased_authentication;
388 goto parse_flag;
389
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000390 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000391 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100392 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000393
Damien Miller95def091999-11-25 00:26:21 +1100394 case oKerberosAuthentication:
395 intptr = &options->kerberos_authentication;
396 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000397
Damien Miller95def091999-11-25 00:26:21 +1100398 case oKerberosTgtPassing:
399 intptr = &options->kerberos_tgt_passing;
400 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000401
Damien Miller95def091999-11-25 00:26:21 +1100402 case oAFSTokenPassing:
403 intptr = &options->afs_token_passing;
404 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000405
Damien Miller95def091999-11-25 00:26:21 +1100406 case oBatchMode:
407 intptr = &options->batch_mode;
408 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000409
Damien Miller95def091999-11-25 00:26:21 +1100410 case oCheckHostIP:
411 intptr = &options->check_host_ip;
412 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000413
Damien Miller37876e92003-05-15 10:19:46 +1000414 case oVerifyHostKeyDNS:
415 intptr = &options->verify_host_key_dns;
416 goto parse_flag;
417
Damien Miller95def091999-11-25 00:26:21 +1100418 case oStrictHostKeyChecking:
419 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000420 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000421 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000422 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100423 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100424 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000425 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100426 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000427 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100428 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000429 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100430 value = 2;
431 else
432 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
433 if (*activep && *intptr == -1)
434 *intptr = value;
435 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000436
Damien Miller95def091999-11-25 00:26:21 +1100437 case oCompression:
438 intptr = &options->compression;
439 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000440
Damien Miller95def091999-11-25 00:26:21 +1100441 case oKeepAlives:
442 intptr = &options->keepalives;
443 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000444
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000445 case oNoHostAuthenticationForLocalhost:
446 intptr = &options->no_host_authentication_for_localhost;
447 goto parse_flag;
448
Damien Miller95def091999-11-25 00:26:21 +1100449 case oNumberOfPasswordPrompts:
450 intptr = &options->number_of_password_prompts;
451 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000452
Damien Miller95def091999-11-25 00:26:21 +1100453 case oCompressionLevel:
454 intptr = &options->compression_level;
455 goto parse_int;
456
Damien Millera5539d22003-04-09 20:50:06 +1000457 case oRekeyLimit:
458 intptr = &options->rekey_limit;
459 arg = strdelim(&s);
460 if (!arg || *arg == '\0')
461 fatal("%.200s line %d: Missing argument.", filename, linenum);
462 if (arg[0] < '0' || arg[0] > '9')
463 fatal("%.200s line %d: Bad number.", filename, linenum);
464 value = strtol(arg, &endofnumber, 10);
465 if (arg == endofnumber)
466 fatal("%.200s line %d: Bad number.", filename, linenum);
467 switch (toupper(*endofnumber)) {
468 case 'K':
469 value *= 1<<10;
470 break;
471 case 'M':
472 value *= 1<<20;
473 break;
474 case 'G':
475 value *= 1<<30;
476 break;
477 }
478 if (*activep && *intptr == -1)
479 *intptr = value;
480 break;
481
Damien Miller95def091999-11-25 00:26:21 +1100482 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000483 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000484 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100485 fatal("%.200s line %d: Missing argument.", filename, linenum);
486 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100487 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000488 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100489 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100490 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100491 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000492 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000493 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100494 }
495 break;
496
Damien Millerd3a18572000-06-07 19:55:44 +1000497 case oXAuthLocation:
498 charptr=&options->xauth_location;
499 goto parse_string;
500
Damien Miller95def091999-11-25 00:26:21 +1100501 case oUser:
502 charptr = &options->user;
503parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000504 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000505 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100506 fatal("%.200s line %d: Missing argument.", filename, linenum);
507 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000508 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100509 break;
510
511 case oGlobalKnownHostsFile:
512 charptr = &options->system_hostfile;
513 goto parse_string;
514
515 case oUserKnownHostsFile:
516 charptr = &options->user_hostfile;
517 goto parse_string;
518
Damien Millereba71ba2000-04-29 23:57:08 +1000519 case oGlobalKnownHostsFile2:
520 charptr = &options->system_hostfile2;
521 goto parse_string;
522
523 case oUserKnownHostsFile2:
524 charptr = &options->user_hostfile2;
525 goto parse_string;
526
Damien Miller95def091999-11-25 00:26:21 +1100527 case oHostName:
528 charptr = &options->hostname;
529 goto parse_string;
530
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000531 case oHostKeyAlias:
532 charptr = &options->host_key_alias;
533 goto parse_string;
534
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000535 case oPreferredAuthentications:
536 charptr = &options->preferred_authentications;
537 goto parse_string;
538
Ben Lindstrome0f88042001-04-30 13:06:24 +0000539 case oBindAddress:
540 charptr = &options->bind_address;
541 goto parse_string;
542
Ben Lindstromae996bf2001-08-06 21:27:53 +0000543 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000544 charptr = &options->smartcard_device;
545 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000546
Damien Miller95def091999-11-25 00:26:21 +1100547 case oProxyCommand:
Darren Tuckera99c1b72003-06-28 12:40:12 +1000548 if (s == NULL)
549 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100550 charptr = &options->proxy_command;
Damien Miller61f08ac2003-02-24 11:56:27 +1100551 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +1100552 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +1100553 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +1100554 return 0;
555
556 case oPort:
557 intptr = &options->port;
558parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000559 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000560 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100561 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000562 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100563 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100564
565 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000566 value = strtol(arg, &endofnumber, 0);
567 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100568 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100569 if (*activep && *intptr == -1)
570 *intptr = value;
571 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000572
Damien Miller95def091999-11-25 00:26:21 +1100573 case oConnectionAttempts:
574 intptr = &options->connection_attempts;
575 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100576
Damien Miller95def091999-11-25 00:26:21 +1100577 case oCipher:
578 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000579 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000580 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000581 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000582 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100583 if (value == -1)
584 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100585 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100586 if (*activep && *intptr == -1)
587 *intptr = value;
588 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000589
Damien Miller78928792000-04-12 20:17:38 +1000590 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000591 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000592 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000593 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000594 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000595 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100596 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000597 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000598 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000599 break;
600
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000601 case oMacs:
602 arg = strdelim(&s);
603 if (!arg || *arg == '\0')
604 fatal("%.200s line %d: Missing argument.", filename, linenum);
605 if (!mac_valid(arg))
606 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100607 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000608 if (*activep && options->macs == NULL)
609 options->macs = xstrdup(arg);
610 break;
611
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000612 case oHostKeyAlgorithms:
613 arg = strdelim(&s);
614 if (!arg || *arg == '\0')
615 fatal("%.200s line %d: Missing argument.", filename, linenum);
616 if (!key_names_valid2(arg))
617 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100618 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000619 if (*activep && options->hostkeyalgorithms == NULL)
620 options->hostkeyalgorithms = xstrdup(arg);
621 break;
622
Damien Miller78928792000-04-12 20:17:38 +1000623 case oProtocol:
624 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000625 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000626 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000627 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000628 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000629 if (value == SSH_PROTO_UNKNOWN)
630 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100631 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000632 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
633 *intptr = value;
634 break;
635
Damien Miller95def091999-11-25 00:26:21 +1100636 case oLogLevel:
637 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000638 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000639 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100640 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000641 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100642 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100643 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100644 *intptr = (LogLevel) value;
645 break;
646
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000647 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100648 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000649 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000650 if (!arg || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000651 fatal("%.200s line %d: Missing port argument.",
652 filename, linenum);
653 if ((fwd_port = a2port(arg)) == 0)
654 fatal("%.200s line %d: Bad listen port.",
655 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000656 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000657 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100658 fatal("%.200s line %d: Missing second argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000659 filename, linenum);
660 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
661 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
662 fatal("%.200s line %d: Bad forwarding specification.",
663 filename, linenum);
664 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
665 fatal("%.200s line %d: Bad forwarding port.",
666 filename, linenum);
667 if (*activep) {
668 if (opcode == oLocalForward)
669 add_local_forward(options, fwd_port, buf,
670 fwd_host_port);
671 else if (opcode == oRemoteForward)
672 add_remote_forward(options, fwd_port, buf,
673 fwd_host_port);
674 }
Damien Miller95def091999-11-25 00:26:21 +1100675 break;
676
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000677 case oDynamicForward:
678 arg = strdelim(&s);
679 if (!arg || *arg == '\0')
680 fatal("%.200s line %d: Missing port argument.",
681 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000682 fwd_port = a2port(arg);
683 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000684 fatal("%.200s line %d: Badly formatted port number.",
685 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000686 if (*activep)
687 add_local_forward(options, fwd_port, "socks4", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000688 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000689
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000690 case oClearAllForwardings:
691 intptr = &options->clear_forwardings;
692 goto parse_flag;
693
Damien Miller95def091999-11-25 00:26:21 +1100694 case oHost:
695 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000696 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000697 if (match_pattern(host, arg)) {
698 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100699 *activep = 1;
700 break;
701 }
Damien Millerbe484b52000-07-15 14:14:16 +1000702 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100703 return 0;
704
705 case oEscapeChar:
706 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000707 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000708 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100709 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000710 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000711 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
712 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000713 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000714 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000715 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000716 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100717 else {
718 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100719 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100720 /* NOTREACHED */
721 value = 0; /* Avoid compiler warning. */
722 }
723 if (*activep && *intptr == -1)
724 *intptr = value;
725 break;
726
Damien Miller20a8f972003-05-18 20:50:30 +1000727 case oAddressFamily:
728 arg = strdelim(&s);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000729 intptr = &options->address_family;
Damien Miller20a8f972003-05-18 20:50:30 +1000730 if (strcasecmp(arg, "inet") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000731 value = AF_INET;
Damien Miller20a8f972003-05-18 20:50:30 +1000732 else if (strcasecmp(arg, "inet6") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000733 value = AF_INET6;
Damien Miller20a8f972003-05-18 20:50:30 +1000734 else if (strcasecmp(arg, "any") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000735 value = AF_UNSPEC;
Damien Miller20a8f972003-05-18 20:50:30 +1000736 else
737 fatal("Unsupported AddressFamily \"%s\"", arg);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000738 if (*activep && *intptr == -1)
739 *intptr = value;
Damien Miller20a8f972003-05-18 20:50:30 +1000740 break;
741
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000742 case oEnableSSHKeysign:
743 intptr = &options->enable_ssh_keysign;
744 goto parse_flag;
745
Ben Lindstrom4daea862002-06-09 20:04:02 +0000746 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000747 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +0000748 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000749 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +0000750
Damien Millerf9b3feb2003-05-16 11:38:32 +1000751 case oUnsupported:
752 error("%s line %d: Unsupported option \"%s\"",
753 filename, linenum, keyword);
754 return 0;
755
Damien Miller95def091999-11-25 00:26:21 +1100756 default:
757 fatal("process_config_line: Unimplemented opcode %d", opcode);
758 }
759
760 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000761 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000762 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100763 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000764 }
Damien Miller95def091999-11-25 00:26:21 +1100765 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000766}
767
768
Damien Miller5428f641999-11-25 11:54:57 +1100769/*
770 * Reads the config file and modifies the options accordingly. Options
771 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000772 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100773 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000774
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000775int
Damien Miller95def091999-11-25 00:26:21 +1100776read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000777{
Damien Miller95def091999-11-25 00:26:21 +1100778 FILE *f;
779 char line[1024];
780 int active, linenum;
781 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000782
Damien Miller95def091999-11-25 00:26:21 +1100783 /* Open the file. */
784 f = fopen(filename, "r");
785 if (!f)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000786 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000787
Damien Miller95def091999-11-25 00:26:21 +1100788 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000789
Damien Miller5428f641999-11-25 11:54:57 +1100790 /*
791 * Mark that we are now processing the options. This flag is turned
792 * on/off by Host specifications.
793 */
Damien Miller95def091999-11-25 00:26:21 +1100794 active = 1;
795 linenum = 0;
796 while (fgets(line, sizeof(line), f)) {
797 /* Update line number counter. */
798 linenum++;
799 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
800 bad_options++;
801 }
802 fclose(f);
803 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000804 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100805 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000806 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000807}
808
Damien Miller5428f641999-11-25 11:54:57 +1100809/*
810 * Initializes options to special values that indicate that they have not yet
811 * been set. Read_config_file will only set options with this value. Options
812 * are processed in the following order: command line, user config file,
813 * system config file. Last, fill_default_options is called.
814 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000815
Damien Miller4af51302000-04-16 11:18:38 +1000816void
Damien Miller95def091999-11-25 00:26:21 +1100817initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000818{
Damien Miller95def091999-11-25 00:26:21 +1100819 memset(options, 'X', sizeof(*options));
820 options->forward_agent = -1;
821 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000822 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100823 options->gateway_ports = -1;
824 options->use_privileged_port = -1;
825 options->rhosts_authentication = -1;
826 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100827 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000828 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100829 options->kerberos_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100830 options->kerberos_tgt_passing = -1;
831 options->afs_token_passing = -1;
Damien Miller95def091999-11-25 00:26:21 +1100832 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100833 options->kbd_interactive_authentication = -1;
834 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100835 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000836 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100837 options->batch_mode = -1;
838 options->check_host_ip = -1;
839 options->strict_host_key_checking = -1;
840 options->compression = -1;
841 options->keepalives = -1;
842 options->compression_level = -1;
843 options->port = -1;
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000844 options->address_family = -1;
Damien Miller95def091999-11-25 00:26:21 +1100845 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000846 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +1100847 options->number_of_password_prompts = -1;
848 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000849 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000850 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000851 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000852 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100853 options->num_identity_files = 0;
854 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000855 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100856 options->proxy_command = NULL;
857 options->user = NULL;
858 options->escape_char = -1;
859 options->system_hostfile = NULL;
860 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000861 options->system_hostfile2 = NULL;
862 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100863 options->num_local_forwards = 0;
864 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000865 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100866 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000867 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000868 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000869 options->smartcard_device = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000870 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000871 options->no_host_authentication_for_localhost = - 1;
Damien Millera5539d22003-04-09 20:50:06 +1000872 options->rekey_limit = - 1;
Damien Miller37876e92003-05-15 10:19:46 +1000873 options->verify_host_key_dns = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000874}
875
Damien Miller5428f641999-11-25 11:54:57 +1100876/*
877 * Called after processing other sources of option data, this fills those
878 * options for which no value has been specified with their default values.
879 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000880
Damien Miller4af51302000-04-16 11:18:38 +1000881void
Damien Miller95def091999-11-25 00:26:21 +1100882fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000883{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000884 int len;
885
Damien Miller95def091999-11-25 00:26:21 +1100886 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000887 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100888 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100889 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000890 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000891 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100892 if (options->gateway_ports == -1)
893 options->gateway_ports = 0;
894 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000895 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100896 if (options->rhosts_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000897 options->rhosts_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100898 if (options->rsa_authentication == -1)
899 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100900 if (options->pubkey_authentication == -1)
901 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000902 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000903 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100904 if (options->kerberos_authentication == -1)
905 options->kerberos_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100906 if (options->kerberos_tgt_passing == -1)
907 options->kerberos_tgt_passing = 1;
908 if (options->afs_token_passing == -1)
909 options->afs_token_passing = 1;
Damien Miller95def091999-11-25 00:26:21 +1100910 if (options->password_authentication == -1)
911 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100912 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000913 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100914 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000915 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000916 if (options->hostbased_authentication == -1)
917 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100918 if (options->batch_mode == -1)
919 options->batch_mode = 0;
920 if (options->check_host_ip == -1)
921 options->check_host_ip = 1;
922 if (options->strict_host_key_checking == -1)
923 options->strict_host_key_checking = 2; /* 2 is default */
924 if (options->compression == -1)
925 options->compression = 0;
926 if (options->keepalives == -1)
927 options->keepalives = 1;
928 if (options->compression_level == -1)
929 options->compression_level = 6;
930 if (options->port == -1)
931 options->port = 0; /* Filled in ssh_connect. */
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000932 if (options->address_family == -1)
933 options->address_family = AF_UNSPEC;
Damien Miller95def091999-11-25 00:26:21 +1100934 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000935 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100936 if (options->number_of_password_prompts == -1)
937 options->number_of_password_prompts = 3;
938 /* Selected in ssh_login(). */
939 if (options->cipher == -1)
940 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000941 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000942 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000943 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000944 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000945 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100946 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100947 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000948 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100949 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000950 xmalloc(len);
951 snprintf(options->identity_files[options->num_identity_files++],
952 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100953 }
954 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000955 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
956 options->identity_files[options->num_identity_files] =
957 xmalloc(len);
958 snprintf(options->identity_files[options->num_identity_files++],
959 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
960
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000961 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100962 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000963 xmalloc(len);
964 snprintf(options->identity_files[options->num_identity_files++],
965 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100966 }
Damien Millereba71ba2000-04-29 23:57:08 +1000967 }
Damien Miller95def091999-11-25 00:26:21 +1100968 if (options->escape_char == -1)
969 options->escape_char = '~';
970 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000971 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100972 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000973 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000974 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000975 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000976 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000977 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +1100978 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000979 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000980 if (options->clear_forwardings == 1)
981 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000982 if (options->no_host_authentication_for_localhost == - 1)
983 options->no_host_authentication_for_localhost = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000984 if (options->enable_ssh_keysign == -1)
985 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +1000986 if (options->rekey_limit == -1)
987 options->rekey_limit = 0;
Damien Miller37876e92003-05-15 10:19:46 +1000988 if (options->verify_host_key_dns == -1)
989 options->verify_host_key_dns = 0;
Damien Miller95def091999-11-25 00:26:21 +1100990 /* options->proxy_command should not be set by default */
991 /* options->user will be set in the main program if appropriate */
992 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000993 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000994 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000995}