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