blob: 801267b4853218665028739dbd99780b7f16b483 [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 Lindstromcf0809d2001-01-19 15:44:10 +000013RCSID("$OpenBSD: servconf.c,v 1.59 2001/01/19 12:45:26 markus Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100014
15#include "ssh.h"
16#include "servconf.h"
17#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100018#include "compat.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100019
Damien Miller34132e52000-01-14 15:45:46 +110020/* add listen address */
21void add_listen_addr(ServerOptions *options, char *addr);
22
Damien Millerd4a8b7e1999-10-27 13:42:43 +100023/* Initializes the server options to their default values. */
24
Damien Miller4af51302000-04-16 11:18:38 +100025void
Damien Miller95def091999-11-25 00:26:21 +110026initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100027{
Damien Miller95def091999-11-25 00:26:21 +110028 memset(options, 0, sizeof(*options));
Damien Miller34132e52000-01-14 15:45:46 +110029 options->num_ports = 0;
30 options->ports_from_cmdline = 0;
31 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110032 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100033 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110034 options->server_key_bits = -1;
35 options->login_grace_time = -1;
36 options->key_regeneration_time = -1;
37 options->permit_root_login = -1;
38 options->ignore_rhosts = -1;
39 options->ignore_user_known_hosts = -1;
40 options->print_motd = -1;
41 options->check_mail = -1;
42 options->x11_forwarding = -1;
43 options->x11_display_offset = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100044 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110045 options->strict_modes = -1;
46 options->keepalives = -1;
47 options->log_facility = (SyslogFacility) - 1;
48 options->log_level = (LogLevel) - 1;
49 options->rhosts_authentication = -1;
50 options->rhosts_rsa_authentication = -1;
51 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110052 options->pubkey_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100053#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +110054 options->kerberos_authentication = -1;
55 options->kerberos_or_local_passwd = -1;
56 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100057#endif
58#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +110059 options->kerberos_tgt_passing = -1;
60 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100061#endif
Damien Miller95def091999-11-25 00:26:21 +110062 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110063 options->kbd_interactive_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110064 options->skey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110065 options->permit_empty_passwd = -1;
66 options->use_login = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110067 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110068 options->num_allow_users = 0;
69 options->num_deny_users = 0;
70 options->num_allow_groups = 0;
71 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100072 options->ciphers = NULL;
73 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +100074 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +100075 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +100076 options->max_startups_begin = -1;
77 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +100078 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +000079 options->banner = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100080}
81
Damien Miller4af51302000-04-16 11:18:38 +100082void
Damien Miller95def091999-11-25 00:26:21 +110083fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100084{
Damien Miller0bc1bd82000-11-13 22:57:25 +110085 if (options->protocol == SSH_PROTO_UNKNOWN)
86 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
87 if (options->num_host_key_files == 0) {
88 /* fill default hostkeys for protocols */
89 if (options->protocol & SSH_PROTO_1)
90 options->host_key_files[options->num_host_key_files++] = HOST_KEY_FILE;
91 if (options->protocol & SSH_PROTO_2)
92 options->host_key_files[options->num_host_key_files++] = HOST_DSA_KEY_FILE;
93 }
Damien Miller34132e52000-01-14 15:45:46 +110094 if (options->num_ports == 0)
95 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
96 if (options->listen_addrs == NULL)
97 add_listen_addr(options, NULL);
Damien Miller6f83b8e2000-05-02 09:23:45 +100098 if (options->pid_file == NULL)
99 options->pid_file = SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100100 if (options->server_key_bits == -1)
101 options->server_key_bits = 768;
102 if (options->login_grace_time == -1)
103 options->login_grace_time = 600;
104 if (options->key_regeneration_time == -1)
105 options->key_regeneration_time = 3600;
106 if (options->permit_root_login == -1)
107 options->permit_root_login = 1; /* yes */
108 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100109 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100110 if (options->ignore_user_known_hosts == -1)
111 options->ignore_user_known_hosts = 0;
112 if (options->check_mail == -1)
113 options->check_mail = 0;
114 if (options->print_motd == -1)
115 options->print_motd = 1;
116 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100117 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100118 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100119 options->x11_display_offset = 10;
Damien Millerd3a18572000-06-07 19:55:44 +1000120#ifdef XAUTH_PATH
121 if (options->xauth_location == NULL)
122 options->xauth_location = XAUTH_PATH;
123#endif /* XAUTH_PATH */
Damien Miller95def091999-11-25 00:26:21 +1100124 if (options->strict_modes == -1)
125 options->strict_modes = 1;
126 if (options->keepalives == -1)
127 options->keepalives = 1;
128 if (options->log_facility == (SyslogFacility) (-1))
129 options->log_facility = SYSLOG_FACILITY_AUTH;
130 if (options->log_level == (LogLevel) (-1))
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000131 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100132 if (options->rhosts_authentication == -1)
133 options->rhosts_authentication = 0;
134 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100135 options->rhosts_rsa_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100136 if (options->rsa_authentication == -1)
137 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100138 if (options->pubkey_authentication == -1)
139 options->pubkey_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000140#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100141 if (options->kerberos_authentication == -1)
142 options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
143 if (options->kerberos_or_local_passwd == -1)
144 options->kerberos_or_local_passwd = 1;
145 if (options->kerberos_ticket_cleanup == -1)
146 options->kerberos_ticket_cleanup = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000147#endif /* KRB4 */
148#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100149 if (options->kerberos_tgt_passing == -1)
150 options->kerberos_tgt_passing = 0;
151 if (options->afs_token_passing == -1)
152 options->afs_token_passing = k_hasafs();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000153#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100154 if (options->password_authentication == -1)
155 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100156 if (options->kbd_interactive_authentication == -1)
157 options->kbd_interactive_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100158 if (options->skey_authentication == -1)
159 options->skey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100160 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100161 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100162 if (options->use_login == -1)
163 options->use_login = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100164 if (options->allow_tcp_forwarding == -1)
165 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000166 if (options->gateway_ports == -1)
167 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000168 if (options->max_startups == -1)
169 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000170 if (options->max_startups_rate == -1)
171 options->max_startups_rate = 100; /* 100% */
172 if (options->max_startups_begin == -1)
173 options->max_startups_begin = options->max_startups;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000174}
175
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000176/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100177typedef enum {
178 sBadOption, /* == unknown option */
179 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
180 sPermitRootLogin, sLogFacility, sLogLevel,
181 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000182#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100183 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000184#endif
185#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100186 sKerberosTgtPassing, sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000187#endif
Damien Miller95def091999-11-25 00:26:21 +1100188 sSkeyAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100189 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Damien Miller95def091999-11-25 00:26:21 +1100190 sPrintMotd, sIgnoreRhosts, sX11Forwarding, sX11DisplayOffset,
191 sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail,
Damien Miller50a41ed2000-10-16 12:14:42 +1100192 sUseLogin, sAllowTcpForwarding,
193 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100194 sIgnoreUserKnownHosts, sCiphers, sProtocol, sPidFile,
195 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000196 sBanner
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000197} ServerOpCodes;
198
199/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100200static struct {
201 const char *name;
202 ServerOpCodes opcode;
203} keywords[] = {
204 { "port", sPort },
205 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100206 { "hostdsakey", sHostKeyFile }, /* alias */
Damien Miller6f83b8e2000-05-02 09:23:45 +1000207 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100208 { "serverkeybits", sServerKeyBits },
209 { "logingracetime", sLoginGraceTime },
210 { "keyregenerationinterval", sKeyRegenerationTime },
211 { "permitrootlogin", sPermitRootLogin },
212 { "syslogfacility", sLogFacility },
213 { "loglevel", sLogLevel },
214 { "rhostsauthentication", sRhostsAuthentication },
215 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
216 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100217 { "pubkeyauthentication", sPubkeyAuthentication },
218 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000219#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100220 { "kerberosauthentication", sKerberosAuthentication },
221 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
222 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223#endif
224#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100225 { "kerberostgtpassing", sKerberosTgtPassing },
226 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000227#endif
Damien Miller95def091999-11-25 00:26:21 +1100228 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100229 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Damien Miller95def091999-11-25 00:26:21 +1100230 { "skeyauthentication", sSkeyAuthentication },
Damien Miller95def091999-11-25 00:26:21 +1100231 { "checkmail", sCheckMail },
232 { "listenaddress", sListenAddress },
233 { "printmotd", sPrintMotd },
234 { "ignorerhosts", sIgnoreRhosts },
235 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
236 { "x11forwarding", sX11Forwarding },
237 { "x11displayoffset", sX11DisplayOffset },
Damien Millerd3a18572000-06-07 19:55:44 +1000238 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100239 { "strictmodes", sStrictModes },
240 { "permitemptypasswords", sEmptyPasswd },
241 { "uselogin", sUseLogin },
242 { "randomseed", sRandomSeedFile },
243 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100244 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100245 { "allowusers", sAllowUsers },
246 { "denyusers", sDenyUsers },
247 { "allowgroups", sAllowGroups },
248 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000249 { "ciphers", sCiphers },
250 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000251 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000252 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000253 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000254 { "banner", sBanner },
Damien Miller95def091999-11-25 00:26:21 +1100255 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000256};
257
Damien Miller5428f641999-11-25 11:54:57 +1100258/*
259 * Returns the number of the token pointed to by cp of length len. Never
260 * returns if the token is not known.
261 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000262
Damien Miller4af51302000-04-16 11:18:38 +1000263static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100264parse_token(const char *cp, const char *filename,
265 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000266{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000267 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000268
Damien Miller95def091999-11-25 00:26:21 +1100269 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100270 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100271 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000272
Damien Miller95def091999-11-25 00:26:21 +1100273 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
274 filename, linenum, cp);
275 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000276}
277
Damien Miller34132e52000-01-14 15:45:46 +1100278/*
279 * add listen address
280 */
Damien Miller4af51302000-04-16 11:18:38 +1000281void
Damien Miller34132e52000-01-14 15:45:46 +1100282add_listen_addr(ServerOptions *options, char *addr)
283{
284 extern int IPv4or6;
285 struct addrinfo hints, *ai, *aitop;
286 char strport[NI_MAXSERV];
287 int gaierr;
288 int i;
289
290 if (options->num_ports == 0)
291 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
292 for (i = 0; i < options->num_ports; i++) {
293 memset(&hints, 0, sizeof(hints));
294 hints.ai_family = IPv4or6;
295 hints.ai_socktype = SOCK_STREAM;
296 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
297 snprintf(strport, sizeof strport, "%d", options->ports[i]);
298 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
299 fatal("bad addr or host: %s (%s)\n",
300 addr ? addr : "<NULL>",
301 gai_strerror(gaierr));
302 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
303 ;
304 ai->ai_next = options->listen_addrs;
305 options->listen_addrs = aitop;
306 }
307}
308
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000309/* Reads the server configuration file. */
310
Damien Miller4af51302000-04-16 11:18:38 +1000311void
Damien Miller95def091999-11-25 00:26:21 +1100312read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000313{
Damien Miller95def091999-11-25 00:26:21 +1100314 FILE *f;
315 char line[1024];
Damien Miller37023962000-07-11 17:31:38 +1000316 char *cp, **charptr, *arg;
Damien Miller95def091999-11-25 00:26:21 +1100317 int linenum, *intptr, value;
318 int bad_options = 0;
319 ServerOpCodes opcode;
Damien Millerf6d9e222000-06-18 14:50:44 +1000320 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000321
Damien Miller95def091999-11-25 00:26:21 +1100322 f = fopen(filename, "r");
323 if (!f) {
324 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000325 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100326 }
327 linenum = 0;
328 while (fgets(line, sizeof(line), f)) {
329 linenum++;
Damien Millerbe484b52000-07-15 14:14:16 +1000330 cp = line;
331 arg = strdelim(&cp);
332 /* Ignore leading whitespace */
333 if (*arg == '\0')
334 arg = strdelim(&cp);
335 if (!*arg || *arg == '#')
Damien Miller95def091999-11-25 00:26:21 +1100336 continue;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100337 intptr = NULL;
338 charptr = NULL;
Damien Miller37023962000-07-11 17:31:38 +1000339 opcode = parse_token(arg, filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100340 switch (opcode) {
341 case sBadOption:
342 bad_options++;
343 continue;
344 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100345 /* ignore ports from configfile if cmdline specifies ports */
346 if (options->ports_from_cmdline)
347 continue;
348 if (options->listen_addrs != NULL)
349 fatal("%s line %d: ports must be specified before "
350 "ListenAdress.\n", filename, linenum);
351 if (options->num_ports >= MAX_PORTS)
352 fatal("%s line %d: too many ports.\n",
Damien Miller4af51302000-04-16 11:18:38 +1000353 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000354 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000355 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100356 fatal("%s line %d: missing port number.\n",
357 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000358 options->ports[options->num_ports++] = atoi(arg);
Damien Miller34132e52000-01-14 15:45:46 +1100359 break;
360
361 case sServerKeyBits:
362 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100363parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000364 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000365 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100366 fprintf(stderr, "%s line %d: missing integer value.\n",
367 filename, linenum);
368 exit(1);
369 }
Damien Miller37023962000-07-11 17:31:38 +1000370 value = atoi(arg);
Damien Miller95def091999-11-25 00:26:21 +1100371 if (*intptr == -1)
372 *intptr = value;
373 break;
Damien Miller32265091999-11-12 11:33:04 +1100374
Damien Miller95def091999-11-25 00:26:21 +1100375 case sLoginGraceTime:
376 intptr = &options->login_grace_time;
377 goto parse_int;
378
379 case sKeyRegenerationTime:
380 intptr = &options->key_regeneration_time;
381 goto parse_int;
382
383 case sListenAddress:
Damien Millerbe484b52000-07-15 14:14:16 +1000384 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000385 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100386 fatal("%s line %d: missing inet addr.\n",
387 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000388 add_listen_addr(options, arg);
Damien Miller95def091999-11-25 00:26:21 +1100389 break;
390
391 case sHostKeyFile:
Damien Miller0bc1bd82000-11-13 22:57:25 +1100392 intptr = &options->num_host_key_files;
393 if (*intptr >= MAX_HOSTKEYS) {
394 fprintf(stderr, "%s line %d: to many host keys specified (max %d).\n",
395 filename, linenum, MAX_HOSTKEYS);
396 exit(1);
397 }
398 charptr = &options->host_key_files[*intptr];
Damien Millerd3a18572000-06-07 19:55:44 +1000399parse_filename:
Damien Millerbe484b52000-07-15 14:14:16 +1000400 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000401 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100402 fprintf(stderr, "%s line %d: missing file name.\n",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000403 filename, linenum);
404 exit(1);
405 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100406 if (*charptr == NULL) {
Damien Miller37023962000-07-11 17:31:38 +1000407 *charptr = tilde_expand_filename(arg, getuid());
Damien Miller0bc1bd82000-11-13 22:57:25 +1100408 /* increase optional counter */
409 if (intptr != NULL)
410 *intptr = *intptr + 1;
411 }
Damien Miller6f83b8e2000-05-02 09:23:45 +1000412 break;
413
414 case sPidFile:
415 charptr = &options->pid_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000416 goto parse_filename;
Damien Miller95def091999-11-25 00:26:21 +1100417
418 case sRandomSeedFile:
419 fprintf(stderr, "%s line %d: \"randomseed\" option is obsolete.\n",
420 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000421 arg = strdelim(&cp);
Damien Miller95def091999-11-25 00:26:21 +1100422 break;
423
424 case sPermitRootLogin:
425 intptr = &options->permit_root_login;
Damien Millerbe484b52000-07-15 14:14:16 +1000426 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000427 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100428 fprintf(stderr, "%s line %d: missing yes/without-password/no argument.\n",
429 filename, linenum);
430 exit(1);
431 }
Damien Miller37023962000-07-11 17:31:38 +1000432 if (strcmp(arg, "without-password") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100433 value = 2;
Damien Miller37023962000-07-11 17:31:38 +1000434 else if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100435 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000436 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100437 value = 0;
438 else {
439 fprintf(stderr, "%s line %d: Bad yes/without-password/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000440 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100441 exit(1);
442 }
443 if (*intptr == -1)
444 *intptr = value;
445 break;
446
447 case sIgnoreRhosts:
448 intptr = &options->ignore_rhosts;
449parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000450 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000451 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100452 fprintf(stderr, "%s line %d: missing yes/no argument.\n",
453 filename, linenum);
454 exit(1);
455 }
Damien Miller37023962000-07-11 17:31:38 +1000456 if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100457 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000458 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100459 value = 0;
460 else {
461 fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000462 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100463 exit(1);
464 }
465 if (*intptr == -1)
466 *intptr = value;
467 break;
468
469 case sIgnoreUserKnownHosts:
470 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100471 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100472
473 case sRhostsAuthentication:
474 intptr = &options->rhosts_authentication;
475 goto parse_flag;
476
477 case sRhostsRSAAuthentication:
478 intptr = &options->rhosts_rsa_authentication;
479 goto parse_flag;
480
481 case sRSAAuthentication:
482 intptr = &options->rsa_authentication;
483 goto parse_flag;
484
Damien Miller0bc1bd82000-11-13 22:57:25 +1100485 case sPubkeyAuthentication:
486 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000487 goto parse_flag;
488
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000489#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100490 case sKerberosAuthentication:
491 intptr = &options->kerberos_authentication;
492 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000493
Damien Miller95def091999-11-25 00:26:21 +1100494 case sKerberosOrLocalPasswd:
495 intptr = &options->kerberos_or_local_passwd;
496 goto parse_flag;
497
498 case sKerberosTicketCleanup:
499 intptr = &options->kerberos_ticket_cleanup;
500 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000501#endif
Damien Miller95def091999-11-25 00:26:21 +1100502
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000503#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100504 case sKerberosTgtPassing:
505 intptr = &options->kerberos_tgt_passing;
506 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000507
Damien Miller95def091999-11-25 00:26:21 +1100508 case sAFSTokenPassing:
509 intptr = &options->afs_token_passing;
510 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000511#endif
512
Damien Miller95def091999-11-25 00:26:21 +1100513 case sPasswordAuthentication:
514 intptr = &options->password_authentication;
515 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000516
Damien Miller874d77b2000-10-14 16:23:11 +1100517 case sKbdInteractiveAuthentication:
518 intptr = &options->kbd_interactive_authentication;
519 goto parse_flag;
520
Damien Miller95def091999-11-25 00:26:21 +1100521 case sCheckMail:
522 intptr = &options->check_mail;
523 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000524
Damien Miller95def091999-11-25 00:26:21 +1100525 case sSkeyAuthentication:
526 intptr = &options->skey_authentication;
527 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000528
Damien Miller95def091999-11-25 00:26:21 +1100529 case sPrintMotd:
530 intptr = &options->print_motd;
531 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000532
Damien Miller95def091999-11-25 00:26:21 +1100533 case sX11Forwarding:
534 intptr = &options->x11_forwarding;
535 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000536
Damien Miller95def091999-11-25 00:26:21 +1100537 case sX11DisplayOffset:
538 intptr = &options->x11_display_offset;
539 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000540
Damien Millerd3a18572000-06-07 19:55:44 +1000541 case sXAuthLocation:
542 charptr = &options->xauth_location;
543 goto parse_filename;
544
Damien Miller95def091999-11-25 00:26:21 +1100545 case sStrictModes:
546 intptr = &options->strict_modes;
547 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000548
Damien Miller95def091999-11-25 00:26:21 +1100549 case sKeepAlives:
550 intptr = &options->keepalives;
551 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000552
Damien Miller95def091999-11-25 00:26:21 +1100553 case sEmptyPasswd:
554 intptr = &options->permit_empty_passwd;
555 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000556
Damien Miller95def091999-11-25 00:26:21 +1100557 case sUseLogin:
558 intptr = &options->use_login;
559 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100560
Damien Millere247cc42000-05-07 12:03:14 +1000561 case sGatewayPorts:
562 intptr = &options->gateway_ports;
563 goto parse_flag;
564
Damien Miller95def091999-11-25 00:26:21 +1100565 case sLogFacility:
566 intptr = (int *) &options->log_facility;
Damien Millerbe484b52000-07-15 14:14:16 +1000567 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000568 value = log_facility_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100569 if (value == (SyslogFacility) - 1)
570 fatal("%.200s line %d: unsupported log facility '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000571 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100572 if (*intptr == -1)
573 *intptr = (SyslogFacility) value;
574 break;
575
576 case sLogLevel:
577 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000578 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000579 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100580 if (value == (LogLevel) - 1)
581 fatal("%.200s line %d: unsupported log level '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000582 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100583 if (*intptr == -1)
584 *intptr = (LogLevel) value;
585 break;
586
Damien Miller50a41ed2000-10-16 12:14:42 +1100587 case sAllowTcpForwarding:
588 intptr = &options->allow_tcp_forwarding;
589 goto parse_flag;
590
Damien Miller95def091999-11-25 00:26:21 +1100591 case sAllowUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000592 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000593 if (options->num_allow_users >= MAX_ALLOW_USERS)
594 fatal("%s line %d: too many allow users.\n",
595 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000596 options->allow_users[options->num_allow_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100597 }
598 break;
599
600 case sDenyUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000601 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000602 if (options->num_deny_users >= MAX_DENY_USERS)
603 fatal( "%s line %d: too many deny users.\n",
604 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000605 options->deny_users[options->num_deny_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100606 }
607 break;
608
609 case sAllowGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000610 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000611 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
612 fatal("%s line %d: too many allow groups.\n",
613 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000614 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100615 }
616 break;
617
618 case sDenyGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000619 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000620 if (options->num_deny_groups >= MAX_DENY_GROUPS)
621 fatal("%s line %d: too many deny groups.\n",
622 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000623 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100624 }
625 break;
626
Damien Miller78928792000-04-12 20:17:38 +1000627 case sCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000628 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000629 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000630 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000631 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000632 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000633 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000634 if (options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000635 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000636 break;
637
638 case sProtocol:
639 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000640 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000641 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000642 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000643 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000644 if (value == SSH_PROTO_UNKNOWN)
645 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000646 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000647 if (*intptr == SSH_PROTO_UNKNOWN)
648 *intptr = value;
649 break;
650
Damien Millerf6d9e222000-06-18 14:50:44 +1000651 case sSubsystem:
652 if(options->num_subsystems >= MAX_SUBSYSTEMS) {
653 fatal("%s line %d: too many subsystems defined.",
654 filename, linenum);
655 }
Damien Millerbe484b52000-07-15 14:14:16 +1000656 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000657 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000658 fatal("%s line %d: Missing subsystem name.",
659 filename, linenum);
660 for (i = 0; i < options->num_subsystems; i++)
Damien Miller37023962000-07-11 17:31:38 +1000661 if(strcmp(arg, options->subsystem_name[i]) == 0)
Damien Millerf6d9e222000-06-18 14:50:44 +1000662 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller37023962000-07-11 17:31:38 +1000663 filename, linenum, arg);
664 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000665 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000666 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000667 fatal("%s line %d: Missing subsystem command.",
668 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000669 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Millerf6d9e222000-06-18 14:50:44 +1000670 options->num_subsystems++;
671 break;
672
Damien Miller37023962000-07-11 17:31:38 +1000673 case sMaxStartups:
Damien Miller942da032000-08-18 13:59:06 +1000674 arg = strdelim(&cp);
675 if (!arg || *arg == '\0')
676 fatal("%s line %d: Missing MaxStartups spec.",
677 filename, linenum);
678 if (sscanf(arg, "%d:%d:%d",
679 &options->max_startups_begin,
680 &options->max_startups_rate,
681 &options->max_startups) == 3) {
682 if (options->max_startups_begin >
683 options->max_startups ||
684 options->max_startups_rate > 100 ||
685 options->max_startups_rate < 1)
686 fatal("%s line %d: Illegal MaxStartups spec.",
687 filename, linenum);
688 break;
689 }
Damien Miller37023962000-07-11 17:31:38 +1000690 intptr = &options->max_startups;
691 goto parse_int;
692
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000693 case sBanner:
694 charptr = &options->banner;
695 goto parse_filename;
696
Damien Miller95def091999-11-25 00:26:21 +1100697 default:
698 fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
Damien Miller37023962000-07-11 17:31:38 +1000699 filename, linenum, arg, opcode);
Damien Miller95def091999-11-25 00:26:21 +1100700 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000701 }
Damien Millerbe484b52000-07-15 14:14:16 +1000702 if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000703 fprintf(stderr,
704 "%s line %d: garbage at end of line; \"%.200s\".\n",
705 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100706 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000707 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000708 }
Damien Miller95def091999-11-25 00:26:21 +1100709 fclose(f);
710 if (bad_options > 0) {
711 fprintf(stderr, "%s: terminating, %d bad configuration options\n",
712 filename, bad_options);
713 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000714 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000715}