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