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