blob: e5f2620a719c30f85d83e6a4ff97eb36aad6ba5e [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11003 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11005 * Functions for reading the configuration files.
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Darren Tucker0a118da2003-10-15 15:54:32 +100015RCSID("$OpenBSD: readconf.c,v 1.123 2003/10/11 08:24:07 markus Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016
17#include "ssh.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100018#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100019#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000020#include "cipher.h"
21#include "pathnames.h"
22#include "log.h"
23#include "readconf.h"
24#include "match.h"
25#include "misc.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000026#include "kex.h"
27#include "mac.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100028
29/* Format of the configuration file:
30
31 # Configuration data is parsed as follows:
32 # 1. command line options
33 # 2. user-specific file
34 # 3. system-wide file
35 # Any configuration value is only changed the first time it is set.
36 # Thus, host-specific definitions should be at the beginning of the
37 # configuration file, and defaults at the end.
38
39 # Host-specific declarations. These may override anything above. A single
40 # host may match multiple declarations; these are processed in the order
41 # that they are given in.
42
43 Host *.ngs.fi ngs.fi
Ben Lindstrom4daea862002-06-09 20:04:02 +000044 User foo
Damien Millerd4a8b7e1999-10-27 13:42:43 +100045
46 Host fake.com
47 HostName another.host.name.real.org
48 User blaah
49 Port 34289
50 ForwardX11 no
51 ForwardAgent no
52
53 Host books.com
54 RemoteForward 9999 shadows.cs.hut.fi:9999
55 Cipher 3des
56
57 Host fascist.blob.com
58 Port 23123
59 User tylonen
Damien Millerd4a8b7e1999-10-27 13:42:43 +100060 PasswordAuthentication no
61
62 Host puukko.hut.fi
63 User t35124p
64 ProxyCommand ssh-proxy %h %p
65
66 Host *.fr
Ben Lindstrom4daea862002-06-09 20:04:02 +000067 PublicKeyAuthentication no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068
69 Host *.su
70 Cipher none
71 PasswordAuthentication no
72
73 # Defaults for various options
74 Host *
75 ForwardAgent no
Damien Miller0bc1bd82000-11-13 22:57:25 +110076 ForwardX11 no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100077 PasswordAuthentication yes
78 RSAAuthentication yes
79 RhostsRSAAuthentication yes
Damien Millerd4a8b7e1999-10-27 13:42:43 +100080 StrictHostKeyChecking yes
81 KeepAlives no
82 IdentityFile ~/.ssh/identity
83 Port 22
84 EscapeChar ~
85
86*/
87
88/* Keyword tokens. */
89
Damien Miller95def091999-11-25 00:26:21 +110090typedef enum {
91 oBadOption,
Darren 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,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000099 oCompressionLevel, oKeepAlives, 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 },
172 { "keepalive", oKeepAlives },
173 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100174 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000175 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000176 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000177 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000178 { "bindaddress", oBindAddress },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000179#ifdef SMARTCARD
Ben Lindstromae996bf2001-08-06 21:27:53 +0000180 { "smartcarddevice", oSmartcardDevice },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000181#else
182 { "smartcarddevice", oUnsupported },
183#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100184 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000185 { "enablesshkeysign", oEnableSSHKeysign },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000186#ifdef DNS
Damien Miller37876e92003-05-15 10:19:46 +1000187 { "verifyhostkeydns", oVerifyHostKeyDNS },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000188#else
189 { "verifyhostkeydns", oUnsupported },
190#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100191 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000192 { "rekeylimit", oRekeyLimit },
Damien Millerb78d5eb2003-05-16 11:39:04 +1000193 { "connecttimeout", oConnectTimeout },
Damien Miller20a8f972003-05-18 20:50:30 +1000194 { "addressfamily", oAddressFamily },
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;
313/* parse_time: */
314 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;
408 goto parse_flag;
409
Damien Miller95def091999-11-25 00:26:21 +1100410 case oStrictHostKeyChecking:
411 intptr = &options->strict_host_key_checking;
Damien Millerbe484b52000-07-15 14:14:16 +1000412 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000413 if (!arg || *arg == '\0')
Ben Lindstrom5ed8acd2001-01-29 08:00:54 +0000414 fatal("%.200s line %d: Missing yes/no/ask argument.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100415 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100416 value = 0; /* To avoid compiler warning... */
Damien Miller37023962000-07-11 17:31:38 +1000417 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100418 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000419 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100420 value = 0;
Damien Miller37023962000-07-11 17:31:38 +1000421 else if (strcmp(arg, "ask") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100422 value = 2;
423 else
424 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
425 if (*activep && *intptr == -1)
426 *intptr = value;
427 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000428
Damien Miller95def091999-11-25 00:26:21 +1100429 case oCompression:
430 intptr = &options->compression;
431 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000432
Damien Miller95def091999-11-25 00:26:21 +1100433 case oKeepAlives:
434 intptr = &options->keepalives;
435 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000436
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000437 case oNoHostAuthenticationForLocalhost:
438 intptr = &options->no_host_authentication_for_localhost;
439 goto parse_flag;
440
Damien Miller95def091999-11-25 00:26:21 +1100441 case oNumberOfPasswordPrompts:
442 intptr = &options->number_of_password_prompts;
443 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000444
Damien Miller95def091999-11-25 00:26:21 +1100445 case oCompressionLevel:
446 intptr = &options->compression_level;
447 goto parse_int;
448
Damien Millera5539d22003-04-09 20:50:06 +1000449 case oRekeyLimit:
450 intptr = &options->rekey_limit;
451 arg = strdelim(&s);
452 if (!arg || *arg == '\0')
453 fatal("%.200s line %d: Missing argument.", filename, linenum);
454 if (arg[0] < '0' || arg[0] > '9')
455 fatal("%.200s line %d: Bad number.", filename, linenum);
456 value = strtol(arg, &endofnumber, 10);
457 if (arg == endofnumber)
458 fatal("%.200s line %d: Bad number.", filename, linenum);
459 switch (toupper(*endofnumber)) {
460 case 'K':
461 value *= 1<<10;
462 break;
463 case 'M':
464 value *= 1<<20;
465 break;
466 case 'G':
467 value *= 1<<30;
468 break;
469 }
470 if (*activep && *intptr == -1)
471 *intptr = value;
472 break;
473
Damien Miller95def091999-11-25 00:26:21 +1100474 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000475 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000476 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100477 fatal("%.200s line %d: Missing argument.", filename, linenum);
478 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100479 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000480 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100481 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100482 filename, linenum, SSH_MAX_IDENTITY_FILES);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100483 charptr = &options->identity_files[*intptr];
Damien Miller37023962000-07-11 17:31:38 +1000484 *charptr = xstrdup(arg);
Damien Millereba71ba2000-04-29 23:57:08 +1000485 *intptr = *intptr + 1;
Damien Miller95def091999-11-25 00:26:21 +1100486 }
487 break;
488
Damien Millerd3a18572000-06-07 19:55:44 +1000489 case oXAuthLocation:
490 charptr=&options->xauth_location;
491 goto parse_string;
492
Damien Miller95def091999-11-25 00:26:21 +1100493 case oUser:
494 charptr = &options->user;
495parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000496 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000497 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100498 fatal("%.200s line %d: Missing argument.", filename, linenum);
499 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000500 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100501 break;
502
503 case oGlobalKnownHostsFile:
504 charptr = &options->system_hostfile;
505 goto parse_string;
506
507 case oUserKnownHostsFile:
508 charptr = &options->user_hostfile;
509 goto parse_string;
510
Damien Millereba71ba2000-04-29 23:57:08 +1000511 case oGlobalKnownHostsFile2:
512 charptr = &options->system_hostfile2;
513 goto parse_string;
514
515 case oUserKnownHostsFile2:
516 charptr = &options->user_hostfile2;
517 goto parse_string;
518
Damien Miller95def091999-11-25 00:26:21 +1100519 case oHostName:
520 charptr = &options->hostname;
521 goto parse_string;
522
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000523 case oHostKeyAlias:
524 charptr = &options->host_key_alias;
525 goto parse_string;
526
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000527 case oPreferredAuthentications:
528 charptr = &options->preferred_authentications;
529 goto parse_string;
530
Ben Lindstrome0f88042001-04-30 13:06:24 +0000531 case oBindAddress:
532 charptr = &options->bind_address;
533 goto parse_string;
534
Ben Lindstromae996bf2001-08-06 21:27:53 +0000535 case oSmartcardDevice:
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000536 charptr = &options->smartcard_device;
537 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +0000538
Damien Miller95def091999-11-25 00:26:21 +1100539 case oProxyCommand:
Darren Tuckera99c1b72003-06-28 12:40:12 +1000540 if (s == NULL)
541 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100542 charptr = &options->proxy_command;
Damien Miller61f08ac2003-02-24 11:56:27 +1100543 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +1100544 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +1100545 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +1100546 return 0;
547
548 case oPort:
549 intptr = &options->port;
550parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000551 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000552 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100553 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000554 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +1100555 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +1100556
557 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +1000558 value = strtol(arg, &endofnumber, 0);
559 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +1100560 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100561 if (*activep && *intptr == -1)
562 *intptr = value;
563 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000564
Damien Miller95def091999-11-25 00:26:21 +1100565 case oConnectionAttempts:
566 intptr = &options->connection_attempts;
567 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +1100568
Damien Miller95def091999-11-25 00:26:21 +1100569 case oCipher:
570 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +1000571 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000572 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000573 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000574 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100575 if (value == -1)
576 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100577 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100578 if (*activep && *intptr == -1)
579 *intptr = value;
580 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000581
Damien Miller78928792000-04-12 20:17:38 +1000582 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000583 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000584 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000585 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000586 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000587 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100588 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000589 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000590 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000591 break;
592
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000593 case oMacs:
594 arg = strdelim(&s);
595 if (!arg || *arg == '\0')
596 fatal("%.200s line %d: Missing argument.", filename, linenum);
597 if (!mac_valid(arg))
598 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100599 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000600 if (*activep && options->macs == NULL)
601 options->macs = xstrdup(arg);
602 break;
603
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000604 case oHostKeyAlgorithms:
605 arg = strdelim(&s);
606 if (!arg || *arg == '\0')
607 fatal("%.200s line %d: Missing argument.", filename, linenum);
608 if (!key_names_valid2(arg))
609 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100610 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000611 if (*activep && options->hostkeyalgorithms == NULL)
612 options->hostkeyalgorithms = xstrdup(arg);
613 break;
614
Damien Miller78928792000-04-12 20:17:38 +1000615 case oProtocol:
616 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000617 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000618 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000619 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000620 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000621 if (value == SSH_PROTO_UNKNOWN)
622 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100623 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000624 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
625 *intptr = value;
626 break;
627
Damien Miller95def091999-11-25 00:26:21 +1100628 case oLogLevel:
629 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000630 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000631 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100632 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000633 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100634 filename, linenum, arg ? arg : "<NONE>");
Damien Millerfcd93202002-02-05 12:26:34 +1100635 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100636 *intptr = (LogLevel) value;
637 break;
638
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000639 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +1100640 case oRemoteForward:
Damien Millerbe484b52000-07-15 14:14:16 +1000641 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000642 if (!arg || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000643 fatal("%.200s line %d: Missing port argument.",
644 filename, linenum);
645 if ((fwd_port = a2port(arg)) == 0)
646 fatal("%.200s line %d: Bad listen port.",
647 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000648 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000649 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100650 fatal("%.200s line %d: Missing second argument.",
Ben Lindstrom62c25a42001-09-12 18:01:59 +0000651 filename, linenum);
652 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
653 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
654 fatal("%.200s line %d: Bad forwarding specification.",
655 filename, linenum);
656 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
657 fatal("%.200s line %d: Bad forwarding port.",
658 filename, linenum);
659 if (*activep) {
660 if (opcode == oLocalForward)
661 add_local_forward(options, fwd_port, buf,
662 fwd_host_port);
663 else if (opcode == oRemoteForward)
664 add_remote_forward(options, fwd_port, buf,
665 fwd_host_port);
666 }
Damien Miller95def091999-11-25 00:26:21 +1100667 break;
668
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000669 case oDynamicForward:
670 arg = strdelim(&s);
671 if (!arg || *arg == '\0')
672 fatal("%.200s line %d: Missing port argument.",
673 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000674 fwd_port = a2port(arg);
675 if (fwd_port == 0)
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000676 fatal("%.200s line %d: Badly formatted port number.",
677 filename, linenum);
Ben Lindstrom525a0932001-09-12 17:35:27 +0000678 if (*activep)
Darren Tucker1c52ee32003-08-13 20:38:36 +1000679 add_local_forward(options, fwd_port, "socks", 0);
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000680 break;
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000681
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000682 case oClearAllForwardings:
683 intptr = &options->clear_forwardings;
684 goto parse_flag;
685
Damien Miller95def091999-11-25 00:26:21 +1100686 case oHost:
687 *activep = 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000688 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
Damien Miller37023962000-07-11 17:31:38 +1000689 if (match_pattern(host, arg)) {
690 debug("Applying options for %.100s", arg);
Damien Miller95def091999-11-25 00:26:21 +1100691 *activep = 1;
692 break;
693 }
Damien Millerbe484b52000-07-15 14:14:16 +1000694 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +1100695 return 0;
696
697 case oEscapeChar:
698 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +1000699 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000700 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100701 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000702 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +0000703 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
704 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +1000705 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +0000706 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +1000707 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +0000708 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +1100709 else {
710 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100711 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100712 /* NOTREACHED */
713 value = 0; /* Avoid compiler warning. */
714 }
715 if (*activep && *intptr == -1)
716 *intptr = value;
717 break;
718
Damien Miller20a8f972003-05-18 20:50:30 +1000719 case oAddressFamily:
720 arg = strdelim(&s);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000721 intptr = &options->address_family;
Damien Miller20a8f972003-05-18 20:50:30 +1000722 if (strcasecmp(arg, "inet") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000723 value = AF_INET;
Damien Miller20a8f972003-05-18 20:50:30 +1000724 else if (strcasecmp(arg, "inet6") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000725 value = AF_INET6;
Damien Miller20a8f972003-05-18 20:50:30 +1000726 else if (strcasecmp(arg, "any") == 0)
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000727 value = AF_UNSPEC;
Damien Miller20a8f972003-05-18 20:50:30 +1000728 else
729 fatal("Unsupported AddressFamily \"%s\"", arg);
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000730 if (*activep && *intptr == -1)
731 *intptr = value;
Damien Miller20a8f972003-05-18 20:50:30 +1000732 break;
733
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000734 case oEnableSSHKeysign:
735 intptr = &options->enable_ssh_keysign;
736 goto parse_flag;
737
Ben Lindstrom4daea862002-06-09 20:04:02 +0000738 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000739 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +0000740 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +0000741 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +0000742
Damien Millerf9b3feb2003-05-16 11:38:32 +1000743 case oUnsupported:
744 error("%s line %d: Unsupported option \"%s\"",
745 filename, linenum, keyword);
746 return 0;
747
Damien Miller95def091999-11-25 00:26:21 +1100748 default:
749 fatal("process_config_line: Unimplemented opcode %d", opcode);
750 }
751
752 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000753 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000754 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100755 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +1000756 }
Damien Miller95def091999-11-25 00:26:21 +1100757 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000758}
759
760
Damien Miller5428f641999-11-25 11:54:57 +1100761/*
762 * Reads the config file and modifies the options accordingly. Options
763 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000764 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +1100765 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000766
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000767int
Damien Miller95def091999-11-25 00:26:21 +1100768read_config_file(const char *filename, const char *host, Options *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000769{
Damien Miller95def091999-11-25 00:26:21 +1100770 FILE *f;
771 char line[1024];
772 int active, linenum;
773 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000774
Damien Miller95def091999-11-25 00:26:21 +1100775 /* Open the file. */
776 f = fopen(filename, "r");
777 if (!f)
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000778 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000779
Damien Miller95def091999-11-25 00:26:21 +1100780 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000781
Damien Miller5428f641999-11-25 11:54:57 +1100782 /*
783 * Mark that we are now processing the options. This flag is turned
784 * on/off by Host specifications.
785 */
Damien Miller95def091999-11-25 00:26:21 +1100786 active = 1;
787 linenum = 0;
788 while (fgets(line, sizeof(line), f)) {
789 /* Update line number counter. */
790 linenum++;
791 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
792 bad_options++;
793 }
794 fclose(f);
795 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000796 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100797 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +0000798 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000799}
800
Damien Miller5428f641999-11-25 11:54:57 +1100801/*
802 * Initializes options to special values that indicate that they have not yet
803 * been set. Read_config_file will only set options with this value. Options
804 * are processed in the following order: command line, user config file,
805 * system config file. Last, fill_default_options is called.
806 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000807
Damien Miller4af51302000-04-16 11:18:38 +1000808void
Damien Miller95def091999-11-25 00:26:21 +1100809initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000810{
Damien Miller95def091999-11-25 00:26:21 +1100811 memset(options, 'X', sizeof(*options));
812 options->forward_agent = -1;
813 options->forward_x11 = -1;
Darren Tucker0a118da2003-10-15 15:54:32 +1000814 options->forward_x11_trusted = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000815 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100816 options->gateway_ports = -1;
817 options->use_privileged_port = -1;
Damien Miller95def091999-11-25 00:26:21 +1100818 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100819 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000820 options->challenge_response_authentication = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000821 options->gss_authentication = -1;
822 options->gss_deleg_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100823 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100824 options->kbd_interactive_authentication = -1;
825 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100826 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000827 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100828 options->batch_mode = -1;
829 options->check_host_ip = -1;
830 options->strict_host_key_checking = -1;
831 options->compression = -1;
832 options->keepalives = -1;
833 options->compression_level = -1;
834 options->port = -1;
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000835 options->address_family = -1;
Damien Miller95def091999-11-25 00:26:21 +1100836 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000837 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +1100838 options->number_of_password_prompts = -1;
839 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +1000840 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000841 options->macs = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000842 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000843 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +1100844 options->num_identity_files = 0;
845 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000846 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100847 options->proxy_command = NULL;
848 options->user = NULL;
849 options->escape_char = -1;
850 options->system_hostfile = NULL;
851 options->user_hostfile = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000852 options->system_hostfile2 = NULL;
853 options->user_hostfile2 = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100854 options->num_local_forwards = 0;
855 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000856 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100857 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000858 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +0000859 options->bind_address = NULL;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +0000860 options->smartcard_device = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000861 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000862 options->no_host_authentication_for_localhost = - 1;
Damien Millera5539d22003-04-09 20:50:06 +1000863 options->rekey_limit = - 1;
Damien Miller37876e92003-05-15 10:19:46 +1000864 options->verify_host_key_dns = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000865}
866
Damien Miller5428f641999-11-25 11:54:57 +1100867/*
868 * Called after processing other sources of option data, this fills those
869 * options for which no value has been specified with their default values.
870 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000871
Damien Miller4af51302000-04-16 11:18:38 +1000872void
Damien Miller95def091999-11-25 00:26:21 +1100873fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000874{
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000875 int len;
876
Damien Miller95def091999-11-25 00:26:21 +1100877 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +1000878 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +1100879 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100880 options->forward_x11 = 0;
Darren Tucker0a118da2003-10-15 15:54:32 +1000881 if (options->forward_x11_trusted == -1)
882 options->forward_x11_trusted = 0;
Damien Millerd3a18572000-06-07 19:55:44 +1000883 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000884 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100885 if (options->gateway_ports == -1)
886 options->gateway_ports = 0;
887 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +0000888 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +1100889 if (options->rsa_authentication == -1)
890 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100891 if (options->pubkey_authentication == -1)
892 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000893 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +0000894 options->challenge_response_authentication = 1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000895 if (options->gss_authentication == -1)
Darren Tuckera044f472003-10-15 15:52:03 +1000896 options->gss_authentication = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000897 if (options->gss_deleg_creds == -1)
898 options->gss_deleg_creds = 0;
Damien Miller95def091999-11-25 00:26:21 +1100899 if (options->password_authentication == -1)
900 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100901 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000902 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100903 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +0000904 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000905 if (options->hostbased_authentication == -1)
906 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100907 if (options->batch_mode == -1)
908 options->batch_mode = 0;
909 if (options->check_host_ip == -1)
910 options->check_host_ip = 1;
911 if (options->strict_host_key_checking == -1)
912 options->strict_host_key_checking = 2; /* 2 is default */
913 if (options->compression == -1)
914 options->compression = 0;
915 if (options->keepalives == -1)
916 options->keepalives = 1;
917 if (options->compression_level == -1)
918 options->compression_level = 6;
919 if (options->port == -1)
920 options->port = 0; /* Filled in ssh_connect. */
Darren Tucker0a4f04b2003-07-03 20:37:47 +1000921 if (options->address_family == -1)
922 options->address_family = AF_UNSPEC;
Damien Miller95def091999-11-25 00:26:21 +1100923 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +0000924 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100925 if (options->number_of_password_prompts == -1)
926 options->number_of_password_prompts = 3;
927 /* Selected in ssh_login(). */
928 if (options->cipher == -1)
929 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +1000930 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000931 /* options->macs, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000932 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +1000933 if (options->protocol == SSH_PROTO_UNKNOWN)
Ben Lindstrom6b776432001-03-22 01:24:04 +0000934 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +1100935 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100936 if (options->protocol & SSH_PROTO_1) {
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000937 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100938 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000939 xmalloc(len);
940 snprintf(options->identity_files[options->num_identity_files++],
941 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100942 }
943 if (options->protocol & SSH_PROTO_2) {
Ben Lindstromb00d4fb2001-03-05 06:03:03 +0000944 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
945 options->identity_files[options->num_identity_files] =
946 xmalloc(len);
947 snprintf(options->identity_files[options->num_identity_files++],
948 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
949
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000950 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100951 options->identity_files[options->num_identity_files] =
Ben Lindstrom4f7a64a2001-02-10 22:50:09 +0000952 xmalloc(len);
953 snprintf(options->identity_files[options->num_identity_files++],
954 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100955 }
Damien Millereba71ba2000-04-29 23:57:08 +1000956 }
Damien Miller95def091999-11-25 00:26:21 +1100957 if (options->escape_char == -1)
958 options->escape_char = '~';
959 if (options->system_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000960 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
Damien Miller95def091999-11-25 00:26:21 +1100961 if (options->user_hostfile == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000962 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
Damien Millereba71ba2000-04-29 23:57:08 +1000963 if (options->system_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000964 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
Damien Millereba71ba2000-04-29 23:57:08 +1000965 if (options->user_hostfile2 == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000966 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
Damien Millerfcd93202002-02-05 12:26:34 +1100967 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000968 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000969 if (options->clear_forwardings == 1)
970 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000971 if (options->no_host_authentication_for_localhost == - 1)
972 options->no_host_authentication_for_localhost = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000973 if (options->enable_ssh_keysign == -1)
974 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +1000975 if (options->rekey_limit == -1)
976 options->rekey_limit = 0;
Damien Miller37876e92003-05-15 10:19:46 +1000977 if (options->verify_host_key_dns == -1)
978 options->verify_host_key_dns = 0;
Damien Miller95def091999-11-25 00:26:21 +1100979 /* options->proxy_command should not be set by default */
980 /* options->user will be set in the main program if appropriate */
981 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000982 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000983 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000984}