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