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