]> andersk Git - openssh.git/blob - servconf.c
- djm@cvs.openbsd.org 2004/04/27 09:46:37
[openssh.git] / servconf.c
1 /*
2  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
3  *                    All rights reserved
4  *
5  * As far as I am concerned, the code I have written for this software
6  * can be used freely for any purpose.  Any derived versions of this
7  * software must be clearly marked as such, and if the derived work is
8  * incompatible with the protocol description in the RFC file, it must be
9  * called by a name other than "ssh" or "Secure Shell".
10  */
11
12 #include "includes.h"
13 RCSID("$OpenBSD: servconf.c,v 1.131 2004/04/27 09:46:37 djm Exp $");
14
15 #include "ssh.h"
16 #include "log.h"
17 #include "servconf.h"
18 #include "xmalloc.h"
19 #include "compat.h"
20 #include "pathnames.h"
21 #include "tildexpand.h"
22 #include "misc.h"
23 #include "cipher.h"
24 #include "kex.h"
25 #include "mac.h"
26
27 static void add_listen_addr(ServerOptions *, char *, u_short);
28 static void add_one_listen_addr(ServerOptions *, char *, u_short);
29
30 /* AF_UNSPEC or AF_INET or AF_INET6 */
31 extern int IPv4or6;
32 /* Use of privilege separation or not */
33 extern int use_privsep;
34
35 /* Initializes the server options to their default values. */
36
37 void
38 initialize_server_options(ServerOptions *options)
39 {
40         memset(options, 0, sizeof(*options));
41
42         /* Portable-specific options */
43         options->use_pam = -1;
44
45         /* Standard Options */
46         options->num_ports = 0;
47         options->ports_from_cmdline = 0;
48         options->listen_addrs = NULL;
49         options->num_host_key_files = 0;
50         options->pid_file = NULL;
51         options->server_key_bits = -1;
52         options->login_grace_time = -1;
53         options->key_regeneration_time = -1;
54         options->permit_root_login = PERMIT_NOT_SET;
55         options->ignore_rhosts = -1;
56         options->ignore_user_known_hosts = -1;
57         options->print_motd = -1;
58         options->print_lastlog = -1;
59         options->x11_forwarding = -1;
60         options->x11_display_offset = -1;
61         options->x11_use_localhost = -1;
62         options->xauth_location = NULL;
63         options->strict_modes = -1;
64         options->tcp_keep_alive = -1;
65         options->log_facility = SYSLOG_FACILITY_NOT_SET;
66         options->log_level = SYSLOG_LEVEL_NOT_SET;
67         options->rhosts_rsa_authentication = -1;
68         options->hostbased_authentication = -1;
69         options->hostbased_uses_name_from_packet_only = -1;
70         options->rsa_authentication = -1;
71         options->pubkey_authentication = -1;
72         options->kerberos_authentication = -1;
73         options->kerberos_or_local_passwd = -1;
74         options->kerberos_ticket_cleanup = -1;
75         options->kerberos_get_afs_token = -1;
76         options->gss_authentication=-1;
77         options->gss_cleanup_creds = -1;
78         options->password_authentication = -1;
79         options->kbd_interactive_authentication = -1;
80         options->challenge_response_authentication = -1;
81         options->permit_empty_passwd = -1;
82         options->permit_user_env = -1;
83         options->use_login = -1;
84         options->compression = -1;
85         options->allow_tcp_forwarding = -1;
86         options->num_allow_users = 0;
87         options->num_deny_users = 0;
88         options->num_allow_groups = 0;
89         options->num_deny_groups = 0;
90         options->ciphers = NULL;
91         options->macs = NULL;
92         options->protocol = SSH_PROTO_UNKNOWN;
93         options->gateway_ports = -1;
94         options->num_subsystems = 0;
95         options->max_startups_begin = -1;
96         options->max_startups_rate = -1;
97         options->max_startups = -1;
98         options->banner = NULL;
99         options->use_dns = -1;
100         options->client_alive_interval = -1;
101         options->client_alive_count_max = -1;
102         options->authorized_keys_file = NULL;
103         options->authorized_keys_file2 = NULL;
104         options->num_accept_env = 0;
105
106         /* Needs to be accessable in many places */
107         use_privsep = -1;
108 }
109
110 void
111 fill_default_server_options(ServerOptions *options)
112 {
113         /* Portable-specific options */
114         if (options->use_pam == -1)
115                 options->use_pam = 0;
116
117         /* Standard Options */
118         if (options->protocol == SSH_PROTO_UNKNOWN)
119                 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
120         if (options->num_host_key_files == 0) {
121                 /* fill default hostkeys for protocols */
122                 if (options->protocol & SSH_PROTO_1)
123                         options->host_key_files[options->num_host_key_files++] =
124                             _PATH_HOST_KEY_FILE;
125                 if (options->protocol & SSH_PROTO_2) {
126                         options->host_key_files[options->num_host_key_files++] =
127                             _PATH_HOST_RSA_KEY_FILE;
128                         options->host_key_files[options->num_host_key_files++] =
129                             _PATH_HOST_DSA_KEY_FILE;
130                 }
131         }
132         if (options->num_ports == 0)
133                 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
134         if (options->listen_addrs == NULL)
135                 add_listen_addr(options, NULL, 0);
136         if (options->pid_file == NULL)
137                 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
138         if (options->server_key_bits == -1)
139                 options->server_key_bits = 768;
140         if (options->login_grace_time == -1)
141                 options->login_grace_time = 120;
142         if (options->key_regeneration_time == -1)
143                 options->key_regeneration_time = 3600;
144         if (options->permit_root_login == PERMIT_NOT_SET)
145                 options->permit_root_login = PERMIT_YES;
146         if (options->ignore_rhosts == -1)
147                 options->ignore_rhosts = 1;
148         if (options->ignore_user_known_hosts == -1)
149                 options->ignore_user_known_hosts = 0;
150         if (options->print_motd == -1)
151                 options->print_motd = 1;
152         if (options->print_lastlog == -1)
153                 options->print_lastlog = 1;
154         if (options->x11_forwarding == -1)
155                 options->x11_forwarding = 0;
156         if (options->x11_display_offset == -1)
157                 options->x11_display_offset = 10;
158         if (options->x11_use_localhost == -1)
159                 options->x11_use_localhost = 1;
160         if (options->xauth_location == NULL)
161                 options->xauth_location = _PATH_XAUTH;
162         if (options->strict_modes == -1)
163                 options->strict_modes = 1;
164         if (options->tcp_keep_alive == -1)
165                 options->tcp_keep_alive = 1;
166         if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
167                 options->log_facility = SYSLOG_FACILITY_AUTH;
168         if (options->log_level == SYSLOG_LEVEL_NOT_SET)
169                 options->log_level = SYSLOG_LEVEL_INFO;
170         if (options->rhosts_rsa_authentication == -1)
171                 options->rhosts_rsa_authentication = 0;
172         if (options->hostbased_authentication == -1)
173                 options->hostbased_authentication = 0;
174         if (options->hostbased_uses_name_from_packet_only == -1)
175                 options->hostbased_uses_name_from_packet_only = 0;
176         if (options->rsa_authentication == -1)
177                 options->rsa_authentication = 1;
178         if (options->pubkey_authentication == -1)
179                 options->pubkey_authentication = 1;
180         if (options->kerberos_authentication == -1)
181                 options->kerberos_authentication = 0;
182         if (options->kerberos_or_local_passwd == -1)
183                 options->kerberos_or_local_passwd = 1;
184         if (options->kerberos_ticket_cleanup == -1)
185                 options->kerberos_ticket_cleanup = 1;
186         if (options->kerberos_get_afs_token == -1)
187                 options->kerberos_get_afs_token = 0;
188         if (options->gss_authentication == -1)
189                 options->gss_authentication = 0;
190         if (options->gss_cleanup_creds == -1)
191                 options->gss_cleanup_creds = 1;
192         if (options->password_authentication == -1)
193                 options->password_authentication = 1;
194         if (options->kbd_interactive_authentication == -1)
195                 options->kbd_interactive_authentication = 0;
196         if (options->challenge_response_authentication == -1)
197                 options->challenge_response_authentication = 1;
198         if (options->permit_empty_passwd == -1)
199                 options->permit_empty_passwd = 0;
200         if (options->permit_user_env == -1)
201                 options->permit_user_env = 0;
202         if (options->use_login == -1)
203                 options->use_login = 0;
204         if (options->compression == -1)
205                 options->compression = 1;
206         if (options->allow_tcp_forwarding == -1)
207                 options->allow_tcp_forwarding = 1;
208         if (options->gateway_ports == -1)
209                 options->gateway_ports = 0;
210         if (options->max_startups == -1)
211                 options->max_startups = 10;
212         if (options->max_startups_rate == -1)
213                 options->max_startups_rate = 100;               /* 100% */
214         if (options->max_startups_begin == -1)
215                 options->max_startups_begin = options->max_startups;
216         if (options->use_dns == -1)
217                 options->use_dns = 1;
218         if (options->client_alive_interval == -1)
219                 options->client_alive_interval = 0;
220         if (options->client_alive_count_max == -1)
221                 options->client_alive_count_max = 3;
222         if (options->authorized_keys_file2 == NULL) {
223                 /* authorized_keys_file2 falls back to authorized_keys_file */
224                 if (options->authorized_keys_file != NULL)
225                         options->authorized_keys_file2 = options->authorized_keys_file;
226                 else
227                         options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
228         }
229         if (options->authorized_keys_file == NULL)
230                 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
231
232         /* Turn privilege separation on by default */
233         if (use_privsep == -1)
234                 use_privsep = 1;
235
236 #ifndef HAVE_MMAP
237         if (use_privsep && options->compression == 1) {
238                 error("This platform does not support both privilege "
239                     "separation and compression");
240                 error("Compression disabled");
241                 options->compression = 0;
242         }
243 #endif
244
245 }
246
247 /* Keyword tokens. */
248 typedef enum {
249         sBadOption,             /* == unknown option */
250         /* Portable-specific options */
251         sUsePAM,
252         /* Standard Options */
253         sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
254         sPermitRootLogin, sLogFacility, sLogLevel,
255         sRhostsRSAAuthentication, sRSAAuthentication,
256         sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
257         sKerberosGetAFSToken,
258         sKerberosTgtPassing, sChallengeResponseAuthentication,
259         sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
260         sPrintMotd, sPrintLastLog, sIgnoreRhosts,
261         sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
262         sStrictModes, sEmptyPasswd, sTCPKeepAlive,
263         sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
264         sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
265         sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
266         sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
267         sBanner, sUseDNS, sHostbasedAuthentication,
268         sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
269         sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
270         sGssAuthentication, sGssCleanupCreds, sAcceptEnv,
271         sUsePrivilegeSeparation,
272         sDeprecated, sUnsupported
273 } ServerOpCodes;
274
275 /* Textual representation of the tokens. */
276 static struct {
277         const char *name;
278         ServerOpCodes opcode;
279 } keywords[] = {
280         /* Portable-specific options */
281 #ifdef USE_PAM
282         { "usepam", sUsePAM },
283 #else
284         { "usepam", sUnsupported },
285 #endif
286         { "pamauthenticationviakbdint", sDeprecated },
287         /* Standard Options */
288         { "port", sPort },
289         { "hostkey", sHostKeyFile },
290         { "hostdsakey", sHostKeyFile },                                 /* alias */
291         { "pidfile", sPidFile },
292         { "serverkeybits", sServerKeyBits },
293         { "logingracetime", sLoginGraceTime },
294         { "keyregenerationinterval", sKeyRegenerationTime },
295         { "permitrootlogin", sPermitRootLogin },
296         { "syslogfacility", sLogFacility },
297         { "loglevel", sLogLevel },
298         { "rhostsauthentication", sDeprecated },
299         { "rhostsrsaauthentication", sRhostsRSAAuthentication },
300         { "hostbasedauthentication", sHostbasedAuthentication },
301         { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
302         { "rsaauthentication", sRSAAuthentication },
303         { "pubkeyauthentication", sPubkeyAuthentication },
304         { "dsaauthentication", sPubkeyAuthentication },                 /* alias */
305 #ifdef KRB5
306         { "kerberosauthentication", sKerberosAuthentication },
307         { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
308         { "kerberosticketcleanup", sKerberosTicketCleanup },
309 #ifdef USE_AFS
310         { "kerberosgetafstoken", sKerberosGetAFSToken },
311 #else
312         { "kerberosgetafstoken", sUnsupported },
313 #endif
314 #else
315         { "kerberosauthentication", sUnsupported },
316         { "kerberosorlocalpasswd", sUnsupported },
317         { "kerberosticketcleanup", sUnsupported },
318         { "kerberosgetafstoken", sUnsupported },
319 #endif
320         { "kerberostgtpassing", sUnsupported },
321         { "afstokenpassing", sUnsupported },
322 #ifdef GSSAPI
323         { "gssapiauthentication", sGssAuthentication },
324         { "gssapicleanupcredentials", sGssCleanupCreds },
325 #else
326         { "gssapiauthentication", sUnsupported },
327         { "gssapicleanupcredentials", sUnsupported },
328 #endif
329         { "passwordauthentication", sPasswordAuthentication },
330         { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
331         { "challengeresponseauthentication", sChallengeResponseAuthentication },
332         { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
333         { "checkmail", sDeprecated },
334         { "listenaddress", sListenAddress },
335         { "printmotd", sPrintMotd },
336         { "printlastlog", sPrintLastLog },
337         { "ignorerhosts", sIgnoreRhosts },
338         { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
339         { "x11forwarding", sX11Forwarding },
340         { "x11displayoffset", sX11DisplayOffset },
341         { "x11uselocalhost", sX11UseLocalhost },
342         { "xauthlocation", sXAuthLocation },
343         { "strictmodes", sStrictModes },
344         { "permitemptypasswords", sEmptyPasswd },
345         { "permituserenvironment", sPermitUserEnvironment },
346         { "uselogin", sUseLogin },
347         { "compression", sCompression },
348         { "tcpkeepalive", sTCPKeepAlive },
349         { "keepalive", sTCPKeepAlive },                         /* obsolete alias */
350         { "allowtcpforwarding", sAllowTcpForwarding },
351         { "allowusers", sAllowUsers },
352         { "denyusers", sDenyUsers },
353         { "allowgroups", sAllowGroups },
354         { "denygroups", sDenyGroups },
355         { "ciphers", sCiphers },
356         { "macs", sMacs },
357         { "protocol", sProtocol },
358         { "gatewayports", sGatewayPorts },
359         { "subsystem", sSubsystem },
360         { "maxstartups", sMaxStartups },
361         { "banner", sBanner },
362         { "usedns", sUseDNS },
363         { "verifyreversemapping", sDeprecated },
364         { "reversemappingcheck", sDeprecated },
365         { "clientaliveinterval", sClientAliveInterval },
366         { "clientalivecountmax", sClientAliveCountMax },
367         { "authorizedkeysfile", sAuthorizedKeysFile },
368         { "authorizedkeysfile2", sAuthorizedKeysFile2 },
369         { "useprivilegeseparation", sUsePrivilegeSeparation},
370         { "acceptenv", sAcceptEnv },
371         { NULL, sBadOption }
372 };
373
374 /*
375  * Returns the number of the token pointed to by cp or sBadOption.
376  */
377
378 static ServerOpCodes
379 parse_token(const char *cp, const char *filename,
380             int linenum)
381 {
382         u_int i;
383
384         for (i = 0; keywords[i].name; i++)
385                 if (strcasecmp(cp, keywords[i].name) == 0)
386                         return keywords[i].opcode;
387
388         error("%s: line %d: Bad configuration option: %s",
389             filename, linenum, cp);
390         return sBadOption;
391 }
392
393 static void
394 add_listen_addr(ServerOptions *options, char *addr, u_short port)
395 {
396         int i;
397
398         if (options->num_ports == 0)
399                 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
400         if (port == 0)
401                 for (i = 0; i < options->num_ports; i++)
402                         add_one_listen_addr(options, addr, options->ports[i]);
403         else
404                 add_one_listen_addr(options, addr, port);
405 }
406
407 static void
408 add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
409 {
410         struct addrinfo hints, *ai, *aitop;
411         char strport[NI_MAXSERV];
412         int gaierr;
413
414         memset(&hints, 0, sizeof(hints));
415         hints.ai_family = IPv4or6;
416         hints.ai_socktype = SOCK_STREAM;
417         hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
418         snprintf(strport, sizeof strport, "%u", port);
419         if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
420                 fatal("bad addr or host: %s (%s)",
421                     addr ? addr : "<NULL>",
422                     gai_strerror(gaierr));
423         for (ai = aitop; ai->ai_next; ai = ai->ai_next)
424                 ;
425         ai->ai_next = options->listen_addrs;
426         options->listen_addrs = aitop;
427 }
428
429 int
430 process_server_config_line(ServerOptions *options, char *line,
431     const char *filename, int linenum)
432 {
433         char *cp, **charptr, *arg, *p;
434         int *intptr, value, i, n;
435         ServerOpCodes opcode;
436
437         cp = line;
438         arg = strdelim(&cp);
439         /* Ignore leading whitespace */
440         if (*arg == '\0')
441                 arg = strdelim(&cp);
442         if (!arg || !*arg || *arg == '#')
443                 return 0;
444         intptr = NULL;
445         charptr = NULL;
446         opcode = parse_token(arg, filename, linenum);
447         switch (opcode) {
448         /* Portable-specific options */
449         case sUsePAM:
450                 intptr = &options->use_pam;
451                 goto parse_flag;
452
453         /* Standard Options */
454         case sBadOption:
455                 return -1;
456         case sPort:
457                 /* ignore ports from configfile if cmdline specifies ports */
458                 if (options->ports_from_cmdline)
459                         return 0;
460                 if (options->listen_addrs != NULL)
461                         fatal("%s line %d: ports must be specified before "
462                             "ListenAddress.", filename, linenum);
463                 if (options->num_ports >= MAX_PORTS)
464                         fatal("%s line %d: too many ports.",
465                             filename, linenum);
466                 arg = strdelim(&cp);
467                 if (!arg || *arg == '\0')
468                         fatal("%s line %d: missing port number.",
469                             filename, linenum);
470                 options->ports[options->num_ports++] = a2port(arg);
471                 if (options->ports[options->num_ports-1] == 0)
472                         fatal("%s line %d: Badly formatted port number.",
473                             filename, linenum);
474                 break;
475
476         case sServerKeyBits:
477                 intptr = &options->server_key_bits;
478 parse_int:
479                 arg = strdelim(&cp);
480                 if (!arg || *arg == '\0')
481                         fatal("%s line %d: missing integer value.",
482                             filename, linenum);
483                 value = atoi(arg);
484                 if (*intptr == -1)
485                         *intptr = value;
486                 break;
487
488         case sLoginGraceTime:
489                 intptr = &options->login_grace_time;
490 parse_time:
491                 arg = strdelim(&cp);
492                 if (!arg || *arg == '\0')
493                         fatal("%s line %d: missing time value.",
494                             filename, linenum);
495                 if ((value = convtime(arg)) == -1)
496                         fatal("%s line %d: invalid time value.",
497                             filename, linenum);
498                 if (*intptr == -1)
499                         *intptr = value;
500                 break;
501
502         case sKeyRegenerationTime:
503                 intptr = &options->key_regeneration_time;
504                 goto parse_time;
505
506         case sListenAddress:
507                 arg = strdelim(&cp);
508                 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
509                         fatal("%s line %d: missing inet addr.",
510                             filename, linenum);
511                 if (*arg == '[') {
512                         if ((p = strchr(arg, ']')) == NULL)
513                                 fatal("%s line %d: bad ipv6 inet addr usage.",
514                                     filename, linenum);
515                         arg++;
516                         memmove(p, p+1, strlen(p+1)+1);
517                 } else if (((p = strchr(arg, ':')) == NULL) ||
518                             (strchr(p+1, ':') != NULL)) {
519                         add_listen_addr(options, arg, 0);
520                         break;
521                 }
522                 if (*p == ':') {
523                         u_short port;
524
525                         p++;
526                         if (*p == '\0')
527                                 fatal("%s line %d: bad inet addr:port usage.",
528                                     filename, linenum);
529                         else {
530                                 *(p-1) = '\0';
531                                 if ((port = a2port(p)) == 0)
532                                         fatal("%s line %d: bad port number.",
533                                             filename, linenum);
534                                 add_listen_addr(options, arg, port);
535                         }
536                 } else if (*p == '\0')
537                         add_listen_addr(options, arg, 0);
538                 else
539                         fatal("%s line %d: bad inet addr usage.",
540                             filename, linenum);
541                 break;
542
543         case sHostKeyFile:
544                 intptr = &options->num_host_key_files;
545                 if (*intptr >= MAX_HOSTKEYS)
546                         fatal("%s line %d: too many host keys specified (max %d).",
547                             filename, linenum, MAX_HOSTKEYS);
548                 charptr = &options->host_key_files[*intptr];
549 parse_filename:
550                 arg = strdelim(&cp);
551                 if (!arg || *arg == '\0')
552                         fatal("%s line %d: missing file name.",
553                             filename, linenum);
554                 if (*charptr == NULL) {
555                         *charptr = tilde_expand_filename(arg, getuid());
556                         /* increase optional counter */
557                         if (intptr != NULL)
558                                 *intptr = *intptr + 1;
559                 }
560                 break;
561
562         case sPidFile:
563                 charptr = &options->pid_file;
564                 goto parse_filename;
565
566         case sPermitRootLogin:
567                 intptr = &options->permit_root_login;
568                 arg = strdelim(&cp);
569                 if (!arg || *arg == '\0')
570                         fatal("%s line %d: missing yes/"
571                             "without-password/forced-commands-only/no "
572                             "argument.", filename, linenum);
573                 value = 0;      /* silence compiler */
574                 if (strcmp(arg, "without-password") == 0)
575                         value = PERMIT_NO_PASSWD;
576                 else if (strcmp(arg, "forced-commands-only") == 0)
577                         value = PERMIT_FORCED_ONLY;
578                 else if (strcmp(arg, "yes") == 0)
579                         value = PERMIT_YES;
580                 else if (strcmp(arg, "no") == 0)
581                         value = PERMIT_NO;
582                 else
583                         fatal("%s line %d: Bad yes/"
584                             "without-password/forced-commands-only/no "
585                             "argument: %s", filename, linenum, arg);
586                 if (*intptr == -1)
587                         *intptr = value;
588                 break;
589
590         case sIgnoreRhosts:
591                 intptr = &options->ignore_rhosts;
592 parse_flag:
593                 arg = strdelim(&cp);
594                 if (!arg || *arg == '\0')
595                         fatal("%s line %d: missing yes/no argument.",
596                             filename, linenum);
597                 value = 0;      /* silence compiler */
598                 if (strcmp(arg, "yes") == 0)
599                         value = 1;
600                 else if (strcmp(arg, "no") == 0)
601                         value = 0;
602                 else
603                         fatal("%s line %d: Bad yes/no argument: %s",
604                                 filename, linenum, arg);
605                 if (*intptr == -1)
606                         *intptr = value;
607                 break;
608
609         case sIgnoreUserKnownHosts:
610                 intptr = &options->ignore_user_known_hosts;
611                 goto parse_flag;
612
613         case sRhostsRSAAuthentication:
614                 intptr = &options->rhosts_rsa_authentication;
615                 goto parse_flag;
616
617         case sHostbasedAuthentication:
618                 intptr = &options->hostbased_authentication;
619                 goto parse_flag;
620
621         case sHostbasedUsesNameFromPacketOnly:
622                 intptr = &options->hostbased_uses_name_from_packet_only;
623                 goto parse_flag;
624
625         case sRSAAuthentication:
626                 intptr = &options->rsa_authentication;
627                 goto parse_flag;
628
629         case sPubkeyAuthentication:
630                 intptr = &options->pubkey_authentication;
631                 goto parse_flag;
632
633         case sKerberosAuthentication:
634                 intptr = &options->kerberos_authentication;
635                 goto parse_flag;
636
637         case sKerberosOrLocalPasswd:
638                 intptr = &options->kerberos_or_local_passwd;
639                 goto parse_flag;
640
641         case sKerberosTicketCleanup:
642                 intptr = &options->kerberos_ticket_cleanup;
643                 goto parse_flag;
644
645         case sKerberosGetAFSToken:
646                 intptr = &options->kerberos_get_afs_token;
647                 goto parse_flag;
648
649         case sGssAuthentication:
650                 intptr = &options->gss_authentication;
651                 goto parse_flag;
652
653         case sGssCleanupCreds:
654                 intptr = &options->gss_cleanup_creds;
655                 goto parse_flag;
656
657         case sPasswordAuthentication:
658                 intptr = &options->password_authentication;
659                 goto parse_flag;
660
661         case sKbdInteractiveAuthentication:
662                 intptr = &options->kbd_interactive_authentication;
663                 goto parse_flag;
664
665         case sChallengeResponseAuthentication:
666                 intptr = &options->challenge_response_authentication;
667                 goto parse_flag;
668
669         case sPrintMotd:
670                 intptr = &options->print_motd;
671                 goto parse_flag;
672
673         case sPrintLastLog:
674                 intptr = &options->print_lastlog;
675                 goto parse_flag;
676
677         case sX11Forwarding:
678                 intptr = &options->x11_forwarding;
679                 goto parse_flag;
680
681         case sX11DisplayOffset:
682                 intptr = &options->x11_display_offset;
683                 goto parse_int;
684
685         case sX11UseLocalhost:
686                 intptr = &options->x11_use_localhost;
687                 goto parse_flag;
688
689         case sXAuthLocation:
690                 charptr = &options->xauth_location;
691                 goto parse_filename;
692
693         case sStrictModes:
694                 intptr = &options->strict_modes;
695                 goto parse_flag;
696
697         case sTCPKeepAlive:
698                 intptr = &options->tcp_keep_alive;
699                 goto parse_flag;
700
701         case sEmptyPasswd:
702                 intptr = &options->permit_empty_passwd;
703                 goto parse_flag;
704
705         case sPermitUserEnvironment:
706                 intptr = &options->permit_user_env;
707                 goto parse_flag;
708
709         case sUseLogin:
710                 intptr = &options->use_login;
711                 goto parse_flag;
712
713         case sCompression:
714                 intptr = &options->compression;
715                 goto parse_flag;
716
717         case sGatewayPorts:
718                 intptr = &options->gateway_ports;
719                 goto parse_flag;
720
721         case sUseDNS:
722                 intptr = &options->use_dns;
723                 goto parse_flag;
724
725         case sLogFacility:
726                 intptr = (int *) &options->log_facility;
727                 arg = strdelim(&cp);
728                 value = log_facility_number(arg);
729                 if (value == SYSLOG_FACILITY_NOT_SET)
730                         fatal("%.200s line %d: unsupported log facility '%s'",
731                             filename, linenum, arg ? arg : "<NONE>");
732                 if (*intptr == -1)
733                         *intptr = (SyslogFacility) value;
734                 break;
735
736         case sLogLevel:
737                 intptr = (int *) &options->log_level;
738                 arg = strdelim(&cp);
739                 value = log_level_number(arg);
740                 if (value == SYSLOG_LEVEL_NOT_SET)
741                         fatal("%.200s line %d: unsupported log level '%s'",
742                             filename, linenum, arg ? arg : "<NONE>");
743                 if (*intptr == -1)
744                         *intptr = (LogLevel) value;
745                 break;
746
747         case sAllowTcpForwarding:
748                 intptr = &options->allow_tcp_forwarding;
749                 goto parse_flag;
750
751         case sUsePrivilegeSeparation:
752                 intptr = &use_privsep;
753                 goto parse_flag;
754
755         case sAllowUsers:
756                 while ((arg = strdelim(&cp)) && *arg != '\0') {
757                         if (options->num_allow_users >= MAX_ALLOW_USERS)
758                                 fatal("%s line %d: too many allow users.",
759                                     filename, linenum);
760                         options->allow_users[options->num_allow_users++] =
761                             xstrdup(arg);
762                 }
763                 break;
764
765         case sDenyUsers:
766                 while ((arg = strdelim(&cp)) && *arg != '\0') {
767                         if (options->num_deny_users >= MAX_DENY_USERS)
768                                 fatal( "%s line %d: too many deny users.",
769                                     filename, linenum);
770                         options->deny_users[options->num_deny_users++] =
771                             xstrdup(arg);
772                 }
773                 break;
774
775         case sAllowGroups:
776                 while ((arg = strdelim(&cp)) && *arg != '\0') {
777                         if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
778                                 fatal("%s line %d: too many allow groups.",
779                                     filename, linenum);
780                         options->allow_groups[options->num_allow_groups++] =
781                             xstrdup(arg);
782                 }
783                 break;
784
785         case sDenyGroups:
786                 while ((arg = strdelim(&cp)) && *arg != '\0') {
787                         if (options->num_deny_groups >= MAX_DENY_GROUPS)
788                                 fatal("%s line %d: too many deny groups.",
789                                     filename, linenum);
790                         options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
791                 }
792                 break;
793
794         case sCiphers:
795                 arg = strdelim(&cp);
796                 if (!arg || *arg == '\0')
797                         fatal("%s line %d: Missing argument.", filename, linenum);
798                 if (!ciphers_valid(arg))
799                         fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
800                             filename, linenum, arg ? arg : "<NONE>");
801                 if (options->ciphers == NULL)
802                         options->ciphers = xstrdup(arg);
803                 break;
804
805         case sMacs:
806                 arg = strdelim(&cp);
807                 if (!arg || *arg == '\0')
808                         fatal("%s line %d: Missing argument.", filename, linenum);
809                 if (!mac_valid(arg))
810                         fatal("%s line %d: Bad SSH2 mac spec '%s'.",
811                             filename, linenum, arg ? arg : "<NONE>");
812                 if (options->macs == NULL)
813                         options->macs = xstrdup(arg);
814                 break;
815
816         case sProtocol:
817                 intptr = &options->protocol;
818                 arg = strdelim(&cp);
819                 if (!arg || *arg == '\0')
820                         fatal("%s line %d: Missing argument.", filename, linenum);
821                 value = proto_spec(arg);
822                 if (value == SSH_PROTO_UNKNOWN)
823                         fatal("%s line %d: Bad protocol spec '%s'.",
824                             filename, linenum, arg ? arg : "<NONE>");
825                 if (*intptr == SSH_PROTO_UNKNOWN)
826                         *intptr = value;
827                 break;
828
829         case sSubsystem:
830                 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
831                         fatal("%s line %d: too many subsystems defined.",
832                             filename, linenum);
833                 }
834                 arg = strdelim(&cp);
835                 if (!arg || *arg == '\0')
836                         fatal("%s line %d: Missing subsystem name.",
837                             filename, linenum);
838                 for (i = 0; i < options->num_subsystems; i++)
839                         if (strcmp(arg, options->subsystem_name[i]) == 0)
840                                 fatal("%s line %d: Subsystem '%s' already defined.",
841                                     filename, linenum, arg);
842                 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
843                 arg = strdelim(&cp);
844                 if (!arg || *arg == '\0')
845                         fatal("%s line %d: Missing subsystem command.",
846                             filename, linenum);
847                 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
848                 options->num_subsystems++;
849                 break;
850
851         case sMaxStartups:
852                 arg = strdelim(&cp);
853                 if (!arg || *arg == '\0')
854                         fatal("%s line %d: Missing MaxStartups spec.",
855                             filename, linenum);
856                 if ((n = sscanf(arg, "%d:%d:%d",
857                     &options->max_startups_begin,
858                     &options->max_startups_rate,
859                     &options->max_startups)) == 3) {
860                         if (options->max_startups_begin >
861                             options->max_startups ||
862                             options->max_startups_rate > 100 ||
863                             options->max_startups_rate < 1)
864                                 fatal("%s line %d: Illegal MaxStartups spec.",
865                                     filename, linenum);
866                 } else if (n != 1)
867                         fatal("%s line %d: Illegal MaxStartups spec.",
868                             filename, linenum);
869                 else
870                         options->max_startups = options->max_startups_begin;
871                 break;
872
873         case sBanner:
874                 charptr = &options->banner;
875                 goto parse_filename;
876         /*
877          * These options can contain %X options expanded at
878          * connect time, so that you can specify paths like:
879          *
880          * AuthorizedKeysFile   /etc/ssh_keys/%u
881          */
882         case sAuthorizedKeysFile:
883         case sAuthorizedKeysFile2:
884                 charptr = (opcode == sAuthorizedKeysFile ) ?
885                     &options->authorized_keys_file :
886                     &options->authorized_keys_file2;
887                 goto parse_filename;
888
889         case sClientAliveInterval:
890                 intptr = &options->client_alive_interval;
891                 goto parse_time;
892
893         case sClientAliveCountMax:
894                 intptr = &options->client_alive_count_max;
895                 goto parse_int;
896
897         case sAcceptEnv:
898                 while ((arg = strdelim(&cp)) && *arg != '\0') {
899                         if (strchr(arg, '=') != NULL)
900                                 fatal("%s line %d: Invalid environment name.",
901                                     filename, linenum);
902                         if (options->num_accept_env >= MAX_ACCEPT_ENV)
903                                 fatal("%s line %d: too many allow env.",
904                                     filename, linenum);
905                         options->accept_env[options->num_accept_env++] =
906                             xstrdup(arg);
907                 }
908                 break;
909
910         case sDeprecated:
911                 logit("%s line %d: Deprecated option %s",
912                     filename, linenum, arg);
913                 while (arg)
914                     arg = strdelim(&cp);
915                 break;
916
917         case sUnsupported:
918                 logit("%s line %d: Unsupported option %s",
919                     filename, linenum, arg);
920                 while (arg)
921                     arg = strdelim(&cp);
922                 break;
923
924         default:
925                 fatal("%s line %d: Missing handler for opcode %s (%d)",
926                     filename, linenum, arg, opcode);
927         }
928         if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
929                 fatal("%s line %d: garbage at end of line; \"%.200s\".",
930                     filename, linenum, arg);
931         return 0;
932 }
933
934 /* Reads the server configuration file. */
935
936 void
937 read_server_config(ServerOptions *options, const char *filename)
938 {
939         int linenum, bad_options = 0;
940         char line[1024];
941         FILE *f;
942
943         debug2("read_server_config: filename %s", filename);
944         f = fopen(filename, "r");
945         if (!f) {
946                 perror(filename);
947                 exit(1);
948         }
949         linenum = 0;
950         while (fgets(line, sizeof(line), f)) {
951                 /* Update line number counter. */
952                 linenum++;
953                 if (process_server_config_line(options, line, filename, linenum) != 0)
954                         bad_options++;
955         }
956         fclose(f);
957         if (bad_options > 0)
958                 fatal("%s: terminating, %d bad configuration options",
959                     filename, bad_options);
960 }
This page took 0.137707 seconds and 5 git commands to generate.