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