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