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