blob: 6affb51e98c442eb30c5216627d979f2a6086a60 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller4af51302000-04-16 11:18:38 +10002 *
Damien Miller95def091999-11-25 00:26:21 +11003 * servconf.c
Damien Miller4af51302000-04-16 11:18:38 +10004 *
Damien Miller95def091999-11-25 00:26:21 +11005 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Miller95def091999-11-25 00:26:21 +11007 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10009 *
Damien Miller95def091999-11-25 00:26:21 +110010 * Created: Mon Aug 21 15:48:58 1995 ylo
Damien Miller4af51302000-04-16 11:18:38 +100011 *
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Miller942da032000-08-18 13:59:06 +100015RCSID("$OpenBSD: servconf.c,v 1.50 2000/07/22 09:14:36 markus Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016
17#include "ssh.h"
18#include "servconf.h"
19#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100020#include "compat.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100021
Damien Miller34132e52000-01-14 15:45:46 +110022/* add listen address */
23void add_listen_addr(ServerOptions *options, char *addr);
24
Damien Millerd4a8b7e1999-10-27 13:42:43 +100025/* Initializes the server options to their default values. */
26
Damien Miller4af51302000-04-16 11:18:38 +100027void
Damien Miller95def091999-11-25 00:26:21 +110028initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100029{
Damien Miller95def091999-11-25 00:26:21 +110030 memset(options, 0, sizeof(*options));
Damien Miller34132e52000-01-14 15:45:46 +110031 options->num_ports = 0;
32 options->ports_from_cmdline = 0;
33 options->listen_addrs = NULL;
Damien Miller95def091999-11-25 00:26:21 +110034 options->host_key_file = NULL;
Damien Millere247cc42000-05-07 12:03:14 +100035 options->host_dsa_key_file = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100036 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110037 options->server_key_bits = -1;
38 options->login_grace_time = -1;
39 options->key_regeneration_time = -1;
40 options->permit_root_login = -1;
41 options->ignore_rhosts = -1;
42 options->ignore_user_known_hosts = -1;
43 options->print_motd = -1;
44 options->check_mail = -1;
45 options->x11_forwarding = -1;
46 options->x11_display_offset = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100047 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110048 options->strict_modes = -1;
49 options->keepalives = -1;
50 options->log_facility = (SyslogFacility) - 1;
51 options->log_level = (LogLevel) - 1;
52 options->rhosts_authentication = -1;
53 options->rhosts_rsa_authentication = -1;
54 options->rsa_authentication = -1;
Damien Millere247cc42000-05-07 12:03:14 +100055 options->dsa_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100056#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +110057 options->kerberos_authentication = -1;
58 options->kerberos_or_local_passwd = -1;
59 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100060#endif
61#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +110062 options->kerberos_tgt_passing = -1;
63 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100064#endif
Damien Miller95def091999-11-25 00:26:21 +110065 options->password_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100066#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +110067 options->skey_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068#endif
Damien Miller95def091999-11-25 00:26:21 +110069 options->permit_empty_passwd = -1;
70 options->use_login = -1;
71 options->num_allow_users = 0;
72 options->num_deny_users = 0;
73 options->num_allow_groups = 0;
74 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100075 options->ciphers = NULL;
76 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +100077 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +100078 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +100079 options->max_startups_begin = -1;
80 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +100081 options->max_startups = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100082}
83
Damien Miller4af51302000-04-16 11:18:38 +100084void
Damien Miller95def091999-11-25 00:26:21 +110085fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100086{
Damien Miller34132e52000-01-14 15:45:46 +110087 if (options->num_ports == 0)
88 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
89 if (options->listen_addrs == NULL)
90 add_listen_addr(options, NULL);
Damien Miller95def091999-11-25 00:26:21 +110091 if (options->host_key_file == NULL)
92 options->host_key_file = HOST_KEY_FILE;
Damien Millere247cc42000-05-07 12:03:14 +100093 if (options->host_dsa_key_file == NULL)
94 options->host_dsa_key_file = HOST_DSA_KEY_FILE;
Damien Miller6f83b8e2000-05-02 09:23:45 +100095 if (options->pid_file == NULL)
96 options->pid_file = SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +110097 if (options->server_key_bits == -1)
98 options->server_key_bits = 768;
99 if (options->login_grace_time == -1)
100 options->login_grace_time = 600;
101 if (options->key_regeneration_time == -1)
102 options->key_regeneration_time = 3600;
103 if (options->permit_root_login == -1)
104 options->permit_root_login = 1; /* yes */
105 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100106 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100107 if (options->ignore_user_known_hosts == -1)
108 options->ignore_user_known_hosts = 0;
109 if (options->check_mail == -1)
110 options->check_mail = 0;
111 if (options->print_motd == -1)
112 options->print_motd = 1;
113 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100114 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100115 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100116 options->x11_display_offset = 10;
Damien Millerd3a18572000-06-07 19:55:44 +1000117#ifdef XAUTH_PATH
118 if (options->xauth_location == NULL)
119 options->xauth_location = XAUTH_PATH;
120#endif /* XAUTH_PATH */
Damien Miller95def091999-11-25 00:26:21 +1100121 if (options->strict_modes == -1)
122 options->strict_modes = 1;
123 if (options->keepalives == -1)
124 options->keepalives = 1;
125 if (options->log_facility == (SyslogFacility) (-1))
126 options->log_facility = SYSLOG_FACILITY_AUTH;
127 if (options->log_level == (LogLevel) (-1))
128 options->log_level = SYSLOG_LEVEL_INFO;
129 if (options->rhosts_authentication == -1)
130 options->rhosts_authentication = 0;
131 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100132 options->rhosts_rsa_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100133 if (options->rsa_authentication == -1)
134 options->rsa_authentication = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000135 if (options->dsa_authentication == -1)
136 options->dsa_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000137#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100138 if (options->kerberos_authentication == -1)
139 options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
140 if (options->kerberos_or_local_passwd == -1)
141 options->kerberos_or_local_passwd = 1;
142 if (options->kerberos_ticket_cleanup == -1)
143 options->kerberos_ticket_cleanup = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000144#endif /* KRB4 */
145#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100146 if (options->kerberos_tgt_passing == -1)
147 options->kerberos_tgt_passing = 0;
148 if (options->afs_token_passing == -1)
149 options->afs_token_passing = k_hasafs();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000150#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100151 if (options->password_authentication == -1)
152 options->password_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000153#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100154 if (options->skey_authentication == -1)
155 options->skey_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000156#endif
Damien Miller95def091999-11-25 00:26:21 +1100157 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100158 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100159 if (options->use_login == -1)
160 options->use_login = 0;
Damien Miller78928792000-04-12 20:17:38 +1000161 if (options->protocol == SSH_PROTO_UNKNOWN)
Damien Millereba71ba2000-04-29 23:57:08 +1000162 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Millere247cc42000-05-07 12:03:14 +1000163 if (options->gateway_ports == -1)
164 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000165 if (options->max_startups == -1)
166 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000167 if (options->max_startups_rate == -1)
168 options->max_startups_rate = 100; /* 100% */
169 if (options->max_startups_begin == -1)
170 options->max_startups_begin = options->max_startups;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000171}
172
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000173/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100174typedef enum {
175 sBadOption, /* == unknown option */
176 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
177 sPermitRootLogin, sLogFacility, sLogLevel,
178 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000179#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100180 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000181#endif
182#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100183 sKerberosTgtPassing, sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000184#endif
185#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100186 sSkeyAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000187#endif
Damien Miller95def091999-11-25 00:26:21 +1100188 sPasswordAuthentication, sListenAddress,
189 sPrintMotd, sIgnoreRhosts, sX11Forwarding, sX11DisplayOffset,
190 sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail,
191 sUseLogin, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Damien Millere247cc42000-05-07 12:03:14 +1000192 sIgnoreUserKnownHosts, sHostDSAKeyFile, sCiphers, sProtocol, sPidFile,
Damien Miller37023962000-07-11 17:31:38 +1000193 sGatewayPorts, sDSAAuthentication, sXAuthLocation, sSubsystem, sMaxStartups
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000194} ServerOpCodes;
195
196/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100197static struct {
198 const char *name;
199 ServerOpCodes opcode;
200} keywords[] = {
201 { "port", sPort },
202 { "hostkey", sHostKeyFile },
Damien Millere247cc42000-05-07 12:03:14 +1000203 { "hostdsakey", sHostDSAKeyFile },
Damien Miller6f83b8e2000-05-02 09:23:45 +1000204 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100205 { "serverkeybits", sServerKeyBits },
206 { "logingracetime", sLoginGraceTime },
207 { "keyregenerationinterval", sKeyRegenerationTime },
208 { "permitrootlogin", sPermitRootLogin },
209 { "syslogfacility", sLogFacility },
210 { "loglevel", sLogLevel },
211 { "rhostsauthentication", sRhostsAuthentication },
212 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
213 { "rsaauthentication", sRSAAuthentication },
Damien Millere247cc42000-05-07 12:03:14 +1000214 { "dsaauthentication", sDSAAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000215#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100216 { "kerberosauthentication", sKerberosAuthentication },
217 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
218 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000219#endif
220#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100221 { "kerberostgtpassing", sKerberosTgtPassing },
222 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223#endif
Damien Miller95def091999-11-25 00:26:21 +1100224 { "passwordauthentication", sPasswordAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000225#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100226 { "skeyauthentication", sSkeyAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000227#endif
Damien Miller95def091999-11-25 00:26:21 +1100228 { "checkmail", sCheckMail },
229 { "listenaddress", sListenAddress },
230 { "printmotd", sPrintMotd },
231 { "ignorerhosts", sIgnoreRhosts },
232 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
233 { "x11forwarding", sX11Forwarding },
234 { "x11displayoffset", sX11DisplayOffset },
Damien Millerd3a18572000-06-07 19:55:44 +1000235 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100236 { "strictmodes", sStrictModes },
237 { "permitemptypasswords", sEmptyPasswd },
238 { "uselogin", sUseLogin },
239 { "randomseed", sRandomSeedFile },
240 { "keepalive", sKeepAlives },
241 { "allowusers", sAllowUsers },
242 { "denyusers", sDenyUsers },
243 { "allowgroups", sAllowGroups },
244 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000245 { "ciphers", sCiphers },
246 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000247 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000248 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000249 { "maxstartups", sMaxStartups },
Damien Miller95def091999-11-25 00:26:21 +1100250 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000251};
252
Damien Miller5428f641999-11-25 11:54:57 +1100253/*
254 * Returns the number of the token pointed to by cp of length len. Never
255 * returns if the token is not known.
256 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000257
Damien Miller4af51302000-04-16 11:18:38 +1000258static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100259parse_token(const char *cp, const char *filename,
260 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000261{
Damien Miller95def091999-11-25 00:26:21 +1100262 unsigned int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000263
Damien Miller95def091999-11-25 00:26:21 +1100264 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100265 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100266 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000267
Damien Miller95def091999-11-25 00:26:21 +1100268 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
269 filename, linenum, cp);
270 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000271}
272
Damien Miller34132e52000-01-14 15:45:46 +1100273/*
274 * add listen address
275 */
Damien Miller4af51302000-04-16 11:18:38 +1000276void
Damien Miller34132e52000-01-14 15:45:46 +1100277add_listen_addr(ServerOptions *options, char *addr)
278{
279 extern int IPv4or6;
280 struct addrinfo hints, *ai, *aitop;
281 char strport[NI_MAXSERV];
282 int gaierr;
283 int i;
284
285 if (options->num_ports == 0)
286 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
287 for (i = 0; i < options->num_ports; i++) {
288 memset(&hints, 0, sizeof(hints));
289 hints.ai_family = IPv4or6;
290 hints.ai_socktype = SOCK_STREAM;
291 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
292 snprintf(strport, sizeof strport, "%d", options->ports[i]);
293 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
294 fatal("bad addr or host: %s (%s)\n",
295 addr ? addr : "<NULL>",
296 gai_strerror(gaierr));
297 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
298 ;
299 ai->ai_next = options->listen_addrs;
300 options->listen_addrs = aitop;
301 }
302}
303
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000304/* Reads the server configuration file. */
305
Damien Miller4af51302000-04-16 11:18:38 +1000306void
Damien Miller95def091999-11-25 00:26:21 +1100307read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000308{
Damien Miller95def091999-11-25 00:26:21 +1100309 FILE *f;
310 char line[1024];
Damien Miller37023962000-07-11 17:31:38 +1000311 char *cp, **charptr, *arg;
Damien Miller95def091999-11-25 00:26:21 +1100312 int linenum, *intptr, value;
313 int bad_options = 0;
314 ServerOpCodes opcode;
Damien Millerf6d9e222000-06-18 14:50:44 +1000315 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000316
Damien Miller95def091999-11-25 00:26:21 +1100317 f = fopen(filename, "r");
318 if (!f) {
319 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000320 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100321 }
322 linenum = 0;
323 while (fgets(line, sizeof(line), f)) {
324 linenum++;
Damien Millerbe484b52000-07-15 14:14:16 +1000325 cp = line;
326 arg = strdelim(&cp);
327 /* Ignore leading whitespace */
328 if (*arg == '\0')
329 arg = strdelim(&cp);
330 if (!*arg || *arg == '#')
Damien Miller95def091999-11-25 00:26:21 +1100331 continue;
Damien Miller37023962000-07-11 17:31:38 +1000332 opcode = parse_token(arg, filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100333 switch (opcode) {
334 case sBadOption:
335 bad_options++;
336 continue;
337 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100338 /* ignore ports from configfile if cmdline specifies ports */
339 if (options->ports_from_cmdline)
340 continue;
341 if (options->listen_addrs != NULL)
342 fatal("%s line %d: ports must be specified before "
343 "ListenAdress.\n", filename, linenum);
344 if (options->num_ports >= MAX_PORTS)
345 fatal("%s line %d: too many ports.\n",
Damien Miller4af51302000-04-16 11:18:38 +1000346 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000347 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000348 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100349 fatal("%s line %d: missing port number.\n",
350 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000351 options->ports[options->num_ports++] = atoi(arg);
Damien Miller34132e52000-01-14 15:45:46 +1100352 break;
353
354 case sServerKeyBits:
355 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100356parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000357 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000358 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100359 fprintf(stderr, "%s line %d: missing integer value.\n",
360 filename, linenum);
361 exit(1);
362 }
Damien Miller37023962000-07-11 17:31:38 +1000363 value = atoi(arg);
Damien Miller95def091999-11-25 00:26:21 +1100364 if (*intptr == -1)
365 *intptr = value;
366 break;
Damien Miller32265091999-11-12 11:33:04 +1100367
Damien Miller95def091999-11-25 00:26:21 +1100368 case sLoginGraceTime:
369 intptr = &options->login_grace_time;
370 goto parse_int;
371
372 case sKeyRegenerationTime:
373 intptr = &options->key_regeneration_time;
374 goto parse_int;
375
376 case sListenAddress:
Damien Millerbe484b52000-07-15 14:14:16 +1000377 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000378 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100379 fatal("%s line %d: missing inet addr.\n",
380 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000381 add_listen_addr(options, arg);
Damien Miller95def091999-11-25 00:26:21 +1100382 break;
383
384 case sHostKeyFile:
Damien Millere247cc42000-05-07 12:03:14 +1000385 case sHostDSAKeyFile:
Damien Millerefb4afe2000-04-12 18:45:05 +1000386 charptr = (opcode == sHostKeyFile ) ?
Damien Millere247cc42000-05-07 12:03:14 +1000387 &options->host_key_file : &options->host_dsa_key_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000388parse_filename:
Damien Millerbe484b52000-07-15 14:14:16 +1000389 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000390 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100391 fprintf(stderr, "%s line %d: missing file name.\n",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000392 filename, linenum);
393 exit(1);
394 }
395 if (*charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000396 *charptr = tilde_expand_filename(arg, getuid());
Damien Miller6f83b8e2000-05-02 09:23:45 +1000397 break;
398
399 case sPidFile:
400 charptr = &options->pid_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000401 goto parse_filename;
Damien Miller95def091999-11-25 00:26:21 +1100402
403 case sRandomSeedFile:
404 fprintf(stderr, "%s line %d: \"randomseed\" option is obsolete.\n",
405 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000406 arg = strdelim(&cp);
Damien Miller95def091999-11-25 00:26:21 +1100407 break;
408
409 case sPermitRootLogin:
410 intptr = &options->permit_root_login;
Damien Millerbe484b52000-07-15 14:14:16 +1000411 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000412 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100413 fprintf(stderr, "%s line %d: missing yes/without-password/no argument.\n",
414 filename, linenum);
415 exit(1);
416 }
Damien Miller37023962000-07-11 17:31:38 +1000417 if (strcmp(arg, "without-password") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100418 value = 2;
Damien Miller37023962000-07-11 17:31:38 +1000419 else if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100420 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000421 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100422 value = 0;
423 else {
424 fprintf(stderr, "%s line %d: Bad yes/without-password/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000425 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100426 exit(1);
427 }
428 if (*intptr == -1)
429 *intptr = value;
430 break;
431
432 case sIgnoreRhosts:
433 intptr = &options->ignore_rhosts;
434parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000435 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000436 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100437 fprintf(stderr, "%s line %d: missing yes/no argument.\n",
438 filename, linenum);
439 exit(1);
440 }
Damien Miller37023962000-07-11 17:31:38 +1000441 if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100442 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000443 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100444 value = 0;
445 else {
446 fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000447 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100448 exit(1);
449 }
450 if (*intptr == -1)
451 *intptr = value;
452 break;
453
454 case sIgnoreUserKnownHosts:
455 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100456 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100457
458 case sRhostsAuthentication:
459 intptr = &options->rhosts_authentication;
460 goto parse_flag;
461
462 case sRhostsRSAAuthentication:
463 intptr = &options->rhosts_rsa_authentication;
464 goto parse_flag;
465
466 case sRSAAuthentication:
467 intptr = &options->rsa_authentication;
468 goto parse_flag;
469
Damien Millere247cc42000-05-07 12:03:14 +1000470 case sDSAAuthentication:
471 intptr = &options->dsa_authentication;
472 goto parse_flag;
473
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000474#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100475 case sKerberosAuthentication:
476 intptr = &options->kerberos_authentication;
477 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000478
Damien Miller95def091999-11-25 00:26:21 +1100479 case sKerberosOrLocalPasswd:
480 intptr = &options->kerberos_or_local_passwd;
481 goto parse_flag;
482
483 case sKerberosTicketCleanup:
484 intptr = &options->kerberos_ticket_cleanup;
485 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000486#endif
Damien Miller95def091999-11-25 00:26:21 +1100487
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000488#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100489 case sKerberosTgtPassing:
490 intptr = &options->kerberos_tgt_passing;
491 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000492
Damien Miller95def091999-11-25 00:26:21 +1100493 case sAFSTokenPassing:
494 intptr = &options->afs_token_passing;
495 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000496#endif
497
Damien Miller95def091999-11-25 00:26:21 +1100498 case sPasswordAuthentication:
499 intptr = &options->password_authentication;
500 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000501
Damien Miller95def091999-11-25 00:26:21 +1100502 case sCheckMail:
503 intptr = &options->check_mail;
504 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000505
506#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100507 case sSkeyAuthentication:
508 intptr = &options->skey_authentication;
509 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000510#endif
511
Damien Miller95def091999-11-25 00:26:21 +1100512 case sPrintMotd:
513 intptr = &options->print_motd;
514 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000515
Damien Miller95def091999-11-25 00:26:21 +1100516 case sX11Forwarding:
517 intptr = &options->x11_forwarding;
518 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000519
Damien Miller95def091999-11-25 00:26:21 +1100520 case sX11DisplayOffset:
521 intptr = &options->x11_display_offset;
522 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000523
Damien Millerd3a18572000-06-07 19:55:44 +1000524 case sXAuthLocation:
525 charptr = &options->xauth_location;
526 goto parse_filename;
527
Damien Miller95def091999-11-25 00:26:21 +1100528 case sStrictModes:
529 intptr = &options->strict_modes;
530 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000531
Damien Miller95def091999-11-25 00:26:21 +1100532 case sKeepAlives:
533 intptr = &options->keepalives;
534 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000535
Damien Miller95def091999-11-25 00:26:21 +1100536 case sEmptyPasswd:
537 intptr = &options->permit_empty_passwd;
538 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000539
Damien Miller95def091999-11-25 00:26:21 +1100540 case sUseLogin:
541 intptr = &options->use_login;
542 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100543
Damien Millere247cc42000-05-07 12:03:14 +1000544 case sGatewayPorts:
545 intptr = &options->gateway_ports;
546 goto parse_flag;
547
Damien Miller95def091999-11-25 00:26:21 +1100548 case sLogFacility:
549 intptr = (int *) &options->log_facility;
Damien Millerbe484b52000-07-15 14:14:16 +1000550 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000551 value = log_facility_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100552 if (value == (SyslogFacility) - 1)
553 fatal("%.200s line %d: unsupported log facility '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000554 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100555 if (*intptr == -1)
556 *intptr = (SyslogFacility) value;
557 break;
558
559 case sLogLevel:
560 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000561 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000562 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100563 if (value == (LogLevel) - 1)
564 fatal("%.200s line %d: unsupported log level '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000565 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100566 if (*intptr == -1)
567 *intptr = (LogLevel) value;
568 break;
569
570 case sAllowUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000571 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000572 if (options->num_allow_users >= MAX_ALLOW_USERS)
573 fatal("%s line %d: too many allow users.\n",
574 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000575 options->allow_users[options->num_allow_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100576 }
577 break;
578
579 case sDenyUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000580 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000581 if (options->num_deny_users >= MAX_DENY_USERS)
582 fatal( "%s line %d: too many deny users.\n",
583 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000584 options->deny_users[options->num_deny_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100585 }
586 break;
587
588 case sAllowGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000589 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000590 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
591 fatal("%s line %d: too many allow groups.\n",
592 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000593 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100594 }
595 break;
596
597 case sDenyGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000598 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000599 if (options->num_deny_groups >= MAX_DENY_GROUPS)
600 fatal("%s line %d: too many deny groups.\n",
601 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000602 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100603 }
604 break;
605
Damien Miller78928792000-04-12 20:17:38 +1000606 case sCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000607 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000608 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000609 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000610 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000611 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000612 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000613 if (options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000614 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000615 break;
616
617 case sProtocol:
618 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000619 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000620 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000621 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000622 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000623 if (value == SSH_PROTO_UNKNOWN)
624 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000625 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000626 if (*intptr == SSH_PROTO_UNKNOWN)
627 *intptr = value;
628 break;
629
Damien Millerf6d9e222000-06-18 14:50:44 +1000630 case sSubsystem:
631 if(options->num_subsystems >= MAX_SUBSYSTEMS) {
632 fatal("%s line %d: too many subsystems defined.",
633 filename, linenum);
634 }
Damien Millerbe484b52000-07-15 14:14:16 +1000635 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000636 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000637 fatal("%s line %d: Missing subsystem name.",
638 filename, linenum);
639 for (i = 0; i < options->num_subsystems; i++)
Damien Miller37023962000-07-11 17:31:38 +1000640 if(strcmp(arg, options->subsystem_name[i]) == 0)
Damien Millerf6d9e222000-06-18 14:50:44 +1000641 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller37023962000-07-11 17:31:38 +1000642 filename, linenum, arg);
643 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000644 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000645 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000646 fatal("%s line %d: Missing subsystem command.",
647 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000648 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Millerf6d9e222000-06-18 14:50:44 +1000649 options->num_subsystems++;
650 break;
651
Damien Miller37023962000-07-11 17:31:38 +1000652 case sMaxStartups:
Damien Miller942da032000-08-18 13:59:06 +1000653 arg = strdelim(&cp);
654 if (!arg || *arg == '\0')
655 fatal("%s line %d: Missing MaxStartups spec.",
656 filename, linenum);
657 if (sscanf(arg, "%d:%d:%d",
658 &options->max_startups_begin,
659 &options->max_startups_rate,
660 &options->max_startups) == 3) {
661 if (options->max_startups_begin >
662 options->max_startups ||
663 options->max_startups_rate > 100 ||
664 options->max_startups_rate < 1)
665 fatal("%s line %d: Illegal MaxStartups spec.",
666 filename, linenum);
667 break;
668 }
Damien Miller37023962000-07-11 17:31:38 +1000669 intptr = &options->max_startups;
670 goto parse_int;
671
Damien Miller95def091999-11-25 00:26:21 +1100672 default:
673 fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
Damien Miller37023962000-07-11 17:31:38 +1000674 filename, linenum, arg, opcode);
Damien Miller95def091999-11-25 00:26:21 +1100675 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000676 }
Damien Millerbe484b52000-07-15 14:14:16 +1000677 if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000678 fprintf(stderr,
679 "%s line %d: garbage at end of line; \"%.200s\".\n",
680 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100681 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000682 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000683 }
Damien Miller95def091999-11-25 00:26:21 +1100684 fclose(f);
685 if (bad_options > 0) {
686 fprintf(stderr, "%s: terminating, %d bad configuration options\n",
687 filename, bad_options);
688 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000689 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000690}