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