blob: 477204cfd69b870fe232166889cc3ec66c649ce7 [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 Millerbe484b52000-07-15 14:14:16 +100015RCSID("$OpenBSD: servconf.c,v 1.49 2000/07/14 22:59:46 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 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 Millerd4a8b7e1999-10-27 13:42:43 +1000165}
166
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000167/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100168typedef enum {
169 sBadOption, /* == unknown option */
170 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
171 sPermitRootLogin, sLogFacility, sLogLevel,
172 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000173#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100174 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000175#endif
176#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100177 sKerberosTgtPassing, sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000178#endif
179#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100180 sSkeyAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000181#endif
Damien Miller95def091999-11-25 00:26:21 +1100182 sPasswordAuthentication, sListenAddress,
183 sPrintMotd, sIgnoreRhosts, sX11Forwarding, sX11DisplayOffset,
184 sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail,
185 sUseLogin, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Damien Millere247cc42000-05-07 12:03:14 +1000186 sIgnoreUserKnownHosts, sHostDSAKeyFile, sCiphers, sProtocol, sPidFile,
Damien Miller37023962000-07-11 17:31:38 +1000187 sGatewayPorts, sDSAAuthentication, sXAuthLocation, sSubsystem, sMaxStartups
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000188} ServerOpCodes;
189
190/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100191static struct {
192 const char *name;
193 ServerOpCodes opcode;
194} keywords[] = {
195 { "port", sPort },
196 { "hostkey", sHostKeyFile },
Damien Millere247cc42000-05-07 12:03:14 +1000197 { "hostdsakey", sHostDSAKeyFile },
Damien Miller6f83b8e2000-05-02 09:23:45 +1000198 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100199 { "serverkeybits", sServerKeyBits },
200 { "logingracetime", sLoginGraceTime },
201 { "keyregenerationinterval", sKeyRegenerationTime },
202 { "permitrootlogin", sPermitRootLogin },
203 { "syslogfacility", sLogFacility },
204 { "loglevel", sLogLevel },
205 { "rhostsauthentication", sRhostsAuthentication },
206 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
207 { "rsaauthentication", sRSAAuthentication },
Damien Millere247cc42000-05-07 12:03:14 +1000208 { "dsaauthentication", sDSAAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000209#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100210 { "kerberosauthentication", sKerberosAuthentication },
211 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
212 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000213#endif
214#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100215 { "kerberostgtpassing", sKerberosTgtPassing },
216 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000217#endif
Damien Miller95def091999-11-25 00:26:21 +1100218 { "passwordauthentication", sPasswordAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000219#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100220 { "skeyauthentication", sSkeyAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000221#endif
Damien Miller95def091999-11-25 00:26:21 +1100222 { "checkmail", sCheckMail },
223 { "listenaddress", sListenAddress },
224 { "printmotd", sPrintMotd },
225 { "ignorerhosts", sIgnoreRhosts },
226 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
227 { "x11forwarding", sX11Forwarding },
228 { "x11displayoffset", sX11DisplayOffset },
Damien Millerd3a18572000-06-07 19:55:44 +1000229 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100230 { "strictmodes", sStrictModes },
231 { "permitemptypasswords", sEmptyPasswd },
232 { "uselogin", sUseLogin },
233 { "randomseed", sRandomSeedFile },
234 { "keepalive", sKeepAlives },
235 { "allowusers", sAllowUsers },
236 { "denyusers", sDenyUsers },
237 { "allowgroups", sAllowGroups },
238 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000239 { "ciphers", sCiphers },
240 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000241 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000242 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000243 { "maxstartups", sMaxStartups },
Damien Miller95def091999-11-25 00:26:21 +1100244 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000245};
246
Damien Miller5428f641999-11-25 11:54:57 +1100247/*
248 * Returns the number of the token pointed to by cp of length len. Never
249 * returns if the token is not known.
250 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000251
Damien Miller4af51302000-04-16 11:18:38 +1000252static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100253parse_token(const char *cp, const char *filename,
254 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000255{
Damien Miller95def091999-11-25 00:26:21 +1100256 unsigned int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000257
Damien Miller95def091999-11-25 00:26:21 +1100258 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100259 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100260 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000261
Damien Miller95def091999-11-25 00:26:21 +1100262 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
263 filename, linenum, cp);
264 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000265}
266
Damien Miller34132e52000-01-14 15:45:46 +1100267/*
268 * add listen address
269 */
Damien Miller4af51302000-04-16 11:18:38 +1000270void
Damien Miller34132e52000-01-14 15:45:46 +1100271add_listen_addr(ServerOptions *options, char *addr)
272{
273 extern int IPv4or6;
274 struct addrinfo hints, *ai, *aitop;
275 char strport[NI_MAXSERV];
276 int gaierr;
277 int i;
278
279 if (options->num_ports == 0)
280 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
281 for (i = 0; i < options->num_ports; i++) {
282 memset(&hints, 0, sizeof(hints));
283 hints.ai_family = IPv4or6;
284 hints.ai_socktype = SOCK_STREAM;
285 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
286 snprintf(strport, sizeof strport, "%d", options->ports[i]);
287 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
288 fatal("bad addr or host: %s (%s)\n",
289 addr ? addr : "<NULL>",
290 gai_strerror(gaierr));
291 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
292 ;
293 ai->ai_next = options->listen_addrs;
294 options->listen_addrs = aitop;
295 }
296}
297
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000298/* Reads the server configuration file. */
299
Damien Miller4af51302000-04-16 11:18:38 +1000300void
Damien Miller95def091999-11-25 00:26:21 +1100301read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000302{
Damien Miller95def091999-11-25 00:26:21 +1100303 FILE *f;
304 char line[1024];
Damien Miller37023962000-07-11 17:31:38 +1000305 char *cp, **charptr, *arg;
Damien Miller95def091999-11-25 00:26:21 +1100306 int linenum, *intptr, value;
307 int bad_options = 0;
308 ServerOpCodes opcode;
Damien Millerf6d9e222000-06-18 14:50:44 +1000309 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000310
Damien Miller95def091999-11-25 00:26:21 +1100311 f = fopen(filename, "r");
312 if (!f) {
313 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000314 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100315 }
316 linenum = 0;
317 while (fgets(line, sizeof(line), f)) {
318 linenum++;
Damien Millerbe484b52000-07-15 14:14:16 +1000319 cp = line;
320 arg = strdelim(&cp);
321 /* Ignore leading whitespace */
322 if (*arg == '\0')
323 arg = strdelim(&cp);
324 if (!*arg || *arg == '#')
Damien Miller95def091999-11-25 00:26:21 +1100325 continue;
Damien Miller37023962000-07-11 17:31:38 +1000326 opcode = parse_token(arg, filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100327 switch (opcode) {
328 case sBadOption:
329 bad_options++;
330 continue;
331 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100332 /* ignore ports from configfile if cmdline specifies ports */
333 if (options->ports_from_cmdline)
334 continue;
335 if (options->listen_addrs != NULL)
336 fatal("%s line %d: ports must be specified before "
337 "ListenAdress.\n", filename, linenum);
338 if (options->num_ports >= MAX_PORTS)
339 fatal("%s line %d: too many ports.\n",
Damien Miller4af51302000-04-16 11:18:38 +1000340 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000341 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000342 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100343 fatal("%s line %d: missing port number.\n",
344 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000345 options->ports[options->num_ports++] = atoi(arg);
Damien Miller34132e52000-01-14 15:45:46 +1100346 break;
347
348 case sServerKeyBits:
349 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100350parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000351 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000352 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100353 fprintf(stderr, "%s line %d: missing integer value.\n",
354 filename, linenum);
355 exit(1);
356 }
Damien Miller37023962000-07-11 17:31:38 +1000357 value = atoi(arg);
Damien Miller95def091999-11-25 00:26:21 +1100358 if (*intptr == -1)
359 *intptr = value;
360 break;
Damien Miller32265091999-11-12 11:33:04 +1100361
Damien Miller95def091999-11-25 00:26:21 +1100362 case sLoginGraceTime:
363 intptr = &options->login_grace_time;
364 goto parse_int;
365
366 case sKeyRegenerationTime:
367 intptr = &options->key_regeneration_time;
368 goto parse_int;
369
370 case sListenAddress:
Damien Millerbe484b52000-07-15 14:14:16 +1000371 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000372 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100373 fatal("%s line %d: missing inet addr.\n",
374 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000375 add_listen_addr(options, arg);
Damien Miller95def091999-11-25 00:26:21 +1100376 break;
377
378 case sHostKeyFile:
Damien Millere247cc42000-05-07 12:03:14 +1000379 case sHostDSAKeyFile:
Damien Millerefb4afe2000-04-12 18:45:05 +1000380 charptr = (opcode == sHostKeyFile ) ?
Damien Millere247cc42000-05-07 12:03:14 +1000381 &options->host_key_file : &options->host_dsa_key_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000382parse_filename:
Damien Millerbe484b52000-07-15 14:14:16 +1000383 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000384 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100385 fprintf(stderr, "%s line %d: missing file name.\n",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000386 filename, linenum);
387 exit(1);
388 }
389 if (*charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000390 *charptr = tilde_expand_filename(arg, getuid());
Damien Miller6f83b8e2000-05-02 09:23:45 +1000391 break;
392
393 case sPidFile:
394 charptr = &options->pid_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000395 goto parse_filename;
Damien Miller95def091999-11-25 00:26:21 +1100396
397 case sRandomSeedFile:
398 fprintf(stderr, "%s line %d: \"randomseed\" option is obsolete.\n",
399 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000400 arg = strdelim(&cp);
Damien Miller95def091999-11-25 00:26:21 +1100401 break;
402
403 case sPermitRootLogin:
404 intptr = &options->permit_root_login;
Damien Millerbe484b52000-07-15 14:14:16 +1000405 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000406 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100407 fprintf(stderr, "%s line %d: missing yes/without-password/no argument.\n",
408 filename, linenum);
409 exit(1);
410 }
Damien Miller37023962000-07-11 17:31:38 +1000411 if (strcmp(arg, "without-password") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100412 value = 2;
Damien Miller37023962000-07-11 17:31:38 +1000413 else if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100414 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000415 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100416 value = 0;
417 else {
418 fprintf(stderr, "%s line %d: Bad yes/without-password/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000419 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100420 exit(1);
421 }
422 if (*intptr == -1)
423 *intptr = value;
424 break;
425
426 case sIgnoreRhosts:
427 intptr = &options->ignore_rhosts;
428parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000429 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000430 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100431 fprintf(stderr, "%s line %d: missing yes/no argument.\n",
432 filename, linenum);
433 exit(1);
434 }
Damien Miller37023962000-07-11 17:31:38 +1000435 if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100436 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000437 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100438 value = 0;
439 else {
440 fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000441 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100442 exit(1);
443 }
444 if (*intptr == -1)
445 *intptr = value;
446 break;
447
448 case sIgnoreUserKnownHosts:
449 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100450 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100451
452 case sRhostsAuthentication:
453 intptr = &options->rhosts_authentication;
454 goto parse_flag;
455
456 case sRhostsRSAAuthentication:
457 intptr = &options->rhosts_rsa_authentication;
458 goto parse_flag;
459
460 case sRSAAuthentication:
461 intptr = &options->rsa_authentication;
462 goto parse_flag;
463
Damien Millere247cc42000-05-07 12:03:14 +1000464 case sDSAAuthentication:
465 intptr = &options->dsa_authentication;
466 goto parse_flag;
467
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000468#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100469 case sKerberosAuthentication:
470 intptr = &options->kerberos_authentication;
471 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000472
Damien Miller95def091999-11-25 00:26:21 +1100473 case sKerberosOrLocalPasswd:
474 intptr = &options->kerberos_or_local_passwd;
475 goto parse_flag;
476
477 case sKerberosTicketCleanup:
478 intptr = &options->kerberos_ticket_cleanup;
479 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000480#endif
Damien Miller95def091999-11-25 00:26:21 +1100481
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000482#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100483 case sKerberosTgtPassing:
484 intptr = &options->kerberos_tgt_passing;
485 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000486
Damien Miller95def091999-11-25 00:26:21 +1100487 case sAFSTokenPassing:
488 intptr = &options->afs_token_passing;
489 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000490#endif
491
Damien Miller95def091999-11-25 00:26:21 +1100492 case sPasswordAuthentication:
493 intptr = &options->password_authentication;
494 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000495
Damien Miller95def091999-11-25 00:26:21 +1100496 case sCheckMail:
497 intptr = &options->check_mail;
498 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000499
500#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100501 case sSkeyAuthentication:
502 intptr = &options->skey_authentication;
503 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000504#endif
505
Damien Miller95def091999-11-25 00:26:21 +1100506 case sPrintMotd:
507 intptr = &options->print_motd;
508 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000509
Damien Miller95def091999-11-25 00:26:21 +1100510 case sX11Forwarding:
511 intptr = &options->x11_forwarding;
512 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000513
Damien Miller95def091999-11-25 00:26:21 +1100514 case sX11DisplayOffset:
515 intptr = &options->x11_display_offset;
516 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000517
Damien Millerd3a18572000-06-07 19:55:44 +1000518 case sXAuthLocation:
519 charptr = &options->xauth_location;
520 goto parse_filename;
521
Damien Miller95def091999-11-25 00:26:21 +1100522 case sStrictModes:
523 intptr = &options->strict_modes;
524 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000525
Damien Miller95def091999-11-25 00:26:21 +1100526 case sKeepAlives:
527 intptr = &options->keepalives;
528 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000529
Damien Miller95def091999-11-25 00:26:21 +1100530 case sEmptyPasswd:
531 intptr = &options->permit_empty_passwd;
532 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000533
Damien Miller95def091999-11-25 00:26:21 +1100534 case sUseLogin:
535 intptr = &options->use_login;
536 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100537
Damien Millere247cc42000-05-07 12:03:14 +1000538 case sGatewayPorts:
539 intptr = &options->gateway_ports;
540 goto parse_flag;
541
Damien Miller95def091999-11-25 00:26:21 +1100542 case sLogFacility:
543 intptr = (int *) &options->log_facility;
Damien Millerbe484b52000-07-15 14:14:16 +1000544 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000545 value = log_facility_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100546 if (value == (SyslogFacility) - 1)
547 fatal("%.200s line %d: unsupported log facility '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000548 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100549 if (*intptr == -1)
550 *intptr = (SyslogFacility) value;
551 break;
552
553 case sLogLevel:
554 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000555 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000556 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100557 if (value == (LogLevel) - 1)
558 fatal("%.200s line %d: unsupported log level '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000559 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100560 if (*intptr == -1)
561 *intptr = (LogLevel) value;
562 break;
563
564 case sAllowUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000565 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000566 if (options->num_allow_users >= MAX_ALLOW_USERS)
567 fatal("%s line %d: too many allow users.\n",
568 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000569 options->allow_users[options->num_allow_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100570 }
571 break;
572
573 case sDenyUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000574 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000575 if (options->num_deny_users >= MAX_DENY_USERS)
576 fatal( "%s line %d: too many deny users.\n",
577 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000578 options->deny_users[options->num_deny_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100579 }
580 break;
581
582 case sAllowGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000583 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000584 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
585 fatal("%s line %d: too many allow groups.\n",
586 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000587 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100588 }
589 break;
590
591 case sDenyGroups:
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_deny_groups >= MAX_DENY_GROUPS)
594 fatal("%s line %d: too many deny groups.\n",
595 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000596 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100597 }
598 break;
599
Damien Miller78928792000-04-12 20:17:38 +1000600 case sCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000601 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000602 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000603 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000604 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000605 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000606 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000607 if (options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000608 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000609 break;
610
611 case sProtocol:
612 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000613 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000614 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000615 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000616 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000617 if (value == SSH_PROTO_UNKNOWN)
618 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000619 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000620 if (*intptr == SSH_PROTO_UNKNOWN)
621 *intptr = value;
622 break;
623
Damien Millerf6d9e222000-06-18 14:50:44 +1000624 case sSubsystem:
625 if(options->num_subsystems >= MAX_SUBSYSTEMS) {
626 fatal("%s line %d: too many subsystems defined.",
627 filename, linenum);
628 }
Damien Millerbe484b52000-07-15 14:14:16 +1000629 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000630 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000631 fatal("%s line %d: Missing subsystem name.",
632 filename, linenum);
633 for (i = 0; i < options->num_subsystems; i++)
Damien Miller37023962000-07-11 17:31:38 +1000634 if(strcmp(arg, options->subsystem_name[i]) == 0)
Damien Millerf6d9e222000-06-18 14:50:44 +1000635 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller37023962000-07-11 17:31:38 +1000636 filename, linenum, arg);
637 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000638 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000639 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000640 fatal("%s line %d: Missing subsystem command.",
641 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000642 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Millerf6d9e222000-06-18 14:50:44 +1000643 options->num_subsystems++;
644 break;
645
Damien Miller37023962000-07-11 17:31:38 +1000646 case sMaxStartups:
647 intptr = &options->max_startups;
648 goto parse_int;
649
Damien Miller95def091999-11-25 00:26:21 +1100650 default:
651 fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
Damien Miller37023962000-07-11 17:31:38 +1000652 filename, linenum, arg, opcode);
Damien Miller95def091999-11-25 00:26:21 +1100653 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000654 }
Damien Millerbe484b52000-07-15 14:14:16 +1000655 if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +1000656 fprintf(stderr,
657 "%s line %d: garbage at end of line; \"%.200s\".\n",
658 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100659 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000660 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000661 }
Damien Miller95def091999-11-25 00:26:21 +1100662 fclose(f);
663 if (bad_options > 0) {
664 fprintf(stderr, "%s: terminating, %d bad configuration options\n",
665 filename, bad_options);
666 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000667 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000668}