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