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