blob: 16eaeba014d1af8042b51af460cd9dab33f79c28 [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 Miller6f83b8e2000-05-02 09:23:45 +100015RCSID("$Id: servconf.c,v 1.14 2000/05/01 23:23:45 damien 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 Millerefb4afe2000-04-12 18:45:05 +100035 options->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;
47 options->strict_modes = -1;
48 options->keepalives = -1;
49 options->log_facility = (SyslogFacility) - 1;
50 options->log_level = (LogLevel) - 1;
51 options->rhosts_authentication = -1;
52 options->rhosts_rsa_authentication = -1;
53 options->rsa_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 Millerd4a8b7e1999-10-27 13:42:43 +100075}
76
Damien Miller4af51302000-04-16 11:18:38 +100077void
Damien Miller95def091999-11-25 00:26:21 +110078fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100079{
Damien Miller34132e52000-01-14 15:45:46 +110080 if (options->num_ports == 0)
81 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
82 if (options->listen_addrs == NULL)
83 add_listen_addr(options, NULL);
Damien Miller95def091999-11-25 00:26:21 +110084 if (options->host_key_file == NULL)
85 options->host_key_file = HOST_KEY_FILE;
Damien Millerefb4afe2000-04-12 18:45:05 +100086 if (options->dsa_key_file == NULL)
87 options->dsa_key_file = DSA_KEY_FILE;
Damien Miller6f83b8e2000-05-02 09:23:45 +100088 if (options->pid_file == NULL)
89 options->pid_file = SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +110090 if (options->server_key_bits == -1)
91 options->server_key_bits = 768;
92 if (options->login_grace_time == -1)
93 options->login_grace_time = 600;
94 if (options->key_regeneration_time == -1)
95 options->key_regeneration_time = 3600;
96 if (options->permit_root_login == -1)
97 options->permit_root_login = 1; /* yes */
98 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +110099 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100100 if (options->ignore_user_known_hosts == -1)
101 options->ignore_user_known_hosts = 0;
102 if (options->check_mail == -1)
103 options->check_mail = 0;
104 if (options->print_motd == -1)
105 options->print_motd = 1;
106 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100107 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100108 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100109 options->x11_display_offset = 10;
Damien Miller95def091999-11-25 00:26:21 +1100110 if (options->strict_modes == -1)
111 options->strict_modes = 1;
112 if (options->keepalives == -1)
113 options->keepalives = 1;
114 if (options->log_facility == (SyslogFacility) (-1))
115 options->log_facility = SYSLOG_FACILITY_AUTH;
116 if (options->log_level == (LogLevel) (-1))
117 options->log_level = SYSLOG_LEVEL_INFO;
118 if (options->rhosts_authentication == -1)
119 options->rhosts_authentication = 0;
120 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100121 options->rhosts_rsa_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100122 if (options->rsa_authentication == -1)
123 options->rsa_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000124#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100125 if (options->kerberos_authentication == -1)
126 options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
127 if (options->kerberos_or_local_passwd == -1)
128 options->kerberos_or_local_passwd = 1;
129 if (options->kerberos_ticket_cleanup == -1)
130 options->kerberos_ticket_cleanup = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000131#endif /* KRB4 */
132#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100133 if (options->kerberos_tgt_passing == -1)
134 options->kerberos_tgt_passing = 0;
135 if (options->afs_token_passing == -1)
136 options->afs_token_passing = k_hasafs();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000137#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100138 if (options->password_authentication == -1)
139 options->password_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000140#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100141 if (options->skey_authentication == -1)
142 options->skey_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000143#endif
Damien Miller95def091999-11-25 00:26:21 +1100144 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100145 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100146 if (options->use_login == -1)
147 options->use_login = 0;
Damien Miller78928792000-04-12 20:17:38 +1000148 if (options->protocol == SSH_PROTO_UNKNOWN)
Damien Millereba71ba2000-04-29 23:57:08 +1000149 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000150}
151
152#define WHITESPACE " \t\r\n"
153
154/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100155typedef enum {
156 sBadOption, /* == unknown option */
157 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
158 sPermitRootLogin, sLogFacility, sLogLevel,
159 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000160#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100161 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000162#endif
163#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100164 sKerberosTgtPassing, sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000165#endif
166#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100167 sSkeyAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000168#endif
Damien Miller95def091999-11-25 00:26:21 +1100169 sPasswordAuthentication, sListenAddress,
170 sPrintMotd, sIgnoreRhosts, sX11Forwarding, sX11DisplayOffset,
171 sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail,
172 sUseLogin, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Damien Miller6f83b8e2000-05-02 09:23:45 +1000173 sIgnoreUserKnownHosts, sDSAKeyFile, sCiphers, sProtocol, sPidFile
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000174} ServerOpCodes;
175
176/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100177static struct {
178 const char *name;
179 ServerOpCodes opcode;
180} keywords[] = {
181 { "port", sPort },
182 { "hostkey", sHostKeyFile },
Damien Millerefb4afe2000-04-12 18:45:05 +1000183 { "dsakey", sDSAKeyFile },
Damien Miller6f83b8e2000-05-02 09:23:45 +1000184 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100185 { "serverkeybits", sServerKeyBits },
186 { "logingracetime", sLoginGraceTime },
187 { "keyregenerationinterval", sKeyRegenerationTime },
188 { "permitrootlogin", sPermitRootLogin },
189 { "syslogfacility", sLogFacility },
190 { "loglevel", sLogLevel },
191 { "rhostsauthentication", sRhostsAuthentication },
192 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
193 { "rsaauthentication", sRSAAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000194#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100195 { "kerberosauthentication", sKerberosAuthentication },
196 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
197 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000198#endif
199#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100200 { "kerberostgtpassing", sKerberosTgtPassing },
201 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000202#endif
Damien Miller95def091999-11-25 00:26:21 +1100203 { "passwordauthentication", sPasswordAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000204#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100205 { "skeyauthentication", sSkeyAuthentication },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000206#endif
Damien Miller95def091999-11-25 00:26:21 +1100207 { "checkmail", sCheckMail },
208 { "listenaddress", sListenAddress },
209 { "printmotd", sPrintMotd },
210 { "ignorerhosts", sIgnoreRhosts },
211 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
212 { "x11forwarding", sX11Forwarding },
213 { "x11displayoffset", sX11DisplayOffset },
214 { "strictmodes", sStrictModes },
215 { "permitemptypasswords", sEmptyPasswd },
216 { "uselogin", sUseLogin },
217 { "randomseed", sRandomSeedFile },
218 { "keepalive", sKeepAlives },
219 { "allowusers", sAllowUsers },
220 { "denyusers", sDenyUsers },
221 { "allowgroups", sAllowGroups },
222 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000223 { "ciphers", sCiphers },
224 { "protocol", sProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100225 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000226};
227
Damien Miller5428f641999-11-25 11:54:57 +1100228/*
229 * Returns the number of the token pointed to by cp of length len. Never
230 * returns if the token is not known.
231 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000232
Damien Miller4af51302000-04-16 11:18:38 +1000233static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100234parse_token(const char *cp, const char *filename,
235 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000236{
Damien Miller95def091999-11-25 00:26:21 +1100237 unsigned int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000238
Damien Miller95def091999-11-25 00:26:21 +1100239 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100240 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100241 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000242
Damien Miller95def091999-11-25 00:26:21 +1100243 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
244 filename, linenum, cp);
245 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000246}
247
Damien Miller34132e52000-01-14 15:45:46 +1100248/*
249 * add listen address
250 */
Damien Miller4af51302000-04-16 11:18:38 +1000251void
Damien Miller34132e52000-01-14 15:45:46 +1100252add_listen_addr(ServerOptions *options, char *addr)
253{
254 extern int IPv4or6;
255 struct addrinfo hints, *ai, *aitop;
256 char strport[NI_MAXSERV];
257 int gaierr;
258 int i;
259
260 if (options->num_ports == 0)
261 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
262 for (i = 0; i < options->num_ports; i++) {
263 memset(&hints, 0, sizeof(hints));
264 hints.ai_family = IPv4or6;
265 hints.ai_socktype = SOCK_STREAM;
266 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
267 snprintf(strport, sizeof strport, "%d", options->ports[i]);
268 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
269 fatal("bad addr or host: %s (%s)\n",
270 addr ? addr : "<NULL>",
271 gai_strerror(gaierr));
272 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
273 ;
274 ai->ai_next = options->listen_addrs;
275 options->listen_addrs = aitop;
276 }
277}
278
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000279/* Reads the server configuration file. */
280
Damien Miller4af51302000-04-16 11:18:38 +1000281void
Damien Miller95def091999-11-25 00:26:21 +1100282read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000283{
Damien Miller95def091999-11-25 00:26:21 +1100284 FILE *f;
285 char line[1024];
286 char *cp, **charptr;
287 int linenum, *intptr, value;
288 int bad_options = 0;
289 ServerOpCodes opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000290
Damien Miller95def091999-11-25 00:26:21 +1100291 f = fopen(filename, "r");
292 if (!f) {
293 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000294 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100295 }
296 linenum = 0;
297 while (fgets(line, sizeof(line), f)) {
298 linenum++;
299 cp = line + strspn(line, WHITESPACE);
300 if (!*cp || *cp == '#')
301 continue;
302 cp = strtok(cp, WHITESPACE);
Damien Miller95def091999-11-25 00:26:21 +1100303 opcode = parse_token(cp, filename, linenum);
304 switch (opcode) {
305 case sBadOption:
306 bad_options++;
307 continue;
308 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100309 /* ignore ports from configfile if cmdline specifies ports */
310 if (options->ports_from_cmdline)
311 continue;
312 if (options->listen_addrs != NULL)
313 fatal("%s line %d: ports must be specified before "
314 "ListenAdress.\n", filename, linenum);
315 if (options->num_ports >= MAX_PORTS)
316 fatal("%s line %d: too many ports.\n",
Damien Miller4af51302000-04-16 11:18:38 +1000317 filename, linenum);
Damien Miller34132e52000-01-14 15:45:46 +1100318 cp = strtok(NULL, WHITESPACE);
319 if (!cp)
320 fatal("%s line %d: missing port number.\n",
321 filename, linenum);
322 options->ports[options->num_ports++] = atoi(cp);
323 break;
324
325 case sServerKeyBits:
326 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100327parse_int:
328 cp = strtok(NULL, WHITESPACE);
329 if (!cp) {
330 fprintf(stderr, "%s line %d: missing integer value.\n",
331 filename, linenum);
332 exit(1);
333 }
334 value = atoi(cp);
335 if (*intptr == -1)
336 *intptr = value;
337 break;
Damien Miller32265091999-11-12 11:33:04 +1100338
Damien Miller95def091999-11-25 00:26:21 +1100339 case sLoginGraceTime:
340 intptr = &options->login_grace_time;
341 goto parse_int;
342
343 case sKeyRegenerationTime:
344 intptr = &options->key_regeneration_time;
345 goto parse_int;
346
347 case sListenAddress:
348 cp = strtok(NULL, WHITESPACE);
Damien Miller34132e52000-01-14 15:45:46 +1100349 if (!cp)
350 fatal("%s line %d: missing inet addr.\n",
351 filename, linenum);
352 add_listen_addr(options, cp);
Damien Miller95def091999-11-25 00:26:21 +1100353 break;
354
355 case sHostKeyFile:
Damien Millerefb4afe2000-04-12 18:45:05 +1000356 case sDSAKeyFile:
357 charptr = (opcode == sHostKeyFile ) ?
358 &options->host_key_file : &options->dsa_key_file;
Damien Miller95def091999-11-25 00:26:21 +1100359 cp = strtok(NULL, WHITESPACE);
360 if (!cp) {
361 fprintf(stderr, "%s line %d: missing file name.\n",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000362 filename, linenum);
363 exit(1);
364 }
365 if (*charptr == NULL)
366 *charptr = tilde_expand_filename(cp, getuid());
367 break;
368
369 case sPidFile:
370 charptr = &options->pid_file;
371 cp = strtok(NULL, WHITESPACE);
372 if (!cp) {
373 fprintf(stderr, "%s line %d: missing file name.\n",
374 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100375 exit(1);
376 }
377 if (*charptr == NULL)
378 *charptr = tilde_expand_filename(cp, getuid());
379 break;
380
381 case sRandomSeedFile:
382 fprintf(stderr, "%s line %d: \"randomseed\" option is obsolete.\n",
383 filename, linenum);
384 cp = strtok(NULL, WHITESPACE);
385 break;
386
387 case sPermitRootLogin:
388 intptr = &options->permit_root_login;
389 cp = strtok(NULL, WHITESPACE);
390 if (!cp) {
391 fprintf(stderr, "%s line %d: missing yes/without-password/no argument.\n",
392 filename, linenum);
393 exit(1);
394 }
395 if (strcmp(cp, "without-password") == 0)
396 value = 2;
397 else if (strcmp(cp, "yes") == 0)
398 value = 1;
399 else if (strcmp(cp, "no") == 0)
400 value = 0;
401 else {
402 fprintf(stderr, "%s line %d: Bad yes/without-password/no argument: %s\n",
403 filename, linenum, cp);
404 exit(1);
405 }
406 if (*intptr == -1)
407 *intptr = value;
408 break;
409
410 case sIgnoreRhosts:
411 intptr = &options->ignore_rhosts;
412parse_flag:
413 cp = strtok(NULL, WHITESPACE);
414 if (!cp) {
415 fprintf(stderr, "%s line %d: missing yes/no argument.\n",
416 filename, linenum);
417 exit(1);
418 }
419 if (strcmp(cp, "yes") == 0)
420 value = 1;
421 else if (strcmp(cp, "no") == 0)
422 value = 0;
423 else {
424 fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
425 filename, linenum, cp);
426 exit(1);
427 }
428 if (*intptr == -1)
429 *intptr = value;
430 break;
431
432 case sIgnoreUserKnownHosts:
433 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100434 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100435
436 case sRhostsAuthentication:
437 intptr = &options->rhosts_authentication;
438 goto parse_flag;
439
440 case sRhostsRSAAuthentication:
441 intptr = &options->rhosts_rsa_authentication;
442 goto parse_flag;
443
444 case sRSAAuthentication:
445 intptr = &options->rsa_authentication;
446 goto parse_flag;
447
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000448#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100449 case sKerberosAuthentication:
450 intptr = &options->kerberos_authentication;
451 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000452
Damien Miller95def091999-11-25 00:26:21 +1100453 case sKerberosOrLocalPasswd:
454 intptr = &options->kerberos_or_local_passwd;
455 goto parse_flag;
456
457 case sKerberosTicketCleanup:
458 intptr = &options->kerberos_ticket_cleanup;
459 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000460#endif
Damien Miller95def091999-11-25 00:26:21 +1100461
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000462#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100463 case sKerberosTgtPassing:
464 intptr = &options->kerberos_tgt_passing;
465 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000466
Damien Miller95def091999-11-25 00:26:21 +1100467 case sAFSTokenPassing:
468 intptr = &options->afs_token_passing;
469 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000470#endif
471
Damien Miller95def091999-11-25 00:26:21 +1100472 case sPasswordAuthentication:
473 intptr = &options->password_authentication;
474 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000475
Damien Miller95def091999-11-25 00:26:21 +1100476 case sCheckMail:
477 intptr = &options->check_mail;
478 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000479
480#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +1100481 case sSkeyAuthentication:
482 intptr = &options->skey_authentication;
483 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000484#endif
485
Damien Miller95def091999-11-25 00:26:21 +1100486 case sPrintMotd:
487 intptr = &options->print_motd;
488 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000489
Damien Miller95def091999-11-25 00:26:21 +1100490 case sX11Forwarding:
491 intptr = &options->x11_forwarding;
492 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000493
Damien Miller95def091999-11-25 00:26:21 +1100494 case sX11DisplayOffset:
495 intptr = &options->x11_display_offset;
496 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000497
Damien Miller95def091999-11-25 00:26:21 +1100498 case sStrictModes:
499 intptr = &options->strict_modes;
500 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000501
Damien Miller95def091999-11-25 00:26:21 +1100502 case sKeepAlives:
503 intptr = &options->keepalives;
504 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000505
Damien Miller95def091999-11-25 00:26:21 +1100506 case sEmptyPasswd:
507 intptr = &options->permit_empty_passwd;
508 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000509
Damien Miller95def091999-11-25 00:26:21 +1100510 case sUseLogin:
511 intptr = &options->use_login;
512 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100513
Damien Miller95def091999-11-25 00:26:21 +1100514 case sLogFacility:
515 intptr = (int *) &options->log_facility;
516 cp = strtok(NULL, WHITESPACE);
517 value = log_facility_number(cp);
518 if (value == (SyslogFacility) - 1)
519 fatal("%.200s line %d: unsupported log facility '%s'\n",
Damien Miller78928792000-04-12 20:17:38 +1000520 filename, linenum, cp ? cp : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100521 if (*intptr == -1)
522 *intptr = (SyslogFacility) value;
523 break;
524
525 case sLogLevel:
526 intptr = (int *) &options->log_level;
527 cp = strtok(NULL, WHITESPACE);
528 value = log_level_number(cp);
529 if (value == (LogLevel) - 1)
530 fatal("%.200s line %d: unsupported log level '%s'\n",
Damien Miller78928792000-04-12 20:17:38 +1000531 filename, linenum, cp ? cp : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100532 if (*intptr == -1)
533 *intptr = (LogLevel) value;
534 break;
535
536 case sAllowUsers:
537 while ((cp = strtok(NULL, WHITESPACE))) {
Damien Miller78928792000-04-12 20:17:38 +1000538 if (options->num_allow_users >= MAX_ALLOW_USERS)
539 fatal("%s line %d: too many allow users.\n",
540 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100541 options->allow_users[options->num_allow_users++] = xstrdup(cp);
542 }
543 break;
544
545 case sDenyUsers:
546 while ((cp = strtok(NULL, WHITESPACE))) {
Damien Miller78928792000-04-12 20:17:38 +1000547 if (options->num_deny_users >= MAX_DENY_USERS)
548 fatal( "%s line %d: too many deny users.\n",
549 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100550 options->deny_users[options->num_deny_users++] = xstrdup(cp);
551 }
552 break;
553
554 case sAllowGroups:
555 while ((cp = strtok(NULL, WHITESPACE))) {
Damien Miller78928792000-04-12 20:17:38 +1000556 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
557 fatal("%s line %d: too many allow groups.\n",
558 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100559 options->allow_groups[options->num_allow_groups++] = xstrdup(cp);
560 }
561 break;
562
563 case sDenyGroups:
564 while ((cp = strtok(NULL, WHITESPACE))) {
Damien Miller78928792000-04-12 20:17:38 +1000565 if (options->num_deny_groups >= MAX_DENY_GROUPS)
566 fatal("%s line %d: too many deny groups.\n",
567 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100568 options->deny_groups[options->num_deny_groups++] = xstrdup(cp);
569 }
570 break;
571
Damien Miller78928792000-04-12 20:17:38 +1000572 case sCiphers:
573 cp = strtok(NULL, WHITESPACE);
574 if (!ciphers_valid(cp))
575 fatal("%s line %d: Bad cipher spec '%s'.",
576 filename, linenum, cp ? cp : "<NONE>");
577 if (options->ciphers == NULL)
578 options->ciphers = xstrdup(cp);
579 break;
580
581 case sProtocol:
582 intptr = &options->protocol;
583 cp = strtok(NULL, WHITESPACE);
584 value = proto_spec(cp);
585 if (value == SSH_PROTO_UNKNOWN)
586 fatal("%s line %d: Bad protocol spec '%s'.",
587 filename, linenum, cp ? cp : "<NONE>");
588 if (*intptr == SSH_PROTO_UNKNOWN)
589 *intptr = value;
590 break;
591
Damien Miller95def091999-11-25 00:26:21 +1100592 default:
593 fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
594 filename, linenum, cp, opcode);
595 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000596 }
Damien Miller95def091999-11-25 00:26:21 +1100597 if (strtok(NULL, WHITESPACE) != NULL) {
598 fprintf(stderr, "%s line %d: garbage at end of line.\n",
599 filename, linenum);
600 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000601 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000602 }
Damien Miller95def091999-11-25 00:26:21 +1100603 fclose(f);
604 if (bad_options > 0) {
605 fprintf(stderr, "%s: terminating, %d bad configuration options\n",
606 filename, bad_options);
607 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000608 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000609}