Annotation of src/usr.bin/ssh/servconf.c, Revision 1.155
1.155 ! stevesk 1: /* $OpenBSD: servconf.c,v 1.154 2006/07/12 22:28:52 stevesk Exp $ */
1.1 deraadt 2: /*
1.26 deraadt 3: * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4: * All rights reserved
1.34 markus 5: *
1.51 deraadt 6: * As far as I am concerned, the code I have written for this software
7: * can be used freely for any purpose. Any derived versions of this
8: * software must be clearly marked as such, and if the derived work is
9: * incompatible with the protocol description in the RFC file, it must be
10: * called by a name other than "ssh" or "Secure Shell".
1.26 deraadt 11: */
1.1 deraadt 12:
13: #include "includes.h"
1.152 stevesk 14:
15: #include <sys/types.h>
16: #include <sys/socket.h>
1.154 stevesk 17:
18: #include <netdb.h>
1.155 ! stevesk 19: #include <unistd.h>
1.1 deraadt 20:
21: #include "ssh.h"
1.62 markus 22: #include "log.h"
1.1 deraadt 23: #include "servconf.h"
24: #include "xmalloc.h"
1.33 markus 25: #include "compat.h"
1.60 markus 26: #include "pathnames.h"
1.62 markus 27: #include "misc.h"
28: #include "cipher.h"
1.66 markus 29: #include "kex.h"
30: #include "mac.h"
1.153 dtucker 31: #include "match.h"
1.1 deraadt 32:
1.84 itojun 33: static void add_listen_addr(ServerOptions *, char *, u_short);
34: static void add_one_listen_addr(ServerOptions *, char *, u_short);
1.29 markus 35:
1.102 provos 36: /* Use of privilege separation or not */
37: extern int use_privsep;
1.153 dtucker 38: extern Buffer cfg;
1.62 markus 39:
1.1 deraadt 40: /* Initializes the server options to their default values. */
41:
1.34 markus 42: void
1.25 markus 43: initialize_server_options(ServerOptions *options)
1.1 deraadt 44: {
1.25 markus 45: memset(options, 0, sizeof(*options));
1.29 markus 46: options->num_ports = 0;
47: options->ports_from_cmdline = 0;
48: options->listen_addrs = NULL;
1.138 djm 49: options->address_family = -1;
1.54 markus 50: options->num_host_key_files = 0;
1.36 markus 51: options->pid_file = NULL;
1.25 markus 52: options->server_key_bits = -1;
53: options->login_grace_time = -1;
54: options->key_regeneration_time = -1;
1.67 markus 55: options->permit_root_login = PERMIT_NOT_SET;
1.25 markus 56: options->ignore_rhosts = -1;
57: options->ignore_user_known_hosts = -1;
58: options->print_motd = -1;
1.72 stevesk 59: options->print_lastlog = -1;
1.25 markus 60: options->x11_forwarding = -1;
61: options->x11_display_offset = -1;
1.99 stevesk 62: options->x11_use_localhost = -1;
1.42 markus 63: options->xauth_location = NULL;
1.25 markus 64: options->strict_modes = -1;
1.129 markus 65: options->tcp_keep_alive = -1;
1.101 markus 66: options->log_facility = SYSLOG_FACILITY_NOT_SET;
67: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.25 markus 68: options->rhosts_rsa_authentication = -1;
1.75 markus 69: options->hostbased_authentication = -1;
70: options->hostbased_uses_name_from_packet_only = -1;
1.25 markus 71: options->rsa_authentication = -1;
1.54 markus 72: options->pubkey_authentication = -1;
1.25 markus 73: options->kerberos_authentication = -1;
74: options->kerberos_or_local_passwd = -1;
75: options->kerberos_ticket_cleanup = -1;
1.130 jakob 76: options->kerberos_get_afs_token = -1;
1.125 markus 77: options->gss_authentication=-1;
78: options->gss_cleanup_creds = -1;
1.25 markus 79: options->password_authentication = -1;
1.52 markus 80: options->kbd_interactive_authentication = -1;
1.80 markus 81: options->challenge_response_authentication = -1;
1.25 markus 82: options->permit_empty_passwd = -1;
1.113 markus 83: options->permit_user_env = -1;
1.25 markus 84: options->use_login = -1;
1.111 markus 85: options->compression = -1;
1.53 markus 86: options->allow_tcp_forwarding = -1;
1.25 markus 87: options->num_allow_users = 0;
88: options->num_deny_users = 0;
89: options->num_allow_groups = 0;
90: options->num_deny_groups = 0;
1.33 markus 91: options->ciphers = NULL;
1.66 markus 92: options->macs = NULL;
1.33 markus 93: options->protocol = SSH_PROTO_UNKNOWN;
1.38 markus 94: options->gateway_ports = -1;
1.43 jakob 95: options->num_subsystems = 0;
1.50 markus 96: options->max_startups_begin = -1;
97: options->max_startups_rate = -1;
1.46 markus 98: options->max_startups = -1;
1.133 dtucker 99: options->max_authtries = -1;
1.57 markus 100: options->banner = NULL;
1.122 markus 101: options->use_dns = -1;
1.77 beck 102: options->client_alive_interval = -1;
103: options->client_alive_count_max = -1;
1.82 markus 104: options->authorized_keys_file = NULL;
105: options->authorized_keys_file2 = NULL;
1.131 djm 106: options->num_accept_env = 0;
1.145 reyk 107: options->permit_tun = -1;
1.1 deraadt 108: }
109:
1.34 markus 110: void
1.25 markus 111: fill_default_server_options(ServerOptions *options)
1.1 deraadt 112: {
1.54 markus 113: if (options->protocol == SSH_PROTO_UNKNOWN)
114: options->protocol = SSH_PROTO_1|SSH_PROTO_2;
115: if (options->num_host_key_files == 0) {
116: /* fill default hostkeys for protocols */
117: if (options->protocol & SSH_PROTO_1)
1.97 stevesk 118: options->host_key_files[options->num_host_key_files++] =
119: _PATH_HOST_KEY_FILE;
120: if (options->protocol & SSH_PROTO_2) {
121: options->host_key_files[options->num_host_key_files++] =
122: _PATH_HOST_RSA_KEY_FILE;
123: options->host_key_files[options->num_host_key_files++] =
124: _PATH_HOST_DSA_KEY_FILE;
125: }
1.54 markus 126: }
1.29 markus 127: if (options->num_ports == 0)
128: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
129: if (options->listen_addrs == NULL)
1.76 stevesk 130: add_listen_addr(options, NULL, 0);
1.36 markus 131: if (options->pid_file == NULL)
1.60 markus 132: options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
1.25 markus 133: if (options->server_key_bits == -1)
134: options->server_key_bits = 768;
135: if (options->login_grace_time == -1)
1.115 stevesk 136: options->login_grace_time = 120;
1.25 markus 137: if (options->key_regeneration_time == -1)
138: options->key_regeneration_time = 3600;
1.67 markus 139: if (options->permit_root_login == PERMIT_NOT_SET)
140: options->permit_root_login = PERMIT_YES;
1.25 markus 141: if (options->ignore_rhosts == -1)
1.30 markus 142: options->ignore_rhosts = 1;
1.25 markus 143: if (options->ignore_user_known_hosts == -1)
144: options->ignore_user_known_hosts = 0;
145: if (options->print_motd == -1)
146: options->print_motd = 1;
1.72 stevesk 147: if (options->print_lastlog == -1)
148: options->print_lastlog = 1;
1.25 markus 149: if (options->x11_forwarding == -1)
1.30 markus 150: options->x11_forwarding = 0;
1.25 markus 151: if (options->x11_display_offset == -1)
1.30 markus 152: options->x11_display_offset = 10;
1.99 stevesk 153: if (options->x11_use_localhost == -1)
154: options->x11_use_localhost = 1;
1.42 markus 155: if (options->xauth_location == NULL)
1.83 markus 156: options->xauth_location = _PATH_XAUTH;
1.25 markus 157: if (options->strict_modes == -1)
158: options->strict_modes = 1;
1.129 markus 159: if (options->tcp_keep_alive == -1)
160: options->tcp_keep_alive = 1;
1.101 markus 161: if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
1.25 markus 162: options->log_facility = SYSLOG_FACILITY_AUTH;
1.101 markus 163: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.58 markus 164: options->log_level = SYSLOG_LEVEL_INFO;
1.25 markus 165: if (options->rhosts_rsa_authentication == -1)
1.30 markus 166: options->rhosts_rsa_authentication = 0;
1.75 markus 167: if (options->hostbased_authentication == -1)
168: options->hostbased_authentication = 0;
169: if (options->hostbased_uses_name_from_packet_only == -1)
170: options->hostbased_uses_name_from_packet_only = 0;
1.25 markus 171: if (options->rsa_authentication == -1)
172: options->rsa_authentication = 1;
1.54 markus 173: if (options->pubkey_authentication == -1)
174: options->pubkey_authentication = 1;
1.25 markus 175: if (options->kerberos_authentication == -1)
1.107 markus 176: options->kerberos_authentication = 0;
1.25 markus 177: if (options->kerberos_or_local_passwd == -1)
178: options->kerberos_or_local_passwd = 1;
179: if (options->kerberos_ticket_cleanup == -1)
180: options->kerberos_ticket_cleanup = 1;
1.130 jakob 181: if (options->kerberos_get_afs_token == -1)
182: options->kerberos_get_afs_token = 0;
1.125 markus 183: if (options->gss_authentication == -1)
184: options->gss_authentication = 0;
185: if (options->gss_cleanup_creds == -1)
186: options->gss_cleanup_creds = 1;
1.25 markus 187: if (options->password_authentication == -1)
188: options->password_authentication = 1;
1.52 markus 189: if (options->kbd_interactive_authentication == -1)
190: options->kbd_interactive_authentication = 0;
1.80 markus 191: if (options->challenge_response_authentication == -1)
192: options->challenge_response_authentication = 1;
1.25 markus 193: if (options->permit_empty_passwd == -1)
1.30 markus 194: options->permit_empty_passwd = 0;
1.113 markus 195: if (options->permit_user_env == -1)
196: options->permit_user_env = 0;
1.25 markus 197: if (options->use_login == -1)
198: options->use_login = 0;
1.111 markus 199: if (options->compression == -1)
1.143 markus 200: options->compression = COMP_DELAYED;
1.53 markus 201: if (options->allow_tcp_forwarding == -1)
202: options->allow_tcp_forwarding = 1;
1.38 markus 203: if (options->gateway_ports == -1)
204: options->gateway_ports = 0;
1.46 markus 205: if (options->max_startups == -1)
206: options->max_startups = 10;
1.50 markus 207: if (options->max_startups_rate == -1)
208: options->max_startups_rate = 100; /* 100% */
209: if (options->max_startups_begin == -1)
210: options->max_startups_begin = options->max_startups;
1.133 dtucker 211: if (options->max_authtries == -1)
212: options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
1.122 markus 213: if (options->use_dns == -1)
214: options->use_dns = 1;
1.77 beck 215: if (options->client_alive_interval == -1)
1.95 deraadt 216: options->client_alive_interval = 0;
1.77 beck 217: if (options->client_alive_count_max == -1)
218: options->client_alive_count_max = 3;
1.90 markus 219: if (options->authorized_keys_file2 == NULL) {
220: /* authorized_keys_file2 falls back to authorized_keys_file */
221: if (options->authorized_keys_file != NULL)
222: options->authorized_keys_file2 = options->authorized_keys_file;
223: else
224: options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
225: }
226: if (options->authorized_keys_file == NULL)
227: options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
1.145 reyk 228: if (options->permit_tun == -1)
1.146 reyk 229: options->permit_tun = SSH_TUNMODE_NO;
1.102 provos 230:
1.110 markus 231: /* Turn privilege separation on by default */
1.102 provos 232: if (use_privsep == -1)
1.110 markus 233: use_privsep = 1;
1.1 deraadt 234: }
235:
236: /* Keyword tokens. */
1.25 markus 237: typedef enum {
238: sBadOption, /* == unknown option */
239: sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
240: sPermitRootLogin, sLogFacility, sLogLevel,
1.124 markus 241: sRhostsRSAAuthentication, sRSAAuthentication,
1.25 markus 242: sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.130 jakob 243: sKerberosGetAFSToken,
1.123 markus 244: sKerberosTgtPassing, sChallengeResponseAuthentication,
1.138 djm 245: sPasswordAuthentication, sKbdInteractiveAuthentication,
246: sListenAddress, sAddressFamily,
1.72 stevesk 247: sPrintMotd, sPrintLastLog, sIgnoreRhosts,
1.99 stevesk 248: sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
1.129 markus 249: sStrictModes, sEmptyPasswd, sTCPKeepAlive,
1.113 markus 250: sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
1.53 markus 251: sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.66 markus 252: sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
1.133 dtucker 253: sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
254: sMaxStartups, sMaxAuthTries,
1.122 markus 255: sBanner, sUseDNS, sHostbasedAuthentication,
1.95 deraadt 256: sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
1.89 jakob 257: sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
1.145 reyk 258: sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
1.153 dtucker 259: sMatch,
1.105 stevesk 260: sUsePrivilegeSeparation,
1.121 jakob 261: sDeprecated, sUnsupported
1.1 deraadt 262: } ServerOpCodes;
263:
1.153 dtucker 264: #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
265: #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
266: #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
267:
1.1 deraadt 268: /* Textual representation of the tokens. */
1.25 markus 269: static struct {
270: const char *name;
271: ServerOpCodes opcode;
1.153 dtucker 272: u_int flags;
1.25 markus 273: } keywords[] = {
1.153 dtucker 274: { "port", sPort, SSHCFG_GLOBAL },
275: { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
276: { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
277: { "pidfile", sPidFile, SSHCFG_GLOBAL },
278: { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
279: { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
280: { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
281: { "permitrootlogin", sPermitRootLogin, SSHCFG_GLOBAL },
282: { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
283: { "loglevel", sLogLevel, SSHCFG_GLOBAL },
284: { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
285: { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_GLOBAL },
286: { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_GLOBAL },
287: { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_GLOBAL },
288: { "rsaauthentication", sRSAAuthentication, SSHCFG_GLOBAL },
289: { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL },
290: { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
1.123 markus 291: #ifdef KRB5
1.153 dtucker 292: { "kerberosauthentication", sKerberosAuthentication, SSHCFG_GLOBAL },
293: { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
294: { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
295: { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
1.121 jakob 296: #else
1.153 dtucker 297: { "kerberosauthentication", sUnsupported, SSHCFG_GLOBAL },
298: { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
299: { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
300: { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
1.126 markus 301: #endif
1.153 dtucker 302: { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
303: { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
1.125 markus 304: #ifdef GSSAPI
1.153 dtucker 305: { "gssapiauthentication", sGssAuthentication, SSHCFG_GLOBAL },
306: { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
1.125 markus 307: #else
1.153 dtucker 308: { "gssapiauthentication", sUnsupported, SSHCFG_GLOBAL },
309: { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
1.125 markus 310: #endif
1.153 dtucker 311: { "passwordauthentication", sPasswordAuthentication, SSHCFG_GLOBAL },
312: { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_GLOBAL },
313: { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
314: { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
315: { "checkmail", sDeprecated, SSHCFG_GLOBAL },
316: { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
317: { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
318: { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
319: { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
320: { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
321: { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
322: { "x11forwarding", sX11Forwarding, SSHCFG_GLOBAL },
323: { "x11displayoffset", sX11DisplayOffset, SSHCFG_GLOBAL },
324: { "x11uselocalhost", sX11UseLocalhost, SSHCFG_GLOBAL },
325: { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
326: { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
327: { "permitemptypasswords", sEmptyPasswd, SSHCFG_GLOBAL },
328: { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
329: { "uselogin", sUseLogin, SSHCFG_GLOBAL },
330: { "compression", sCompression, SSHCFG_GLOBAL },
331: { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
332: { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
333: { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
334: { "allowusers", sAllowUsers, SSHCFG_GLOBAL },
335: { "denyusers", sDenyUsers, SSHCFG_GLOBAL },
336: { "allowgroups", sAllowGroups, SSHCFG_GLOBAL },
337: { "denygroups", sDenyGroups, SSHCFG_GLOBAL },
338: { "ciphers", sCiphers, SSHCFG_GLOBAL },
339: { "macs", sMacs, SSHCFG_GLOBAL },
340: { "protocol", sProtocol, SSHCFG_GLOBAL },
341: { "gatewayports", sGatewayPorts, SSHCFG_ALL },
342: { "subsystem", sSubsystem, SSHCFG_GLOBAL },
343: { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
344: { "maxauthtries", sMaxAuthTries, SSHCFG_GLOBAL },
345: { "banner", sBanner, SSHCFG_GLOBAL },
346: { "usedns", sUseDNS, SSHCFG_GLOBAL },
347: { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
348: { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
349: { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
350: { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
351: { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL },
352: { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL },
353: { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
354: { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
355: { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL },
356: { "match", sMatch, SSHCFG_ALL },
357: { NULL, sBadOption, 0 }
1.1 deraadt 358: };
359:
1.27 markus 360: /*
1.73 stevesk 361: * Returns the number of the token pointed to by cp or sBadOption.
1.27 markus 362: */
1.1 deraadt 363:
1.34 markus 364: static ServerOpCodes
1.25 markus 365: parse_token(const char *cp, const char *filename,
1.153 dtucker 366: int linenum, u_int *flags)
1.1 deraadt 367: {
1.55 markus 368: u_int i;
1.1 deraadt 369:
1.25 markus 370: for (i = 0; keywords[i].name; i++)
1.153 dtucker 371: if (strcasecmp(cp, keywords[i].name) == 0) {
372: *flags = keywords[i].flags;
1.25 markus 373: return keywords[i].opcode;
1.153 dtucker 374: }
1.25 markus 375:
1.78 stevesk 376: error("%s: line %d: Bad configuration option: %s",
377: filename, linenum, cp);
1.25 markus 378: return sBadOption;
1.1 deraadt 379: }
380:
1.84 itojun 381: static void
1.76 stevesk 382: add_listen_addr(ServerOptions *options, char *addr, u_short port)
1.74 stevesk 383: {
1.142 djm 384: u_int i;
1.74 stevesk 385:
386: if (options->num_ports == 0)
387: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
1.138 djm 388: if (options->address_family == -1)
389: options->address_family = AF_UNSPEC;
1.76 stevesk 390: if (port == 0)
1.74 stevesk 391: for (i = 0; i < options->num_ports; i++)
392: add_one_listen_addr(options, addr, options->ports[i]);
393: else
1.76 stevesk 394: add_one_listen_addr(options, addr, port);
1.74 stevesk 395: }
396:
1.84 itojun 397: static void
1.74 stevesk 398: add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
1.29 markus 399: {
400: struct addrinfo hints, *ai, *aitop;
401: char strport[NI_MAXSERV];
402: int gaierr;
403:
1.74 stevesk 404: memset(&hints, 0, sizeof(hints));
1.138 djm 405: hints.ai_family = options->address_family;
1.74 stevesk 406: hints.ai_socktype = SOCK_STREAM;
407: hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
1.112 deraadt 408: snprintf(strport, sizeof strport, "%u", port);
1.74 stevesk 409: if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
410: fatal("bad addr or host: %s (%s)",
411: addr ? addr : "<NULL>",
412: gai_strerror(gaierr));
413: for (ai = aitop; ai->ai_next; ai = ai->ai_next)
414: ;
415: ai->ai_next = options->listen_addrs;
416: options->listen_addrs = aitop;
1.29 markus 417: }
418:
1.153 dtucker 419: /*
420: * The strategy for the Match blocks is that the config file is parsed twice.
421: *
422: * The first time is at startup. activep is initialized to 1 and the
423: * directives in the global context are processed and acted on. Hitting a
424: * Match directive unsets activep and the directives inside the block are
425: * checked for syntax only.
426: *
427: * The second time is after a connection has been established but before
428: * authentication. activep is initialized to 2 and global config directives
429: * are ignored since they have already been processed. If the criteria in a
430: * Match block is met, activep is set and the subsequent directives
431: * processed and actioned until EOF or another Match block unsets it. Any
432: * options set are copied into the main server config.
433: *
434: * Potential additions/improvements:
435: * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
436: *
437: * - Add a Tag directive (idea from David Leonard) ala pf, eg:
438: * Match Address 192.168.0.*
439: * Tag trusted
440: * Match Group wheel
441: * Tag trusted
442: * Match Tag trusted
443: * AllowTcpForwarding yes
444: * GatewayPorts clientspecified
445: * [...]
446: *
447: * - Add a PermittedChannelRequests directive
448: * Match Group shell
449: * PermittedChannelRequests session,forwarded-tcpip
450: */
451:
452: static int
453: match_cfg_line(char **condition, int line, const char *user, const char *host,
454: const char *address)
455: {
456: int result = 1;
457: char *arg, *attrib, *cp = *condition;
458: size_t len;
459:
460: if (user == NULL)
461: debug3("checking syntax for 'Match %s'", cp);
462: else
463: debug3("checking match for '%s' user %s host %s addr %s", cp,
464: user ? user : "(null)", host ? host : "(null)",
465: address ? address : "(null)");
466:
467: while ((attrib = strdelim(&cp)) && *attrib != '\0') {
468: if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
469: error("Missing Match criteria for %s", attrib);
470: return -1;
471: }
472: len = strlen(arg);
473: if (strcasecmp(attrib, "user") == 0) {
474: if (!user) {
475: result = 0;
476: continue;
477: }
478: if (match_pattern_list(user, arg, len, 0) != 1)
479: result = 0;
480: else
481: debug("user %.100s matched 'User %.100s' at "
482: "line %d", user, arg, line);
483: } else if (strcasecmp(attrib, "host") == 0) {
484: if (!host) {
485: result = 0;
486: continue;
487: }
488: if (match_hostname(host, arg, len) != 1)
489: result = 0;
490: else
491: debug("connection from %.100s matched 'Host "
492: "%.100s' at line %d", host, arg, line);
493: } else if (strcasecmp(attrib, "address") == 0) {
494: debug("address '%s' arg '%s'", address, arg);
495: if (!address) {
496: result = 0;
497: continue;
498: }
499: if (match_hostname(address, arg, len) != 1)
500: result = 0;
501: else
502: debug("connection from %.100s matched 'Address "
503: "%.100s' at line %d", address, arg, line);
504: } else {
505: error("Unsupported Match attribute %s", attrib);
506: return -1;
507: }
508: }
509: if (user != NULL)
510: debug3("match %sfound", result ? "" : "not ");
511: *condition = cp;
512: return result;
513: }
514:
1.94 markus 515: int
516: process_server_config_line(ServerOptions *options, char *line,
1.153 dtucker 517: const char *filename, int linenum, int *activep, const char *user,
518: const char *host, const char *address)
1.1 deraadt 519: {
1.74 stevesk 520: char *cp, **charptr, *arg, *p;
1.153 dtucker 521: int cmdline = 0, *intptr, value, n;
1.25 markus 522: ServerOpCodes opcode;
1.139 djm 523: u_short port;
1.153 dtucker 524: u_int i, flags = 0;
1.151 djm 525: size_t len;
1.25 markus 526:
1.94 markus 527: cp = line;
1.148 dtucker 528: if ((arg = strdelim(&cp)) == NULL)
1.147 djm 529: return 0;
1.94 markus 530: /* Ignore leading whitespace */
531: if (*arg == '\0')
532: arg = strdelim(&cp);
533: if (!arg || !*arg || *arg == '#')
534: return 0;
535: intptr = NULL;
536: charptr = NULL;
1.153 dtucker 537: opcode = parse_token(arg, filename, linenum, &flags);
538:
539: if (activep == NULL) { /* We are processing a command line directive */
540: cmdline = 1;
541: activep = &cmdline;
542: }
543: if (*activep && opcode != sMatch)
544: debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
545: if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
546: if (user == NULL) {
547: fatal("%s line %d: Directive '%s' is not allowed "
548: "within a Match block", filename, linenum, arg);
549: } else { /* this is a directive we have already processed */
550: while (arg)
551: arg = strdelim(&cp);
552: return 0;
553: }
554: }
555:
1.94 markus 556: switch (opcode) {
557: case sBadOption:
558: return -1;
559: case sPort:
560: /* ignore ports from configfile if cmdline specifies ports */
561: if (options->ports_from_cmdline)
562: return 0;
563: if (options->listen_addrs != NULL)
564: fatal("%s line %d: ports must be specified before "
1.98 stevesk 565: "ListenAddress.", filename, linenum);
1.94 markus 566: if (options->num_ports >= MAX_PORTS)
567: fatal("%s line %d: too many ports.",
568: filename, linenum);
1.48 provos 569: arg = strdelim(&cp);
1.94 markus 570: if (!arg || *arg == '\0')
571: fatal("%s line %d: missing port number.",
572: filename, linenum);
573: options->ports[options->num_ports++] = a2port(arg);
574: if (options->ports[options->num_ports-1] == 0)
575: fatal("%s line %d: Badly formatted port number.",
576: filename, linenum);
577: break;
1.29 markus 578:
1.94 markus 579: case sServerKeyBits:
580: intptr = &options->server_key_bits;
1.25 markus 581: parse_int:
1.94 markus 582: arg = strdelim(&cp);
583: if (!arg || *arg == '\0')
584: fatal("%s line %d: missing integer value.",
585: filename, linenum);
586: value = atoi(arg);
1.153 dtucker 587: if (*activep && *intptr == -1)
1.94 markus 588: *intptr = value;
589: break;
1.25 markus 590:
1.94 markus 591: case sLoginGraceTime:
592: intptr = &options->login_grace_time;
1.81 stevesk 593: parse_time:
1.94 markus 594: arg = strdelim(&cp);
595: if (!arg || *arg == '\0')
596: fatal("%s line %d: missing time value.",
597: filename, linenum);
598: if ((value = convtime(arg)) == -1)
599: fatal("%s line %d: invalid time value.",
600: filename, linenum);
601: if (*intptr == -1)
602: *intptr = value;
603: break;
604:
605: case sKeyRegenerationTime:
606: intptr = &options->key_regeneration_time;
607: goto parse_time;
608:
609: case sListenAddress:
610: arg = strdelim(&cp);
1.139 djm 611: if (arg == NULL || *arg == '\0')
612: fatal("%s line %d: missing address",
1.94 markus 613: filename, linenum);
1.144 dtucker 614: /* check for bare IPv6 address: no "[]" and 2 or more ":" */
615: if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
616: && strchr(p+1, ':') != NULL) {
617: add_listen_addr(options, arg, 0);
618: break;
619: }
1.139 djm 620: p = hpdelim(&arg);
621: if (p == NULL)
622: fatal("%s line %d: bad address:port usage",
623: filename, linenum);
624: p = cleanhostname(p);
625: if (arg == NULL)
626: port = 0;
627: else if ((port = a2port(arg)) == 0)
628: fatal("%s line %d: bad port number", filename, linenum);
629:
630: add_listen_addr(options, p, port);
1.25 markus 631:
1.138 djm 632: break;
633:
634: case sAddressFamily:
635: arg = strdelim(&cp);
1.141 markus 636: if (!arg || *arg == '\0')
637: fatal("%s line %d: missing address family.",
638: filename, linenum);
1.138 djm 639: intptr = &options->address_family;
640: if (options->listen_addrs != NULL)
641: fatal("%s line %d: address family must be specified before "
642: "ListenAddress.", filename, linenum);
643: if (strcasecmp(arg, "inet") == 0)
644: value = AF_INET;
645: else if (strcasecmp(arg, "inet6") == 0)
646: value = AF_INET6;
647: else if (strcasecmp(arg, "any") == 0)
648: value = AF_UNSPEC;
649: else
650: fatal("%s line %d: unsupported address family \"%s\".",
651: filename, linenum, arg);
652: if (*intptr == -1)
653: *intptr = value;
1.94 markus 654: break;
655:
656: case sHostKeyFile:
657: intptr = &options->num_host_key_files;
658: if (*intptr >= MAX_HOSTKEYS)
659: fatal("%s line %d: too many host keys specified (max %d).",
660: filename, linenum, MAX_HOSTKEYS);
661: charptr = &options->host_key_files[*intptr];
662: parse_filename:
663: arg = strdelim(&cp);
664: if (!arg || *arg == '\0')
665: fatal("%s line %d: missing file name.",
666: filename, linenum);
1.153 dtucker 667: if (*activep && *charptr == NULL) {
1.94 markus 668: *charptr = tilde_expand_filename(arg, getuid());
669: /* increase optional counter */
670: if (intptr != NULL)
671: *intptr = *intptr + 1;
672: }
673: break;
1.76 stevesk 674:
1.94 markus 675: case sPidFile:
676: charptr = &options->pid_file;
677: goto parse_filename;
1.25 markus 678:
1.94 markus 679: case sPermitRootLogin:
680: intptr = &options->permit_root_login;
681: arg = strdelim(&cp);
682: if (!arg || *arg == '\0')
683: fatal("%s line %d: missing yes/"
684: "without-password/forced-commands-only/no "
685: "argument.", filename, linenum);
686: value = 0; /* silence compiler */
687: if (strcmp(arg, "without-password") == 0)
688: value = PERMIT_NO_PASSWD;
689: else if (strcmp(arg, "forced-commands-only") == 0)
690: value = PERMIT_FORCED_ONLY;
691: else if (strcmp(arg, "yes") == 0)
692: value = PERMIT_YES;
693: else if (strcmp(arg, "no") == 0)
694: value = PERMIT_NO;
695: else
696: fatal("%s line %d: Bad yes/"
697: "without-password/forced-commands-only/no "
698: "argument: %s", filename, linenum, arg);
699: if (*intptr == -1)
700: *intptr = value;
701: break;
1.36 markus 702:
1.94 markus 703: case sIgnoreRhosts:
704: intptr = &options->ignore_rhosts;
1.25 markus 705: parse_flag:
1.94 markus 706: arg = strdelim(&cp);
707: if (!arg || *arg == '\0')
708: fatal("%s line %d: missing yes/no argument.",
709: filename, linenum);
710: value = 0; /* silence compiler */
711: if (strcmp(arg, "yes") == 0)
712: value = 1;
713: else if (strcmp(arg, "no") == 0)
714: value = 0;
715: else
716: fatal("%s line %d: Bad yes/no argument: %s",
717: filename, linenum, arg);
1.153 dtucker 718: if (*activep && *intptr == -1)
1.94 markus 719: *intptr = value;
720: break;
721:
722: case sIgnoreUserKnownHosts:
723: intptr = &options->ignore_user_known_hosts;
724: goto parse_flag;
725:
726: case sRhostsRSAAuthentication:
727: intptr = &options->rhosts_rsa_authentication;
728: goto parse_flag;
729:
730: case sHostbasedAuthentication:
731: intptr = &options->hostbased_authentication;
732: goto parse_flag;
733:
734: case sHostbasedUsesNameFromPacketOnly:
735: intptr = &options->hostbased_uses_name_from_packet_only;
736: goto parse_flag;
737:
738: case sRSAAuthentication:
739: intptr = &options->rsa_authentication;
740: goto parse_flag;
741:
742: case sPubkeyAuthentication:
743: intptr = &options->pubkey_authentication;
744: goto parse_flag;
1.119 jakob 745:
1.94 markus 746: case sKerberosAuthentication:
747: intptr = &options->kerberos_authentication;
748: goto parse_flag;
749:
750: case sKerberosOrLocalPasswd:
751: intptr = &options->kerberos_or_local_passwd;
752: goto parse_flag;
753:
754: case sKerberosTicketCleanup:
755: intptr = &options->kerberos_ticket_cleanup;
1.130 jakob 756: goto parse_flag;
757:
758: case sKerberosGetAFSToken:
759: intptr = &options->kerberos_get_afs_token;
1.125 markus 760: goto parse_flag;
761:
762: case sGssAuthentication:
763: intptr = &options->gss_authentication;
764: goto parse_flag;
765:
766: case sGssCleanupCreds:
767: intptr = &options->gss_cleanup_creds;
1.94 markus 768: goto parse_flag;
769:
770: case sPasswordAuthentication:
771: intptr = &options->password_authentication;
772: goto parse_flag;
773:
774: case sKbdInteractiveAuthentication:
775: intptr = &options->kbd_interactive_authentication;
776: goto parse_flag;
777:
778: case sChallengeResponseAuthentication:
779: intptr = &options->challenge_response_authentication;
780: goto parse_flag;
781:
782: case sPrintMotd:
783: intptr = &options->print_motd;
784: goto parse_flag;
785:
786: case sPrintLastLog:
787: intptr = &options->print_lastlog;
788: goto parse_flag;
789:
790: case sX11Forwarding:
791: intptr = &options->x11_forwarding;
792: goto parse_flag;
793:
794: case sX11DisplayOffset:
795: intptr = &options->x11_display_offset;
796: goto parse_int;
1.99 stevesk 797:
798: case sX11UseLocalhost:
799: intptr = &options->x11_use_localhost;
800: goto parse_flag;
1.94 markus 801:
802: case sXAuthLocation:
803: charptr = &options->xauth_location;
804: goto parse_filename;
805:
806: case sStrictModes:
807: intptr = &options->strict_modes;
808: goto parse_flag;
809:
1.129 markus 810: case sTCPKeepAlive:
811: intptr = &options->tcp_keep_alive;
1.94 markus 812: goto parse_flag;
813:
814: case sEmptyPasswd:
815: intptr = &options->permit_empty_passwd;
1.113 markus 816: goto parse_flag;
817:
818: case sPermitUserEnvironment:
819: intptr = &options->permit_user_env;
1.94 markus 820: goto parse_flag;
821:
822: case sUseLogin:
823: intptr = &options->use_login;
1.111 markus 824: goto parse_flag;
825:
826: case sCompression:
827: intptr = &options->compression;
1.143 markus 828: arg = strdelim(&cp);
829: if (!arg || *arg == '\0')
830: fatal("%s line %d: missing yes/no/delayed "
831: "argument.", filename, linenum);
832: value = 0; /* silence compiler */
833: if (strcmp(arg, "delayed") == 0)
834: value = COMP_DELAYED;
835: else if (strcmp(arg, "yes") == 0)
836: value = COMP_ZLIB;
837: else if (strcmp(arg, "no") == 0)
838: value = COMP_NONE;
839: else
840: fatal("%s line %d: Bad yes/no/delayed "
841: "argument: %s", filename, linenum, arg);
842: if (*intptr == -1)
843: *intptr = value;
844: break;
1.94 markus 845:
846: case sGatewayPorts:
847: intptr = &options->gateway_ports;
1.139 djm 848: arg = strdelim(&cp);
849: if (!arg || *arg == '\0')
850: fatal("%s line %d: missing yes/no/clientspecified "
851: "argument.", filename, linenum);
852: value = 0; /* silence compiler */
853: if (strcmp(arg, "clientspecified") == 0)
854: value = 2;
855: else if (strcmp(arg, "yes") == 0)
856: value = 1;
857: else if (strcmp(arg, "no") == 0)
858: value = 0;
859: else
860: fatal("%s line %d: Bad yes/no/clientspecified "
861: "argument: %s", filename, linenum, arg);
862: if (*intptr == -1)
863: *intptr = value;
864: break;
1.25 markus 865:
1.122 markus 866: case sUseDNS:
867: intptr = &options->use_dns;
1.94 markus 868: goto parse_flag;
1.53 markus 869:
1.94 markus 870: case sLogFacility:
871: intptr = (int *) &options->log_facility;
872: arg = strdelim(&cp);
873: value = log_facility_number(arg);
1.101 markus 874: if (value == SYSLOG_FACILITY_NOT_SET)
1.94 markus 875: fatal("%.200s line %d: unsupported log facility '%s'",
876: filename, linenum, arg ? arg : "<NONE>");
877: if (*intptr == -1)
878: *intptr = (SyslogFacility) value;
879: break;
1.25 markus 880:
1.94 markus 881: case sLogLevel:
882: intptr = (int *) &options->log_level;
883: arg = strdelim(&cp);
884: value = log_level_number(arg);
1.101 markus 885: if (value == SYSLOG_LEVEL_NOT_SET)
1.94 markus 886: fatal("%.200s line %d: unsupported log level '%s'",
887: filename, linenum, arg ? arg : "<NONE>");
888: if (*intptr == -1)
889: *intptr = (LogLevel) value;
890: break;
891:
892: case sAllowTcpForwarding:
893: intptr = &options->allow_tcp_forwarding;
894: goto parse_flag;
1.102 provos 895:
896: case sUsePrivilegeSeparation:
897: intptr = &use_privsep;
898: goto parse_flag;
1.94 markus 899:
900: case sAllowUsers:
901: while ((arg = strdelim(&cp)) && *arg != '\0') {
902: if (options->num_allow_users >= MAX_ALLOW_USERS)
903: fatal("%s line %d: too many allow users.",
904: filename, linenum);
1.112 deraadt 905: options->allow_users[options->num_allow_users++] =
906: xstrdup(arg);
1.94 markus 907: }
908: break;
1.25 markus 909:
1.94 markus 910: case sDenyUsers:
911: while ((arg = strdelim(&cp)) && *arg != '\0') {
912: if (options->num_deny_users >= MAX_DENY_USERS)
913: fatal( "%s line %d: too many deny users.",
914: filename, linenum);
1.112 deraadt 915: options->deny_users[options->num_deny_users++] =
916: xstrdup(arg);
1.94 markus 917: }
918: break;
1.25 markus 919:
1.94 markus 920: case sAllowGroups:
921: while ((arg = strdelim(&cp)) && *arg != '\0') {
922: if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
923: fatal("%s line %d: too many allow groups.",
924: filename, linenum);
1.112 deraadt 925: options->allow_groups[options->num_allow_groups++] =
926: xstrdup(arg);
1.94 markus 927: }
928: break;
1.33 markus 929:
1.94 markus 930: case sDenyGroups:
931: while ((arg = strdelim(&cp)) && *arg != '\0') {
932: if (options->num_deny_groups >= MAX_DENY_GROUPS)
933: fatal("%s line %d: too many deny groups.",
934: filename, linenum);
935: options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
936: }
937: break;
1.66 markus 938:
1.94 markus 939: case sCiphers:
940: arg = strdelim(&cp);
941: if (!arg || *arg == '\0')
942: fatal("%s line %d: Missing argument.", filename, linenum);
943: if (!ciphers_valid(arg))
944: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
945: filename, linenum, arg ? arg : "<NONE>");
946: if (options->ciphers == NULL)
947: options->ciphers = xstrdup(arg);
948: break;
1.33 markus 949:
1.94 markus 950: case sMacs:
951: arg = strdelim(&cp);
952: if (!arg || *arg == '\0')
953: fatal("%s line %d: Missing argument.", filename, linenum);
954: if (!mac_valid(arg))
955: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
956: filename, linenum, arg ? arg : "<NONE>");
957: if (options->macs == NULL)
958: options->macs = xstrdup(arg);
959: break;
1.43 jakob 960:
1.94 markus 961: case sProtocol:
962: intptr = &options->protocol;
963: arg = strdelim(&cp);
964: if (!arg || *arg == '\0')
965: fatal("%s line %d: Missing argument.", filename, linenum);
966: value = proto_spec(arg);
967: if (value == SSH_PROTO_UNKNOWN)
968: fatal("%s line %d: Bad protocol spec '%s'.",
1.95 deraadt 969: filename, linenum, arg ? arg : "<NONE>");
1.94 markus 970: if (*intptr == SSH_PROTO_UNKNOWN)
971: *intptr = value;
972: break;
973:
974: case sSubsystem:
975: if (options->num_subsystems >= MAX_SUBSYSTEMS) {
976: fatal("%s line %d: too many subsystems defined.",
1.95 deraadt 977: filename, linenum);
1.94 markus 978: }
979: arg = strdelim(&cp);
980: if (!arg || *arg == '\0')
981: fatal("%s line %d: Missing subsystem name.",
1.95 deraadt 982: filename, linenum);
1.153 dtucker 983: if (!*activep) {
984: arg = strdelim(&cp);
985: break;
986: }
1.94 markus 987: for (i = 0; i < options->num_subsystems; i++)
988: if (strcmp(arg, options->subsystem_name[i]) == 0)
989: fatal("%s line %d: Subsystem '%s' already defined.",
1.95 deraadt 990: filename, linenum, arg);
1.94 markus 991: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
992: arg = strdelim(&cp);
993: if (!arg || *arg == '\0')
994: fatal("%s line %d: Missing subsystem command.",
1.95 deraadt 995: filename, linenum);
1.94 markus 996: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151 djm 997:
998: /* Collect arguments (separate to executable) */
999: p = xstrdup(arg);
1000: len = strlen(p) + 1;
1001: while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1002: len += 1 + strlen(arg);
1003: p = xrealloc(p, 1, len);
1004: strlcat(p, " ", len);
1005: strlcat(p, arg, len);
1006: }
1007: options->subsystem_args[options->num_subsystems] = p;
1.94 markus 1008: options->num_subsystems++;
1009: break;
1.46 markus 1010:
1.94 markus 1011: case sMaxStartups:
1012: arg = strdelim(&cp);
1013: if (!arg || *arg == '\0')
1014: fatal("%s line %d: Missing MaxStartups spec.",
1.95 deraadt 1015: filename, linenum);
1.94 markus 1016: if ((n = sscanf(arg, "%d:%d:%d",
1017: &options->max_startups_begin,
1018: &options->max_startups_rate,
1019: &options->max_startups)) == 3) {
1020: if (options->max_startups_begin >
1021: options->max_startups ||
1022: options->max_startups_rate > 100 ||
1023: options->max_startups_rate < 1)
1.50 markus 1024: fatal("%s line %d: Illegal MaxStartups spec.",
1.87 stevesk 1025: filename, linenum);
1.94 markus 1026: } else if (n != 1)
1027: fatal("%s line %d: Illegal MaxStartups spec.",
1028: filename, linenum);
1029: else
1030: options->max_startups = options->max_startups_begin;
1031: break;
1.133 dtucker 1032:
1033: case sMaxAuthTries:
1034: intptr = &options->max_authtries;
1035: goto parse_int;
1.94 markus 1036:
1037: case sBanner:
1038: charptr = &options->banner;
1039: goto parse_filename;
1040: /*
1041: * These options can contain %X options expanded at
1042: * connect time, so that you can specify paths like:
1043: *
1044: * AuthorizedKeysFile /etc/ssh_keys/%u
1045: */
1046: case sAuthorizedKeysFile:
1047: case sAuthorizedKeysFile2:
1048: charptr = (opcode == sAuthorizedKeysFile ) ?
1049: &options->authorized_keys_file :
1050: &options->authorized_keys_file2;
1051: goto parse_filename;
1052:
1053: case sClientAliveInterval:
1054: intptr = &options->client_alive_interval;
1055: goto parse_time;
1056:
1057: case sClientAliveCountMax:
1058: intptr = &options->client_alive_count_max;
1059: goto parse_int;
1.131 djm 1060:
1061: case sAcceptEnv:
1062: while ((arg = strdelim(&cp)) && *arg != '\0') {
1063: if (strchr(arg, '=') != NULL)
1064: fatal("%s line %d: Invalid environment name.",
1065: filename, linenum);
1066: if (options->num_accept_env >= MAX_ACCEPT_ENV)
1067: fatal("%s line %d: too many allow env.",
1068: filename, linenum);
1.153 dtucker 1069: if (!*activep)
1070: break;
1.131 djm 1071: options->accept_env[options->num_accept_env++] =
1072: xstrdup(arg);
1073: }
1074: break;
1.145 reyk 1075:
1076: case sPermitTunnel:
1077: intptr = &options->permit_tun;
1.146 reyk 1078: arg = strdelim(&cp);
1079: if (!arg || *arg == '\0')
1080: fatal("%s line %d: Missing yes/point-to-point/"
1081: "ethernet/no argument.", filename, linenum);
1082: value = 0; /* silence compiler */
1083: if (strcasecmp(arg, "ethernet") == 0)
1084: value = SSH_TUNMODE_ETHERNET;
1085: else if (strcasecmp(arg, "point-to-point") == 0)
1086: value = SSH_TUNMODE_POINTOPOINT;
1087: else if (strcasecmp(arg, "yes") == 0)
1088: value = SSH_TUNMODE_YES;
1089: else if (strcasecmp(arg, "no") == 0)
1090: value = SSH_TUNMODE_NO;
1091: else
1092: fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1093: "no argument: %s", filename, linenum, arg);
1094: if (*intptr == -1)
1095: *intptr = value;
1096: break;
1.94 markus 1097:
1.153 dtucker 1098: case sMatch:
1099: if (cmdline)
1100: fatal("Match directive not supported as a command-line "
1101: "option");
1102: value = match_cfg_line(&cp, linenum, user, host, address);
1103: if (value < 0)
1104: fatal("%s line %d: Bad Match condition", filename,
1105: linenum);
1106: *activep = value;
1107: break;
1108:
1.94 markus 1109: case sDeprecated:
1.117 itojun 1110: logit("%s line %d: Deprecated option %s",
1.121 jakob 1111: filename, linenum, arg);
1112: while (arg)
1113: arg = strdelim(&cp);
1114: break;
1115:
1116: case sUnsupported:
1117: logit("%s line %d: Unsupported option %s",
1.94 markus 1118: filename, linenum, arg);
1119: while (arg)
1120: arg = strdelim(&cp);
1121: break;
1122:
1123: default:
1124: fatal("%s line %d: Missing handler for opcode %s (%d)",
1125: filename, linenum, arg, opcode);
1126: }
1127: if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1128: fatal("%s line %d: garbage at end of line; \"%.200s\".",
1129: filename, linenum, arg);
1130: return 0;
1131: }
1132:
1133: /* Reads the server configuration file. */
1.25 markus 1134:
1.94 markus 1135: void
1.134 djm 1136: load_server_config(const char *filename, Buffer *conf)
1.94 markus 1137: {
1.134 djm 1138: char line[1024], *cp;
1.94 markus 1139: FILE *f;
1.81 stevesk 1140:
1.134 djm 1141: debug2("%s: filename %s", __func__, filename);
1142: if ((f = fopen(filename, "r")) == NULL) {
1.94 markus 1143: perror(filename);
1144: exit(1);
1145: }
1.134 djm 1146: buffer_clear(conf);
1147: while (fgets(line, sizeof(line), f)) {
1148: /*
1149: * Trim out comments and strip whitespace
1.135 deraadt 1150: * NB - preserve newlines, they are needed to reproduce
1.134 djm 1151: * line numbers later for error messages
1152: */
1153: if ((cp = strchr(line, '#')) != NULL)
1154: memcpy(cp, "\n", 2);
1155: cp = line + strspn(line, " \t\r");
1156:
1157: buffer_append(conf, cp, strlen(cp));
1158: }
1159: buffer_append(conf, "\0", 1);
1160: fclose(f);
1161: debug2("%s: done config len = %d", __func__, buffer_len(conf));
1162: }
1163:
1164: void
1.153 dtucker 1165: parse_server_match_config(ServerOptions *options, const char *user,
1166: const char *host, const char *address)
1167: {
1168: ServerOptions mo;
1169:
1170: initialize_server_options(&mo);
1171: parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
1172: copy_set_server_options(options, &mo);
1173: }
1174:
1175: /* Copy any (supported) values that are set */
1176: void
1177: copy_set_server_options(ServerOptions *dst, ServerOptions *src)
1178: {
1179: if (src->allow_tcp_forwarding != -1)
1180: dst->allow_tcp_forwarding = src->allow_tcp_forwarding;
1181: if (src->gateway_ports != -1)
1182: dst->gateway_ports = src->gateway_ports;
1183: }
1184:
1185: void
1186: parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1187: const char *user, const char *host, const char *address)
1.134 djm 1188: {
1.153 dtucker 1189: int active, linenum, bad_options = 0;
1.136 dtucker 1190: char *cp, *obuf, *cbuf;
1.134 djm 1191:
1192: debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1193:
1.136 dtucker 1194: obuf = cbuf = xstrdup(buffer_ptr(conf));
1.153 dtucker 1195: active = user ? 0 : 1;
1.137 dtucker 1196: linenum = 1;
1.140 deraadt 1197: while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134 djm 1198: if (process_server_config_line(options, cp, filename,
1.153 dtucker 1199: linenum++, &active, user, host, address) != 0)
1.94 markus 1200: bad_options++;
1.1 deraadt 1201: }
1.136 dtucker 1202: xfree(obuf);
1.78 stevesk 1203: if (bad_options > 0)
1204: fatal("%s: terminating, %d bad configuration options",
1205: filename, bad_options);
1.1 deraadt 1206: }