blob: 2591e0dba090b9a65fbdf1ac251c49ad3179be73 [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 Miller509b0102003-12-17 16:33:10 +110015RCSID("$OpenBSD: readconf.c,v 1.127 2003/12/16 15:49:51 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 Miller509b0102003-12-17 16:33:10 +1100108 oServerAliveInterval, oServerAliveCountMax,
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 },
Darren Tucker0a118da2003-10-15 15:54:32 +1000120 { "forwardx11trusted", oForwardX11Trusted },
Damien Millerd3a18572000-06-07 19:55:44 +1000121 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100122 { "gatewayports", oGatewayPorts },
123 { "useprivilegedport", oUsePrivilegedPort },
Darren Tuckerec960f22003-08-13 20:37:05 +1000124 { "rhostsauthentication", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100125 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100126 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
127 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100128 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100129 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000130 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000131 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000132 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000133 { "challengeresponseauthentication", oChallengeResponseAuthentication },
134 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
135 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Millerf9b3feb2003-05-16 11:38:32 +1000136 { "kerberosauthentication", oUnsupported },
137 { "kerberostgtpassing", oUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000138 { "afstokenpassing", oUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000139#if defined(GSSAPI)
140 { "gssapiauthentication", oGssAuthentication },
Darren Tucker0efd1552003-08-26 11:49:55 +1000141 { "gssapidelegatecredentials", oGssDelegateCreds },
142#else
143 { "gssapiauthentication", oUnsupported },
144 { "gssapidelegatecredentials", oUnsupported },
145#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000146 { "fallbacktorsh", oDeprecated },
147 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100148 { "identityfile", oIdentityFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100149 { "identityfile2", oIdentityFile }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100150 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000151 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100152 { "proxycommand", oProxyCommand },
153 { "port", oPort },
154 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000155 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000156 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000157 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100158 { "remoteforward", oRemoteForward },
159 { "localforward", oLocalForward },
160 { "user", oUser },
161 { "host", oHost },
162 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100163 { "globalknownhostsfile", oGlobalKnownHostsFile },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000164 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
Damien Millereba71ba2000-04-29 23:57:08 +1000165 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
Ben Lindstromd6481ea2001-06-25 04:37:41 +0000166 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100167 { "connectionattempts", oConnectionAttempts },
168 { "batchmode", oBatchMode },
169 { "checkhostip", oCheckHostIP },
170 { "stricthostkeychecking", oStrictHostKeyChecking },
171 { "compression", oCompression },
172 { "compressionlevel", oCompressionLevel },
Damien Miller12c150e2003-12-17 16:31:10 +1100173 { "tcpkeepalive", oTCPKeepAlive },
174 { "keepalive", oTCPKeepAlive }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100175 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100176 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000177 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000178 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000179 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000180 { "bindaddress", oBindAddress },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000181#ifdef SMARTCARD
Ben Lindstromae996bf2001-08-06 21:27:53 +0000182 { "smartcarddevice", oSmartcardDevice },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000183#else
184 { "smartcarddevice", oUnsupported },
185#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100186 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000187 { "enablesshkeysign", oEnableSSHKeysign },
Damien Miller37876e92003-05-15 10:19:46 +1000188 { "verifyhostkeydns", oVerifyHostKeyDNS },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100189 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000190 { "rekeylimit", oRekeyLimit },
Damien Millerb78d5eb2003-05-16 11:39:04 +1000191 { "connecttimeout", oConnectTimeout },
Damien Miller20a8f972003-05-18 20:50:30 +1000192 { "addressfamily", oAddressFamily },
Damien Miller509b0102003-12-17 16:33:10 +1100193 { "serveraliveinterval", oServerAliveInterval },
194 { "serveralivecountmax", oServerAliveCountMax },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000195 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100196};
197
Damien Miller5428f641999-11-25 11:54:57 +1100198/*
199 * Adds a local TCP/IP port forward to options. Never returns if there is an
200 * error.
201 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000202
Damien Miller4af51302000-04-16 11:18:38 +1000203void
Damien Milleraae6c611999-12-06 11:47:28 +1100204add_local_forward(Options *options, u_short port, const char *host,
205 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000206{
Damien Miller95def091999-11-25 00:26:21 +1100207 Forward *fwd;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000208#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100209 extern uid_t original_real_uid;
Damien Miller95def091999-11-25 00:26:21 +1100210 if (port < IPPORT_RESERVED && original_real_uid != 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000211 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100212#endif
Damien Miller95def091999-11-25 00:26:21 +1100213 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
214 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
215 fwd = &options->local_forwards[options->num_local_forwards++];
216 fwd->port = port;
217 fwd->host = xstrdup(host);
218 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000219}
220
Damien Miller5428f641999-11-25 11:54:57 +1100221/*
222 * Adds a remote TCP/IP port forward to options. Never returns if there is
223 * an error.
224 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000225
Damien Miller4af51302000-04-16 11:18:38 +1000226void
Damien Milleraae6c611999-12-06 11:47:28 +1100227add_remote_forward(Options *options, u_short port, const char *host,
228 u_short host_port)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000229{
Damien Miller95def091999-11-25 00:26:21 +1100230 Forward *fwd;
231 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
232 fatal("Too many remote forwards (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100233 SSH_MAX_FORWARDS_PER_DIRECTION);
Damien Miller95def091999-11-25 00:26:21 +1100234 fwd = &options->remote_forwards[options->num_remote_forwards++];
235 fwd->port = port;
236 fwd->host = xstrdup(host);
237 fwd->host_port = host_port;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000238}
239
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000240static void
241clear_forwardings(Options *options)
242{
243 int i;
244
245 for (i = 0; i < options->num_local_forwards; i++)
246 xfree(options->local_forwards[i].host);
247 options->num_local_forwards = 0;
248 for (i = 0; i < options->num_remote_forwards; i++)
249 xfree(options->remote_forwards[i].host);
250 options->num_remote_forwards = 0;
251}
252
Damien Miller5428f641999-11-25 11:54:57 +1100253/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000254 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100255 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000256
Damien Miller4af51302000-04-16 11:18:38 +1000257static OpCodes
Damien Miller95def091999-11-25 00:26:21 +1100258parse_token(const char *cp, const char *filename, int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000259{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000260 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000261
Damien Miller95def091999-11-25 00:26:21 +1100262 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100263 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100264 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000265
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000266 error("%s: line %d: Bad configuration option: %s",
267 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100268 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000269}
270
Damien Miller5428f641999-11-25 11:54:57 +1100271/*
272 * Processes a single option line as used in the configuration files. This
273 * only sets those values that have not already been set.
274 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100275#define WHITESPACE " \t\r\n"
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000276
Damien Miller2ccf6611999-11-15 15:25:10 +1100277int
278process_config_line(Options *options, const char *host,
Damien Miller95def091999-11-25 00:26:21 +1100279 char *line, const char *filename, int linenum,
280 int *activep)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000281{
Damien Miller61f08ac2003-02-24 11:56:27 +1100282 char buf[256], *s, **charptr, *endofnumber, *keyword, *arg;
Damien Milleraae6c611999-12-06 11:47:28 +1100283 int opcode, *intptr, value;
Damien Miller61f08ac2003-02-24 11:56:27 +1100284 size_t len;
Damien Milleraae6c611999-12-06 11:47:28 +1100285 u_short fwd_port, fwd_host_port;
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000286 char sfwd_host_port[6];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000287
Damien Millerc652cac2003-05-14 13:40:54 +1000288 /* Strip trailing whitespace */
289 for(len = strlen(line) - 1; len > 0; len--) {
290 if (strchr(WHITESPACE, line[len]) == NULL)
291 break;
292 line[len] = '\0';
293 }
294
Damien Millerbe484b52000-07-15 14:14:16 +1000295 s = line;
296 /* Get the keyword. (Each line is supposed to begin with a keyword). */
297 keyword = strdelim(&s);
298 /* Ignore leading whitespace. */
299 if (*keyword == '\0')
300 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000301 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100302 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000303
Damien Miller37023962000-07-11 17:31:38 +1000304 opcode = parse_token(keyword, filename, linenum);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000305
Damien Miller95def091999-11-25 00:26:21 +1100306 switch (opcode) {
307 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100308 /* don't panic, but count bad options */
309 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100310 /* NOTREACHED */
Damien Millerb78d5eb2003-05-16 11:39:04 +1000311 case oConnectTimeout:
312 intptr = &options->connection_timeout;
Damien Miller509b0102003-12-17 16:33:10 +1100313parse_time:
Damien Millerb78d5eb2003-05-16 11:39:04 +1000314 arg = strdelim(&s);
315 if (!arg || *arg == '\0')
316 fatal("%s line %d: missing time value.",
317 filename, linenum);
318 if ((value = convtime(arg)) == -1)
319 fatal("%s line %d: invalid time value.",
320 filename, linenum);
321 if (*intptr == -1)
322 *intptr = value;
323 break;
324
Damien Miller95def091999-11-25 00:26:21 +1100325 case oForwardAgent:
326 intptr = &options->forward_agent;
327parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000328 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000329 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100330 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
331 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000332 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100333 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000334 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100335 value = 0;
336 else
337 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
338 if (*activep && *intptr == -1)
339 *intptr = value;
340 break;
341
342 case oForwardX11:
343 intptr = &options->forward_x11;
344 goto parse_flag;
345
Darren Tucker0a118da2003-10-15 15:54:32 +1000346 case oForwardX11Trusted:
347 intptr = &options->forward_x11_trusted;
348 goto parse_flag;
349
Damien Miller95def091999-11-25 00:26:21 +1100350 case oGatewayPorts:
351 intptr = &options->gateway_ports;
352 goto parse_flag;
353
354 case oUsePrivilegedPort:
355 intptr = &options->use_privileged_port;
356 goto parse_flag;
357
Damien Miller95def091999-11-25 00:26:21 +1100358 case oPasswordAuthentication:
359 intptr = &options->password_authentication;
360 goto parse_flag;
361
Damien Miller874d77b2000-10-14 16:23:11 +1100362 case oKbdInteractiveAuthentication:
363 intptr = &options->kbd_interactive_authentication;
364 goto parse_flag;
365
366 case oKbdInteractiveDevices:
367 charptr = &options->kbd_interactive_devices;
368 goto parse_string;
369
Damien Miller0bc1bd82000-11-13 22:57:25 +1100370 case oPubkeyAuthentication:
371 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000372 goto parse_flag;
373
Damien Miller95def091999-11-25 00:26:21 +1100374 case oRSAAuthentication:
375 intptr = &options->rsa_authentication;
376 goto parse_flag;
377
378 case oRhostsRSAAuthentication:
379 intptr = &options->rhosts_rsa_authentication;
380 goto parse_flag;
381
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000382 case oHostbasedAuthentication:
383 intptr = &options->hostbased_authentication;
384 goto parse_flag;
385
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000386 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000387 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100388 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000389
Darren Tucker0efd1552003-08-26 11:49:55 +1000390 case oGssAuthentication:
391 intptr = &options->gss_authentication;
392 goto parse_flag;
393
394 case oGssDelegateCreds:
395 intptr = &options->gss_deleg_creds;
396 goto parse_flag;
397
Damien Miller95def091999-11-25 00:26:21 +1100398 case oBatchMode:
399 intptr = &options->batch_mode;
400 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000401
Damien Miller95def091999-11-25 00:26:21 +1100402 case oCheckHostIP:
403 intptr = &options->check_host_ip;
404 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000405
Damien Miller37876e92003-05-15 10:19:46 +1000406 case oVerifyHostKeyDNS:
407 intptr = &options->verify_host_key_dns;
Damien Miller150b5572003-11-17 21:19:29 +1100408 goto parse_yesnoask;
Damien Miller37876e92003-05-15 10:19:46 +1000409
Damien Miller95def091999-11-25 00:26:21 +1100410 case oStrictHostKeyChecking:
411 intptr = &options->strict_host_key_checking;
Damien Miller150b5572003-11-17 21:19:29 +1100412parse_yesnoask:
Damien Millerbe484b52000-07-15 14:14:16 +1000413 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000414 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000415 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100416 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100417 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000418 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100419 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000420 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100421 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000422 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100423 value = 2;
424 else
425 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
426 if (*activep && *intptr == -1)
427 *intptr = value;
428 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000429
Damien Miller95def091999-11-25 00:26:21 +1100430 case oCompression:
431 intptr = &options->compression;
432 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000433
Damien Miller12c150e2003-12-17 16:31:10 +1100434 case oTCPKeepAlive:
435 intptr = &options->tcp_keep_alive;
Damien Miller95def091999-11-25 00:26:21 +1100436 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000437
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000438 case oNoHostAuthenticationForLocalhost:
439 intptr = &options->no_host_authentication_for_localhost;
440 goto parse_flag;
441
Damien Miller95def091999-11-25 00:26:21 +1100442 case oNumberOfPasswordPrompts:
443 intptr = &options->number_of_password_prompts;
444 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000445
Damien Miller95def091999-11-25 00:26:21 +1100446 case oCompressionLevel:
447 intptr = &options->compression_level;
448 goto parse_int;
449
Damien Millera5539d22003-04-09 20:50:06 +1000450 case oRekeyLimit:
451 intptr = &options->rekey_limit;
452 arg = strdelim(&s);
453 if (!arg || *arg == '\0')
454 fatal("%.200s line %d: Missing argument.", filename, linenum);
455 if (arg[0] < '0' || arg[0] > '9')
456 fatal("%.200s line %d: Bad number.", filename, linenum);
457 value = strtol(arg, &endofnumber, 10);
458 if (arg == endofnumber)
459 fatal("%.200s line %d: Bad number.", filename, linenum);
460 switch (toupper(*endofnumber)) {
461 case 'K':
462 value *= 1<<10;
463 break;
464 case 'M':
465 value *= 1<<20;
466 break;
467 case 'G':
468 value *= 1<<30;
469 break;
470 }
471 if (*activep && *intptr == -1)
472 *intptr = value;
473 break;
474
Damien Miller95def091999-11-25 00:26:21 +1100475 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000476 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000477 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100478 fatal("%.200s line %d: Missing argument.", filename, linenum);
479 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100480 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000481 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100482 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100483 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100484 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000485 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000486 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100487 }
488 break;
489
Damien Millerd3a18572000-06-07 19:55:44 +1000490 case oXAuthLocation:
491 charptr=&options->xauth_location;
492 goto parse_string;
493
Damien Miller95def091999-11-25 00:26:21 +1100494 case oUser:
495 charptr = &options->user;
496parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000497 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000498 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100499 fatal("%.200s line %d: Missing argument.", filename, linenum);
500 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000501 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100502 break;
503
504 case oGlobalKnownHostsFile:
505 charptr = &options->system_hostfile;
506 goto parse_string;
507
508 case oUserKnownHostsFile:
509 charptr = &options->user_hostfile;
510 goto parse_string;
511
Damien Millereba71ba2000-04-29 23:57:08 +1000512 case oGlobalKnownHostsFile2:
513 charptr = &options->system_hostfile2;
514 goto parse_string;
515
516 case oUserKnownHostsFile2:
517 charptr = &options->user_hostfile2;
518 goto parse_string;
519
Damien Miller95def091999-11-25 00:26:21 +1100520 case oHostName:
521 charptr = &options->hostname;
522 goto parse_string;
523
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000524 case oHostKeyAlias:
525 charptr = &options->host_key_alias;
526 goto parse_string;
527
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000528 case oPreferredAuthentications:
529 charptr = &options->preferred_authentications;
530 goto parse_string;
531
Ben Lindstrome0f88042001-04-30 13:06:24 +0000532 case oBindAddress:
533 charptr = &options->bind_address;
534 goto parse_string;
535
Ben Lindstromae996bf2001-08-06 21:27:53 +0000536 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000537 charptr = &options->smartcard_device;
538 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000539
Damien Miller95def091999-11-25 00:26:21 +1100540 case oProxyCommand:
Darren Tuckera99c1b72003-06-28 12:40:12 +1000541 if (s == NULL)
542 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100543 charptr = &options->proxy_command;
Damien Miller61f08ac2003-02-24 11:56:27 +1100544 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +1100545 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +1100546 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +1100547 return 0;
548
549 case oPort:
550 intptr = &options->port;
551parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000552 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000553 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100554 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000555 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100556 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100557
558 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000559 value = strtol(arg, &endofnumber, 0);
560 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100561 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100562 if (*activep && *intptr == -1)
563 *intptr = value;
564 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000565
Damien Miller95def091999-11-25 00:26:21 +1100566 case oConnectionAttempts:
567 intptr = &options->connection_attempts;
568 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100569
Damien Miller95def091999-11-25 00:26:21 +1100570 case oCipher:
571 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000572 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000573 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000574 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000575 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100576 if (value == -1)
577 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100578 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100579 if (*activep && *intptr == -1)
580 *intptr = value;
581 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000582
Damien Miller78928792000-04-12 20:17:38 +1000583 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000584 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000585 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000586 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000587 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000588 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100589 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000590 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000591 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000592 break;
593
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000594 case oMacs:
595 arg = strdelim(&s);
596 if (!arg || *arg == '\0')
597 fatal("%.200s line %d: Missing argument.", filename, linenum);
598 if (!mac_valid(arg))
599 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100600 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000601 if (*activep && options->macs == NULL)
602 options->macs = xstrdup(arg);
603 break;
604
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000605 case oHostKeyAlgorithms:
606 arg = strdelim(&s);
607 if (!arg || *arg == '\0')
608 fatal("%.200s line %d: Missing argument.", filename, linenum);
609 if (!key_names_valid2(arg))
610 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100611 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000612 if (*activep && options->hostkeyalgorithms == NULL)
613 options->hostkeyalgorithms = xstrdup(arg);
614 break;
615
Damien Miller78928792000-04-12 20:17:38 +1000616 case oProtocol:
617 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000618 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000619 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000620 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000621 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000622 if (value == SSH_PROTO_UNKNOWN)
623 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100624 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000625 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
626 *intptr = value;
627 break;
628
Damien Miller95def091999-11-25 00:26:21 +1100629 case oLogLevel:
630 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000631 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000632 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100633 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000634 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100635 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100636 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100637 *intptr = (LogLevel) value;
638 break;
639
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000640 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100641 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000642 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000643 if (!arg || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000644 fatal("%.200s line %d: Missing port argument.",
645 filename, linenum);
646 if ((fwd_port = a2port(arg)) == 0)
647 fatal("%.200s line %d: Bad listen port.",
648 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000649 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000650 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100651 fatal("%.200s line %d: Missing second argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000652 filename, linenum);
653 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
654 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
655 fatal("%.200s line %d: Bad forwarding specification.",
656 filename, linenum);
657 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
658 fatal("%.200s line %d: Bad forwarding port.",
659 filename, linenum);
660 if (*activep) {
661 if (opcode == oLocalForward)
662 add_local_forward(options, fwd_port, buf,
663 fwd_host_port);
664 else if (opcode == oRemoteForward)
665 add_remote_forward(options, fwd_port, buf,
666 fwd_host_port);
667 }
Damien Miller95def091999-11-25 00:26:21 +1100668 break;
669
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000670 case oDynamicForward:
671 arg = strdelim(&s);
672 if (!arg || *arg == '\0')
673 fatal("%.200s line %d: Missing port argument.",
674 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000675 fwd_port = a2port(arg);
676 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000677 fatal("%.200s line %d: Badly formatted port number.",
678 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000679 if (*activep)
Darren Tucker1c52ee32003-08-13 20:38:36 +1000680 add_local_forward(options, fwd_port, "socks", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000681 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000682
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000683 case oClearAllForwardings:
684 intptr = &options->clear_forwardings;
685 goto parse_flag;
686
Damien Miller95def091999-11-25 00:26:21 +1100687 case oHost:
688 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000689 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000690 if (match_pattern(host, arg)) {
691 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100692 *activep = 1;
693 break;
694 }
Damien Millerbe484b52000-07-15 14:14:16 +1000695 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100696 return 0;
697
698 case oEscapeChar:
699 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000700 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000701 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100702 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000703 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000704 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
705 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000706 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000707 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000708 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000709 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100710 else {
711 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100712 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100713 /* NOTREACHED */
714 value = 0; /* Avoid compiler warning. */
715 }
716 if (*activep && *intptr == -1)
717 *intptr = value;
718 break;
719
Damien Miller20a8f972003-05-18 20:50:30 +1000720 case oAddressFamily:
721 arg = strdelim(&s);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000722 intptr = &options->address_family;
Damien Miller20a8f972003-05-18 20:50:30 +1000723 if (strcasecmp(arg, "inet") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000724 value = AF_INET;
Damien Miller20a8f972003-05-18 20:50:30 +1000725 else if (strcasecmp(arg, "inet6") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000726 value = AF_INET6;
Damien Miller20a8f972003-05-18 20:50:30 +1000727 else if (strcasecmp(arg, "any") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000728 value = AF_UNSPEC;
Damien Miller20a8f972003-05-18 20:50:30 +1000729 else
730 fatal("Unsupported AddressFamily \"%s\"", arg);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000731 if (*activep && *intptr == -1)
732 *intptr = value;
Damien Miller20a8f972003-05-18 20:50:30 +1000733 break;
734
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000735 case oEnableSSHKeysign:
736 intptr = &options->enable_ssh_keysign;
737 goto parse_flag;
738
Damien Miller509b0102003-12-17 16:33:10 +1100739 case oServerAliveInterval:
740 intptr = &options->server_alive_interval;
741 goto parse_time;
742
743 case oServerAliveCountMax:
744 intptr = &options->server_alive_count_max;
745 goto parse_int;
746
Ben Lindstrom4daea862002-06-09 20:04:02 +0000747 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000748 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +0000749 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000750 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +0000751
Damien Millerf9b3feb2003-05-16 11:38:32 +1000752 case oUnsupported:
753 error("%s line %d: Unsupported option \"%s\"",
754 filename, linenum, keyword);
755 return 0;
756
Damien Miller95def091999-11-25 00:26:21 +1100757 default:
758 fatal("process_config_line: Unimplemented opcode %d", opcode);
759 }
760
761 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000762 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000763 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100764 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000765 }
Damien Miller95def091999-11-25 00:26:21 +1100766 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000767}
768
769
Damien Miller5428f641999-11-25 11:54:57 +1100770/*
771 * Reads the config file and modifies the options accordingly. Options
772 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000773 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100774 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000775
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000776int
Damien Miller95def091999-11-25 00:26:21 +1100777read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000778{
Damien Miller95def091999-11-25 00:26:21 +1100779 FILE *f;
780 char line[1024];
781 int active, linenum;
782 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000783
Damien Miller95def091999-11-25 00:26:21 +1100784 /* Open the file. */
785 f = fopen(filename, "r");
786 if (!f)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000787 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000788
Damien Miller95def091999-11-25 00:26:21 +1100789 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000790
Damien Miller5428f641999-11-25 11:54:57 +1100791 /*
792 * Mark that we are now processing the options. This flag is turned
793 * on/off by Host specifications.
794 */
Damien Miller95def091999-11-25 00:26:21 +1100795 active = 1;
796 linenum = 0;
797 while (fgets(line, sizeof(line), f)) {
798 /* Update line number counter. */
799 linenum++;
800 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
801 bad_options++;
802 }
803 fclose(f);
804 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000805 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100806 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000807 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000808}
809
Damien Miller5428f641999-11-25 11:54:57 +1100810/*
811 * Initializes options to special values that indicate that they have not yet
812 * been set. Read_config_file will only set options with this value. Options
813 * are processed in the following order: command line, user config file,
814 * system config file. Last, fill_default_options is called.
815 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000816
Damien Miller4af51302000-04-16 11:18:38 +1000817void
Damien Miller95def091999-11-25 00:26:21 +1100818initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000819{
Damien Miller95def091999-11-25 00:26:21 +1100820 memset(options, 'X', sizeof(*options));
821 options->forward_agent = -1;
822 options->forward_x11 = -1;
Darren Tucker0a118da2003-10-15 15:54:32 +1000823 options->forward_x11_trusted = -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;
Darren Tucker0efd1552003-08-26 11:49:55 +1000830 options->gss_authentication = -1;
831 options->gss_deleg_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100832 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100833 options->kbd_interactive_authentication = -1;
834 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100835 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000836 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100837 options->batch_mode = -1;
838 options->check_host_ip = -1;
839 options->strict_host_key_checking = -1;
840 options->compression = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100841 options->tcp_keep_alive = -1;
Damien Miller95def091999-11-25 00:26:21 +1100842 options->compression_level = -1;
843 options->port = -1;
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000844 options->address_family = -1;
Damien Miller95def091999-11-25 00:26:21 +1100845 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000846 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +1100847 options->number_of_password_prompts = -1;
848 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000849 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000850 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000851 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000852 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100853 options->num_identity_files = 0;
854 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000855 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100856 options->proxy_command = NULL;
857 options->user = NULL;
858 options->escape_char = -1;
859 options->system_hostfile = NULL;
860 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000861 options->system_hostfile2 = NULL;
862 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100863 options->num_local_forwards = 0;
864 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000865 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100866 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000867 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000868 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000869 options->smartcard_device = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000870 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000871 options->no_host_authentication_for_localhost = - 1;
Damien Millera5539d22003-04-09 20:50:06 +1000872 options->rekey_limit = - 1;
Damien Miller37876e92003-05-15 10:19:46 +1000873 options->verify_host_key_dns = -1;
Damien Miller509b0102003-12-17 16:33:10 +1100874 options->server_alive_interval = -1;
875 options->server_alive_count_max = -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;
Darren Tucker0a118da2003-10-15 15:54:32 +1000892 if (options->forward_x11_trusted == -1)
893 options->forward_x11_trusted = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000894 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000895 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100896 if (options->gateway_ports == -1)
897 options->gateway_ports = 0;
898 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000899 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100900 if (options->rsa_authentication == -1)
901 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100902 if (options->pubkey_authentication == -1)
903 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000904 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000905 options->challenge_response_authentication = 1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000906 if (options->gss_authentication == -1)
Darren Tuckera044f472003-10-15 15:52:03 +1000907 options->gss_authentication = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000908 if (options->gss_deleg_creds == -1)
909 options->gss_deleg_creds = 0;
Damien Miller95def091999-11-25 00:26:21 +1100910 if (options->password_authentication == -1)
911 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100912 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000913 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100914 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000915 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000916 if (options->hostbased_authentication == -1)
917 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100918 if (options->batch_mode == -1)
919 options->batch_mode = 0;
920 if (options->check_host_ip == -1)
921 options->check_host_ip = 1;
922 if (options->strict_host_key_checking == -1)
923 options->strict_host_key_checking = 2; /* 2 is default */
924 if (options->compression == -1)
925 options->compression = 0;
Damien Miller12c150e2003-12-17 16:31:10 +1100926 if (options->tcp_keep_alive == -1)
927 options->tcp_keep_alive = 1;
Damien Miller95def091999-11-25 00:26:21 +1100928 if (options->compression_level == -1)
929 options->compression_level = 6;
930 if (options->port == -1)
931 options->port = 0; /* Filled in ssh_connect. */
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000932 if (options->address_family == -1)
933 options->address_family = AF_UNSPEC;
Damien Miller95def091999-11-25 00:26:21 +1100934 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000935 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100936 if (options->number_of_password_prompts == -1)
937 options->number_of_password_prompts = 3;
938 /* Selected in ssh_login(). */
939 if (options->cipher == -1)
940 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000941 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000942 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000943 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000944 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000945 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100946 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100947 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000948 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100949 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000950 xmalloc(len);
951 snprintf(options->identity_files[options->num_identity_files++],
952 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100953 }
954 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000955 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
956 options->identity_files[options->num_identity_files] =
957 xmalloc(len);
958 snprintf(options->identity_files[options->num_identity_files++],
959 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
960
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000961 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100962 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000963 xmalloc(len);
964 snprintf(options->identity_files[options->num_identity_files++],
965 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100966 }
Damien Millereba71ba2000-04-29 23:57:08 +1000967 }
Damien Miller95def091999-11-25 00:26:21 +1100968 if (options->escape_char == -1)
969 options->escape_char = '~';
970 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000971 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100972 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000973 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000974 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000975 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000976 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000977 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +1100978 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000979 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000980 if (options->clear_forwardings == 1)
981 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000982 if (options->no_host_authentication_for_localhost == - 1)
983 options->no_host_authentication_for_localhost = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000984 if (options->enable_ssh_keysign == -1)
985 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +1000986 if (options->rekey_limit == -1)
987 options->rekey_limit = 0;
Damien Miller37876e92003-05-15 10:19:46 +1000988 if (options->verify_host_key_dns == -1)
989 options->verify_host_key_dns = 0;
Damien Miller509b0102003-12-17 16:33:10 +1100990 if (options->server_alive_interval == -1)
991 options->server_alive_interval = 0;
992 if (options->server_alive_count_max == -1)
993 options->server_alive_count_max = 3;
Damien Miller95def091999-11-25 00:26:21 +1100994 /* options->proxy_command should not be set by default */
995 /* options->user will be set in the main program if appropriate */
996 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000997 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000998 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000999}