blob: 02d06bdad1518721ae9cc0b579c5a35dc2eb4968 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
3 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10004 *
Damien Millere4340be2000-09-16 13:29:08 +11005 * 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".
Damien Miller95def091999-11-25 00:26:21 +110010 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100011
12#include "includes.h"
Ben Lindstrom551ea372001-06-05 18:56:16 +000013RCSID("$OpenBSD: servconf.c,v 1.80 2001/05/18 14:13:29 markus Exp $");
Ben Lindstrom226cfa02001-01-22 05:34:40 +000014
15#ifdef KRB4
16#include <krb.h>
17#endif
18#ifdef AFS
19#include <kafs.h>
20#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100021
22#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000023#include "log.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100024#include "servconf.h"
25#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100026#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000027#include "pathnames.h"
28#include "tildexpand.h"
29#include "misc.h"
30#include "cipher.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000031#include "kex.h"
32#include "mac.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000033
Ben Lindstrom19066a12001-04-12 23:39:26 +000034void add_listen_addr(ServerOptions *options, char *addr, u_short port);
Ben Lindstromc510af42001-04-07 17:25:48 +000035void add_one_listen_addr(ServerOptions *options, char *addr, u_short port);
Damien Miller34132e52000-01-14 15:45:46 +110036
Ben Lindstrom226cfa02001-01-22 05:34:40 +000037/* AF_UNSPEC or AF_INET or AF_INET6 */
38extern int IPv4or6;
39
Damien Millerd4a8b7e1999-10-27 13:42:43 +100040/* Initializes the server options to their default values. */
41
Damien Miller4af51302000-04-16 11:18:38 +100042void
Damien Miller95def091999-11-25 00:26:21 +110043initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044{
Damien Miller95def091999-11-25 00:26:21 +110045 memset(options, 0, sizeof(*options));
Damien Miller34132e52000-01-14 15:45:46 +110046 options->num_ports = 0;
47 options->ports_from_cmdline = 0;
48 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110049 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100050 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110051 options->server_key_bits = -1;
52 options->login_grace_time = -1;
53 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000054 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110055 options->ignore_rhosts = -1;
56 options->ignore_user_known_hosts = -1;
57 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000058 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110059 options->check_mail = -1;
60 options->x11_forwarding = -1;
61 options->x11_display_offset = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100062 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110063 options->strict_modes = -1;
64 options->keepalives = -1;
65 options->log_facility = (SyslogFacility) - 1;
66 options->log_level = (LogLevel) - 1;
67 options->rhosts_authentication = -1;
68 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000069 options->hostbased_authentication = -1;
70 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110071 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110072 options->pubkey_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100073#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +110074 options->kerberos_authentication = -1;
75 options->kerberos_or_local_passwd = -1;
76 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100077#endif
78#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +110079 options->kerberos_tgt_passing = -1;
80 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100081#endif
Damien Miller95def091999-11-25 00:26:21 +110082 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110083 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000084 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110085 options->permit_empty_passwd = -1;
86 options->use_login = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110087 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110088 options->num_allow_users = 0;
89 options->num_deny_users = 0;
90 options->num_allow_groups = 0;
91 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100092 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000093 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +100094 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +100095 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +100096 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +100097 options->max_startups_begin = -1;
98 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +100099 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000100 options->banner = NULL;
Damien Miller33804262001-02-04 23:20:18 +1100101 options->reverse_mapping_check = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000102 options->client_alive_interval = -1;
103 options->client_alive_count_max = -1;
Damien Millerf8154422001-04-25 22:44:14 +1000104 options->pam_authentication_via_kbd_int = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000105}
106
Damien Miller4af51302000-04-16 11:18:38 +1000107void
Damien Miller95def091999-11-25 00:26:21 +1100108fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000109{
Damien Miller0bc1bd82000-11-13 22:57:25 +1100110 if (options->protocol == SSH_PROTO_UNKNOWN)
111 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
112 if (options->num_host_key_files == 0) {
113 /* fill default hostkeys for protocols */
114 if (options->protocol & SSH_PROTO_1)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000115 options->host_key_files[options->num_host_key_files++] = _PATH_HOST_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100116 if (options->protocol & SSH_PROTO_2)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000117 options->host_key_files[options->num_host_key_files++] = _PATH_HOST_DSA_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100118 }
Damien Miller34132e52000-01-14 15:45:46 +1100119 if (options->num_ports == 0)
120 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
121 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000122 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000123 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000124 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100125 if (options->server_key_bits == -1)
126 options->server_key_bits = 768;
127 if (options->login_grace_time == -1)
128 options->login_grace_time = 600;
129 if (options->key_regeneration_time == -1)
130 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000131 if (options->permit_root_login == PERMIT_NOT_SET)
132 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100133 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100134 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100135 if (options->ignore_user_known_hosts == -1)
136 options->ignore_user_known_hosts = 0;
137 if (options->check_mail == -1)
138 options->check_mail = 0;
139 if (options->print_motd == -1)
140 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000141 if (options->print_lastlog == -1)
142 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100143 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100144 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100145 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100146 options->x11_display_offset = 10;
Damien Millerd3a18572000-06-07 19:55:44 +1000147#ifdef XAUTH_PATH
148 if (options->xauth_location == NULL)
149 options->xauth_location = XAUTH_PATH;
150#endif /* XAUTH_PATH */
Damien Miller95def091999-11-25 00:26:21 +1100151 if (options->strict_modes == -1)
152 options->strict_modes = 1;
153 if (options->keepalives == -1)
154 options->keepalives = 1;
155 if (options->log_facility == (SyslogFacility) (-1))
156 options->log_facility = SYSLOG_FACILITY_AUTH;
157 if (options->log_level == (LogLevel) (-1))
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000158 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100159 if (options->rhosts_authentication == -1)
160 options->rhosts_authentication = 0;
161 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100162 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000163 if (options->hostbased_authentication == -1)
164 options->hostbased_authentication = 0;
165 if (options->hostbased_uses_name_from_packet_only == -1)
166 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100167 if (options->rsa_authentication == -1)
168 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100169 if (options->pubkey_authentication == -1)
170 options->pubkey_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000171#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100172 if (options->kerberos_authentication == -1)
173 options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
174 if (options->kerberos_or_local_passwd == -1)
175 options->kerberos_or_local_passwd = 1;
176 if (options->kerberos_ticket_cleanup == -1)
177 options->kerberos_ticket_cleanup = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000178#endif /* KRB4 */
179#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100180 if (options->kerberos_tgt_passing == -1)
181 options->kerberos_tgt_passing = 0;
182 if (options->afs_token_passing == -1)
183 options->afs_token_passing = k_hasafs();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000184#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100185 if (options->password_authentication == -1)
186 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100187 if (options->kbd_interactive_authentication == -1)
188 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000189 if (options->challenge_response_authentication == -1)
190 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100191 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100192 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100193 if (options->use_login == -1)
194 options->use_login = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100195 if (options->allow_tcp_forwarding == -1)
196 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000197 if (options->gateway_ports == -1)
198 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000199 if (options->max_startups == -1)
200 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000201 if (options->max_startups_rate == -1)
202 options->max_startups_rate = 100; /* 100% */
203 if (options->max_startups_begin == -1)
204 options->max_startups_begin = options->max_startups;
Damien Miller33804262001-02-04 23:20:18 +1100205 if (options->reverse_mapping_check == -1)
206 options->reverse_mapping_check = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000207 if (options->client_alive_interval == -1)
208 options->client_alive_interval = 0;
209 if (options->client_alive_count_max == -1)
210 options->client_alive_count_max = 3;
Damien Millerf8154422001-04-25 22:44:14 +1000211 if (options->pam_authentication_via_kbd_int == -1)
212 options->pam_authentication_via_kbd_int = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000213}
214
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000215/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100216typedef enum {
217 sBadOption, /* == unknown option */
218 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
219 sPermitRootLogin, sLogFacility, sLogLevel,
220 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000221#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100222 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223#endif
224#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100225 sKerberosTgtPassing, sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000226#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000227 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100228 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000229 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
230 sX11Forwarding, sX11DisplayOffset,
Ben Lindstromd9cae222001-03-05 07:42:03 +0000231 sStrictModes, sEmptyPasswd, sKeepAlives, sCheckMail,
Damien Miller50a41ed2000-10-16 12:14:42 +1100232 sUseLogin, sAllowTcpForwarding,
233 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000234 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100235 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000236 sBanner, sReverseMappingCheck, sHostbasedAuthentication,
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000237 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerf8154422001-04-25 22:44:14 +1000238 sClientAliveCountMax, sPAMAuthenticationViaKbdInt
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000239} ServerOpCodes;
240
241/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100242static struct {
243 const char *name;
244 ServerOpCodes opcode;
245} keywords[] = {
246 { "port", sPort },
247 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100248 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000249 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100250 { "serverkeybits", sServerKeyBits },
251 { "logingracetime", sLoginGraceTime },
252 { "keyregenerationinterval", sKeyRegenerationTime },
253 { "permitrootlogin", sPermitRootLogin },
254 { "syslogfacility", sLogFacility },
255 { "loglevel", sLogLevel },
256 { "rhostsauthentication", sRhostsAuthentication },
257 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000258 { "hostbasedauthentication", sHostbasedAuthentication },
259 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100260 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100261 { "pubkeyauthentication", sPubkeyAuthentication },
262 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000263#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100264 { "kerberosauthentication", sKerberosAuthentication },
265 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
266 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000267#endif
268#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100269 { "kerberostgtpassing", sKerberosTgtPassing },
270 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000271#endif
Damien Miller95def091999-11-25 00:26:21 +1100272 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100273 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000274 { "challengeresponseauthentication", sChallengeResponseAuthentication },
275 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100276 { "checkmail", sCheckMail },
277 { "listenaddress", sListenAddress },
278 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000279 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100280 { "ignorerhosts", sIgnoreRhosts },
281 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
282 { "x11forwarding", sX11Forwarding },
283 { "x11displayoffset", sX11DisplayOffset },
Damien Millerd3a18572000-06-07 19:55:44 +1000284 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100285 { "strictmodes", sStrictModes },
286 { "permitemptypasswords", sEmptyPasswd },
287 { "uselogin", sUseLogin },
Damien Miller95def091999-11-25 00:26:21 +1100288 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100289 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100290 { "allowusers", sAllowUsers },
291 { "denyusers", sDenyUsers },
292 { "allowgroups", sAllowGroups },
293 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000294 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000295 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000296 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000297 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000298 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000299 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000300 { "banner", sBanner },
Damien Miller33804262001-02-04 23:20:18 +1100301 { "reversemappingcheck", sReverseMappingCheck },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000302 { "clientaliveinterval", sClientAliveInterval },
303 { "clientalivecountmax", sClientAliveCountMax },
Damien Millerf8154422001-04-25 22:44:14 +1000304 { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt },
Damien Miller95def091999-11-25 00:26:21 +1100305 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000306};
307
Damien Miller5428f641999-11-25 11:54:57 +1100308/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000309 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100310 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000311
Damien Miller4af51302000-04-16 11:18:38 +1000312static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100313parse_token(const char *cp, const char *filename,
314 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000315{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000316 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000317
Damien Miller95def091999-11-25 00:26:21 +1100318 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100319 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100320 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000321
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000322 error("%s: line %d: Bad configuration option: %s",
323 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100324 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000325}
326
Damien Miller4af51302000-04-16 11:18:38 +1000327void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000328add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100329{
Damien Miller34132e52000-01-14 15:45:46 +1100330 int i;
331
332 if (options->num_ports == 0)
333 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000334 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000335 for (i = 0; i < options->num_ports; i++)
336 add_one_listen_addr(options, addr, options->ports[i]);
337 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000338 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000339}
340
341void
342add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
343{
344 struct addrinfo hints, *ai, *aitop;
345 char strport[NI_MAXSERV];
346 int gaierr;
347
348 memset(&hints, 0, sizeof(hints));
349 hints.ai_family = IPv4or6;
350 hints.ai_socktype = SOCK_STREAM;
351 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
352 snprintf(strport, sizeof strport, "%d", port);
353 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
354 fatal("bad addr or host: %s (%s)",
355 addr ? addr : "<NULL>",
356 gai_strerror(gaierr));
357 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
358 ;
359 ai->ai_next = options->listen_addrs;
360 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100361}
362
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000363/* Reads the server configuration file. */
364
Damien Miller4af51302000-04-16 11:18:38 +1000365void
Damien Miller95def091999-11-25 00:26:21 +1100366read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000367{
Damien Miller95def091999-11-25 00:26:21 +1100368 FILE *f;
369 char line[1024];
Ben Lindstromc510af42001-04-07 17:25:48 +0000370 char *cp, **charptr, *arg, *p;
Damien Miller95def091999-11-25 00:26:21 +1100371 int linenum, *intptr, value;
372 int bad_options = 0;
373 ServerOpCodes opcode;
Damien Millerf6d9e222000-06-18 14:50:44 +1000374 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000375
Damien Miller95def091999-11-25 00:26:21 +1100376 f = fopen(filename, "r");
377 if (!f) {
378 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000379 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100380 }
381 linenum = 0;
382 while (fgets(line, sizeof(line), f)) {
383 linenum++;
Damien Millerbe484b52000-07-15 14:14:16 +1000384 cp = line;
385 arg = strdelim(&cp);
386 /* Ignore leading whitespace */
387 if (*arg == '\0')
388 arg = strdelim(&cp);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000389 if (!arg || !*arg || *arg == '#')
Damien Miller95def091999-11-25 00:26:21 +1100390 continue;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100391 intptr = NULL;
392 charptr = NULL;
Damien Miller37023962000-07-11 17:31:38 +1000393 opcode = parse_token(arg, filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100394 switch (opcode) {
395 case sBadOption:
396 bad_options++;
397 continue;
398 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100399 /* ignore ports from configfile if cmdline specifies ports */
400 if (options->ports_from_cmdline)
401 continue;
402 if (options->listen_addrs != NULL)
403 fatal("%s line %d: ports must be specified before "
Ben Lindstroma6218b82001-05-03 22:39:11 +0000404 "ListenAdress.", filename, linenum);
Damien Miller34132e52000-01-14 15:45:46 +1100405 if (options->num_ports >= MAX_PORTS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000406 fatal("%s line %d: too many ports.",
Damien Miller4af51302000-04-16 11:18:38 +1000407 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000408 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000409 if (!arg || *arg == '\0')
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000410 fatal("%s line %d: missing port number.",
Damien Miller34132e52000-01-14 15:45:46 +1100411 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000412 options->ports[options->num_ports++] = a2port(arg);
413 if (options->ports[options->num_ports-1] == 0)
414 fatal("%s line %d: Badly formatted port number.",
415 filename, linenum);
Damien Miller34132e52000-01-14 15:45:46 +1100416 break;
417
418 case sServerKeyBits:
419 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100420parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000421 arg = strdelim(&cp);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000422 if (!arg || *arg == '\0')
423 fatal("%s line %d: missing integer value.",
424 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000425 value = atoi(arg);
Damien Miller95def091999-11-25 00:26:21 +1100426 if (*intptr == -1)
427 *intptr = value;
428 break;
Damien Miller32265091999-11-12 11:33:04 +1100429
Damien Miller95def091999-11-25 00:26:21 +1100430 case sLoginGraceTime:
431 intptr = &options->login_grace_time;
432 goto parse_int;
433
434 case sKeyRegenerationTime:
435 intptr = &options->key_regeneration_time;
436 goto parse_int;
437
438 case sListenAddress:
Damien Millerbe484b52000-07-15 14:14:16 +1000439 arg = strdelim(&cp);
Ben Lindstromc510af42001-04-07 17:25:48 +0000440 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000441 fatal("%s line %d: missing inet addr.",
Damien Miller34132e52000-01-14 15:45:46 +1100442 filename, linenum);
Ben Lindstromc510af42001-04-07 17:25:48 +0000443 if (*arg == '[') {
444 if ((p = strchr(arg, ']')) == NULL)
445 fatal("%s line %d: bad ipv6 inet addr usage.",
446 filename, linenum);
447 arg++;
448 memmove(p, p+1, strlen(p+1)+1);
449 } else if (((p = strchr(arg, ':')) == NULL) ||
450 (strchr(p+1, ':') != NULL)) {
Ben Lindstrom19066a12001-04-12 23:39:26 +0000451 add_listen_addr(options, arg, 0);
Ben Lindstromc510af42001-04-07 17:25:48 +0000452 break;
453 }
454 if (*p == ':') {
Ben Lindstrom19066a12001-04-12 23:39:26 +0000455 u_short port;
456
Ben Lindstromc510af42001-04-07 17:25:48 +0000457 p++;
458 if (*p == '\0')
459 fatal("%s line %d: bad inet addr:port usage.",
460 filename, linenum);
461 else {
462 *(p-1) = '\0';
Ben Lindstrom19066a12001-04-12 23:39:26 +0000463 if ((port = a2port(p)) == 0)
464 fatal("%s line %d: bad port number.",
465 filename, linenum);
466 add_listen_addr(options, arg, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000467 }
468 } else if (*p == '\0')
Ben Lindstrom19066a12001-04-12 23:39:26 +0000469 add_listen_addr(options, arg, 0);
Ben Lindstromc510af42001-04-07 17:25:48 +0000470 else
471 fatal("%s line %d: bad inet addr usage.",
472 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100473 break;
474
475 case sHostKeyFile:
Damien Miller0bc1bd82000-11-13 22:57:25 +1100476 intptr = &options->num_host_key_files;
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000477 if (*intptr >= MAX_HOSTKEYS)
478 fatal("%s line %d: too many host keys specified (max %d).",
Damien Miller0bc1bd82000-11-13 22:57:25 +1100479 filename, linenum, MAX_HOSTKEYS);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100480 charptr = &options->host_key_files[*intptr];
Damien Millerd3a18572000-06-07 19:55:44 +1000481parse_filename:
Damien Millerbe484b52000-07-15 14:14:16 +1000482 arg = strdelim(&cp);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000483 if (!arg || *arg == '\0')
484 fatal("%s line %d: missing file name.",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000485 filename, linenum);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100486 if (*charptr == NULL) {
Damien Miller37023962000-07-11 17:31:38 +1000487 *charptr = tilde_expand_filename(arg, getuid());
Damien Miller0bc1bd82000-11-13 22:57:25 +1100488 /* increase optional counter */
489 if (intptr != NULL)
490 *intptr = *intptr + 1;
491 }
Damien Miller6f83b8e2000-05-02 09:23:45 +1000492 break;
493
494 case sPidFile:
495 charptr = &options->pid_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000496 goto parse_filename;
Damien Miller95def091999-11-25 00:26:21 +1100497
Damien Miller95def091999-11-25 00:26:21 +1100498 case sPermitRootLogin:
499 intptr = &options->permit_root_login;
Damien Millerbe484b52000-07-15 14:14:16 +1000500 arg = strdelim(&cp);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000501 if (!arg || *arg == '\0')
502 fatal("%s line %d: missing yes/"
Ben Lindstrom35f1f4e2001-03-06 01:02:41 +0000503 "without-password/forced-commands-only/no "
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000504 "argument.", filename, linenum);
505 value = 0; /* silence compiler */
Damien Miller37023962000-07-11 17:31:38 +1000506 if (strcmp(arg, "without-password") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000507 value = PERMIT_NO_PASSWD;
508 else if (strcmp(arg, "forced-commands-only") == 0)
509 value = PERMIT_FORCED_ONLY;
Damien Miller37023962000-07-11 17:31:38 +1000510 else if (strcmp(arg, "yes") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000511 value = PERMIT_YES;
Damien Miller37023962000-07-11 17:31:38 +1000512 else if (strcmp(arg, "no") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000513 value = PERMIT_NO;
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000514 else
515 fatal("%s line %d: Bad yes/"
Ben Lindstromd8a90212001-02-15 03:08:27 +0000516 "without-password/forced-commands-only/no "
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000517 "argument: %s", filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100518 if (*intptr == -1)
519 *intptr = value;
520 break;
521
522 case sIgnoreRhosts:
523 intptr = &options->ignore_rhosts;
524parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000525 arg = strdelim(&cp);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000526 if (!arg || *arg == '\0')
527 fatal("%s line %d: missing yes/no argument.",
528 filename, linenum);
529 value = 0; /* silence compiler */
Damien Miller37023962000-07-11 17:31:38 +1000530 if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100531 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000532 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100533 value = 0;
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000534 else
535 fatal("%s line %d: Bad yes/no argument: %s",
Damien Miller37023962000-07-11 17:31:38 +1000536 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100537 if (*intptr == -1)
538 *intptr = value;
539 break;
540
541 case sIgnoreUserKnownHosts:
542 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100543 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100544
545 case sRhostsAuthentication:
546 intptr = &options->rhosts_authentication;
547 goto parse_flag;
548
549 case sRhostsRSAAuthentication:
550 intptr = &options->rhosts_rsa_authentication;
551 goto parse_flag;
552
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000553 case sHostbasedAuthentication:
554 intptr = &options->hostbased_authentication;
555 goto parse_flag;
556
557 case sHostbasedUsesNameFromPacketOnly:
558 intptr = &options->hostbased_uses_name_from_packet_only;
559 goto parse_flag;
560
Damien Miller95def091999-11-25 00:26:21 +1100561 case sRSAAuthentication:
562 intptr = &options->rsa_authentication;
563 goto parse_flag;
564
Damien Miller0bc1bd82000-11-13 22:57:25 +1100565 case sPubkeyAuthentication:
566 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000567 goto parse_flag;
568
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000569#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100570 case sKerberosAuthentication:
571 intptr = &options->kerberos_authentication;
572 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000573
Damien Miller95def091999-11-25 00:26:21 +1100574 case sKerberosOrLocalPasswd:
575 intptr = &options->kerberos_or_local_passwd;
576 goto parse_flag;
577
578 case sKerberosTicketCleanup:
579 intptr = &options->kerberos_ticket_cleanup;
580 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000581#endif
Damien Miller95def091999-11-25 00:26:21 +1100582
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000583#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100584 case sKerberosTgtPassing:
585 intptr = &options->kerberos_tgt_passing;
586 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000587
Damien Miller95def091999-11-25 00:26:21 +1100588 case sAFSTokenPassing:
589 intptr = &options->afs_token_passing;
590 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000591#endif
592
Damien Miller95def091999-11-25 00:26:21 +1100593 case sPasswordAuthentication:
594 intptr = &options->password_authentication;
595 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000596
Damien Miller874d77b2000-10-14 16:23:11 +1100597 case sKbdInteractiveAuthentication:
598 intptr = &options->kbd_interactive_authentication;
599 goto parse_flag;
600
Damien Miller95def091999-11-25 00:26:21 +1100601 case sCheckMail:
602 intptr = &options->check_mail;
603 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000604
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000605 case sChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000606 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100607 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000608
Damien Miller95def091999-11-25 00:26:21 +1100609 case sPrintMotd:
610 intptr = &options->print_motd;
611 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000612
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000613 case sPrintLastLog:
614 intptr = &options->print_lastlog;
615 goto parse_flag;
616
Damien Miller95def091999-11-25 00:26:21 +1100617 case sX11Forwarding:
618 intptr = &options->x11_forwarding;
619 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000620
Damien Miller95def091999-11-25 00:26:21 +1100621 case sX11DisplayOffset:
622 intptr = &options->x11_display_offset;
623 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000624
Damien Millerd3a18572000-06-07 19:55:44 +1000625 case sXAuthLocation:
626 charptr = &options->xauth_location;
627 goto parse_filename;
Kevin Stevesef4eea92001-02-05 12:42:17 +0000628
Damien Miller95def091999-11-25 00:26:21 +1100629 case sStrictModes:
630 intptr = &options->strict_modes;
631 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000632
Damien Miller95def091999-11-25 00:26:21 +1100633 case sKeepAlives:
634 intptr = &options->keepalives;
635 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000636
Damien Miller95def091999-11-25 00:26:21 +1100637 case sEmptyPasswd:
638 intptr = &options->permit_empty_passwd;
639 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000640
Damien Miller95def091999-11-25 00:26:21 +1100641 case sUseLogin:
642 intptr = &options->use_login;
643 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100644
Damien Millere247cc42000-05-07 12:03:14 +1000645 case sGatewayPorts:
646 intptr = &options->gateway_ports;
647 goto parse_flag;
648
Damien Miller33804262001-02-04 23:20:18 +1100649 case sReverseMappingCheck:
650 intptr = &options->reverse_mapping_check;
651 goto parse_flag;
652
Damien Miller95def091999-11-25 00:26:21 +1100653 case sLogFacility:
654 intptr = (int *) &options->log_facility;
Damien Millerbe484b52000-07-15 14:14:16 +1000655 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000656 value = log_facility_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100657 if (value == (SyslogFacility) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000658 fatal("%.200s line %d: unsupported log facility '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000659 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100660 if (*intptr == -1)
661 *intptr = (SyslogFacility) value;
662 break;
663
664 case sLogLevel:
665 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000666 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000667 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100668 if (value == (LogLevel) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000669 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000670 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100671 if (*intptr == -1)
672 *intptr = (LogLevel) value;
673 break;
674
Damien Miller50a41ed2000-10-16 12:14:42 +1100675 case sAllowTcpForwarding:
676 intptr = &options->allow_tcp_forwarding;
677 goto parse_flag;
678
Damien Miller95def091999-11-25 00:26:21 +1100679 case sAllowUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000680 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000681 if (options->num_allow_users >= MAX_ALLOW_USERS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000682 fatal("%s line %d: too many allow users.",
Damien Miller78928792000-04-12 20:17:38 +1000683 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000684 options->allow_users[options->num_allow_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100685 }
686 break;
687
688 case sDenyUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000689 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000690 if (options->num_deny_users >= MAX_DENY_USERS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000691 fatal( "%s line %d: too many deny users.",
Damien Miller78928792000-04-12 20:17:38 +1000692 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000693 options->deny_users[options->num_deny_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100694 }
695 break;
696
697 case sAllowGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000698 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000699 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000700 fatal("%s line %d: too many allow groups.",
Damien Miller78928792000-04-12 20:17:38 +1000701 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000702 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100703 }
704 break;
705
706 case sDenyGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000707 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000708 if (options->num_deny_groups >= MAX_DENY_GROUPS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000709 fatal("%s line %d: too many deny groups.",
Damien Miller78928792000-04-12 20:17:38 +1000710 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000711 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100712 }
713 break;
714
Damien Miller78928792000-04-12 20:17:38 +1000715 case sCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000716 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000717 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000718 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000719 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000720 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000721 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000722 if (options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000723 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000724 break;
725
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000726 case sMacs:
727 arg = strdelim(&cp);
728 if (!arg || *arg == '\0')
729 fatal("%s line %d: Missing argument.", filename, linenum);
730 if (!mac_valid(arg))
731 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
732 filename, linenum, arg ? arg : "<NONE>");
733 if (options->macs == NULL)
734 options->macs = xstrdup(arg);
735 break;
736
Damien Miller78928792000-04-12 20:17:38 +1000737 case sProtocol:
738 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000739 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000740 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000741 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000742 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000743 if (value == SSH_PROTO_UNKNOWN)
744 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000745 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000746 if (*intptr == SSH_PROTO_UNKNOWN)
747 *intptr = value;
748 break;
749
Damien Millerf6d9e222000-06-18 14:50:44 +1000750 case sSubsystem:
751 if(options->num_subsystems >= MAX_SUBSYSTEMS) {
752 fatal("%s line %d: too many subsystems defined.",
753 filename, linenum);
754 }
Damien Millerbe484b52000-07-15 14:14:16 +1000755 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000756 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000757 fatal("%s line %d: Missing subsystem name.",
758 filename, linenum);
759 for (i = 0; i < options->num_subsystems; i++)
Damien Miller37023962000-07-11 17:31:38 +1000760 if(strcmp(arg, options->subsystem_name[i]) == 0)
Damien Millerf6d9e222000-06-18 14:50:44 +1000761 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller37023962000-07-11 17:31:38 +1000762 filename, linenum, arg);
763 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000764 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000765 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000766 fatal("%s line %d: Missing subsystem command.",
767 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000768 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Millerf6d9e222000-06-18 14:50:44 +1000769 options->num_subsystems++;
770 break;
771
Damien Miller37023962000-07-11 17:31:38 +1000772 case sMaxStartups:
Damien Miller942da032000-08-18 13:59:06 +1000773 arg = strdelim(&cp);
774 if (!arg || *arg == '\0')
775 fatal("%s line %d: Missing MaxStartups spec.",
776 filename, linenum);
777 if (sscanf(arg, "%d:%d:%d",
778 &options->max_startups_begin,
779 &options->max_startups_rate,
780 &options->max_startups) == 3) {
781 if (options->max_startups_begin >
782 options->max_startups ||
783 options->max_startups_rate > 100 ||
784 options->max_startups_rate < 1)
785 fatal("%s line %d: Illegal MaxStartups spec.",
786 filename, linenum);
787 break;
788 }
Damien Miller37023962000-07-11 17:31:38 +1000789 intptr = &options->max_startups;
790 goto parse_int;
791
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000792 case sBanner:
793 charptr = &options->banner;
794 goto parse_filename;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000795 case sClientAliveInterval:
796 intptr = &options->client_alive_interval;
797 goto parse_int;
798 case sClientAliveCountMax:
799 intptr = &options->client_alive_count_max;
800 goto parse_int;
Damien Millerf8154422001-04-25 22:44:14 +1000801 case sPAMAuthenticationViaKbdInt:
802 intptr = &options->pam_authentication_via_kbd_int;
803 goto parse_flag;
804
Damien Miller95def091999-11-25 00:26:21 +1100805 default:
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000806 fatal("%s line %d: Missing handler for opcode %s (%d)",
807 filename, linenum, arg, opcode);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000808 }
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000809 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
810 fatal("%s line %d: garbage at end of line; \"%.200s\".",
811 filename, linenum, arg);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000812 }
Damien Miller95def091999-11-25 00:26:21 +1100813 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000814 if (bad_options > 0)
815 fatal("%s: terminating, %d bad configuration options",
816 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000817}