Annotation of src/usr.bin/ssh/servconf.c, Revision 1.319
1.226 dtucker 1:
1.319 ! dtucker 2: /* $OpenBSD: servconf.c,v 1.318 2017/10/25 02:10:39 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.317 djm 808: ci.rdomain = ssh_packet_rdomain_in(ssh);
1.226 dtucker 809: return &ci;
810: }
811:
1.153 dtucker 812: /*
813: * The strategy for the Match blocks is that the config file is parsed twice.
814: *
815: * The first time is at startup. activep is initialized to 1 and the
816: * directives in the global context are processed and acted on. Hitting a
817: * Match directive unsets activep and the directives inside the block are
818: * checked for syntax only.
819: *
820: * The second time is after a connection has been established but before
821: * authentication. activep is initialized to 2 and global config directives
822: * are ignored since they have already been processed. If the criteria in a
823: * Match block is met, activep is set and the subsequent directives
824: * processed and actioned until EOF or another Match block unsets it. Any
825: * options set are copied into the main server config.
826: *
827: * Potential additions/improvements:
1.295 djm 828: * - Add Match support for pre-kex directives, eg. Ciphers.
1.153 dtucker 829: *
830: * - Add a Tag directive (idea from David Leonard) ala pf, eg:
831: * Match Address 192.168.0.*
832: * Tag trusted
833: * Match Group wheel
834: * Tag trusted
835: * Match Tag trusted
836: * AllowTcpForwarding yes
837: * GatewayPorts clientspecified
838: * [...]
839: *
840: * - Add a PermittedChannelRequests directive
841: * Match Group shell
842: * PermittedChannelRequests session,forwarded-tcpip
843: */
844:
845: static int
1.165 dtucker 846: match_cfg_line_group(const char *grps, int line, const char *user)
847: {
848: int result = 0;
849: struct passwd *pw;
850:
851: if (user == NULL)
852: goto out;
853:
854: if ((pw = getpwnam(user)) == NULL) {
855: debug("Can't match group at line %d because user %.100s does "
856: "not exist", line, user);
857: } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
858: debug("Can't Match group because user %.100s not in any group "
859: "at line %d", user, line);
1.186 djm 860: } else if (ga_match_pattern_list(grps) != 1) {
861: debug("user %.100s does not match group list %.100s at line %d",
862: user, grps, line);
1.165 dtucker 863: } else {
1.186 djm 864: debug("user %.100s matched group list %.100s at line %d", user,
865: grps, line);
1.165 dtucker 866: result = 1;
867: }
868: out:
869: ga_free();
870: return result;
871: }
872:
1.319 ! dtucker 873: static void
! 874: match_test_missing_fatal(const char *criteria, const char *attrib)
! 875: {
! 876: fatal("'Match %s' in configuration but '%s' not in connection "
! 877: "test specification.", criteria, attrib);
! 878: }
! 879:
1.226 dtucker 880: /*
1.230 dtucker 881: * All of the attributes on a single Match line are ANDed together, so we need
1.242 dtucker 882: * to check every attribute and set the result to zero if any attribute does
1.230 dtucker 883: * not match.
1.226 dtucker 884: */
1.165 dtucker 885: static int
1.226 dtucker 886: match_cfg_line(char **condition, int line, struct connection_info *ci)
1.153 dtucker 887: {
1.243 dtucker 888: int result = 1, attributes = 0, port;
1.153 dtucker 889: char *arg, *attrib, *cp = *condition;
890:
1.226 dtucker 891: if (ci == NULL)
1.153 dtucker 892: debug3("checking syntax for 'Match %s'", cp);
893: else
1.226 dtucker 894: debug3("checking match for '%s' user %s host %s addr %s "
895: "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
896: ci->host ? ci->host : "(null)",
897: ci->address ? ci->address : "(null)",
898: ci->laddress ? ci->laddress : "(null)", ci->lport);
1.153 dtucker 899:
900: while ((attrib = strdelim(&cp)) && *attrib != '\0') {
1.243 dtucker 901: attributes++;
902: if (strcasecmp(attrib, "all") == 0) {
903: if (attributes != 1 ||
904: ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
905: error("'all' cannot be combined with other "
906: "Match attributes");
907: return -1;
908: }
909: *condition = cp;
910: return 1;
911: }
1.153 dtucker 912: if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
913: error("Missing Match criteria for %s", attrib);
914: return -1;
915: }
916: if (strcasecmp(attrib, "user") == 0) {
1.319 ! dtucker 917: if (ci == NULL) {
1.153 dtucker 918: result = 0;
919: continue;
920: }
1.319 ! dtucker 921: if (ci->user == NULL)
! 922: match_test_missing_fatal("User", "user");
1.269 djm 923: if (match_pattern_list(ci->user, arg, 0) != 1)
1.153 dtucker 924: result = 0;
925: else
926: debug("user %.100s matched 'User %.100s' at "
1.226 dtucker 927: "line %d", ci->user, arg, line);
1.165 dtucker 928: } else if (strcasecmp(attrib, "group") == 0) {
1.319 ! dtucker 929: if (ci == NULL) {
1.226 dtucker 930: result = 0;
931: continue;
932: }
1.319 ! dtucker 933: if (ci->user == NULL)
! 934: match_test_missing_fatal("Group", "user");
1.226 dtucker 935: switch (match_cfg_line_group(arg, line, ci->user)) {
1.165 dtucker 936: case -1:
937: return -1;
938: case 0:
939: result = 0;
940: }
1.153 dtucker 941: } else if (strcasecmp(attrib, "host") == 0) {
1.319 ! dtucker 942: if (ci == NULL) {
1.153 dtucker 943: result = 0;
944: continue;
945: }
1.319 ! dtucker 946: if (ci->host == NULL)
! 947: match_test_missing_fatal("Host", "host");
1.269 djm 948: if (match_hostname(ci->host, arg) != 1)
1.153 dtucker 949: result = 0;
950: else
951: debug("connection from %.100s matched 'Host "
1.226 dtucker 952: "%.100s' at line %d", ci->host, arg, line);
1.153 dtucker 953: } else if (strcasecmp(attrib, "address") == 0) {
1.319 ! dtucker 954: if (ci == NULL) {
1.226 dtucker 955: result = 0;
956: continue;
957: }
1.319 ! dtucker 958: if (ci->address == NULL)
! 959: match_test_missing_fatal("Address", "addr");
1.226 dtucker 960: switch (addr_match_list(ci->address, arg)) {
1.181 djm 961: case 1:
962: debug("connection from %.100s matched 'Address "
1.226 dtucker 963: "%.100s' at line %d", ci->address, arg, line);
1.181 djm 964: break;
965: case 0:
1.183 djm 966: case -1:
1.153 dtucker 967: result = 0;
1.181 djm 968: break;
1.183 djm 969: case -2:
1.181 djm 970: return -1;
1.153 dtucker 971: }
1.226 dtucker 972: } else if (strcasecmp(attrib, "localaddress") == 0){
1.319 ! dtucker 973: if (ci == NULL) {
1.226 dtucker 974: result = 0;
975: continue;
976: }
1.319 ! dtucker 977: if (ci->laddress == NULL)
! 978: match_test_missing_fatal("LocalAddress",
! 979: "laddr");
1.226 dtucker 980: switch (addr_match_list(ci->laddress, arg)) {
981: case 1:
982: debug("connection from %.100s matched "
983: "'LocalAddress %.100s' at line %d",
984: ci->laddress, arg, line);
985: break;
986: case 0:
987: case -1:
988: result = 0;
989: break;
990: case -2:
991: return -1;
992: }
993: } else if (strcasecmp(attrib, "localport") == 0) {
994: if ((port = a2port(arg)) == -1) {
995: error("Invalid LocalPort '%s' on Match line",
996: arg);
997: return -1;
998: }
1.319 ! dtucker 999: if (ci == NULL) {
1.226 dtucker 1000: result = 0;
1001: continue;
1002: }
1.319 ! dtucker 1003: if (ci->lport == 0)
! 1004: match_test_missing_fatal("LocalPort", "lport");
1.226 dtucker 1005: /* TODO support port lists */
1006: if (port == ci->lport)
1007: debug("connection from %.100s matched "
1008: "'LocalPort %d' at line %d",
1009: ci->laddress, port, line);
1010: else
1011: result = 0;
1.317 djm 1012: } else if (strcasecmp(attrib, "rdomain") == 0) {
1013: if (ci == NULL || ci->rdomain == NULL) {
1014: result = 0;
1015: continue;
1016: }
1017: if (match_pattern_list(ci->rdomain, arg, 0) != 1)
1018: result = 0;
1019: else
1020: debug("user %.100s matched 'RDomain %.100s' at "
1021: "line %d", ci->rdomain, arg, line);
1.153 dtucker 1022: } else {
1023: error("Unsupported Match attribute %s", attrib);
1024: return -1;
1025: }
1.243 dtucker 1026: }
1027: if (attributes == 0) {
1028: error("One or more attributes required for Match");
1029: return -1;
1.153 dtucker 1030: }
1.226 dtucker 1031: if (ci != NULL)
1.153 dtucker 1032: debug3("match %sfound", result ? "" : "not ");
1033: *condition = cp;
1034: return result;
1035: }
1036:
1.158 dtucker 1037: #define WHITESPACE " \t\r\n"
1038:
1.220 djm 1039: /* Multistate option parsing */
1040: struct multistate {
1041: char *key;
1042: int value;
1043: };
1044: static const struct multistate multistate_addressfamily[] = {
1045: { "inet", AF_INET },
1046: { "inet6", AF_INET6 },
1047: { "any", AF_UNSPEC },
1048: { NULL, -1 }
1049: };
1050: static const struct multistate multistate_permitrootlogin[] = {
1051: { "without-password", PERMIT_NO_PASSWD },
1.280 deraadt 1052: { "prohibit-password", PERMIT_NO_PASSWD },
1.220 djm 1053: { "forced-commands-only", PERMIT_FORCED_ONLY },
1054: { "yes", PERMIT_YES },
1055: { "no", PERMIT_NO },
1056: { NULL, -1 }
1057: };
1058: static const struct multistate multistate_compression[] = {
1.297 djm 1059: { "yes", COMP_DELAYED },
1.220 djm 1060: { "delayed", COMP_DELAYED },
1061: { "no", COMP_NONE },
1062: { NULL, -1 }
1063: };
1064: static const struct multistate multistate_gatewayports[] = {
1065: { "clientspecified", 2 },
1066: { "yes", 1 },
1067: { "no", 0 },
1.222 djm 1068: { NULL, -1 }
1069: };
1.233 djm 1070: static const struct multistate multistate_tcpfwd[] = {
1071: { "yes", FORWARD_ALLOW },
1072: { "all", FORWARD_ALLOW },
1073: { "no", FORWARD_DENY },
1074: { "remote", FORWARD_REMOTE },
1075: { "local", FORWARD_LOCAL },
1076: { NULL, -1 }
1077: };
1.220 djm 1078:
1.94 markus 1079: int
1080: process_server_config_line(ServerOptions *options, char *line,
1.226 dtucker 1081: const char *filename, int linenum, int *activep,
1082: struct connection_info *connectinfo)
1.1 deraadt 1083: {
1.310 djm 1084: char *cp, **charptr, *arg, *arg2, *p;
1.237 dtucker 1085: int cmdline = 0, *intptr, value, value2, n, port;
1.174 dtucker 1086: SyslogFacility *log_facility_ptr;
1087: LogLevel *log_level_ptr;
1.25 markus 1088: ServerOpCodes opcode;
1.153 dtucker 1089: u_int i, flags = 0;
1.151 djm 1090: size_t len;
1.237 dtucker 1091: long long val64;
1.220 djm 1092: const struct multistate *multistate_ptr;
1.303 djm 1093:
1094: /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1095: if ((len = strlen(line)) == 0)
1096: return 0;
1097: for (len--; len > 0; len--) {
1098: if (strchr(WHITESPACE "\f", line[len]) == NULL)
1099: break;
1100: line[len] = '\0';
1101: }
1.25 markus 1102:
1.94 markus 1103: cp = line;
1.148 dtucker 1104: if ((arg = strdelim(&cp)) == NULL)
1.147 djm 1105: return 0;
1.94 markus 1106: /* Ignore leading whitespace */
1107: if (*arg == '\0')
1108: arg = strdelim(&cp);
1109: if (!arg || !*arg || *arg == '#')
1110: return 0;
1111: intptr = NULL;
1112: charptr = NULL;
1.153 dtucker 1113: opcode = parse_token(arg, filename, linenum, &flags);
1114:
1115: if (activep == NULL) { /* We are processing a command line directive */
1116: cmdline = 1;
1117: activep = &cmdline;
1118: }
1119: if (*activep && opcode != sMatch)
1120: debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1121: if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
1.226 dtucker 1122: if (connectinfo == NULL) {
1.153 dtucker 1123: fatal("%s line %d: Directive '%s' is not allowed "
1124: "within a Match block", filename, linenum, arg);
1125: } else { /* this is a directive we have already processed */
1126: while (arg)
1127: arg = strdelim(&cp);
1128: return 0;
1129: }
1130: }
1131:
1.94 markus 1132: switch (opcode) {
1133: case sBadOption:
1134: return -1;
1135: case sPort:
1136: /* ignore ports from configfile if cmdline specifies ports */
1137: if (options->ports_from_cmdline)
1138: return 0;
1139: if (options->num_ports >= MAX_PORTS)
1140: fatal("%s line %d: too many ports.",
1141: filename, linenum);
1.48 provos 1142: arg = strdelim(&cp);
1.94 markus 1143: if (!arg || *arg == '\0')
1144: fatal("%s line %d: missing port number.",
1145: filename, linenum);
1146: options->ports[options->num_ports++] = a2port(arg);
1.194 djm 1147: if (options->ports[options->num_ports-1] <= 0)
1.94 markus 1148: fatal("%s line %d: Badly formatted port number.",
1149: filename, linenum);
1150: break;
1.29 markus 1151:
1.94 markus 1152: case sLoginGraceTime:
1153: intptr = &options->login_grace_time;
1.180 djm 1154: parse_time:
1.94 markus 1155: arg = strdelim(&cp);
1156: if (!arg || *arg == '\0')
1157: fatal("%s line %d: missing time value.",
1158: filename, linenum);
1159: if ((value = convtime(arg)) == -1)
1160: fatal("%s line %d: invalid time value.",
1161: filename, linenum);
1.268 djm 1162: if (*activep && *intptr == -1)
1.94 markus 1163: *intptr = value;
1164: break;
1165:
1166: case sListenAddress:
1167: arg = strdelim(&cp);
1.139 djm 1168: if (arg == NULL || *arg == '\0')
1169: fatal("%s line %d: missing address",
1.94 markus 1170: filename, linenum);
1.144 dtucker 1171: /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1172: if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1173: && strchr(p+1, ':') != NULL) {
1.315 djm 1174: port = 0;
1175: p = arg;
1176: } else {
1177: p = hpdelim(&arg);
1178: if (p == NULL)
1179: fatal("%s line %d: bad address:port usage",
1180: filename, linenum);
1181: p = cleanhostname(p);
1182: if (arg == NULL)
1183: port = 0;
1184: else if ((port = a2port(arg)) <= 0)
1185: fatal("%s line %d: bad port number",
1186: filename, linenum);
1187: }
1188: /* Optional routing table */
1189: arg2 = NULL;
1190: if ((arg = strdelim(&cp)) != NULL) {
1191: if (strcmp(arg, "rdomain") != 0 ||
1192: (arg2 = strdelim(&cp)) == NULL)
1193: fatal("%s line %d: bad ListenAddress syntax",
1194: filename, linenum);
1195: if (!valid_rdomain(arg2))
1196: fatal("%s line %d: bad routing domain",
1197: filename, linenum);
1.144 dtucker 1198: }
1.139 djm 1199:
1.315 djm 1200: queue_listen_addr(options, p, arg2, port);
1.25 markus 1201:
1.138 djm 1202: break;
1203:
1204: case sAddressFamily:
1.220 djm 1205: intptr = &options->address_family;
1206: multistate_ptr = multistate_addressfamily;
1207: parse_multistate:
1.138 djm 1208: arg = strdelim(&cp);
1.141 markus 1209: if (!arg || *arg == '\0')
1.220 djm 1210: fatal("%s line %d: missing argument.",
1.141 markus 1211: filename, linenum);
1.220 djm 1212: value = -1;
1213: for (i = 0; multistate_ptr[i].key != NULL; i++) {
1214: if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1215: value = multistate_ptr[i].value;
1216: break;
1217: }
1218: }
1219: if (value == -1)
1220: fatal("%s line %d: unsupported option \"%s\".",
1.138 djm 1221: filename, linenum, arg);
1.220 djm 1222: if (*activep && *intptr == -1)
1.138 djm 1223: *intptr = value;
1.94 markus 1224: break;
1225:
1226: case sHostKeyFile:
1227: arg = strdelim(&cp);
1228: if (!arg || *arg == '\0')
1229: fatal("%s line %d: missing file name.",
1230: filename, linenum);
1.314 djm 1231: if (*activep)
1232: servconf_add_hostkey(filename, linenum, options, arg);
1.94 markus 1233: break;
1.76 stevesk 1234:
1.240 markus 1235: case sHostKeyAgent:
1236: charptr = &options->host_key_agent;
1237: arg = strdelim(&cp);
1238: if (!arg || *arg == '\0')
1239: fatal("%s line %d: missing socket name.",
1240: filename, linenum);
1241: if (*activep && *charptr == NULL)
1242: *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1243: xstrdup(arg) : derelativise_path(arg);
1244: break;
1245:
1.203 djm 1246: case sHostCertificate:
1.314 djm 1247: arg = strdelim(&cp);
1248: if (!arg || *arg == '\0')
1249: fatal("%s line %d: missing file name.",
1250: filename, linenum);
1251: if (*activep)
1252: servconf_add_hostcert(filename, linenum, options, arg);
1253: break;
1.203 djm 1254:
1.94 markus 1255: case sPidFile:
1256: charptr = &options->pid_file;
1.314 djm 1257: parse_filename:
1258: arg = strdelim(&cp);
1259: if (!arg || *arg == '\0')
1260: fatal("%s line %d: missing file name.",
1261: filename, linenum);
1262: if (*activep && *charptr == NULL) {
1263: *charptr = derelativise_path(arg);
1264: /* increase optional counter */
1265: if (intptr != NULL)
1266: *intptr = *intptr + 1;
1267: }
1268: break;
1.25 markus 1269:
1.94 markus 1270: case sPermitRootLogin:
1271: intptr = &options->permit_root_login;
1.220 djm 1272: multistate_ptr = multistate_permitrootlogin;
1273: goto parse_multistate;
1.36 markus 1274:
1.94 markus 1275: case sIgnoreRhosts:
1276: intptr = &options->ignore_rhosts;
1.180 djm 1277: parse_flag:
1.94 markus 1278: arg = strdelim(&cp);
1279: if (!arg || *arg == '\0')
1280: fatal("%s line %d: missing yes/no argument.",
1281: filename, linenum);
1282: value = 0; /* silence compiler */
1283: if (strcmp(arg, "yes") == 0)
1284: value = 1;
1285: else if (strcmp(arg, "no") == 0)
1286: value = 0;
1287: else
1288: fatal("%s line %d: Bad yes/no argument: %s",
1289: filename, linenum, arg);
1.153 dtucker 1290: if (*activep && *intptr == -1)
1.94 markus 1291: *intptr = value;
1292: break;
1293:
1294: case sIgnoreUserKnownHosts:
1295: intptr = &options->ignore_user_known_hosts;
1296: goto parse_flag;
1297:
1298: case sHostbasedAuthentication:
1299: intptr = &options->hostbased_authentication;
1300: goto parse_flag;
1301:
1302: case sHostbasedUsesNameFromPacketOnly:
1303: intptr = &options->hostbased_uses_name_from_packet_only;
1304: goto parse_flag;
1305:
1.258 djm 1306: case sHostbasedAcceptedKeyTypes:
1307: charptr = &options->hostbased_key_types;
1308: parse_keytypes:
1309: arg = strdelim(&cp);
1310: if (!arg || *arg == '\0')
1311: fatal("%s line %d: Missing argument.",
1312: filename, linenum);
1.304 djm 1313: if (*arg != '-' &&
1314: !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1.258 djm 1315: fatal("%s line %d: Bad key types '%s'.",
1316: filename, linenum, arg ? arg : "<NONE>");
1317: if (*activep && *charptr == NULL)
1318: *charptr = xstrdup(arg);
1319: break;
1320:
1.276 markus 1321: case sHostKeyAlgorithms:
1322: charptr = &options->hostkeyalgorithms;
1323: goto parse_keytypes;
1324:
1.94 markus 1325: case sPubkeyAuthentication:
1326: intptr = &options->pubkey_authentication;
1327: goto parse_flag;
1.119 jakob 1328:
1.258 djm 1329: case sPubkeyAcceptedKeyTypes:
1330: charptr = &options->pubkey_key_types;
1331: goto parse_keytypes;
1332:
1.94 markus 1333: case sKerberosAuthentication:
1334: intptr = &options->kerberos_authentication;
1335: goto parse_flag;
1336:
1337: case sKerberosOrLocalPasswd:
1338: intptr = &options->kerberos_or_local_passwd;
1339: goto parse_flag;
1340:
1341: case sKerberosTicketCleanup:
1342: intptr = &options->kerberos_ticket_cleanup;
1.130 jakob 1343: goto parse_flag;
1344:
1345: case sKerberosGetAFSToken:
1346: intptr = &options->kerberos_get_afs_token;
1.125 markus 1347: goto parse_flag;
1348:
1349: case sGssAuthentication:
1350: intptr = &options->gss_authentication;
1351: goto parse_flag;
1352:
1353: case sGssCleanupCreds:
1354: intptr = &options->gss_cleanup_creds;
1.271 djm 1355: goto parse_flag;
1356:
1357: case sGssStrictAcceptor:
1358: intptr = &options->gss_strict_acceptor;
1.94 markus 1359: goto parse_flag;
1360:
1361: case sPasswordAuthentication:
1362: intptr = &options->password_authentication;
1363: goto parse_flag;
1364:
1365: case sKbdInteractiveAuthentication:
1366: intptr = &options->kbd_interactive_authentication;
1367: goto parse_flag;
1368:
1369: case sChallengeResponseAuthentication:
1370: intptr = &options->challenge_response_authentication;
1371: goto parse_flag;
1372:
1373: case sPrintMotd:
1374: intptr = &options->print_motd;
1375: goto parse_flag;
1376:
1377: case sPrintLastLog:
1378: intptr = &options->print_lastlog;
1379: goto parse_flag;
1380:
1381: case sX11Forwarding:
1382: intptr = &options->x11_forwarding;
1383: goto parse_flag;
1384:
1385: case sX11DisplayOffset:
1386: intptr = &options->x11_display_offset;
1.293 naddy 1387: parse_int:
1388: arg = strdelim(&cp);
1389: if (!arg || *arg == '\0')
1390: fatal("%s line %d: missing integer value.",
1391: filename, linenum);
1392: value = atoi(arg);
1393: if (*activep && *intptr == -1)
1394: *intptr = value;
1395: break;
1.99 stevesk 1396:
1397: case sX11UseLocalhost:
1398: intptr = &options->x11_use_localhost;
1399: goto parse_flag;
1.94 markus 1400:
1401: case sXAuthLocation:
1402: charptr = &options->xauth_location;
1403: goto parse_filename;
1404:
1.244 djm 1405: case sPermitTTY:
1406: intptr = &options->permit_tty;
1407: goto parse_flag;
1408:
1.250 djm 1409: case sPermitUserRC:
1410: intptr = &options->permit_user_rc;
1411: goto parse_flag;
1412:
1.94 markus 1413: case sStrictModes:
1414: intptr = &options->strict_modes;
1415: goto parse_flag;
1416:
1.129 markus 1417: case sTCPKeepAlive:
1418: intptr = &options->tcp_keep_alive;
1.94 markus 1419: goto parse_flag;
1420:
1421: case sEmptyPasswd:
1422: intptr = &options->permit_empty_passwd;
1.113 markus 1423: goto parse_flag;
1424:
1425: case sPermitUserEnvironment:
1426: intptr = &options->permit_user_env;
1.94 markus 1427: goto parse_flag;
1428:
1.111 markus 1429: case sCompression:
1430: intptr = &options->compression;
1.220 djm 1431: multistate_ptr = multistate_compression;
1432: goto parse_multistate;
1.94 markus 1433:
1.235 dtucker 1434: case sRekeyLimit:
1435: arg = strdelim(&cp);
1436: if (!arg || *arg == '\0')
1437: fatal("%.200s line %d: Missing argument.", filename,
1438: linenum);
1439: if (strcmp(arg, "default") == 0) {
1440: val64 = 0;
1441: } else {
1.236 dtucker 1442: if (scan_scaled(arg, &val64) == -1)
1443: fatal("%.200s line %d: Bad number '%s': %s",
1444: filename, linenum, arg, strerror(errno));
1.235 dtucker 1445: if (val64 != 0 && val64 < 16)
1446: fatal("%.200s line %d: RekeyLimit too small",
1447: filename, linenum);
1448: }
1449: if (*activep && options->rekey_limit == -1)
1.284 dtucker 1450: options->rekey_limit = val64;
1.235 dtucker 1451: if (cp != NULL) { /* optional rekey interval present */
1452: if (strcmp(cp, "none") == 0) {
1453: (void)strdelim(&cp); /* discard */
1454: break;
1455: }
1456: intptr = &options->rekey_interval;
1457: goto parse_time;
1458: }
1459: break;
1460:
1.94 markus 1461: case sGatewayPorts:
1.251 millert 1462: intptr = &options->fwd_opts.gateway_ports;
1.220 djm 1463: multistate_ptr = multistate_gatewayports;
1464: goto parse_multistate;
1.25 markus 1465:
1.122 markus 1466: case sUseDNS:
1467: intptr = &options->use_dns;
1.94 markus 1468: goto parse_flag;
1.53 markus 1469:
1.94 markus 1470: case sLogFacility:
1.174 dtucker 1471: log_facility_ptr = &options->log_facility;
1.94 markus 1472: arg = strdelim(&cp);
1473: value = log_facility_number(arg);
1.101 markus 1474: if (value == SYSLOG_FACILITY_NOT_SET)
1.94 markus 1475: fatal("%.200s line %d: unsupported log facility '%s'",
1476: filename, linenum, arg ? arg : "<NONE>");
1.174 dtucker 1477: if (*log_facility_ptr == -1)
1478: *log_facility_ptr = (SyslogFacility) value;
1.94 markus 1479: break;
1.25 markus 1480:
1.94 markus 1481: case sLogLevel:
1.174 dtucker 1482: log_level_ptr = &options->log_level;
1.94 markus 1483: arg = strdelim(&cp);
1484: value = log_level_number(arg);
1.101 markus 1485: if (value == SYSLOG_LEVEL_NOT_SET)
1.94 markus 1486: fatal("%.200s line %d: unsupported log level '%s'",
1487: filename, linenum, arg ? arg : "<NONE>");
1.308 djm 1488: if (*activep && *log_level_ptr == -1)
1.174 dtucker 1489: *log_level_ptr = (LogLevel) value;
1.94 markus 1490: break;
1491:
1492: case sAllowTcpForwarding:
1493: intptr = &options->allow_tcp_forwarding;
1.233 djm 1494: multistate_ptr = multistate_tcpfwd;
1495: goto parse_multistate;
1.102 provos 1496:
1.251 millert 1497: case sAllowStreamLocalForwarding:
1498: intptr = &options->allow_streamlocal_forwarding;
1499: multistate_ptr = multistate_tcpfwd;
1500: goto parse_multistate;
1501:
1.178 pyr 1502: case sAllowAgentForwarding:
1503: intptr = &options->allow_agent_forwarding;
1504: goto parse_flag;
1505:
1.301 djm 1506: case sDisableForwarding:
1507: intptr = &options->disable_forwarding;
1508: goto parse_flag;
1509:
1.94 markus 1510: case sAllowUsers:
1511: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.299 djm 1512: if (match_user(NULL, NULL, NULL, arg) == -1)
1513: fatal("%s line %d: invalid AllowUsers pattern: "
1514: "\"%.100s\"", filename, linenum, arg);
1.227 markus 1515: if (!*activep)
1516: continue;
1.314 djm 1517: array_append(filename, linenum, "AllowUsers",
1518: &options->allow_users, &options->num_allow_users,
1519: arg);
1.94 markus 1520: }
1521: break;
1.25 markus 1522:
1.94 markus 1523: case sDenyUsers:
1524: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.299 djm 1525: if (match_user(NULL, NULL, NULL, arg) == -1)
1526: fatal("%s line %d: invalid DenyUsers pattern: "
1527: "\"%.100s\"", filename, linenum, arg);
1.227 markus 1528: if (!*activep)
1529: continue;
1.314 djm 1530: array_append(filename, linenum, "DenyUsers",
1531: &options->deny_users, &options->num_deny_users,
1532: arg);
1.94 markus 1533: }
1534: break;
1.25 markus 1535:
1.94 markus 1536: case sAllowGroups:
1537: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.227 markus 1538: if (!*activep)
1539: continue;
1.314 djm 1540: array_append(filename, linenum, "AllowGroups",
1541: &options->allow_groups, &options->num_allow_groups,
1542: arg);
1.94 markus 1543: }
1544: break;
1.33 markus 1545:
1.94 markus 1546: case sDenyGroups:
1547: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.227 markus 1548: if (!*activep)
1549: continue;
1.314 djm 1550: array_append(filename, linenum, "DenyGroups",
1551: &options->deny_groups, &options->num_deny_groups,
1552: arg);
1.94 markus 1553: }
1554: break;
1.66 markus 1555:
1.94 markus 1556: case sCiphers:
1557: arg = strdelim(&cp);
1558: if (!arg || *arg == '\0')
1559: fatal("%s line %d: Missing argument.", filename, linenum);
1.304 djm 1560: if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
1.94 markus 1561: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1562: filename, linenum, arg ? arg : "<NONE>");
1563: if (options->ciphers == NULL)
1564: options->ciphers = xstrdup(arg);
1565: break;
1.33 markus 1566:
1.94 markus 1567: case sMacs:
1568: arg = strdelim(&cp);
1569: if (!arg || *arg == '\0')
1570: fatal("%s line %d: Missing argument.", filename, linenum);
1.304 djm 1571: if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
1.94 markus 1572: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1573: filename, linenum, arg ? arg : "<NONE>");
1574: if (options->macs == NULL)
1575: options->macs = xstrdup(arg);
1.211 djm 1576: break;
1577:
1578: case sKexAlgorithms:
1579: arg = strdelim(&cp);
1580: if (!arg || *arg == '\0')
1581: fatal("%s line %d: Missing argument.",
1582: filename, linenum);
1.304 djm 1583: if (*arg != '-' &&
1584: !kex_names_valid(*arg == '+' ? arg + 1 : arg))
1.211 djm 1585: fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1586: filename, linenum, arg ? arg : "<NONE>");
1587: if (options->kex_algorithms == NULL)
1588: options->kex_algorithms = xstrdup(arg);
1.94 markus 1589: break;
1.43 jakob 1590:
1.94 markus 1591: case sSubsystem:
1592: if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1593: fatal("%s line %d: too many subsystems defined.",
1.95 deraadt 1594: filename, linenum);
1.94 markus 1595: }
1596: arg = strdelim(&cp);
1597: if (!arg || *arg == '\0')
1598: fatal("%s line %d: Missing subsystem name.",
1.95 deraadt 1599: filename, linenum);
1.153 dtucker 1600: if (!*activep) {
1601: arg = strdelim(&cp);
1602: break;
1603: }
1.94 markus 1604: for (i = 0; i < options->num_subsystems; i++)
1605: if (strcmp(arg, options->subsystem_name[i]) == 0)
1606: fatal("%s line %d: Subsystem '%s' already defined.",
1.95 deraadt 1607: filename, linenum, arg);
1.94 markus 1608: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1609: arg = strdelim(&cp);
1610: if (!arg || *arg == '\0')
1611: fatal("%s line %d: Missing subsystem command.",
1.95 deraadt 1612: filename, linenum);
1.94 markus 1613: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151 djm 1614:
1615: /* Collect arguments (separate to executable) */
1616: p = xstrdup(arg);
1617: len = strlen(p) + 1;
1618: while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1619: len += 1 + strlen(arg);
1.264 deraadt 1620: p = xreallocarray(p, 1, len);
1.151 djm 1621: strlcat(p, " ", len);
1622: strlcat(p, arg, len);
1623: }
1624: options->subsystem_args[options->num_subsystems] = p;
1.94 markus 1625: options->num_subsystems++;
1626: break;
1.46 markus 1627:
1.94 markus 1628: case sMaxStartups:
1629: arg = strdelim(&cp);
1630: if (!arg || *arg == '\0')
1631: fatal("%s line %d: Missing MaxStartups spec.",
1.95 deraadt 1632: filename, linenum);
1.94 markus 1633: if ((n = sscanf(arg, "%d:%d:%d",
1634: &options->max_startups_begin,
1635: &options->max_startups_rate,
1636: &options->max_startups)) == 3) {
1637: if (options->max_startups_begin >
1638: options->max_startups ||
1639: options->max_startups_rate > 100 ||
1640: options->max_startups_rate < 1)
1.50 markus 1641: fatal("%s line %d: Illegal MaxStartups spec.",
1.87 stevesk 1642: filename, linenum);
1.94 markus 1643: } else if (n != 1)
1644: fatal("%s line %d: Illegal MaxStartups spec.",
1645: filename, linenum);
1646: else
1647: options->max_startups = options->max_startups_begin;
1648: break;
1.133 dtucker 1649:
1650: case sMaxAuthTries:
1651: intptr = &options->max_authtries;
1652: goto parse_int;
1.94 markus 1653:
1.180 djm 1654: case sMaxSessions:
1655: intptr = &options->max_sessions;
1656: goto parse_int;
1657:
1.94 markus 1658: case sBanner:
1659: charptr = &options->banner;
1660: goto parse_filename;
1.176 djm 1661:
1.94 markus 1662: /*
1663: * These options can contain %X options expanded at
1664: * connect time, so that you can specify paths like:
1665: *
1666: * AuthorizedKeysFile /etc/ssh_keys/%u
1667: */
1668: case sAuthorizedKeysFile:
1.219 djm 1669: if (*activep && options->num_authkeys_files == 0) {
1670: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.314 djm 1671: arg = tilde_expand_filename(arg, getuid());
1672: array_append(filename, linenum,
1673: "AuthorizedKeysFile",
1674: &options->authorized_keys_files,
1675: &options->num_authkeys_files, arg);
1676: free(arg);
1.219 djm 1677: }
1678: }
1679: return 0;
1680:
1.208 djm 1681: case sAuthorizedPrincipalsFile:
1682: charptr = &options->authorized_principals_file;
1.205 djm 1683: arg = strdelim(&cp);
1684: if (!arg || *arg == '\0')
1685: fatal("%s line %d: missing file name.",
1686: filename, linenum);
1687: if (*activep && *charptr == NULL) {
1.206 markus 1688: *charptr = tilde_expand_filename(arg, getuid());
1.205 djm 1689: /* increase optional counter */
1690: if (intptr != NULL)
1691: *intptr = *intptr + 1;
1692: }
1693: break;
1.94 markus 1694:
1695: case sClientAliveInterval:
1696: intptr = &options->client_alive_interval;
1697: goto parse_time;
1698:
1699: case sClientAliveCountMax:
1700: intptr = &options->client_alive_count_max;
1701: goto parse_int;
1.131 djm 1702:
1703: case sAcceptEnv:
1704: while ((arg = strdelim(&cp)) && *arg != '\0') {
1705: if (strchr(arg, '=') != NULL)
1706: fatal("%s line %d: Invalid environment name.",
1707: filename, linenum);
1.153 dtucker 1708: if (!*activep)
1.227 markus 1709: continue;
1.314 djm 1710: array_append(filename, linenum, "AcceptEnv",
1711: &options->accept_env, &options->num_accept_env,
1712: arg);
1.131 djm 1713: }
1714: break;
1.145 reyk 1715:
1716: case sPermitTunnel:
1717: intptr = &options->permit_tun;
1.146 reyk 1718: arg = strdelim(&cp);
1719: if (!arg || *arg == '\0')
1720: fatal("%s line %d: Missing yes/point-to-point/"
1721: "ethernet/no argument.", filename, linenum);
1.182 dtucker 1722: value = -1;
1723: for (i = 0; tunmode_desc[i].val != -1; i++)
1724: if (strcmp(tunmode_desc[i].text, arg) == 0) {
1725: value = tunmode_desc[i].val;
1726: break;
1727: }
1728: if (value == -1)
1.146 reyk 1729: fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1730: "no argument: %s", filename, linenum, arg);
1.268 djm 1731: if (*activep && *intptr == -1)
1.146 reyk 1732: *intptr = value;
1733: break;
1.94 markus 1734:
1.153 dtucker 1735: case sMatch:
1736: if (cmdline)
1737: fatal("Match directive not supported as a command-line "
1738: "option");
1.226 dtucker 1739: value = match_cfg_line(&cp, linenum, connectinfo);
1.153 dtucker 1740: if (value < 0)
1741: fatal("%s line %d: Bad Match condition", filename,
1742: linenum);
1743: *activep = value;
1.156 dtucker 1744: break;
1745:
1746: case sPermitOpen:
1747: arg = strdelim(&cp);
1748: if (!arg || *arg == '\0')
1749: fatal("%s line %d: missing PermitOpen specification",
1750: filename, linenum);
1.313 djm 1751: value = options->num_permitted_opens; /* modified later */
1.310 djm 1752: if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
1.313 djm 1753: if (*activep && value == 0) {
1.224 dtucker 1754: options->num_permitted_opens = 1;
1.310 djm 1755: options->permitted_opens = xcalloc(1,
1756: sizeof(*options->permitted_opens));
1757: options->permitted_opens[0] = xstrdup(arg);
1.311 dtucker 1758: }
1.156 dtucker 1759: break;
1760: }
1.159 dtucker 1761: for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1.310 djm 1762: arg2 = xstrdup(arg);
1.159 dtucker 1763: p = hpdelim(&arg);
1764: if (p == NULL)
1765: fatal("%s line %d: missing host in PermitOpen",
1766: filename, linenum);
1767: p = cleanhostname(p);
1.223 dtucker 1768: if (arg == NULL || ((port = permitopen_port(arg)) < 0))
1.159 dtucker 1769: fatal("%s line %d: bad port number in "
1770: "PermitOpen", filename, linenum);
1.313 djm 1771: if (*activep && value == 0) {
1.314 djm 1772: array_append(filename, linenum,
1773: "PermitOpen",
1774: &options->permitted_opens,
1775: &options->num_permitted_opens, arg2);
1776: }
1777: free(arg2);
1.159 dtucker 1778: }
1.153 dtucker 1779: break;
1780:
1.158 dtucker 1781: case sForceCommand:
1.262 dtucker 1782: if (cp == NULL || *cp == '\0')
1.158 dtucker 1783: fatal("%.200s line %d: Missing argument.", filename,
1784: linenum);
1785: len = strspn(cp, WHITESPACE);
1786: if (*activep && options->adm_forced_command == NULL)
1787: options->adm_forced_command = xstrdup(cp + len);
1788: return 0;
1789:
1.176 djm 1790: case sChrootDirectory:
1791: charptr = &options->chroot_directory;
1.177 djm 1792:
1793: arg = strdelim(&cp);
1794: if (!arg || *arg == '\0')
1795: fatal("%s line %d: missing file name.",
1796: filename, linenum);
1797: if (*activep && *charptr == NULL)
1798: *charptr = xstrdup(arg);
1799: break;
1.176 djm 1800:
1.204 djm 1801: case sTrustedUserCAKeys:
1802: charptr = &options->trusted_user_ca_keys;
1803: goto parse_filename;
1804:
1805: case sRevokedKeys:
1806: charptr = &options->revoked_keys_file;
1807: goto parse_filename;
1808:
1.213 djm 1809: case sIPQoS:
1810: arg = strdelim(&cp);
1811: if ((value = parse_ipqos(arg)) == -1)
1812: fatal("%s line %d: Bad IPQoS value: %s",
1813: filename, linenum, arg);
1814: arg = strdelim(&cp);
1815: if (arg == NULL)
1816: value2 = value;
1817: else if ((value2 = parse_ipqos(arg)) == -1)
1818: fatal("%s line %d: Bad IPQoS value: %s",
1819: filename, linenum, arg);
1820: if (*activep) {
1821: options->ip_qos_interactive = value;
1822: options->ip_qos_bulk = value2;
1823: }
1824: break;
1825:
1.225 djm 1826: case sVersionAddendum:
1.262 dtucker 1827: if (cp == NULL || *cp == '\0')
1.225 djm 1828: fatal("%.200s line %d: Missing argument.", filename,
1829: linenum);
1830: len = strspn(cp, WHITESPACE);
1831: if (*activep && options->version_addendum == NULL) {
1832: if (strcasecmp(cp + len, "none") == 0)
1833: options->version_addendum = xstrdup("");
1834: else if (strchr(cp + len, '\r') != NULL)
1835: fatal("%.200s line %d: Invalid argument",
1836: filename, linenum);
1837: else
1838: options->version_addendum = xstrdup(cp + len);
1839: }
1840: return 0;
1841:
1.231 djm 1842: case sAuthorizedKeysCommand:
1.255 jsg 1843: if (cp == NULL)
1844: fatal("%.200s line %d: Missing argument.", filename,
1845: linenum);
1.231 djm 1846: len = strspn(cp, WHITESPACE);
1847: if (*activep && options->authorized_keys_command == NULL) {
1848: if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1849: fatal("%.200s line %d: AuthorizedKeysCommand "
1850: "must be an absolute path",
1851: filename, linenum);
1852: options->authorized_keys_command = xstrdup(cp + len);
1853: }
1854: return 0;
1855:
1856: case sAuthorizedKeysCommandUser:
1857: charptr = &options->authorized_keys_command_user;
1858:
1859: arg = strdelim(&cp);
1.255 jsg 1860: if (!arg || *arg == '\0')
1861: fatal("%s line %d: missing AuthorizedKeysCommandUser "
1862: "argument.", filename, linenum);
1.231 djm 1863: if (*activep && *charptr == NULL)
1864: *charptr = xstrdup(arg);
1865: break;
1866:
1.270 djm 1867: case sAuthorizedPrincipalsCommand:
1868: if (cp == NULL)
1869: fatal("%.200s line %d: Missing argument.", filename,
1870: linenum);
1871: len = strspn(cp, WHITESPACE);
1872: if (*activep &&
1873: options->authorized_principals_command == NULL) {
1874: if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1875: fatal("%.200s line %d: "
1876: "AuthorizedPrincipalsCommand must be "
1877: "an absolute path", filename, linenum);
1878: options->authorized_principals_command =
1879: xstrdup(cp + len);
1880: }
1881: return 0;
1882:
1883: case sAuthorizedPrincipalsCommandUser:
1884: charptr = &options->authorized_principals_command_user;
1885:
1886: arg = strdelim(&cp);
1887: if (!arg || *arg == '\0')
1888: fatal("%s line %d: missing "
1889: "AuthorizedPrincipalsCommandUser argument.",
1890: filename, linenum);
1891: if (*activep && *charptr == NULL)
1892: *charptr = xstrdup(arg);
1893: break;
1894:
1.232 djm 1895: case sAuthenticationMethods:
1.268 djm 1896: if (options->num_auth_methods == 0) {
1.291 djm 1897: value = 0; /* seen "any" pseudo-method */
1.292 djm 1898: value2 = 0; /* sucessfully parsed any method */
1.232 djm 1899: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.291 djm 1900: if (strcmp(arg, "any") == 0) {
1901: if (options->num_auth_methods > 0) {
1902: fatal("%s line %d: \"any\" "
1903: "must appear alone in "
1904: "AuthenticationMethods",
1905: filename, linenum);
1906: }
1907: value = 1;
1908: } else if (value) {
1909: fatal("%s line %d: \"any\" must appear "
1910: "alone in AuthenticationMethods",
1911: filename, linenum);
1912: } else if (auth2_methods_valid(arg, 0) != 0) {
1.232 djm 1913: fatal("%s line %d: invalid "
1914: "authentication method list.",
1915: filename, linenum);
1.291 djm 1916: }
1.292 djm 1917: value2 = 1;
1.268 djm 1918: if (!*activep)
1919: continue;
1.314 djm 1920: array_append(filename, linenum,
1921: "AuthenticationMethods",
1922: &options->auth_methods,
1923: &options->num_auth_methods, arg);
1.232 djm 1924: }
1.292 djm 1925: if (value2 == 0) {
1.291 djm 1926: fatal("%s line %d: no AuthenticationMethods "
1927: "specified", filename, linenum);
1928: }
1.232 djm 1929: }
1930: return 0;
1931:
1.251 millert 1932: case sStreamLocalBindMask:
1933: arg = strdelim(&cp);
1934: if (!arg || *arg == '\0')
1.268 djm 1935: fatal("%s line %d: missing StreamLocalBindMask "
1936: "argument.", filename, linenum);
1.251 millert 1937: /* Parse mode in octal format */
1938: value = strtol(arg, &p, 8);
1939: if (arg == p || value < 0 || value > 0777)
1940: fatal("%s line %d: Bad mask.", filename, linenum);
1.268 djm 1941: if (*activep)
1942: options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1.251 millert 1943: break;
1944:
1945: case sStreamLocalBindUnlink:
1946: intptr = &options->fwd_opts.streamlocal_bind_unlink;
1947: goto parse_flag;
1948:
1.256 djm 1949: case sFingerprintHash:
1950: arg = strdelim(&cp);
1951: if (!arg || *arg == '\0')
1952: fatal("%.200s line %d: Missing argument.",
1953: filename, linenum);
1954: if ((value = ssh_digest_alg_by_name(arg)) == -1)
1955: fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1956: filename, linenum, arg);
1957: if (*activep)
1958: options->fingerprint_hash = value;
1959: break;
1960:
1.309 djm 1961: case sExposeAuthInfo:
1962: intptr = &options->expose_userauth_info;
1963: goto parse_flag;
1964:
1.316 djm 1965: case sRDomain:
1966: charptr = &options->routing_domain;
1967: arg = strdelim(&cp);
1968: if (!arg || *arg == '\0')
1969: fatal("%.200s line %d: Missing argument.",
1970: filename, linenum);
1971: if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
1972: !valid_rdomain(arg))
1973: fatal("%s line %d: bad routing domain",
1974: filename, linenum);
1975: if (*activep && *charptr == NULL)
1976: *charptr = xstrdup(arg);
1977:
1.94 markus 1978: case sDeprecated:
1.295 djm 1979: case sIgnore:
1.121 jakob 1980: case sUnsupported:
1.295 djm 1981: do_log2(opcode == sIgnore ?
1982: SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1983: "%s line %d: %s option %s", filename, linenum,
1984: opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
1.94 markus 1985: while (arg)
1986: arg = strdelim(&cp);
1987: break;
1988:
1989: default:
1990: fatal("%s line %d: Missing handler for opcode %s (%d)",
1991: filename, linenum, arg, opcode);
1992: }
1993: if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1994: fatal("%s line %d: garbage at end of line; \"%.200s\".",
1995: filename, linenum, arg);
1996: return 0;
1997: }
1998:
1999: /* Reads the server configuration file. */
1.25 markus 2000:
1.94 markus 2001: void
1.134 djm 2002: load_server_config(const char *filename, Buffer *conf)
1.94 markus 2003: {
1.229 dtucker 2004: char line[4096], *cp;
1.94 markus 2005: FILE *f;
1.229 dtucker 2006: int lineno = 0;
1.81 stevesk 2007:
1.134 djm 2008: debug2("%s: filename %s", __func__, filename);
2009: if ((f = fopen(filename, "r")) == NULL) {
1.94 markus 2010: perror(filename);
2011: exit(1);
2012: }
1.134 djm 2013: buffer_clear(conf);
2014: while (fgets(line, sizeof(line), f)) {
1.229 dtucker 2015: lineno++;
2016: if (strlen(line) == sizeof(line) - 1)
2017: fatal("%s line %d too long", filename, lineno);
1.134 djm 2018: /*
2019: * Trim out comments and strip whitespace
1.135 deraadt 2020: * NB - preserve newlines, they are needed to reproduce
1.134 djm 2021: * line numbers later for error messages
2022: */
2023: if ((cp = strchr(line, '#')) != NULL)
2024: memcpy(cp, "\n", 2);
2025: cp = line + strspn(line, " \t\r");
2026:
2027: buffer_append(conf, cp, strlen(cp));
2028: }
2029: buffer_append(conf, "\0", 1);
2030: fclose(f);
2031: debug2("%s: done config len = %d", __func__, buffer_len(conf));
2032: }
2033:
2034: void
1.226 dtucker 2035: parse_server_match_config(ServerOptions *options,
2036: struct connection_info *connectinfo)
1.153 dtucker 2037: {
2038: ServerOptions mo;
2039:
2040: initialize_server_options(&mo);
1.226 dtucker 2041: parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
1.168 dtucker 2042: copy_set_server_options(options, &mo, 0);
1.153 dtucker 2043: }
2044:
1.226 dtucker 2045: int parse_server_match_testspec(struct connection_info *ci, char *spec)
2046: {
2047: char *p;
2048:
2049: while ((p = strsep(&spec, ",")) && *p != '\0') {
2050: if (strncmp(p, "addr=", 5) == 0) {
2051: ci->address = xstrdup(p + 5);
2052: } else if (strncmp(p, "host=", 5) == 0) {
2053: ci->host = xstrdup(p + 5);
2054: } else if (strncmp(p, "user=", 5) == 0) {
2055: ci->user = xstrdup(p + 5);
2056: } else if (strncmp(p, "laddr=", 6) == 0) {
2057: ci->laddress = xstrdup(p + 6);
1.317 djm 2058: } else if (strncmp(p, "rdomain=", 8) == 0) {
2059: ci->rdomain = xstrdup(p + 8);
1.226 dtucker 2060: } else if (strncmp(p, "lport=", 6) == 0) {
2061: ci->lport = a2port(p + 6);
2062: if (ci->lport == -1) {
2063: fprintf(stderr, "Invalid port '%s' in test mode"
2064: " specification %s\n", p+6, p);
2065: return -1;
2066: }
2067: } else {
2068: fprintf(stderr, "Invalid test mode specification %s\n",
2069: p);
2070: return -1;
2071: }
2072: }
2073: return 0;
2074: }
2075:
1.168 dtucker 2076: /*
2077: * Copy any supported values that are set.
2078: *
1.195 jj 2079: * If the preauth flag is set, we do not bother copying the string or
1.168 dtucker 2080: * array values that are not used pre-authentication, because any that we
2081: * do use must be explictly sent in mm_getpwnamallow().
2082: */
1.153 dtucker 2083: void
1.168 dtucker 2084: copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1.153 dtucker 2085: {
1.247 djm 2086: #define M_CP_INTOPT(n) do {\
2087: if (src->n != -1) \
2088: dst->n = src->n; \
2089: } while (0)
2090:
1.168 dtucker 2091: M_CP_INTOPT(password_authentication);
2092: M_CP_INTOPT(gss_authentication);
2093: M_CP_INTOPT(pubkey_authentication);
2094: M_CP_INTOPT(kerberos_authentication);
2095: M_CP_INTOPT(hostbased_authentication);
1.209 djm 2096: M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1.168 dtucker 2097: M_CP_INTOPT(kbd_interactive_authentication);
1.175 dtucker 2098: M_CP_INTOPT(permit_root_login);
1.188 djm 2099: M_CP_INTOPT(permit_empty_passwd);
1.168 dtucker 2100:
2101: M_CP_INTOPT(allow_tcp_forwarding);
1.251 millert 2102: M_CP_INTOPT(allow_streamlocal_forwarding);
1.178 pyr 2103: M_CP_INTOPT(allow_agent_forwarding);
1.301 djm 2104: M_CP_INTOPT(disable_forwarding);
1.309 djm 2105: M_CP_INTOPT(expose_userauth_info);
1.209 djm 2106: M_CP_INTOPT(permit_tun);
1.251 millert 2107: M_CP_INTOPT(fwd_opts.gateway_ports);
1.289 djm 2108: M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
1.168 dtucker 2109: M_CP_INTOPT(x11_display_offset);
2110: M_CP_INTOPT(x11_forwarding);
2111: M_CP_INTOPT(x11_use_localhost);
1.244 djm 2112: M_CP_INTOPT(permit_tty);
1.250 djm 2113: M_CP_INTOPT(permit_user_rc);
1.180 djm 2114: M_CP_INTOPT(max_sessions);
1.184 dtucker 2115: M_CP_INTOPT(max_authtries);
1.300 markus 2116: M_CP_INTOPT(client_alive_count_max);
2117: M_CP_INTOPT(client_alive_interval);
1.213 djm 2118: M_CP_INTOPT(ip_qos_interactive);
2119: M_CP_INTOPT(ip_qos_bulk);
1.235 dtucker 2120: M_CP_INTOPT(rekey_limit);
2121: M_CP_INTOPT(rekey_interval);
1.308 djm 2122: M_CP_INTOPT(log_level);
1.289 djm 2123:
2124: /*
2125: * The bind_mask is a mode_t that may be unsigned, so we can't use
2126: * M_CP_INTOPT - it does a signed comparison that causes compiler
2127: * warnings.
2128: */
1.290 dtucker 2129: if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
1.289 djm 2130: dst->fwd_opts.streamlocal_bind_mask =
2131: src->fwd_opts.streamlocal_bind_mask;
2132: }
1.247 djm 2133:
2134: /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2135: #define M_CP_STROPT(n) do {\
2136: if (src->n != NULL && dst->n != src->n) { \
2137: free(dst->n); \
2138: dst->n = src->n; \
2139: } \
2140: } while(0)
1.314 djm 2141: #define M_CP_STRARRAYOPT(s, num_s) do {\
2142: u_int i; \
2143: if (src->num_s != 0) { \
2144: for (i = 0; i < dst->num_s; i++) \
2145: free(dst->s[i]); \
2146: free(dst->s); \
2147: dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2148: for (i = 0; i < src->num_s; i++) \
2149: dst->s[i] = xstrdup(src->s[i]); \
2150: dst->num_s = src->num_s; \
1.312 djm 2151: } \
2152: } while(0)
1.168 dtucker 2153:
1.218 djm 2154: /* See comment in servconf.h */
2155: COPY_MATCH_STRING_OPTS();
1.282 djm 2156:
2157: /* Arguments that accept '+...' need to be expanded */
2158: assemble_algorithms(dst);
1.216 djm 2159:
1.217 dtucker 2160: /*
2161: * The only things that should be below this point are string options
2162: * which are only used after authentication.
2163: */
1.168 dtucker 2164: if (preauth)
2165: return;
1.219 djm 2166:
1.283 djm 2167: /* These options may be "none" to clear a global setting */
1.168 dtucker 2168: M_CP_STROPT(adm_forced_command);
1.283 djm 2169: if (option_clear_or_none(dst->adm_forced_command)) {
2170: free(dst->adm_forced_command);
2171: dst->adm_forced_command = NULL;
2172: }
1.176 djm 2173: M_CP_STROPT(chroot_directory);
1.283 djm 2174: if (option_clear_or_none(dst->chroot_directory)) {
2175: free(dst->chroot_directory);
2176: dst->chroot_directory = NULL;
2177: }
1.153 dtucker 2178: }
1.168 dtucker 2179:
2180: #undef M_CP_INTOPT
2181: #undef M_CP_STROPT
1.219 djm 2182: #undef M_CP_STRARRAYOPT
1.153 dtucker 2183:
2184: void
2185: parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1.226 dtucker 2186: struct connection_info *connectinfo)
1.134 djm 2187: {
1.153 dtucker 2188: int active, linenum, bad_options = 0;
1.136 dtucker 2189: char *cp, *obuf, *cbuf;
1.134 djm 2190:
2191: debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2192:
1.287 djm 2193: if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2194: fatal("%s: sshbuf_dup_string failed", __func__);
1.226 dtucker 2195: active = connectinfo ? 0 : 1;
1.137 dtucker 2196: linenum = 1;
1.140 deraadt 2197: while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134 djm 2198: if (process_server_config_line(options, cp, filename,
1.226 dtucker 2199: linenum++, &active, connectinfo) != 0)
1.94 markus 2200: bad_options++;
1.1 deraadt 2201: }
1.239 djm 2202: free(obuf);
1.78 stevesk 2203: if (bad_options > 0)
2204: fatal("%s: terminating, %d bad configuration options",
2205: filename, bad_options);
1.266 dtucker 2206: process_queued_listen_addrs(options);
1.182 dtucker 2207: }
2208:
2209: static const char *
1.221 djm 2210: fmt_multistate_int(int val, const struct multistate *m)
2211: {
2212: u_int i;
2213:
2214: for (i = 0; m[i].key != NULL; i++) {
2215: if (m[i].value == val)
2216: return m[i].key;
2217: }
2218: return "UNKNOWN";
2219: }
2220:
2221: static const char *
1.182 dtucker 2222: fmt_intarg(ServerOpCodes code, int val)
2223: {
1.221 djm 2224: if (val == -1)
2225: return "unset";
2226: switch (code) {
2227: case sAddressFamily:
2228: return fmt_multistate_int(val, multistate_addressfamily);
2229: case sPermitRootLogin:
2230: return fmt_multistate_int(val, multistate_permitrootlogin);
2231: case sGatewayPorts:
2232: return fmt_multistate_int(val, multistate_gatewayports);
2233: case sCompression:
2234: return fmt_multistate_int(val, multistate_compression);
1.233 djm 2235: case sAllowTcpForwarding:
2236: return fmt_multistate_int(val, multistate_tcpfwd);
1.251 millert 2237: case sAllowStreamLocalForwarding:
2238: return fmt_multistate_int(val, multistate_tcpfwd);
1.256 djm 2239: case sFingerprintHash:
2240: return ssh_digest_alg_name(val);
1.221 djm 2241: default:
2242: switch (val) {
2243: case 0:
2244: return "no";
2245: case 1:
2246: return "yes";
2247: default:
2248: return "UNKNOWN";
2249: }
1.182 dtucker 2250: }
2251: }
2252:
2253: static const char *
2254: lookup_opcode_name(ServerOpCodes code)
2255: {
2256: u_int i;
2257:
2258: for (i = 0; keywords[i].name != NULL; i++)
2259: if (keywords[i].opcode == code)
2260: return(keywords[i].name);
2261: return "UNKNOWN";
2262: }
2263:
2264: static void
2265: dump_cfg_int(ServerOpCodes code, int val)
2266: {
2267: printf("%s %d\n", lookup_opcode_name(code), val);
2268: }
2269:
2270: static void
1.263 dtucker 2271: dump_cfg_oct(ServerOpCodes code, int val)
2272: {
2273: printf("%s 0%o\n", lookup_opcode_name(code), val);
2274: }
2275:
2276: static void
1.182 dtucker 2277: dump_cfg_fmtint(ServerOpCodes code, int val)
2278: {
2279: printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2280: }
2281:
2282: static void
2283: dump_cfg_string(ServerOpCodes code, const char *val)
2284: {
1.257 djm 2285: printf("%s %s\n", lookup_opcode_name(code),
2286: val == NULL ? "none" : val);
1.182 dtucker 2287: }
2288:
2289: static void
2290: dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2291: {
2292: u_int i;
2293:
2294: for (i = 0; i < count; i++)
1.219 djm 2295: printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2296: }
2297:
2298: static void
2299: dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2300: {
2301: u_int i;
2302:
1.291 djm 2303: if (count <= 0 && code != sAuthenticationMethods)
1.261 dtucker 2304: return;
1.219 djm 2305: printf("%s", lookup_opcode_name(code));
2306: for (i = 0; i < count; i++)
2307: printf(" %s", vals[i]);
1.291 djm 2308: if (code == sAuthenticationMethods && count == 0)
2309: printf(" any");
1.219 djm 2310: printf("\n");
1.182 dtucker 2311: }
2312:
1.315 djm 2313: static char *
2314: format_listen_addrs(struct listenaddr *la)
1.182 dtucker 2315: {
1.315 djm 2316: int r;
1.182 dtucker 2317: struct addrinfo *ai;
1.315 djm 2318: char addr[NI_MAXHOST], port[NI_MAXSERV];
1.263 dtucker 2319: char *laddr1 = xstrdup(""), *laddr2 = NULL;
1.182 dtucker 2320:
1.263 dtucker 2321: /*
2322: * ListenAddress must be after Port. add_one_listen_addr pushes
2323: * addresses onto a stack, so to maintain ordering we need to
2324: * print these in reverse order.
2325: */
1.315 djm 2326: for (ai = la->addrs; ai; ai = ai->ai_next) {
2327: if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1.182 dtucker 2328: sizeof(addr), port, sizeof(port),
2329: NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1.315 djm 2330: error("getnameinfo: %.100s", ssh_gai_strerror(r));
2331: continue;
2332: }
2333: laddr2 = laddr1;
2334: if (ai->ai_family == AF_INET6) {
2335: xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2336: addr, port,
2337: la->rdomain == NULL ? "" : " rdomain ",
2338: la->rdomain == NULL ? "" : la->rdomain,
2339: laddr2);
1.182 dtucker 2340: } else {
1.315 djm 2341: xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2342: addr, port,
2343: la->rdomain == NULL ? "" : " rdomain ",
2344: la->rdomain == NULL ? "" : la->rdomain,
2345: laddr2);
1.182 dtucker 2346: }
1.315 djm 2347: free(laddr2);
2348: }
2349: return laddr1;
2350: }
2351:
2352: void
2353: dump_config(ServerOptions *o)
2354: {
2355: char *s;
2356: u_int i;
2357:
2358: /* these are usually at the top of the config */
2359: for (i = 0; i < o->num_ports; i++)
2360: printf("port %d\n", o->ports[i]);
2361: dump_cfg_fmtint(sAddressFamily, o->address_family);
2362:
2363: for (i = 0; i < o->num_listen_addrs; i++) {
2364: s = format_listen_addrs(&o->listen_addrs[i]);
2365: printf("%s", s);
2366: free(s);
1.182 dtucker 2367: }
2368:
2369: /* integer arguments */
2370: dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2371: dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2372: dump_cfg_int(sMaxAuthTries, o->max_authtries);
1.189 djm 2373: dump_cfg_int(sMaxSessions, o->max_sessions);
1.182 dtucker 2374: dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2375: dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1.263 dtucker 2376: dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
1.182 dtucker 2377:
2378: /* formatted integer arguments */
2379: dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2380: dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2381: dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2382: dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2383: dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2384: o->hostbased_uses_name_from_packet_only);
2385: dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
1.187 djm 2386: #ifdef KRB5
1.182 dtucker 2387: dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2388: dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2389: dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
2390: dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
1.187 djm 2391: #endif
2392: #ifdef GSSAPI
1.182 dtucker 2393: dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2394: dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
1.187 djm 2395: #endif
1.182 dtucker 2396: dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2397: dump_cfg_fmtint(sKbdInteractiveAuthentication,
2398: o->kbd_interactive_authentication);
2399: dump_cfg_fmtint(sChallengeResponseAuthentication,
2400: o->challenge_response_authentication);
2401: dump_cfg_fmtint(sPrintMotd, o->print_motd);
2402: dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2403: dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2404: dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1.244 djm 2405: dump_cfg_fmtint(sPermitTTY, o->permit_tty);
1.250 djm 2406: dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
1.182 dtucker 2407: dump_cfg_fmtint(sStrictModes, o->strict_modes);
2408: dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2409: dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2410: dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2411: dump_cfg_fmtint(sCompression, o->compression);
1.251 millert 2412: dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
1.182 dtucker 2413: dump_cfg_fmtint(sUseDNS, o->use_dns);
2414: dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1.261 dtucker 2415: dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
1.301 djm 2416: dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
1.251 millert 2417: dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
1.288 djm 2418: dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
1.256 djm 2419: dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
1.309 djm 2420: dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
1.182 dtucker 2421:
2422: /* string arguments */
2423: dump_cfg_string(sPidFile, o->pid_file);
2424: dump_cfg_string(sXAuthLocation, o->xauth_location);
1.252 djm 2425: dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2426: dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
1.182 dtucker 2427: dump_cfg_string(sBanner, o->banner);
2428: dump_cfg_string(sForceCommand, o->adm_forced_command);
1.201 dtucker 2429: dump_cfg_string(sChrootDirectory, o->chroot_directory);
1.204 djm 2430: dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2431: dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
1.208 djm 2432: dump_cfg_string(sAuthorizedPrincipalsFile,
2433: o->authorized_principals_file);
1.261 dtucker 2434: dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2435: ? "none" : o->version_addendum);
1.231 djm 2436: dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2437: dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
1.270 djm 2438: dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2439: dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
1.240 markus 2440: dump_cfg_string(sHostKeyAgent, o->host_key_agent);
1.252 djm 2441: dump_cfg_string(sKexAlgorithms,
1.253 djm 2442: o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
1.258 djm 2443: dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2444: o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
1.276 markus 2445: dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2446: o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
1.258 djm 2447: dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2448: o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
1.316 djm 2449: dump_cfg_string(sRDomain, o->routing_domain);
1.182 dtucker 2450:
2451: /* string arguments requiring a lookup */
2452: dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2453: dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2454:
2455: /* string array arguments */
1.219 djm 2456: dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2457: o->authorized_keys_files);
1.182 dtucker 2458: dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2459: o->host_key_files);
1.261 dtucker 2460: dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
1.203 djm 2461: o->host_cert_files);
1.182 dtucker 2462: dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2463: dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2464: dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2465: dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2466: dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1.232 djm 2467: dump_cfg_strarray_oneline(sAuthenticationMethods,
2468: o->num_auth_methods, o->auth_methods);
1.182 dtucker 2469:
2470: /* other arguments */
2471: for (i = 0; i < o->num_subsystems; i++)
2472: printf("subsystem %s %s\n", o->subsystem_name[i],
2473: o->subsystem_args[i]);
2474:
2475: printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2476: o->max_startups_rate, o->max_startups);
2477:
1.318 djm 2478: s = NULL;
2479: for (i = 0; tunmode_desc[i].val != -1; i++) {
1.182 dtucker 2480: if (tunmode_desc[i].val == o->permit_tun) {
2481: s = tunmode_desc[i].text;
2482: break;
2483: }
1.318 djm 2484: }
1.182 dtucker 2485: dump_cfg_string(sPermitTunnel, s);
1.213 djm 2486:
1.214 stevesk 2487: printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2488: printf("%s\n", iptos2str(o->ip_qos_bulk));
1.235 dtucker 2489:
1.284 dtucker 2490: printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
1.241 djm 2491: o->rekey_interval);
1.182 dtucker 2492:
1.310 djm 2493: printf("permitopen");
2494: if (o->num_permitted_opens == 0)
2495: printf(" any");
2496: else {
2497: for (i = 0; i < o->num_permitted_opens; i++)
2498: printf(" %s", o->permitted_opens[i]);
2499: }
2500: printf("\n");
1.1 deraadt 2501: }