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