Annotation of src/usr.bin/ssh/servconf.c, Revision 1.228
1.226 dtucker 1:
1.228 ! djm 2: /* $OpenBSD: servconf.c,v 1.227 2012/06/19 18:25:27 markus 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.228 ! djm 274: use_privsep = PRIVSEP_NOSANDBOX;
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[] = {
1.228 ! djm 734: { "yes", PRIVSEP_NOSANDBOX },
! 735: { "sandbox", PRIVSEP_ON },
! 736: { "nosandbox", PRIVSEP_NOSANDBOX },
1.222 djm 737: { "no", PRIVSEP_OFF },
738: { NULL, -1 }
739: };
1.220 djm 740:
1.94 markus 741: int
742: process_server_config_line(ServerOptions *options, char *line,
1.226 dtucker 743: const char *filename, int linenum, int *activep,
744: struct connection_info *connectinfo)
1.1 deraadt 745: {
1.74 stevesk 746: char *cp, **charptr, *arg, *p;
1.213 djm 747: int cmdline = 0, *intptr, value, value2, n;
1.174 dtucker 748: SyslogFacility *log_facility_ptr;
749: LogLevel *log_level_ptr;
1.25 markus 750: ServerOpCodes opcode;
1.194 djm 751: int port;
1.153 dtucker 752: u_int i, flags = 0;
1.151 djm 753: size_t len;
1.220 djm 754: const struct multistate *multistate_ptr;
1.25 markus 755:
1.94 markus 756: cp = line;
1.148 dtucker 757: if ((arg = strdelim(&cp)) == NULL)
1.147 djm 758: return 0;
1.94 markus 759: /* Ignore leading whitespace */
760: if (*arg == '\0')
761: arg = strdelim(&cp);
762: if (!arg || !*arg || *arg == '#')
763: return 0;
764: intptr = NULL;
765: charptr = NULL;
1.153 dtucker 766: opcode = parse_token(arg, filename, linenum, &flags);
767:
768: if (activep == NULL) { /* We are processing a command line directive */
769: cmdline = 1;
770: activep = &cmdline;
771: }
772: if (*activep && opcode != sMatch)
773: debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
774: if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
1.226 dtucker 775: if (connectinfo == NULL) {
1.153 dtucker 776: fatal("%s line %d: Directive '%s' is not allowed "
777: "within a Match block", filename, linenum, arg);
778: } else { /* this is a directive we have already processed */
779: while (arg)
780: arg = strdelim(&cp);
781: return 0;
782: }
783: }
784:
1.94 markus 785: switch (opcode) {
786: case sBadOption:
787: return -1;
788: case sPort:
789: /* ignore ports from configfile if cmdline specifies ports */
790: if (options->ports_from_cmdline)
791: return 0;
792: if (options->listen_addrs != NULL)
793: fatal("%s line %d: ports must be specified before "
1.98 stevesk 794: "ListenAddress.", filename, linenum);
1.94 markus 795: if (options->num_ports >= MAX_PORTS)
796: fatal("%s line %d: too many ports.",
797: filename, linenum);
1.48 provos 798: arg = strdelim(&cp);
1.94 markus 799: if (!arg || *arg == '\0')
800: fatal("%s line %d: missing port number.",
801: filename, linenum);
802: options->ports[options->num_ports++] = a2port(arg);
1.194 djm 803: if (options->ports[options->num_ports-1] <= 0)
1.94 markus 804: fatal("%s line %d: Badly formatted port number.",
805: filename, linenum);
806: break;
1.29 markus 807:
1.94 markus 808: case sServerKeyBits:
809: intptr = &options->server_key_bits;
1.180 djm 810: parse_int:
1.94 markus 811: arg = strdelim(&cp);
812: if (!arg || *arg == '\0')
813: fatal("%s line %d: missing integer value.",
814: filename, linenum);
815: value = atoi(arg);
1.153 dtucker 816: if (*activep && *intptr == -1)
1.94 markus 817: *intptr = value;
818: break;
1.25 markus 819:
1.94 markus 820: case sLoginGraceTime:
821: intptr = &options->login_grace_time;
1.180 djm 822: parse_time:
1.94 markus 823: arg = strdelim(&cp);
824: if (!arg || *arg == '\0')
825: fatal("%s line %d: missing time value.",
826: filename, linenum);
827: if ((value = convtime(arg)) == -1)
828: fatal("%s line %d: invalid time value.",
829: filename, linenum);
830: if (*intptr == -1)
831: *intptr = value;
832: break;
833:
834: case sKeyRegenerationTime:
835: intptr = &options->key_regeneration_time;
836: goto parse_time;
837:
838: case sListenAddress:
839: arg = strdelim(&cp);
1.139 djm 840: if (arg == NULL || *arg == '\0')
841: fatal("%s line %d: missing address",
1.94 markus 842: filename, linenum);
1.144 dtucker 843: /* check for bare IPv6 address: no "[]" and 2 or more ":" */
844: if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
845: && strchr(p+1, ':') != NULL) {
846: add_listen_addr(options, arg, 0);
847: break;
848: }
1.139 djm 849: p = hpdelim(&arg);
850: if (p == NULL)
851: fatal("%s line %d: bad address:port usage",
852: filename, linenum);
853: p = cleanhostname(p);
854: if (arg == NULL)
855: port = 0;
1.194 djm 856: else if ((port = a2port(arg)) <= 0)
1.139 djm 857: fatal("%s line %d: bad port number", filename, linenum);
858:
859: add_listen_addr(options, p, port);
1.25 markus 860:
1.138 djm 861: break;
862:
863: case sAddressFamily:
1.220 djm 864: intptr = &options->address_family;
865: multistate_ptr = multistate_addressfamily;
866: if (options->listen_addrs != NULL)
867: fatal("%s line %d: address family must be specified "
868: "before ListenAddress.", filename, linenum);
869: parse_multistate:
1.138 djm 870: arg = strdelim(&cp);
1.141 markus 871: if (!arg || *arg == '\0')
1.220 djm 872: fatal("%s line %d: missing argument.",
1.141 markus 873: filename, linenum);
1.220 djm 874: value = -1;
875: for (i = 0; multistate_ptr[i].key != NULL; i++) {
876: if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
877: value = multistate_ptr[i].value;
878: break;
879: }
880: }
881: if (value == -1)
882: fatal("%s line %d: unsupported option \"%s\".",
1.138 djm 883: filename, linenum, arg);
1.220 djm 884: if (*activep && *intptr == -1)
1.138 djm 885: *intptr = value;
1.94 markus 886: break;
887:
888: case sHostKeyFile:
889: intptr = &options->num_host_key_files;
890: if (*intptr >= MAX_HOSTKEYS)
891: fatal("%s line %d: too many host keys specified (max %d).",
892: filename, linenum, MAX_HOSTKEYS);
893: charptr = &options->host_key_files[*intptr];
1.180 djm 894: parse_filename:
1.94 markus 895: arg = strdelim(&cp);
896: if (!arg || *arg == '\0')
897: fatal("%s line %d: missing file name.",
898: filename, linenum);
1.153 dtucker 899: if (*activep && *charptr == NULL) {
1.202 djm 900: *charptr = derelativise_path(arg);
1.94 markus 901: /* increase optional counter */
902: if (intptr != NULL)
903: *intptr = *intptr + 1;
904: }
905: break;
1.76 stevesk 906:
1.203 djm 907: case sHostCertificate:
908: intptr = &options->num_host_cert_files;
909: if (*intptr >= MAX_HOSTKEYS)
910: fatal("%s line %d: too many host certificates "
911: "specified (max %d).", filename, linenum,
912: MAX_HOSTCERTS);
913: charptr = &options->host_cert_files[*intptr];
914: goto parse_filename;
915: break;
916:
1.94 markus 917: case sPidFile:
918: charptr = &options->pid_file;
919: goto parse_filename;
1.25 markus 920:
1.94 markus 921: case sPermitRootLogin:
922: intptr = &options->permit_root_login;
1.220 djm 923: multistate_ptr = multistate_permitrootlogin;
924: goto parse_multistate;
1.36 markus 925:
1.94 markus 926: case sIgnoreRhosts:
927: intptr = &options->ignore_rhosts;
1.180 djm 928: parse_flag:
1.94 markus 929: arg = strdelim(&cp);
930: if (!arg || *arg == '\0')
931: fatal("%s line %d: missing yes/no argument.",
932: filename, linenum);
933: value = 0; /* silence compiler */
934: if (strcmp(arg, "yes") == 0)
935: value = 1;
936: else if (strcmp(arg, "no") == 0)
937: value = 0;
938: else
939: fatal("%s line %d: Bad yes/no argument: %s",
940: filename, linenum, arg);
1.153 dtucker 941: if (*activep && *intptr == -1)
1.94 markus 942: *intptr = value;
943: break;
944:
945: case sIgnoreUserKnownHosts:
946: intptr = &options->ignore_user_known_hosts;
947: goto parse_flag;
948:
949: case sRhostsRSAAuthentication:
950: intptr = &options->rhosts_rsa_authentication;
951: goto parse_flag;
952:
953: case sHostbasedAuthentication:
954: intptr = &options->hostbased_authentication;
955: goto parse_flag;
956:
957: case sHostbasedUsesNameFromPacketOnly:
958: intptr = &options->hostbased_uses_name_from_packet_only;
959: goto parse_flag;
960:
961: case sRSAAuthentication:
962: intptr = &options->rsa_authentication;
963: goto parse_flag;
964:
965: case sPubkeyAuthentication:
966: intptr = &options->pubkey_authentication;
967: goto parse_flag;
1.119 jakob 968:
1.94 markus 969: case sKerberosAuthentication:
970: intptr = &options->kerberos_authentication;
971: goto parse_flag;
972:
973: case sKerberosOrLocalPasswd:
974: intptr = &options->kerberos_or_local_passwd;
975: goto parse_flag;
976:
977: case sKerberosTicketCleanup:
978: intptr = &options->kerberos_ticket_cleanup;
1.130 jakob 979: goto parse_flag;
980:
981: case sKerberosGetAFSToken:
982: intptr = &options->kerberos_get_afs_token;
1.125 markus 983: goto parse_flag;
984:
985: case sGssAuthentication:
986: intptr = &options->gss_authentication;
987: goto parse_flag;
988:
989: case sGssCleanupCreds:
990: intptr = &options->gss_cleanup_creds;
1.94 markus 991: goto parse_flag;
992:
993: case sPasswordAuthentication:
994: intptr = &options->password_authentication;
995: goto parse_flag;
996:
1.190 djm 997: case sZeroKnowledgePasswordAuthentication:
998: intptr = &options->zero_knowledge_password_authentication;
999: goto parse_flag;
1000:
1.94 markus 1001: case sKbdInteractiveAuthentication:
1002: intptr = &options->kbd_interactive_authentication;
1003: goto parse_flag;
1004:
1005: case sChallengeResponseAuthentication:
1006: intptr = &options->challenge_response_authentication;
1007: goto parse_flag;
1008:
1009: case sPrintMotd:
1010: intptr = &options->print_motd;
1011: goto parse_flag;
1012:
1013: case sPrintLastLog:
1014: intptr = &options->print_lastlog;
1015: goto parse_flag;
1016:
1017: case sX11Forwarding:
1018: intptr = &options->x11_forwarding;
1019: goto parse_flag;
1020:
1021: case sX11DisplayOffset:
1022: intptr = &options->x11_display_offset;
1023: goto parse_int;
1.99 stevesk 1024:
1025: case sX11UseLocalhost:
1026: intptr = &options->x11_use_localhost;
1027: goto parse_flag;
1.94 markus 1028:
1029: case sXAuthLocation:
1030: charptr = &options->xauth_location;
1031: goto parse_filename;
1032:
1033: case sStrictModes:
1034: intptr = &options->strict_modes;
1035: goto parse_flag;
1036:
1.129 markus 1037: case sTCPKeepAlive:
1038: intptr = &options->tcp_keep_alive;
1.94 markus 1039: goto parse_flag;
1040:
1041: case sEmptyPasswd:
1042: intptr = &options->permit_empty_passwd;
1.113 markus 1043: goto parse_flag;
1044:
1045: case sPermitUserEnvironment:
1046: intptr = &options->permit_user_env;
1.94 markus 1047: goto parse_flag;
1048:
1049: case sUseLogin:
1050: intptr = &options->use_login;
1.111 markus 1051: goto parse_flag;
1052:
1053: case sCompression:
1054: intptr = &options->compression;
1.220 djm 1055: multistate_ptr = multistate_compression;
1056: goto parse_multistate;
1.94 markus 1057:
1058: case sGatewayPorts:
1059: intptr = &options->gateway_ports;
1.220 djm 1060: multistate_ptr = multistate_gatewayports;
1061: goto parse_multistate;
1.25 markus 1062:
1.122 markus 1063: case sUseDNS:
1064: intptr = &options->use_dns;
1.94 markus 1065: goto parse_flag;
1.53 markus 1066:
1.94 markus 1067: case sLogFacility:
1.174 dtucker 1068: log_facility_ptr = &options->log_facility;
1.94 markus 1069: arg = strdelim(&cp);
1070: value = log_facility_number(arg);
1.101 markus 1071: if (value == SYSLOG_FACILITY_NOT_SET)
1.94 markus 1072: fatal("%.200s line %d: unsupported log facility '%s'",
1073: filename, linenum, arg ? arg : "<NONE>");
1.174 dtucker 1074: if (*log_facility_ptr == -1)
1075: *log_facility_ptr = (SyslogFacility) value;
1.94 markus 1076: break;
1.25 markus 1077:
1.94 markus 1078: case sLogLevel:
1.174 dtucker 1079: log_level_ptr = &options->log_level;
1.94 markus 1080: arg = strdelim(&cp);
1081: value = log_level_number(arg);
1.101 markus 1082: if (value == SYSLOG_LEVEL_NOT_SET)
1.94 markus 1083: fatal("%.200s line %d: unsupported log level '%s'",
1084: filename, linenum, arg ? arg : "<NONE>");
1.174 dtucker 1085: if (*log_level_ptr == -1)
1086: *log_level_ptr = (LogLevel) value;
1.94 markus 1087: break;
1088:
1089: case sAllowTcpForwarding:
1090: intptr = &options->allow_tcp_forwarding;
1091: goto parse_flag;
1.102 provos 1092:
1.178 pyr 1093: case sAllowAgentForwarding:
1094: intptr = &options->allow_agent_forwarding;
1095: goto parse_flag;
1096:
1.102 provos 1097: case sUsePrivilegeSeparation:
1098: intptr = &use_privsep;
1.222 djm 1099: multistate_ptr = multistate_privsep;
1100: goto parse_multistate;
1.94 markus 1101:
1102: case sAllowUsers:
1103: while ((arg = strdelim(&cp)) && *arg != '\0') {
1104: if (options->num_allow_users >= MAX_ALLOW_USERS)
1105: fatal("%s line %d: too many allow users.",
1106: filename, linenum);
1.227 markus 1107: if (!*activep)
1108: continue;
1.112 deraadt 1109: options->allow_users[options->num_allow_users++] =
1110: xstrdup(arg);
1.94 markus 1111: }
1112: break;
1.25 markus 1113:
1.94 markus 1114: case sDenyUsers:
1115: while ((arg = strdelim(&cp)) && *arg != '\0') {
1116: if (options->num_deny_users >= MAX_DENY_USERS)
1.163 stevesk 1117: fatal("%s line %d: too many deny users.",
1.94 markus 1118: filename, linenum);
1.227 markus 1119: if (!*activep)
1120: continue;
1.112 deraadt 1121: options->deny_users[options->num_deny_users++] =
1122: xstrdup(arg);
1.94 markus 1123: }
1124: break;
1.25 markus 1125:
1.94 markus 1126: case sAllowGroups:
1127: while ((arg = strdelim(&cp)) && *arg != '\0') {
1128: if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1129: fatal("%s line %d: too many allow groups.",
1130: filename, linenum);
1.227 markus 1131: if (!*activep)
1132: continue;
1.112 deraadt 1133: options->allow_groups[options->num_allow_groups++] =
1134: xstrdup(arg);
1.94 markus 1135: }
1136: break;
1.33 markus 1137:
1.94 markus 1138: case sDenyGroups:
1139: while ((arg = strdelim(&cp)) && *arg != '\0') {
1140: if (options->num_deny_groups >= MAX_DENY_GROUPS)
1141: fatal("%s line %d: too many deny groups.",
1142: filename, linenum);
1.227 markus 1143: if (!*activep)
1144: continue;
1145: options->deny_groups[options->num_deny_groups++] =
1146: xstrdup(arg);
1.94 markus 1147: }
1148: break;
1.66 markus 1149:
1.94 markus 1150: case sCiphers:
1151: arg = strdelim(&cp);
1152: if (!arg || *arg == '\0')
1153: fatal("%s line %d: Missing argument.", filename, linenum);
1154: if (!ciphers_valid(arg))
1155: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1156: filename, linenum, arg ? arg : "<NONE>");
1157: if (options->ciphers == NULL)
1158: options->ciphers = xstrdup(arg);
1159: break;
1.33 markus 1160:
1.94 markus 1161: case sMacs:
1162: arg = strdelim(&cp);
1163: if (!arg || *arg == '\0')
1164: fatal("%s line %d: Missing argument.", filename, linenum);
1165: if (!mac_valid(arg))
1166: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1167: filename, linenum, arg ? arg : "<NONE>");
1168: if (options->macs == NULL)
1169: options->macs = xstrdup(arg);
1.211 djm 1170: break;
1171:
1172: case sKexAlgorithms:
1173: arg = strdelim(&cp);
1174: if (!arg || *arg == '\0')
1175: fatal("%s line %d: Missing argument.",
1176: filename, linenum);
1177: if (!kex_names_valid(arg))
1178: fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1179: filename, linenum, arg ? arg : "<NONE>");
1180: if (options->kex_algorithms == NULL)
1181: options->kex_algorithms = xstrdup(arg);
1.94 markus 1182: break;
1.43 jakob 1183:
1.94 markus 1184: case sProtocol:
1185: intptr = &options->protocol;
1186: arg = strdelim(&cp);
1187: if (!arg || *arg == '\0')
1188: fatal("%s line %d: Missing argument.", filename, linenum);
1189: value = proto_spec(arg);
1190: if (value == SSH_PROTO_UNKNOWN)
1191: fatal("%s line %d: Bad protocol spec '%s'.",
1.95 deraadt 1192: filename, linenum, arg ? arg : "<NONE>");
1.94 markus 1193: if (*intptr == SSH_PROTO_UNKNOWN)
1194: *intptr = value;
1195: break;
1196:
1197: case sSubsystem:
1198: if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1199: fatal("%s line %d: too many subsystems defined.",
1.95 deraadt 1200: filename, linenum);
1.94 markus 1201: }
1202: arg = strdelim(&cp);
1203: if (!arg || *arg == '\0')
1204: fatal("%s line %d: Missing subsystem name.",
1.95 deraadt 1205: filename, linenum);
1.153 dtucker 1206: if (!*activep) {
1207: arg = strdelim(&cp);
1208: break;
1209: }
1.94 markus 1210: for (i = 0; i < options->num_subsystems; i++)
1211: if (strcmp(arg, options->subsystem_name[i]) == 0)
1212: fatal("%s line %d: Subsystem '%s' already defined.",
1.95 deraadt 1213: filename, linenum, arg);
1.94 markus 1214: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1215: arg = strdelim(&cp);
1216: if (!arg || *arg == '\0')
1217: fatal("%s line %d: Missing subsystem command.",
1.95 deraadt 1218: filename, linenum);
1.94 markus 1219: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151 djm 1220:
1221: /* Collect arguments (separate to executable) */
1222: p = xstrdup(arg);
1223: len = strlen(p) + 1;
1224: while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1225: len += 1 + strlen(arg);
1226: p = xrealloc(p, 1, len);
1227: strlcat(p, " ", len);
1228: strlcat(p, arg, len);
1229: }
1230: options->subsystem_args[options->num_subsystems] = p;
1.94 markus 1231: options->num_subsystems++;
1232: break;
1.46 markus 1233:
1.94 markus 1234: case sMaxStartups:
1235: arg = strdelim(&cp);
1236: if (!arg || *arg == '\0')
1237: fatal("%s line %d: Missing MaxStartups spec.",
1.95 deraadt 1238: filename, linenum);
1.94 markus 1239: if ((n = sscanf(arg, "%d:%d:%d",
1240: &options->max_startups_begin,
1241: &options->max_startups_rate,
1242: &options->max_startups)) == 3) {
1243: if (options->max_startups_begin >
1244: options->max_startups ||
1245: options->max_startups_rate > 100 ||
1246: options->max_startups_rate < 1)
1.50 markus 1247: fatal("%s line %d: Illegal MaxStartups spec.",
1.87 stevesk 1248: filename, linenum);
1.94 markus 1249: } else if (n != 1)
1250: fatal("%s line %d: Illegal MaxStartups spec.",
1251: filename, linenum);
1252: else
1253: options->max_startups = options->max_startups_begin;
1254: break;
1.133 dtucker 1255:
1256: case sMaxAuthTries:
1257: intptr = &options->max_authtries;
1258: goto parse_int;
1.94 markus 1259:
1.180 djm 1260: case sMaxSessions:
1261: intptr = &options->max_sessions;
1262: goto parse_int;
1263:
1.94 markus 1264: case sBanner:
1265: charptr = &options->banner;
1266: goto parse_filename;
1.176 djm 1267:
1.94 markus 1268: /*
1269: * These options can contain %X options expanded at
1270: * connect time, so that you can specify paths like:
1271: *
1272: * AuthorizedKeysFile /etc/ssh_keys/%u
1273: */
1274: case sAuthorizedKeysFile:
1.219 djm 1275: if (*activep && options->num_authkeys_files == 0) {
1276: while ((arg = strdelim(&cp)) && *arg != '\0') {
1277: if (options->num_authkeys_files >=
1278: MAX_AUTHKEYS_FILES)
1279: fatal("%s line %d: "
1280: "too many authorized keys files.",
1281: filename, linenum);
1282: options->authorized_keys_files[
1283: options->num_authkeys_files++] =
1284: tilde_expand_filename(arg, getuid());
1285: }
1286: }
1287: return 0;
1288:
1.208 djm 1289: case sAuthorizedPrincipalsFile:
1290: charptr = &options->authorized_principals_file;
1.205 djm 1291: arg = strdelim(&cp);
1292: if (!arg || *arg == '\0')
1293: fatal("%s line %d: missing file name.",
1294: filename, linenum);
1295: if (*activep && *charptr == NULL) {
1.206 markus 1296: *charptr = tilde_expand_filename(arg, getuid());
1.205 djm 1297: /* increase optional counter */
1298: if (intptr != NULL)
1299: *intptr = *intptr + 1;
1300: }
1301: break;
1.94 markus 1302:
1303: case sClientAliveInterval:
1304: intptr = &options->client_alive_interval;
1305: goto parse_time;
1306:
1307: case sClientAliveCountMax:
1308: intptr = &options->client_alive_count_max;
1309: goto parse_int;
1.131 djm 1310:
1311: case sAcceptEnv:
1312: while ((arg = strdelim(&cp)) && *arg != '\0') {
1313: if (strchr(arg, '=') != NULL)
1314: fatal("%s line %d: Invalid environment name.",
1315: filename, linenum);
1316: if (options->num_accept_env >= MAX_ACCEPT_ENV)
1317: fatal("%s line %d: too many allow env.",
1318: filename, linenum);
1.153 dtucker 1319: if (!*activep)
1.227 markus 1320: continue;
1.131 djm 1321: options->accept_env[options->num_accept_env++] =
1322: xstrdup(arg);
1323: }
1324: break;
1.145 reyk 1325:
1326: case sPermitTunnel:
1327: intptr = &options->permit_tun;
1.146 reyk 1328: arg = strdelim(&cp);
1329: if (!arg || *arg == '\0')
1330: fatal("%s line %d: Missing yes/point-to-point/"
1331: "ethernet/no argument.", filename, linenum);
1.182 dtucker 1332: value = -1;
1333: for (i = 0; tunmode_desc[i].val != -1; i++)
1334: if (strcmp(tunmode_desc[i].text, arg) == 0) {
1335: value = tunmode_desc[i].val;
1336: break;
1337: }
1338: if (value == -1)
1.146 reyk 1339: fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1340: "no argument: %s", filename, linenum, arg);
1341: if (*intptr == -1)
1342: *intptr = value;
1343: break;
1.94 markus 1344:
1.153 dtucker 1345: case sMatch:
1346: if (cmdline)
1347: fatal("Match directive not supported as a command-line "
1348: "option");
1.226 dtucker 1349: value = match_cfg_line(&cp, linenum, connectinfo);
1.153 dtucker 1350: if (value < 0)
1351: fatal("%s line %d: Bad Match condition", filename,
1352: linenum);
1353: *activep = value;
1.156 dtucker 1354: break;
1355:
1356: case sPermitOpen:
1357: arg = strdelim(&cp);
1358: if (!arg || *arg == '\0')
1359: fatal("%s line %d: missing PermitOpen specification",
1360: filename, linenum);
1.167 dtucker 1361: n = options->num_permitted_opens; /* modified later */
1.156 dtucker 1362: if (strcmp(arg, "any") == 0) {
1.167 dtucker 1363: if (*activep && n == -1) {
1.156 dtucker 1364: channel_clear_adm_permitted_opens();
1.159 dtucker 1365: options->num_permitted_opens = 0;
1.224 dtucker 1366: }
1367: break;
1368: }
1369: if (strcmp(arg, "none") == 0) {
1370: if (*activep && n == -1) {
1371: channel_clear_adm_permitted_opens();
1372: options->num_permitted_opens = 1;
1373: channel_disable_adm_local_opens();
1.159 dtucker 1374: }
1.156 dtucker 1375: break;
1376: }
1.166 dtucker 1377: if (*activep && n == -1)
1378: channel_clear_adm_permitted_opens();
1.159 dtucker 1379: for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1380: p = hpdelim(&arg);
1381: if (p == NULL)
1382: fatal("%s line %d: missing host in PermitOpen",
1383: filename, linenum);
1384: p = cleanhostname(p);
1.223 dtucker 1385: if (arg == NULL || ((port = permitopen_port(arg)) < 0))
1.159 dtucker 1386: fatal("%s line %d: bad port number in "
1387: "PermitOpen", filename, linenum);
1.166 dtucker 1388: if (*activep && n == -1)
1.159 dtucker 1389: options->num_permitted_opens =
1390: channel_add_adm_permitted_opens(p, port);
1391: }
1.153 dtucker 1392: break;
1393:
1.158 dtucker 1394: case sForceCommand:
1395: if (cp == NULL)
1396: fatal("%.200s line %d: Missing argument.", filename,
1397: linenum);
1398: len = strspn(cp, WHITESPACE);
1399: if (*activep && options->adm_forced_command == NULL)
1400: options->adm_forced_command = xstrdup(cp + len);
1401: return 0;
1402:
1.176 djm 1403: case sChrootDirectory:
1404: charptr = &options->chroot_directory;
1.177 djm 1405:
1406: arg = strdelim(&cp);
1407: if (!arg || *arg == '\0')
1408: fatal("%s line %d: missing file name.",
1409: filename, linenum);
1410: if (*activep && *charptr == NULL)
1411: *charptr = xstrdup(arg);
1412: break;
1.176 djm 1413:
1.204 djm 1414: case sTrustedUserCAKeys:
1415: charptr = &options->trusted_user_ca_keys;
1416: goto parse_filename;
1417:
1418: case sRevokedKeys:
1419: charptr = &options->revoked_keys_file;
1420: goto parse_filename;
1421:
1.213 djm 1422: case sIPQoS:
1423: arg = strdelim(&cp);
1424: if ((value = parse_ipqos(arg)) == -1)
1425: fatal("%s line %d: Bad IPQoS value: %s",
1426: filename, linenum, arg);
1427: arg = strdelim(&cp);
1428: if (arg == NULL)
1429: value2 = value;
1430: else if ((value2 = parse_ipqos(arg)) == -1)
1431: fatal("%s line %d: Bad IPQoS value: %s",
1432: filename, linenum, arg);
1433: if (*activep) {
1434: options->ip_qos_interactive = value;
1435: options->ip_qos_bulk = value2;
1436: }
1437: break;
1438:
1.225 djm 1439: case sVersionAddendum:
1440: if (cp == NULL)
1441: fatal("%.200s line %d: Missing argument.", filename,
1442: linenum);
1443: len = strspn(cp, WHITESPACE);
1444: if (*activep && options->version_addendum == NULL) {
1445: if (strcasecmp(cp + len, "none") == 0)
1446: options->version_addendum = xstrdup("");
1447: else if (strchr(cp + len, '\r') != NULL)
1448: fatal("%.200s line %d: Invalid argument",
1449: filename, linenum);
1450: else
1451: options->version_addendum = xstrdup(cp + len);
1452: }
1453: return 0;
1454:
1.94 markus 1455: case sDeprecated:
1.117 itojun 1456: logit("%s line %d: Deprecated option %s",
1.121 jakob 1457: filename, linenum, arg);
1458: while (arg)
1459: arg = strdelim(&cp);
1460: break;
1461:
1462: case sUnsupported:
1463: logit("%s line %d: Unsupported option %s",
1.94 markus 1464: filename, linenum, arg);
1465: while (arg)
1466: arg = strdelim(&cp);
1467: break;
1468:
1469: default:
1470: fatal("%s line %d: Missing handler for opcode %s (%d)",
1471: filename, linenum, arg, opcode);
1472: }
1473: if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1474: fatal("%s line %d: garbage at end of line; \"%.200s\".",
1475: filename, linenum, arg);
1476: return 0;
1477: }
1478:
1479: /* Reads the server configuration file. */
1.25 markus 1480:
1.94 markus 1481: void
1.134 djm 1482: load_server_config(const char *filename, Buffer *conf)
1.94 markus 1483: {
1.134 djm 1484: char line[1024], *cp;
1.94 markus 1485: FILE *f;
1.81 stevesk 1486:
1.134 djm 1487: debug2("%s: filename %s", __func__, filename);
1488: if ((f = fopen(filename, "r")) == NULL) {
1.94 markus 1489: perror(filename);
1490: exit(1);
1491: }
1.134 djm 1492: buffer_clear(conf);
1493: while (fgets(line, sizeof(line), f)) {
1494: /*
1495: * Trim out comments and strip whitespace
1.135 deraadt 1496: * NB - preserve newlines, they are needed to reproduce
1.134 djm 1497: * line numbers later for error messages
1498: */
1499: if ((cp = strchr(line, '#')) != NULL)
1500: memcpy(cp, "\n", 2);
1501: cp = line + strspn(line, " \t\r");
1502:
1503: buffer_append(conf, cp, strlen(cp));
1504: }
1505: buffer_append(conf, "\0", 1);
1506: fclose(f);
1507: debug2("%s: done config len = %d", __func__, buffer_len(conf));
1508: }
1509:
1510: void
1.226 dtucker 1511: parse_server_match_config(ServerOptions *options,
1512: struct connection_info *connectinfo)
1.153 dtucker 1513: {
1514: ServerOptions mo;
1515:
1516: initialize_server_options(&mo);
1.226 dtucker 1517: parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
1.168 dtucker 1518: copy_set_server_options(options, &mo, 0);
1.153 dtucker 1519: }
1520:
1.226 dtucker 1521: int parse_server_match_testspec(struct connection_info *ci, char *spec)
1522: {
1523: char *p;
1524:
1525: while ((p = strsep(&spec, ",")) && *p != '\0') {
1526: if (strncmp(p, "addr=", 5) == 0) {
1527: ci->address = xstrdup(p + 5);
1528: } else if (strncmp(p, "host=", 5) == 0) {
1529: ci->host = xstrdup(p + 5);
1530: } else if (strncmp(p, "user=", 5) == 0) {
1531: ci->user = xstrdup(p + 5);
1532: } else if (strncmp(p, "laddr=", 6) == 0) {
1533: ci->laddress = xstrdup(p + 6);
1534: } else if (strncmp(p, "lport=", 6) == 0) {
1535: ci->lport = a2port(p + 6);
1536: if (ci->lport == -1) {
1537: fprintf(stderr, "Invalid port '%s' in test mode"
1538: " specification %s\n", p+6, p);
1539: return -1;
1540: }
1541: } else {
1542: fprintf(stderr, "Invalid test mode specification %s\n",
1543: p);
1544: return -1;
1545: }
1546: }
1547: return 0;
1548: }
1549:
1550: /*
1551: * returns 1 for a complete spec, 0 for partial spec and -1 for an
1552: * empty spec.
1553: */
1554: int server_match_spec_complete(struct connection_info *ci)
1555: {
1556: if (ci->user && ci->host && ci->address)
1557: return 1; /* complete */
1558: if (!ci->user && !ci->host && !ci->address)
1559: return -1; /* empty */
1560: return 0; /* partial */
1561: }
1562:
1.168 dtucker 1563: /* Helper macros */
1564: #define M_CP_INTOPT(n) do {\
1565: if (src->n != -1) \
1566: dst->n = src->n; \
1567: } while (0)
1568: #define M_CP_STROPT(n) do {\
1569: if (src->n != NULL) { \
1570: if (dst->n != NULL) \
1571: xfree(dst->n); \
1572: dst->n = src->n; \
1573: } \
1574: } while(0)
1.219 djm 1575: #define M_CP_STRARRAYOPT(n, num_n) do {\
1576: if (src->num_n != 0) { \
1577: for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1578: dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1579: } \
1580: } while(0)
1.168 dtucker 1581:
1582: /*
1583: * Copy any supported values that are set.
1584: *
1.195 jj 1585: * If the preauth flag is set, we do not bother copying the string or
1.168 dtucker 1586: * array values that are not used pre-authentication, because any that we
1587: * do use must be explictly sent in mm_getpwnamallow().
1588: */
1.153 dtucker 1589: void
1.168 dtucker 1590: copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1.153 dtucker 1591: {
1.168 dtucker 1592: M_CP_INTOPT(password_authentication);
1593: M_CP_INTOPT(gss_authentication);
1594: M_CP_INTOPT(rsa_authentication);
1595: M_CP_INTOPT(pubkey_authentication);
1596: M_CP_INTOPT(kerberos_authentication);
1597: M_CP_INTOPT(hostbased_authentication);
1.209 djm 1598: M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1.168 dtucker 1599: M_CP_INTOPT(kbd_interactive_authentication);
1.190 djm 1600: M_CP_INTOPT(zero_knowledge_password_authentication);
1.175 dtucker 1601: M_CP_INTOPT(permit_root_login);
1.188 djm 1602: M_CP_INTOPT(permit_empty_passwd);
1.168 dtucker 1603:
1604: M_CP_INTOPT(allow_tcp_forwarding);
1.178 pyr 1605: M_CP_INTOPT(allow_agent_forwarding);
1.209 djm 1606: M_CP_INTOPT(permit_tun);
1.168 dtucker 1607: M_CP_INTOPT(gateway_ports);
1608: M_CP_INTOPT(x11_display_offset);
1609: M_CP_INTOPT(x11_forwarding);
1610: M_CP_INTOPT(x11_use_localhost);
1.180 djm 1611: M_CP_INTOPT(max_sessions);
1.184 dtucker 1612: M_CP_INTOPT(max_authtries);
1.213 djm 1613: M_CP_INTOPT(ip_qos_interactive);
1614: M_CP_INTOPT(ip_qos_bulk);
1.168 dtucker 1615:
1.218 djm 1616: /* See comment in servconf.h */
1617: COPY_MATCH_STRING_OPTS();
1.216 djm 1618:
1.217 dtucker 1619: /*
1620: * The only things that should be below this point are string options
1621: * which are only used after authentication.
1622: */
1.168 dtucker 1623: if (preauth)
1624: return;
1.219 djm 1625:
1.168 dtucker 1626: M_CP_STROPT(adm_forced_command);
1.176 djm 1627: M_CP_STROPT(chroot_directory);
1.153 dtucker 1628: }
1.168 dtucker 1629:
1630: #undef M_CP_INTOPT
1631: #undef M_CP_STROPT
1.219 djm 1632: #undef M_CP_STRARRAYOPT
1.153 dtucker 1633:
1634: void
1635: parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1.226 dtucker 1636: struct connection_info *connectinfo)
1.134 djm 1637: {
1.153 dtucker 1638: int active, linenum, bad_options = 0;
1.136 dtucker 1639: char *cp, *obuf, *cbuf;
1.134 djm 1640:
1641: debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1642:
1.136 dtucker 1643: obuf = cbuf = xstrdup(buffer_ptr(conf));
1.226 dtucker 1644: active = connectinfo ? 0 : 1;
1.137 dtucker 1645: linenum = 1;
1.140 deraadt 1646: while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134 djm 1647: if (process_server_config_line(options, cp, filename,
1.226 dtucker 1648: linenum++, &active, connectinfo) != 0)
1.94 markus 1649: bad_options++;
1.1 deraadt 1650: }
1.136 dtucker 1651: xfree(obuf);
1.78 stevesk 1652: if (bad_options > 0)
1653: fatal("%s: terminating, %d bad configuration options",
1654: filename, bad_options);
1.182 dtucker 1655: }
1656:
1657: static const char *
1.221 djm 1658: fmt_multistate_int(int val, const struct multistate *m)
1659: {
1660: u_int i;
1661:
1662: for (i = 0; m[i].key != NULL; i++) {
1663: if (m[i].value == val)
1664: return m[i].key;
1665: }
1666: return "UNKNOWN";
1667: }
1668:
1669: static const char *
1.182 dtucker 1670: fmt_intarg(ServerOpCodes code, int val)
1671: {
1.221 djm 1672: if (val == -1)
1673: return "unset";
1674: switch (code) {
1675: case sAddressFamily:
1676: return fmt_multistate_int(val, multistate_addressfamily);
1677: case sPermitRootLogin:
1678: return fmt_multistate_int(val, multistate_permitrootlogin);
1679: case sGatewayPorts:
1680: return fmt_multistate_int(val, multistate_gatewayports);
1681: case sCompression:
1682: return fmt_multistate_int(val, multistate_compression);
1.222 djm 1683: case sUsePrivilegeSeparation:
1684: return fmt_multistate_int(val, multistate_privsep);
1.221 djm 1685: case sProtocol:
1.182 dtucker 1686: switch (val) {
1687: case SSH_PROTO_1:
1688: return "1";
1689: case SSH_PROTO_2:
1690: return "2";
1691: case (SSH_PROTO_1|SSH_PROTO_2):
1692: return "2,1";
1693: default:
1694: return "UNKNOWN";
1695: }
1.221 djm 1696: default:
1697: switch (val) {
1698: case 0:
1699: return "no";
1700: case 1:
1701: return "yes";
1702: default:
1703: return "UNKNOWN";
1704: }
1.182 dtucker 1705: }
1706: }
1707:
1708: static const char *
1709: lookup_opcode_name(ServerOpCodes code)
1710: {
1711: u_int i;
1712:
1713: for (i = 0; keywords[i].name != NULL; i++)
1714: if (keywords[i].opcode == code)
1715: return(keywords[i].name);
1716: return "UNKNOWN";
1717: }
1718:
1719: static void
1720: dump_cfg_int(ServerOpCodes code, int val)
1721: {
1722: printf("%s %d\n", lookup_opcode_name(code), val);
1723: }
1724:
1725: static void
1726: dump_cfg_fmtint(ServerOpCodes code, int val)
1727: {
1728: printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1729: }
1730:
1731: static void
1732: dump_cfg_string(ServerOpCodes code, const char *val)
1733: {
1734: if (val == NULL)
1735: return;
1736: printf("%s %s\n", lookup_opcode_name(code), val);
1737: }
1738:
1739: static void
1740: dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1741: {
1742: u_int i;
1743:
1744: for (i = 0; i < count; i++)
1.219 djm 1745: printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1746: }
1747:
1748: static void
1749: dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1750: {
1751: u_int i;
1752:
1753: printf("%s", lookup_opcode_name(code));
1754: for (i = 0; i < count; i++)
1755: printf(" %s", vals[i]);
1756: printf("\n");
1.182 dtucker 1757: }
1758:
1759: void
1760: dump_config(ServerOptions *o)
1761: {
1762: u_int i;
1763: int ret;
1764: struct addrinfo *ai;
1765: char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1766:
1767: /* these are usually at the top of the config */
1768: for (i = 0; i < o->num_ports; i++)
1769: printf("port %d\n", o->ports[i]);
1770: dump_cfg_fmtint(sProtocol, o->protocol);
1771: dump_cfg_fmtint(sAddressFamily, o->address_family);
1772:
1773: /* ListenAddress must be after Port */
1774: for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1775: if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1776: sizeof(addr), port, sizeof(port),
1777: NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1778: error("getnameinfo failed: %.100s",
1779: (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1780: strerror(errno));
1781: } else {
1782: if (ai->ai_family == AF_INET6)
1783: printf("listenaddress [%s]:%s\n", addr, port);
1784: else
1785: printf("listenaddress %s:%s\n", addr, port);
1786: }
1787: }
1788:
1789: /* integer arguments */
1790: dump_cfg_int(sServerKeyBits, o->server_key_bits);
1791: dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1792: dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1793: dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1794: dump_cfg_int(sMaxAuthTries, o->max_authtries);
1.189 djm 1795: dump_cfg_int(sMaxSessions, o->max_sessions);
1.182 dtucker 1796: dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1797: dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1798:
1799: /* formatted integer arguments */
1800: dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1801: dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1802: dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1803: dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1804: dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1805: dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1806: o->hostbased_uses_name_from_packet_only);
1807: dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1808: dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
1.187 djm 1809: #ifdef KRB5
1.182 dtucker 1810: dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1811: dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1812: dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
1813: dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
1.187 djm 1814: #endif
1815: #ifdef GSSAPI
1.182 dtucker 1816: dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1817: dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
1.190 djm 1818: #endif
1819: #ifdef JPAKE
1820: dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1821: o->zero_knowledge_password_authentication);
1.187 djm 1822: #endif
1.182 dtucker 1823: dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1824: dump_cfg_fmtint(sKbdInteractiveAuthentication,
1825: o->kbd_interactive_authentication);
1826: dump_cfg_fmtint(sChallengeResponseAuthentication,
1827: o->challenge_response_authentication);
1828: dump_cfg_fmtint(sPrintMotd, o->print_motd);
1829: dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1830: dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
1831: dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1832: dump_cfg_fmtint(sStrictModes, o->strict_modes);
1833: dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
1834: dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
1835: dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
1836: dump_cfg_fmtint(sUseLogin, o->use_login);
1837: dump_cfg_fmtint(sCompression, o->compression);
1838: dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
1839: dump_cfg_fmtint(sUseDNS, o->use_dns);
1840: dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1841: dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1842:
1843: /* string arguments */
1844: dump_cfg_string(sPidFile, o->pid_file);
1845: dump_cfg_string(sXAuthLocation, o->xauth_location);
1846: dump_cfg_string(sCiphers, o->ciphers);
1847: dump_cfg_string(sMacs, o->macs);
1848: dump_cfg_string(sBanner, o->banner);
1849: dump_cfg_string(sForceCommand, o->adm_forced_command);
1.201 dtucker 1850: dump_cfg_string(sChrootDirectory, o->chroot_directory);
1.204 djm 1851: dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
1852: dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
1.208 djm 1853: dump_cfg_string(sAuthorizedPrincipalsFile,
1854: o->authorized_principals_file);
1.225 djm 1855: dump_cfg_string(sVersionAddendum, o->version_addendum);
1.182 dtucker 1856:
1857: /* string arguments requiring a lookup */
1858: dump_cfg_string(sLogLevel, log_level_name(o->log_level));
1859: dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
1860:
1861: /* string array arguments */
1.219 djm 1862: dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
1863: o->authorized_keys_files);
1.182 dtucker 1864: dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
1865: o->host_key_files);
1.203 djm 1866: dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
1867: o->host_cert_files);
1.182 dtucker 1868: dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
1869: dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
1870: dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
1871: dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
1872: dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1873:
1874: /* other arguments */
1875: for (i = 0; i < o->num_subsystems; i++)
1876: printf("subsystem %s %s\n", o->subsystem_name[i],
1877: o->subsystem_args[i]);
1878:
1879: printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
1880: o->max_startups_rate, o->max_startups);
1881:
1882: for (i = 0; tunmode_desc[i].val != -1; i++)
1883: if (tunmode_desc[i].val == o->permit_tun) {
1884: s = tunmode_desc[i].text;
1885: break;
1886: }
1887: dump_cfg_string(sPermitTunnel, s);
1.213 djm 1888:
1.214 stevesk 1889: printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
1890: printf("%s\n", iptos2str(o->ip_qos_bulk));
1.182 dtucker 1891:
1892: channel_print_adm_permitted_opens();
1.1 deraadt 1893: }