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