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