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