blob: 7dfd040c81ad5966913583a7dae3513da42b1bef [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 Lindstrom226cfa02001-01-22 05:34:40 +000013RCSID("$OpenBSD: servconf.c,v 1.62 2001/01/21 19:05:55 markus Exp $");
14
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;
Damien Miller95def091999-11-25 00:26:21 +110080 options->skey_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;
Damien Miller95def091999-11-25 00:26:21 +1100174 if (options->skey_authentication == -1)
175 options->skey_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
Damien Miller95def091999-11-25 00:26:21 +1100204 sSkeyAuthentication,
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 },
Damien Miller95def091999-11-25 00:26:21 +1100246 { "skeyauthentication", sSkeyAuthentication },
Damien Miller95def091999-11-25 00:26:21 +1100247 { "checkmail", sCheckMail },
248 { "listenaddress", sListenAddress },
249 { "printmotd", sPrintMotd },
250 { "ignorerhosts", sIgnoreRhosts },
251 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
252 { "x11forwarding", sX11Forwarding },
253 { "x11displayoffset", sX11DisplayOffset },
Damien Millerd3a18572000-06-07 19:55:44 +1000254 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100255 { "strictmodes", sStrictModes },
256 { "permitemptypasswords", sEmptyPasswd },
257 { "uselogin", sUseLogin },
258 { "randomseed", sRandomSeedFile },
259 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100260 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100261 { "allowusers", sAllowUsers },
262 { "denyusers", sDenyUsers },
263 { "allowgroups", sAllowGroups },
264 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000265 { "ciphers", sCiphers },
266 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000267 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000268 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000269 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000270 { "banner", sBanner },
Damien Miller95def091999-11-25 00:26:21 +1100271 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000272};
273
Damien Miller5428f641999-11-25 11:54:57 +1100274/*
275 * Returns the number of the token pointed to by cp of length len. Never
276 * returns if the token is not known.
277 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000278
Damien Miller4af51302000-04-16 11:18:38 +1000279static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100280parse_token(const char *cp, const char *filename,
281 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000282{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000283 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000284
Damien Miller95def091999-11-25 00:26:21 +1100285 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100286 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100287 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000288
Damien Miller95def091999-11-25 00:26:21 +1100289 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
290 filename, linenum, cp);
291 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000292}
293
Damien Miller34132e52000-01-14 15:45:46 +1100294/*
295 * add listen address
296 */
Damien Miller4af51302000-04-16 11:18:38 +1000297void
Damien Miller34132e52000-01-14 15:45:46 +1100298add_listen_addr(ServerOptions *options, char *addr)
299{
Damien Miller34132e52000-01-14 15:45:46 +1100300 struct addrinfo hints, *ai, *aitop;
301 char strport[NI_MAXSERV];
302 int gaierr;
303 int i;
304
305 if (options->num_ports == 0)
306 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
307 for (i = 0; i < options->num_ports; i++) {
308 memset(&hints, 0, sizeof(hints));
309 hints.ai_family = IPv4or6;
310 hints.ai_socktype = SOCK_STREAM;
311 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
312 snprintf(strport, sizeof strport, "%d", options->ports[i]);
313 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
314 fatal("bad addr or host: %s (%s)\n",
315 addr ? addr : "<NULL>",
316 gai_strerror(gaierr));
317 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
318 ;
319 ai->ai_next = options->listen_addrs;
320 options->listen_addrs = aitop;
321 }
322}
323
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000324/* Reads the server configuration file. */
325
Damien Miller4af51302000-04-16 11:18:38 +1000326void
Damien Miller95def091999-11-25 00:26:21 +1100327read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000328{
Damien Miller95def091999-11-25 00:26:21 +1100329 FILE *f;
330 char line[1024];
Damien Miller37023962000-07-11 17:31:38 +1000331 char *cp, **charptr, *arg;
Damien Miller95def091999-11-25 00:26:21 +1100332 int linenum, *intptr, value;
333 int bad_options = 0;
334 ServerOpCodes opcode;
Damien Millerf6d9e222000-06-18 14:50:44 +1000335 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000336
Damien Miller95def091999-11-25 00:26:21 +1100337 f = fopen(filename, "r");
338 if (!f) {
339 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000340 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100341 }
342 linenum = 0;
343 while (fgets(line, sizeof(line), f)) {
344 linenum++;
Damien Millerbe484b52000-07-15 14:14:16 +1000345 cp = line;
346 arg = strdelim(&cp);
347 /* Ignore leading whitespace */
348 if (*arg == '\0')
349 arg = strdelim(&cp);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000350 if (!arg || !*arg || *arg == '#')
Damien Miller95def091999-11-25 00:26:21 +1100351 continue;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100352 intptr = NULL;
353 charptr = NULL;
Damien Miller37023962000-07-11 17:31:38 +1000354 opcode = parse_token(arg, filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100355 switch (opcode) {
356 case sBadOption:
357 bad_options++;
358 continue;
359 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100360 /* ignore ports from configfile if cmdline specifies ports */
361 if (options->ports_from_cmdline)
362 continue;
363 if (options->listen_addrs != NULL)
364 fatal("%s line %d: ports must be specified before "
365 "ListenAdress.\n", filename, linenum);
366 if (options->num_ports >= MAX_PORTS)
367 fatal("%s line %d: too many ports.\n",
Damien Miller4af51302000-04-16 11:18:38 +1000368 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000369 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000370 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100371 fatal("%s line %d: missing port number.\n",
372 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000373 options->ports[options->num_ports++] = atoi(arg);
Damien Miller34132e52000-01-14 15:45:46 +1100374 break;
375
376 case sServerKeyBits:
377 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100378parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000379 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000380 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100381 fprintf(stderr, "%s line %d: missing integer value.\n",
382 filename, linenum);
383 exit(1);
384 }
Damien Miller37023962000-07-11 17:31:38 +1000385 value = atoi(arg);
Damien Miller95def091999-11-25 00:26:21 +1100386 if (*intptr == -1)
387 *intptr = value;
388 break;
Damien Miller32265091999-11-12 11:33:04 +1100389
Damien Miller95def091999-11-25 00:26:21 +1100390 case sLoginGraceTime:
391 intptr = &options->login_grace_time;
392 goto parse_int;
393
394 case sKeyRegenerationTime:
395 intptr = &options->key_regeneration_time;
396 goto parse_int;
397
398 case sListenAddress:
Damien Millerbe484b52000-07-15 14:14:16 +1000399 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000400 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100401 fatal("%s line %d: missing inet addr.\n",
402 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000403 add_listen_addr(options, arg);
Damien Miller95def091999-11-25 00:26:21 +1100404 break;
405
406 case sHostKeyFile:
Damien Miller0bc1bd82000-11-13 22:57:25 +1100407 intptr = &options->num_host_key_files;
408 if (*intptr >= MAX_HOSTKEYS) {
409 fprintf(stderr, "%s line %d: to many host keys specified (max %d).\n",
410 filename, linenum, MAX_HOSTKEYS);
411 exit(1);
412 }
413 charptr = &options->host_key_files[*intptr];
Damien Millerd3a18572000-06-07 19:55:44 +1000414parse_filename:
Damien Millerbe484b52000-07-15 14:14:16 +1000415 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000416 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100417 fprintf(stderr, "%s line %d: missing file name.\n",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000418 filename, linenum);
419 exit(1);
420 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100421 if (*charptr == NULL) {
Damien Miller37023962000-07-11 17:31:38 +1000422 *charptr = tilde_expand_filename(arg, getuid());
Damien Miller0bc1bd82000-11-13 22:57:25 +1100423 /* increase optional counter */
424 if (intptr != NULL)
425 *intptr = *intptr + 1;
426 }
Damien Miller6f83b8e2000-05-02 09:23:45 +1000427 break;
428
429 case sPidFile:
430 charptr = &options->pid_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000431 goto parse_filename;
Damien Miller95def091999-11-25 00:26:21 +1100432
433 case sRandomSeedFile:
434 fprintf(stderr, "%s line %d: \"randomseed\" option is obsolete.\n",
435 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000436 arg = strdelim(&cp);
Damien Miller95def091999-11-25 00:26:21 +1100437 break;
438
439 case sPermitRootLogin:
440 intptr = &options->permit_root_login;
Damien Millerbe484b52000-07-15 14:14:16 +1000441 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000442 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100443 fprintf(stderr, "%s line %d: missing yes/without-password/no argument.\n",
444 filename, linenum);
445 exit(1);
446 }
Damien Miller37023962000-07-11 17:31:38 +1000447 if (strcmp(arg, "without-password") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100448 value = 2;
Damien Miller37023962000-07-11 17:31:38 +1000449 else if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100450 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000451 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100452 value = 0;
453 else {
454 fprintf(stderr, "%s line %d: Bad yes/without-password/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000455 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100456 exit(1);
457 }
458 if (*intptr == -1)
459 *intptr = value;
460 break;
461
462 case sIgnoreRhosts:
463 intptr = &options->ignore_rhosts;
464parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000465 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000466 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100467 fprintf(stderr, "%s line %d: missing yes/no argument.\n",
468 filename, linenum);
469 exit(1);
470 }
Damien Miller37023962000-07-11 17:31:38 +1000471 if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100472 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000473 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100474 value = 0;
475 else {
476 fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000477 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100478 exit(1);
479 }
480 if (*intptr == -1)
481 *intptr = value;
482 break;
483
484 case sIgnoreUserKnownHosts:
485 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100486 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100487
488 case sRhostsAuthentication:
489 intptr = &options->rhosts_authentication;
490 goto parse_flag;
491
492 case sRhostsRSAAuthentication:
493 intptr = &options->rhosts_rsa_authentication;
494 goto parse_flag;
495
496 case sRSAAuthentication:
497 intptr = &options->rsa_authentication;
498 goto parse_flag;
499
Damien Miller0bc1bd82000-11-13 22:57:25 +1100500 case sPubkeyAuthentication:
501 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000502 goto parse_flag;
503
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000504#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100505 case sKerberosAuthentication:
506 intptr = &options->kerberos_authentication;
507 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000508
Damien Miller95def091999-11-25 00:26:21 +1100509 case sKerberosOrLocalPasswd:
510 intptr = &options->kerberos_or_local_passwd;
511 goto parse_flag;
512
513 case sKerberosTicketCleanup:
514 intptr = &options->kerberos_ticket_cleanup;
515 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000516#endif
Damien Miller95def091999-11-25 00:26:21 +1100517
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000518#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100519 case sKerberosTgtPassing:
520 intptr = &options->kerberos_tgt_passing;
521 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000522
Damien Miller95def091999-11-25 00:26:21 +1100523 case sAFSTokenPassing:
524 intptr = &options->afs_token_passing;
525 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000526#endif
527
Damien Miller95def091999-11-25 00:26:21 +1100528 case sPasswordAuthentication:
529 intptr = &options->password_authentication;
530 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000531
Damien Miller874d77b2000-10-14 16:23:11 +1100532 case sKbdInteractiveAuthentication:
533 intptr = &options->kbd_interactive_authentication;
534 goto parse_flag;
535
Damien Miller95def091999-11-25 00:26:21 +1100536 case sCheckMail:
537 intptr = &options->check_mail;
538 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000539
Damien Miller95def091999-11-25 00:26:21 +1100540 case sSkeyAuthentication:
541 intptr = &options->skey_authentication;
542 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000543
Damien Miller95def091999-11-25 00:26:21 +1100544 case sPrintMotd:
545 intptr = &options->print_motd;
546 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000547
Damien Miller95def091999-11-25 00:26:21 +1100548 case sX11Forwarding:
549 intptr = &options->x11_forwarding;
550 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000551
Damien Miller95def091999-11-25 00:26:21 +1100552 case sX11DisplayOffset:
553 intptr = &options->x11_display_offset;
554 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000555
Damien Millerd3a18572000-06-07 19:55:44 +1000556 case sXAuthLocation:
557 charptr = &options->xauth_location;
558 goto parse_filename;
559
Damien Miller95def091999-11-25 00:26:21 +1100560 case sStrictModes:
561 intptr = &options->strict_modes;
562 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000563
Damien Miller95def091999-11-25 00:26:21 +1100564 case sKeepAlives:
565 intptr = &options->keepalives;
566 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000567
Damien Miller95def091999-11-25 00:26:21 +1100568 case sEmptyPasswd:
569 intptr = &options->permit_empty_passwd;
570 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000571
Damien Miller95def091999-11-25 00:26:21 +1100572 case sUseLogin:
573 intptr = &options->use_login;
574 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100575
Damien Millere247cc42000-05-07 12:03:14 +1000576 case sGatewayPorts:
577 intptr = &options->gateway_ports;
578 goto parse_flag;
579
Damien Miller95def091999-11-25 00:26:21 +1100580 case sLogFacility:
581 intptr = (int *) &options->log_facility;
Damien Millerbe484b52000-07-15 14:14:16 +1000582 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000583 value = log_facility_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100584 if (value == (SyslogFacility) - 1)
585 fatal("%.200s line %d: unsupported log facility '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000586 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100587 if (*intptr == -1)
588 *intptr = (SyslogFacility) value;
589 break;
590
591 case sLogLevel:
592 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000593 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000594 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100595 if (value == (LogLevel) - 1)
596 fatal("%.200s line %d: unsupported log level '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000597 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100598 if (*intptr == -1)
599 *intptr = (LogLevel) value;
600 break;
601
Damien Miller50a41ed2000-10-16 12:14:42 +1100602 case sAllowTcpForwarding:
603 intptr = &options->allow_tcp_forwarding;
604 goto parse_flag;
605
Damien Miller95def091999-11-25 00:26:21 +1100606 case sAllowUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000607 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000608 if (options->num_allow_users >= MAX_ALLOW_USERS)
609 fatal("%s line %d: too many allow users.\n",
610 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000611 options->allow_users[options->num_allow_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100612 }
613 break;
614
615 case sDenyUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000616 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000617 if (options->num_deny_users >= MAX_DENY_USERS)
618 fatal( "%s line %d: too many deny users.\n",
619 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000620 options->deny_users[options->num_deny_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100621 }
622 break;
623
624 case sAllowGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000625 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000626 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
627 fatal("%s line %d: too many allow groups.\n",
628 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000629 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100630 }
631 break;
632
633 case sDenyGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000634 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000635 if (options->num_deny_groups >= MAX_DENY_GROUPS)
636 fatal("%s line %d: too many deny groups.\n",
637 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000638 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100639 }
640 break;
641
Damien Miller78928792000-04-12 20:17:38 +1000642 case sCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000643 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000644 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000645 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000646 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000647 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000648 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000649 if (options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000650 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000651 break;
652
653 case sProtocol:
654 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000655 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000656 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000657 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000658 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000659 if (value == SSH_PROTO_UNKNOWN)
660 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000661 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000662 if (*intptr == SSH_PROTO_UNKNOWN)
663 *intptr = value;
664 break;
665
Damien Millerf6d9e222000-06-18 14:50:44 +1000666 case sSubsystem:
667 if(options->num_subsystems >= MAX_SUBSYSTEMS) {
668 fatal("%s line %d: too many subsystems defined.",
669 filename, linenum);
670 }
Damien Millerbe484b52000-07-15 14:14:16 +1000671 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000672 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000673 fatal("%s line %d: Missing subsystem name.",
674 filename, linenum);
675 for (i = 0; i < options->num_subsystems; i++)
Damien Miller37023962000-07-11 17:31:38 +1000676 if(strcmp(arg, options->subsystem_name[i]) == 0)
Damien Millerf6d9e222000-06-18 14:50:44 +1000677 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller37023962000-07-11 17:31:38 +1000678 filename, linenum, arg);
679 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000680 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000681 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000682 fatal("%s line %d: Missing subsystem command.",
683 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000684 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Millerf6d9e222000-06-18 14:50:44 +1000685 options->num_subsystems++;
686 break;
687
Damien Miller37023962000-07-11 17:31:38 +1000688 case sMaxStartups:
Damien Miller942da032000-08-18 13:59:06 +1000689 arg = strdelim(&cp);
690 if (!arg || *arg == '\0')
691 fatal("%s line %d: Missing MaxStartups spec.",
692 filename, linenum);
693 if (sscanf(arg, "%d:%d:%d",
694 &options->max_startups_begin,
695 &options->max_startups_rate,
696 &options->max_startups) == 3) {
697 if (options->max_startups_begin >
698 options->max_startups ||
699 options->max_startups_rate > 100 ||
700 options->max_startups_rate < 1)
701 fatal("%s line %d: Illegal MaxStartups spec.",
702 filename, linenum);
703 break;
704 }
Damien Miller37023962000-07-11 17:31:38 +1000705 intptr = &options->max_startups;
706 goto parse_int;
707
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000708 case sBanner:
709 charptr = &options->banner;
710 goto parse_filename;
711
Damien Miller95def091999-11-25 00:26:21 +1100712 default:
713 fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
Damien Miller37023962000-07-11 17:31:38 +1000714 filename, linenum, arg, opcode);
Damien Miller95def091999-11-25 00:26:21 +1100715 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000716 }
Damien Millerbe484b52000-07-15 14:14:16 +1000717 if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000718 fprintf(stderr,
719 "%s line %d: garbage at end of line; \"%.200s\".\n",
720 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100721 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000722 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000723 }
Damien Miller95def091999-11-25 00:26:21 +1100724 fclose(f);
725 if (bad_options > 0) {
726 fprintf(stderr, "%s: terminating, %d bad configuration options\n",
727 filename, bad_options);
728 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000729 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000730}