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