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