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