blob: 9447cb55fa49fd5c85540425ac27743099025a79 [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 Tucker0efd1552003-08-26 11:49:55 +100015RCSID("$OpenBSD: readconf.c,v 1.118 2003/08/22 10:56:09 markus Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016
17#include "ssh.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100018#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100019#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000020#include "cipher.h"
21#include "pathnames.h"
22#include "log.h"
23#include "readconf.h"
24#include "match.h"
25#include "misc.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000026#include "kex.h"
27#include "mac.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100028
29/* Format of the configuration file:
30
31 # Configuration data is parsed as follows:
32 # 1. command line options
33 # 2. user-specific file
34 # 3. system-wide file
35 # Any configuration value is only changed the first time it is set.
36 # Thus, host-specific definitions should be at the beginning of the
37 # configuration file, and defaults at the end.
38
39 # Host-specific declarations. These may override anything above. A single
40 # host may match multiple declarations; these are processed in the order
41 # that they are given in.
42
43 Host *.ngs.fi ngs.fi
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
Damien Millerd4a8b7e1999-10-27 13:42:43 +100060 PasswordAuthentication no
61
62 Host puukko.hut.fi
63 User t35124p
64 ProxyCommand ssh-proxy %h %p
65
66 Host *.fr
Ben Lindstrom4daea862002-06-09 20:04:02 +000067 PublicKeyAuthentication no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068
69 Host *.su
70 Cipher none
71 PasswordAuthentication no
72
73 # Defaults for various options
74 Host *
75 ForwardAgent no
Damien Miller0bc1bd82000-11-13 22:57:25 +110076 ForwardX11 no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100077 PasswordAuthentication yes
78 RSAAuthentication yes
79 RhostsRSAAuthentication yes
Damien Millerd4a8b7e1999-10-27 13:42:43 +100080 StrictHostKeyChecking yes
81 KeepAlives no
82 IdentityFile ~/.ssh/identity
83 Port 22
84 EscapeChar ~
85
86*/
87
88/* Keyword tokens. */
89
Damien Miller95def091999-11-25 00:26:21 +110090typedef enum {
91 oBadOption,
Darren Tuckerec960f22003-08-13 20:37:05 +100092 oForwardAgent, oForwardX11, oGatewayPorts,
Ben Lindstromcb72e4f2002-06-21 00:41:51 +000093 oPasswordAuthentication, oRSAAuthentication,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000094 oChallengeResponseAuthentication, oXAuthLocation,
Darren Tucker6aaa58c2003-08-02 22:24:49 +100095 oKerberosAuthentication, oKerberosTgtPassing,
Damien Miller95def091999-11-25 00:26:21 +110096 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
97 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
98 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
99 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000100 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000101 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100102 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000103 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000104 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000105 oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000106 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
Damien Millerb78d5eb2003-05-16 11:39:04 +1000107 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
Darren Tucker0efd1552003-08-26 11:49:55 +1000108 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000109 oDeprecated, oUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000110} OpCodes;
111
112/* Textual representations of the tokens. */
113
Damien Miller95def091999-11-25 00:26:21 +1100114static struct {
115 const char *name;
116 OpCodes opcode;
117} keywords[] = {
118 { "forwardagent", oForwardAgent },
119 { "forwardx11", oForwardX11 },
Damien Millerd3a18572000-06-07 19:55:44 +1000120 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100121 { "gatewayports", oGatewayPorts },
122 { "useprivilegedport", oUsePrivilegedPort },
Darren Tuckerec960f22003-08-13 20:37:05 +1000123 { "rhostsauthentication", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100124 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100125 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
126 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100127 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100128 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000129 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000130 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000131 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000132 { "challengeresponseauthentication", oChallengeResponseAuthentication },
133 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
134 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000135#ifdef KRB5
Damien Miller95def091999-11-25 00:26:21 +1100136 { "kerberosauthentication", oKerberosAuthentication },
Damien Miller95def091999-11-25 00:26:21 +1100137 { "kerberostgtpassing", oKerberosTgtPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000138#else
139 { "kerberosauthentication", oUnsupported },
140 { "kerberostgtpassing", oUnsupported },
141#endif
Damien Millerf9b3feb2003-05-16 11:38:32 +1000142 { "afstokenpassing", oUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000143#if defined(GSSAPI)
144 { "gssapiauthentication", oGssAuthentication },
145 { "gssapidelegatecreds", oGssDelegateCreds },
146 { "gssapidelegatecredentials", oGssDelegateCreds },
147#else
148 { "gssapiauthentication", oUnsupported },
149 { "gssapidelegatecredentials", oUnsupported },
150#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000151 { "fallbacktorsh", oDeprecated },
152 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100153 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100154 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100155 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000156 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100157 { "proxycommand", oProxyCommand },
158 { "port", oPort },
159 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000160 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000161 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000162 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100163 { "remoteforward", oRemoteForward },
164 { "localforward", oLocalForward },
165 { "user", oUser },
166 { "host", oHost },
167 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100168 { "globalknownhostsfile", oGlobalKnownHostsFile },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000169 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
Damien Millereba71ba2000-04-29 23:57:08 +1000170 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000171 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100172 { "connectionattempts", oConnectionAttempts },
173 { "batchmode", oBatchMode },
174 { "checkhostip", oCheckHostIP },
175 { "stricthostkeychecking", oStrictHostKeyChecking },
176 { "compression", oCompression },
177 { "compressionlevel", oCompressionLevel },
178 { "keepalive", oKeepAlives },
179 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100180 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000181 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000182 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000183 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000184 { "bindaddress", oBindAddress },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000185#ifdef SMARTCARD
Ben Lindstromae996bf2001-08-06 21:27:53 +0000186 { "smartcarddevice", oSmartcardDevice },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000187#else
188 { "smartcarddevice", oUnsupported },
189#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100190 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000191 { "enablesshkeysign", oEnableSSHKeysign },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000192#ifdef DNS
Damien Miller37876e92003-05-15 10:19:46 +1000193 { "verifyhostkeydns", oVerifyHostKeyDNS },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000194#else
195 { "verifyhostkeydns", oUnsupported },
196#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100197 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000198 { "rekeylimit", oRekeyLimit },
Damien Millerb78d5eb2003-05-16 11:39:04 +1000199 { "connecttimeout", oConnectTimeout },
Damien Miller20a8f972003-05-18 20:50:30 +1000200 { "addressfamily", oAddressFamily },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000201 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100202};
203
Damien Miller5428f641999-11-25 11:54:57 +1100204/*
205 * Adds a local TCP/IP port forward to options. Never returns if there is an
206 * error.
207 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000208
Damien Miller4af51302000-04-16 11:18:38 +1000209void
Damien Milleraae6c611999-12-06 11:47:28 +1100210add_local_forward(Options *options, u_short port, const char *host,
211 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000212{
Damien Miller95def091999-11-25 00:26:21 +1100213 Forward *fwd;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000214#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100215 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100216 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000217 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100218#endif
Damien Miller95def091999-11-25 00:26:21 +1100219 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
220 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
221 fwd = &options->local_forwards[options->num_local_forwards++];
222 fwd->port = port;
223 fwd->host = xstrdup(host);
224 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000225}
226
Damien Miller5428f641999-11-25 11:54:57 +1100227/*
228 * Adds a remote TCP/IP port forward to options. Never returns if there is
229 * an error.
230 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000231
Damien Miller4af51302000-04-16 11:18:38 +1000232void
Damien Milleraae6c611999-12-06 11:47:28 +1100233add_remote_forward(Options *options, u_short port, const char *host,
234 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000235{
Damien Miller95def091999-11-25 00:26:21 +1100236 Forward *fwd;
237 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
238 fatal("Too many remote forwards (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100239 SSH_MAX_FORWARDS_PER_DIRECTION);
Damien Miller95def091999-11-25 00:26:21 +1100240 fwd = &options->remote_forwards[options->num_remote_forwards++];
241 fwd->port = port;
242 fwd->host = xstrdup(host);
243 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000244}
245
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000246static void
247clear_forwardings(Options *options)
248{
249 int i;
250
251 for (i = 0; i < options->num_local_forwards; i++)
252 xfree(options->local_forwards[i].host);
253 options->num_local_forwards = 0;
254 for (i = 0; i < options->num_remote_forwards; i++)
255 xfree(options->remote_forwards[i].host);
256 options->num_remote_forwards = 0;
257}
258
Damien Miller5428f641999-11-25 11:54:57 +1100259/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000260 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100261 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000262
Damien Miller4af51302000-04-16 11:18:38 +1000263static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100264parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000265{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000266 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000267
Damien Miller95def091999-11-25 00:26:21 +1100268 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100269 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100270 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000271
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000272 error("%s: line %d: Bad configuration option: %s",
273 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100274 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000275}
276
Damien Miller5428f641999-11-25 11:54:57 +1100277/*
278 * Processes a single option line as used in the configuration files. This
279 * only sets those values that have not already been set.
280 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100281#define WHITESPACE " \t\r\n"
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000282
Damien Miller2ccf6611999-11-15 15:25:10 +1100283int
284process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100285 char *line, const char *filename, int linenum,
286 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000287{
Damien Miller61f08ac2003-02-24 11:56:27 +1100288 char buf[256], *s, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100289 int opcode, *intptr, value;
Damien Miller61f08ac2003-02-24 11:56:27 +1100290 size_t len;
Damien Milleraae6c611999-12-06 11:47:28 +1100291 u_short fwd_port, fwd_host_port;
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000292 char sfwd_host_port[6];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000293
Damien Millerc652cac2003-05-14 13:40:54 +1000294 /* Strip trailing whitespace */
295 for(len = strlen(line) - 1; len > 0; len--) {
296 if (strchr(WHITESPACE, line[len]) == NULL)
297 break;
298 line[len] = '\0';
299 }
300
Damien Millerbe484b52000-07-15 14:14:16 +1000301 s = line;
302 /* Get the keyword. (Each line is supposed to begin with a keyword). */
303 keyword = strdelim(&s);
304 /* Ignore leading whitespace. */
305 if (*keyword == '\0')
306 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000307 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100308 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000309
Damien Miller37023962000-07-11 17:31:38 +1000310 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000311
Damien Miller95def091999-11-25 00:26:21 +1100312 switch (opcode) {
313 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100314 /* don't panic, but count bad options */
315 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100316 /* NOTREACHED */
Damien Millerb78d5eb2003-05-16 11:39:04 +1000317 case oConnectTimeout:
318 intptr = &options->connection_timeout;
319/* parse_time: */
320 arg = strdelim(&s);
321 if (!arg || *arg == '\0')
322 fatal("%s line %d: missing time value.",
323 filename, linenum);
324 if ((value = convtime(arg)) == -1)
325 fatal("%s line %d: invalid time value.",
326 filename, linenum);
327 if (*intptr == -1)
328 *intptr = value;
329 break;
330
Damien Miller95def091999-11-25 00:26:21 +1100331 case oForwardAgent:
332 intptr = &options->forward_agent;
333parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000334 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000335 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100336 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
337 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000338 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100339 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000340 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100341 value = 0;
342 else
343 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
344 if (*activep && *intptr == -1)
345 *intptr = value;
346 break;
347
348 case oForwardX11:
349 intptr = &options->forward_x11;
350 goto parse_flag;
351
352 case oGatewayPorts:
353 intptr = &options->gateway_ports;
354 goto parse_flag;
355
356 case oUsePrivilegedPort:
357 intptr = &options->use_privileged_port;
358 goto parse_flag;
359
Damien Miller95def091999-11-25 00:26:21 +1100360 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
Darren Tucker0efd1552003-08-26 11:49:55 +1000400 case oGssAuthentication:
401 intptr = &options->gss_authentication;
402 goto parse_flag;
403
404 case oGssDelegateCreds:
405 intptr = &options->gss_deleg_creds;
406 goto parse_flag;
407
Damien Miller95def091999-11-25 00:26:21 +1100408 case oBatchMode:
409 intptr = &options->batch_mode;
410 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000411
Damien Miller95def091999-11-25 00:26:21 +1100412 case oCheckHostIP:
413 intptr = &options->check_host_ip;
414 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000415
Damien Miller37876e92003-05-15 10:19:46 +1000416 case oVerifyHostKeyDNS:
417 intptr = &options->verify_host_key_dns;
418 goto parse_flag;
419
Damien Miller95def091999-11-25 00:26:21 +1100420 case oStrictHostKeyChecking:
421 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000422 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000423 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000424 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100425 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100426 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000427 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100428 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000429 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100430 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000431 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100432 value = 2;
433 else
434 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
435 if (*activep && *intptr == -1)
436 *intptr = value;
437 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000438
Damien Miller95def091999-11-25 00:26:21 +1100439 case oCompression:
440 intptr = &options->compression;
441 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000442
Damien Miller95def091999-11-25 00:26:21 +1100443 case oKeepAlives:
444 intptr = &options->keepalives;
445 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000446
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000447 case oNoHostAuthenticationForLocalhost:
448 intptr = &options->no_host_authentication_for_localhost;
449 goto parse_flag;
450
Damien Miller95def091999-11-25 00:26:21 +1100451 case oNumberOfPasswordPrompts:
452 intptr = &options->number_of_password_prompts;
453 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000454
Damien Miller95def091999-11-25 00:26:21 +1100455 case oCompressionLevel:
456 intptr = &options->compression_level;
457 goto parse_int;
458
Damien Millera5539d22003-04-09 20:50:06 +1000459 case oRekeyLimit:
460 intptr = &options->rekey_limit;
461 arg = strdelim(&s);
462 if (!arg || *arg == '\0')
463 fatal("%.200s line %d: Missing argument.", filename, linenum);
464 if (arg[0] < '0' || arg[0] > '9')
465 fatal("%.200s line %d: Bad number.", filename, linenum);
466 value = strtol(arg, &endofnumber, 10);
467 if (arg == endofnumber)
468 fatal("%.200s line %d: Bad number.", filename, linenum);
469 switch (toupper(*endofnumber)) {
470 case 'K':
471 value *= 1<<10;
472 break;
473 case 'M':
474 value *= 1<<20;
475 break;
476 case 'G':
477 value *= 1<<30;
478 break;
479 }
480 if (*activep && *intptr == -1)
481 *intptr = value;
482 break;
483
Damien Miller95def091999-11-25 00:26:21 +1100484 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000485 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000486 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100487 fatal("%.200s line %d: Missing argument.", filename, linenum);
488 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100489 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000490 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100491 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100492 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100493 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000494 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000495 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100496 }
497 break;
498
Damien Millerd3a18572000-06-07 19:55:44 +1000499 case oXAuthLocation:
500 charptr=&options->xauth_location;
501 goto parse_string;
502
Damien Miller95def091999-11-25 00:26:21 +1100503 case oUser:
504 charptr = &options->user;
505parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000506 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000507 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100508 fatal("%.200s line %d: Missing argument.", filename, linenum);
509 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000510 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100511 break;
512
513 case oGlobalKnownHostsFile:
514 charptr = &options->system_hostfile;
515 goto parse_string;
516
517 case oUserKnownHostsFile:
518 charptr = &options->user_hostfile;
519 goto parse_string;
520
Damien Millereba71ba2000-04-29 23:57:08 +1000521 case oGlobalKnownHostsFile2:
522 charptr = &options->system_hostfile2;
523 goto parse_string;
524
525 case oUserKnownHostsFile2:
526 charptr = &options->user_hostfile2;
527 goto parse_string;
528
Damien Miller95def091999-11-25 00:26:21 +1100529 case oHostName:
530 charptr = &options->hostname;
531 goto parse_string;
532
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000533 case oHostKeyAlias:
534 charptr = &options->host_key_alias;
535 goto parse_string;
536
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000537 case oPreferredAuthentications:
538 charptr = &options->preferred_authentications;
539 goto parse_string;
540
Ben Lindstrome0f88042001-04-30 13:06:24 +0000541 case oBindAddress:
542 charptr = &options->bind_address;
543 goto parse_string;
544
Ben Lindstromae996bf2001-08-06 21:27:53 +0000545 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000546 charptr = &options->smartcard_device;
547 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000548
Damien Miller95def091999-11-25 00:26:21 +1100549 case oProxyCommand:
Darren Tuckera99c1b72003-06-28 12:40:12 +1000550 if (s == NULL)
551 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100552 charptr = &options->proxy_command;
Damien Miller61f08ac2003-02-24 11:56:27 +1100553 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +1100554 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +1100555 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +1100556 return 0;
557
558 case oPort:
559 intptr = &options->port;
560parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000561 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000562 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100563 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000564 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100565 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100566
567 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000568 value = strtol(arg, &endofnumber, 0);
569 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100570 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100571 if (*activep && *intptr == -1)
572 *intptr = value;
573 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000574
Damien Miller95def091999-11-25 00:26:21 +1100575 case oConnectionAttempts:
576 intptr = &options->connection_attempts;
577 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100578
Damien Miller95def091999-11-25 00:26:21 +1100579 case oCipher:
580 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000581 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000582 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000583 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000584 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100585 if (value == -1)
586 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100587 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100588 if (*activep && *intptr == -1)
589 *intptr = value;
590 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000591
Damien Miller78928792000-04-12 20:17:38 +1000592 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000593 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000594 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000595 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000596 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000597 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100598 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000599 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000600 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000601 break;
602
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000603 case oMacs:
604 arg = strdelim(&s);
605 if (!arg || *arg == '\0')
606 fatal("%.200s line %d: Missing argument.", filename, linenum);
607 if (!mac_valid(arg))
608 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100609 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000610 if (*activep && options->macs == NULL)
611 options->macs = xstrdup(arg);
612 break;
613
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000614 case oHostKeyAlgorithms:
615 arg = strdelim(&s);
616 if (!arg || *arg == '\0')
617 fatal("%.200s line %d: Missing argument.", filename, linenum);
618 if (!key_names_valid2(arg))
619 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100620 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000621 if (*activep && options->hostkeyalgorithms == NULL)
622 options->hostkeyalgorithms = xstrdup(arg);
623 break;
624
Damien Miller78928792000-04-12 20:17:38 +1000625 case oProtocol:
626 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000627 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000628 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000629 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000630 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000631 if (value == SSH_PROTO_UNKNOWN)
632 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100633 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000634 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
635 *intptr = value;
636 break;
637
Damien Miller95def091999-11-25 00:26:21 +1100638 case oLogLevel:
639 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000640 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000641 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100642 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000643 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100644 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100645 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100646 *intptr = (LogLevel) value;
647 break;
648
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000649 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100650 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000651 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000652 if (!arg || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000653 fatal("%.200s line %d: Missing port argument.",
654 filename, linenum);
655 if ((fwd_port = a2port(arg)) == 0)
656 fatal("%.200s line %d: Bad listen port.",
657 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000658 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000659 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100660 fatal("%.200s line %d: Missing second argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000661 filename, linenum);
662 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
663 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
664 fatal("%.200s line %d: Bad forwarding specification.",
665 filename, linenum);
666 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
667 fatal("%.200s line %d: Bad forwarding port.",
668 filename, linenum);
669 if (*activep) {
670 if (opcode == oLocalForward)
671 add_local_forward(options, fwd_port, buf,
672 fwd_host_port);
673 else if (opcode == oRemoteForward)
674 add_remote_forward(options, fwd_port, buf,
675 fwd_host_port);
676 }
Damien Miller95def091999-11-25 00:26:21 +1100677 break;
678
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000679 case oDynamicForward:
680 arg = strdelim(&s);
681 if (!arg || *arg == '\0')
682 fatal("%.200s line %d: Missing port argument.",
683 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000684 fwd_port = a2port(arg);
685 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000686 fatal("%.200s line %d: Badly formatted port number.",
687 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000688 if (*activep)
Darren Tucker1c52ee32003-08-13 20:38:36 +1000689 add_local_forward(options, fwd_port, "socks", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000690 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000691
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000692 case oClearAllForwardings:
693 intptr = &options->clear_forwardings;
694 goto parse_flag;
695
Damien Miller95def091999-11-25 00:26:21 +1100696 case oHost:
697 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000698 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000699 if (match_pattern(host, arg)) {
700 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100701 *activep = 1;
702 break;
703 }
Damien Millerbe484b52000-07-15 14:14:16 +1000704 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100705 return 0;
706
707 case oEscapeChar:
708 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000709 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000710 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100711 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000712 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000713 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
714 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000715 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000716 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000717 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000718 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100719 else {
720 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100721 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100722 /* NOTREACHED */
723 value = 0; /* Avoid compiler warning. */
724 }
725 if (*activep && *intptr == -1)
726 *intptr = value;
727 break;
728
Damien Miller20a8f972003-05-18 20:50:30 +1000729 case oAddressFamily:
730 arg = strdelim(&s);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000731 intptr = &options->address_family;
Damien Miller20a8f972003-05-18 20:50:30 +1000732 if (strcasecmp(arg, "inet") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000733 value = AF_INET;
Damien Miller20a8f972003-05-18 20:50:30 +1000734 else if (strcasecmp(arg, "inet6") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000735 value = AF_INET6;
Damien Miller20a8f972003-05-18 20:50:30 +1000736 else if (strcasecmp(arg, "any") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000737 value = AF_UNSPEC;
Damien Miller20a8f972003-05-18 20:50:30 +1000738 else
739 fatal("Unsupported AddressFamily \"%s\"", arg);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000740 if (*activep && *intptr == -1)
741 *intptr = value;
Damien Miller20a8f972003-05-18 20:50:30 +1000742 break;
743
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000744 case oEnableSSHKeysign:
745 intptr = &options->enable_ssh_keysign;
746 goto parse_flag;
747
Ben Lindstrom4daea862002-06-09 20:04:02 +0000748 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000749 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +0000750 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000751 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +0000752
Damien Millerf9b3feb2003-05-16 11:38:32 +1000753 case oUnsupported:
754 error("%s line %d: Unsupported option \"%s\"",
755 filename, linenum, keyword);
756 return 0;
757
Damien Miller95def091999-11-25 00:26:21 +1100758 default:
759 fatal("process_config_line: Unimplemented opcode %d", opcode);
760 }
761
762 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000763 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000764 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100765 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000766 }
Damien Miller95def091999-11-25 00:26:21 +1100767 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000768}
769
770
Damien Miller5428f641999-11-25 11:54:57 +1100771/*
772 * Reads the config file and modifies the options accordingly. Options
773 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000774 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100775 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000776
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000777int
Damien Miller95def091999-11-25 00:26:21 +1100778read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000779{
Damien Miller95def091999-11-25 00:26:21 +1100780 FILE *f;
781 char line[1024];
782 int active, linenum;
783 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000784
Damien Miller95def091999-11-25 00:26:21 +1100785 /* Open the file. */
786 f = fopen(filename, "r");
787 if (!f)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000788 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000789
Damien Miller95def091999-11-25 00:26:21 +1100790 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000791
Damien Miller5428f641999-11-25 11:54:57 +1100792 /*
793 * Mark that we are now processing the options. This flag is turned
794 * on/off by Host specifications.
795 */
Damien Miller95def091999-11-25 00:26:21 +1100796 active = 1;
797 linenum = 0;
798 while (fgets(line, sizeof(line), f)) {
799 /* Update line number counter. */
800 linenum++;
801 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
802 bad_options++;
803 }
804 fclose(f);
805 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000806 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100807 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000808 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000809}
810
Damien Miller5428f641999-11-25 11:54:57 +1100811/*
812 * Initializes options to special values that indicate that they have not yet
813 * been set. Read_config_file will only set options with this value. Options
814 * are processed in the following order: command line, user config file,
815 * system config file. Last, fill_default_options is called.
816 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000817
Damien Miller4af51302000-04-16 11:18:38 +1000818void
Damien Miller95def091999-11-25 00:26:21 +1100819initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000820{
Damien Miller95def091999-11-25 00:26:21 +1100821 memset(options, 'X', sizeof(*options));
822 options->forward_agent = -1;
823 options->forward_x11 = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000824 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100825 options->gateway_ports = -1;
826 options->use_privileged_port = -1;
Damien Miller95def091999-11-25 00:26:21 +1100827 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100828 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000829 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100830 options->kerberos_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100831 options->kerberos_tgt_passing = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000832 options->gss_authentication = -1;
833 options->gss_deleg_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100834 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100835 options->kbd_interactive_authentication = -1;
836 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100837 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000838 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100839 options->batch_mode = -1;
840 options->check_host_ip = -1;
841 options->strict_host_key_checking = -1;
842 options->compression = -1;
843 options->keepalives = -1;
844 options->compression_level = -1;
845 options->port = -1;
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000846 options->address_family = -1;
Damien Miller95def091999-11-25 00:26:21 +1100847 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000848 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +1100849 options->number_of_password_prompts = -1;
850 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000851 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000852 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000853 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000854 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100855 options->num_identity_files = 0;
856 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000857 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100858 options->proxy_command = NULL;
859 options->user = NULL;
860 options->escape_char = -1;
861 options->system_hostfile = NULL;
862 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000863 options->system_hostfile2 = NULL;
864 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100865 options->num_local_forwards = 0;
866 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000867 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100868 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000869 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000870 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000871 options->smartcard_device = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000872 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000873 options->no_host_authentication_for_localhost = - 1;
Damien Millera5539d22003-04-09 20:50:06 +1000874 options->rekey_limit = - 1;
Damien Miller37876e92003-05-15 10:19:46 +1000875 options->verify_host_key_dns = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000876}
877
Damien Miller5428f641999-11-25 11:54:57 +1100878/*
879 * Called after processing other sources of option data, this fills those
880 * options for which no value has been specified with their default values.
881 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000882
Damien Miller4af51302000-04-16 11:18:38 +1000883void
Damien Miller95def091999-11-25 00:26:21 +1100884fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000885{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000886 int len;
887
Damien Miller95def091999-11-25 00:26:21 +1100888 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000889 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100890 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100891 options->forward_x11 = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000892 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000893 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100894 if (options->gateway_ports == -1)
895 options->gateway_ports = 0;
896 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000897 options->use_privileged_port = 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;
Darren Tucker0efd1552003-08-26 11:49:55 +1000908 if (options->gss_authentication == -1)
909 options->gss_authentication = 1;
910 if (options->gss_deleg_creds == -1)
911 options->gss_deleg_creds = 0;
Damien Miller95def091999-11-25 00:26:21 +1100912 if (options->password_authentication == -1)
913 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100914 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000915 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100916 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000917 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000918 if (options->hostbased_authentication == -1)
919 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100920 if (options->batch_mode == -1)
921 options->batch_mode = 0;
922 if (options->check_host_ip == -1)
923 options->check_host_ip = 1;
924 if (options->strict_host_key_checking == -1)
925 options->strict_host_key_checking = 2; /* 2 is default */
926 if (options->compression == -1)
927 options->compression = 0;
928 if (options->keepalives == -1)
929 options->keepalives = 1;
930 if (options->compression_level == -1)
931 options->compression_level = 6;
932 if (options->port == -1)
933 options->port = 0; /* Filled in ssh_connect. */
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000934 if (options->address_family == -1)
935 options->address_family = AF_UNSPEC;
Damien Miller95def091999-11-25 00:26:21 +1100936 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000937 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100938 if (options->number_of_password_prompts == -1)
939 options->number_of_password_prompts = 3;
940 /* Selected in ssh_login(). */
941 if (options->cipher == -1)
942 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000943 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000944 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000945 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000946 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000947 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100948 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100949 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000950 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100951 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000952 xmalloc(len);
953 snprintf(options->identity_files[options->num_identity_files++],
954 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100955 }
956 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000957 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
958 options->identity_files[options->num_identity_files] =
959 xmalloc(len);
960 snprintf(options->identity_files[options->num_identity_files++],
961 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
962
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000963 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100964 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000965 xmalloc(len);
966 snprintf(options->identity_files[options->num_identity_files++],
967 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100968 }
Damien Millereba71ba2000-04-29 23:57:08 +1000969 }
Damien Miller95def091999-11-25 00:26:21 +1100970 if (options->escape_char == -1)
971 options->escape_char = '~';
972 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000973 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100974 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000975 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000976 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000977 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000978 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000979 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +1100980 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000981 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000982 if (options->clear_forwardings == 1)
983 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000984 if (options->no_host_authentication_for_localhost == - 1)
985 options->no_host_authentication_for_localhost = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000986 if (options->enable_ssh_keysign == -1)
987 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +1000988 if (options->rekey_limit == -1)
989 options->rekey_limit = 0;
Damien Miller37876e92003-05-15 10:19:46 +1000990 if (options->verify_host_key_dns == -1)
991 options->verify_host_key_dns = 0;
Damien Miller95def091999-11-25 00:26:21 +1100992 /* options->proxy_command should not be set by default */
993 /* options->user will be set in the main program if appropriate */
994 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000995 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000996 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000997}