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