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