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