blob: 77ac8452749990f35ac667b580ab7238e2670d3c [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 Miller37023962000-07-11 17:31:38 +100015RCSID("$OpenBSD: servconf.c,v 1.47 2000/07/10 16:30:25 ho 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 Millerf6d9e222000-06-18 14:50:44 +1000167#define WHITESPACE " \t\r\n="
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000168
169/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100170typedef enum {
171 sBadOption, /* == unknown option */
172 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
173 sPermitRootLogin, sLogFacility, sLogLevel,
174 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000175#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100176 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000177#endif
178#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100179 sKerberosTgtPassing, sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000180#endif
181#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100182 sSkeyAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000183#endif
Damien Miller95def091999-11-25 00:26:21 +1100184 sPasswordAuthentication, sListenAddress,
185 sPrintMotd, sIgnoreRhosts, sX11Forwarding, sX11DisplayOffset,
186 sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail,
187 sUseLogin, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Damien Millere247cc42000-05-07 12:03:14 +1000188 sIgnoreUserKnownHosts, sHostDSAKeyFile, sCiphers, sProtocol, sPidFile,
Damien Miller37023962000-07-11 17:31:38 +1000189 sGatewayPorts, sDSAAuthentication, sXAuthLocation, sSubsystem, sMaxStartups
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000190} ServerOpCodes;
191
192/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100193static struct {
194 const char *name;
195 ServerOpCodes opcode;
196} keywords[] = {
197 { "port", sPort },
198 { "hostkey", sHostKeyFile },
Damien Millere247cc42000-05-07 12:03:14 +1000199 { "hostdsakey", sHostDSAKeyFile },
Damien Miller6f83b8e2000-05-02 09:23:45 +1000200 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100201 { "serverkeybits", sServerKeyBits },
202 { "logingracetime", sLoginGraceTime },
203 { "keyregenerationinterval", sKeyRegenerationTime },
204 { "permitrootlogin", sPermitRootLogin },
205 { "syslogfacility", sLogFacility },
206 { "loglevel", sLogLevel },
207 { "rhostsauthentication", sRhostsAuthentication },
208 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
209 { "rsaauthentication", sRSAAuthentication },
Damien Millere247cc42000-05-07 12:03:14 +1000210 { "dsaauthentication", sDSAAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000211#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100212 { "kerberosauthentication", sKerberosAuthentication },
213 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
214 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000215#endif
216#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100217 { "kerberostgtpassing", sKerberosTgtPassing },
218 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000219#endif
Damien Miller95def091999-11-25 00:26:21 +1100220 { "passwordauthentication", sPasswordAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000221#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100222 { "skeyauthentication", sSkeyAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223#endif
Damien Miller95def091999-11-25 00:26:21 +1100224 { "checkmail", sCheckMail },
225 { "listenaddress", sListenAddress },
226 { "printmotd", sPrintMotd },
227 { "ignorerhosts", sIgnoreRhosts },
228 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
229 { "x11forwarding", sX11Forwarding },
230 { "x11displayoffset", sX11DisplayOffset },
Damien Millerd3a18572000-06-07 19:55:44 +1000231 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100232 { "strictmodes", sStrictModes },
233 { "permitemptypasswords", sEmptyPasswd },
234 { "uselogin", sUseLogin },
235 { "randomseed", sRandomSeedFile },
236 { "keepalive", sKeepAlives },
237 { "allowusers", sAllowUsers },
238 { "denyusers", sDenyUsers },
239 { "allowgroups", sAllowGroups },
240 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000241 { "ciphers", sCiphers },
242 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000243 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000244 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000245 { "maxstartups", sMaxStartups },
Damien Miller95def091999-11-25 00:26:21 +1100246 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000247};
248
Damien Miller5428f641999-11-25 11:54:57 +1100249/*
250 * Returns the number of the token pointed to by cp of length len. Never
251 * returns if the token is not known.
252 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000253
Damien Miller4af51302000-04-16 11:18:38 +1000254static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100255parse_token(const char *cp, const char *filename,
256 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000257{
Damien Miller95def091999-11-25 00:26:21 +1100258 unsigned int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000259
Damien Miller95def091999-11-25 00:26:21 +1100260 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100261 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100262 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000263
Damien Miller95def091999-11-25 00:26:21 +1100264 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
265 filename, linenum, cp);
266 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000267}
268
Damien Miller34132e52000-01-14 15:45:46 +1100269/*
270 * add listen address
271 */
Damien Miller4af51302000-04-16 11:18:38 +1000272void
Damien Miller34132e52000-01-14 15:45:46 +1100273add_listen_addr(ServerOptions *options, char *addr)
274{
275 extern int IPv4or6;
276 struct addrinfo hints, *ai, *aitop;
277 char strport[NI_MAXSERV];
278 int gaierr;
279 int i;
280
281 if (options->num_ports == 0)
282 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
283 for (i = 0; i < options->num_ports; i++) {
284 memset(&hints, 0, sizeof(hints));
285 hints.ai_family = IPv4or6;
286 hints.ai_socktype = SOCK_STREAM;
287 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
288 snprintf(strport, sizeof strport, "%d", options->ports[i]);
289 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
290 fatal("bad addr or host: %s (%s)\n",
291 addr ? addr : "<NULL>",
292 gai_strerror(gaierr));
293 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
294 ;
295 ai->ai_next = options->listen_addrs;
296 options->listen_addrs = aitop;
297 }
298}
299
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000300/* Reads the server configuration file. */
301
Damien Miller4af51302000-04-16 11:18:38 +1000302void
Damien Miller95def091999-11-25 00:26:21 +1100303read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000304{
Damien Miller95def091999-11-25 00:26:21 +1100305 FILE *f;
306 char line[1024];
Damien Miller37023962000-07-11 17:31:38 +1000307 char *cp, **charptr, *arg;
Damien Miller95def091999-11-25 00:26:21 +1100308 int linenum, *intptr, value;
309 int bad_options = 0;
310 ServerOpCodes opcode;
Damien Millerf6d9e222000-06-18 14:50:44 +1000311 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000312
Damien Miller95def091999-11-25 00:26:21 +1100313 f = fopen(filename, "r");
314 if (!f) {
315 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000316 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100317 }
318 linenum = 0;
319 while (fgets(line, sizeof(line), f)) {
320 linenum++;
321 cp = line + strspn(line, WHITESPACE);
322 if (!*cp || *cp == '#')
323 continue;
Damien Miller37023962000-07-11 17:31:38 +1000324 arg = strsep(&cp, WHITESPACE);
325 opcode = parse_token(arg, filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100326 switch (opcode) {
327 case sBadOption:
328 bad_options++;
329 continue;
330 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100331 /* ignore ports from configfile if cmdline specifies ports */
332 if (options->ports_from_cmdline)
333 continue;
334 if (options->listen_addrs != NULL)
335 fatal("%s line %d: ports must be specified before "
336 "ListenAdress.\n", filename, linenum);
337 if (options->num_ports >= MAX_PORTS)
338 fatal("%s line %d: too many ports.\n",
Damien Miller4af51302000-04-16 11:18:38 +1000339 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000340 arg = strsep(&cp, WHITESPACE);
341 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100342 fatal("%s line %d: missing port number.\n",
343 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000344 options->ports[options->num_ports++] = atoi(arg);
Damien Miller34132e52000-01-14 15:45:46 +1100345 break;
346
347 case sServerKeyBits:
348 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100349parse_int:
Damien Miller37023962000-07-11 17:31:38 +1000350 arg = strsep(&cp, WHITESPACE);
351 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100352 fprintf(stderr, "%s line %d: missing integer value.\n",
353 filename, linenum);
354 exit(1);
355 }
Damien Miller37023962000-07-11 17:31:38 +1000356 value = atoi(arg);
Damien Miller95def091999-11-25 00:26:21 +1100357 if (*intptr == -1)
358 *intptr = value;
359 break;
Damien Miller32265091999-11-12 11:33:04 +1100360
Damien Miller95def091999-11-25 00:26:21 +1100361 case sLoginGraceTime:
362 intptr = &options->login_grace_time;
363 goto parse_int;
364
365 case sKeyRegenerationTime:
366 intptr = &options->key_regeneration_time;
367 goto parse_int;
368
369 case sListenAddress:
Damien Miller37023962000-07-11 17:31:38 +1000370 arg = strsep(&cp, WHITESPACE);
371 if (!arg || *arg == '\0')
Damien Miller34132e52000-01-14 15:45:46 +1100372 fatal("%s line %d: missing inet addr.\n",
373 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000374 add_listen_addr(options, arg);
Damien Miller95def091999-11-25 00:26:21 +1100375 break;
376
377 case sHostKeyFile:
Damien Millere247cc42000-05-07 12:03:14 +1000378 case sHostDSAKeyFile:
Damien Millerefb4afe2000-04-12 18:45:05 +1000379 charptr = (opcode == sHostKeyFile ) ?
Damien Millere247cc42000-05-07 12:03:14 +1000380 &options->host_key_file : &options->host_dsa_key_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000381parse_filename:
Damien Miller37023962000-07-11 17:31:38 +1000382 arg = strsep(&cp, WHITESPACE);
383 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100384 fprintf(stderr, "%s line %d: missing file name.\n",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000385 filename, linenum);
386 exit(1);
387 }
388 if (*charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000389 *charptr = tilde_expand_filename(arg, getuid());
Damien Miller6f83b8e2000-05-02 09:23:45 +1000390 break;
391
392 case sPidFile:
393 charptr = &options->pid_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000394 goto parse_filename;
Damien Miller95def091999-11-25 00:26:21 +1100395
396 case sRandomSeedFile:
397 fprintf(stderr, "%s line %d: \"randomseed\" option is obsolete.\n",
398 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000399 arg = strsep(&cp, WHITESPACE);
Damien Miller95def091999-11-25 00:26:21 +1100400 break;
401
402 case sPermitRootLogin:
403 intptr = &options->permit_root_login;
Damien Miller37023962000-07-11 17:31:38 +1000404 arg = strsep(&cp, WHITESPACE);
405 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100406 fprintf(stderr, "%s line %d: missing yes/without-password/no argument.\n",
407 filename, linenum);
408 exit(1);
409 }
Damien Miller37023962000-07-11 17:31:38 +1000410 if (strcmp(arg, "without-password") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100411 value = 2;
Damien Miller37023962000-07-11 17:31:38 +1000412 else if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100413 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000414 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100415 value = 0;
416 else {
417 fprintf(stderr, "%s line %d: Bad yes/without-password/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000418 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100419 exit(1);
420 }
421 if (*intptr == -1)
422 *intptr = value;
423 break;
424
425 case sIgnoreRhosts:
426 intptr = &options->ignore_rhosts;
427parse_flag:
Damien Miller37023962000-07-11 17:31:38 +1000428 arg = strsep(&cp, WHITESPACE);
429 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100430 fprintf(stderr, "%s line %d: missing yes/no argument.\n",
431 filename, linenum);
432 exit(1);
433 }
Damien Miller37023962000-07-11 17:31:38 +1000434 if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100435 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000436 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100437 value = 0;
438 else {
439 fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000440 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100441 exit(1);
442 }
443 if (*intptr == -1)
444 *intptr = value;
445 break;
446
447 case sIgnoreUserKnownHosts:
448 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100449 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100450
451 case sRhostsAuthentication:
452 intptr = &options->rhosts_authentication;
453 goto parse_flag;
454
455 case sRhostsRSAAuthentication:
456 intptr = &options->rhosts_rsa_authentication;
457 goto parse_flag;
458
459 case sRSAAuthentication:
460 intptr = &options->rsa_authentication;
461 goto parse_flag;
462
Damien Millere247cc42000-05-07 12:03:14 +1000463 case sDSAAuthentication:
464 intptr = &options->dsa_authentication;
465 goto parse_flag;
466
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000467#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100468 case sKerberosAuthentication:
469 intptr = &options->kerberos_authentication;
470 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000471
Damien Miller95def091999-11-25 00:26:21 +1100472 case sKerberosOrLocalPasswd:
473 intptr = &options->kerberos_or_local_passwd;
474 goto parse_flag;
475
476 case sKerberosTicketCleanup:
477 intptr = &options->kerberos_ticket_cleanup;
478 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000479#endif
Damien Miller95def091999-11-25 00:26:21 +1100480
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000481#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100482 case sKerberosTgtPassing:
483 intptr = &options->kerberos_tgt_passing;
484 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000485
Damien Miller95def091999-11-25 00:26:21 +1100486 case sAFSTokenPassing:
487 intptr = &options->afs_token_passing;
488 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000489#endif
490
Damien Miller95def091999-11-25 00:26:21 +1100491 case sPasswordAuthentication:
492 intptr = &options->password_authentication;
493 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000494
Damien Miller95def091999-11-25 00:26:21 +1100495 case sCheckMail:
496 intptr = &options->check_mail;
497 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000498
499#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100500 case sSkeyAuthentication:
501 intptr = &options->skey_authentication;
502 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000503#endif
504
Damien Miller95def091999-11-25 00:26:21 +1100505 case sPrintMotd:
506 intptr = &options->print_motd;
507 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000508
Damien Miller95def091999-11-25 00:26:21 +1100509 case sX11Forwarding:
510 intptr = &options->x11_forwarding;
511 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000512
Damien Miller95def091999-11-25 00:26:21 +1100513 case sX11DisplayOffset:
514 intptr = &options->x11_display_offset;
515 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000516
Damien Millerd3a18572000-06-07 19:55:44 +1000517 case sXAuthLocation:
518 charptr = &options->xauth_location;
519 goto parse_filename;
520
Damien Miller95def091999-11-25 00:26:21 +1100521 case sStrictModes:
522 intptr = &options->strict_modes;
523 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000524
Damien Miller95def091999-11-25 00:26:21 +1100525 case sKeepAlives:
526 intptr = &options->keepalives;
527 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000528
Damien Miller95def091999-11-25 00:26:21 +1100529 case sEmptyPasswd:
530 intptr = &options->permit_empty_passwd;
531 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000532
Damien Miller95def091999-11-25 00:26:21 +1100533 case sUseLogin:
534 intptr = &options->use_login;
535 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100536
Damien Millere247cc42000-05-07 12:03:14 +1000537 case sGatewayPorts:
538 intptr = &options->gateway_ports;
539 goto parse_flag;
540
Damien Miller95def091999-11-25 00:26:21 +1100541 case sLogFacility:
542 intptr = (int *) &options->log_facility;
Damien Miller37023962000-07-11 17:31:38 +1000543 arg = strsep(&cp, WHITESPACE);
544 value = log_facility_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100545 if (value == (SyslogFacility) - 1)
546 fatal("%.200s line %d: unsupported log facility '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000547 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100548 if (*intptr == -1)
549 *intptr = (SyslogFacility) value;
550 break;
551
552 case sLogLevel:
553 intptr = (int *) &options->log_level;
Damien Miller37023962000-07-11 17:31:38 +1000554 arg = strsep(&cp, WHITESPACE);
555 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100556 if (value == (LogLevel) - 1)
557 fatal("%.200s line %d: unsupported log level '%s'\n",
Damien Miller37023962000-07-11 17:31:38 +1000558 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100559 if (*intptr == -1)
560 *intptr = (LogLevel) value;
561 break;
562
563 case sAllowUsers:
Damien Miller37023962000-07-11 17:31:38 +1000564 while ((arg = strsep(&cp, WHITESPACE)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000565 if (options->num_allow_users >= MAX_ALLOW_USERS)
566 fatal("%s line %d: too many allow users.\n",
567 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000568 options->allow_users[options->num_allow_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100569 }
570 break;
571
572 case sDenyUsers:
Damien Miller37023962000-07-11 17:31:38 +1000573 while ((arg = strsep(&cp, WHITESPACE)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000574 if (options->num_deny_users >= MAX_DENY_USERS)
575 fatal( "%s line %d: too many deny users.\n",
576 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000577 options->deny_users[options->num_deny_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100578 }
579 break;
580
581 case sAllowGroups:
Damien Miller37023962000-07-11 17:31:38 +1000582 while ((arg = strsep(&cp, WHITESPACE)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000583 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
584 fatal("%s line %d: too many allow groups.\n",
585 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000586 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100587 }
588 break;
589
590 case sDenyGroups:
Damien Miller37023962000-07-11 17:31:38 +1000591 while ((arg = strsep(&cp, WHITESPACE)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000592 if (options->num_deny_groups >= MAX_DENY_GROUPS)
593 fatal("%s line %d: too many deny groups.\n",
594 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000595 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100596 }
597 break;
598
Damien Miller78928792000-04-12 20:17:38 +1000599 case sCiphers:
Damien Miller37023962000-07-11 17:31:38 +1000600 arg = strsep(&cp, WHITESPACE);
601 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000602 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000603 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000604 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000605 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000606 if (options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000607 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000608 break;
609
610 case sProtocol:
611 intptr = &options->protocol;
Damien Miller37023962000-07-11 17:31:38 +1000612 arg = strsep(&cp, WHITESPACE);
613 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000614 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000615 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000616 if (value == SSH_PROTO_UNKNOWN)
617 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000618 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000619 if (*intptr == SSH_PROTO_UNKNOWN)
620 *intptr = value;
621 break;
622
Damien Millerf6d9e222000-06-18 14:50:44 +1000623 case sSubsystem:
624 if(options->num_subsystems >= MAX_SUBSYSTEMS) {
625 fatal("%s line %d: too many subsystems defined.",
626 filename, linenum);
627 }
Damien Miller37023962000-07-11 17:31:38 +1000628 arg = strsep(&cp, WHITESPACE);
629 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000630 fatal("%s line %d: Missing subsystem name.",
631 filename, linenum);
632 for (i = 0; i < options->num_subsystems; i++)
Damien Miller37023962000-07-11 17:31:38 +1000633 if(strcmp(arg, options->subsystem_name[i]) == 0)
Damien Millerf6d9e222000-06-18 14:50:44 +1000634 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller37023962000-07-11 17:31:38 +1000635 filename, linenum, arg);
636 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
637 arg = strsep(&cp, WHITESPACE);
638 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000639 fatal("%s line %d: Missing subsystem command.",
640 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000641 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Millerf6d9e222000-06-18 14:50:44 +1000642 options->num_subsystems++;
643 break;
644
Damien Miller37023962000-07-11 17:31:38 +1000645 case sMaxStartups:
646 intptr = &options->max_startups;
647 goto parse_int;
648
Damien Miller95def091999-11-25 00:26:21 +1100649 default:
650 fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
Damien Miller37023962000-07-11 17:31:38 +1000651 filename, linenum, arg, opcode);
Damien Miller95def091999-11-25 00:26:21 +1100652 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000653 }
Damien Miller37023962000-07-11 17:31:38 +1000654 if ((arg = strsep(&cp, WHITESPACE)) != NULL && *arg != '\0') {
655 fprintf(stderr,
656 "%s line %d: garbage at end of line; \"%.200s\".\n",
657 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100658 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000659 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000660 }
Damien Miller95def091999-11-25 00:26:21 +1100661 fclose(f);
662 if (bad_options > 0) {
663 fprintf(stderr, "%s: terminating, %d bad configuration options\n",
664 filename, bad_options);
665 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000666 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000667}