blob: 0f16c851e4064b756b02a58f1e297b7eed9afa0d [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"
Damien Millerc4b7fea2001-07-14 12:20:32 +100013RCSID("$OpenBSD: servconf.c,v 1.88 2001/07/11 00:24:53 itojun Exp $");
Ben Lindstrom226cfa02001-01-22 05:34:40 +000014
Damien Millerc4b7fea2001-07-14 12:20:32 +100015#if defined(KRB4) || defined(KRB5)
Ben Lindstrom226cfa02001-01-22 05:34:40 +000016#include <krb.h>
17#endif
Ben Lindstromeb7a84c2001-07-04 04:48:36 +000018#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 Lindstrombba81212001-06-25 05:01:22 +000034static void add_listen_addr(ServerOptions *, char *, u_short);
35static void add_one_listen_addr(ServerOptions *, char *, u_short);
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;
Ben Lindstromec95ed92001-07-04 04:21:14 +000073#if defined(KRB4) || defined(KRB5)
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
Ben Lindstromec95ed92001-07-04 04:21:14 +000078#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110079 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +000080#endif
81#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +110082 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100083#endif
Damien Miller95def091999-11-25 00:26:21 +110084 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110085 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000086 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110087 options->permit_empty_passwd = -1;
88 options->use_login = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110089 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110090 options->num_allow_users = 0;
91 options->num_deny_users = 0;
92 options->num_allow_groups = 0;
93 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100094 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000095 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +100096 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +100097 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +100098 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +100099 options->max_startups_begin = -1;
100 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000101 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000102 options->banner = NULL;
Damien Miller33804262001-02-04 23:20:18 +1100103 options->reverse_mapping_check = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000104 options->client_alive_interval = -1;
105 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000106 options->authorized_keys_file = NULL;
107 options->authorized_keys_file2 = NULL;
Damien Millerf8154422001-04-25 22:44:14 +1000108 options->pam_authentication_via_kbd_int = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000109}
110
Damien Miller4af51302000-04-16 11:18:38 +1000111void
Damien Miller95def091999-11-25 00:26:21 +1100112fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000113{
Damien Miller0bc1bd82000-11-13 22:57:25 +1100114 if (options->protocol == SSH_PROTO_UNKNOWN)
115 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
116 if (options->num_host_key_files == 0) {
117 /* fill default hostkeys for protocols */
118 if (options->protocol & SSH_PROTO_1)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000119 options->host_key_files[options->num_host_key_files++] = _PATH_HOST_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100120 if (options->protocol & SSH_PROTO_2)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000121 options->host_key_files[options->num_host_key_files++] = _PATH_HOST_DSA_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100122 }
Damien Miller34132e52000-01-14 15:45:46 +1100123 if (options->num_ports == 0)
124 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
125 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000126 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000127 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000128 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100129 if (options->server_key_bits == -1)
130 options->server_key_bits = 768;
131 if (options->login_grace_time == -1)
132 options->login_grace_time = 600;
133 if (options->key_regeneration_time == -1)
134 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000135 if (options->permit_root_login == PERMIT_NOT_SET)
136 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100137 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100138 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100139 if (options->ignore_user_known_hosts == -1)
140 options->ignore_user_known_hosts = 0;
141 if (options->check_mail == -1)
142 options->check_mail = 0;
143 if (options->print_motd == -1)
144 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000145 if (options->print_lastlog == -1)
146 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100147 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100148 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100149 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100150 options->x11_display_offset = 10;
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000151#ifdef _PATH_XAUTH
Damien Millerd3a18572000-06-07 19:55:44 +1000152 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000153 options->xauth_location = _PATH_XAUTH;
154#endif
Damien Miller95def091999-11-25 00:26:21 +1100155 if (options->strict_modes == -1)
156 options->strict_modes = 1;
157 if (options->keepalives == -1)
158 options->keepalives = 1;
159 if (options->log_facility == (SyslogFacility) (-1))
160 options->log_facility = SYSLOG_FACILITY_AUTH;
161 if (options->log_level == (LogLevel) (-1))
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000162 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100163 if (options->rhosts_authentication == -1)
164 options->rhosts_authentication = 0;
165 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100166 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000167 if (options->hostbased_authentication == -1)
168 options->hostbased_authentication = 0;
169 if (options->hostbased_uses_name_from_packet_only == -1)
170 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100171 if (options->rsa_authentication == -1)
172 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100173 if (options->pubkey_authentication == -1)
174 options->pubkey_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000175#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100176 if (options->kerberos_authentication == -1)
177 options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
178 if (options->kerberos_or_local_passwd == -1)
179 options->kerberos_or_local_passwd = 1;
180 if (options->kerberos_ticket_cleanup == -1)
181 options->kerberos_ticket_cleanup = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000182#endif
183#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100184 if (options->kerberos_tgt_passing == -1)
185 options->kerberos_tgt_passing = 0;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000186#endif
187#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100188 if (options->afs_token_passing == -1)
189 options->afs_token_passing = k_hasafs();
Ben Lindstromec95ed92001-07-04 04:21:14 +0000190#endif
Damien Miller95def091999-11-25 00:26:21 +1100191 if (options->password_authentication == -1)
192 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100193 if (options->kbd_interactive_authentication == -1)
194 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000195 if (options->challenge_response_authentication == -1)
196 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100197 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100198 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100199 if (options->use_login == -1)
200 options->use_login = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100201 if (options->allow_tcp_forwarding == -1)
202 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000203 if (options->gateway_ports == -1)
204 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000205 if (options->max_startups == -1)
206 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000207 if (options->max_startups_rate == -1)
208 options->max_startups_rate = 100; /* 100% */
209 if (options->max_startups_begin == -1)
210 options->max_startups_begin = options->max_startups;
Damien Miller33804262001-02-04 23:20:18 +1100211 if (options->reverse_mapping_check == -1)
212 options->reverse_mapping_check = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000213 if (options->client_alive_interval == -1)
214 options->client_alive_interval = 0;
215 if (options->client_alive_count_max == -1)
216 options->client_alive_count_max = 3;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000217 if (options->authorized_keys_file == NULL)
Kevin Steves27fd1922001-07-04 18:29:14 +0000218 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000219 if (options->authorized_keys_file2 == NULL)
Kevin Steves27fd1922001-07-04 18:29:14 +0000220 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
Damien Millerf8154422001-04-25 22:44:14 +1000221 if (options->pam_authentication_via_kbd_int == -1)
222 options->pam_authentication_via_kbd_int = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223}
224
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000225/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100226typedef enum {
227 sBadOption, /* == unknown option */
228 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
229 sPermitRootLogin, sLogFacility, sLogLevel,
230 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Ben Lindstromec95ed92001-07-04 04:21:14 +0000231#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100232 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000233#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000234#if defined(AFS) || defined(KRB5)
235 sKerberosTgtPassing,
236#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000237#ifdef AFS
Ben Lindstromec95ed92001-07-04 04:21:14 +0000238 sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000239#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000240 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100241 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000242 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
243 sX11Forwarding, sX11DisplayOffset,
Ben Lindstromd9cae222001-03-05 07:42:03 +0000244 sStrictModes, sEmptyPasswd, sKeepAlives, sCheckMail,
Damien Miller50a41ed2000-10-16 12:14:42 +1100245 sUseLogin, sAllowTcpForwarding,
246 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000247 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100248 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000249 sBanner, sReverseMappingCheck, sHostbasedAuthentication,
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000250 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000251 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
252 sPAMAuthenticationViaKbdInt
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000253} ServerOpCodes;
254
255/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100256static struct {
257 const char *name;
258 ServerOpCodes opcode;
259} keywords[] = {
260 { "port", sPort },
261 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100262 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000263 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100264 { "serverkeybits", sServerKeyBits },
265 { "logingracetime", sLoginGraceTime },
266 { "keyregenerationinterval", sKeyRegenerationTime },
267 { "permitrootlogin", sPermitRootLogin },
268 { "syslogfacility", sLogFacility },
269 { "loglevel", sLogLevel },
270 { "rhostsauthentication", sRhostsAuthentication },
271 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000272 { "hostbasedauthentication", sHostbasedAuthentication },
273 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100274 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100275 { "pubkeyauthentication", sPubkeyAuthentication },
276 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000277#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100278 { "kerberosauthentication", sKerberosAuthentication },
279 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
280 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000281#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000282#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100283 { "kerberostgtpassing", sKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000284#endif
285#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100286 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000287#endif
Damien Miller95def091999-11-25 00:26:21 +1100288 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100289 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000290 { "challengeresponseauthentication", sChallengeResponseAuthentication },
291 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100292 { "checkmail", sCheckMail },
293 { "listenaddress", sListenAddress },
294 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000295 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100296 { "ignorerhosts", sIgnoreRhosts },
297 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
298 { "x11forwarding", sX11Forwarding },
299 { "x11displayoffset", sX11DisplayOffset },
Damien Millerd3a18572000-06-07 19:55:44 +1000300 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100301 { "strictmodes", sStrictModes },
302 { "permitemptypasswords", sEmptyPasswd },
303 { "uselogin", sUseLogin },
Damien Miller95def091999-11-25 00:26:21 +1100304 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100305 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100306 { "allowusers", sAllowUsers },
307 { "denyusers", sDenyUsers },
308 { "allowgroups", sAllowGroups },
309 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000310 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000311 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000312 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000313 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000314 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000315 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000316 { "banner", sBanner },
Damien Miller33804262001-02-04 23:20:18 +1100317 { "reversemappingcheck", sReverseMappingCheck },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000318 { "clientaliveinterval", sClientAliveInterval },
319 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000320 { "authorizedkeysfile", sAuthorizedKeysFile },
321 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Damien Millerf8154422001-04-25 22:44:14 +1000322 { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt },
Damien Miller95def091999-11-25 00:26:21 +1100323 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000324};
325
Damien Miller5428f641999-11-25 11:54:57 +1100326/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000327 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100328 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000329
Damien Miller4af51302000-04-16 11:18:38 +1000330static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100331parse_token(const char *cp, const char *filename,
332 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000333{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000334 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000335
Damien Miller95def091999-11-25 00:26:21 +1100336 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100337 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100338 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000339
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000340 error("%s: line %d: Bad configuration option: %s",
341 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100342 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000343}
344
Ben Lindstrombba81212001-06-25 05:01:22 +0000345static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000346add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100347{
Damien Miller34132e52000-01-14 15:45:46 +1100348 int i;
349
350 if (options->num_ports == 0)
351 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000352 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000353 for (i = 0; i < options->num_ports; i++)
354 add_one_listen_addr(options, addr, options->ports[i]);
355 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000356 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000357}
358
Ben Lindstrombba81212001-06-25 05:01:22 +0000359static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000360add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
361{
362 struct addrinfo hints, *ai, *aitop;
363 char strport[NI_MAXSERV];
364 int gaierr;
365
366 memset(&hints, 0, sizeof(hints));
367 hints.ai_family = IPv4or6;
368 hints.ai_socktype = SOCK_STREAM;
369 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
370 snprintf(strport, sizeof strport, "%d", port);
371 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
372 fatal("bad addr or host: %s (%s)",
373 addr ? addr : "<NULL>",
374 gai_strerror(gaierr));
375 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
376 ;
377 ai->ai_next = options->listen_addrs;
378 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100379}
380
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000381/* Reads the server configuration file. */
382
Damien Miller4af51302000-04-16 11:18:38 +1000383void
Damien Miller95def091999-11-25 00:26:21 +1100384read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000385{
Damien Miller95def091999-11-25 00:26:21 +1100386 FILE *f;
387 char line[1024];
Ben Lindstromc510af42001-04-07 17:25:48 +0000388 char *cp, **charptr, *arg, *p;
Damien Miller95def091999-11-25 00:26:21 +1100389 int linenum, *intptr, value;
390 int bad_options = 0;
391 ServerOpCodes opcode;
Damien Miller40857852001-07-14 12:17:33 +1000392 int i, n;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000393
Damien Miller95def091999-11-25 00:26:21 +1100394 f = fopen(filename, "r");
395 if (!f) {
396 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000397 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100398 }
399 linenum = 0;
400 while (fgets(line, sizeof(line), f)) {
401 linenum++;
Damien Millerbe484b52000-07-15 14:14:16 +1000402 cp = line;
403 arg = strdelim(&cp);
404 /* Ignore leading whitespace */
405 if (*arg == '\0')
406 arg = strdelim(&cp);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000407 if (!arg || !*arg || *arg == '#')
Damien Miller95def091999-11-25 00:26:21 +1100408 continue;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100409 intptr = NULL;
410 charptr = NULL;
Damien Miller37023962000-07-11 17:31:38 +1000411 opcode = parse_token(arg, filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100412 switch (opcode) {
413 case sBadOption:
414 bad_options++;
415 continue;
416 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100417 /* ignore ports from configfile if cmdline specifies ports */
418 if (options->ports_from_cmdline)
419 continue;
420 if (options->listen_addrs != NULL)
421 fatal("%s line %d: ports must be specified before "
Ben Lindstroma6218b82001-05-03 22:39:11 +0000422 "ListenAdress.", filename, linenum);
Damien Miller34132e52000-01-14 15:45:46 +1100423 if (options->num_ports >= MAX_PORTS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000424 fatal("%s line %d: too many ports.",
Damien Miller4af51302000-04-16 11:18:38 +1000425 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000426 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000427 if (!arg || *arg == '\0')
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000428 fatal("%s line %d: missing port number.",
Damien Miller34132e52000-01-14 15:45:46 +1100429 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000430 options->ports[options->num_ports++] = a2port(arg);
431 if (options->ports[options->num_ports-1] == 0)
432 fatal("%s line %d: Badly formatted port number.",
433 filename, linenum);
Damien Miller34132e52000-01-14 15:45:46 +1100434 break;
435
436 case sServerKeyBits:
437 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100438parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000439 arg = strdelim(&cp);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000440 if (!arg || *arg == '\0')
441 fatal("%s line %d: missing integer value.",
442 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000443 value = atoi(arg);
Damien Miller95def091999-11-25 00:26:21 +1100444 if (*intptr == -1)
445 *intptr = value;
446 break;
Damien Miller32265091999-11-12 11:33:04 +1100447
Damien Miller95def091999-11-25 00:26:21 +1100448 case sLoginGraceTime:
449 intptr = &options->login_grace_time;
Ben Lindstrom1bda4c82001-06-05 19:59:08 +0000450parse_time:
451 arg = strdelim(&cp);
452 if (!arg || *arg == '\0')
453 fatal("%s line %d: missing time value.",
454 filename, linenum);
455 if ((value = convtime(arg)) == -1)
456 fatal("%s line %d: invalid time value.",
457 filename, linenum);
458 if (*intptr == -1)
459 *intptr = value;
460 break;
Damien Miller95def091999-11-25 00:26:21 +1100461
462 case sKeyRegenerationTime:
463 intptr = &options->key_regeneration_time;
Ben Lindstrom1bda4c82001-06-05 19:59:08 +0000464 goto parse_time;
Damien Miller95def091999-11-25 00:26:21 +1100465
466 case sListenAddress:
Damien Millerbe484b52000-07-15 14:14:16 +1000467 arg = strdelim(&cp);
Ben Lindstromc510af42001-04-07 17:25:48 +0000468 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000469 fatal("%s line %d: missing inet addr.",
Damien Miller34132e52000-01-14 15:45:46 +1100470 filename, linenum);
Ben Lindstromc510af42001-04-07 17:25:48 +0000471 if (*arg == '[') {
472 if ((p = strchr(arg, ']')) == NULL)
473 fatal("%s line %d: bad ipv6 inet addr usage.",
474 filename, linenum);
475 arg++;
476 memmove(p, p+1, strlen(p+1)+1);
477 } else if (((p = strchr(arg, ':')) == NULL) ||
478 (strchr(p+1, ':') != NULL)) {
Ben Lindstrom19066a12001-04-12 23:39:26 +0000479 add_listen_addr(options, arg, 0);
Ben Lindstromc510af42001-04-07 17:25:48 +0000480 break;
481 }
482 if (*p == ':') {
Ben Lindstrom19066a12001-04-12 23:39:26 +0000483 u_short port;
484
Ben Lindstromc510af42001-04-07 17:25:48 +0000485 p++;
486 if (*p == '\0')
487 fatal("%s line %d: bad inet addr:port usage.",
488 filename, linenum);
489 else {
490 *(p-1) = '\0';
Ben Lindstrom19066a12001-04-12 23:39:26 +0000491 if ((port = a2port(p)) == 0)
492 fatal("%s line %d: bad port number.",
493 filename, linenum);
494 add_listen_addr(options, arg, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000495 }
496 } else if (*p == '\0')
Ben Lindstrom19066a12001-04-12 23:39:26 +0000497 add_listen_addr(options, arg, 0);
Ben Lindstromc510af42001-04-07 17:25:48 +0000498 else
499 fatal("%s line %d: bad inet addr usage.",
500 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100501 break;
502
503 case sHostKeyFile:
Damien Miller0bc1bd82000-11-13 22:57:25 +1100504 intptr = &options->num_host_key_files;
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000505 if (*intptr >= MAX_HOSTKEYS)
506 fatal("%s line %d: too many host keys specified (max %d).",
Damien Miller0bc1bd82000-11-13 22:57:25 +1100507 filename, linenum, MAX_HOSTKEYS);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100508 charptr = &options->host_key_files[*intptr];
Damien Millerd3a18572000-06-07 19:55:44 +1000509parse_filename:
Damien Millerbe484b52000-07-15 14:14:16 +1000510 arg = strdelim(&cp);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000511 if (!arg || *arg == '\0')
512 fatal("%s line %d: missing file name.",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000513 filename, linenum);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100514 if (*charptr == NULL) {
Damien Miller37023962000-07-11 17:31:38 +1000515 *charptr = tilde_expand_filename(arg, getuid());
Damien Miller0bc1bd82000-11-13 22:57:25 +1100516 /* increase optional counter */
517 if (intptr != NULL)
518 *intptr = *intptr + 1;
519 }
Damien Miller6f83b8e2000-05-02 09:23:45 +1000520 break;
521
522 case sPidFile:
523 charptr = &options->pid_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000524 goto parse_filename;
Damien Miller95def091999-11-25 00:26:21 +1100525
Damien Miller95def091999-11-25 00:26:21 +1100526 case sPermitRootLogin:
527 intptr = &options->permit_root_login;
Damien Millerbe484b52000-07-15 14:14:16 +1000528 arg = strdelim(&cp);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000529 if (!arg || *arg == '\0')
530 fatal("%s line %d: missing yes/"
Ben Lindstrom35f1f4e2001-03-06 01:02:41 +0000531 "without-password/forced-commands-only/no "
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000532 "argument.", filename, linenum);
533 value = 0; /* silence compiler */
Damien Miller37023962000-07-11 17:31:38 +1000534 if (strcmp(arg, "without-password") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000535 value = PERMIT_NO_PASSWD;
536 else if (strcmp(arg, "forced-commands-only") == 0)
537 value = PERMIT_FORCED_ONLY;
Damien Miller37023962000-07-11 17:31:38 +1000538 else if (strcmp(arg, "yes") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000539 value = PERMIT_YES;
Damien Miller37023962000-07-11 17:31:38 +1000540 else if (strcmp(arg, "no") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000541 value = PERMIT_NO;
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000542 else
543 fatal("%s line %d: Bad yes/"
Ben Lindstromd8a90212001-02-15 03:08:27 +0000544 "without-password/forced-commands-only/no "
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000545 "argument: %s", filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100546 if (*intptr == -1)
547 *intptr = value;
548 break;
549
550 case sIgnoreRhosts:
551 intptr = &options->ignore_rhosts;
552parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000553 arg = strdelim(&cp);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000554 if (!arg || *arg == '\0')
555 fatal("%s line %d: missing yes/no argument.",
556 filename, linenum);
557 value = 0; /* silence compiler */
Damien Miller37023962000-07-11 17:31:38 +1000558 if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100559 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000560 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100561 value = 0;
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000562 else
563 fatal("%s line %d: Bad yes/no argument: %s",
Damien Miller37023962000-07-11 17:31:38 +1000564 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100565 if (*intptr == -1)
566 *intptr = value;
567 break;
568
569 case sIgnoreUserKnownHosts:
570 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100571 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100572
573 case sRhostsAuthentication:
574 intptr = &options->rhosts_authentication;
575 goto parse_flag;
576
577 case sRhostsRSAAuthentication:
578 intptr = &options->rhosts_rsa_authentication;
579 goto parse_flag;
580
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000581 case sHostbasedAuthentication:
582 intptr = &options->hostbased_authentication;
583 goto parse_flag;
584
585 case sHostbasedUsesNameFromPacketOnly:
586 intptr = &options->hostbased_uses_name_from_packet_only;
587 goto parse_flag;
588
Damien Miller95def091999-11-25 00:26:21 +1100589 case sRSAAuthentication:
590 intptr = &options->rsa_authentication;
591 goto parse_flag;
592
Damien Miller0bc1bd82000-11-13 22:57:25 +1100593 case sPubkeyAuthentication:
594 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000595 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000596#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100597 case sKerberosAuthentication:
598 intptr = &options->kerberos_authentication;
599 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000600
Damien Miller95def091999-11-25 00:26:21 +1100601 case sKerberosOrLocalPasswd:
602 intptr = &options->kerberos_or_local_passwd;
603 goto parse_flag;
604
605 case sKerberosTicketCleanup:
606 intptr = &options->kerberos_ticket_cleanup;
607 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000608#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000609#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100610 case sKerberosTgtPassing:
611 intptr = &options->kerberos_tgt_passing;
612 goto parse_flag;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000613#endif
614#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100615 case sAFSTokenPassing:
616 intptr = &options->afs_token_passing;
617 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000618#endif
619
Damien Miller95def091999-11-25 00:26:21 +1100620 case sPasswordAuthentication:
621 intptr = &options->password_authentication;
622 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000623
Damien Miller874d77b2000-10-14 16:23:11 +1100624 case sKbdInteractiveAuthentication:
625 intptr = &options->kbd_interactive_authentication;
626 goto parse_flag;
627
Damien Miller95def091999-11-25 00:26:21 +1100628 case sCheckMail:
629 intptr = &options->check_mail;
630 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000631
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000632 case sChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000633 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100634 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000635
Damien Miller95def091999-11-25 00:26:21 +1100636 case sPrintMotd:
637 intptr = &options->print_motd;
638 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000639
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000640 case sPrintLastLog:
641 intptr = &options->print_lastlog;
642 goto parse_flag;
643
Damien Miller95def091999-11-25 00:26:21 +1100644 case sX11Forwarding:
645 intptr = &options->x11_forwarding;
646 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000647
Damien Miller95def091999-11-25 00:26:21 +1100648 case sX11DisplayOffset:
649 intptr = &options->x11_display_offset;
650 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000651
Damien Millerd3a18572000-06-07 19:55:44 +1000652 case sXAuthLocation:
653 charptr = &options->xauth_location;
654 goto parse_filename;
Kevin Stevesef4eea92001-02-05 12:42:17 +0000655
Damien Miller95def091999-11-25 00:26:21 +1100656 case sStrictModes:
657 intptr = &options->strict_modes;
658 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000659
Damien Miller95def091999-11-25 00:26:21 +1100660 case sKeepAlives:
661 intptr = &options->keepalives;
662 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000663
Damien Miller95def091999-11-25 00:26:21 +1100664 case sEmptyPasswd:
665 intptr = &options->permit_empty_passwd;
666 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000667
Damien Miller95def091999-11-25 00:26:21 +1100668 case sUseLogin:
669 intptr = &options->use_login;
670 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100671
Damien Millere247cc42000-05-07 12:03:14 +1000672 case sGatewayPorts:
673 intptr = &options->gateway_ports;
674 goto parse_flag;
675
Damien Miller33804262001-02-04 23:20:18 +1100676 case sReverseMappingCheck:
677 intptr = &options->reverse_mapping_check;
678 goto parse_flag;
679
Damien Miller95def091999-11-25 00:26:21 +1100680 case sLogFacility:
681 intptr = (int *) &options->log_facility;
Damien Millerbe484b52000-07-15 14:14:16 +1000682 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000683 value = log_facility_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100684 if (value == (SyslogFacility) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000685 fatal("%.200s line %d: unsupported log facility '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000686 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100687 if (*intptr == -1)
688 *intptr = (SyslogFacility) value;
689 break;
690
691 case sLogLevel:
692 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000693 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000694 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100695 if (value == (LogLevel) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000696 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000697 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100698 if (*intptr == -1)
699 *intptr = (LogLevel) value;
700 break;
701
Damien Miller50a41ed2000-10-16 12:14:42 +1100702 case sAllowTcpForwarding:
703 intptr = &options->allow_tcp_forwarding;
704 goto parse_flag;
705
Damien Miller95def091999-11-25 00:26:21 +1100706 case sAllowUsers:
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_allow_users >= MAX_ALLOW_USERS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000709 fatal("%s line %d: too many allow users.",
Damien Miller78928792000-04-12 20:17:38 +1000710 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000711 options->allow_users[options->num_allow_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100712 }
713 break;
714
715 case sDenyUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000716 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000717 if (options->num_deny_users >= MAX_DENY_USERS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000718 fatal( "%s line %d: too many deny users.",
Damien Miller78928792000-04-12 20:17:38 +1000719 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000720 options->deny_users[options->num_deny_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100721 }
722 break;
723
724 case sAllowGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000725 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000726 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000727 fatal("%s line %d: too many allow groups.",
Damien Miller78928792000-04-12 20:17:38 +1000728 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000729 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100730 }
731 break;
732
733 case sDenyGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000734 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000735 if (options->num_deny_groups >= MAX_DENY_GROUPS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000736 fatal("%s line %d: too many deny groups.",
Damien Miller78928792000-04-12 20:17:38 +1000737 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000738 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100739 }
740 break;
741
Damien Miller78928792000-04-12 20:17:38 +1000742 case sCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000743 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000744 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000745 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000746 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000747 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000748 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000749 if (options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000750 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000751 break;
752
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000753 case sMacs:
754 arg = strdelim(&cp);
755 if (!arg || *arg == '\0')
756 fatal("%s line %d: Missing argument.", filename, linenum);
757 if (!mac_valid(arg))
758 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
759 filename, linenum, arg ? arg : "<NONE>");
760 if (options->macs == NULL)
761 options->macs = xstrdup(arg);
762 break;
763
Damien Miller78928792000-04-12 20:17:38 +1000764 case sProtocol:
765 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000766 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000767 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000768 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000769 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000770 if (value == SSH_PROTO_UNKNOWN)
771 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000772 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000773 if (*intptr == SSH_PROTO_UNKNOWN)
774 *intptr = value;
775 break;
776
Damien Millerf6d9e222000-06-18 14:50:44 +1000777 case sSubsystem:
778 if(options->num_subsystems >= MAX_SUBSYSTEMS) {
779 fatal("%s line %d: too many subsystems defined.",
780 filename, linenum);
781 }
Damien Millerbe484b52000-07-15 14:14:16 +1000782 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000783 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000784 fatal("%s line %d: Missing subsystem name.",
785 filename, linenum);
786 for (i = 0; i < options->num_subsystems; i++)
Damien Miller37023962000-07-11 17:31:38 +1000787 if(strcmp(arg, options->subsystem_name[i]) == 0)
Damien Millerf6d9e222000-06-18 14:50:44 +1000788 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller37023962000-07-11 17:31:38 +1000789 filename, linenum, arg);
790 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000791 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000792 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000793 fatal("%s line %d: Missing subsystem command.",
794 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000795 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Millerf6d9e222000-06-18 14:50:44 +1000796 options->num_subsystems++;
797 break;
798
Damien Miller37023962000-07-11 17:31:38 +1000799 case sMaxStartups:
Damien Miller942da032000-08-18 13:59:06 +1000800 arg = strdelim(&cp);
801 if (!arg || *arg == '\0')
802 fatal("%s line %d: Missing MaxStartups spec.",
803 filename, linenum);
Damien Miller40857852001-07-14 12:17:33 +1000804 if ((n = sscanf(arg, "%d:%d:%d",
Damien Miller942da032000-08-18 13:59:06 +1000805 &options->max_startups_begin,
806 &options->max_startups_rate,
Damien Miller40857852001-07-14 12:17:33 +1000807 &options->max_startups)) == 3) {
Damien Miller942da032000-08-18 13:59:06 +1000808 if (options->max_startups_begin >
809 options->max_startups ||
810 options->max_startups_rate > 100 ||
811 options->max_startups_rate < 1)
Damien Miller40857852001-07-14 12:17:33 +1000812 fatal("%s line %d: Illegal MaxStartups spec.",
813 filename, linenum);
814 } else if (n != 1)
Damien Miller942da032000-08-18 13:59:06 +1000815 fatal("%s line %d: Illegal MaxStartups spec.",
Damien Miller40857852001-07-14 12:17:33 +1000816 filename, linenum);
817 else
818 options->max_startups = options->max_startups_begin;
819 break;
Damien Miller37023962000-07-11 17:31:38 +1000820
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000821 case sBanner:
822 charptr = &options->banner;
823 goto parse_filename;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000824 /*
825 * These options can contain %X options expanded at
826 * connect time, so that you can specify paths like:
827 *
828 * AuthorizedKeysFile /etc/ssh_keys/%u
829 */
830 case sAuthorizedKeysFile:
831 case sAuthorizedKeysFile2:
832 charptr = (opcode == sAuthorizedKeysFile ) ?
833 &options->authorized_keys_file :
834 &options->authorized_keys_file2;
835 goto parse_filename;
Ben Lindstrom1bda4c82001-06-05 19:59:08 +0000836
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000837 case sClientAliveInterval:
838 intptr = &options->client_alive_interval;
Ben Lindstrom1bda4c82001-06-05 19:59:08 +0000839 goto parse_time;
840
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000841 case sClientAliveCountMax:
842 intptr = &options->client_alive_count_max;
843 goto parse_int;
Ben Lindstrom1bda4c82001-06-05 19:59:08 +0000844
Damien Millerf8154422001-04-25 22:44:14 +1000845 case sPAMAuthenticationViaKbdInt:
846 intptr = &options->pam_authentication_via_kbd_int;
847 goto parse_flag;
848
Damien Miller95def091999-11-25 00:26:21 +1100849 default:
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000850 fatal("%s line %d: Missing handler for opcode %s (%d)",
851 filename, linenum, arg, opcode);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000852 }
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000853 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
854 fatal("%s line %d: garbage at end of line; \"%.200s\".",
855 filename, linenum, arg);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000856 }
Damien Miller95def091999-11-25 00:26:21 +1100857 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000858 if (bad_options > 0)
859 fatal("%s: terminating, %d bad configuration options",
860 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000861}