blob: 2738c62e91a3977df544b9d90151a8ede3e54c56 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
3 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10004 *
Damien Millere4340be2000-09-16 13:29:08 +11005 * As far as I am concerned, the code I have written for this software
6 * can be used freely for any purpose. Any derived versions of this
7 * software must be clearly marked as such, and if the derived work is
8 * incompatible with the protocol description in the RFC file, it must be
9 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110010 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100011
12#include "includes.h"
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000013RCSID("$OpenBSD: servconf.c,v 1.63 2001/01/22 23:06:39 markus Exp $");
Ben Lindstrom226cfa02001-01-22 05:34:40 +000014
15#ifdef KRB4
16#include <krb.h>
17#endif
18#ifdef AFS
19#include <kafs.h>
20#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100021
22#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000023#include "log.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100024#include "servconf.h"
25#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100026#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000027#include "pathnames.h"
28#include "tildexpand.h"
29#include "misc.h"
30#include "cipher.h"
31
Damien Millerd4a8b7e1999-10-27 13:42:43 +100032
Damien Miller34132e52000-01-14 15:45:46 +110033/* add listen address */
34void add_listen_addr(ServerOptions *options, char *addr);
35
Ben Lindstrom226cfa02001-01-22 05:34:40 +000036/* AF_UNSPEC or AF_INET or AF_INET6 */
37extern int IPv4or6;
38
Damien Millerd4a8b7e1999-10-27 13:42:43 +100039/* Initializes the server options to their default values. */
40
Damien Miller4af51302000-04-16 11:18:38 +100041void
Damien Miller95def091999-11-25 00:26:21 +110042initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100043{
Damien Miller95def091999-11-25 00:26:21 +110044 memset(options, 0, sizeof(*options));
Damien Miller34132e52000-01-14 15:45:46 +110045 options->num_ports = 0;
46 options->ports_from_cmdline = 0;
47 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110048 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100049 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110050 options->server_key_bits = -1;
51 options->login_grace_time = -1;
52 options->key_regeneration_time = -1;
53 options->permit_root_login = -1;
54 options->ignore_rhosts = -1;
55 options->ignore_user_known_hosts = -1;
56 options->print_motd = -1;
57 options->check_mail = -1;
58 options->x11_forwarding = -1;
59 options->x11_display_offset = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100060 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110061 options->strict_modes = -1;
62 options->keepalives = -1;
63 options->log_facility = (SyslogFacility) - 1;
64 options->log_level = (LogLevel) - 1;
65 options->rhosts_authentication = -1;
66 options->rhosts_rsa_authentication = -1;
67 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110068 options->pubkey_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100069#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +110070 options->kerberos_authentication = -1;
71 options->kerberos_or_local_passwd = -1;
72 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100073#endif
74#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +110075 options->kerberos_tgt_passing = -1;
76 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100077#endif
Damien Miller95def091999-11-25 00:26:21 +110078 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110079 options->kbd_interactive_authentication = -1;
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000080 options->challenge_reponse_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110081 options->permit_empty_passwd = -1;
82 options->use_login = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110083 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110084 options->num_allow_users = 0;
85 options->num_deny_users = 0;
86 options->num_allow_groups = 0;
87 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100088 options->ciphers = NULL;
89 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +100090 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +100091 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +100092 options->max_startups_begin = -1;
93 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +100094 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +000095 options->banner = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100096}
97
Damien Miller4af51302000-04-16 11:18:38 +100098void
Damien Miller95def091999-11-25 00:26:21 +110099fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000100{
Damien Miller0bc1bd82000-11-13 22:57:25 +1100101 if (options->protocol == SSH_PROTO_UNKNOWN)
102 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
103 if (options->num_host_key_files == 0) {
104 /* fill default hostkeys for protocols */
105 if (options->protocol & SSH_PROTO_1)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000106 options->host_key_files[options->num_host_key_files++] = _PATH_HOST_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100107 if (options->protocol & SSH_PROTO_2)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000108 options->host_key_files[options->num_host_key_files++] = _PATH_HOST_DSA_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100109 }
Damien Miller34132e52000-01-14 15:45:46 +1100110 if (options->num_ports == 0)
111 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
112 if (options->listen_addrs == NULL)
113 add_listen_addr(options, NULL);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000114 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000115 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100116 if (options->server_key_bits == -1)
117 options->server_key_bits = 768;
118 if (options->login_grace_time == -1)
119 options->login_grace_time = 600;
120 if (options->key_regeneration_time == -1)
121 options->key_regeneration_time = 3600;
122 if (options->permit_root_login == -1)
123 options->permit_root_login = 1; /* yes */
124 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100125 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100126 if (options->ignore_user_known_hosts == -1)
127 options->ignore_user_known_hosts = 0;
128 if (options->check_mail == -1)
129 options->check_mail = 0;
130 if (options->print_motd == -1)
131 options->print_motd = 1;
132 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100133 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100134 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100135 options->x11_display_offset = 10;
Damien Millerd3a18572000-06-07 19:55:44 +1000136#ifdef XAUTH_PATH
137 if (options->xauth_location == NULL)
138 options->xauth_location = XAUTH_PATH;
139#endif /* XAUTH_PATH */
Damien Miller95def091999-11-25 00:26:21 +1100140 if (options->strict_modes == -1)
141 options->strict_modes = 1;
142 if (options->keepalives == -1)
143 options->keepalives = 1;
144 if (options->log_facility == (SyslogFacility) (-1))
145 options->log_facility = SYSLOG_FACILITY_AUTH;
146 if (options->log_level == (LogLevel) (-1))
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000147 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100148 if (options->rhosts_authentication == -1)
149 options->rhosts_authentication = 0;
150 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100151 options->rhosts_rsa_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100152 if (options->rsa_authentication == -1)
153 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100154 if (options->pubkey_authentication == -1)
155 options->pubkey_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000156#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100157 if (options->kerberos_authentication == -1)
158 options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
159 if (options->kerberos_or_local_passwd == -1)
160 options->kerberos_or_local_passwd = 1;
161 if (options->kerberos_ticket_cleanup == -1)
162 options->kerberos_ticket_cleanup = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000163#endif /* KRB4 */
164#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100165 if (options->kerberos_tgt_passing == -1)
166 options->kerberos_tgt_passing = 0;
167 if (options->afs_token_passing == -1)
168 options->afs_token_passing = k_hasafs();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000169#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100170 if (options->password_authentication == -1)
171 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100172 if (options->kbd_interactive_authentication == -1)
173 options->kbd_interactive_authentication = 0;
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000174 if (options->challenge_reponse_authentication == -1)
175 options->challenge_reponse_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100176 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100177 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100178 if (options->use_login == -1)
179 options->use_login = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100180 if (options->allow_tcp_forwarding == -1)
181 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000182 if (options->gateway_ports == -1)
183 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000184 if (options->max_startups == -1)
185 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000186 if (options->max_startups_rate == -1)
187 options->max_startups_rate = 100; /* 100% */
188 if (options->max_startups_begin == -1)
189 options->max_startups_begin = options->max_startups;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000190}
191
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000192/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100193typedef enum {
194 sBadOption, /* == unknown option */
195 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
196 sPermitRootLogin, sLogFacility, sLogLevel,
197 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000198#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100199 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000200#endif
201#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100202 sKerberosTgtPassing, sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000203#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000204 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100205 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Damien Miller95def091999-11-25 00:26:21 +1100206 sPrintMotd, sIgnoreRhosts, sX11Forwarding, sX11DisplayOffset,
207 sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail,
Damien Miller50a41ed2000-10-16 12:14:42 +1100208 sUseLogin, sAllowTcpForwarding,
209 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100210 sIgnoreUserKnownHosts, sCiphers, sProtocol, sPidFile,
211 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000212 sBanner
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000213} ServerOpCodes;
214
215/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100216static struct {
217 const char *name;
218 ServerOpCodes opcode;
219} keywords[] = {
220 { "port", sPort },
221 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100222 { "hostdsakey", sHostKeyFile }, /* alias */
Damien Miller6f83b8e2000-05-02 09:23:45 +1000223 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100224 { "serverkeybits", sServerKeyBits },
225 { "logingracetime", sLoginGraceTime },
226 { "keyregenerationinterval", sKeyRegenerationTime },
227 { "permitrootlogin", sPermitRootLogin },
228 { "syslogfacility", sLogFacility },
229 { "loglevel", sLogLevel },
230 { "rhostsauthentication", sRhostsAuthentication },
231 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
232 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100233 { "pubkeyauthentication", sPubkeyAuthentication },
234 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000235#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100236 { "kerberosauthentication", sKerberosAuthentication },
237 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
238 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000239#endif
240#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100241 { "kerberostgtpassing", sKerberosTgtPassing },
242 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000243#endif
Damien Miller95def091999-11-25 00:26:21 +1100244 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100245 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000246 { "challengeresponseauthentication", sChallengeResponseAuthentication },
247 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100248 { "checkmail", sCheckMail },
249 { "listenaddress", sListenAddress },
250 { "printmotd", sPrintMotd },
251 { "ignorerhosts", sIgnoreRhosts },
252 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
253 { "x11forwarding", sX11Forwarding },
254 { "x11displayoffset", sX11DisplayOffset },
Damien Millerd3a18572000-06-07 19:55:44 +1000255 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100256 { "strictmodes", sStrictModes },
257 { "permitemptypasswords", sEmptyPasswd },
258 { "uselogin", sUseLogin },
259 { "randomseed", sRandomSeedFile },
260 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100261 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100262 { "allowusers", sAllowUsers },
263 { "denyusers", sDenyUsers },
264 { "allowgroups", sAllowGroups },
265 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000266 { "ciphers", sCiphers },
267 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000268 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000269 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000270 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000271 { "banner", sBanner },
Damien Miller95def091999-11-25 00:26:21 +1100272 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000273};
274
Damien Miller5428f641999-11-25 11:54:57 +1100275/*
276 * Returns the number of the token pointed to by cp of length len. Never
277 * returns if the token is not known.
278 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000279
Damien Miller4af51302000-04-16 11:18:38 +1000280static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100281parse_token(const char *cp, const char *filename,
282 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000283{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000284 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000285
Damien Miller95def091999-11-25 00:26:21 +1100286 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100287 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100288 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000289
Damien Miller95def091999-11-25 00:26:21 +1100290 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
291 filename, linenum, cp);
292 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000293}
294
Damien Miller34132e52000-01-14 15:45:46 +1100295/*
296 * add listen address
297 */
Damien Miller4af51302000-04-16 11:18:38 +1000298void
Damien Miller34132e52000-01-14 15:45:46 +1100299add_listen_addr(ServerOptions *options, char *addr)
300{
Damien Miller34132e52000-01-14 15:45:46 +1100301 struct addrinfo hints, *ai, *aitop;
302 char strport[NI_MAXSERV];
303 int gaierr;
304 int i;
305
306 if (options->num_ports == 0)
307 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
308 for (i = 0; i < options->num_ports; i++) {
309 memset(&hints, 0, sizeof(hints));
310 hints.ai_family = IPv4or6;
311 hints.ai_socktype = SOCK_STREAM;
312 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
313 snprintf(strport, sizeof strport, "%d", options->ports[i]);
314 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
315 fatal("bad addr or host: %s (%s)\n",
316 addr ? addr : "<NULL>",
317 gai_strerror(gaierr));
318 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
319 ;
320 ai->ai_next = options->listen_addrs;
321 options->listen_addrs = aitop;
322 }
323}
324
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000325/* Reads the server configuration file. */
326
Damien Miller4af51302000-04-16 11:18:38 +1000327void
Damien Miller95def091999-11-25 00:26:21 +1100328read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000329{
Damien Miller95def091999-11-25 00:26:21 +1100330 FILE *f;
331 char line[1024];
Damien Miller37023962000-07-11 17:31:38 +1000332 char *cp, **charptr, *arg;
Damien Miller95def091999-11-25 00:26:21 +1100333 int linenum, *intptr, value;
334 int bad_options = 0;
335 ServerOpCodes opcode;
Damien Millerf6d9e222000-06-18 14:50:44 +1000336 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000337
Damien Miller95def091999-11-25 00:26:21 +1100338 f = fopen(filename, "r");
339 if (!f) {
340 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000341 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100342 }
343 linenum = 0;
344 while (fgets(line, sizeof(line), f)) {
345 linenum++;
Damien Millerbe484b52000-07-15 14:14:16 +1000346 cp = line;
347 arg = strdelim(&cp);
348 /* Ignore leading whitespace */
349 if (*arg == '\0')
350 arg = strdelim(&cp);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000351 if (!arg || !*arg || *arg == '#')
Damien Miller95def091999-11-25 00:26:21 +1100352 continue;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100353 intptr = NULL;
354 charptr = NULL;
Damien Miller37023962000-07-11 17:31:38 +1000355 opcode = parse_token(arg, filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100356 switch (opcode) {
357 case sBadOption:
358 bad_options++;
359 continue;
360 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100361 /* ignore ports from configfile if cmdline specifies ports */
362 if (options->ports_from_cmdline)
363 continue;
364 if (options->listen_addrs != NULL)
365 fatal("%s line %d: ports must be specified before "
366 "ListenAdress.\n", filename, linenum);
367 if (options->num_ports >= MAX_PORTS)
368 fatal("%s line %d: too many ports.\n",
Damien Miller4af51302000-04-16 11:18:38 +1000369 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000370 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000371 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100372 fatal("%s line %d: missing port number.\n",
373 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000374 options->ports[options->num_ports++] = atoi(arg);
Damien Miller34132e52000-01-14 15:45:46 +1100375 break;
376
377 case sServerKeyBits:
378 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100379parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000380 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000381 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100382 fprintf(stderr, "%s line %d: missing integer value.\n",
383 filename, linenum);
384 exit(1);
385 }
Damien Miller37023962000-07-11 17:31:38 +1000386 value = atoi(arg);
Damien Miller95def091999-11-25 00:26:21 +1100387 if (*intptr == -1)
388 *intptr = value;
389 break;
Damien Miller32265091999-11-12 11:33:04 +1100390
Damien Miller95def091999-11-25 00:26:21 +1100391 case sLoginGraceTime:
392 intptr = &options->login_grace_time;
393 goto parse_int;
394
395 case sKeyRegenerationTime:
396 intptr = &options->key_regeneration_time;
397 goto parse_int;
398
399 case sListenAddress:
Damien Millerbe484b52000-07-15 14:14:16 +1000400 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000401 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100402 fatal("%s line %d: missing inet addr.\n",
403 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000404 add_listen_addr(options, arg);
Damien Miller95def091999-11-25 00:26:21 +1100405 break;
406
407 case sHostKeyFile:
Damien Miller0bc1bd82000-11-13 22:57:25 +1100408 intptr = &options->num_host_key_files;
409 if (*intptr >= MAX_HOSTKEYS) {
410 fprintf(stderr, "%s line %d: to many host keys specified (max %d).\n",
411 filename, linenum, MAX_HOSTKEYS);
412 exit(1);
413 }
414 charptr = &options->host_key_files[*intptr];
Damien Millerd3a18572000-06-07 19:55:44 +1000415parse_filename:
Damien Millerbe484b52000-07-15 14:14:16 +1000416 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000417 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100418 fprintf(stderr, "%s line %d: missing file name.\n",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000419 filename, linenum);
420 exit(1);
421 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100422 if (*charptr == NULL) {
Damien Miller37023962000-07-11 17:31:38 +1000423 *charptr = tilde_expand_filename(arg, getuid());
Damien Miller0bc1bd82000-11-13 22:57:25 +1100424 /* increase optional counter */
425 if (intptr != NULL)
426 *intptr = *intptr + 1;
427 }
Damien Miller6f83b8e2000-05-02 09:23:45 +1000428 break;
429
430 case sPidFile:
431 charptr = &options->pid_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000432 goto parse_filename;
Damien Miller95def091999-11-25 00:26:21 +1100433
434 case sRandomSeedFile:
435 fprintf(stderr, "%s line %d: \"randomseed\" option is obsolete.\n",
436 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000437 arg = strdelim(&cp);
Damien Miller95def091999-11-25 00:26:21 +1100438 break;
439
440 case sPermitRootLogin:
441 intptr = &options->permit_root_login;
Damien Millerbe484b52000-07-15 14:14:16 +1000442 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000443 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100444 fprintf(stderr, "%s line %d: missing yes/without-password/no argument.\n",
445 filename, linenum);
446 exit(1);
447 }
Damien Miller37023962000-07-11 17:31:38 +1000448 if (strcmp(arg, "without-password") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100449 value = 2;
Damien Miller37023962000-07-11 17:31:38 +1000450 else if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100451 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000452 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100453 value = 0;
454 else {
455 fprintf(stderr, "%s line %d: Bad yes/without-password/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000456 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100457 exit(1);
458 }
459 if (*intptr == -1)
460 *intptr = value;
461 break;
462
463 case sIgnoreRhosts:
464 intptr = &options->ignore_rhosts;
465parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000466 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000467 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100468 fprintf(stderr, "%s line %d: missing yes/no argument.\n",
469 filename, linenum);
470 exit(1);
471 }
Damien Miller37023962000-07-11 17:31:38 +1000472 if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100473 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000474 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100475 value = 0;
476 else {
477 fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000478 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100479 exit(1);
480 }
481 if (*intptr == -1)
482 *intptr = value;
483 break;
484
485 case sIgnoreUserKnownHosts:
486 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100487 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100488
489 case sRhostsAuthentication:
490 intptr = &options->rhosts_authentication;
491 goto parse_flag;
492
493 case sRhostsRSAAuthentication:
494 intptr = &options->rhosts_rsa_authentication;
495 goto parse_flag;
496
497 case sRSAAuthentication:
498 intptr = &options->rsa_authentication;
499 goto parse_flag;
500
Damien Miller0bc1bd82000-11-13 22:57:25 +1100501 case sPubkeyAuthentication:
502 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000503 goto parse_flag;
504
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000505#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100506 case sKerberosAuthentication:
507 intptr = &options->kerberos_authentication;
508 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000509
Damien Miller95def091999-11-25 00:26:21 +1100510 case sKerberosOrLocalPasswd:
511 intptr = &options->kerberos_or_local_passwd;
512 goto parse_flag;
513
514 case sKerberosTicketCleanup:
515 intptr = &options->kerberos_ticket_cleanup;
516 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000517#endif
Damien Miller95def091999-11-25 00:26:21 +1100518
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000519#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100520 case sKerberosTgtPassing:
521 intptr = &options->kerberos_tgt_passing;
522 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000523
Damien Miller95def091999-11-25 00:26:21 +1100524 case sAFSTokenPassing:
525 intptr = &options->afs_token_passing;
526 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000527#endif
528
Damien Miller95def091999-11-25 00:26:21 +1100529 case sPasswordAuthentication:
530 intptr = &options->password_authentication;
531 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000532
Damien Miller874d77b2000-10-14 16:23:11 +1100533 case sKbdInteractiveAuthentication:
534 intptr = &options->kbd_interactive_authentication;
535 goto parse_flag;
536
Damien Miller95def091999-11-25 00:26:21 +1100537 case sCheckMail:
538 intptr = &options->check_mail;
539 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000540
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000541 case sChallengeResponseAuthentication:
542 intptr = &options->challenge_reponse_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100543 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000544
Damien Miller95def091999-11-25 00:26:21 +1100545 case sPrintMotd:
546 intptr = &options->print_motd;
547 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000548
Damien Miller95def091999-11-25 00:26:21 +1100549 case sX11Forwarding:
550 intptr = &options->x11_forwarding;
551 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000552
Damien Miller95def091999-11-25 00:26:21 +1100553 case sX11DisplayOffset:
554 intptr = &options->x11_display_offset;
555 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000556
Damien Millerd3a18572000-06-07 19:55:44 +1000557 case sXAuthLocation:
558 charptr = &options->xauth_location;
559 goto parse_filename;
560
Damien Miller95def091999-11-25 00:26:21 +1100561 case sStrictModes:
562 intptr = &options->strict_modes;
563 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000564
Damien Miller95def091999-11-25 00:26:21 +1100565 case sKeepAlives:
566 intptr = &options->keepalives;
567 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000568
Damien Miller95def091999-11-25 00:26:21 +1100569 case sEmptyPasswd:
570 intptr = &options->permit_empty_passwd;
571 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000572
Damien Miller95def091999-11-25 00:26:21 +1100573 case sUseLogin:
574 intptr = &options->use_login;
575 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100576
Damien Millere247cc42000-05-07 12:03:14 +1000577 case sGatewayPorts:
578 intptr = &options->gateway_ports;
579 goto parse_flag;
580
Damien Miller95def091999-11-25 00:26:21 +1100581 case sLogFacility:
582 intptr = (int *) &options->log_facility;
Damien Millerbe484b52000-07-15 14:14:16 +1000583 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000584 value = log_facility_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100585 if (value == (SyslogFacility) - 1)
586 fatal("%.200s line %d: unsupported log facility '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000587 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100588 if (*intptr == -1)
589 *intptr = (SyslogFacility) value;
590 break;
591
592 case sLogLevel:
593 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000594 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000595 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100596 if (value == (LogLevel) - 1)
597 fatal("%.200s line %d: unsupported log level '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000598 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100599 if (*intptr == -1)
600 *intptr = (LogLevel) value;
601 break;
602
Damien Miller50a41ed2000-10-16 12:14:42 +1100603 case sAllowTcpForwarding:
604 intptr = &options->allow_tcp_forwarding;
605 goto parse_flag;
606
Damien Miller95def091999-11-25 00:26:21 +1100607 case sAllowUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000608 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000609 if (options->num_allow_users >= MAX_ALLOW_USERS)
610 fatal("%s line %d: too many allow users.\n",
611 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000612 options->allow_users[options->num_allow_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100613 }
614 break;
615
616 case sDenyUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000617 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000618 if (options->num_deny_users >= MAX_DENY_USERS)
619 fatal( "%s line %d: too many deny users.\n",
620 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000621 options->deny_users[options->num_deny_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100622 }
623 break;
624
625 case sAllowGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000626 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000627 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
628 fatal("%s line %d: too many allow groups.\n",
629 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000630 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100631 }
632 break;
633
634 case sDenyGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000635 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000636 if (options->num_deny_groups >= MAX_DENY_GROUPS)
637 fatal("%s line %d: too many deny groups.\n",
638 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000639 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100640 }
641 break;
642
Damien Miller78928792000-04-12 20:17:38 +1000643 case sCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000644 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000645 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000646 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000647 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000648 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000649 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000650 if (options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000651 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000652 break;
653
654 case sProtocol:
655 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000656 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000657 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000658 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000659 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000660 if (value == SSH_PROTO_UNKNOWN)
661 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000662 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000663 if (*intptr == SSH_PROTO_UNKNOWN)
664 *intptr = value;
665 break;
666
Damien Millerf6d9e222000-06-18 14:50:44 +1000667 case sSubsystem:
668 if(options->num_subsystems >= MAX_SUBSYSTEMS) {
669 fatal("%s line %d: too many subsystems defined.",
670 filename, linenum);
671 }
Damien Millerbe484b52000-07-15 14:14:16 +1000672 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000673 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000674 fatal("%s line %d: Missing subsystem name.",
675 filename, linenum);
676 for (i = 0; i < options->num_subsystems; i++)
Damien Miller37023962000-07-11 17:31:38 +1000677 if(strcmp(arg, options->subsystem_name[i]) == 0)
Damien Millerf6d9e222000-06-18 14:50:44 +1000678 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller37023962000-07-11 17:31:38 +1000679 filename, linenum, arg);
680 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000681 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000682 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000683 fatal("%s line %d: Missing subsystem command.",
684 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000685 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Millerf6d9e222000-06-18 14:50:44 +1000686 options->num_subsystems++;
687 break;
688
Damien Miller37023962000-07-11 17:31:38 +1000689 case sMaxStartups:
Damien Miller942da032000-08-18 13:59:06 +1000690 arg = strdelim(&cp);
691 if (!arg || *arg == '\0')
692 fatal("%s line %d: Missing MaxStartups spec.",
693 filename, linenum);
694 if (sscanf(arg, "%d:%d:%d",
695 &options->max_startups_begin,
696 &options->max_startups_rate,
697 &options->max_startups) == 3) {
698 if (options->max_startups_begin >
699 options->max_startups ||
700 options->max_startups_rate > 100 ||
701 options->max_startups_rate < 1)
702 fatal("%s line %d: Illegal MaxStartups spec.",
703 filename, linenum);
704 break;
705 }
Damien Miller37023962000-07-11 17:31:38 +1000706 intptr = &options->max_startups;
707 goto parse_int;
708
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000709 case sBanner:
710 charptr = &options->banner;
711 goto parse_filename;
712
Damien Miller95def091999-11-25 00:26:21 +1100713 default:
714 fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
Damien Miller37023962000-07-11 17:31:38 +1000715 filename, linenum, arg, opcode);
Damien Miller95def091999-11-25 00:26:21 +1100716 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000717 }
Damien Millerbe484b52000-07-15 14:14:16 +1000718 if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000719 fprintf(stderr,
720 "%s line %d: garbage at end of line; \"%.200s\".\n",
721 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100722 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000723 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000724 }
Damien Miller95def091999-11-25 00:26:21 +1100725 fclose(f);
726 if (bad_options > 0) {
727 fprintf(stderr, "%s: terminating, %d bad configuration options\n",
728 filename, bad_options);
729 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000730 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000731}