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