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