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