blob: 81551081432a21f438541ffcdca8a703bba03a25 [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"
Damien Millere4340be2000-09-16 13:29:08 +110013RCSID("$OpenBSD: servconf.c,v 1.51 2000/09/07 20:27:53 deraadt 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 Miller95def091999-11-25 00:26:21 +110032 options->host_key_file = NULL;
Damien Millere247cc42000-05-07 12:03:14 +100033 options->host_dsa_key_file = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100034 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110035 options->server_key_bits = -1;
36 options->login_grace_time = -1;
37 options->key_regeneration_time = -1;
38 options->permit_root_login = -1;
39 options->ignore_rhosts = -1;
40 options->ignore_user_known_hosts = -1;
41 options->print_motd = -1;
42 options->check_mail = -1;
43 options->x11_forwarding = -1;
44 options->x11_display_offset = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100045 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110046 options->strict_modes = -1;
47 options->keepalives = -1;
48 options->log_facility = (SyslogFacility) - 1;
49 options->log_level = (LogLevel) - 1;
50 options->rhosts_authentication = -1;
51 options->rhosts_rsa_authentication = -1;
52 options->rsa_authentication = -1;
Damien Millere247cc42000-05-07 12:03:14 +100053 options->dsa_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100054#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +110055 options->kerberos_authentication = -1;
56 options->kerberos_or_local_passwd = -1;
57 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100058#endif
59#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +110060 options->kerberos_tgt_passing = -1;
61 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100062#endif
Damien Miller95def091999-11-25 00:26:21 +110063 options->password_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100064#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +110065 options->skey_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100066#endif
Damien Miller95def091999-11-25 00:26:21 +110067 options->permit_empty_passwd = -1;
68 options->use_login = -1;
69 options->num_allow_users = 0;
70 options->num_deny_users = 0;
71 options->num_allow_groups = 0;
72 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100073 options->ciphers = NULL;
74 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +100075 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +100076 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +100077 options->max_startups_begin = -1;
78 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +100079 options->max_startups = -1;
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 Miller34132e52000-01-14 15:45:46 +110085 if (options->num_ports == 0)
86 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
87 if (options->listen_addrs == NULL)
88 add_listen_addr(options, NULL);
Damien Miller95def091999-11-25 00:26:21 +110089 if (options->host_key_file == NULL)
90 options->host_key_file = HOST_KEY_FILE;
Damien Millere247cc42000-05-07 12:03:14 +100091 if (options->host_dsa_key_file == NULL)
92 options->host_dsa_key_file = HOST_DSA_KEY_FILE;
Damien Miller6f83b8e2000-05-02 09:23:45 +100093 if (options->pid_file == NULL)
94 options->pid_file = SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +110095 if (options->server_key_bits == -1)
96 options->server_key_bits = 768;
97 if (options->login_grace_time == -1)
98 options->login_grace_time = 600;
99 if (options->key_regeneration_time == -1)
100 options->key_regeneration_time = 3600;
101 if (options->permit_root_login == -1)
102 options->permit_root_login = 1; /* yes */
103 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100104 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100105 if (options->ignore_user_known_hosts == -1)
106 options->ignore_user_known_hosts = 0;
107 if (options->check_mail == -1)
108 options->check_mail = 0;
109 if (options->print_motd == -1)
110 options->print_motd = 1;
111 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100112 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100113 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100114 options->x11_display_offset = 10;
Damien Millerd3a18572000-06-07 19:55:44 +1000115#ifdef XAUTH_PATH
116 if (options->xauth_location == NULL)
117 options->xauth_location = XAUTH_PATH;
118#endif /* XAUTH_PATH */
Damien Miller95def091999-11-25 00:26:21 +1100119 if (options->strict_modes == -1)
120 options->strict_modes = 1;
121 if (options->keepalives == -1)
122 options->keepalives = 1;
123 if (options->log_facility == (SyslogFacility) (-1))
124 options->log_facility = SYSLOG_FACILITY_AUTH;
125 if (options->log_level == (LogLevel) (-1))
126 options->log_level = SYSLOG_LEVEL_INFO;
127 if (options->rhosts_authentication == -1)
128 options->rhosts_authentication = 0;
129 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100130 options->rhosts_rsa_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100131 if (options->rsa_authentication == -1)
132 options->rsa_authentication = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000133 if (options->dsa_authentication == -1)
134 options->dsa_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000135#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100136 if (options->kerberos_authentication == -1)
137 options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
138 if (options->kerberos_or_local_passwd == -1)
139 options->kerberos_or_local_passwd = 1;
140 if (options->kerberos_ticket_cleanup == -1)
141 options->kerberos_ticket_cleanup = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000142#endif /* KRB4 */
143#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100144 if (options->kerberos_tgt_passing == -1)
145 options->kerberos_tgt_passing = 0;
146 if (options->afs_token_passing == -1)
147 options->afs_token_passing = k_hasafs();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000148#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100149 if (options->password_authentication == -1)
150 options->password_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000151#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100152 if (options->skey_authentication == -1)
153 options->skey_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000154#endif
Damien Miller95def091999-11-25 00:26:21 +1100155 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100156 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100157 if (options->use_login == -1)
158 options->use_login = 0;
Damien Miller78928792000-04-12 20:17:38 +1000159 if (options->protocol == SSH_PROTO_UNKNOWN)
Damien Millereba71ba2000-04-29 23:57:08 +1000160 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Millere247cc42000-05-07 12:03:14 +1000161 if (options->gateway_ports == -1)
162 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000163 if (options->max_startups == -1)
164 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000165 if (options->max_startups_rate == -1)
166 options->max_startups_rate = 100; /* 100% */
167 if (options->max_startups_begin == -1)
168 options->max_startups_begin = options->max_startups;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000169}
170
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000171/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100172typedef enum {
173 sBadOption, /* == unknown option */
174 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
175 sPermitRootLogin, sLogFacility, sLogLevel,
176 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000177#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100178 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000179#endif
180#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100181 sKerberosTgtPassing, sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000182#endif
183#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100184 sSkeyAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000185#endif
Damien Miller95def091999-11-25 00:26:21 +1100186 sPasswordAuthentication, sListenAddress,
187 sPrintMotd, sIgnoreRhosts, sX11Forwarding, sX11DisplayOffset,
188 sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail,
189 sUseLogin, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Damien Millere247cc42000-05-07 12:03:14 +1000190 sIgnoreUserKnownHosts, sHostDSAKeyFile, sCiphers, sProtocol, sPidFile,
Damien Miller37023962000-07-11 17:31:38 +1000191 sGatewayPorts, sDSAAuthentication, sXAuthLocation, sSubsystem, sMaxStartups
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000192} ServerOpCodes;
193
194/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100195static struct {
196 const char *name;
197 ServerOpCodes opcode;
198} keywords[] = {
199 { "port", sPort },
200 { "hostkey", sHostKeyFile },
Damien Millere247cc42000-05-07 12:03:14 +1000201 { "hostdsakey", sHostDSAKeyFile },
Damien Miller6f83b8e2000-05-02 09:23:45 +1000202 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100203 { "serverkeybits", sServerKeyBits },
204 { "logingracetime", sLoginGraceTime },
205 { "keyregenerationinterval", sKeyRegenerationTime },
206 { "permitrootlogin", sPermitRootLogin },
207 { "syslogfacility", sLogFacility },
208 { "loglevel", sLogLevel },
209 { "rhostsauthentication", sRhostsAuthentication },
210 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
211 { "rsaauthentication", sRSAAuthentication },
Damien Millere247cc42000-05-07 12:03:14 +1000212 { "dsaauthentication", sDSAAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000213#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100214 { "kerberosauthentication", sKerberosAuthentication },
215 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
216 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000217#endif
218#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100219 { "kerberostgtpassing", sKerberosTgtPassing },
220 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000221#endif
Damien Miller95def091999-11-25 00:26:21 +1100222 { "passwordauthentication", sPasswordAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100224 { "skeyauthentication", sSkeyAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000225#endif
Damien Miller95def091999-11-25 00:26:21 +1100226 { "checkmail", sCheckMail },
227 { "listenaddress", sListenAddress },
228 { "printmotd", sPrintMotd },
229 { "ignorerhosts", sIgnoreRhosts },
230 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
231 { "x11forwarding", sX11Forwarding },
232 { "x11displayoffset", sX11DisplayOffset },
Damien Millerd3a18572000-06-07 19:55:44 +1000233 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100234 { "strictmodes", sStrictModes },
235 { "permitemptypasswords", sEmptyPasswd },
236 { "uselogin", sUseLogin },
237 { "randomseed", sRandomSeedFile },
238 { "keepalive", sKeepAlives },
239 { "allowusers", sAllowUsers },
240 { "denyusers", sDenyUsers },
241 { "allowgroups", sAllowGroups },
242 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000243 { "ciphers", sCiphers },
244 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000245 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000246 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000247 { "maxstartups", sMaxStartups },
Damien Miller95def091999-11-25 00:26:21 +1100248 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000249};
250
Damien Miller5428f641999-11-25 11:54:57 +1100251/*
252 * Returns the number of the token pointed to by cp of length len. Never
253 * returns if the token is not known.
254 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000255
Damien Miller4af51302000-04-16 11:18:38 +1000256static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100257parse_token(const char *cp, const char *filename,
258 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000259{
Damien Miller95def091999-11-25 00:26:21 +1100260 unsigned int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000261
Damien Miller95def091999-11-25 00:26:21 +1100262 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100263 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100264 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000265
Damien Miller95def091999-11-25 00:26:21 +1100266 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
267 filename, linenum, cp);
268 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000269}
270
Damien Miller34132e52000-01-14 15:45:46 +1100271/*
272 * add listen address
273 */
Damien Miller4af51302000-04-16 11:18:38 +1000274void
Damien Miller34132e52000-01-14 15:45:46 +1100275add_listen_addr(ServerOptions *options, char *addr)
276{
277 extern int IPv4or6;
278 struct addrinfo hints, *ai, *aitop;
279 char strport[NI_MAXSERV];
280 int gaierr;
281 int i;
282
283 if (options->num_ports == 0)
284 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
285 for (i = 0; i < options->num_ports; i++) {
286 memset(&hints, 0, sizeof(hints));
287 hints.ai_family = IPv4or6;
288 hints.ai_socktype = SOCK_STREAM;
289 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
290 snprintf(strport, sizeof strport, "%d", options->ports[i]);
291 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
292 fatal("bad addr or host: %s (%s)\n",
293 addr ? addr : "<NULL>",
294 gai_strerror(gaierr));
295 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
296 ;
297 ai->ai_next = options->listen_addrs;
298 options->listen_addrs = aitop;
299 }
300}
301
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000302/* Reads the server configuration file. */
303
Damien Miller4af51302000-04-16 11:18:38 +1000304void
Damien Miller95def091999-11-25 00:26:21 +1100305read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000306{
Damien Miller95def091999-11-25 00:26:21 +1100307 FILE *f;
308 char line[1024];
Damien Miller37023962000-07-11 17:31:38 +1000309 char *cp, **charptr, *arg;
Damien Miller95def091999-11-25 00:26:21 +1100310 int linenum, *intptr, value;
311 int bad_options = 0;
312 ServerOpCodes opcode;
Damien Millerf6d9e222000-06-18 14:50:44 +1000313 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000314
Damien Miller95def091999-11-25 00:26:21 +1100315 f = fopen(filename, "r");
316 if (!f) {
317 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000318 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100319 }
320 linenum = 0;
321 while (fgets(line, sizeof(line), f)) {
322 linenum++;
Damien Millerbe484b52000-07-15 14:14:16 +1000323 cp = line;
324 arg = strdelim(&cp);
325 /* Ignore leading whitespace */
326 if (*arg == '\0')
327 arg = strdelim(&cp);
328 if (!*arg || *arg == '#')
Damien Miller95def091999-11-25 00:26:21 +1100329 continue;
Damien Miller37023962000-07-11 17:31:38 +1000330 opcode = parse_token(arg, filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100331 switch (opcode) {
332 case sBadOption:
333 bad_options++;
334 continue;
335 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100336 /* ignore ports from configfile if cmdline specifies ports */
337 if (options->ports_from_cmdline)
338 continue;
339 if (options->listen_addrs != NULL)
340 fatal("%s line %d: ports must be specified before "
341 "ListenAdress.\n", filename, linenum);
342 if (options->num_ports >= MAX_PORTS)
343 fatal("%s line %d: too many ports.\n",
Damien Miller4af51302000-04-16 11:18:38 +1000344 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000345 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000346 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100347 fatal("%s line %d: missing port number.\n",
348 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000349 options->ports[options->num_ports++] = atoi(arg);
Damien Miller34132e52000-01-14 15:45:46 +1100350 break;
351
352 case sServerKeyBits:
353 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100354parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000355 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000356 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100357 fprintf(stderr, "%s line %d: missing integer value.\n",
358 filename, linenum);
359 exit(1);
360 }
Damien Miller37023962000-07-11 17:31:38 +1000361 value = atoi(arg);
Damien Miller95def091999-11-25 00:26:21 +1100362 if (*intptr == -1)
363 *intptr = value;
364 break;
Damien Miller32265091999-11-12 11:33:04 +1100365
Damien Miller95def091999-11-25 00:26:21 +1100366 case sLoginGraceTime:
367 intptr = &options->login_grace_time;
368 goto parse_int;
369
370 case sKeyRegenerationTime:
371 intptr = &options->key_regeneration_time;
372 goto parse_int;
373
374 case sListenAddress:
Damien Millerbe484b52000-07-15 14:14:16 +1000375 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000376 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100377 fatal("%s line %d: missing inet addr.\n",
378 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000379 add_listen_addr(options, arg);
Damien Miller95def091999-11-25 00:26:21 +1100380 break;
381
382 case sHostKeyFile:
Damien Millere247cc42000-05-07 12:03:14 +1000383 case sHostDSAKeyFile:
Damien Millerefb4afe2000-04-12 18:45:05 +1000384 charptr = (opcode == sHostKeyFile ) ?
Damien Millere247cc42000-05-07 12:03:14 +1000385 &options->host_key_file : &options->host_dsa_key_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000386parse_filename:
Damien Millerbe484b52000-07-15 14:14:16 +1000387 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000388 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100389 fprintf(stderr, "%s line %d: missing file name.\n",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000390 filename, linenum);
391 exit(1);
392 }
393 if (*charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000394 *charptr = tilde_expand_filename(arg, getuid());
Damien Miller6f83b8e2000-05-02 09:23:45 +1000395 break;
396
397 case sPidFile:
398 charptr = &options->pid_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000399 goto parse_filename;
Damien Miller95def091999-11-25 00:26:21 +1100400
401 case sRandomSeedFile:
402 fprintf(stderr, "%s line %d: \"randomseed\" option is obsolete.\n",
403 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000404 arg = strdelim(&cp);
Damien Miller95def091999-11-25 00:26:21 +1100405 break;
406
407 case sPermitRootLogin:
408 intptr = &options->permit_root_login;
Damien Millerbe484b52000-07-15 14:14:16 +1000409 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000410 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100411 fprintf(stderr, "%s line %d: missing yes/without-password/no argument.\n",
412 filename, linenum);
413 exit(1);
414 }
Damien Miller37023962000-07-11 17:31:38 +1000415 if (strcmp(arg, "without-password") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100416 value = 2;
Damien Miller37023962000-07-11 17:31:38 +1000417 else if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100418 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000419 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100420 value = 0;
421 else {
422 fprintf(stderr, "%s line %d: Bad yes/without-password/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000423 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100424 exit(1);
425 }
426 if (*intptr == -1)
427 *intptr = value;
428 break;
429
430 case sIgnoreRhosts:
431 intptr = &options->ignore_rhosts;
432parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000433 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000434 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100435 fprintf(stderr, "%s line %d: missing yes/no argument.\n",
436 filename, linenum);
437 exit(1);
438 }
Damien Miller37023962000-07-11 17:31:38 +1000439 if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100440 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000441 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100442 value = 0;
443 else {
444 fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000445 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100446 exit(1);
447 }
448 if (*intptr == -1)
449 *intptr = value;
450 break;
451
452 case sIgnoreUserKnownHosts:
453 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100454 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100455
456 case sRhostsAuthentication:
457 intptr = &options->rhosts_authentication;
458 goto parse_flag;
459
460 case sRhostsRSAAuthentication:
461 intptr = &options->rhosts_rsa_authentication;
462 goto parse_flag;
463
464 case sRSAAuthentication:
465 intptr = &options->rsa_authentication;
466 goto parse_flag;
467
Damien Millere247cc42000-05-07 12:03:14 +1000468 case sDSAAuthentication:
469 intptr = &options->dsa_authentication;
470 goto parse_flag;
471
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000472#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100473 case sKerberosAuthentication:
474 intptr = &options->kerberos_authentication;
475 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000476
Damien Miller95def091999-11-25 00:26:21 +1100477 case sKerberosOrLocalPasswd:
478 intptr = &options->kerberos_or_local_passwd;
479 goto parse_flag;
480
481 case sKerberosTicketCleanup:
482 intptr = &options->kerberos_ticket_cleanup;
483 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000484#endif
Damien Miller95def091999-11-25 00:26:21 +1100485
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000486#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100487 case sKerberosTgtPassing:
488 intptr = &options->kerberos_tgt_passing;
489 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000490
Damien Miller95def091999-11-25 00:26:21 +1100491 case sAFSTokenPassing:
492 intptr = &options->afs_token_passing;
493 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000494#endif
495
Damien Miller95def091999-11-25 00:26:21 +1100496 case sPasswordAuthentication:
497 intptr = &options->password_authentication;
498 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000499
Damien Miller95def091999-11-25 00:26:21 +1100500 case sCheckMail:
501 intptr = &options->check_mail;
502 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000503
504#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100505 case sSkeyAuthentication:
506 intptr = &options->skey_authentication;
507 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000508#endif
509
Damien Miller95def091999-11-25 00:26:21 +1100510 case sPrintMotd:
511 intptr = &options->print_motd;
512 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000513
Damien Miller95def091999-11-25 00:26:21 +1100514 case sX11Forwarding:
515 intptr = &options->x11_forwarding;
516 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000517
Damien Miller95def091999-11-25 00:26:21 +1100518 case sX11DisplayOffset:
519 intptr = &options->x11_display_offset;
520 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000521
Damien Millerd3a18572000-06-07 19:55:44 +1000522 case sXAuthLocation:
523 charptr = &options->xauth_location;
524 goto parse_filename;
525
Damien Miller95def091999-11-25 00:26:21 +1100526 case sStrictModes:
527 intptr = &options->strict_modes;
528 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000529
Damien Miller95def091999-11-25 00:26:21 +1100530 case sKeepAlives:
531 intptr = &options->keepalives;
532 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000533
Damien Miller95def091999-11-25 00:26:21 +1100534 case sEmptyPasswd:
535 intptr = &options->permit_empty_passwd;
536 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000537
Damien Miller95def091999-11-25 00:26:21 +1100538 case sUseLogin:
539 intptr = &options->use_login;
540 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100541
Damien Millere247cc42000-05-07 12:03:14 +1000542 case sGatewayPorts:
543 intptr = &options->gateway_ports;
544 goto parse_flag;
545
Damien Miller95def091999-11-25 00:26:21 +1100546 case sLogFacility:
547 intptr = (int *) &options->log_facility;
Damien Millerbe484b52000-07-15 14:14:16 +1000548 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000549 value = log_facility_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100550 if (value == (SyslogFacility) - 1)
551 fatal("%.200s line %d: unsupported log facility '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000552 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100553 if (*intptr == -1)
554 *intptr = (SyslogFacility) value;
555 break;
556
557 case sLogLevel:
558 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000559 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000560 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100561 if (value == (LogLevel) - 1)
562 fatal("%.200s line %d: unsupported log level '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000563 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100564 if (*intptr == -1)
565 *intptr = (LogLevel) value;
566 break;
567
568 case sAllowUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000569 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000570 if (options->num_allow_users >= MAX_ALLOW_USERS)
571 fatal("%s line %d: too many allow users.\n",
572 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000573 options->allow_users[options->num_allow_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100574 }
575 break;
576
577 case sDenyUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000578 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000579 if (options->num_deny_users >= MAX_DENY_USERS)
580 fatal( "%s line %d: too many deny users.\n",
581 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000582 options->deny_users[options->num_deny_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100583 }
584 break;
585
586 case sAllowGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000587 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000588 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
589 fatal("%s line %d: too many allow groups.\n",
590 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000591 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100592 }
593 break;
594
595 case sDenyGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000596 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000597 if (options->num_deny_groups >= MAX_DENY_GROUPS)
598 fatal("%s line %d: too many deny groups.\n",
599 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000600 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100601 }
602 break;
603
Damien Miller78928792000-04-12 20:17:38 +1000604 case sCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000605 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000606 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000607 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000608 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000609 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000610 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000611 if (options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000612 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000613 break;
614
615 case sProtocol:
616 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000617 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000618 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000619 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000620 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000621 if (value == SSH_PROTO_UNKNOWN)
622 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000623 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000624 if (*intptr == SSH_PROTO_UNKNOWN)
625 *intptr = value;
626 break;
627
Damien Millerf6d9e222000-06-18 14:50:44 +1000628 case sSubsystem:
629 if(options->num_subsystems >= MAX_SUBSYSTEMS) {
630 fatal("%s line %d: too many subsystems defined.",
631 filename, linenum);
632 }
Damien Millerbe484b52000-07-15 14:14:16 +1000633 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000634 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000635 fatal("%s line %d: Missing subsystem name.",
636 filename, linenum);
637 for (i = 0; i < options->num_subsystems; i++)
Damien Miller37023962000-07-11 17:31:38 +1000638 if(strcmp(arg, options->subsystem_name[i]) == 0)
Damien Millerf6d9e222000-06-18 14:50:44 +1000639 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller37023962000-07-11 17:31:38 +1000640 filename, linenum, arg);
641 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000642 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000643 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000644 fatal("%s line %d: Missing subsystem command.",
645 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000646 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Millerf6d9e222000-06-18 14:50:44 +1000647 options->num_subsystems++;
648 break;
649
Damien Miller37023962000-07-11 17:31:38 +1000650 case sMaxStartups:
Damien Miller942da032000-08-18 13:59:06 +1000651 arg = strdelim(&cp);
652 if (!arg || *arg == '\0')
653 fatal("%s line %d: Missing MaxStartups spec.",
654 filename, linenum);
655 if (sscanf(arg, "%d:%d:%d",
656 &options->max_startups_begin,
657 &options->max_startups_rate,
658 &options->max_startups) == 3) {
659 if (options->max_startups_begin >
660 options->max_startups ||
661 options->max_startups_rate > 100 ||
662 options->max_startups_rate < 1)
663 fatal("%s line %d: Illegal MaxStartups spec.",
664 filename, linenum);
665 break;
666 }
Damien Miller37023962000-07-11 17:31:38 +1000667 intptr = &options->max_startups;
668 goto parse_int;
669
Damien Miller95def091999-11-25 00:26:21 +1100670 default:
671 fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
Damien Miller37023962000-07-11 17:31:38 +1000672 filename, linenum, arg, opcode);
Damien Miller95def091999-11-25 00:26:21 +1100673 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000674 }
Damien Millerbe484b52000-07-15 14:14:16 +1000675 if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000676 fprintf(stderr,
677 "%s line %d: garbage at end of line; \"%.200s\".\n",
678 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100679 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000680 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000681 }
Damien Miller95def091999-11-25 00:26:21 +1100682 fclose(f);
683 if (bad_options > 0) {
684 fprintf(stderr, "%s: terminating, %d bad configuration options\n",
685 filename, bad_options);
686 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000687 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000688}