blob: f978c632b30c5cfad10f001aca04da51b009d566 [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 Lindstrom5744dc42001-04-13 23:28:01 +000013RCSID("$OpenBSD: servconf.c,v 1.77 2001/04/13 22:46:53 beck 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 Lindstrom95fb2dd2001-01-23 03:12:10 +000084 options->challenge_reponse_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 Millerd4a8b7e1999-10-27 13:42:43 +1000104}
105
Damien Miller4af51302000-04-16 11:18:38 +1000106void
Damien Miller95def091999-11-25 00:26:21 +1100107fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000108{
Damien Miller0bc1bd82000-11-13 22:57:25 +1100109 if (options->protocol == SSH_PROTO_UNKNOWN)
110 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
111 if (options->num_host_key_files == 0) {
112 /* fill default hostkeys for protocols */
113 if (options->protocol & SSH_PROTO_1)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000114 options->host_key_files[options->num_host_key_files++] = _PATH_HOST_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100115 if (options->protocol & SSH_PROTO_2)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000116 options->host_key_files[options->num_host_key_files++] = _PATH_HOST_DSA_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100117 }
Damien Miller34132e52000-01-14 15:45:46 +1100118 if (options->num_ports == 0)
119 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
120 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000121 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000122 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000123 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100124 if (options->server_key_bits == -1)
125 options->server_key_bits = 768;
126 if (options->login_grace_time == -1)
127 options->login_grace_time = 600;
128 if (options->key_regeneration_time == -1)
129 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000130 if (options->permit_root_login == PERMIT_NOT_SET)
131 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100132 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100133 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100134 if (options->ignore_user_known_hosts == -1)
135 options->ignore_user_known_hosts = 0;
136 if (options->check_mail == -1)
137 options->check_mail = 0;
138 if (options->print_motd == -1)
139 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000140 if (options->print_lastlog == -1)
141 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100142 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100143 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100144 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100145 options->x11_display_offset = 10;
Damien Millerd3a18572000-06-07 19:55:44 +1000146#ifdef XAUTH_PATH
147 if (options->xauth_location == NULL)
148 options->xauth_location = XAUTH_PATH;
149#endif /* XAUTH_PATH */
Damien Miller95def091999-11-25 00:26:21 +1100150 if (options->strict_modes == -1)
151 options->strict_modes = 1;
152 if (options->keepalives == -1)
153 options->keepalives = 1;
154 if (options->log_facility == (SyslogFacility) (-1))
155 options->log_facility = SYSLOG_FACILITY_AUTH;
156 if (options->log_level == (LogLevel) (-1))
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000157 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100158 if (options->rhosts_authentication == -1)
159 options->rhosts_authentication = 0;
160 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100161 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000162 if (options->hostbased_authentication == -1)
163 options->hostbased_authentication = 0;
164 if (options->hostbased_uses_name_from_packet_only == -1)
165 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100166 if (options->rsa_authentication == -1)
167 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100168 if (options->pubkey_authentication == -1)
169 options->pubkey_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000170#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100171 if (options->kerberos_authentication == -1)
172 options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
173 if (options->kerberos_or_local_passwd == -1)
174 options->kerberos_or_local_passwd = 1;
175 if (options->kerberos_ticket_cleanup == -1)
176 options->kerberos_ticket_cleanup = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000177#endif /* KRB4 */
178#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100179 if (options->kerberos_tgt_passing == -1)
180 options->kerberos_tgt_passing = 0;
181 if (options->afs_token_passing == -1)
182 options->afs_token_passing = k_hasafs();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000183#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100184 if (options->password_authentication == -1)
185 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100186 if (options->kbd_interactive_authentication == -1)
187 options->kbd_interactive_authentication = 0;
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000188 if (options->challenge_reponse_authentication == -1)
189 options->challenge_reponse_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100190 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100191 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100192 if (options->use_login == -1)
193 options->use_login = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100194 if (options->allow_tcp_forwarding == -1)
195 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000196 if (options->gateway_ports == -1)
197 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000198 if (options->max_startups == -1)
199 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000200 if (options->max_startups_rate == -1)
201 options->max_startups_rate = 100; /* 100% */
202 if (options->max_startups_begin == -1)
203 options->max_startups_begin = options->max_startups;
Damien Miller33804262001-02-04 23:20:18 +1100204 if (options->reverse_mapping_check == -1)
205 options->reverse_mapping_check = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000206 if (options->client_alive_interval == -1)
207 options->client_alive_interval = 0;
208 if (options->client_alive_count_max == -1)
209 options->client_alive_count_max = 3;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000210}
211
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000212/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100213typedef enum {
214 sBadOption, /* == unknown option */
215 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
216 sPermitRootLogin, sLogFacility, sLogLevel,
217 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000218#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100219 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000220#endif
221#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100222 sKerberosTgtPassing, sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000224 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100225 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000226 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
227 sX11Forwarding, sX11DisplayOffset,
Ben Lindstromd9cae222001-03-05 07:42:03 +0000228 sStrictModes, sEmptyPasswd, sKeepAlives, sCheckMail,
Damien Miller50a41ed2000-10-16 12:14:42 +1100229 sUseLogin, sAllowTcpForwarding,
230 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000231 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100232 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000233 sBanner, sReverseMappingCheck, sHostbasedAuthentication,
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000234 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
235 sClientAliveCountMax
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000236} ServerOpCodes;
237
238/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100239static struct {
240 const char *name;
241 ServerOpCodes opcode;
242} keywords[] = {
243 { "port", sPort },
244 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100245 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000246 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100247 { "serverkeybits", sServerKeyBits },
248 { "logingracetime", sLoginGraceTime },
249 { "keyregenerationinterval", sKeyRegenerationTime },
250 { "permitrootlogin", sPermitRootLogin },
251 { "syslogfacility", sLogFacility },
252 { "loglevel", sLogLevel },
253 { "rhostsauthentication", sRhostsAuthentication },
254 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000255 { "hostbasedauthentication", sHostbasedAuthentication },
256 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100257 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100258 { "pubkeyauthentication", sPubkeyAuthentication },
259 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000260#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100261 { "kerberosauthentication", sKerberosAuthentication },
262 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
263 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000264#endif
265#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100266 { "kerberostgtpassing", sKerberosTgtPassing },
267 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000268#endif
Damien Miller95def091999-11-25 00:26:21 +1100269 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100270 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000271 { "challengeresponseauthentication", sChallengeResponseAuthentication },
272 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100273 { "checkmail", sCheckMail },
274 { "listenaddress", sListenAddress },
275 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000276 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100277 { "ignorerhosts", sIgnoreRhosts },
278 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
279 { "x11forwarding", sX11Forwarding },
280 { "x11displayoffset", sX11DisplayOffset },
Damien Millerd3a18572000-06-07 19:55:44 +1000281 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100282 { "strictmodes", sStrictModes },
283 { "permitemptypasswords", sEmptyPasswd },
284 { "uselogin", sUseLogin },
Damien Miller95def091999-11-25 00:26:21 +1100285 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100286 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100287 { "allowusers", sAllowUsers },
288 { "denyusers", sDenyUsers },
289 { "allowgroups", sAllowGroups },
290 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000291 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000292 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000293 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000294 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000295 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000296 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000297 { "banner", sBanner },
Damien Miller33804262001-02-04 23:20:18 +1100298 { "reversemappingcheck", sReverseMappingCheck },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000299 { "clientaliveinterval", sClientAliveInterval },
300 { "clientalivecountmax", sClientAliveCountMax },
Damien Miller95def091999-11-25 00:26:21 +1100301 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000302};
303
Damien Miller5428f641999-11-25 11:54:57 +1100304/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000305 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100306 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000307
Damien Miller4af51302000-04-16 11:18:38 +1000308static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100309parse_token(const char *cp, const char *filename,
310 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000311{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000312 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000313
Damien Miller95def091999-11-25 00:26:21 +1100314 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100315 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100316 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000317
Damien Miller95def091999-11-25 00:26:21 +1100318 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
319 filename, linenum, cp);
320 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000321}
322
Damien Miller4af51302000-04-16 11:18:38 +1000323void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000324add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100325{
Damien Miller34132e52000-01-14 15:45:46 +1100326 int i;
327
328 if (options->num_ports == 0)
329 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000330 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000331 for (i = 0; i < options->num_ports; i++)
332 add_one_listen_addr(options, addr, options->ports[i]);
333 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000334 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000335}
336
337void
338add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
339{
340 struct addrinfo hints, *ai, *aitop;
341 char strport[NI_MAXSERV];
342 int gaierr;
343
344 memset(&hints, 0, sizeof(hints));
345 hints.ai_family = IPv4or6;
346 hints.ai_socktype = SOCK_STREAM;
347 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
348 snprintf(strport, sizeof strport, "%d", port);
349 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
350 fatal("bad addr or host: %s (%s)",
351 addr ? addr : "<NULL>",
352 gai_strerror(gaierr));
353 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
354 ;
355 ai->ai_next = options->listen_addrs;
356 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100357}
358
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000359/* Reads the server configuration file. */
360
Damien Miller4af51302000-04-16 11:18:38 +1000361void
Damien Miller95def091999-11-25 00:26:21 +1100362read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000363{
Damien Miller95def091999-11-25 00:26:21 +1100364 FILE *f;
365 char line[1024];
Ben Lindstromc510af42001-04-07 17:25:48 +0000366 char *cp, **charptr, *arg, *p;
Damien Miller95def091999-11-25 00:26:21 +1100367 int linenum, *intptr, value;
368 int bad_options = 0;
369 ServerOpCodes opcode;
Damien Millerf6d9e222000-06-18 14:50:44 +1000370 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000371
Damien Miller95def091999-11-25 00:26:21 +1100372 f = fopen(filename, "r");
373 if (!f) {
374 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000375 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100376 }
377 linenum = 0;
378 while (fgets(line, sizeof(line), f)) {
379 linenum++;
Damien Millerbe484b52000-07-15 14:14:16 +1000380 cp = line;
381 arg = strdelim(&cp);
382 /* Ignore leading whitespace */
383 if (*arg == '\0')
384 arg = strdelim(&cp);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000385 if (!arg || !*arg || *arg == '#')
Damien Miller95def091999-11-25 00:26:21 +1100386 continue;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100387 intptr = NULL;
388 charptr = NULL;
Damien Miller37023962000-07-11 17:31:38 +1000389 opcode = parse_token(arg, filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100390 switch (opcode) {
391 case sBadOption:
392 bad_options++;
393 continue;
394 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100395 /* ignore ports from configfile if cmdline specifies ports */
396 if (options->ports_from_cmdline)
397 continue;
398 if (options->listen_addrs != NULL)
399 fatal("%s line %d: ports must be specified before "
400 "ListenAdress.\n", filename, linenum);
401 if (options->num_ports >= MAX_PORTS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000402 fatal("%s line %d: too many ports.",
Damien Miller4af51302000-04-16 11:18:38 +1000403 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000404 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000405 if (!arg || *arg == '\0')
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000406 fatal("%s line %d: missing port number.",
Damien Miller34132e52000-01-14 15:45:46 +1100407 filename, linenum);
Ben Lindstrom19066a12001-04-12 23:39:26 +0000408 options->ports[options->num_ports++] = a2port(arg);
409 if (options->ports[options->num_ports-1] == 0)
410 fatal("%s line %d: Badly formatted port number.",
411 filename, linenum);
Damien Miller34132e52000-01-14 15:45:46 +1100412 break;
413
414 case sServerKeyBits:
415 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100416parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000417 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000418 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100419 fprintf(stderr, "%s line %d: missing integer value.\n",
420 filename, linenum);
421 exit(1);
422 }
Damien Miller37023962000-07-11 17:31:38 +1000423 value = atoi(arg);
Damien Miller95def091999-11-25 00:26:21 +1100424 if (*intptr == -1)
425 *intptr = value;
426 break;
Damien Miller32265091999-11-12 11:33:04 +1100427
Damien Miller95def091999-11-25 00:26:21 +1100428 case sLoginGraceTime:
429 intptr = &options->login_grace_time;
430 goto parse_int;
431
432 case sKeyRegenerationTime:
433 intptr = &options->key_regeneration_time;
434 goto parse_int;
435
436 case sListenAddress:
Damien Millerbe484b52000-07-15 14:14:16 +1000437 arg = strdelim(&cp);
Ben Lindstromc510af42001-04-07 17:25:48 +0000438 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000439 fatal("%s line %d: missing inet addr.",
Damien Miller34132e52000-01-14 15:45:46 +1100440 filename, linenum);
Ben Lindstromc510af42001-04-07 17:25:48 +0000441 if (*arg == '[') {
442 if ((p = strchr(arg, ']')) == NULL)
443 fatal("%s line %d: bad ipv6 inet addr usage.",
444 filename, linenum);
445 arg++;
446 memmove(p, p+1, strlen(p+1)+1);
447 } else if (((p = strchr(arg, ':')) == NULL) ||
448 (strchr(p+1, ':') != NULL)) {
Ben Lindstrom19066a12001-04-12 23:39:26 +0000449 add_listen_addr(options, arg, 0);
Ben Lindstromc510af42001-04-07 17:25:48 +0000450 break;
451 }
452 if (*p == ':') {
Ben Lindstrom19066a12001-04-12 23:39:26 +0000453 u_short port;
454
Ben Lindstromc510af42001-04-07 17:25:48 +0000455 p++;
456 if (*p == '\0')
457 fatal("%s line %d: bad inet addr:port usage.",
458 filename, linenum);
459 else {
460 *(p-1) = '\0';
Ben Lindstrom19066a12001-04-12 23:39:26 +0000461 if ((port = a2port(p)) == 0)
462 fatal("%s line %d: bad port number.",
463 filename, linenum);
464 add_listen_addr(options, arg, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000465 }
466 } else if (*p == '\0')
Ben Lindstrom19066a12001-04-12 23:39:26 +0000467 add_listen_addr(options, arg, 0);
Ben Lindstromc510af42001-04-07 17:25:48 +0000468 else
469 fatal("%s line %d: bad inet addr usage.",
470 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100471 break;
472
473 case sHostKeyFile:
Damien Miller0bc1bd82000-11-13 22:57:25 +1100474 intptr = &options->num_host_key_files;
475 if (*intptr >= MAX_HOSTKEYS) {
Ben Lindstrom33a3cc32001-03-05 05:07:52 +0000476 fprintf(stderr,
477 "%s line %d: too many host keys specified (max %d).\n",
Damien Miller0bc1bd82000-11-13 22:57:25 +1100478 filename, linenum, MAX_HOSTKEYS);
479 exit(1);
480 }
481 charptr = &options->host_key_files[*intptr];
Damien Millerd3a18572000-06-07 19:55:44 +1000482parse_filename:
Damien Millerbe484b52000-07-15 14:14:16 +1000483 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000484 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100485 fprintf(stderr, "%s line %d: missing file name.\n",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000486 filename, linenum);
487 exit(1);
488 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100489 if (*charptr == NULL) {
Damien Miller37023962000-07-11 17:31:38 +1000490 *charptr = tilde_expand_filename(arg, getuid());
Damien Miller0bc1bd82000-11-13 22:57:25 +1100491 /* increase optional counter */
492 if (intptr != NULL)
493 *intptr = *intptr + 1;
494 }
Damien Miller6f83b8e2000-05-02 09:23:45 +1000495 break;
496
497 case sPidFile:
498 charptr = &options->pid_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000499 goto parse_filename;
Damien Miller95def091999-11-25 00:26:21 +1100500
Damien Miller95def091999-11-25 00:26:21 +1100501 case sPermitRootLogin:
502 intptr = &options->permit_root_login;
Damien Millerbe484b52000-07-15 14:14:16 +1000503 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000504 if (!arg || *arg == '\0') {
Ben Lindstrom35f1f4e2001-03-06 01:02:41 +0000505 fprintf(stderr, "%s line %d: missing yes/"
506 "without-password/forced-commands-only/no "
507 "argument.\n", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100508 exit(1);
509 }
Damien Miller37023962000-07-11 17:31:38 +1000510 if (strcmp(arg, "without-password") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000511 value = PERMIT_NO_PASSWD;
512 else if (strcmp(arg, "forced-commands-only") == 0)
513 value = PERMIT_FORCED_ONLY;
Damien Miller37023962000-07-11 17:31:38 +1000514 else if (strcmp(arg, "yes") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000515 value = PERMIT_YES;
Damien Miller37023962000-07-11 17:31:38 +1000516 else if (strcmp(arg, "no") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000517 value = PERMIT_NO;
Damien Miller95def091999-11-25 00:26:21 +1100518 else {
Ben Lindstromd8a90212001-02-15 03:08:27 +0000519 fprintf(stderr, "%s line %d: Bad yes/"
520 "without-password/forced-commands-only/no "
521 "argument: %s\n", filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100522 exit(1);
523 }
524 if (*intptr == -1)
525 *intptr = value;
526 break;
527
528 case sIgnoreRhosts:
529 intptr = &options->ignore_rhosts;
530parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000531 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000532 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100533 fprintf(stderr, "%s line %d: missing yes/no argument.\n",
534 filename, linenum);
535 exit(1);
536 }
Damien Miller37023962000-07-11 17:31:38 +1000537 if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100538 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000539 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100540 value = 0;
541 else {
542 fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000543 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100544 exit(1);
545 }
546 if (*intptr == -1)
547 *intptr = value;
548 break;
549
550 case sIgnoreUserKnownHosts:
551 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100552 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100553
554 case sRhostsAuthentication:
555 intptr = &options->rhosts_authentication;
556 goto parse_flag;
557
558 case sRhostsRSAAuthentication:
559 intptr = &options->rhosts_rsa_authentication;
560 goto parse_flag;
561
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000562 case sHostbasedAuthentication:
563 intptr = &options->hostbased_authentication;
564 goto parse_flag;
565
566 case sHostbasedUsesNameFromPacketOnly:
567 intptr = &options->hostbased_uses_name_from_packet_only;
568 goto parse_flag;
569
Damien Miller95def091999-11-25 00:26:21 +1100570 case sRSAAuthentication:
571 intptr = &options->rsa_authentication;
572 goto parse_flag;
573
Damien Miller0bc1bd82000-11-13 22:57:25 +1100574 case sPubkeyAuthentication:
575 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000576 goto parse_flag;
577
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000578#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100579 case sKerberosAuthentication:
580 intptr = &options->kerberos_authentication;
581 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000582
Damien Miller95def091999-11-25 00:26:21 +1100583 case sKerberosOrLocalPasswd:
584 intptr = &options->kerberos_or_local_passwd;
585 goto parse_flag;
586
587 case sKerberosTicketCleanup:
588 intptr = &options->kerberos_ticket_cleanup;
589 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000590#endif
Damien Miller95def091999-11-25 00:26:21 +1100591
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000592#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100593 case sKerberosTgtPassing:
594 intptr = &options->kerberos_tgt_passing;
595 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000596
Damien Miller95def091999-11-25 00:26:21 +1100597 case sAFSTokenPassing:
598 intptr = &options->afs_token_passing;
599 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000600#endif
601
Damien Miller95def091999-11-25 00:26:21 +1100602 case sPasswordAuthentication:
603 intptr = &options->password_authentication;
604 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000605
Damien Miller874d77b2000-10-14 16:23:11 +1100606 case sKbdInteractiveAuthentication:
607 intptr = &options->kbd_interactive_authentication;
608 goto parse_flag;
609
Damien Miller95def091999-11-25 00:26:21 +1100610 case sCheckMail:
611 intptr = &options->check_mail;
612 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000613
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000614 case sChallengeResponseAuthentication:
615 intptr = &options->challenge_reponse_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100616 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000617
Damien Miller95def091999-11-25 00:26:21 +1100618 case sPrintMotd:
619 intptr = &options->print_motd;
620 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000621
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000622 case sPrintLastLog:
623 intptr = &options->print_lastlog;
624 goto parse_flag;
625
Damien Miller95def091999-11-25 00:26:21 +1100626 case sX11Forwarding:
627 intptr = &options->x11_forwarding;
628 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000629
Damien Miller95def091999-11-25 00:26:21 +1100630 case sX11DisplayOffset:
631 intptr = &options->x11_display_offset;
632 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000633
Damien Millerd3a18572000-06-07 19:55:44 +1000634 case sXAuthLocation:
635 charptr = &options->xauth_location;
636 goto parse_filename;
Kevin Stevesef4eea92001-02-05 12:42:17 +0000637
Damien Miller95def091999-11-25 00:26:21 +1100638 case sStrictModes:
639 intptr = &options->strict_modes;
640 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000641
Damien Miller95def091999-11-25 00:26:21 +1100642 case sKeepAlives:
643 intptr = &options->keepalives;
644 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000645
Damien Miller95def091999-11-25 00:26:21 +1100646 case sEmptyPasswd:
647 intptr = &options->permit_empty_passwd;
648 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000649
Damien Miller95def091999-11-25 00:26:21 +1100650 case sUseLogin:
651 intptr = &options->use_login;
652 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100653
Damien Millere247cc42000-05-07 12:03:14 +1000654 case sGatewayPorts:
655 intptr = &options->gateway_ports;
656 goto parse_flag;
657
Damien Miller33804262001-02-04 23:20:18 +1100658 case sReverseMappingCheck:
659 intptr = &options->reverse_mapping_check;
660 goto parse_flag;
661
Damien Miller95def091999-11-25 00:26:21 +1100662 case sLogFacility:
663 intptr = (int *) &options->log_facility;
Damien Millerbe484b52000-07-15 14:14:16 +1000664 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000665 value = log_facility_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100666 if (value == (SyslogFacility) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000667 fatal("%.200s line %d: unsupported log facility '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000668 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100669 if (*intptr == -1)
670 *intptr = (SyslogFacility) value;
671 break;
672
673 case sLogLevel:
674 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000675 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000676 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100677 if (value == (LogLevel) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000678 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000679 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100680 if (*intptr == -1)
681 *intptr = (LogLevel) value;
682 break;
683
Damien Miller50a41ed2000-10-16 12:14:42 +1100684 case sAllowTcpForwarding:
685 intptr = &options->allow_tcp_forwarding;
686 goto parse_flag;
687
Damien Miller95def091999-11-25 00:26:21 +1100688 case sAllowUsers:
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_allow_users >= MAX_ALLOW_USERS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000691 fatal("%s line %d: too many allow users.",
Damien Miller78928792000-04-12 20:17:38 +1000692 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000693 options->allow_users[options->num_allow_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100694 }
695 break;
696
697 case sDenyUsers:
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_deny_users >= MAX_DENY_USERS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000700 fatal( "%s line %d: too many deny users.",
Damien Miller78928792000-04-12 20:17:38 +1000701 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000702 options->deny_users[options->num_deny_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100703 }
704 break;
705
706 case sAllowGroups:
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_groups >= MAX_ALLOW_GROUPS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000709 fatal("%s line %d: too many allow groups.",
Damien Miller78928792000-04-12 20:17:38 +1000710 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000711 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100712 }
713 break;
714
715 case sDenyGroups:
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_groups >= MAX_DENY_GROUPS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000718 fatal("%s line %d: too many deny groups.",
Damien Miller78928792000-04-12 20:17:38 +1000719 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000720 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100721 }
722 break;
723
Damien Miller78928792000-04-12 20:17:38 +1000724 case sCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000725 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000726 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000727 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000728 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000729 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000730 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000731 if (options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000732 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000733 break;
734
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000735 case sMacs:
736 arg = strdelim(&cp);
737 if (!arg || *arg == '\0')
738 fatal("%s line %d: Missing argument.", filename, linenum);
739 if (!mac_valid(arg))
740 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
741 filename, linenum, arg ? arg : "<NONE>");
742 if (options->macs == NULL)
743 options->macs = xstrdup(arg);
744 break;
745
Damien Miller78928792000-04-12 20:17:38 +1000746 case sProtocol:
747 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000748 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000749 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000750 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000751 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000752 if (value == SSH_PROTO_UNKNOWN)
753 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000754 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000755 if (*intptr == SSH_PROTO_UNKNOWN)
756 *intptr = value;
757 break;
758
Damien Millerf6d9e222000-06-18 14:50:44 +1000759 case sSubsystem:
760 if(options->num_subsystems >= MAX_SUBSYSTEMS) {
761 fatal("%s line %d: too many subsystems defined.",
762 filename, linenum);
763 }
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 name.",
767 filename, linenum);
768 for (i = 0; i < options->num_subsystems; i++)
Damien Miller37023962000-07-11 17:31:38 +1000769 if(strcmp(arg, options->subsystem_name[i]) == 0)
Damien Millerf6d9e222000-06-18 14:50:44 +1000770 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller37023962000-07-11 17:31:38 +1000771 filename, linenum, arg);
772 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000773 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000774 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000775 fatal("%s line %d: Missing subsystem command.",
776 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000777 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Millerf6d9e222000-06-18 14:50:44 +1000778 options->num_subsystems++;
779 break;
780
Damien Miller37023962000-07-11 17:31:38 +1000781 case sMaxStartups:
Damien Miller942da032000-08-18 13:59:06 +1000782 arg = strdelim(&cp);
783 if (!arg || *arg == '\0')
784 fatal("%s line %d: Missing MaxStartups spec.",
785 filename, linenum);
786 if (sscanf(arg, "%d:%d:%d",
787 &options->max_startups_begin,
788 &options->max_startups_rate,
789 &options->max_startups) == 3) {
790 if (options->max_startups_begin >
791 options->max_startups ||
792 options->max_startups_rate > 100 ||
793 options->max_startups_rate < 1)
794 fatal("%s line %d: Illegal MaxStartups spec.",
795 filename, linenum);
796 break;
797 }
Damien Miller37023962000-07-11 17:31:38 +1000798 intptr = &options->max_startups;
799 goto parse_int;
800
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000801 case sBanner:
802 charptr = &options->banner;
803 goto parse_filename;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000804 case sClientAliveInterval:
805 intptr = &options->client_alive_interval;
806 goto parse_int;
807 case sClientAliveCountMax:
808 intptr = &options->client_alive_count_max;
809 goto parse_int;
Damien Miller95def091999-11-25 00:26:21 +1100810 default:
811 fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
Damien Miller37023962000-07-11 17:31:38 +1000812 filename, linenum, arg, opcode);
Damien Miller95def091999-11-25 00:26:21 +1100813 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000814 }
Damien Millerbe484b52000-07-15 14:14:16 +1000815 if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
Kevin Stevesef4eea92001-02-05 12:42:17 +0000816 fprintf(stderr,
Damien Miller37023962000-07-11 17:31:38 +1000817 "%s line %d: garbage at end of line; \"%.200s\".\n",
818 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100819 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000820 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000821 }
Damien Miller95def091999-11-25 00:26:21 +1100822 fclose(f);
823 if (bad_options > 0) {
824 fprintf(stderr, "%s: terminating, %d bad configuration options\n",
825 filename, bad_options);
826 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000827 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000828}