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