Annotation of src/usr.bin/ssh/servconf.c, Revision 1.227
1.226 dtucker 1:
1.227 ! markus 2: /* $OpenBSD: servconf.c,v 1.226 2012/05/13 01:42:32 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.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.227 ! markus 384: { "allowusers", sAllowUsers, SSHCFG_ALL },
! 385: { "denyusers", sDenyUsers, SSHCFG_ALL },
! 386: { "allowgroups", sAllowGroups, SSHCFG_ALL },
! 387: { "denygroups", sDenyGroups, SSHCFG_ALL },
1.153 dtucker 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},
1.227 ! markus 405: { "acceptenv", sAcceptEnv, SSHCFG_ALL },
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.227 ! markus 1106: if (!*activep)
! 1107: continue;
1.112 deraadt 1108: options->allow_users[options->num_allow_users++] =
1109: xstrdup(arg);
1.94 markus 1110: }
1111: break;
1.25 markus 1112:
1.94 markus 1113: case sDenyUsers:
1114: while ((arg = strdelim(&cp)) && *arg != '\0') {
1115: if (options->num_deny_users >= MAX_DENY_USERS)
1.163 stevesk 1116: fatal("%s line %d: too many deny users.",
1.94 markus 1117: filename, linenum);
1.227 ! markus 1118: if (!*activep)
! 1119: continue;
1.112 deraadt 1120: options->deny_users[options->num_deny_users++] =
1121: xstrdup(arg);
1.94 markus 1122: }
1123: break;
1.25 markus 1124:
1.94 markus 1125: case sAllowGroups:
1126: while ((arg = strdelim(&cp)) && *arg != '\0') {
1127: if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1128: fatal("%s line %d: too many allow groups.",
1129: filename, linenum);
1.227 ! markus 1130: if (!*activep)
! 1131: continue;
1.112 deraadt 1132: options->allow_groups[options->num_allow_groups++] =
1133: xstrdup(arg);
1.94 markus 1134: }
1135: break;
1.33 markus 1136:
1.94 markus 1137: case sDenyGroups:
1138: while ((arg = strdelim(&cp)) && *arg != '\0') {
1139: if (options->num_deny_groups >= MAX_DENY_GROUPS)
1140: fatal("%s line %d: too many deny groups.",
1141: filename, linenum);
1.227 ! markus 1142: if (!*activep)
! 1143: continue;
! 1144: options->deny_groups[options->num_deny_groups++] =
! 1145: xstrdup(arg);
1.94 markus 1146: }
1147: break;
1.66 markus 1148:
1.94 markus 1149: case sCiphers:
1150: arg = strdelim(&cp);
1151: if (!arg || *arg == '\0')
1152: fatal("%s line %d: Missing argument.", filename, linenum);
1153: if (!ciphers_valid(arg))
1154: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1155: filename, linenum, arg ? arg : "<NONE>");
1156: if (options->ciphers == NULL)
1157: options->ciphers = xstrdup(arg);
1158: break;
1.33 markus 1159:
1.94 markus 1160: case sMacs:
1161: arg = strdelim(&cp);
1162: if (!arg || *arg == '\0')
1163: fatal("%s line %d: Missing argument.", filename, linenum);
1164: if (!mac_valid(arg))
1165: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1166: filename, linenum, arg ? arg : "<NONE>");
1167: if (options->macs == NULL)
1168: options->macs = xstrdup(arg);
1.211 djm 1169: break;
1170:
1171: case sKexAlgorithms:
1172: arg = strdelim(&cp);
1173: if (!arg || *arg == '\0')
1174: fatal("%s line %d: Missing argument.",
1175: filename, linenum);
1176: if (!kex_names_valid(arg))
1177: fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1178: filename, linenum, arg ? arg : "<NONE>");
1179: if (options->kex_algorithms == NULL)
1180: options->kex_algorithms = xstrdup(arg);
1.94 markus 1181: break;
1.43 jakob 1182:
1.94 markus 1183: case sProtocol:
1184: intptr = &options->protocol;
1185: arg = strdelim(&cp);
1186: if (!arg || *arg == '\0')
1187: fatal("%s line %d: Missing argument.", filename, linenum);
1188: value = proto_spec(arg);
1189: if (value == SSH_PROTO_UNKNOWN)
1190: fatal("%s line %d: Bad protocol spec '%s'.",
1.95 deraadt 1191: filename, linenum, arg ? arg : "<NONE>");
1.94 markus 1192: if (*intptr == SSH_PROTO_UNKNOWN)
1193: *intptr = value;
1194: break;
1195:
1196: case sSubsystem:
1197: if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1198: fatal("%s line %d: too many subsystems defined.",
1.95 deraadt 1199: filename, linenum);
1.94 markus 1200: }
1201: arg = strdelim(&cp);
1202: if (!arg || *arg == '\0')
1203: fatal("%s line %d: Missing subsystem name.",
1.95 deraadt 1204: filename, linenum);
1.153 dtucker 1205: if (!*activep) {
1206: arg = strdelim(&cp);
1207: break;
1208: }
1.94 markus 1209: for (i = 0; i < options->num_subsystems; i++)
1210: if (strcmp(arg, options->subsystem_name[i]) == 0)
1211: fatal("%s line %d: Subsystem '%s' already defined.",
1.95 deraadt 1212: filename, linenum, arg);
1.94 markus 1213: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1214: arg = strdelim(&cp);
1215: if (!arg || *arg == '\0')
1216: fatal("%s line %d: Missing subsystem command.",
1.95 deraadt 1217: filename, linenum);
1.94 markus 1218: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151 djm 1219:
1220: /* Collect arguments (separate to executable) */
1221: p = xstrdup(arg);
1222: len = strlen(p) + 1;
1223: while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1224: len += 1 + strlen(arg);
1225: p = xrealloc(p, 1, len);
1226: strlcat(p, " ", len);
1227: strlcat(p, arg, len);
1228: }
1229: options->subsystem_args[options->num_subsystems] = p;
1.94 markus 1230: options->num_subsystems++;
1231: break;
1.46 markus 1232:
1.94 markus 1233: case sMaxStartups:
1234: arg = strdelim(&cp);
1235: if (!arg || *arg == '\0')
1236: fatal("%s line %d: Missing MaxStartups spec.",
1.95 deraadt 1237: filename, linenum);
1.94 markus 1238: if ((n = sscanf(arg, "%d:%d:%d",
1239: &options->max_startups_begin,
1240: &options->max_startups_rate,
1241: &options->max_startups)) == 3) {
1242: if (options->max_startups_begin >
1243: options->max_startups ||
1244: options->max_startups_rate > 100 ||
1245: options->max_startups_rate < 1)
1.50 markus 1246: fatal("%s line %d: Illegal MaxStartups spec.",
1.87 stevesk 1247: filename, linenum);
1.94 markus 1248: } else if (n != 1)
1249: fatal("%s line %d: Illegal MaxStartups spec.",
1250: filename, linenum);
1251: else
1252: options->max_startups = options->max_startups_begin;
1253: break;
1.133 dtucker 1254:
1255: case sMaxAuthTries:
1256: intptr = &options->max_authtries;
1257: goto parse_int;
1.94 markus 1258:
1.180 djm 1259: case sMaxSessions:
1260: intptr = &options->max_sessions;
1261: goto parse_int;
1262:
1.94 markus 1263: case sBanner:
1264: charptr = &options->banner;
1265: goto parse_filename;
1.176 djm 1266:
1.94 markus 1267: /*
1268: * These options can contain %X options expanded at
1269: * connect time, so that you can specify paths like:
1270: *
1271: * AuthorizedKeysFile /etc/ssh_keys/%u
1272: */
1273: case sAuthorizedKeysFile:
1.219 djm 1274: if (*activep && options->num_authkeys_files == 0) {
1275: while ((arg = strdelim(&cp)) && *arg != '\0') {
1276: if (options->num_authkeys_files >=
1277: MAX_AUTHKEYS_FILES)
1278: fatal("%s line %d: "
1279: "too many authorized keys files.",
1280: filename, linenum);
1281: options->authorized_keys_files[
1282: options->num_authkeys_files++] =
1283: tilde_expand_filename(arg, getuid());
1284: }
1285: }
1286: return 0;
1287:
1.208 djm 1288: case sAuthorizedPrincipalsFile:
1289: charptr = &options->authorized_principals_file;
1.205 djm 1290: arg = strdelim(&cp);
1291: if (!arg || *arg == '\0')
1292: fatal("%s line %d: missing file name.",
1293: filename, linenum);
1294: if (*activep && *charptr == NULL) {
1.206 markus 1295: *charptr = tilde_expand_filename(arg, getuid());
1.205 djm 1296: /* increase optional counter */
1297: if (intptr != NULL)
1298: *intptr = *intptr + 1;
1299: }
1300: break;
1.94 markus 1301:
1302: case sClientAliveInterval:
1303: intptr = &options->client_alive_interval;
1304: goto parse_time;
1305:
1306: case sClientAliveCountMax:
1307: intptr = &options->client_alive_count_max;
1308: goto parse_int;
1.131 djm 1309:
1310: case sAcceptEnv:
1311: while ((arg = strdelim(&cp)) && *arg != '\0') {
1312: if (strchr(arg, '=') != NULL)
1313: fatal("%s line %d: Invalid environment name.",
1314: filename, linenum);
1315: if (options->num_accept_env >= MAX_ACCEPT_ENV)
1316: fatal("%s line %d: too many allow env.",
1317: filename, linenum);
1.153 dtucker 1318: if (!*activep)
1.227 ! markus 1319: continue;
1.131 djm 1320: options->accept_env[options->num_accept_env++] =
1321: xstrdup(arg);
1322: }
1323: break;
1.145 reyk 1324:
1325: case sPermitTunnel:
1326: intptr = &options->permit_tun;
1.146 reyk 1327: arg = strdelim(&cp);
1328: if (!arg || *arg == '\0')
1329: fatal("%s line %d: Missing yes/point-to-point/"
1330: "ethernet/no argument.", filename, linenum);
1.182 dtucker 1331: value = -1;
1332: for (i = 0; tunmode_desc[i].val != -1; i++)
1333: if (strcmp(tunmode_desc[i].text, arg) == 0) {
1334: value = tunmode_desc[i].val;
1335: break;
1336: }
1337: if (value == -1)
1.146 reyk 1338: fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1339: "no argument: %s", filename, linenum, arg);
1340: if (*intptr == -1)
1341: *intptr = value;
1342: break;
1.94 markus 1343:
1.153 dtucker 1344: case sMatch:
1345: if (cmdline)
1346: fatal("Match directive not supported as a command-line "
1347: "option");
1.226 dtucker 1348: value = match_cfg_line(&cp, linenum, connectinfo);
1.153 dtucker 1349: if (value < 0)
1350: fatal("%s line %d: Bad Match condition", filename,
1351: linenum);
1352: *activep = value;
1.156 dtucker 1353: break;
1354:
1355: case sPermitOpen:
1356: arg = strdelim(&cp);
1357: if (!arg || *arg == '\0')
1358: fatal("%s line %d: missing PermitOpen specification",
1359: filename, linenum);
1.167 dtucker 1360: n = options->num_permitted_opens; /* modified later */
1.156 dtucker 1361: if (strcmp(arg, "any") == 0) {
1.167 dtucker 1362: if (*activep && n == -1) {
1.156 dtucker 1363: channel_clear_adm_permitted_opens();
1.159 dtucker 1364: options->num_permitted_opens = 0;
1.224 dtucker 1365: }
1366: break;
1367: }
1368: if (strcmp(arg, "none") == 0) {
1369: if (*activep && n == -1) {
1370: channel_clear_adm_permitted_opens();
1371: options->num_permitted_opens = 1;
1372: channel_disable_adm_local_opens();
1.159 dtucker 1373: }
1.156 dtucker 1374: break;
1375: }
1.166 dtucker 1376: if (*activep && n == -1)
1377: channel_clear_adm_permitted_opens();
1.159 dtucker 1378: for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1379: p = hpdelim(&arg);
1380: if (p == NULL)
1381: fatal("%s line %d: missing host in PermitOpen",
1382: filename, linenum);
1383: p = cleanhostname(p);
1.223 dtucker 1384: if (arg == NULL || ((port = permitopen_port(arg)) < 0))
1.159 dtucker 1385: fatal("%s line %d: bad port number in "
1386: "PermitOpen", filename, linenum);
1.166 dtucker 1387: if (*activep && n == -1)
1.159 dtucker 1388: options->num_permitted_opens =
1389: channel_add_adm_permitted_opens(p, port);
1390: }
1.153 dtucker 1391: break;
1392:
1.158 dtucker 1393: case sForceCommand:
1394: if (cp == NULL)
1395: fatal("%.200s line %d: Missing argument.", filename,
1396: linenum);
1397: len = strspn(cp, WHITESPACE);
1398: if (*activep && options->adm_forced_command == NULL)
1399: options->adm_forced_command = xstrdup(cp + len);
1400: return 0;
1401:
1.176 djm 1402: case sChrootDirectory:
1403: charptr = &options->chroot_directory;
1.177 djm 1404:
1405: arg = strdelim(&cp);
1406: if (!arg || *arg == '\0')
1407: fatal("%s line %d: missing file name.",
1408: filename, linenum);
1409: if (*activep && *charptr == NULL)
1410: *charptr = xstrdup(arg);
1411: break;
1.176 djm 1412:
1.204 djm 1413: case sTrustedUserCAKeys:
1414: charptr = &options->trusted_user_ca_keys;
1415: goto parse_filename;
1416:
1417: case sRevokedKeys:
1418: charptr = &options->revoked_keys_file;
1419: goto parse_filename;
1420:
1.213 djm 1421: case sIPQoS:
1422: arg = strdelim(&cp);
1423: if ((value = parse_ipqos(arg)) == -1)
1424: fatal("%s line %d: Bad IPQoS value: %s",
1425: filename, linenum, arg);
1426: arg = strdelim(&cp);
1427: if (arg == NULL)
1428: value2 = value;
1429: else if ((value2 = parse_ipqos(arg)) == -1)
1430: fatal("%s line %d: Bad IPQoS value: %s",
1431: filename, linenum, arg);
1432: if (*activep) {
1433: options->ip_qos_interactive = value;
1434: options->ip_qos_bulk = value2;
1435: }
1436: break;
1437:
1.225 djm 1438: case sVersionAddendum:
1439: if (cp == NULL)
1440: fatal("%.200s line %d: Missing argument.", filename,
1441: linenum);
1442: len = strspn(cp, WHITESPACE);
1443: if (*activep && options->version_addendum == NULL) {
1444: if (strcasecmp(cp + len, "none") == 0)
1445: options->version_addendum = xstrdup("");
1446: else if (strchr(cp + len, '\r') != NULL)
1447: fatal("%.200s line %d: Invalid argument",
1448: filename, linenum);
1449: else
1450: options->version_addendum = xstrdup(cp + len);
1451: }
1452: return 0;
1453:
1.94 markus 1454: case sDeprecated:
1.117 itojun 1455: logit("%s line %d: Deprecated option %s",
1.121 jakob 1456: filename, linenum, arg);
1457: while (arg)
1458: arg = strdelim(&cp);
1459: break;
1460:
1461: case sUnsupported:
1462: logit("%s line %d: Unsupported option %s",
1.94 markus 1463: filename, linenum, arg);
1464: while (arg)
1465: arg = strdelim(&cp);
1466: break;
1467:
1468: default:
1469: fatal("%s line %d: Missing handler for opcode %s (%d)",
1470: filename, linenum, arg, opcode);
1471: }
1472: if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1473: fatal("%s line %d: garbage at end of line; \"%.200s\".",
1474: filename, linenum, arg);
1475: return 0;
1476: }
1477:
1478: /* Reads the server configuration file. */
1.25 markus 1479:
1.94 markus 1480: void
1.134 djm 1481: load_server_config(const char *filename, Buffer *conf)
1.94 markus 1482: {
1.134 djm 1483: char line[1024], *cp;
1.94 markus 1484: FILE *f;
1.81 stevesk 1485:
1.134 djm 1486: debug2("%s: filename %s", __func__, filename);
1487: if ((f = fopen(filename, "r")) == NULL) {
1.94 markus 1488: perror(filename);
1489: exit(1);
1490: }
1.134 djm 1491: buffer_clear(conf);
1492: while (fgets(line, sizeof(line), f)) {
1493: /*
1494: * Trim out comments and strip whitespace
1.135 deraadt 1495: * NB - preserve newlines, they are needed to reproduce
1.134 djm 1496: * line numbers later for error messages
1497: */
1498: if ((cp = strchr(line, '#')) != NULL)
1499: memcpy(cp, "\n", 2);
1500: cp = line + strspn(line, " \t\r");
1501:
1502: buffer_append(conf, cp, strlen(cp));
1503: }
1504: buffer_append(conf, "\0", 1);
1505: fclose(f);
1506: debug2("%s: done config len = %d", __func__, buffer_len(conf));
1507: }
1508:
1509: void
1.226 dtucker 1510: parse_server_match_config(ServerOptions *options,
1511: struct connection_info *connectinfo)
1.153 dtucker 1512: {
1513: ServerOptions mo;
1514:
1515: initialize_server_options(&mo);
1.226 dtucker 1516: parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
1.168 dtucker 1517: copy_set_server_options(options, &mo, 0);
1.153 dtucker 1518: }
1519:
1.226 dtucker 1520: int parse_server_match_testspec(struct connection_info *ci, char *spec)
1521: {
1522: char *p;
1523:
1524: while ((p = strsep(&spec, ",")) && *p != '\0') {
1525: if (strncmp(p, "addr=", 5) == 0) {
1526: ci->address = xstrdup(p + 5);
1527: } else if (strncmp(p, "host=", 5) == 0) {
1528: ci->host = xstrdup(p + 5);
1529: } else if (strncmp(p, "user=", 5) == 0) {
1530: ci->user = xstrdup(p + 5);
1531: } else if (strncmp(p, "laddr=", 6) == 0) {
1532: ci->laddress = xstrdup(p + 6);
1533: } else if (strncmp(p, "lport=", 6) == 0) {
1534: ci->lport = a2port(p + 6);
1535: if (ci->lport == -1) {
1536: fprintf(stderr, "Invalid port '%s' in test mode"
1537: " specification %s\n", p+6, p);
1538: return -1;
1539: }
1540: } else {
1541: fprintf(stderr, "Invalid test mode specification %s\n",
1542: p);
1543: return -1;
1544: }
1545: }
1546: return 0;
1547: }
1548:
1549: /*
1550: * returns 1 for a complete spec, 0 for partial spec and -1 for an
1551: * empty spec.
1552: */
1553: int server_match_spec_complete(struct connection_info *ci)
1554: {
1555: if (ci->user && ci->host && ci->address)
1556: return 1; /* complete */
1557: if (!ci->user && !ci->host && !ci->address)
1558: return -1; /* empty */
1559: return 0; /* partial */
1560: }
1561:
1.168 dtucker 1562: /* Helper macros */
1563: #define M_CP_INTOPT(n) do {\
1564: if (src->n != -1) \
1565: dst->n = src->n; \
1566: } while (0)
1567: #define M_CP_STROPT(n) do {\
1568: if (src->n != NULL) { \
1569: if (dst->n != NULL) \
1570: xfree(dst->n); \
1571: dst->n = src->n; \
1572: } \
1573: } while(0)
1.219 djm 1574: #define M_CP_STRARRAYOPT(n, num_n) do {\
1575: if (src->num_n != 0) { \
1576: for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1577: dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1578: } \
1579: } while(0)
1.168 dtucker 1580:
1581: /*
1582: * Copy any supported values that are set.
1583: *
1.195 jj 1584: * If the preauth flag is set, we do not bother copying the string or
1.168 dtucker 1585: * array values that are not used pre-authentication, because any that we
1586: * do use must be explictly sent in mm_getpwnamallow().
1587: */
1.153 dtucker 1588: void
1.168 dtucker 1589: copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1.153 dtucker 1590: {
1.168 dtucker 1591: M_CP_INTOPT(password_authentication);
1592: M_CP_INTOPT(gss_authentication);
1593: M_CP_INTOPT(rsa_authentication);
1594: M_CP_INTOPT(pubkey_authentication);
1595: M_CP_INTOPT(kerberos_authentication);
1596: M_CP_INTOPT(hostbased_authentication);
1.209 djm 1597: M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1.168 dtucker 1598: M_CP_INTOPT(kbd_interactive_authentication);
1.190 djm 1599: M_CP_INTOPT(zero_knowledge_password_authentication);
1.175 dtucker 1600: M_CP_INTOPT(permit_root_login);
1.188 djm 1601: M_CP_INTOPT(permit_empty_passwd);
1.168 dtucker 1602:
1603: M_CP_INTOPT(allow_tcp_forwarding);
1.178 pyr 1604: M_CP_INTOPT(allow_agent_forwarding);
1.209 djm 1605: M_CP_INTOPT(permit_tun);
1.168 dtucker 1606: M_CP_INTOPT(gateway_ports);
1607: M_CP_INTOPT(x11_display_offset);
1608: M_CP_INTOPT(x11_forwarding);
1609: M_CP_INTOPT(x11_use_localhost);
1.180 djm 1610: M_CP_INTOPT(max_sessions);
1.184 dtucker 1611: M_CP_INTOPT(max_authtries);
1.213 djm 1612: M_CP_INTOPT(ip_qos_interactive);
1613: M_CP_INTOPT(ip_qos_bulk);
1.168 dtucker 1614:
1.218 djm 1615: /* See comment in servconf.h */
1616: COPY_MATCH_STRING_OPTS();
1.216 djm 1617:
1.217 dtucker 1618: /*
1619: * The only things that should be below this point are string options
1620: * which are only used after authentication.
1621: */
1.168 dtucker 1622: if (preauth)
1623: return;
1.219 djm 1624:
1.168 dtucker 1625: M_CP_STROPT(adm_forced_command);
1.176 djm 1626: M_CP_STROPT(chroot_directory);
1.153 dtucker 1627: }
1.168 dtucker 1628:
1629: #undef M_CP_INTOPT
1630: #undef M_CP_STROPT
1.219 djm 1631: #undef M_CP_STRARRAYOPT
1.153 dtucker 1632:
1633: void
1634: parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1.226 dtucker 1635: struct connection_info *connectinfo)
1.134 djm 1636: {
1.153 dtucker 1637: int active, linenum, bad_options = 0;
1.136 dtucker 1638: char *cp, *obuf, *cbuf;
1.134 djm 1639:
1640: debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1641:
1.136 dtucker 1642: obuf = cbuf = xstrdup(buffer_ptr(conf));
1.226 dtucker 1643: active = connectinfo ? 0 : 1;
1.137 dtucker 1644: linenum = 1;
1.140 deraadt 1645: while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134 djm 1646: if (process_server_config_line(options, cp, filename,
1.226 dtucker 1647: linenum++, &active, connectinfo) != 0)
1.94 markus 1648: bad_options++;
1.1 deraadt 1649: }
1.136 dtucker 1650: xfree(obuf);
1.78 stevesk 1651: if (bad_options > 0)
1652: fatal("%s: terminating, %d bad configuration options",
1653: filename, bad_options);
1.182 dtucker 1654: }
1655:
1656: static const char *
1.221 djm 1657: fmt_multistate_int(int val, const struct multistate *m)
1658: {
1659: u_int i;
1660:
1661: for (i = 0; m[i].key != NULL; i++) {
1662: if (m[i].value == val)
1663: return m[i].key;
1664: }
1665: return "UNKNOWN";
1666: }
1667:
1668: static const char *
1.182 dtucker 1669: fmt_intarg(ServerOpCodes code, int val)
1670: {
1.221 djm 1671: if (val == -1)
1672: return "unset";
1673: switch (code) {
1674: case sAddressFamily:
1675: return fmt_multistate_int(val, multistate_addressfamily);
1676: case sPermitRootLogin:
1677: return fmt_multistate_int(val, multistate_permitrootlogin);
1678: case sGatewayPorts:
1679: return fmt_multistate_int(val, multistate_gatewayports);
1680: case sCompression:
1681: return fmt_multistate_int(val, multistate_compression);
1.222 djm 1682: case sUsePrivilegeSeparation:
1683: return fmt_multistate_int(val, multistate_privsep);
1.221 djm 1684: case sProtocol:
1.182 dtucker 1685: switch (val) {
1686: case SSH_PROTO_1:
1687: return "1";
1688: case SSH_PROTO_2:
1689: return "2";
1690: case (SSH_PROTO_1|SSH_PROTO_2):
1691: return "2,1";
1692: default:
1693: return "UNKNOWN";
1694: }
1.221 djm 1695: default:
1696: switch (val) {
1697: case 0:
1698: return "no";
1699: case 1:
1700: return "yes";
1701: default:
1702: return "UNKNOWN";
1703: }
1.182 dtucker 1704: }
1705: }
1706:
1707: static const char *
1708: lookup_opcode_name(ServerOpCodes code)
1709: {
1710: u_int i;
1711:
1712: for (i = 0; keywords[i].name != NULL; i++)
1713: if (keywords[i].opcode == code)
1714: return(keywords[i].name);
1715: return "UNKNOWN";
1716: }
1717:
1718: static void
1719: dump_cfg_int(ServerOpCodes code, int val)
1720: {
1721: printf("%s %d\n", lookup_opcode_name(code), val);
1722: }
1723:
1724: static void
1725: dump_cfg_fmtint(ServerOpCodes code, int val)
1726: {
1727: printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1728: }
1729:
1730: static void
1731: dump_cfg_string(ServerOpCodes code, const char *val)
1732: {
1733: if (val == NULL)
1734: return;
1735: printf("%s %s\n", lookup_opcode_name(code), val);
1736: }
1737:
1738: static void
1739: dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1740: {
1741: u_int i;
1742:
1743: for (i = 0; i < count; i++)
1.219 djm 1744: printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1745: }
1746:
1747: static void
1748: dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1749: {
1750: u_int i;
1751:
1752: printf("%s", lookup_opcode_name(code));
1753: for (i = 0; i < count; i++)
1754: printf(" %s", vals[i]);
1755: printf("\n");
1.182 dtucker 1756: }
1757:
1758: void
1759: dump_config(ServerOptions *o)
1760: {
1761: u_int i;
1762: int ret;
1763: struct addrinfo *ai;
1764: char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1765:
1766: /* these are usually at the top of the config */
1767: for (i = 0; i < o->num_ports; i++)
1768: printf("port %d\n", o->ports[i]);
1769: dump_cfg_fmtint(sProtocol, o->protocol);
1770: dump_cfg_fmtint(sAddressFamily, o->address_family);
1771:
1772: /* ListenAddress must be after Port */
1773: for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1774: if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1775: sizeof(addr), port, sizeof(port),
1776: NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1777: error("getnameinfo failed: %.100s",
1778: (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1779: strerror(errno));
1780: } else {
1781: if (ai->ai_family == AF_INET6)
1782: printf("listenaddress [%s]:%s\n", addr, port);
1783: else
1784: printf("listenaddress %s:%s\n", addr, port);
1785: }
1786: }
1787:
1788: /* integer arguments */
1789: dump_cfg_int(sServerKeyBits, o->server_key_bits);
1790: dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1791: dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1792: dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1793: dump_cfg_int(sMaxAuthTries, o->max_authtries);
1.189 djm 1794: dump_cfg_int(sMaxSessions, o->max_sessions);
1.182 dtucker 1795: dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1796: dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1797:
1798: /* formatted integer arguments */
1799: dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1800: dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1801: dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1802: dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1803: dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1804: dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1805: o->hostbased_uses_name_from_packet_only);
1806: dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1807: dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
1.187 djm 1808: #ifdef KRB5
1.182 dtucker 1809: dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1810: dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1811: dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
1812: dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
1.187 djm 1813: #endif
1814: #ifdef GSSAPI
1.182 dtucker 1815: dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1816: dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
1.190 djm 1817: #endif
1818: #ifdef JPAKE
1819: dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1820: o->zero_knowledge_password_authentication);
1.187 djm 1821: #endif
1.182 dtucker 1822: dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1823: dump_cfg_fmtint(sKbdInteractiveAuthentication,
1824: o->kbd_interactive_authentication);
1825: dump_cfg_fmtint(sChallengeResponseAuthentication,
1826: o->challenge_response_authentication);
1827: dump_cfg_fmtint(sPrintMotd, o->print_motd);
1828: dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1829: dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
1830: dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1831: dump_cfg_fmtint(sStrictModes, o->strict_modes);
1832: dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
1833: dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
1834: dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
1835: dump_cfg_fmtint(sUseLogin, o->use_login);
1836: dump_cfg_fmtint(sCompression, o->compression);
1837: dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
1838: dump_cfg_fmtint(sUseDNS, o->use_dns);
1839: dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1840: dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1841:
1842: /* string arguments */
1843: dump_cfg_string(sPidFile, o->pid_file);
1844: dump_cfg_string(sXAuthLocation, o->xauth_location);
1845: dump_cfg_string(sCiphers, o->ciphers);
1846: dump_cfg_string(sMacs, o->macs);
1847: dump_cfg_string(sBanner, o->banner);
1848: dump_cfg_string(sForceCommand, o->adm_forced_command);
1.201 dtucker 1849: dump_cfg_string(sChrootDirectory, o->chroot_directory);
1.204 djm 1850: dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
1851: dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
1.208 djm 1852: dump_cfg_string(sAuthorizedPrincipalsFile,
1853: o->authorized_principals_file);
1.225 djm 1854: dump_cfg_string(sVersionAddendum, o->version_addendum);
1.182 dtucker 1855:
1856: /* string arguments requiring a lookup */
1857: dump_cfg_string(sLogLevel, log_level_name(o->log_level));
1858: dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
1859:
1860: /* string array arguments */
1.219 djm 1861: dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
1862: o->authorized_keys_files);
1.182 dtucker 1863: dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
1864: o->host_key_files);
1.203 djm 1865: dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
1866: o->host_cert_files);
1.182 dtucker 1867: dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
1868: dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
1869: dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
1870: dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
1871: dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1872:
1873: /* other arguments */
1874: for (i = 0; i < o->num_subsystems; i++)
1875: printf("subsystem %s %s\n", o->subsystem_name[i],
1876: o->subsystem_args[i]);
1877:
1878: printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
1879: o->max_startups_rate, o->max_startups);
1880:
1881: for (i = 0; tunmode_desc[i].val != -1; i++)
1882: if (tunmode_desc[i].val == o->permit_tun) {
1883: s = tunmode_desc[i].text;
1884: break;
1885: }
1886: dump_cfg_string(sPermitTunnel, s);
1.213 djm 1887:
1.214 stevesk 1888: printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
1889: printf("%s\n", iptos2str(o->ip_qos_bulk));
1.182 dtucker 1890:
1891: channel_print_adm_permitted_opens();
1.1 deraadt 1892: }