blob: cd2c81443324cb99c788598339c013153401536b [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11003 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11005 * Functions for reading the configuration files.
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Miller12c150e2003-12-17 16:31:10 +110015RCSID("$OpenBSD: readconf.c,v 1.126 2003/12/09 21:53:36 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
Damien Miller12c150e2003-12-17 16:31:10 +110081 TcpKeepAlive no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100082 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 Tucker0a118da2003-10-15 15:54:32 +100092 oForwardAgent, oForwardX11, oForwardX11Trusted, oGatewayPorts,
Ben Lindstromcb72e4f2002-06-21 00:41:51 +000093 oPasswordAuthentication, oRSAAuthentication,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000094 oChallengeResponseAuthentication, oXAuthLocation,
Damien Miller95def091999-11-25 00:26:21 +110095 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
96 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
97 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
98 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Damien Miller12c150e2003-12-17 16:31:10 +110099 oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000100 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100101 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000102 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000103 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000104 oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000105 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
Damien Millerb78d5eb2003-05-16 11:39:04 +1000106 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
Darren Tucker0efd1552003-08-26 11:49:55 +1000107 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000108 oDeprecated, oUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000109} OpCodes;
110
111/* Textual representations of the tokens. */
112
Damien Miller95def091999-11-25 00:26:21 +1100113static struct {
114 const char *name;
115 OpCodes opcode;
116} keywords[] = {
117 { "forwardagent", oForwardAgent },
118 { "forwardx11", oForwardX11 },
Darren Tucker0a118da2003-10-15 15:54:32 +1000119 { "forwardx11trusted", oForwardX11Trusted },
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 */
Damien Millerf9b3feb2003-05-16 11:38:32 +1000135 { "kerberosauthentication", oUnsupported },
136 { "kerberostgtpassing", oUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000137 { "afstokenpassing", oUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000138#if defined(GSSAPI)
139 { "gssapiauthentication", oGssAuthentication },
Darren Tucker0efd1552003-08-26 11:49:55 +1000140 { "gssapidelegatecredentials", oGssDelegateCreds },
141#else
142 { "gssapiauthentication", oUnsupported },
143 { "gssapidelegatecredentials", oUnsupported },
144#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000145 { "fallbacktorsh", oDeprecated },
146 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100147 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100148 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100149 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000150 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100151 { "proxycommand", oProxyCommand },
152 { "port", oPort },
153 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000154 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000155 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000156 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100157 { "remoteforward", oRemoteForward },
158 { "localforward", oLocalForward },
159 { "user", oUser },
160 { "host", oHost },
161 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100162 { "globalknownhostsfile", oGlobalKnownHostsFile },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000163 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
Damien Millereba71ba2000-04-29 23:57:08 +1000164 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000165 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100166 { "connectionattempts", oConnectionAttempts },
167 { "batchmode", oBatchMode },
168 { "checkhostip", oCheckHostIP },
169 { "stricthostkeychecking", oStrictHostKeyChecking },
170 { "compression", oCompression },
171 { "compressionlevel", oCompressionLevel },
Damien Miller12c150e2003-12-17 16:31:10 +1100172 { "tcpkeepalive", oTCPKeepAlive },
173 { "keepalive", oTCPKeepAlive }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100174 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100175 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000176 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000177 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000178 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000179 { "bindaddress", oBindAddress },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000180#ifdef SMARTCARD
Ben Lindstromae996bf2001-08-06 21:27:53 +0000181 { "smartcarddevice", oSmartcardDevice },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000182#else
183 { "smartcarddevice", oUnsupported },
184#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100185 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000186 { "enablesshkeysign", oEnableSSHKeysign },
Damien Miller37876e92003-05-15 10:19:46 +1000187 { "verifyhostkeydns", oVerifyHostKeyDNS },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100188 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000189 { "rekeylimit", oRekeyLimit },
Damien Millerb78d5eb2003-05-16 11:39:04 +1000190 { "connecttimeout", oConnectTimeout },
Damien Miller20a8f972003-05-18 20:50:30 +1000191 { "addressfamily", oAddressFamily },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000192 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100193};
194
Damien Miller5428f641999-11-25 11:54:57 +1100195/*
196 * Adds a local TCP/IP port forward to options. Never returns if there is an
197 * error.
198 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000199
Damien Miller4af51302000-04-16 11:18:38 +1000200void
Damien Milleraae6c611999-12-06 11:47:28 +1100201add_local_forward(Options *options, u_short port, const char *host,
202 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000203{
Damien Miller95def091999-11-25 00:26:21 +1100204 Forward *fwd;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000205#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100206 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100207 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000208 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100209#endif
Damien Miller95def091999-11-25 00:26:21 +1100210 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
211 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
212 fwd = &options->local_forwards[options->num_local_forwards++];
213 fwd->port = port;
214 fwd->host = xstrdup(host);
215 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000216}
217
Damien Miller5428f641999-11-25 11:54:57 +1100218/*
219 * Adds a remote TCP/IP port forward to options. Never returns if there is
220 * an error.
221 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000222
Damien Miller4af51302000-04-16 11:18:38 +1000223void
Damien Milleraae6c611999-12-06 11:47:28 +1100224add_remote_forward(Options *options, u_short port, const char *host,
225 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000226{
Damien Miller95def091999-11-25 00:26:21 +1100227 Forward *fwd;
228 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
229 fatal("Too many remote forwards (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100230 SSH_MAX_FORWARDS_PER_DIRECTION);
Damien Miller95def091999-11-25 00:26:21 +1100231 fwd = &options->remote_forwards[options->num_remote_forwards++];
232 fwd->port = port;
233 fwd->host = xstrdup(host);
234 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000235}
236
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000237static void
238clear_forwardings(Options *options)
239{
240 int i;
241
242 for (i = 0; i < options->num_local_forwards; i++)
243 xfree(options->local_forwards[i].host);
244 options->num_local_forwards = 0;
245 for (i = 0; i < options->num_remote_forwards; i++)
246 xfree(options->remote_forwards[i].host);
247 options->num_remote_forwards = 0;
248}
249
Damien Miller5428f641999-11-25 11:54:57 +1100250/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000251 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100252 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000253
Damien Miller4af51302000-04-16 11:18:38 +1000254static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100255parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000256{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000257 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000258
Damien Miller95def091999-11-25 00:26:21 +1100259 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100260 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100261 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000262
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000263 error("%s: line %d: Bad configuration option: %s",
264 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100265 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000266}
267
Damien Miller5428f641999-11-25 11:54:57 +1100268/*
269 * Processes a single option line as used in the configuration files. This
270 * only sets those values that have not already been set.
271 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100272#define WHITESPACE " \t\r\n"
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000273
Damien Miller2ccf6611999-11-15 15:25:10 +1100274int
275process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100276 char *line, const char *filename, int linenum,
277 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000278{
Damien Miller61f08ac2003-02-24 11:56:27 +1100279 char buf[256], *s, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100280 int opcode, *intptr, value;
Damien Miller61f08ac2003-02-24 11:56:27 +1100281 size_t len;
Damien Milleraae6c611999-12-06 11:47:28 +1100282 u_short fwd_port, fwd_host_port;
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000283 char sfwd_host_port[6];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000284
Damien Millerc652cac2003-05-14 13:40:54 +1000285 /* Strip trailing whitespace */
286 for(len = strlen(line) - 1; len > 0; len--) {
287 if (strchr(WHITESPACE, line[len]) == NULL)
288 break;
289 line[len] = '\0';
290 }
291
Damien Millerbe484b52000-07-15 14:14:16 +1000292 s = line;
293 /* Get the keyword. (Each line is supposed to begin with a keyword). */
294 keyword = strdelim(&s);
295 /* Ignore leading whitespace. */
296 if (*keyword == '\0')
297 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000298 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100299 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000300
Damien Miller37023962000-07-11 17:31:38 +1000301 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000302
Damien Miller95def091999-11-25 00:26:21 +1100303 switch (opcode) {
304 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100305 /* don't panic, but count bad options */
306 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100307 /* NOTREACHED */
Damien Millerb78d5eb2003-05-16 11:39:04 +1000308 case oConnectTimeout:
309 intptr = &options->connection_timeout;
310/* parse_time: */
311 arg = strdelim(&s);
312 if (!arg || *arg == '\0')
313 fatal("%s line %d: missing time value.",
314 filename, linenum);
315 if ((value = convtime(arg)) == -1)
316 fatal("%s line %d: invalid time value.",
317 filename, linenum);
318 if (*intptr == -1)
319 *intptr = value;
320 break;
321
Damien Miller95def091999-11-25 00:26:21 +1100322 case oForwardAgent:
323 intptr = &options->forward_agent;
324parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000325 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000326 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100327 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
328 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000329 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100330 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000331 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100332 value = 0;
333 else
334 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
335 if (*activep && *intptr == -1)
336 *intptr = value;
337 break;
338
339 case oForwardX11:
340 intptr = &options->forward_x11;
341 goto parse_flag;
342
Darren Tucker0a118da2003-10-15 15:54:32 +1000343 case oForwardX11Trusted:
344 intptr = &options->forward_x11_trusted;
345 goto parse_flag;
346
Damien Miller95def091999-11-25 00:26:21 +1100347 case oGatewayPorts:
348 intptr = &options->gateway_ports;
349 goto parse_flag;
350
351 case oUsePrivilegedPort:
352 intptr = &options->use_privileged_port;
353 goto parse_flag;
354
Damien Miller95def091999-11-25 00:26:21 +1100355 case oPasswordAuthentication:
356 intptr = &options->password_authentication;
357 goto parse_flag;
358
Damien Miller874d77b2000-10-14 16:23:11 +1100359 case oKbdInteractiveAuthentication:
360 intptr = &options->kbd_interactive_authentication;
361 goto parse_flag;
362
363 case oKbdInteractiveDevices:
364 charptr = &options->kbd_interactive_devices;
365 goto parse_string;
366
Damien Miller0bc1bd82000-11-13 22:57:25 +1100367 case oPubkeyAuthentication:
368 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000369 goto parse_flag;
370
Damien Miller95def091999-11-25 00:26:21 +1100371 case oRSAAuthentication:
372 intptr = &options->rsa_authentication;
373 goto parse_flag;
374
375 case oRhostsRSAAuthentication:
376 intptr = &options->rhosts_rsa_authentication;
377 goto parse_flag;
378
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000379 case oHostbasedAuthentication:
380 intptr = &options->hostbased_authentication;
381 goto parse_flag;
382
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000383 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000384 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100385 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000386
Darren Tucker0efd1552003-08-26 11:49:55 +1000387 case oGssAuthentication:
388 intptr = &options->gss_authentication;
389 goto parse_flag;
390
391 case oGssDelegateCreds:
392 intptr = &options->gss_deleg_creds;
393 goto parse_flag;
394
Damien Miller95def091999-11-25 00:26:21 +1100395 case oBatchMode:
396 intptr = &options->batch_mode;
397 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000398
Damien Miller95def091999-11-25 00:26:21 +1100399 case oCheckHostIP:
400 intptr = &options->check_host_ip;
401 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000402
Damien Miller37876e92003-05-15 10:19:46 +1000403 case oVerifyHostKeyDNS:
404 intptr = &options->verify_host_key_dns;
Damien Miller150b5572003-11-17 21:19:29 +1100405 goto parse_yesnoask;
Damien Miller37876e92003-05-15 10:19:46 +1000406
Damien Miller95def091999-11-25 00:26:21 +1100407 case oStrictHostKeyChecking:
408 intptr = &options->strict_host_key_checking;
Damien Miller150b5572003-11-17 21:19:29 +1100409parse_yesnoask:
Damien Millerbe484b52000-07-15 14:14:16 +1000410 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000411 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000412 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100413 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100414 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000415 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100416 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000417 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100418 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000419 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100420 value = 2;
421 else
422 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
423 if (*activep && *intptr == -1)
424 *intptr = value;
425 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000426
Damien Miller95def091999-11-25 00:26:21 +1100427 case oCompression:
428 intptr = &options->compression;
429 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000430
Damien Miller12c150e2003-12-17 16:31:10 +1100431 case oTCPKeepAlive:
432 intptr = &options->tcp_keep_alive;
Damien Miller95def091999-11-25 00:26:21 +1100433 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000434
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000435 case oNoHostAuthenticationForLocalhost:
436 intptr = &options->no_host_authentication_for_localhost;
437 goto parse_flag;
438
Damien Miller95def091999-11-25 00:26:21 +1100439 case oNumberOfPasswordPrompts:
440 intptr = &options->number_of_password_prompts;
441 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000442
Damien Miller95def091999-11-25 00:26:21 +1100443 case oCompressionLevel:
444 intptr = &options->compression_level;
445 goto parse_int;
446
Damien Millera5539d22003-04-09 20:50:06 +1000447 case oRekeyLimit:
448 intptr = &options->rekey_limit;
449 arg = strdelim(&s);
450 if (!arg || *arg == '\0')
451 fatal("%.200s line %d: Missing argument.", filename, linenum);
452 if (arg[0] < '0' || arg[0] > '9')
453 fatal("%.200s line %d: Bad number.", filename, linenum);
454 value = strtol(arg, &endofnumber, 10);
455 if (arg == endofnumber)
456 fatal("%.200s line %d: Bad number.", filename, linenum);
457 switch (toupper(*endofnumber)) {
458 case 'K':
459 value *= 1<<10;
460 break;
461 case 'M':
462 value *= 1<<20;
463 break;
464 case 'G':
465 value *= 1<<30;
466 break;
467 }
468 if (*activep && *intptr == -1)
469 *intptr = value;
470 break;
471
Damien Miller95def091999-11-25 00:26:21 +1100472 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000473 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000474 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100475 fatal("%.200s line %d: Missing argument.", filename, linenum);
476 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100477 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000478 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100479 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100480 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100481 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000482 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000483 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100484 }
485 break;
486
Damien Millerd3a18572000-06-07 19:55:44 +1000487 case oXAuthLocation:
488 charptr=&options->xauth_location;
489 goto parse_string;
490
Damien Miller95def091999-11-25 00:26:21 +1100491 case oUser:
492 charptr = &options->user;
493parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000494 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000495 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100496 fatal("%.200s line %d: Missing argument.", filename, linenum);
497 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000498 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100499 break;
500
501 case oGlobalKnownHostsFile:
502 charptr = &options->system_hostfile;
503 goto parse_string;
504
505 case oUserKnownHostsFile:
506 charptr = &options->user_hostfile;
507 goto parse_string;
508
Damien Millereba71ba2000-04-29 23:57:08 +1000509 case oGlobalKnownHostsFile2:
510 charptr = &options->system_hostfile2;
511 goto parse_string;
512
513 case oUserKnownHostsFile2:
514 charptr = &options->user_hostfile2;
515 goto parse_string;
516
Damien Miller95def091999-11-25 00:26:21 +1100517 case oHostName:
518 charptr = &options->hostname;
519 goto parse_string;
520
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000521 case oHostKeyAlias:
522 charptr = &options->host_key_alias;
523 goto parse_string;
524
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000525 case oPreferredAuthentications:
526 charptr = &options->preferred_authentications;
527 goto parse_string;
528
Ben Lindstrome0f88042001-04-30 13:06:24 +0000529 case oBindAddress:
530 charptr = &options->bind_address;
531 goto parse_string;
532
Ben Lindstromae996bf2001-08-06 21:27:53 +0000533 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000534 charptr = &options->smartcard_device;
535 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000536
Damien Miller95def091999-11-25 00:26:21 +1100537 case oProxyCommand:
Darren Tuckera99c1b72003-06-28 12:40:12 +1000538 if (s == NULL)
539 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100540 charptr = &options->proxy_command;
Damien Miller61f08ac2003-02-24 11:56:27 +1100541 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +1100542 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +1100543 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +1100544 return 0;
545
546 case oPort:
547 intptr = &options->port;
548parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000549 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000550 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100551 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000552 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100553 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100554
555 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000556 value = strtol(arg, &endofnumber, 0);
557 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100558 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100559 if (*activep && *intptr == -1)
560 *intptr = value;
561 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000562
Damien Miller95def091999-11-25 00:26:21 +1100563 case oConnectionAttempts:
564 intptr = &options->connection_attempts;
565 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100566
Damien Miller95def091999-11-25 00:26:21 +1100567 case oCipher:
568 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000569 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000570 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000571 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000572 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100573 if (value == -1)
574 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100575 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100576 if (*activep && *intptr == -1)
577 *intptr = value;
578 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000579
Damien Miller78928792000-04-12 20:17:38 +1000580 case oCiphers:
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 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000585 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100586 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000587 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000588 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000589 break;
590
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000591 case oMacs:
592 arg = strdelim(&s);
593 if (!arg || *arg == '\0')
594 fatal("%.200s line %d: Missing argument.", filename, linenum);
595 if (!mac_valid(arg))
596 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100597 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000598 if (*activep && options->macs == NULL)
599 options->macs = xstrdup(arg);
600 break;
601
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000602 case oHostKeyAlgorithms:
603 arg = strdelim(&s);
604 if (!arg || *arg == '\0')
605 fatal("%.200s line %d: Missing argument.", filename, linenum);
606 if (!key_names_valid2(arg))
607 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100608 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000609 if (*activep && options->hostkeyalgorithms == NULL)
610 options->hostkeyalgorithms = xstrdup(arg);
611 break;
612
Damien Miller78928792000-04-12 20:17:38 +1000613 case oProtocol:
614 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000615 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000616 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000617 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000618 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000619 if (value == SSH_PROTO_UNKNOWN)
620 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100621 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000622 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
623 *intptr = value;
624 break;
625
Damien Miller95def091999-11-25 00:26:21 +1100626 case oLogLevel:
627 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000628 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000629 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100630 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000631 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100632 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100633 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100634 *intptr = (LogLevel) value;
635 break;
636
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000637 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100638 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000639 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000640 if (!arg || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000641 fatal("%.200s line %d: Missing port argument.",
642 filename, linenum);
643 if ((fwd_port = a2port(arg)) == 0)
644 fatal("%.200s line %d: Bad listen port.",
645 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000646 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000647 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100648 fatal("%.200s line %d: Missing second argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000649 filename, linenum);
650 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
651 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
652 fatal("%.200s line %d: Bad forwarding specification.",
653 filename, linenum);
654 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
655 fatal("%.200s line %d: Bad forwarding port.",
656 filename, linenum);
657 if (*activep) {
658 if (opcode == oLocalForward)
659 add_local_forward(options, fwd_port, buf,
660 fwd_host_port);
661 else if (opcode == oRemoteForward)
662 add_remote_forward(options, fwd_port, buf,
663 fwd_host_port);
664 }
Damien Miller95def091999-11-25 00:26:21 +1100665 break;
666
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000667 case oDynamicForward:
668 arg = strdelim(&s);
669 if (!arg || *arg == '\0')
670 fatal("%.200s line %d: Missing port argument.",
671 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000672 fwd_port = a2port(arg);
673 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000674 fatal("%.200s line %d: Badly formatted port number.",
675 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000676 if (*activep)
Darren Tucker1c52ee32003-08-13 20:38:36 +1000677 add_local_forward(options, fwd_port, "socks", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000678 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000679
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000680 case oClearAllForwardings:
681 intptr = &options->clear_forwardings;
682 goto parse_flag;
683
Damien Miller95def091999-11-25 00:26:21 +1100684 case oHost:
685 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000686 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000687 if (match_pattern(host, arg)) {
688 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100689 *activep = 1;
690 break;
691 }
Damien Millerbe484b52000-07-15 14:14:16 +1000692 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100693 return 0;
694
695 case oEscapeChar:
696 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000697 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000698 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100699 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000700 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000701 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
702 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000703 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000704 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000705 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000706 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100707 else {
708 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100709 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100710 /* NOTREACHED */
711 value = 0; /* Avoid compiler warning. */
712 }
713 if (*activep && *intptr == -1)
714 *intptr = value;
715 break;
716
Damien Miller20a8f972003-05-18 20:50:30 +1000717 case oAddressFamily:
718 arg = strdelim(&s);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000719 intptr = &options->address_family;
Damien Miller20a8f972003-05-18 20:50:30 +1000720 if (strcasecmp(arg, "inet") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000721 value = AF_INET;
Damien Miller20a8f972003-05-18 20:50:30 +1000722 else if (strcasecmp(arg, "inet6") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000723 value = AF_INET6;
Damien Miller20a8f972003-05-18 20:50:30 +1000724 else if (strcasecmp(arg, "any") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000725 value = AF_UNSPEC;
Damien Miller20a8f972003-05-18 20:50:30 +1000726 else
727 fatal("Unsupported AddressFamily \"%s\"", arg);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000728 if (*activep && *intptr == -1)
729 *intptr = value;
Damien Miller20a8f972003-05-18 20:50:30 +1000730 break;
731
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000732 case oEnableSSHKeysign:
733 intptr = &options->enable_ssh_keysign;
734 goto parse_flag;
735
Ben Lindstrom4daea862002-06-09 20:04:02 +0000736 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000737 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +0000738 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000739 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +0000740
Damien Millerf9b3feb2003-05-16 11:38:32 +1000741 case oUnsupported:
742 error("%s line %d: Unsupported option \"%s\"",
743 filename, linenum, keyword);
744 return 0;
745
Damien Miller95def091999-11-25 00:26:21 +1100746 default:
747 fatal("process_config_line: Unimplemented opcode %d", opcode);
748 }
749
750 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000751 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000752 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100753 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000754 }
Damien Miller95def091999-11-25 00:26:21 +1100755 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000756}
757
758
Damien Miller5428f641999-11-25 11:54:57 +1100759/*
760 * Reads the config file and modifies the options accordingly. Options
761 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000762 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100763 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000764
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000765int
Damien Miller95def091999-11-25 00:26:21 +1100766read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000767{
Damien Miller95def091999-11-25 00:26:21 +1100768 FILE *f;
769 char line[1024];
770 int active, linenum;
771 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000772
Damien Miller95def091999-11-25 00:26:21 +1100773 /* Open the file. */
774 f = fopen(filename, "r");
775 if (!f)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000776 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000777
Damien Miller95def091999-11-25 00:26:21 +1100778 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000779
Damien Miller5428f641999-11-25 11:54:57 +1100780 /*
781 * Mark that we are now processing the options. This flag is turned
782 * on/off by Host specifications.
783 */
Damien Miller95def091999-11-25 00:26:21 +1100784 active = 1;
785 linenum = 0;
786 while (fgets(line, sizeof(line), f)) {
787 /* Update line number counter. */
788 linenum++;
789 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
790 bad_options++;
791 }
792 fclose(f);
793 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000794 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100795 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000796 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000797}
798
Damien Miller5428f641999-11-25 11:54:57 +1100799/*
800 * Initializes options to special values that indicate that they have not yet
801 * been set. Read_config_file will only set options with this value. Options
802 * are processed in the following order: command line, user config file,
803 * system config file. Last, fill_default_options is called.
804 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000805
Damien Miller4af51302000-04-16 11:18:38 +1000806void
Damien Miller95def091999-11-25 00:26:21 +1100807initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000808{
Damien Miller95def091999-11-25 00:26:21 +1100809 memset(options, 'X', sizeof(*options));
810 options->forward_agent = -1;
811 options->forward_x11 = -1;
Darren Tucker0a118da2003-10-15 15:54:32 +1000812 options->forward_x11_trusted = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000813 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100814 options->gateway_ports = -1;
815 options->use_privileged_port = -1;
Damien Miller95def091999-11-25 00:26:21 +1100816 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100817 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000818 options->challenge_response_authentication = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000819 options->gss_authentication = -1;
820 options->gss_deleg_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100821 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100822 options->kbd_interactive_authentication = -1;
823 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100824 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000825 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100826 options->batch_mode = -1;
827 options->check_host_ip = -1;
828 options->strict_host_key_checking = -1;
829 options->compression = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100830 options->tcp_keep_alive = -1;
Damien Miller95def091999-11-25 00:26:21 +1100831 options->compression_level = -1;
832 options->port = -1;
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000833 options->address_family = -1;
Damien Miller95def091999-11-25 00:26:21 +1100834 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000835 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +1100836 options->number_of_password_prompts = -1;
837 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000838 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000839 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000840 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000841 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100842 options->num_identity_files = 0;
843 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000844 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100845 options->proxy_command = NULL;
846 options->user = NULL;
847 options->escape_char = -1;
848 options->system_hostfile = NULL;
849 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000850 options->system_hostfile2 = NULL;
851 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100852 options->num_local_forwards = 0;
853 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000854 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100855 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000856 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000857 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000858 options->smartcard_device = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000859 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000860 options->no_host_authentication_for_localhost = - 1;
Damien Millera5539d22003-04-09 20:50:06 +1000861 options->rekey_limit = - 1;
Damien Miller37876e92003-05-15 10:19:46 +1000862 options->verify_host_key_dns = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000863}
864
Damien Miller5428f641999-11-25 11:54:57 +1100865/*
866 * Called after processing other sources of option data, this fills those
867 * options for which no value has been specified with their default values.
868 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000869
Damien Miller4af51302000-04-16 11:18:38 +1000870void
Damien Miller95def091999-11-25 00:26:21 +1100871fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000872{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000873 int len;
874
Damien Miller95def091999-11-25 00:26:21 +1100875 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000876 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100877 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100878 options->forward_x11 = 0;
Darren Tucker0a118da2003-10-15 15:54:32 +1000879 if (options->forward_x11_trusted == -1)
880 options->forward_x11_trusted = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000881 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000882 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100883 if (options->gateway_ports == -1)
884 options->gateway_ports = 0;
885 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000886 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100887 if (options->rsa_authentication == -1)
888 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100889 if (options->pubkey_authentication == -1)
890 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000891 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000892 options->challenge_response_authentication = 1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000893 if (options->gss_authentication == -1)
Darren Tuckera044f472003-10-15 15:52:03 +1000894 options->gss_authentication = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000895 if (options->gss_deleg_creds == -1)
896 options->gss_deleg_creds = 0;
Damien Miller95def091999-11-25 00:26:21 +1100897 if (options->password_authentication == -1)
898 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100899 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000900 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100901 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000902 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000903 if (options->hostbased_authentication == -1)
904 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100905 if (options->batch_mode == -1)
906 options->batch_mode = 0;
907 if (options->check_host_ip == -1)
908 options->check_host_ip = 1;
909 if (options->strict_host_key_checking == -1)
910 options->strict_host_key_checking = 2; /* 2 is default */
911 if (options->compression == -1)
912 options->compression = 0;
Damien Miller12c150e2003-12-17 16:31:10 +1100913 if (options->tcp_keep_alive == -1)
914 options->tcp_keep_alive = 1;
Damien Miller95def091999-11-25 00:26:21 +1100915 if (options->compression_level == -1)
916 options->compression_level = 6;
917 if (options->port == -1)
918 options->port = 0; /* Filled in ssh_connect. */
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000919 if (options->address_family == -1)
920 options->address_family = AF_UNSPEC;
Damien Miller95def091999-11-25 00:26:21 +1100921 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000922 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100923 if (options->number_of_password_prompts == -1)
924 options->number_of_password_prompts = 3;
925 /* Selected in ssh_login(). */
926 if (options->cipher == -1)
927 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000928 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000929 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000930 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000931 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000932 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100933 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100934 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000935 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100936 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000937 xmalloc(len);
938 snprintf(options->identity_files[options->num_identity_files++],
939 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100940 }
941 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000942 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
943 options->identity_files[options->num_identity_files] =
944 xmalloc(len);
945 snprintf(options->identity_files[options->num_identity_files++],
946 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
947
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000948 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 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_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100953 }
Damien Millereba71ba2000-04-29 23:57:08 +1000954 }
Damien Miller95def091999-11-25 00:26:21 +1100955 if (options->escape_char == -1)
956 options->escape_char = '~';
957 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000958 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100959 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000960 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000961 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000962 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000963 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000964 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +1100965 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000966 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000967 if (options->clear_forwardings == 1)
968 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000969 if (options->no_host_authentication_for_localhost == - 1)
970 options->no_host_authentication_for_localhost = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000971 if (options->enable_ssh_keysign == -1)
972 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +1000973 if (options->rekey_limit == -1)
974 options->rekey_limit = 0;
Damien Miller37876e92003-05-15 10:19:46 +1000975 if (options->verify_host_key_dns == -1)
976 options->verify_host_key_dns = 0;
Damien Miller95def091999-11-25 00:26:21 +1100977 /* options->proxy_command should not be set by default */
978 /* options->user will be set in the main program if appropriate */
979 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000980 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000981 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000982}