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