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 | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 13 | RCSID("$OpenBSD: servconf.c,v 1.52 2000/10/11 20:14:39 markus Exp $"); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 14 | |
| 15 | #include "ssh.h" |
| 16 | #include "servconf.h" |
| 17 | #include "xmalloc.h" |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 18 | #include "compat.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 19 | |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 20 | /* add listen address */ |
| 21 | void add_listen_addr(ServerOptions *options, char *addr); |
| 22 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 23 | /* Initializes the server options to their default values. */ |
| 24 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 25 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 26 | initialize_server_options(ServerOptions *options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 27 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 28 | memset(options, 0, sizeof(*options)); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 29 | options->num_ports = 0; |
| 30 | options->ports_from_cmdline = 0; |
| 31 | options->listen_addrs = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 32 | options->host_key_file = NULL; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 33 | options->host_dsa_key_file = NULL; |
Damien Miller | 6f83b8e | 2000-05-02 09:23:45 +1000 | [diff] [blame] | 34 | options->pid_file = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 35 | options->server_key_bits = -1; |
| 36 | options->login_grace_time = -1; |
| 37 | options->key_regeneration_time = -1; |
| 38 | options->permit_root_login = -1; |
| 39 | options->ignore_rhosts = -1; |
| 40 | options->ignore_user_known_hosts = -1; |
| 41 | options->print_motd = -1; |
| 42 | options->check_mail = -1; |
| 43 | options->x11_forwarding = -1; |
| 44 | options->x11_display_offset = -1; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 45 | options->xauth_location = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 46 | options->strict_modes = -1; |
| 47 | options->keepalives = -1; |
| 48 | options->log_facility = (SyslogFacility) - 1; |
| 49 | options->log_level = (LogLevel) - 1; |
| 50 | options->rhosts_authentication = -1; |
| 51 | options->rhosts_rsa_authentication = -1; |
| 52 | options->rsa_authentication = -1; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 53 | options->dsa_authentication = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 54 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 55 | options->kerberos_authentication = -1; |
| 56 | options->kerberos_or_local_passwd = -1; |
| 57 | options->kerberos_ticket_cleanup = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 58 | #endif |
| 59 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 60 | options->kerberos_tgt_passing = -1; |
| 61 | options->afs_token_passing = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 62 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 63 | options->password_authentication = -1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 64 | options->kbd_interactive_authentication = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 65 | #ifdef SKEY |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 66 | options->skey_authentication = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 67 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 68 | options->permit_empty_passwd = -1; |
| 69 | options->use_login = -1; |
| 70 | options->num_allow_users = 0; |
| 71 | options->num_deny_users = 0; |
| 72 | options->num_allow_groups = 0; |
| 73 | options->num_deny_groups = 0; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 74 | options->ciphers = NULL; |
| 75 | options->protocol = SSH_PROTO_UNKNOWN; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 76 | options->gateway_ports = -1; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 77 | options->num_subsystems = 0; |
Damien Miller | 942da03 | 2000-08-18 13:59:06 +1000 | [diff] [blame] | 78 | options->max_startups_begin = -1; |
| 79 | options->max_startups_rate = -1; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 80 | options->max_startups = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 81 | } |
| 82 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 83 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 84 | fill_default_server_options(ServerOptions *options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 85 | { |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 86 | if (options->num_ports == 0) |
| 87 | options->ports[options->num_ports++] = SSH_DEFAULT_PORT; |
| 88 | if (options->listen_addrs == NULL) |
| 89 | add_listen_addr(options, NULL); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 90 | if (options->host_key_file == NULL) |
| 91 | options->host_key_file = HOST_KEY_FILE; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 92 | if (options->host_dsa_key_file == NULL) |
| 93 | options->host_dsa_key_file = HOST_DSA_KEY_FILE; |
Damien Miller | 6f83b8e | 2000-05-02 09:23:45 +1000 | [diff] [blame] | 94 | if (options->pid_file == NULL) |
| 95 | options->pid_file = SSH_DAEMON_PID_FILE; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 96 | if (options->server_key_bits == -1) |
| 97 | options->server_key_bits = 768; |
| 98 | if (options->login_grace_time == -1) |
| 99 | options->login_grace_time = 600; |
| 100 | if (options->key_regeneration_time == -1) |
| 101 | options->key_regeneration_time = 3600; |
| 102 | if (options->permit_root_login == -1) |
| 103 | options->permit_root_login = 1; /* yes */ |
| 104 | if (options->ignore_rhosts == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 105 | options->ignore_rhosts = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 106 | if (options->ignore_user_known_hosts == -1) |
| 107 | options->ignore_user_known_hosts = 0; |
| 108 | if (options->check_mail == -1) |
| 109 | options->check_mail = 0; |
| 110 | if (options->print_motd == -1) |
| 111 | options->print_motd = 1; |
| 112 | if (options->x11_forwarding == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 113 | options->x11_forwarding = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 114 | if (options->x11_display_offset == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 115 | options->x11_display_offset = 10; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 116 | #ifdef XAUTH_PATH |
| 117 | if (options->xauth_location == NULL) |
| 118 | options->xauth_location = XAUTH_PATH; |
| 119 | #endif /* XAUTH_PATH */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 120 | if (options->strict_modes == -1) |
| 121 | options->strict_modes = 1; |
| 122 | if (options->keepalives == -1) |
| 123 | options->keepalives = 1; |
| 124 | if (options->log_facility == (SyslogFacility) (-1)) |
| 125 | options->log_facility = SYSLOG_FACILITY_AUTH; |
| 126 | if (options->log_level == (LogLevel) (-1)) |
| 127 | options->log_level = SYSLOG_LEVEL_INFO; |
| 128 | if (options->rhosts_authentication == -1) |
| 129 | options->rhosts_authentication = 0; |
| 130 | if (options->rhosts_rsa_authentication == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 131 | options->rhosts_rsa_authentication = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 132 | if (options->rsa_authentication == -1) |
| 133 | options->rsa_authentication = 1; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 134 | if (options->dsa_authentication == -1) |
| 135 | options->dsa_authentication = 1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 136 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 137 | if (options->kerberos_authentication == -1) |
| 138 | options->kerberos_authentication = (access(KEYFILE, R_OK) == 0); |
| 139 | if (options->kerberos_or_local_passwd == -1) |
| 140 | options->kerberos_or_local_passwd = 1; |
| 141 | if (options->kerberos_ticket_cleanup == -1) |
| 142 | options->kerberos_ticket_cleanup = 1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 143 | #endif /* KRB4 */ |
| 144 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 145 | if (options->kerberos_tgt_passing == -1) |
| 146 | options->kerberos_tgt_passing = 0; |
| 147 | if (options->afs_token_passing == -1) |
| 148 | options->afs_token_passing = k_hasafs(); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 149 | #endif /* AFS */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 150 | if (options->password_authentication == -1) |
| 151 | options->password_authentication = 1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 152 | if (options->kbd_interactive_authentication == -1) |
| 153 | options->kbd_interactive_authentication = 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 154 | #ifdef SKEY |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 155 | if (options->skey_authentication == -1) |
| 156 | options->skey_authentication = 1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 157 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 158 | if (options->permit_empty_passwd == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 159 | options->permit_empty_passwd = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 160 | if (options->use_login == -1) |
| 161 | options->use_login = 0; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 162 | if (options->protocol == SSH_PROTO_UNKNOWN) |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 163 | options->protocol = SSH_PROTO_1|SSH_PROTO_2; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 164 | if (options->gateway_ports == -1) |
| 165 | options->gateway_ports = 0; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 166 | if (options->max_startups == -1) |
| 167 | options->max_startups = 10; |
Damien Miller | 942da03 | 2000-08-18 13:59:06 +1000 | [diff] [blame] | 168 | if (options->max_startups_rate == -1) |
| 169 | options->max_startups_rate = 100; /* 100% */ |
| 170 | if (options->max_startups_begin == -1) |
| 171 | options->max_startups_begin = options->max_startups; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 172 | } |
| 173 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 174 | /* Keyword tokens. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 175 | typedef enum { |
| 176 | sBadOption, /* == unknown option */ |
| 177 | sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime, |
| 178 | sPermitRootLogin, sLogFacility, sLogLevel, |
| 179 | sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 180 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 181 | sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 182 | #endif |
| 183 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 184 | sKerberosTgtPassing, sAFSTokenPassing, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 185 | #endif |
| 186 | #ifdef SKEY |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 187 | sSkeyAuthentication, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 188 | #endif |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 189 | sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 190 | sPrintMotd, sIgnoreRhosts, sX11Forwarding, sX11DisplayOffset, |
| 191 | sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail, |
| 192 | sUseLogin, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups, |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 193 | sIgnoreUserKnownHosts, sHostDSAKeyFile, sCiphers, sProtocol, sPidFile, |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 194 | sGatewayPorts, sDSAAuthentication, sXAuthLocation, sSubsystem, sMaxStartups |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 195 | } ServerOpCodes; |
| 196 | |
| 197 | /* Textual representation of the tokens. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 198 | static struct { |
| 199 | const char *name; |
| 200 | ServerOpCodes opcode; |
| 201 | } keywords[] = { |
| 202 | { "port", sPort }, |
| 203 | { "hostkey", sHostKeyFile }, |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 204 | { "hostdsakey", sHostDSAKeyFile }, |
Damien Miller | 6f83b8e | 2000-05-02 09:23:45 +1000 | [diff] [blame] | 205 | { "pidfile", sPidFile }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 206 | { "serverkeybits", sServerKeyBits }, |
| 207 | { "logingracetime", sLoginGraceTime }, |
| 208 | { "keyregenerationinterval", sKeyRegenerationTime }, |
| 209 | { "permitrootlogin", sPermitRootLogin }, |
| 210 | { "syslogfacility", sLogFacility }, |
| 211 | { "loglevel", sLogLevel }, |
| 212 | { "rhostsauthentication", sRhostsAuthentication }, |
| 213 | { "rhostsrsaauthentication", sRhostsRSAAuthentication }, |
| 214 | { "rsaauthentication", sRSAAuthentication }, |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 215 | { "dsaauthentication", sDSAAuthentication }, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 216 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 217 | { "kerberosauthentication", sKerberosAuthentication }, |
| 218 | { "kerberosorlocalpasswd", sKerberosOrLocalPasswd }, |
| 219 | { "kerberosticketcleanup", sKerberosTicketCleanup }, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 220 | #endif |
| 221 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 222 | { "kerberostgtpassing", sKerberosTgtPassing }, |
| 223 | { "afstokenpassing", sAFSTokenPassing }, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 224 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 225 | { "passwordauthentication", sPasswordAuthentication }, |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 226 | { "kbdinteractiveauthentication", sKbdInteractiveAuthentication }, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 227 | #ifdef SKEY |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 228 | { "skeyauthentication", sSkeyAuthentication }, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 229 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 230 | { "checkmail", sCheckMail }, |
| 231 | { "listenaddress", sListenAddress }, |
| 232 | { "printmotd", sPrintMotd }, |
| 233 | { "ignorerhosts", sIgnoreRhosts }, |
| 234 | { "ignoreuserknownhosts", sIgnoreUserKnownHosts }, |
| 235 | { "x11forwarding", sX11Forwarding }, |
| 236 | { "x11displayoffset", sX11DisplayOffset }, |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 237 | { "xauthlocation", sXAuthLocation }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 238 | { "strictmodes", sStrictModes }, |
| 239 | { "permitemptypasswords", sEmptyPasswd }, |
| 240 | { "uselogin", sUseLogin }, |
| 241 | { "randomseed", sRandomSeedFile }, |
| 242 | { "keepalive", sKeepAlives }, |
| 243 | { "allowusers", sAllowUsers }, |
| 244 | { "denyusers", sDenyUsers }, |
| 245 | { "allowgroups", sAllowGroups }, |
| 246 | { "denygroups", sDenyGroups }, |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 247 | { "ciphers", sCiphers }, |
| 248 | { "protocol", sProtocol }, |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 249 | { "gatewayports", sGatewayPorts }, |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 250 | { "subsystem", sSubsystem }, |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 251 | { "maxstartups", sMaxStartups }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 252 | { NULL, 0 } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 253 | }; |
| 254 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 255 | /* |
| 256 | * Returns the number of the token pointed to by cp of length len. Never |
| 257 | * returns if the token is not known. |
| 258 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 259 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 260 | static ServerOpCodes |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 261 | parse_token(const char *cp, const char *filename, |
| 262 | int linenum) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 263 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 264 | unsigned int i; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 265 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 266 | for (i = 0; keywords[i].name; i++) |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 267 | if (strcasecmp(cp, keywords[i].name) == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 268 | return keywords[i].opcode; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 269 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 270 | fprintf(stderr, "%s: line %d: Bad configuration option: %s\n", |
| 271 | filename, linenum, cp); |
| 272 | return sBadOption; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 273 | } |
| 274 | |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 275 | /* |
| 276 | * add listen address |
| 277 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 278 | void |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 279 | add_listen_addr(ServerOptions *options, char *addr) |
| 280 | { |
| 281 | extern int IPv4or6; |
| 282 | struct addrinfo hints, *ai, *aitop; |
| 283 | char strport[NI_MAXSERV]; |
| 284 | int gaierr; |
| 285 | int i; |
| 286 | |
| 287 | if (options->num_ports == 0) |
| 288 | options->ports[options->num_ports++] = SSH_DEFAULT_PORT; |
| 289 | for (i = 0; i < options->num_ports; i++) { |
| 290 | memset(&hints, 0, sizeof(hints)); |
| 291 | hints.ai_family = IPv4or6; |
| 292 | hints.ai_socktype = SOCK_STREAM; |
| 293 | hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0; |
| 294 | snprintf(strport, sizeof strport, "%d", options->ports[i]); |
| 295 | if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0) |
| 296 | fatal("bad addr or host: %s (%s)\n", |
| 297 | addr ? addr : "<NULL>", |
| 298 | gai_strerror(gaierr)); |
| 299 | for (ai = aitop; ai->ai_next; ai = ai->ai_next) |
| 300 | ; |
| 301 | ai->ai_next = options->listen_addrs; |
| 302 | options->listen_addrs = aitop; |
| 303 | } |
| 304 | } |
| 305 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 306 | /* Reads the server configuration file. */ |
| 307 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 308 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 309 | read_server_config(ServerOptions *options, const char *filename) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 310 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 311 | FILE *f; |
| 312 | char line[1024]; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 313 | char *cp, **charptr, *arg; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 314 | int linenum, *intptr, value; |
| 315 | int bad_options = 0; |
| 316 | ServerOpCodes opcode; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 317 | int i; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 318 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 319 | f = fopen(filename, "r"); |
| 320 | if (!f) { |
| 321 | perror(filename); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 322 | exit(1); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 323 | } |
| 324 | linenum = 0; |
| 325 | while (fgets(line, sizeof(line), f)) { |
| 326 | linenum++; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 327 | cp = line; |
| 328 | arg = strdelim(&cp); |
| 329 | /* Ignore leading whitespace */ |
| 330 | if (*arg == '\0') |
| 331 | arg = strdelim(&cp); |
| 332 | if (!*arg || *arg == '#') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 333 | continue; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 334 | opcode = parse_token(arg, filename, linenum); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 335 | switch (opcode) { |
| 336 | case sBadOption: |
| 337 | bad_options++; |
| 338 | continue; |
| 339 | case sPort: |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 340 | /* ignore ports from configfile if cmdline specifies ports */ |
| 341 | if (options->ports_from_cmdline) |
| 342 | continue; |
| 343 | if (options->listen_addrs != NULL) |
| 344 | fatal("%s line %d: ports must be specified before " |
| 345 | "ListenAdress.\n", filename, linenum); |
| 346 | if (options->num_ports >= MAX_PORTS) |
| 347 | fatal("%s line %d: too many ports.\n", |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 348 | filename, linenum); |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 349 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 350 | if (!arg || *arg == '\0') |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 351 | fatal("%s line %d: missing port number.\n", |
| 352 | filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 353 | options->ports[options->num_ports++] = atoi(arg); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 354 | break; |
| 355 | |
| 356 | case sServerKeyBits: |
| 357 | intptr = &options->server_key_bits; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 358 | parse_int: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 359 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 360 | if (!arg || *arg == '\0') { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 361 | fprintf(stderr, "%s line %d: missing integer value.\n", |
| 362 | filename, linenum); |
| 363 | exit(1); |
| 364 | } |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 365 | value = atoi(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 366 | if (*intptr == -1) |
| 367 | *intptr = value; |
| 368 | break; |
Damien Miller | 3226509 | 1999-11-12 11:33:04 +1100 | [diff] [blame] | 369 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 370 | case sLoginGraceTime: |
| 371 | intptr = &options->login_grace_time; |
| 372 | goto parse_int; |
| 373 | |
| 374 | case sKeyRegenerationTime: |
| 375 | intptr = &options->key_regeneration_time; |
| 376 | goto parse_int; |
| 377 | |
| 378 | case sListenAddress: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 379 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 380 | if (!arg || *arg == '\0') |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 381 | fatal("%s line %d: missing inet addr.\n", |
| 382 | filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 383 | add_listen_addr(options, arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 384 | break; |
| 385 | |
| 386 | case sHostKeyFile: |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 387 | case sHostDSAKeyFile: |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 388 | charptr = (opcode == sHostKeyFile ) ? |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 389 | &options->host_key_file : &options->host_dsa_key_file; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 390 | parse_filename: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 391 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 392 | if (!arg || *arg == '\0') { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 393 | fprintf(stderr, "%s line %d: missing file name.\n", |
Damien Miller | 6f83b8e | 2000-05-02 09:23:45 +1000 | [diff] [blame] | 394 | filename, linenum); |
| 395 | exit(1); |
| 396 | } |
| 397 | if (*charptr == NULL) |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 398 | *charptr = tilde_expand_filename(arg, getuid()); |
Damien Miller | 6f83b8e | 2000-05-02 09:23:45 +1000 | [diff] [blame] | 399 | break; |
| 400 | |
| 401 | case sPidFile: |
| 402 | charptr = &options->pid_file; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 403 | goto parse_filename; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 404 | |
| 405 | case sRandomSeedFile: |
| 406 | fprintf(stderr, "%s line %d: \"randomseed\" option is obsolete.\n", |
| 407 | filename, linenum); |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 408 | arg = strdelim(&cp); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 409 | break; |
| 410 | |
| 411 | case sPermitRootLogin: |
| 412 | intptr = &options->permit_root_login; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 413 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 414 | if (!arg || *arg == '\0') { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 415 | fprintf(stderr, "%s line %d: missing yes/without-password/no argument.\n", |
| 416 | filename, linenum); |
| 417 | exit(1); |
| 418 | } |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 419 | if (strcmp(arg, "without-password") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 420 | value = 2; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 421 | else if (strcmp(arg, "yes") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 422 | value = 1; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 423 | else if (strcmp(arg, "no") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 424 | value = 0; |
| 425 | else { |
| 426 | fprintf(stderr, "%s line %d: Bad yes/without-password/no argument: %s\n", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 427 | filename, linenum, arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 428 | exit(1); |
| 429 | } |
| 430 | if (*intptr == -1) |
| 431 | *intptr = value; |
| 432 | break; |
| 433 | |
| 434 | case sIgnoreRhosts: |
| 435 | intptr = &options->ignore_rhosts; |
| 436 | parse_flag: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 437 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 438 | if (!arg || *arg == '\0') { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 439 | fprintf(stderr, "%s line %d: missing yes/no argument.\n", |
| 440 | filename, linenum); |
| 441 | exit(1); |
| 442 | } |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 443 | if (strcmp(arg, "yes") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 444 | value = 1; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 445 | else if (strcmp(arg, "no") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 446 | value = 0; |
| 447 | else { |
| 448 | fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 449 | filename, linenum, arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 450 | exit(1); |
| 451 | } |
| 452 | if (*intptr == -1) |
| 453 | *intptr = value; |
| 454 | break; |
| 455 | |
| 456 | case sIgnoreUserKnownHosts: |
| 457 | intptr = &options->ignore_user_known_hosts; |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 458 | goto parse_flag; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 459 | |
| 460 | case sRhostsAuthentication: |
| 461 | intptr = &options->rhosts_authentication; |
| 462 | goto parse_flag; |
| 463 | |
| 464 | case sRhostsRSAAuthentication: |
| 465 | intptr = &options->rhosts_rsa_authentication; |
| 466 | goto parse_flag; |
| 467 | |
| 468 | case sRSAAuthentication: |
| 469 | intptr = &options->rsa_authentication; |
| 470 | goto parse_flag; |
| 471 | |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 472 | case sDSAAuthentication: |
| 473 | intptr = &options->dsa_authentication; |
| 474 | goto parse_flag; |
| 475 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 476 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 477 | case sKerberosAuthentication: |
| 478 | intptr = &options->kerberos_authentication; |
| 479 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 480 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 481 | case sKerberosOrLocalPasswd: |
| 482 | intptr = &options->kerberos_or_local_passwd; |
| 483 | goto parse_flag; |
| 484 | |
| 485 | case sKerberosTicketCleanup: |
| 486 | intptr = &options->kerberos_ticket_cleanup; |
| 487 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 488 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 489 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 490 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 491 | case sKerberosTgtPassing: |
| 492 | intptr = &options->kerberos_tgt_passing; |
| 493 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 494 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 495 | case sAFSTokenPassing: |
| 496 | intptr = &options->afs_token_passing; |
| 497 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 498 | #endif |
| 499 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 500 | case sPasswordAuthentication: |
| 501 | intptr = &options->password_authentication; |
| 502 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 503 | |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 504 | case sKbdInteractiveAuthentication: |
| 505 | intptr = &options->kbd_interactive_authentication; |
| 506 | goto parse_flag; |
| 507 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 508 | case sCheckMail: |
| 509 | intptr = &options->check_mail; |
| 510 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 511 | |
| 512 | #ifdef SKEY |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 513 | case sSkeyAuthentication: |
| 514 | intptr = &options->skey_authentication; |
| 515 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 516 | #endif |
| 517 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 518 | case sPrintMotd: |
| 519 | intptr = &options->print_motd; |
| 520 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 521 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 522 | case sX11Forwarding: |
| 523 | intptr = &options->x11_forwarding; |
| 524 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 525 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 526 | case sX11DisplayOffset: |
| 527 | intptr = &options->x11_display_offset; |
| 528 | goto parse_int; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 529 | |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 530 | case sXAuthLocation: |
| 531 | charptr = &options->xauth_location; |
| 532 | goto parse_filename; |
| 533 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 534 | case sStrictModes: |
| 535 | intptr = &options->strict_modes; |
| 536 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 537 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 538 | case sKeepAlives: |
| 539 | intptr = &options->keepalives; |
| 540 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 541 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 542 | case sEmptyPasswd: |
| 543 | intptr = &options->permit_empty_passwd; |
| 544 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 545 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 546 | case sUseLogin: |
| 547 | intptr = &options->use_login; |
| 548 | goto parse_flag; |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 549 | |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 550 | case sGatewayPorts: |
| 551 | intptr = &options->gateway_ports; |
| 552 | goto parse_flag; |
| 553 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 554 | case sLogFacility: |
| 555 | intptr = (int *) &options->log_facility; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 556 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 557 | value = log_facility_number(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 558 | if (value == (SyslogFacility) - 1) |
| 559 | fatal("%.200s line %d: unsupported log facility '%s'\n", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 560 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 561 | if (*intptr == -1) |
| 562 | *intptr = (SyslogFacility) value; |
| 563 | break; |
| 564 | |
| 565 | case sLogLevel: |
| 566 | intptr = (int *) &options->log_level; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 567 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 568 | value = log_level_number(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 569 | if (value == (LogLevel) - 1) |
| 570 | fatal("%.200s line %d: unsupported log level '%s'\n", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 571 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 572 | if (*intptr == -1) |
| 573 | *intptr = (LogLevel) value; |
| 574 | break; |
| 575 | |
| 576 | case sAllowUsers: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 577 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 578 | if (options->num_allow_users >= MAX_ALLOW_USERS) |
| 579 | fatal("%s line %d: too many allow users.\n", |
| 580 | filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 581 | options->allow_users[options->num_allow_users++] = xstrdup(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 582 | } |
| 583 | break; |
| 584 | |
| 585 | case sDenyUsers: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 586 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 587 | if (options->num_deny_users >= MAX_DENY_USERS) |
| 588 | fatal( "%s line %d: too many deny users.\n", |
| 589 | filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 590 | options->deny_users[options->num_deny_users++] = xstrdup(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 591 | } |
| 592 | break; |
| 593 | |
| 594 | case sAllowGroups: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 595 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 596 | if (options->num_allow_groups >= MAX_ALLOW_GROUPS) |
| 597 | fatal("%s line %d: too many allow groups.\n", |
| 598 | filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 599 | options->allow_groups[options->num_allow_groups++] = xstrdup(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 600 | } |
| 601 | break; |
| 602 | |
| 603 | case sDenyGroups: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 604 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 605 | if (options->num_deny_groups >= MAX_DENY_GROUPS) |
| 606 | fatal("%s line %d: too many deny groups.\n", |
| 607 | filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 608 | options->deny_groups[options->num_deny_groups++] = xstrdup(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 609 | } |
| 610 | break; |
| 611 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 612 | case sCiphers: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 613 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 614 | if (!arg || *arg == '\0') |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 615 | fatal("%s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 616 | if (!ciphers_valid(arg)) |
Damien Miller | 30c3d42 | 2000-05-09 11:02:59 +1000 | [diff] [blame] | 617 | fatal("%s line %d: Bad SSH2 cipher spec '%s'.", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 618 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 619 | if (options->ciphers == NULL) |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 620 | options->ciphers = xstrdup(arg); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 621 | break; |
| 622 | |
| 623 | case sProtocol: |
| 624 | intptr = &options->protocol; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 625 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 626 | if (!arg || *arg == '\0') |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 627 | fatal("%s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 628 | value = proto_spec(arg); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 629 | if (value == SSH_PROTO_UNKNOWN) |
| 630 | fatal("%s line %d: Bad protocol spec '%s'.", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 631 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 632 | if (*intptr == SSH_PROTO_UNKNOWN) |
| 633 | *intptr = value; |
| 634 | break; |
| 635 | |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 636 | case sSubsystem: |
| 637 | if(options->num_subsystems >= MAX_SUBSYSTEMS) { |
| 638 | fatal("%s line %d: too many subsystems defined.", |
| 639 | filename, linenum); |
| 640 | } |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 641 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 642 | if (!arg || *arg == '\0') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 643 | fatal("%s line %d: Missing subsystem name.", |
| 644 | filename, linenum); |
| 645 | for (i = 0; i < options->num_subsystems; i++) |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 646 | if(strcmp(arg, options->subsystem_name[i]) == 0) |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 647 | fatal("%s line %d: Subsystem '%s' already defined.", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 648 | filename, linenum, arg); |
| 649 | options->subsystem_name[options->num_subsystems] = xstrdup(arg); |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 650 | arg = strdelim(&cp); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 651 | if (!arg || *arg == '\0') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 652 | fatal("%s line %d: Missing subsystem command.", |
| 653 | filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 654 | options->subsystem_command[options->num_subsystems] = xstrdup(arg); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 655 | options->num_subsystems++; |
| 656 | break; |
| 657 | |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 658 | case sMaxStartups: |
Damien Miller | 942da03 | 2000-08-18 13:59:06 +1000 | [diff] [blame] | 659 | arg = strdelim(&cp); |
| 660 | if (!arg || *arg == '\0') |
| 661 | fatal("%s line %d: Missing MaxStartups spec.", |
| 662 | filename, linenum); |
| 663 | if (sscanf(arg, "%d:%d:%d", |
| 664 | &options->max_startups_begin, |
| 665 | &options->max_startups_rate, |
| 666 | &options->max_startups) == 3) { |
| 667 | if (options->max_startups_begin > |
| 668 | options->max_startups || |
| 669 | options->max_startups_rate > 100 || |
| 670 | options->max_startups_rate < 1) |
| 671 | fatal("%s line %d: Illegal MaxStartups spec.", |
| 672 | filename, linenum); |
| 673 | break; |
| 674 | } |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 675 | intptr = &options->max_startups; |
| 676 | goto parse_int; |
| 677 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 678 | default: |
| 679 | fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 680 | filename, linenum, arg, opcode); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 681 | exit(1); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 682 | } |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 683 | if ((arg = strdelim(&cp)) != NULL && *arg != '\0') { |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 684 | fprintf(stderr, |
| 685 | "%s line %d: garbage at end of line; \"%.200s\".\n", |
| 686 | filename, linenum, arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 687 | exit(1); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 688 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 689 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 690 | fclose(f); |
| 691 | if (bad_options > 0) { |
| 692 | fprintf(stderr, "%s: terminating, %d bad configuration options\n", |
| 693 | filename, bad_options); |
| 694 | exit(1); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 695 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 696 | } |