Annotation of src/usr.bin/ssh/servconf.c, Revision 1.316
1.226 dtucker 1:
1.316 ! djm 2: /* $OpenBSD: servconf.c,v 1.315 2017/10/25 00:15:35 djm Exp $ */
1.1 deraadt 3: /*
1.26 deraadt 4: * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5: * All rights reserved
1.34 markus 6: *
1.51 deraadt 7: * As far as I am concerned, the code I have written for this software
8: * can be used freely for any purpose. Any derived versions of this
9: * software must be clearly marked as such, and if the derived work is
10: * incompatible with the protocol description in the RFC file, it must be
11: * called by a name other than "ssh" or "Secure Shell".
1.26 deraadt 12: */
1.1 deraadt 13:
1.152 stevesk 14: #include <sys/types.h>
15: #include <sys/socket.h>
1.179 djm 16: #include <sys/queue.h>
1.315 djm 17: #include <sys/sysctl.h>
1.154 stevesk 18:
1.213 djm 19: #include <netinet/in.h>
20: #include <netinet/ip.h>
1.315 djm 21: #include <net/route.h>
1.213 djm 22:
1.235 dtucker 23: #include <ctype.h>
1.154 stevesk 24: #include <netdb.h>
1.165 dtucker 25: #include <pwd.h>
1.162 stevesk 26: #include <stdio.h>
1.161 stevesk 27: #include <stdlib.h>
1.160 stevesk 28: #include <string.h>
1.164 deraadt 29: #include <signal.h>
1.155 stevesk 30: #include <unistd.h>
1.259 deraadt 31: #include <limits.h>
1.164 deraadt 32: #include <stdarg.h>
1.182 dtucker 33: #include <errno.h>
1.236 dtucker 34: #include <util.h>
1.1 deraadt 35:
1.164 deraadt 36: #include "xmalloc.h"
1.1 deraadt 37: #include "ssh.h"
1.62 markus 38: #include "log.h"
1.164 deraadt 39: #include "buffer.h"
1.251 millert 40: #include "misc.h"
1.1 deraadt 41: #include "servconf.h"
1.33 markus 42: #include "compat.h"
1.60 markus 43: #include "pathnames.h"
1.62 markus 44: #include "cipher.h"
1.164 deraadt 45: #include "key.h"
1.66 markus 46: #include "kex.h"
47: #include "mac.h"
1.153 dtucker 48: #include "match.h"
1.156 dtucker 49: #include "channels.h"
1.165 dtucker 50: #include "groupaccess.h"
1.226 dtucker 51: #include "canohost.h"
52: #include "packet.h"
1.232 djm 53: #include "hostfile.h"
54: #include "auth.h"
1.252 djm 55: #include "myproposal.h"
1.256 djm 56: #include "digest.h"
1.1 deraadt 57:
1.315 djm 58: static void add_listen_addr(ServerOptions *, const char *,
59: const char *, int);
60: static void add_one_listen_addr(ServerOptions *, const char *,
61: const char *, int);
1.29 markus 62:
1.102 provos 63: /* Use of privilege separation or not */
64: extern int use_privsep;
1.153 dtucker 65: extern Buffer cfg;
1.62 markus 66:
1.1 deraadt 67: /* Initializes the server options to their default values. */
68:
1.34 markus 69: void
1.25 markus 70: initialize_server_options(ServerOptions *options)
1.1 deraadt 71: {
1.25 markus 72: memset(options, 0, sizeof(*options));
1.29 markus 73: options->num_ports = 0;
74: options->ports_from_cmdline = 0;
1.266 dtucker 75: options->queued_listen_addrs = NULL;
76: options->num_queued_listens = 0;
1.29 markus 77: options->listen_addrs = NULL;
1.315 djm 78: options->num_listen_addrs = 0;
1.138 djm 79: options->address_family = -1;
1.316 ! djm 80: options->routing_domain = NULL;
1.54 markus 81: options->num_host_key_files = 0;
1.203 djm 82: options->num_host_cert_files = 0;
1.240 markus 83: options->host_key_agent = NULL;
1.36 markus 84: options->pid_file = NULL;
1.25 markus 85: options->login_grace_time = -1;
1.279 chris 86: options->permit_root_login = PERMIT_NOT_SET;
1.25 markus 87: options->ignore_rhosts = -1;
88: options->ignore_user_known_hosts = -1;
89: options->print_motd = -1;
1.72 stevesk 90: options->print_lastlog = -1;
1.25 markus 91: options->x11_forwarding = -1;
92: options->x11_display_offset = -1;
1.99 stevesk 93: options->x11_use_localhost = -1;
1.244 djm 94: options->permit_tty = -1;
1.250 djm 95: options->permit_user_rc = -1;
1.42 markus 96: options->xauth_location = NULL;
1.25 markus 97: options->strict_modes = -1;
1.129 markus 98: options->tcp_keep_alive = -1;
1.101 markus 99: options->log_facility = SYSLOG_FACILITY_NOT_SET;
100: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.75 markus 101: options->hostbased_authentication = -1;
102: options->hostbased_uses_name_from_packet_only = -1;
1.258 djm 103: options->hostbased_key_types = NULL;
1.276 markus 104: options->hostkeyalgorithms = NULL;
1.54 markus 105: options->pubkey_authentication = -1;
1.258 djm 106: options->pubkey_key_types = NULL;
1.25 markus 107: options->kerberos_authentication = -1;
108: options->kerberos_or_local_passwd = -1;
109: options->kerberos_ticket_cleanup = -1;
1.130 jakob 110: options->kerberos_get_afs_token = -1;
1.125 markus 111: options->gss_authentication=-1;
112: options->gss_cleanup_creds = -1;
1.271 djm 113: options->gss_strict_acceptor = -1;
1.25 markus 114: options->password_authentication = -1;
1.52 markus 115: options->kbd_interactive_authentication = -1;
1.80 markus 116: options->challenge_response_authentication = -1;
1.25 markus 117: options->permit_empty_passwd = -1;
1.113 markus 118: options->permit_user_env = -1;
1.111 markus 119: options->compression = -1;
1.235 dtucker 120: options->rekey_limit = -1;
121: options->rekey_interval = -1;
1.53 markus 122: options->allow_tcp_forwarding = -1;
1.251 millert 123: options->allow_streamlocal_forwarding = -1;
1.178 pyr 124: options->allow_agent_forwarding = -1;
1.25 markus 125: options->num_allow_users = 0;
126: options->num_deny_users = 0;
127: options->num_allow_groups = 0;
128: options->num_deny_groups = 0;
1.33 markus 129: options->ciphers = NULL;
1.66 markus 130: options->macs = NULL;
1.211 djm 131: options->kex_algorithms = NULL;
1.251 millert 132: options->fwd_opts.gateway_ports = -1;
133: options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
134: options->fwd_opts.streamlocal_bind_unlink = -1;
1.43 jakob 135: options->num_subsystems = 0;
1.50 markus 136: options->max_startups_begin = -1;
137: options->max_startups_rate = -1;
1.46 markus 138: options->max_startups = -1;
1.133 dtucker 139: options->max_authtries = -1;
1.180 djm 140: options->max_sessions = -1;
1.57 markus 141: options->banner = NULL;
1.122 markus 142: options->use_dns = -1;
1.77 beck 143: options->client_alive_interval = -1;
144: options->client_alive_count_max = -1;
1.219 djm 145: options->num_authkeys_files = 0;
1.131 djm 146: options->num_accept_env = 0;
1.145 reyk 147: options->permit_tun = -1;
1.310 djm 148: options->permitted_opens = NULL;
1.158 dtucker 149: options->adm_forced_command = NULL;
1.176 djm 150: options->chroot_directory = NULL;
1.231 djm 151: options->authorized_keys_command = NULL;
152: options->authorized_keys_command_user = NULL;
1.204 djm 153: options->revoked_keys_file = NULL;
154: options->trusted_user_ca_keys = NULL;
1.208 djm 155: options->authorized_principals_file = NULL;
1.270 djm 156: options->authorized_principals_command = NULL;
157: options->authorized_principals_command_user = NULL;
1.213 djm 158: options->ip_qos_interactive = -1;
159: options->ip_qos_bulk = -1;
1.225 djm 160: options->version_addendum = NULL;
1.256 djm 161: options->fingerprint_hash = -1;
1.301 djm 162: options->disable_forwarding = -1;
1.309 djm 163: options->expose_userauth_info = -1;
1.1 deraadt 164: }
165:
1.257 djm 166: /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
167: static int
168: option_clear_or_none(const char *o)
169: {
170: return o == NULL || strcasecmp(o, "none") == 0;
171: }
172:
1.282 djm 173: static void
174: assemble_algorithms(ServerOptions *o)
175: {
176: if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
177: kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
178: kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
179: kex_assemble_names(KEX_DEFAULT_PK_ALG,
180: &o->hostkeyalgorithms) != 0 ||
181: kex_assemble_names(KEX_DEFAULT_PK_ALG,
182: &o->hostbased_key_types) != 0 ||
183: kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
184: fatal("kex_assemble_names failed");
185: }
186:
1.314 djm 187: static void
188: array_append(const char *file, const int line, const char *directive,
189: char ***array, u_int *lp, const char *s)
190: {
191:
192: if (*lp >= INT_MAX)
193: fatal("%s line %d: Too many %s entries", file, line, directive);
194:
195: *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
196: (*array)[*lp] = xstrdup(s);
197: (*lp)++;
198: }
199:
200: void
201: servconf_add_hostkey(const char *file, const int line,
202: ServerOptions *options, const char *path)
203: {
204: char *apath = derelativise_path(path);
205:
206: array_append(file, line, "HostKey",
207: &options->host_key_files, &options->num_host_key_files, apath);
208: free(apath);
209: }
210:
211: void
212: servconf_add_hostcert(const char *file, const int line,
213: ServerOptions *options, const char *path)
214: {
215: char *apath = derelativise_path(path);
216:
217: array_append(file, line, "HostCertificate",
218: &options->host_cert_files, &options->num_host_cert_files, apath);
219: free(apath);
220: }
221:
1.34 markus 222: void
1.25 markus 223: fill_default_server_options(ServerOptions *options)
1.1 deraadt 224: {
1.314 djm 225: u_int i;
1.257 djm 226:
1.54 markus 227: if (options->num_host_key_files == 0) {
1.293 naddy 228: /* fill default hostkeys */
1.314 djm 229: servconf_add_hostkey("[default]", 0, options,
230: _PATH_HOST_RSA_KEY_FILE);
231: servconf_add_hostkey("[default]", 0, options,
232: _PATH_HOST_DSA_KEY_FILE);
233: servconf_add_hostkey("[default]", 0, options,
234: _PATH_HOST_ECDSA_KEY_FILE);
235: servconf_add_hostkey("[default]", 0, options,
236: _PATH_HOST_ED25519_KEY_FILE);
1.54 markus 237: }
1.203 djm 238: /* No certificates by default */
1.29 markus 239: if (options->num_ports == 0)
240: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
1.266 dtucker 241: if (options->address_family == -1)
242: options->address_family = AF_UNSPEC;
1.29 markus 243: if (options->listen_addrs == NULL)
1.315 djm 244: add_listen_addr(options, NULL, NULL, 0);
1.36 markus 245: if (options->pid_file == NULL)
1.257 djm 246: options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
1.25 markus 247: if (options->login_grace_time == -1)
1.115 stevesk 248: options->login_grace_time = 120;
1.67 markus 249: if (options->permit_root_login == PERMIT_NOT_SET)
1.279 chris 250: options->permit_root_login = PERMIT_NO_PASSWD;
1.25 markus 251: if (options->ignore_rhosts == -1)
1.30 markus 252: options->ignore_rhosts = 1;
1.25 markus 253: if (options->ignore_user_known_hosts == -1)
254: options->ignore_user_known_hosts = 0;
255: if (options->print_motd == -1)
256: options->print_motd = 1;
1.72 stevesk 257: if (options->print_lastlog == -1)
258: options->print_lastlog = 1;
1.25 markus 259: if (options->x11_forwarding == -1)
1.30 markus 260: options->x11_forwarding = 0;
1.25 markus 261: if (options->x11_display_offset == -1)
1.30 markus 262: options->x11_display_offset = 10;
1.99 stevesk 263: if (options->x11_use_localhost == -1)
264: options->x11_use_localhost = 1;
1.42 markus 265: if (options->xauth_location == NULL)
1.257 djm 266: options->xauth_location = xstrdup(_PATH_XAUTH);
1.244 djm 267: if (options->permit_tty == -1)
268: options->permit_tty = 1;
1.250 djm 269: if (options->permit_user_rc == -1)
270: options->permit_user_rc = 1;
1.25 markus 271: if (options->strict_modes == -1)
272: options->strict_modes = 1;
1.129 markus 273: if (options->tcp_keep_alive == -1)
274: options->tcp_keep_alive = 1;
1.101 markus 275: if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
1.25 markus 276: options->log_facility = SYSLOG_FACILITY_AUTH;
1.101 markus 277: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.58 markus 278: options->log_level = SYSLOG_LEVEL_INFO;
1.75 markus 279: if (options->hostbased_authentication == -1)
280: options->hostbased_authentication = 0;
281: if (options->hostbased_uses_name_from_packet_only == -1)
282: options->hostbased_uses_name_from_packet_only = 0;
1.54 markus 283: if (options->pubkey_authentication == -1)
284: options->pubkey_authentication = 1;
1.25 markus 285: if (options->kerberos_authentication == -1)
1.107 markus 286: options->kerberos_authentication = 0;
1.25 markus 287: if (options->kerberos_or_local_passwd == -1)
288: options->kerberos_or_local_passwd = 1;
289: if (options->kerberos_ticket_cleanup == -1)
290: options->kerberos_ticket_cleanup = 1;
1.130 jakob 291: if (options->kerberos_get_afs_token == -1)
292: options->kerberos_get_afs_token = 0;
1.125 markus 293: if (options->gss_authentication == -1)
294: options->gss_authentication = 0;
295: if (options->gss_cleanup_creds == -1)
296: options->gss_cleanup_creds = 1;
1.271 djm 297: if (options->gss_strict_acceptor == -1)
1.302 djm 298: options->gss_strict_acceptor = 1;
1.25 markus 299: if (options->password_authentication == -1)
300: options->password_authentication = 1;
1.52 markus 301: if (options->kbd_interactive_authentication == -1)
302: options->kbd_interactive_authentication = 0;
1.80 markus 303: if (options->challenge_response_authentication == -1)
304: options->challenge_response_authentication = 1;
1.25 markus 305: if (options->permit_empty_passwd == -1)
1.30 markus 306: options->permit_empty_passwd = 0;
1.113 markus 307: if (options->permit_user_env == -1)
308: options->permit_user_env = 0;
1.111 markus 309: if (options->compression == -1)
1.143 markus 310: options->compression = COMP_DELAYED;
1.235 dtucker 311: if (options->rekey_limit == -1)
312: options->rekey_limit = 0;
313: if (options->rekey_interval == -1)
314: options->rekey_interval = 0;
1.53 markus 315: if (options->allow_tcp_forwarding == -1)
1.233 djm 316: options->allow_tcp_forwarding = FORWARD_ALLOW;
1.251 millert 317: if (options->allow_streamlocal_forwarding == -1)
318: options->allow_streamlocal_forwarding = FORWARD_ALLOW;
1.178 pyr 319: if (options->allow_agent_forwarding == -1)
320: options->allow_agent_forwarding = 1;
1.251 millert 321: if (options->fwd_opts.gateway_ports == -1)
322: options->fwd_opts.gateway_ports = 0;
1.46 markus 323: if (options->max_startups == -1)
1.234 dtucker 324: options->max_startups = 100;
1.50 markus 325: if (options->max_startups_rate == -1)
1.234 dtucker 326: options->max_startups_rate = 30; /* 30% */
1.50 markus 327: if (options->max_startups_begin == -1)
1.234 dtucker 328: options->max_startups_begin = 10;
1.133 dtucker 329: if (options->max_authtries == -1)
330: options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
1.180 djm 331: if (options->max_sessions == -1)
332: options->max_sessions = DEFAULT_SESSIONS_MAX;
1.122 markus 333: if (options->use_dns == -1)
1.260 deraadt 334: options->use_dns = 0;
1.77 beck 335: if (options->client_alive_interval == -1)
1.95 deraadt 336: options->client_alive_interval = 0;
1.77 beck 337: if (options->client_alive_count_max == -1)
338: options->client_alive_count_max = 3;
1.219 djm 339: if (options->num_authkeys_files == 0) {
1.314 djm 340: array_append("[default]", 0, "AuthorizedKeysFiles",
341: &options->authorized_keys_files,
342: &options->num_authkeys_files,
343: _PATH_SSH_USER_PERMITTED_KEYS);
344: array_append("[default]", 0, "AuthorizedKeysFiles",
345: &options->authorized_keys_files,
346: &options->num_authkeys_files,
347: _PATH_SSH_USER_PERMITTED_KEYS2);
1.219 djm 348: }
1.145 reyk 349: if (options->permit_tun == -1)
1.146 reyk 350: options->permit_tun = SSH_TUNMODE_NO;
1.213 djm 351: if (options->ip_qos_interactive == -1)
352: options->ip_qos_interactive = IPTOS_LOWDELAY;
353: if (options->ip_qos_bulk == -1)
354: options->ip_qos_bulk = IPTOS_THROUGHPUT;
1.225 djm 355: if (options->version_addendum == NULL)
356: options->version_addendum = xstrdup("");
1.251 millert 357: if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
358: options->fwd_opts.streamlocal_bind_mask = 0177;
359: if (options->fwd_opts.streamlocal_bind_unlink == -1)
360: options->fwd_opts.streamlocal_bind_unlink = 0;
1.256 djm 361: if (options->fingerprint_hash == -1)
362: options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
1.301 djm 363: if (options->disable_forwarding == -1)
364: options->disable_forwarding = 0;
1.309 djm 365: if (options->expose_userauth_info == -1)
366: options->expose_userauth_info = 0;
1.277 djm 367:
1.282 djm 368: assemble_algorithms(options);
1.277 djm 369:
1.285 djm 370: /* Turn privilege separation and sandboxing on by default */
1.102 provos 371: if (use_privsep == -1)
1.285 djm 372: use_privsep = PRIVSEP_ON;
1.257 djm 373:
374: #define CLEAR_ON_NONE(v) \
375: do { \
376: if (option_clear_or_none(v)) { \
377: free(v); \
378: v = NULL; \
379: } \
380: } while(0)
381: CLEAR_ON_NONE(options->pid_file);
382: CLEAR_ON_NONE(options->xauth_location);
383: CLEAR_ON_NONE(options->banner);
384: CLEAR_ON_NONE(options->trusted_user_ca_keys);
385: CLEAR_ON_NONE(options->revoked_keys_file);
1.267 djm 386: CLEAR_ON_NONE(options->authorized_principals_file);
1.283 djm 387: CLEAR_ON_NONE(options->adm_forced_command);
388: CLEAR_ON_NONE(options->chroot_directory);
1.316 ! djm 389: CLEAR_ON_NONE(options->routing_domain);
1.257 djm 390: for (i = 0; i < options->num_host_key_files; i++)
391: CLEAR_ON_NONE(options->host_key_files[i]);
392: for (i = 0; i < options->num_host_cert_files; i++)
393: CLEAR_ON_NONE(options->host_cert_files[i]);
394: #undef CLEAR_ON_NONE
1.291 djm 395:
396: /* Similar handling for AuthenticationMethods=any */
397: if (options->num_auth_methods == 1 &&
398: strcmp(options->auth_methods[0], "any") == 0) {
399: free(options->auth_methods[0]);
400: options->auth_methods[0] = NULL;
401: options->num_auth_methods = 0;
402: }
403:
1.1 deraadt 404: }
405:
406: /* Keyword tokens. */
1.25 markus 407: typedef enum {
408: sBadOption, /* == unknown option */
1.293 naddy 409: sPort, sHostKeyFile, sLoginGraceTime,
410: sPermitRootLogin, sLogFacility, sLogLevel,
1.25 markus 411: sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.130 jakob 412: sKerberosGetAFSToken,
1.123 markus 413: sKerberosTgtPassing, sChallengeResponseAuthentication,
1.138 djm 414: sPasswordAuthentication, sKbdInteractiveAuthentication,
415: sListenAddress, sAddressFamily,
1.72 stevesk 416: sPrintMotd, sPrintLastLog, sIgnoreRhosts,
1.99 stevesk 417: sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
1.244 djm 418: sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
1.294 djm 419: sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
1.235 dtucker 420: sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.293 naddy 421: sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
1.258 djm 422: sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
423: sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
1.122 markus 424: sBanner, sUseDNS, sHostbasedAuthentication,
1.258 djm 425: sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
1.276 markus 426: sHostKeyAlgorithms,
1.258 djm 427: sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
1.271 djm 428: sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
429: sAcceptEnv, sPermitTunnel,
1.176 djm 430: sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
1.200 dtucker 431: sUsePrivilegeSeparation, sAllowAgentForwarding,
1.249 djm 432: sHostCertificate,
1.208 djm 433: sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
1.270 djm 434: sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
1.225 djm 435: sKexAlgorithms, sIPQoS, sVersionAddendum,
1.231 djm 436: sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
1.250 djm 437: sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
1.251 millert 438: sStreamLocalBindMask, sStreamLocalBindUnlink,
1.301 djm 439: sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
1.316 ! djm 440: sExposeAuthInfo, sRDomain,
1.295 djm 441: sDeprecated, sIgnore, sUnsupported
1.1 deraadt 442: } ServerOpCodes;
443:
1.153 dtucker 444: #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
445: #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
446: #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
447:
1.1 deraadt 448: /* Textual representation of the tokens. */
1.25 markus 449: static struct {
450: const char *name;
451: ServerOpCodes opcode;
1.153 dtucker 452: u_int flags;
1.25 markus 453: } keywords[] = {
1.153 dtucker 454: { "port", sPort, SSHCFG_GLOBAL },
455: { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
456: { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
1.240 markus 457: { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
1.153 dtucker 458: { "pidfile", sPidFile, SSHCFG_GLOBAL },
1.293 naddy 459: { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
1.153 dtucker 460: { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
1.293 naddy 461: { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
1.175 dtucker 462: { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
1.153 dtucker 463: { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
1.308 djm 464: { "loglevel", sLogLevel, SSHCFG_ALL },
1.153 dtucker 465: { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
1.293 naddy 466: { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
1.168 dtucker 467: { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
1.209 djm 468: { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
1.258 djm 469: { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
1.276 markus 470: { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
1.293 naddy 471: { "rsaauthentication", sDeprecated, SSHCFG_ALL },
1.168 dtucker 472: { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
1.258 djm 473: { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
1.153 dtucker 474: { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
1.123 markus 475: #ifdef KRB5
1.168 dtucker 476: { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
1.153 dtucker 477: { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
478: { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
479: { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
1.121 jakob 480: #else
1.168 dtucker 481: { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
1.153 dtucker 482: { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
483: { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
484: { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
1.126 markus 485: #endif
1.153 dtucker 486: { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
487: { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
1.125 markus 488: #ifdef GSSAPI
1.168 dtucker 489: { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
1.153 dtucker 490: { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
1.271 djm 491: { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
1.125 markus 492: #else
1.168 dtucker 493: { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
1.153 dtucker 494: { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
1.271 djm 495: { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
1.125 markus 496: #endif
1.168 dtucker 497: { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
498: { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
1.170 dtucker 499: { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
1.153 dtucker 500: { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
501: { "checkmail", sDeprecated, SSHCFG_GLOBAL },
502: { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
503: { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
504: { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
505: { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
506: { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
507: { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
1.157 dtucker 508: { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
509: { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
510: { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
1.153 dtucker 511: { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
512: { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
1.188 djm 513: { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
1.153 dtucker 514: { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
1.294 djm 515: { "uselogin", sDeprecated, SSHCFG_GLOBAL },
1.153 dtucker 516: { "compression", sCompression, SSHCFG_GLOBAL },
1.235 dtucker 517: { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
1.153 dtucker 518: { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
519: { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
520: { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
1.178 pyr 521: { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
1.227 markus 522: { "allowusers", sAllowUsers, SSHCFG_ALL },
523: { "denyusers", sDenyUsers, SSHCFG_ALL },
524: { "allowgroups", sAllowGroups, SSHCFG_ALL },
525: { "denygroups", sDenyGroups, SSHCFG_ALL },
1.153 dtucker 526: { "ciphers", sCiphers, SSHCFG_GLOBAL },
527: { "macs", sMacs, SSHCFG_GLOBAL },
1.295 djm 528: { "protocol", sIgnore, SSHCFG_GLOBAL },
1.153 dtucker 529: { "gatewayports", sGatewayPorts, SSHCFG_ALL },
530: { "subsystem", sSubsystem, SSHCFG_GLOBAL },
531: { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
1.184 dtucker 532: { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
1.180 djm 533: { "maxsessions", sMaxSessions, SSHCFG_ALL },
1.168 dtucker 534: { "banner", sBanner, SSHCFG_ALL },
1.153 dtucker 535: { "usedns", sUseDNS, SSHCFG_GLOBAL },
536: { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
537: { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
1.300 markus 538: { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
539: { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
1.209 djm 540: { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
1.219 djm 541: { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
1.306 djm 542: { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
1.227 markus 543: { "acceptenv", sAcceptEnv, SSHCFG_ALL },
1.209 djm 544: { "permittunnel", sPermitTunnel, SSHCFG_ALL },
1.244 djm 545: { "permittty", sPermitTTY, SSHCFG_ALL },
1.250 djm 546: { "permituserrc", sPermitUserRC, SSHCFG_ALL },
1.153 dtucker 547: { "match", sMatch, SSHCFG_ALL },
1.156 dtucker 548: { "permitopen", sPermitOpen, SSHCFG_ALL },
1.158 dtucker 549: { "forcecommand", sForceCommand, SSHCFG_ALL },
1.176 djm 550: { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
1.203 djm 551: { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
1.204 djm 552: { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
553: { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
1.209 djm 554: { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
1.211 djm 555: { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
1.213 djm 556: { "ipqos", sIPQoS, SSHCFG_ALL },
1.231 djm 557: { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
558: { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
1.270 djm 559: { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
560: { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
1.225 djm 561: { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
1.232 djm 562: { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
1.251 millert 563: { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
564: { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
565: { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
1.256 djm 566: { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
1.301 djm 567: { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
1.309 djm 568: { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
1.316 ! djm 569: { "rdomain", sRDomain, SSHCFG_ALL },
1.153 dtucker 570: { NULL, sBadOption, 0 }
1.1 deraadt 571: };
572:
1.182 dtucker 573: static struct {
574: int val;
575: char *text;
576: } tunmode_desc[] = {
577: { SSH_TUNMODE_NO, "no" },
578: { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
579: { SSH_TUNMODE_ETHERNET, "ethernet" },
580: { SSH_TUNMODE_YES, "yes" },
581: { -1, NULL }
582: };
583:
1.27 markus 584: /*
1.73 stevesk 585: * Returns the number of the token pointed to by cp or sBadOption.
1.27 markus 586: */
1.1 deraadt 587:
1.34 markus 588: static ServerOpCodes
1.25 markus 589: parse_token(const char *cp, const char *filename,
1.153 dtucker 590: int linenum, u_int *flags)
1.1 deraadt 591: {
1.55 markus 592: u_int i;
1.1 deraadt 593:
1.25 markus 594: for (i = 0; keywords[i].name; i++)
1.153 dtucker 595: if (strcasecmp(cp, keywords[i].name) == 0) {
596: *flags = keywords[i].flags;
1.25 markus 597: return keywords[i].opcode;
1.153 dtucker 598: }
1.25 markus 599:
1.78 stevesk 600: error("%s: line %d: Bad configuration option: %s",
601: filename, linenum, cp);
1.25 markus 602: return sBadOption;
1.1 deraadt 603: }
604:
1.202 djm 605: char *
606: derelativise_path(const char *path)
607: {
1.259 deraadt 608: char *expanded, *ret, cwd[PATH_MAX];
1.202 djm 609:
1.257 djm 610: if (strcasecmp(path, "none") == 0)
611: return xstrdup("none");
1.202 djm 612: expanded = tilde_expand_filename(path, getuid());
613: if (*expanded == '/')
614: return expanded;
1.207 djm 615: if (getcwd(cwd, sizeof(cwd)) == NULL)
1.202 djm 616: fatal("%s: getcwd: %s", __func__, strerror(errno));
617: xasprintf(&ret, "%s/%s", cwd, expanded);
1.239 djm 618: free(expanded);
1.202 djm 619: return ret;
620: }
621:
1.84 itojun 622: static void
1.315 djm 623: add_listen_addr(ServerOptions *options, const char *addr,
624: const char *rdomain, int port)
1.74 stevesk 625: {
1.142 djm 626: u_int i;
1.74 stevesk 627:
1.315 djm 628: if (port > 0)
629: add_one_listen_addr(options, addr, rdomain, port);
630: else {
631: for (i = 0; i < options->num_ports; i++) {
632: add_one_listen_addr(options, addr, rdomain,
633: options->ports[i]);
634: }
635: }
1.74 stevesk 636: }
637:
1.84 itojun 638: static void
1.315 djm 639: add_one_listen_addr(ServerOptions *options, const char *addr,
640: const char *rdomain, int port)
1.29 markus 641: {
642: struct addrinfo hints, *ai, *aitop;
643: char strport[NI_MAXSERV];
644: int gaierr;
1.315 djm 645: u_int i;
646:
647: /* Find listen_addrs entry for this rdomain */
648: for (i = 0; i < options->num_listen_addrs; i++) {
649: if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
650: break;
651: if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
652: continue;
653: if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
654: break;
655: }
656: if (i >= options->num_listen_addrs) {
657: /* No entry for this rdomain; allocate one */
658: if (i >= INT_MAX)
659: fatal("%s: too many listen addresses", __func__);
660: options->listen_addrs = xrecallocarray(options->listen_addrs,
661: options->num_listen_addrs, options->num_listen_addrs + 1,
662: sizeof(*options->listen_addrs));
663: i = options->num_listen_addrs++;
664: if (rdomain != NULL)
665: options->listen_addrs[i].rdomain = xstrdup(rdomain);
666: }
667: /* options->listen_addrs[i] points to the addresses for this rdomain */
1.29 markus 668:
1.74 stevesk 669: memset(&hints, 0, sizeof(hints));
1.138 djm 670: hints.ai_family = options->address_family;
1.74 stevesk 671: hints.ai_socktype = SOCK_STREAM;
672: hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
1.194 djm 673: snprintf(strport, sizeof strport, "%d", port);
1.74 stevesk 674: if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
675: fatal("bad addr or host: %s (%s)",
676: addr ? addr : "<NULL>",
1.173 dtucker 677: ssh_gai_strerror(gaierr));
1.74 stevesk 678: for (ai = aitop; ai->ai_next; ai = ai->ai_next)
679: ;
1.315 djm 680: ai->ai_next = options->listen_addrs[i].addrs;
681: options->listen_addrs[i].addrs = aitop;
682: }
683:
684: /* Returns nonzero if the routing domain name is valid */
685: static int
686: valid_rdomain(const char *name)
687: {
688: const char *errstr;
689: long long num;
690: struct rt_tableinfo info;
691: int mib[6];
692: size_t miblen = sizeof(mib);
693:
694: if (name == NULL)
695: return 1;
696:
697: num = strtonum(name, 0, 255, &errstr);
698: if (errstr != NULL)
699: return 0;
700:
701: /* Check whether the table actually exists */
702: memset(mib, 0, sizeof(mib));
703: mib[0] = CTL_NET;
704: mib[1] = PF_ROUTE;
705: mib[4] = NET_RT_TABLE;
706: mib[5] = (int)num;
707: if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
708: return 0;
709:
710: return 1;
1.29 markus 711: }
712:
1.266 dtucker 713: /*
714: * Queue a ListenAddress to be processed once we have all of the Ports
715: * and AddressFamily options.
716: */
717: static void
1.315 djm 718: queue_listen_addr(ServerOptions *options, const char *addr,
719: const char *rdomain, int port)
1.266 dtucker 720: {
1.315 djm 721: struct queued_listenaddr *qla;
722:
723: options->queued_listen_addrs = xrecallocarray(
724: options->queued_listen_addrs,
725: options->num_queued_listens, options->num_queued_listens + 1,
726: sizeof(*options->queued_listen_addrs));
727: qla = &options->queued_listen_addrs[options->num_queued_listens++];
728: qla->addr = xstrdup(addr);
729: qla->port = port;
730: qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
1.266 dtucker 731: }
732:
733: /*
734: * Process queued (text) ListenAddress entries.
735: */
736: static void
737: process_queued_listen_addrs(ServerOptions *options)
738: {
739: u_int i;
1.315 djm 740: struct queued_listenaddr *qla;
1.266 dtucker 741:
742: if (options->num_ports == 0)
743: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
744: if (options->address_family == -1)
745: options->address_family = AF_UNSPEC;
746:
747: for (i = 0; i < options->num_queued_listens; i++) {
1.315 djm 748: qla = &options->queued_listen_addrs[i];
749: add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
750: free(qla->addr);
751: free(qla->rdomain);
1.266 dtucker 752: }
753: free(options->queued_listen_addrs);
754: options->queued_listen_addrs = NULL;
755: options->num_queued_listens = 0;
756: }
757:
1.310 djm 758: /*
759: * Inform channels layer of permitopen options from configuration.
760: */
761: void
762: process_permitopen(struct ssh *ssh, ServerOptions *options)
763: {
764: u_int i;
765: int port;
766: char *host, *arg, *oarg;
767:
768: channel_clear_adm_permitted_opens(ssh);
769: if (options->num_permitted_opens == 0)
770: return; /* permit any */
771:
772: /* handle keywords: "any" / "none" */
773: if (options->num_permitted_opens == 1 &&
774: strcmp(options->permitted_opens[0], "any") == 0)
775: return;
776: if (options->num_permitted_opens == 1 &&
777: strcmp(options->permitted_opens[0], "none") == 0) {
778: channel_disable_adm_local_opens(ssh);
779: return;
780: }
781: /* Otherwise treat it as a list of permitted host:port */
782: for (i = 0; i < options->num_permitted_opens; i++) {
783: oarg = arg = xstrdup(options->permitted_opens[i]);
784: host = hpdelim(&arg);
785: if (host == NULL)
786: fatal("%s: missing host in PermitOpen", __func__);
787: host = cleanhostname(host);
788: if (arg == NULL || ((port = permitopen_port(arg)) < 0))
789: fatal("%s: bad port number in PermitOpen", __func__);
790: /* Send it to channels layer */
791: channel_add_adm_permitted_opens(ssh, host, port);
792: free(oarg);
793: }
794: }
795:
1.226 dtucker 796: struct connection_info *
797: get_connection_info(int populate, int use_dns)
798: {
1.286 djm 799: struct ssh *ssh = active_state; /* XXX */
1.226 dtucker 800: static struct connection_info ci;
801:
802: if (!populate)
803: return &ci;
1.286 djm 804: ci.host = auth_get_canonical_hostname(ssh, use_dns);
805: ci.address = ssh_remote_ipaddr(ssh);
806: ci.laddress = ssh_local_ipaddr(ssh);
807: ci.lport = ssh_local_port(ssh);
1.226 dtucker 808: return &ci;
809: }
810:
1.153 dtucker 811: /*
812: * The strategy for the Match blocks is that the config file is parsed twice.
813: *
814: * The first time is at startup. activep is initialized to 1 and the
815: * directives in the global context are processed and acted on. Hitting a
816: * Match directive unsets activep and the directives inside the block are
817: * checked for syntax only.
818: *
819: * The second time is after a connection has been established but before
820: * authentication. activep is initialized to 2 and global config directives
821: * are ignored since they have already been processed. If the criteria in a
822: * Match block is met, activep is set and the subsequent directives
823: * processed and actioned until EOF or another Match block unsets it. Any
824: * options set are copied into the main server config.
825: *
826: * Potential additions/improvements:
1.295 djm 827: * - Add Match support for pre-kex directives, eg. Ciphers.
1.153 dtucker 828: *
829: * - Add a Tag directive (idea from David Leonard) ala pf, eg:
830: * Match Address 192.168.0.*
831: * Tag trusted
832: * Match Group wheel
833: * Tag trusted
834: * Match Tag trusted
835: * AllowTcpForwarding yes
836: * GatewayPorts clientspecified
837: * [...]
838: *
839: * - Add a PermittedChannelRequests directive
840: * Match Group shell
841: * PermittedChannelRequests session,forwarded-tcpip
842: */
843:
844: static int
1.165 dtucker 845: match_cfg_line_group(const char *grps, int line, const char *user)
846: {
847: int result = 0;
848: struct passwd *pw;
849:
850: if (user == NULL)
851: goto out;
852:
853: if ((pw = getpwnam(user)) == NULL) {
854: debug("Can't match group at line %d because user %.100s does "
855: "not exist", line, user);
856: } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
857: debug("Can't Match group because user %.100s not in any group "
858: "at line %d", user, line);
1.186 djm 859: } else if (ga_match_pattern_list(grps) != 1) {
860: debug("user %.100s does not match group list %.100s at line %d",
861: user, grps, line);
1.165 dtucker 862: } else {
1.186 djm 863: debug("user %.100s matched group list %.100s at line %d", user,
864: grps, line);
1.165 dtucker 865: result = 1;
866: }
867: out:
868: ga_free();
869: return result;
870: }
871:
1.226 dtucker 872: /*
1.230 dtucker 873: * All of the attributes on a single Match line are ANDed together, so we need
1.242 dtucker 874: * to check every attribute and set the result to zero if any attribute does
1.230 dtucker 875: * not match.
1.226 dtucker 876: */
1.165 dtucker 877: static int
1.226 dtucker 878: match_cfg_line(char **condition, int line, struct connection_info *ci)
1.153 dtucker 879: {
1.243 dtucker 880: int result = 1, attributes = 0, port;
1.153 dtucker 881: char *arg, *attrib, *cp = *condition;
882:
1.226 dtucker 883: if (ci == NULL)
1.153 dtucker 884: debug3("checking syntax for 'Match %s'", cp);
885: else
1.226 dtucker 886: debug3("checking match for '%s' user %s host %s addr %s "
887: "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
888: ci->host ? ci->host : "(null)",
889: ci->address ? ci->address : "(null)",
890: ci->laddress ? ci->laddress : "(null)", ci->lport);
1.153 dtucker 891:
892: while ((attrib = strdelim(&cp)) && *attrib != '\0') {
1.243 dtucker 893: attributes++;
894: if (strcasecmp(attrib, "all") == 0) {
895: if (attributes != 1 ||
896: ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
897: error("'all' cannot be combined with other "
898: "Match attributes");
899: return -1;
900: }
901: *condition = cp;
902: return 1;
903: }
1.153 dtucker 904: if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
905: error("Missing Match criteria for %s", attrib);
906: return -1;
907: }
908: if (strcasecmp(attrib, "user") == 0) {
1.226 dtucker 909: if (ci == NULL || ci->user == NULL) {
1.153 dtucker 910: result = 0;
911: continue;
912: }
1.269 djm 913: if (match_pattern_list(ci->user, arg, 0) != 1)
1.153 dtucker 914: result = 0;
915: else
916: debug("user %.100s matched 'User %.100s' at "
1.226 dtucker 917: "line %d", ci->user, arg, line);
1.165 dtucker 918: } else if (strcasecmp(attrib, "group") == 0) {
1.226 dtucker 919: if (ci == NULL || ci->user == NULL) {
920: result = 0;
921: continue;
922: }
923: switch (match_cfg_line_group(arg, line, ci->user)) {
1.165 dtucker 924: case -1:
925: return -1;
926: case 0:
927: result = 0;
928: }
1.153 dtucker 929: } else if (strcasecmp(attrib, "host") == 0) {
1.226 dtucker 930: if (ci == NULL || ci->host == NULL) {
1.153 dtucker 931: result = 0;
932: continue;
933: }
1.269 djm 934: if (match_hostname(ci->host, arg) != 1)
1.153 dtucker 935: result = 0;
936: else
937: debug("connection from %.100s matched 'Host "
1.226 dtucker 938: "%.100s' at line %d", ci->host, arg, line);
1.153 dtucker 939: } else if (strcasecmp(attrib, "address") == 0) {
1.226 dtucker 940: if (ci == NULL || ci->address == NULL) {
941: result = 0;
942: continue;
943: }
944: switch (addr_match_list(ci->address, arg)) {
1.181 djm 945: case 1:
946: debug("connection from %.100s matched 'Address "
1.226 dtucker 947: "%.100s' at line %d", ci->address, arg, line);
1.181 djm 948: break;
949: case 0:
1.183 djm 950: case -1:
1.153 dtucker 951: result = 0;
1.181 djm 952: break;
1.183 djm 953: case -2:
1.181 djm 954: return -1;
1.153 dtucker 955: }
1.226 dtucker 956: } else if (strcasecmp(attrib, "localaddress") == 0){
957: if (ci == NULL || ci->laddress == NULL) {
958: result = 0;
959: continue;
960: }
961: switch (addr_match_list(ci->laddress, arg)) {
962: case 1:
963: debug("connection from %.100s matched "
964: "'LocalAddress %.100s' at line %d",
965: ci->laddress, arg, line);
966: break;
967: case 0:
968: case -1:
969: result = 0;
970: break;
971: case -2:
972: return -1;
973: }
974: } else if (strcasecmp(attrib, "localport") == 0) {
975: if ((port = a2port(arg)) == -1) {
976: error("Invalid LocalPort '%s' on Match line",
977: arg);
978: return -1;
979: }
980: if (ci == NULL || ci->lport == 0) {
981: result = 0;
982: continue;
983: }
984: /* TODO support port lists */
985: if (port == ci->lport)
986: debug("connection from %.100s matched "
987: "'LocalPort %d' at line %d",
988: ci->laddress, port, line);
989: else
990: result = 0;
1.153 dtucker 991: } else {
992: error("Unsupported Match attribute %s", attrib);
993: return -1;
994: }
1.243 dtucker 995: }
996: if (attributes == 0) {
997: error("One or more attributes required for Match");
998: return -1;
1.153 dtucker 999: }
1.226 dtucker 1000: if (ci != NULL)
1.153 dtucker 1001: debug3("match %sfound", result ? "" : "not ");
1002: *condition = cp;
1003: return result;
1004: }
1005:
1.158 dtucker 1006: #define WHITESPACE " \t\r\n"
1007:
1.220 djm 1008: /* Multistate option parsing */
1009: struct multistate {
1010: char *key;
1011: int value;
1012: };
1013: static const struct multistate multistate_addressfamily[] = {
1014: { "inet", AF_INET },
1015: { "inet6", AF_INET6 },
1016: { "any", AF_UNSPEC },
1017: { NULL, -1 }
1018: };
1019: static const struct multistate multistate_permitrootlogin[] = {
1020: { "without-password", PERMIT_NO_PASSWD },
1.280 deraadt 1021: { "prohibit-password", PERMIT_NO_PASSWD },
1.220 djm 1022: { "forced-commands-only", PERMIT_FORCED_ONLY },
1023: { "yes", PERMIT_YES },
1024: { "no", PERMIT_NO },
1025: { NULL, -1 }
1026: };
1027: static const struct multistate multistate_compression[] = {
1.297 djm 1028: { "yes", COMP_DELAYED },
1.220 djm 1029: { "delayed", COMP_DELAYED },
1030: { "no", COMP_NONE },
1031: { NULL, -1 }
1032: };
1033: static const struct multistate multistate_gatewayports[] = {
1034: { "clientspecified", 2 },
1035: { "yes", 1 },
1036: { "no", 0 },
1.222 djm 1037: { NULL, -1 }
1038: };
1.233 djm 1039: static const struct multistate multistate_tcpfwd[] = {
1040: { "yes", FORWARD_ALLOW },
1041: { "all", FORWARD_ALLOW },
1042: { "no", FORWARD_DENY },
1043: { "remote", FORWARD_REMOTE },
1044: { "local", FORWARD_LOCAL },
1045: { NULL, -1 }
1046: };
1.220 djm 1047:
1.94 markus 1048: int
1049: process_server_config_line(ServerOptions *options, char *line,
1.226 dtucker 1050: const char *filename, int linenum, int *activep,
1051: struct connection_info *connectinfo)
1.1 deraadt 1052: {
1.310 djm 1053: char *cp, **charptr, *arg, *arg2, *p;
1.237 dtucker 1054: int cmdline = 0, *intptr, value, value2, n, port;
1.174 dtucker 1055: SyslogFacility *log_facility_ptr;
1056: LogLevel *log_level_ptr;
1.25 markus 1057: ServerOpCodes opcode;
1.153 dtucker 1058: u_int i, flags = 0;
1.151 djm 1059: size_t len;
1.237 dtucker 1060: long long val64;
1.220 djm 1061: const struct multistate *multistate_ptr;
1.303 djm 1062:
1063: /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1064: if ((len = strlen(line)) == 0)
1065: return 0;
1066: for (len--; len > 0; len--) {
1067: if (strchr(WHITESPACE "\f", line[len]) == NULL)
1068: break;
1069: line[len] = '\0';
1070: }
1.25 markus 1071:
1.94 markus 1072: cp = line;
1.148 dtucker 1073: if ((arg = strdelim(&cp)) == NULL)
1.147 djm 1074: return 0;
1.94 markus 1075: /* Ignore leading whitespace */
1076: if (*arg == '\0')
1077: arg = strdelim(&cp);
1078: if (!arg || !*arg || *arg == '#')
1079: return 0;
1080: intptr = NULL;
1081: charptr = NULL;
1.153 dtucker 1082: opcode = parse_token(arg, filename, linenum, &flags);
1083:
1084: if (activep == NULL) { /* We are processing a command line directive */
1085: cmdline = 1;
1086: activep = &cmdline;
1087: }
1088: if (*activep && opcode != sMatch)
1089: debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1090: if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
1.226 dtucker 1091: if (connectinfo == NULL) {
1.153 dtucker 1092: fatal("%s line %d: Directive '%s' is not allowed "
1093: "within a Match block", filename, linenum, arg);
1094: } else { /* this is a directive we have already processed */
1095: while (arg)
1096: arg = strdelim(&cp);
1097: return 0;
1098: }
1099: }
1100:
1.94 markus 1101: switch (opcode) {
1102: case sBadOption:
1103: return -1;
1104: case sPort:
1105: /* ignore ports from configfile if cmdline specifies ports */
1106: if (options->ports_from_cmdline)
1107: return 0;
1108: if (options->num_ports >= MAX_PORTS)
1109: fatal("%s line %d: too many ports.",
1110: filename, linenum);
1.48 provos 1111: arg = strdelim(&cp);
1.94 markus 1112: if (!arg || *arg == '\0')
1113: fatal("%s line %d: missing port number.",
1114: filename, linenum);
1115: options->ports[options->num_ports++] = a2port(arg);
1.194 djm 1116: if (options->ports[options->num_ports-1] <= 0)
1.94 markus 1117: fatal("%s line %d: Badly formatted port number.",
1118: filename, linenum);
1119: break;
1.29 markus 1120:
1.94 markus 1121: case sLoginGraceTime:
1122: intptr = &options->login_grace_time;
1.180 djm 1123: parse_time:
1.94 markus 1124: arg = strdelim(&cp);
1125: if (!arg || *arg == '\0')
1126: fatal("%s line %d: missing time value.",
1127: filename, linenum);
1128: if ((value = convtime(arg)) == -1)
1129: fatal("%s line %d: invalid time value.",
1130: filename, linenum);
1.268 djm 1131: if (*activep && *intptr == -1)
1.94 markus 1132: *intptr = value;
1133: break;
1134:
1135: case sListenAddress:
1136: arg = strdelim(&cp);
1.139 djm 1137: if (arg == NULL || *arg == '\0')
1138: fatal("%s line %d: missing address",
1.94 markus 1139: filename, linenum);
1.144 dtucker 1140: /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1141: if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1142: && strchr(p+1, ':') != NULL) {
1.315 djm 1143: port = 0;
1144: p = arg;
1145: } else {
1146: p = hpdelim(&arg);
1147: if (p == NULL)
1148: fatal("%s line %d: bad address:port usage",
1149: filename, linenum);
1150: p = cleanhostname(p);
1151: if (arg == NULL)
1152: port = 0;
1153: else if ((port = a2port(arg)) <= 0)
1154: fatal("%s line %d: bad port number",
1155: filename, linenum);
1156: }
1157: /* Optional routing table */
1158: arg2 = NULL;
1159: if ((arg = strdelim(&cp)) != NULL) {
1160: if (strcmp(arg, "rdomain") != 0 ||
1161: (arg2 = strdelim(&cp)) == NULL)
1162: fatal("%s line %d: bad ListenAddress syntax",
1163: filename, linenum);
1164: if (!valid_rdomain(arg2))
1165: fatal("%s line %d: bad routing domain",
1166: filename, linenum);
1.144 dtucker 1167: }
1.139 djm 1168:
1.315 djm 1169: queue_listen_addr(options, p, arg2, port);
1.25 markus 1170:
1.138 djm 1171: break;
1172:
1173: case sAddressFamily:
1.220 djm 1174: intptr = &options->address_family;
1175: multistate_ptr = multistate_addressfamily;
1176: parse_multistate:
1.138 djm 1177: arg = strdelim(&cp);
1.141 markus 1178: if (!arg || *arg == '\0')
1.220 djm 1179: fatal("%s line %d: missing argument.",
1.141 markus 1180: filename, linenum);
1.220 djm 1181: value = -1;
1182: for (i = 0; multistate_ptr[i].key != NULL; i++) {
1183: if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1184: value = multistate_ptr[i].value;
1185: break;
1186: }
1187: }
1188: if (value == -1)
1189: fatal("%s line %d: unsupported option \"%s\".",
1.138 djm 1190: filename, linenum, arg);
1.220 djm 1191: if (*activep && *intptr == -1)
1.138 djm 1192: *intptr = value;
1.94 markus 1193: break;
1194:
1195: case sHostKeyFile:
1196: arg = strdelim(&cp);
1197: if (!arg || *arg == '\0')
1198: fatal("%s line %d: missing file name.",
1199: filename, linenum);
1.314 djm 1200: if (*activep)
1201: servconf_add_hostkey(filename, linenum, options, arg);
1.94 markus 1202: break;
1.76 stevesk 1203:
1.240 markus 1204: case sHostKeyAgent:
1205: charptr = &options->host_key_agent;
1206: arg = strdelim(&cp);
1207: if (!arg || *arg == '\0')
1208: fatal("%s line %d: missing socket name.",
1209: filename, linenum);
1210: if (*activep && *charptr == NULL)
1211: *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1212: xstrdup(arg) : derelativise_path(arg);
1213: break;
1214:
1.203 djm 1215: case sHostCertificate:
1.314 djm 1216: arg = strdelim(&cp);
1217: if (!arg || *arg == '\0')
1218: fatal("%s line %d: missing file name.",
1219: filename, linenum);
1220: if (*activep)
1221: servconf_add_hostcert(filename, linenum, options, arg);
1222: break;
1.203 djm 1223:
1.94 markus 1224: case sPidFile:
1225: charptr = &options->pid_file;
1.314 djm 1226: parse_filename:
1227: arg = strdelim(&cp);
1228: if (!arg || *arg == '\0')
1229: fatal("%s line %d: missing file name.",
1230: filename, linenum);
1231: if (*activep && *charptr == NULL) {
1232: *charptr = derelativise_path(arg);
1233: /* increase optional counter */
1234: if (intptr != NULL)
1235: *intptr = *intptr + 1;
1236: }
1237: break;
1.25 markus 1238:
1.94 markus 1239: case sPermitRootLogin:
1240: intptr = &options->permit_root_login;
1.220 djm 1241: multistate_ptr = multistate_permitrootlogin;
1242: goto parse_multistate;
1.36 markus 1243:
1.94 markus 1244: case sIgnoreRhosts:
1245: intptr = &options->ignore_rhosts;
1.180 djm 1246: parse_flag:
1.94 markus 1247: arg = strdelim(&cp);
1248: if (!arg || *arg == '\0')
1249: fatal("%s line %d: missing yes/no argument.",
1250: filename, linenum);
1251: value = 0; /* silence compiler */
1252: if (strcmp(arg, "yes") == 0)
1253: value = 1;
1254: else if (strcmp(arg, "no") == 0)
1255: value = 0;
1256: else
1257: fatal("%s line %d: Bad yes/no argument: %s",
1258: filename, linenum, arg);
1.153 dtucker 1259: if (*activep && *intptr == -1)
1.94 markus 1260: *intptr = value;
1261: break;
1262:
1263: case sIgnoreUserKnownHosts:
1264: intptr = &options->ignore_user_known_hosts;
1265: goto parse_flag;
1266:
1267: case sHostbasedAuthentication:
1268: intptr = &options->hostbased_authentication;
1269: goto parse_flag;
1270:
1271: case sHostbasedUsesNameFromPacketOnly:
1272: intptr = &options->hostbased_uses_name_from_packet_only;
1273: goto parse_flag;
1274:
1.258 djm 1275: case sHostbasedAcceptedKeyTypes:
1276: charptr = &options->hostbased_key_types;
1277: parse_keytypes:
1278: arg = strdelim(&cp);
1279: if (!arg || *arg == '\0')
1280: fatal("%s line %d: Missing argument.",
1281: filename, linenum);
1.304 djm 1282: if (*arg != '-' &&
1283: !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1.258 djm 1284: fatal("%s line %d: Bad key types '%s'.",
1285: filename, linenum, arg ? arg : "<NONE>");
1286: if (*activep && *charptr == NULL)
1287: *charptr = xstrdup(arg);
1288: break;
1289:
1.276 markus 1290: case sHostKeyAlgorithms:
1291: charptr = &options->hostkeyalgorithms;
1292: goto parse_keytypes;
1293:
1.94 markus 1294: case sPubkeyAuthentication:
1295: intptr = &options->pubkey_authentication;
1296: goto parse_flag;
1.119 jakob 1297:
1.258 djm 1298: case sPubkeyAcceptedKeyTypes:
1299: charptr = &options->pubkey_key_types;
1300: goto parse_keytypes;
1301:
1.94 markus 1302: case sKerberosAuthentication:
1303: intptr = &options->kerberos_authentication;
1304: goto parse_flag;
1305:
1306: case sKerberosOrLocalPasswd:
1307: intptr = &options->kerberos_or_local_passwd;
1308: goto parse_flag;
1309:
1310: case sKerberosTicketCleanup:
1311: intptr = &options->kerberos_ticket_cleanup;
1.130 jakob 1312: goto parse_flag;
1313:
1314: case sKerberosGetAFSToken:
1315: intptr = &options->kerberos_get_afs_token;
1.125 markus 1316: goto parse_flag;
1317:
1318: case sGssAuthentication:
1319: intptr = &options->gss_authentication;
1320: goto parse_flag;
1321:
1322: case sGssCleanupCreds:
1323: intptr = &options->gss_cleanup_creds;
1.271 djm 1324: goto parse_flag;
1325:
1326: case sGssStrictAcceptor:
1327: intptr = &options->gss_strict_acceptor;
1.94 markus 1328: goto parse_flag;
1329:
1330: case sPasswordAuthentication:
1331: intptr = &options->password_authentication;
1332: goto parse_flag;
1333:
1334: case sKbdInteractiveAuthentication:
1335: intptr = &options->kbd_interactive_authentication;
1336: goto parse_flag;
1337:
1338: case sChallengeResponseAuthentication:
1339: intptr = &options->challenge_response_authentication;
1340: goto parse_flag;
1341:
1342: case sPrintMotd:
1343: intptr = &options->print_motd;
1344: goto parse_flag;
1345:
1346: case sPrintLastLog:
1347: intptr = &options->print_lastlog;
1348: goto parse_flag;
1349:
1350: case sX11Forwarding:
1351: intptr = &options->x11_forwarding;
1352: goto parse_flag;
1353:
1354: case sX11DisplayOffset:
1355: intptr = &options->x11_display_offset;
1.293 naddy 1356: parse_int:
1357: arg = strdelim(&cp);
1358: if (!arg || *arg == '\0')
1359: fatal("%s line %d: missing integer value.",
1360: filename, linenum);
1361: value = atoi(arg);
1362: if (*activep && *intptr == -1)
1363: *intptr = value;
1364: break;
1.99 stevesk 1365:
1366: case sX11UseLocalhost:
1367: intptr = &options->x11_use_localhost;
1368: goto parse_flag;
1.94 markus 1369:
1370: case sXAuthLocation:
1371: charptr = &options->xauth_location;
1372: goto parse_filename;
1373:
1.244 djm 1374: case sPermitTTY:
1375: intptr = &options->permit_tty;
1376: goto parse_flag;
1377:
1.250 djm 1378: case sPermitUserRC:
1379: intptr = &options->permit_user_rc;
1380: goto parse_flag;
1381:
1.94 markus 1382: case sStrictModes:
1383: intptr = &options->strict_modes;
1384: goto parse_flag;
1385:
1.129 markus 1386: case sTCPKeepAlive:
1387: intptr = &options->tcp_keep_alive;
1.94 markus 1388: goto parse_flag;
1389:
1390: case sEmptyPasswd:
1391: intptr = &options->permit_empty_passwd;
1.113 markus 1392: goto parse_flag;
1393:
1394: case sPermitUserEnvironment:
1395: intptr = &options->permit_user_env;
1.94 markus 1396: goto parse_flag;
1397:
1.111 markus 1398: case sCompression:
1399: intptr = &options->compression;
1.220 djm 1400: multistate_ptr = multistate_compression;
1401: goto parse_multistate;
1.94 markus 1402:
1.235 dtucker 1403: case sRekeyLimit:
1404: arg = strdelim(&cp);
1405: if (!arg || *arg == '\0')
1406: fatal("%.200s line %d: Missing argument.", filename,
1407: linenum);
1408: if (strcmp(arg, "default") == 0) {
1409: val64 = 0;
1410: } else {
1.236 dtucker 1411: if (scan_scaled(arg, &val64) == -1)
1412: fatal("%.200s line %d: Bad number '%s': %s",
1413: filename, linenum, arg, strerror(errno));
1.235 dtucker 1414: if (val64 != 0 && val64 < 16)
1415: fatal("%.200s line %d: RekeyLimit too small",
1416: filename, linenum);
1417: }
1418: if (*activep && options->rekey_limit == -1)
1.284 dtucker 1419: options->rekey_limit = val64;
1.235 dtucker 1420: if (cp != NULL) { /* optional rekey interval present */
1421: if (strcmp(cp, "none") == 0) {
1422: (void)strdelim(&cp); /* discard */
1423: break;
1424: }
1425: intptr = &options->rekey_interval;
1426: goto parse_time;
1427: }
1428: break;
1429:
1.94 markus 1430: case sGatewayPorts:
1.251 millert 1431: intptr = &options->fwd_opts.gateway_ports;
1.220 djm 1432: multistate_ptr = multistate_gatewayports;
1433: goto parse_multistate;
1.25 markus 1434:
1.122 markus 1435: case sUseDNS:
1436: intptr = &options->use_dns;
1.94 markus 1437: goto parse_flag;
1.53 markus 1438:
1.94 markus 1439: case sLogFacility:
1.174 dtucker 1440: log_facility_ptr = &options->log_facility;
1.94 markus 1441: arg = strdelim(&cp);
1442: value = log_facility_number(arg);
1.101 markus 1443: if (value == SYSLOG_FACILITY_NOT_SET)
1.94 markus 1444: fatal("%.200s line %d: unsupported log facility '%s'",
1445: filename, linenum, arg ? arg : "<NONE>");
1.174 dtucker 1446: if (*log_facility_ptr == -1)
1447: *log_facility_ptr = (SyslogFacility) value;
1.94 markus 1448: break;
1.25 markus 1449:
1.94 markus 1450: case sLogLevel:
1.174 dtucker 1451: log_level_ptr = &options->log_level;
1.94 markus 1452: arg = strdelim(&cp);
1453: value = log_level_number(arg);
1.101 markus 1454: if (value == SYSLOG_LEVEL_NOT_SET)
1.94 markus 1455: fatal("%.200s line %d: unsupported log level '%s'",
1456: filename, linenum, arg ? arg : "<NONE>");
1.308 djm 1457: if (*activep && *log_level_ptr == -1)
1.174 dtucker 1458: *log_level_ptr = (LogLevel) value;
1.94 markus 1459: break;
1460:
1461: case sAllowTcpForwarding:
1462: intptr = &options->allow_tcp_forwarding;
1.233 djm 1463: multistate_ptr = multistate_tcpfwd;
1464: goto parse_multistate;
1.102 provos 1465:
1.251 millert 1466: case sAllowStreamLocalForwarding:
1467: intptr = &options->allow_streamlocal_forwarding;
1468: multistate_ptr = multistate_tcpfwd;
1469: goto parse_multistate;
1470:
1.178 pyr 1471: case sAllowAgentForwarding:
1472: intptr = &options->allow_agent_forwarding;
1473: goto parse_flag;
1474:
1.301 djm 1475: case sDisableForwarding:
1476: intptr = &options->disable_forwarding;
1477: goto parse_flag;
1478:
1.94 markus 1479: case sAllowUsers:
1480: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.299 djm 1481: if (match_user(NULL, NULL, NULL, arg) == -1)
1482: fatal("%s line %d: invalid AllowUsers pattern: "
1483: "\"%.100s\"", filename, linenum, arg);
1.227 markus 1484: if (!*activep)
1485: continue;
1.314 djm 1486: array_append(filename, linenum, "AllowUsers",
1487: &options->allow_users, &options->num_allow_users,
1488: arg);
1.94 markus 1489: }
1490: break;
1.25 markus 1491:
1.94 markus 1492: case sDenyUsers:
1493: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.299 djm 1494: if (match_user(NULL, NULL, NULL, arg) == -1)
1495: fatal("%s line %d: invalid DenyUsers pattern: "
1496: "\"%.100s\"", filename, linenum, arg);
1.227 markus 1497: if (!*activep)
1498: continue;
1.314 djm 1499: array_append(filename, linenum, "DenyUsers",
1500: &options->deny_users, &options->num_deny_users,
1501: arg);
1.94 markus 1502: }
1503: break;
1.25 markus 1504:
1.94 markus 1505: case sAllowGroups:
1506: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.227 markus 1507: if (!*activep)
1508: continue;
1.314 djm 1509: array_append(filename, linenum, "AllowGroups",
1510: &options->allow_groups, &options->num_allow_groups,
1511: arg);
1.94 markus 1512: }
1513: break;
1.33 markus 1514:
1.94 markus 1515: case sDenyGroups:
1516: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.227 markus 1517: if (!*activep)
1518: continue;
1.314 djm 1519: array_append(filename, linenum, "DenyGroups",
1520: &options->deny_groups, &options->num_deny_groups,
1521: arg);
1.94 markus 1522: }
1523: break;
1.66 markus 1524:
1.94 markus 1525: case sCiphers:
1526: arg = strdelim(&cp);
1527: if (!arg || *arg == '\0')
1528: fatal("%s line %d: Missing argument.", filename, linenum);
1.304 djm 1529: if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
1.94 markus 1530: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1531: filename, linenum, arg ? arg : "<NONE>");
1532: if (options->ciphers == NULL)
1533: options->ciphers = xstrdup(arg);
1534: break;
1.33 markus 1535:
1.94 markus 1536: case sMacs:
1537: arg = strdelim(&cp);
1538: if (!arg || *arg == '\0')
1539: fatal("%s line %d: Missing argument.", filename, linenum);
1.304 djm 1540: if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
1.94 markus 1541: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1542: filename, linenum, arg ? arg : "<NONE>");
1543: if (options->macs == NULL)
1544: options->macs = xstrdup(arg);
1.211 djm 1545: break;
1546:
1547: case sKexAlgorithms:
1548: arg = strdelim(&cp);
1549: if (!arg || *arg == '\0')
1550: fatal("%s line %d: Missing argument.",
1551: filename, linenum);
1.304 djm 1552: if (*arg != '-' &&
1553: !kex_names_valid(*arg == '+' ? arg + 1 : arg))
1.211 djm 1554: fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1555: filename, linenum, arg ? arg : "<NONE>");
1556: if (options->kex_algorithms == NULL)
1557: options->kex_algorithms = xstrdup(arg);
1.94 markus 1558: break;
1.43 jakob 1559:
1.94 markus 1560: case sSubsystem:
1561: if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1562: fatal("%s line %d: too many subsystems defined.",
1.95 deraadt 1563: filename, linenum);
1.94 markus 1564: }
1565: arg = strdelim(&cp);
1566: if (!arg || *arg == '\0')
1567: fatal("%s line %d: Missing subsystem name.",
1.95 deraadt 1568: filename, linenum);
1.153 dtucker 1569: if (!*activep) {
1570: arg = strdelim(&cp);
1571: break;
1572: }
1.94 markus 1573: for (i = 0; i < options->num_subsystems; i++)
1574: if (strcmp(arg, options->subsystem_name[i]) == 0)
1575: fatal("%s line %d: Subsystem '%s' already defined.",
1.95 deraadt 1576: filename, linenum, arg);
1.94 markus 1577: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1578: arg = strdelim(&cp);
1579: if (!arg || *arg == '\0')
1580: fatal("%s line %d: Missing subsystem command.",
1.95 deraadt 1581: filename, linenum);
1.94 markus 1582: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151 djm 1583:
1584: /* Collect arguments (separate to executable) */
1585: p = xstrdup(arg);
1586: len = strlen(p) + 1;
1587: while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1588: len += 1 + strlen(arg);
1.264 deraadt 1589: p = xreallocarray(p, 1, len);
1.151 djm 1590: strlcat(p, " ", len);
1591: strlcat(p, arg, len);
1592: }
1593: options->subsystem_args[options->num_subsystems] = p;
1.94 markus 1594: options->num_subsystems++;
1595: break;
1.46 markus 1596:
1.94 markus 1597: case sMaxStartups:
1598: arg = strdelim(&cp);
1599: if (!arg || *arg == '\0')
1600: fatal("%s line %d: Missing MaxStartups spec.",
1.95 deraadt 1601: filename, linenum);
1.94 markus 1602: if ((n = sscanf(arg, "%d:%d:%d",
1603: &options->max_startups_begin,
1604: &options->max_startups_rate,
1605: &options->max_startups)) == 3) {
1606: if (options->max_startups_begin >
1607: options->max_startups ||
1608: options->max_startups_rate > 100 ||
1609: options->max_startups_rate < 1)
1.50 markus 1610: fatal("%s line %d: Illegal MaxStartups spec.",
1.87 stevesk 1611: filename, linenum);
1.94 markus 1612: } else if (n != 1)
1613: fatal("%s line %d: Illegal MaxStartups spec.",
1614: filename, linenum);
1615: else
1616: options->max_startups = options->max_startups_begin;
1617: break;
1.133 dtucker 1618:
1619: case sMaxAuthTries:
1620: intptr = &options->max_authtries;
1621: goto parse_int;
1.94 markus 1622:
1.180 djm 1623: case sMaxSessions:
1624: intptr = &options->max_sessions;
1625: goto parse_int;
1626:
1.94 markus 1627: case sBanner:
1628: charptr = &options->banner;
1629: goto parse_filename;
1.176 djm 1630:
1.94 markus 1631: /*
1632: * These options can contain %X options expanded at
1633: * connect time, so that you can specify paths like:
1634: *
1635: * AuthorizedKeysFile /etc/ssh_keys/%u
1636: */
1637: case sAuthorizedKeysFile:
1.219 djm 1638: if (*activep && options->num_authkeys_files == 0) {
1639: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.314 djm 1640: arg = tilde_expand_filename(arg, getuid());
1641: array_append(filename, linenum,
1642: "AuthorizedKeysFile",
1643: &options->authorized_keys_files,
1644: &options->num_authkeys_files, arg);
1645: free(arg);
1.219 djm 1646: }
1647: }
1648: return 0;
1649:
1.208 djm 1650: case sAuthorizedPrincipalsFile:
1651: charptr = &options->authorized_principals_file;
1.205 djm 1652: arg = strdelim(&cp);
1653: if (!arg || *arg == '\0')
1654: fatal("%s line %d: missing file name.",
1655: filename, linenum);
1656: if (*activep && *charptr == NULL) {
1.206 markus 1657: *charptr = tilde_expand_filename(arg, getuid());
1.205 djm 1658: /* increase optional counter */
1659: if (intptr != NULL)
1660: *intptr = *intptr + 1;
1661: }
1662: break;
1.94 markus 1663:
1664: case sClientAliveInterval:
1665: intptr = &options->client_alive_interval;
1666: goto parse_time;
1667:
1668: case sClientAliveCountMax:
1669: intptr = &options->client_alive_count_max;
1670: goto parse_int;
1.131 djm 1671:
1672: case sAcceptEnv:
1673: while ((arg = strdelim(&cp)) && *arg != '\0') {
1674: if (strchr(arg, '=') != NULL)
1675: fatal("%s line %d: Invalid environment name.",
1676: filename, linenum);
1.153 dtucker 1677: if (!*activep)
1.227 markus 1678: continue;
1.314 djm 1679: array_append(filename, linenum, "AcceptEnv",
1680: &options->accept_env, &options->num_accept_env,
1681: arg);
1.131 djm 1682: }
1683: break;
1.145 reyk 1684:
1685: case sPermitTunnel:
1686: intptr = &options->permit_tun;
1.146 reyk 1687: arg = strdelim(&cp);
1688: if (!arg || *arg == '\0')
1689: fatal("%s line %d: Missing yes/point-to-point/"
1690: "ethernet/no argument.", filename, linenum);
1.182 dtucker 1691: value = -1;
1692: for (i = 0; tunmode_desc[i].val != -1; i++)
1693: if (strcmp(tunmode_desc[i].text, arg) == 0) {
1694: value = tunmode_desc[i].val;
1695: break;
1696: }
1697: if (value == -1)
1.146 reyk 1698: fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1699: "no argument: %s", filename, linenum, arg);
1.268 djm 1700: if (*activep && *intptr == -1)
1.146 reyk 1701: *intptr = value;
1702: break;
1.94 markus 1703:
1.153 dtucker 1704: case sMatch:
1705: if (cmdline)
1706: fatal("Match directive not supported as a command-line "
1707: "option");
1.226 dtucker 1708: value = match_cfg_line(&cp, linenum, connectinfo);
1.153 dtucker 1709: if (value < 0)
1710: fatal("%s line %d: Bad Match condition", filename,
1711: linenum);
1712: *activep = value;
1.156 dtucker 1713: break;
1714:
1715: case sPermitOpen:
1716: arg = strdelim(&cp);
1717: if (!arg || *arg == '\0')
1718: fatal("%s line %d: missing PermitOpen specification",
1719: filename, linenum);
1.313 djm 1720: value = options->num_permitted_opens; /* modified later */
1.310 djm 1721: if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
1.313 djm 1722: if (*activep && value == 0) {
1.224 dtucker 1723: options->num_permitted_opens = 1;
1.310 djm 1724: options->permitted_opens = xcalloc(1,
1725: sizeof(*options->permitted_opens));
1726: options->permitted_opens[0] = xstrdup(arg);
1.311 dtucker 1727: }
1.156 dtucker 1728: break;
1729: }
1.159 dtucker 1730: for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1.310 djm 1731: arg2 = xstrdup(arg);
1.159 dtucker 1732: p = hpdelim(&arg);
1733: if (p == NULL)
1734: fatal("%s line %d: missing host in PermitOpen",
1735: filename, linenum);
1736: p = cleanhostname(p);
1.223 dtucker 1737: if (arg == NULL || ((port = permitopen_port(arg)) < 0))
1.159 dtucker 1738: fatal("%s line %d: bad port number in "
1739: "PermitOpen", filename, linenum);
1.313 djm 1740: if (*activep && value == 0) {
1.314 djm 1741: array_append(filename, linenum,
1742: "PermitOpen",
1743: &options->permitted_opens,
1744: &options->num_permitted_opens, arg2);
1745: }
1746: free(arg2);
1.159 dtucker 1747: }
1.153 dtucker 1748: break;
1749:
1.158 dtucker 1750: case sForceCommand:
1.262 dtucker 1751: if (cp == NULL || *cp == '\0')
1.158 dtucker 1752: fatal("%.200s line %d: Missing argument.", filename,
1753: linenum);
1754: len = strspn(cp, WHITESPACE);
1755: if (*activep && options->adm_forced_command == NULL)
1756: options->adm_forced_command = xstrdup(cp + len);
1757: return 0;
1758:
1.176 djm 1759: case sChrootDirectory:
1760: charptr = &options->chroot_directory;
1.177 djm 1761:
1762: arg = strdelim(&cp);
1763: if (!arg || *arg == '\0')
1764: fatal("%s line %d: missing file name.",
1765: filename, linenum);
1766: if (*activep && *charptr == NULL)
1767: *charptr = xstrdup(arg);
1768: break;
1.176 djm 1769:
1.204 djm 1770: case sTrustedUserCAKeys:
1771: charptr = &options->trusted_user_ca_keys;
1772: goto parse_filename;
1773:
1774: case sRevokedKeys:
1775: charptr = &options->revoked_keys_file;
1776: goto parse_filename;
1777:
1.213 djm 1778: case sIPQoS:
1779: arg = strdelim(&cp);
1780: if ((value = parse_ipqos(arg)) == -1)
1781: fatal("%s line %d: Bad IPQoS value: %s",
1782: filename, linenum, arg);
1783: arg = strdelim(&cp);
1784: if (arg == NULL)
1785: value2 = value;
1786: else if ((value2 = parse_ipqos(arg)) == -1)
1787: fatal("%s line %d: Bad IPQoS value: %s",
1788: filename, linenum, arg);
1789: if (*activep) {
1790: options->ip_qos_interactive = value;
1791: options->ip_qos_bulk = value2;
1792: }
1793: break;
1794:
1.225 djm 1795: case sVersionAddendum:
1.262 dtucker 1796: if (cp == NULL || *cp == '\0')
1.225 djm 1797: fatal("%.200s line %d: Missing argument.", filename,
1798: linenum);
1799: len = strspn(cp, WHITESPACE);
1800: if (*activep && options->version_addendum == NULL) {
1801: if (strcasecmp(cp + len, "none") == 0)
1802: options->version_addendum = xstrdup("");
1803: else if (strchr(cp + len, '\r') != NULL)
1804: fatal("%.200s line %d: Invalid argument",
1805: filename, linenum);
1806: else
1807: options->version_addendum = xstrdup(cp + len);
1808: }
1809: return 0;
1810:
1.231 djm 1811: case sAuthorizedKeysCommand:
1.255 jsg 1812: if (cp == NULL)
1813: fatal("%.200s line %d: Missing argument.", filename,
1814: linenum);
1.231 djm 1815: len = strspn(cp, WHITESPACE);
1816: if (*activep && options->authorized_keys_command == NULL) {
1817: if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1818: fatal("%.200s line %d: AuthorizedKeysCommand "
1819: "must be an absolute path",
1820: filename, linenum);
1821: options->authorized_keys_command = xstrdup(cp + len);
1822: }
1823: return 0;
1824:
1825: case sAuthorizedKeysCommandUser:
1826: charptr = &options->authorized_keys_command_user;
1827:
1828: arg = strdelim(&cp);
1.255 jsg 1829: if (!arg || *arg == '\0')
1830: fatal("%s line %d: missing AuthorizedKeysCommandUser "
1831: "argument.", filename, linenum);
1.231 djm 1832: if (*activep && *charptr == NULL)
1833: *charptr = xstrdup(arg);
1834: break;
1835:
1.270 djm 1836: case sAuthorizedPrincipalsCommand:
1837: if (cp == NULL)
1838: fatal("%.200s line %d: Missing argument.", filename,
1839: linenum);
1840: len = strspn(cp, WHITESPACE);
1841: if (*activep &&
1842: options->authorized_principals_command == NULL) {
1843: if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1844: fatal("%.200s line %d: "
1845: "AuthorizedPrincipalsCommand must be "
1846: "an absolute path", filename, linenum);
1847: options->authorized_principals_command =
1848: xstrdup(cp + len);
1849: }
1850: return 0;
1851:
1852: case sAuthorizedPrincipalsCommandUser:
1853: charptr = &options->authorized_principals_command_user;
1854:
1855: arg = strdelim(&cp);
1856: if (!arg || *arg == '\0')
1857: fatal("%s line %d: missing "
1858: "AuthorizedPrincipalsCommandUser argument.",
1859: filename, linenum);
1860: if (*activep && *charptr == NULL)
1861: *charptr = xstrdup(arg);
1862: break;
1863:
1.232 djm 1864: case sAuthenticationMethods:
1.268 djm 1865: if (options->num_auth_methods == 0) {
1.291 djm 1866: value = 0; /* seen "any" pseudo-method */
1.292 djm 1867: value2 = 0; /* sucessfully parsed any method */
1.232 djm 1868: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.291 djm 1869: if (strcmp(arg, "any") == 0) {
1870: if (options->num_auth_methods > 0) {
1871: fatal("%s line %d: \"any\" "
1872: "must appear alone in "
1873: "AuthenticationMethods",
1874: filename, linenum);
1875: }
1876: value = 1;
1877: } else if (value) {
1878: fatal("%s line %d: \"any\" must appear "
1879: "alone in AuthenticationMethods",
1880: filename, linenum);
1881: } else if (auth2_methods_valid(arg, 0) != 0) {
1.232 djm 1882: fatal("%s line %d: invalid "
1883: "authentication method list.",
1884: filename, linenum);
1.291 djm 1885: }
1.292 djm 1886: value2 = 1;
1.268 djm 1887: if (!*activep)
1888: continue;
1.314 djm 1889: array_append(filename, linenum,
1890: "AuthenticationMethods",
1891: &options->auth_methods,
1892: &options->num_auth_methods, arg);
1.232 djm 1893: }
1.292 djm 1894: if (value2 == 0) {
1.291 djm 1895: fatal("%s line %d: no AuthenticationMethods "
1896: "specified", filename, linenum);
1897: }
1.232 djm 1898: }
1899: return 0;
1900:
1.251 millert 1901: case sStreamLocalBindMask:
1902: arg = strdelim(&cp);
1903: if (!arg || *arg == '\0')
1.268 djm 1904: fatal("%s line %d: missing StreamLocalBindMask "
1905: "argument.", filename, linenum);
1.251 millert 1906: /* Parse mode in octal format */
1907: value = strtol(arg, &p, 8);
1908: if (arg == p || value < 0 || value > 0777)
1909: fatal("%s line %d: Bad mask.", filename, linenum);
1.268 djm 1910: if (*activep)
1911: options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1.251 millert 1912: break;
1913:
1914: case sStreamLocalBindUnlink:
1915: intptr = &options->fwd_opts.streamlocal_bind_unlink;
1916: goto parse_flag;
1917:
1.256 djm 1918: case sFingerprintHash:
1919: arg = strdelim(&cp);
1920: if (!arg || *arg == '\0')
1921: fatal("%.200s line %d: Missing argument.",
1922: filename, linenum);
1923: if ((value = ssh_digest_alg_by_name(arg)) == -1)
1924: fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1925: filename, linenum, arg);
1926: if (*activep)
1927: options->fingerprint_hash = value;
1928: break;
1929:
1.309 djm 1930: case sExposeAuthInfo:
1931: intptr = &options->expose_userauth_info;
1932: goto parse_flag;
1933:
1.316 ! djm 1934: case sRDomain:
! 1935: charptr = &options->routing_domain;
! 1936: arg = strdelim(&cp);
! 1937: if (!arg || *arg == '\0')
! 1938: fatal("%.200s line %d: Missing argument.",
! 1939: filename, linenum);
! 1940: if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
! 1941: !valid_rdomain(arg))
! 1942: fatal("%s line %d: bad routing domain",
! 1943: filename, linenum);
! 1944: if (*activep && *charptr == NULL)
! 1945: *charptr = xstrdup(arg);
! 1946:
1.94 markus 1947: case sDeprecated:
1.295 djm 1948: case sIgnore:
1.121 jakob 1949: case sUnsupported:
1.295 djm 1950: do_log2(opcode == sIgnore ?
1951: SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1952: "%s line %d: %s option %s", filename, linenum,
1953: opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
1.94 markus 1954: while (arg)
1955: arg = strdelim(&cp);
1956: break;
1957:
1958: default:
1959: fatal("%s line %d: Missing handler for opcode %s (%d)",
1960: filename, linenum, arg, opcode);
1961: }
1962: if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1963: fatal("%s line %d: garbage at end of line; \"%.200s\".",
1964: filename, linenum, arg);
1965: return 0;
1966: }
1967:
1968: /* Reads the server configuration file. */
1.25 markus 1969:
1.94 markus 1970: void
1.134 djm 1971: load_server_config(const char *filename, Buffer *conf)
1.94 markus 1972: {
1.229 dtucker 1973: char line[4096], *cp;
1.94 markus 1974: FILE *f;
1.229 dtucker 1975: int lineno = 0;
1.81 stevesk 1976:
1.134 djm 1977: debug2("%s: filename %s", __func__, filename);
1978: if ((f = fopen(filename, "r")) == NULL) {
1.94 markus 1979: perror(filename);
1980: exit(1);
1981: }
1.134 djm 1982: buffer_clear(conf);
1983: while (fgets(line, sizeof(line), f)) {
1.229 dtucker 1984: lineno++;
1985: if (strlen(line) == sizeof(line) - 1)
1986: fatal("%s line %d too long", filename, lineno);
1.134 djm 1987: /*
1988: * Trim out comments and strip whitespace
1.135 deraadt 1989: * NB - preserve newlines, they are needed to reproduce
1.134 djm 1990: * line numbers later for error messages
1991: */
1992: if ((cp = strchr(line, '#')) != NULL)
1993: memcpy(cp, "\n", 2);
1994: cp = line + strspn(line, " \t\r");
1995:
1996: buffer_append(conf, cp, strlen(cp));
1997: }
1998: buffer_append(conf, "\0", 1);
1999: fclose(f);
2000: debug2("%s: done config len = %d", __func__, buffer_len(conf));
2001: }
2002:
2003: void
1.226 dtucker 2004: parse_server_match_config(ServerOptions *options,
2005: struct connection_info *connectinfo)
1.153 dtucker 2006: {
2007: ServerOptions mo;
2008:
2009: initialize_server_options(&mo);
1.226 dtucker 2010: parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
1.168 dtucker 2011: copy_set_server_options(options, &mo, 0);
1.153 dtucker 2012: }
2013:
1.226 dtucker 2014: int parse_server_match_testspec(struct connection_info *ci, char *spec)
2015: {
2016: char *p;
2017:
2018: while ((p = strsep(&spec, ",")) && *p != '\0') {
2019: if (strncmp(p, "addr=", 5) == 0) {
2020: ci->address = xstrdup(p + 5);
2021: } else if (strncmp(p, "host=", 5) == 0) {
2022: ci->host = xstrdup(p + 5);
2023: } else if (strncmp(p, "user=", 5) == 0) {
2024: ci->user = xstrdup(p + 5);
2025: } else if (strncmp(p, "laddr=", 6) == 0) {
2026: ci->laddress = xstrdup(p + 6);
2027: } else if (strncmp(p, "lport=", 6) == 0) {
2028: ci->lport = a2port(p + 6);
2029: if (ci->lport == -1) {
2030: fprintf(stderr, "Invalid port '%s' in test mode"
2031: " specification %s\n", p+6, p);
2032: return -1;
2033: }
2034: } else {
2035: fprintf(stderr, "Invalid test mode specification %s\n",
2036: p);
2037: return -1;
2038: }
2039: }
2040: return 0;
2041: }
2042:
2043: /*
2044: * returns 1 for a complete spec, 0 for partial spec and -1 for an
2045: * empty spec.
2046: */
2047: int server_match_spec_complete(struct connection_info *ci)
2048: {
2049: if (ci->user && ci->host && ci->address)
2050: return 1; /* complete */
2051: if (!ci->user && !ci->host && !ci->address)
2052: return -1; /* empty */
2053: return 0; /* partial */
2054: }
2055:
1.168 dtucker 2056: /*
2057: * Copy any supported values that are set.
2058: *
1.195 jj 2059: * If the preauth flag is set, we do not bother copying the string or
1.168 dtucker 2060: * array values that are not used pre-authentication, because any that we
2061: * do use must be explictly sent in mm_getpwnamallow().
2062: */
1.153 dtucker 2063: void
1.168 dtucker 2064: copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1.153 dtucker 2065: {
1.247 djm 2066: #define M_CP_INTOPT(n) do {\
2067: if (src->n != -1) \
2068: dst->n = src->n; \
2069: } while (0)
2070:
1.168 dtucker 2071: M_CP_INTOPT(password_authentication);
2072: M_CP_INTOPT(gss_authentication);
2073: M_CP_INTOPT(pubkey_authentication);
2074: M_CP_INTOPT(kerberos_authentication);
2075: M_CP_INTOPT(hostbased_authentication);
1.209 djm 2076: M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1.168 dtucker 2077: M_CP_INTOPT(kbd_interactive_authentication);
1.175 dtucker 2078: M_CP_INTOPT(permit_root_login);
1.188 djm 2079: M_CP_INTOPT(permit_empty_passwd);
1.168 dtucker 2080:
2081: M_CP_INTOPT(allow_tcp_forwarding);
1.251 millert 2082: M_CP_INTOPT(allow_streamlocal_forwarding);
1.178 pyr 2083: M_CP_INTOPT(allow_agent_forwarding);
1.301 djm 2084: M_CP_INTOPT(disable_forwarding);
1.309 djm 2085: M_CP_INTOPT(expose_userauth_info);
1.209 djm 2086: M_CP_INTOPT(permit_tun);
1.251 millert 2087: M_CP_INTOPT(fwd_opts.gateway_ports);
1.289 djm 2088: M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
1.168 dtucker 2089: M_CP_INTOPT(x11_display_offset);
2090: M_CP_INTOPT(x11_forwarding);
2091: M_CP_INTOPT(x11_use_localhost);
1.244 djm 2092: M_CP_INTOPT(permit_tty);
1.250 djm 2093: M_CP_INTOPT(permit_user_rc);
1.180 djm 2094: M_CP_INTOPT(max_sessions);
1.184 dtucker 2095: M_CP_INTOPT(max_authtries);
1.300 markus 2096: M_CP_INTOPT(client_alive_count_max);
2097: M_CP_INTOPT(client_alive_interval);
1.213 djm 2098: M_CP_INTOPT(ip_qos_interactive);
2099: M_CP_INTOPT(ip_qos_bulk);
1.235 dtucker 2100: M_CP_INTOPT(rekey_limit);
2101: M_CP_INTOPT(rekey_interval);
1.308 djm 2102: M_CP_INTOPT(log_level);
1.289 djm 2103:
2104: /*
2105: * The bind_mask is a mode_t that may be unsigned, so we can't use
2106: * M_CP_INTOPT - it does a signed comparison that causes compiler
2107: * warnings.
2108: */
1.290 dtucker 2109: if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
1.289 djm 2110: dst->fwd_opts.streamlocal_bind_mask =
2111: src->fwd_opts.streamlocal_bind_mask;
2112: }
1.247 djm 2113:
2114: /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2115: #define M_CP_STROPT(n) do {\
2116: if (src->n != NULL && dst->n != src->n) { \
2117: free(dst->n); \
2118: dst->n = src->n; \
2119: } \
2120: } while(0)
1.314 djm 2121: #define M_CP_STRARRAYOPT(s, num_s) do {\
2122: u_int i; \
2123: if (src->num_s != 0) { \
2124: for (i = 0; i < dst->num_s; i++) \
2125: free(dst->s[i]); \
2126: free(dst->s); \
2127: dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2128: for (i = 0; i < src->num_s; i++) \
2129: dst->s[i] = xstrdup(src->s[i]); \
2130: dst->num_s = src->num_s; \
1.312 djm 2131: } \
2132: } while(0)
1.168 dtucker 2133:
1.218 djm 2134: /* See comment in servconf.h */
2135: COPY_MATCH_STRING_OPTS();
1.282 djm 2136:
2137: /* Arguments that accept '+...' need to be expanded */
2138: assemble_algorithms(dst);
1.216 djm 2139:
1.217 dtucker 2140: /*
2141: * The only things that should be below this point are string options
2142: * which are only used after authentication.
2143: */
1.168 dtucker 2144: if (preauth)
2145: return;
1.219 djm 2146:
1.283 djm 2147: /* These options may be "none" to clear a global setting */
1.168 dtucker 2148: M_CP_STROPT(adm_forced_command);
1.283 djm 2149: if (option_clear_or_none(dst->adm_forced_command)) {
2150: free(dst->adm_forced_command);
2151: dst->adm_forced_command = NULL;
2152: }
1.176 djm 2153: M_CP_STROPT(chroot_directory);
1.283 djm 2154: if (option_clear_or_none(dst->chroot_directory)) {
2155: free(dst->chroot_directory);
2156: dst->chroot_directory = NULL;
2157: }
1.153 dtucker 2158: }
1.168 dtucker 2159:
2160: #undef M_CP_INTOPT
2161: #undef M_CP_STROPT
1.219 djm 2162: #undef M_CP_STRARRAYOPT
1.153 dtucker 2163:
2164: void
2165: parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1.226 dtucker 2166: struct connection_info *connectinfo)
1.134 djm 2167: {
1.153 dtucker 2168: int active, linenum, bad_options = 0;
1.136 dtucker 2169: char *cp, *obuf, *cbuf;
1.134 djm 2170:
2171: debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2172:
1.287 djm 2173: if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2174: fatal("%s: sshbuf_dup_string failed", __func__);
1.226 dtucker 2175: active = connectinfo ? 0 : 1;
1.137 dtucker 2176: linenum = 1;
1.140 deraadt 2177: while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134 djm 2178: if (process_server_config_line(options, cp, filename,
1.226 dtucker 2179: linenum++, &active, connectinfo) != 0)
1.94 markus 2180: bad_options++;
1.1 deraadt 2181: }
1.239 djm 2182: free(obuf);
1.78 stevesk 2183: if (bad_options > 0)
2184: fatal("%s: terminating, %d bad configuration options",
2185: filename, bad_options);
1.266 dtucker 2186: process_queued_listen_addrs(options);
1.182 dtucker 2187: }
2188:
2189: static const char *
1.221 djm 2190: fmt_multistate_int(int val, const struct multistate *m)
2191: {
2192: u_int i;
2193:
2194: for (i = 0; m[i].key != NULL; i++) {
2195: if (m[i].value == val)
2196: return m[i].key;
2197: }
2198: return "UNKNOWN";
2199: }
2200:
2201: static const char *
1.182 dtucker 2202: fmt_intarg(ServerOpCodes code, int val)
2203: {
1.221 djm 2204: if (val == -1)
2205: return "unset";
2206: switch (code) {
2207: case sAddressFamily:
2208: return fmt_multistate_int(val, multistate_addressfamily);
2209: case sPermitRootLogin:
2210: return fmt_multistate_int(val, multistate_permitrootlogin);
2211: case sGatewayPorts:
2212: return fmt_multistate_int(val, multistate_gatewayports);
2213: case sCompression:
2214: return fmt_multistate_int(val, multistate_compression);
1.233 djm 2215: case sAllowTcpForwarding:
2216: return fmt_multistate_int(val, multistate_tcpfwd);
1.251 millert 2217: case sAllowStreamLocalForwarding:
2218: return fmt_multistate_int(val, multistate_tcpfwd);
1.256 djm 2219: case sFingerprintHash:
2220: return ssh_digest_alg_name(val);
1.221 djm 2221: default:
2222: switch (val) {
2223: case 0:
2224: return "no";
2225: case 1:
2226: return "yes";
2227: default:
2228: return "UNKNOWN";
2229: }
1.182 dtucker 2230: }
2231: }
2232:
2233: static const char *
2234: lookup_opcode_name(ServerOpCodes code)
2235: {
2236: u_int i;
2237:
2238: for (i = 0; keywords[i].name != NULL; i++)
2239: if (keywords[i].opcode == code)
2240: return(keywords[i].name);
2241: return "UNKNOWN";
2242: }
2243:
2244: static void
2245: dump_cfg_int(ServerOpCodes code, int val)
2246: {
2247: printf("%s %d\n", lookup_opcode_name(code), val);
2248: }
2249:
2250: static void
1.263 dtucker 2251: dump_cfg_oct(ServerOpCodes code, int val)
2252: {
2253: printf("%s 0%o\n", lookup_opcode_name(code), val);
2254: }
2255:
2256: static void
1.182 dtucker 2257: dump_cfg_fmtint(ServerOpCodes code, int val)
2258: {
2259: printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2260: }
2261:
2262: static void
2263: dump_cfg_string(ServerOpCodes code, const char *val)
2264: {
1.257 djm 2265: printf("%s %s\n", lookup_opcode_name(code),
2266: val == NULL ? "none" : val);
1.182 dtucker 2267: }
2268:
2269: static void
2270: dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2271: {
2272: u_int i;
2273:
2274: for (i = 0; i < count; i++)
1.219 djm 2275: printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2276: }
2277:
2278: static void
2279: dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2280: {
2281: u_int i;
2282:
1.291 djm 2283: if (count <= 0 && code != sAuthenticationMethods)
1.261 dtucker 2284: return;
1.219 djm 2285: printf("%s", lookup_opcode_name(code));
2286: for (i = 0; i < count; i++)
2287: printf(" %s", vals[i]);
1.291 djm 2288: if (code == sAuthenticationMethods && count == 0)
2289: printf(" any");
1.219 djm 2290: printf("\n");
1.182 dtucker 2291: }
2292:
1.315 djm 2293: static char *
2294: format_listen_addrs(struct listenaddr *la)
1.182 dtucker 2295: {
1.315 djm 2296: int r;
1.182 dtucker 2297: struct addrinfo *ai;
1.315 djm 2298: char addr[NI_MAXHOST], port[NI_MAXSERV];
1.263 dtucker 2299: char *laddr1 = xstrdup(""), *laddr2 = NULL;
1.182 dtucker 2300:
1.263 dtucker 2301: /*
2302: * ListenAddress must be after Port. add_one_listen_addr pushes
2303: * addresses onto a stack, so to maintain ordering we need to
2304: * print these in reverse order.
2305: */
1.315 djm 2306: for (ai = la->addrs; ai; ai = ai->ai_next) {
2307: if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1.182 dtucker 2308: sizeof(addr), port, sizeof(port),
2309: NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1.315 djm 2310: error("getnameinfo: %.100s", ssh_gai_strerror(r));
2311: continue;
2312: }
2313: laddr2 = laddr1;
2314: if (ai->ai_family == AF_INET6) {
2315: xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2316: addr, port,
2317: la->rdomain == NULL ? "" : " rdomain ",
2318: la->rdomain == NULL ? "" : la->rdomain,
2319: laddr2);
1.182 dtucker 2320: } else {
1.315 djm 2321: xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2322: addr, port,
2323: la->rdomain == NULL ? "" : " rdomain ",
2324: la->rdomain == NULL ? "" : la->rdomain,
2325: laddr2);
1.182 dtucker 2326: }
1.315 djm 2327: free(laddr2);
2328: }
2329: return laddr1;
2330: }
2331:
2332: void
2333: dump_config(ServerOptions *o)
2334: {
2335: char *s;
2336: u_int i;
2337:
2338: /* these are usually at the top of the config */
2339: for (i = 0; i < o->num_ports; i++)
2340: printf("port %d\n", o->ports[i]);
2341: dump_cfg_fmtint(sAddressFamily, o->address_family);
2342:
2343: for (i = 0; i < o->num_listen_addrs; i++) {
2344: s = format_listen_addrs(&o->listen_addrs[i]);
2345: printf("%s", s);
2346: free(s);
1.182 dtucker 2347: }
2348:
2349: /* integer arguments */
2350: dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2351: dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2352: dump_cfg_int(sMaxAuthTries, o->max_authtries);
1.189 djm 2353: dump_cfg_int(sMaxSessions, o->max_sessions);
1.182 dtucker 2354: dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2355: dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1.263 dtucker 2356: dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
1.182 dtucker 2357:
2358: /* formatted integer arguments */
2359: dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2360: dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2361: dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2362: dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2363: dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2364: o->hostbased_uses_name_from_packet_only);
2365: dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
1.187 djm 2366: #ifdef KRB5
1.182 dtucker 2367: dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2368: dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2369: dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
2370: dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
1.187 djm 2371: #endif
2372: #ifdef GSSAPI
1.182 dtucker 2373: dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2374: dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
1.187 djm 2375: #endif
1.182 dtucker 2376: dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2377: dump_cfg_fmtint(sKbdInteractiveAuthentication,
2378: o->kbd_interactive_authentication);
2379: dump_cfg_fmtint(sChallengeResponseAuthentication,
2380: o->challenge_response_authentication);
2381: dump_cfg_fmtint(sPrintMotd, o->print_motd);
2382: dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2383: dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2384: dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1.244 djm 2385: dump_cfg_fmtint(sPermitTTY, o->permit_tty);
1.250 djm 2386: dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
1.182 dtucker 2387: dump_cfg_fmtint(sStrictModes, o->strict_modes);
2388: dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2389: dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2390: dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2391: dump_cfg_fmtint(sCompression, o->compression);
1.251 millert 2392: dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
1.182 dtucker 2393: dump_cfg_fmtint(sUseDNS, o->use_dns);
2394: dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1.261 dtucker 2395: dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
1.301 djm 2396: dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
1.251 millert 2397: dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
1.288 djm 2398: dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
1.256 djm 2399: dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
1.309 djm 2400: dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
1.182 dtucker 2401:
2402: /* string arguments */
2403: dump_cfg_string(sPidFile, o->pid_file);
2404: dump_cfg_string(sXAuthLocation, o->xauth_location);
1.252 djm 2405: dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2406: dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
1.182 dtucker 2407: dump_cfg_string(sBanner, o->banner);
2408: dump_cfg_string(sForceCommand, o->adm_forced_command);
1.201 dtucker 2409: dump_cfg_string(sChrootDirectory, o->chroot_directory);
1.204 djm 2410: dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2411: dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
1.208 djm 2412: dump_cfg_string(sAuthorizedPrincipalsFile,
2413: o->authorized_principals_file);
1.261 dtucker 2414: dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2415: ? "none" : o->version_addendum);
1.231 djm 2416: dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2417: dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
1.270 djm 2418: dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2419: dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
1.240 markus 2420: dump_cfg_string(sHostKeyAgent, o->host_key_agent);
1.252 djm 2421: dump_cfg_string(sKexAlgorithms,
1.253 djm 2422: o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
1.258 djm 2423: dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2424: o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
1.276 markus 2425: dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2426: o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
1.258 djm 2427: dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2428: o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
1.316 ! djm 2429: dump_cfg_string(sRDomain, o->routing_domain);
1.182 dtucker 2430:
2431: /* string arguments requiring a lookup */
2432: dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2433: dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2434:
2435: /* string array arguments */
1.219 djm 2436: dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2437: o->authorized_keys_files);
1.182 dtucker 2438: dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2439: o->host_key_files);
1.261 dtucker 2440: dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
1.203 djm 2441: o->host_cert_files);
1.182 dtucker 2442: dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2443: dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2444: dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2445: dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2446: dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1.232 djm 2447: dump_cfg_strarray_oneline(sAuthenticationMethods,
2448: o->num_auth_methods, o->auth_methods);
1.182 dtucker 2449:
2450: /* other arguments */
2451: for (i = 0; i < o->num_subsystems; i++)
2452: printf("subsystem %s %s\n", o->subsystem_name[i],
2453: o->subsystem_args[i]);
2454:
2455: printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2456: o->max_startups_rate, o->max_startups);
2457:
2458: for (i = 0; tunmode_desc[i].val != -1; i++)
2459: if (tunmode_desc[i].val == o->permit_tun) {
2460: s = tunmode_desc[i].text;
2461: break;
2462: }
2463: dump_cfg_string(sPermitTunnel, s);
1.213 djm 2464:
1.214 stevesk 2465: printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2466: printf("%s\n", iptos2str(o->ip_qos_bulk));
1.235 dtucker 2467:
1.284 dtucker 2468: printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
1.241 djm 2469: o->rekey_interval);
1.182 dtucker 2470:
1.310 djm 2471: printf("permitopen");
2472: if (o->num_permitted_opens == 0)
2473: printf(" any");
2474: else {
2475: for (i = 0; i < o->num_permitted_opens; i++)
2476: printf(" %s", o->permitted_opens[i]);
2477: }
2478: printf("\n");
1.1 deraadt 2479: }