Annotation of src/usr.bin/ssh/servconf.c, Revision 1.153
1.153 ! dtucker 1: /* $OpenBSD: servconf.c,v 1.152 2006/07/08 21:47:12 stevesk 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:
13: #include "includes.h"
1.152 stevesk 14:
15: #include <sys/types.h>
16: #include <sys/socket.h>
1.1 deraadt 17:
18: #include "ssh.h"
1.62 markus 19: #include "log.h"
1.1 deraadt 20: #include "servconf.h"
21: #include "xmalloc.h"
1.33 markus 22: #include "compat.h"
1.60 markus 23: #include "pathnames.h"
1.62 markus 24: #include "misc.h"
25: #include "cipher.h"
1.66 markus 26: #include "kex.h"
27: #include "mac.h"
1.153 ! dtucker 28: #include "match.h"
1.1 deraadt 29:
1.84 itojun 30: static void add_listen_addr(ServerOptions *, char *, u_short);
31: static void add_one_listen_addr(ServerOptions *, char *, u_short);
1.29 markus 32:
1.102 provos 33: /* Use of privilege separation or not */
34: extern int use_privsep;
1.153 ! dtucker 35: extern Buffer cfg;
1.62 markus 36:
1.1 deraadt 37: /* Initializes the server options to their default values. */
38:
1.34 markus 39: void
1.25 markus 40: initialize_server_options(ServerOptions *options)
1.1 deraadt 41: {
1.25 markus 42: memset(options, 0, sizeof(*options));
1.29 markus 43: options->num_ports = 0;
44: options->ports_from_cmdline = 0;
45: options->listen_addrs = NULL;
1.138 djm 46: options->address_family = -1;
1.54 markus 47: options->num_host_key_files = 0;
1.36 markus 48: options->pid_file = NULL;
1.25 markus 49: options->server_key_bits = -1;
50: options->login_grace_time = -1;
51: options->key_regeneration_time = -1;
1.67 markus 52: options->permit_root_login = PERMIT_NOT_SET;
1.25 markus 53: options->ignore_rhosts = -1;
54: options->ignore_user_known_hosts = -1;
55: options->print_motd = -1;
1.72 stevesk 56: options->print_lastlog = -1;
1.25 markus 57: options->x11_forwarding = -1;
58: options->x11_display_offset = -1;
1.99 stevesk 59: options->x11_use_localhost = -1;
1.42 markus 60: options->xauth_location = NULL;
1.25 markus 61: options->strict_modes = -1;
1.129 markus 62: options->tcp_keep_alive = -1;
1.101 markus 63: options->log_facility = SYSLOG_FACILITY_NOT_SET;
64: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.25 markus 65: options->rhosts_rsa_authentication = -1;
1.75 markus 66: options->hostbased_authentication = -1;
67: options->hostbased_uses_name_from_packet_only = -1;
1.25 markus 68: options->rsa_authentication = -1;
1.54 markus 69: options->pubkey_authentication = -1;
1.25 markus 70: options->kerberos_authentication = -1;
71: options->kerberos_or_local_passwd = -1;
72: options->kerberos_ticket_cleanup = -1;
1.130 jakob 73: options->kerberos_get_afs_token = -1;
1.125 markus 74: options->gss_authentication=-1;
75: options->gss_cleanup_creds = -1;
1.25 markus 76: options->password_authentication = -1;
1.52 markus 77: options->kbd_interactive_authentication = -1;
1.80 markus 78: options->challenge_response_authentication = -1;
1.25 markus 79: options->permit_empty_passwd = -1;
1.113 markus 80: options->permit_user_env = -1;
1.25 markus 81: options->use_login = -1;
1.111 markus 82: options->compression = -1;
1.53 markus 83: options->allow_tcp_forwarding = -1;
1.25 markus 84: options->num_allow_users = 0;
85: options->num_deny_users = 0;
86: options->num_allow_groups = 0;
87: options->num_deny_groups = 0;
1.33 markus 88: options->ciphers = NULL;
1.66 markus 89: options->macs = NULL;
1.33 markus 90: options->protocol = SSH_PROTO_UNKNOWN;
1.38 markus 91: options->gateway_ports = -1;
1.43 jakob 92: options->num_subsystems = 0;
1.50 markus 93: options->max_startups_begin = -1;
94: options->max_startups_rate = -1;
1.46 markus 95: options->max_startups = -1;
1.133 dtucker 96: options->max_authtries = -1;
1.57 markus 97: options->banner = NULL;
1.122 markus 98: options->use_dns = -1;
1.77 beck 99: options->client_alive_interval = -1;
100: options->client_alive_count_max = -1;
1.82 markus 101: options->authorized_keys_file = NULL;
102: options->authorized_keys_file2 = NULL;
1.131 djm 103: options->num_accept_env = 0;
1.145 reyk 104: options->permit_tun = -1;
1.1 deraadt 105: }
106:
1.34 markus 107: void
1.25 markus 108: fill_default_server_options(ServerOptions *options)
1.1 deraadt 109: {
1.54 markus 110: if (options->protocol == SSH_PROTO_UNKNOWN)
111: options->protocol = SSH_PROTO_1|SSH_PROTO_2;
112: if (options->num_host_key_files == 0) {
113: /* fill default hostkeys for protocols */
114: if (options->protocol & SSH_PROTO_1)
1.97 stevesk 115: options->host_key_files[options->num_host_key_files++] =
116: _PATH_HOST_KEY_FILE;
117: if (options->protocol & SSH_PROTO_2) {
118: options->host_key_files[options->num_host_key_files++] =
119: _PATH_HOST_RSA_KEY_FILE;
120: options->host_key_files[options->num_host_key_files++] =
121: _PATH_HOST_DSA_KEY_FILE;
122: }
1.54 markus 123: }
1.29 markus 124: if (options->num_ports == 0)
125: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
126: if (options->listen_addrs == NULL)
1.76 stevesk 127: add_listen_addr(options, NULL, 0);
1.36 markus 128: if (options->pid_file == NULL)
1.60 markus 129: options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
1.25 markus 130: if (options->server_key_bits == -1)
131: options->server_key_bits = 768;
132: if (options->login_grace_time == -1)
1.115 stevesk 133: options->login_grace_time = 120;
1.25 markus 134: if (options->key_regeneration_time == -1)
135: options->key_regeneration_time = 3600;
1.67 markus 136: if (options->permit_root_login == PERMIT_NOT_SET)
137: options->permit_root_login = PERMIT_YES;
1.25 markus 138: if (options->ignore_rhosts == -1)
1.30 markus 139: options->ignore_rhosts = 1;
1.25 markus 140: if (options->ignore_user_known_hosts == -1)
141: options->ignore_user_known_hosts = 0;
142: if (options->print_motd == -1)
143: options->print_motd = 1;
1.72 stevesk 144: if (options->print_lastlog == -1)
145: options->print_lastlog = 1;
1.25 markus 146: if (options->x11_forwarding == -1)
1.30 markus 147: options->x11_forwarding = 0;
1.25 markus 148: if (options->x11_display_offset == -1)
1.30 markus 149: options->x11_display_offset = 10;
1.99 stevesk 150: if (options->x11_use_localhost == -1)
151: options->x11_use_localhost = 1;
1.42 markus 152: if (options->xauth_location == NULL)
1.83 markus 153: options->xauth_location = _PATH_XAUTH;
1.25 markus 154: if (options->strict_modes == -1)
155: options->strict_modes = 1;
1.129 markus 156: if (options->tcp_keep_alive == -1)
157: options->tcp_keep_alive = 1;
1.101 markus 158: if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
1.25 markus 159: options->log_facility = SYSLOG_FACILITY_AUTH;
1.101 markus 160: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.58 markus 161: options->log_level = SYSLOG_LEVEL_INFO;
1.25 markus 162: if (options->rhosts_rsa_authentication == -1)
1.30 markus 163: options->rhosts_rsa_authentication = 0;
1.75 markus 164: if (options->hostbased_authentication == -1)
165: options->hostbased_authentication = 0;
166: if (options->hostbased_uses_name_from_packet_only == -1)
167: options->hostbased_uses_name_from_packet_only = 0;
1.25 markus 168: if (options->rsa_authentication == -1)
169: options->rsa_authentication = 1;
1.54 markus 170: if (options->pubkey_authentication == -1)
171: options->pubkey_authentication = 1;
1.25 markus 172: if (options->kerberos_authentication == -1)
1.107 markus 173: options->kerberos_authentication = 0;
1.25 markus 174: if (options->kerberos_or_local_passwd == -1)
175: options->kerberos_or_local_passwd = 1;
176: if (options->kerberos_ticket_cleanup == -1)
177: options->kerberos_ticket_cleanup = 1;
1.130 jakob 178: if (options->kerberos_get_afs_token == -1)
179: options->kerberos_get_afs_token = 0;
1.125 markus 180: if (options->gss_authentication == -1)
181: options->gss_authentication = 0;
182: if (options->gss_cleanup_creds == -1)
183: options->gss_cleanup_creds = 1;
1.25 markus 184: if (options->password_authentication == -1)
185: options->password_authentication = 1;
1.52 markus 186: if (options->kbd_interactive_authentication == -1)
187: options->kbd_interactive_authentication = 0;
1.80 markus 188: if (options->challenge_response_authentication == -1)
189: options->challenge_response_authentication = 1;
1.25 markus 190: if (options->permit_empty_passwd == -1)
1.30 markus 191: options->permit_empty_passwd = 0;
1.113 markus 192: if (options->permit_user_env == -1)
193: options->permit_user_env = 0;
1.25 markus 194: if (options->use_login == -1)
195: options->use_login = 0;
1.111 markus 196: if (options->compression == -1)
1.143 markus 197: options->compression = COMP_DELAYED;
1.53 markus 198: if (options->allow_tcp_forwarding == -1)
199: options->allow_tcp_forwarding = 1;
1.38 markus 200: if (options->gateway_ports == -1)
201: options->gateway_ports = 0;
1.46 markus 202: if (options->max_startups == -1)
203: options->max_startups = 10;
1.50 markus 204: if (options->max_startups_rate == -1)
205: options->max_startups_rate = 100; /* 100% */
206: if (options->max_startups_begin == -1)
207: options->max_startups_begin = options->max_startups;
1.133 dtucker 208: if (options->max_authtries == -1)
209: options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
1.122 markus 210: if (options->use_dns == -1)
211: options->use_dns = 1;
1.77 beck 212: if (options->client_alive_interval == -1)
1.95 deraadt 213: options->client_alive_interval = 0;
1.77 beck 214: if (options->client_alive_count_max == -1)
215: options->client_alive_count_max = 3;
1.90 markus 216: if (options->authorized_keys_file2 == NULL) {
217: /* authorized_keys_file2 falls back to authorized_keys_file */
218: if (options->authorized_keys_file != NULL)
219: options->authorized_keys_file2 = options->authorized_keys_file;
220: else
221: options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
222: }
223: if (options->authorized_keys_file == NULL)
224: options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
1.145 reyk 225: if (options->permit_tun == -1)
1.146 reyk 226: options->permit_tun = SSH_TUNMODE_NO;
1.102 provos 227:
1.110 markus 228: /* Turn privilege separation on by default */
1.102 provos 229: if (use_privsep == -1)
1.110 markus 230: use_privsep = 1;
1.1 deraadt 231: }
232:
233: /* Keyword tokens. */
1.25 markus 234: typedef enum {
235: sBadOption, /* == unknown option */
236: sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
237: sPermitRootLogin, sLogFacility, sLogLevel,
1.124 markus 238: sRhostsRSAAuthentication, sRSAAuthentication,
1.25 markus 239: sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.130 jakob 240: sKerberosGetAFSToken,
1.123 markus 241: sKerberosTgtPassing, sChallengeResponseAuthentication,
1.138 djm 242: sPasswordAuthentication, sKbdInteractiveAuthentication,
243: sListenAddress, sAddressFamily,
1.72 stevesk 244: sPrintMotd, sPrintLastLog, sIgnoreRhosts,
1.99 stevesk 245: sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
1.129 markus 246: sStrictModes, sEmptyPasswd, sTCPKeepAlive,
1.113 markus 247: sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
1.53 markus 248: sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.66 markus 249: sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
1.133 dtucker 250: sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
251: sMaxStartups, sMaxAuthTries,
1.122 markus 252: sBanner, sUseDNS, sHostbasedAuthentication,
1.95 deraadt 253: sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
1.89 jakob 254: sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
1.145 reyk 255: sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
1.153 ! dtucker 256: sMatch,
1.105 stevesk 257: sUsePrivilegeSeparation,
1.121 jakob 258: sDeprecated, sUnsupported
1.1 deraadt 259: } ServerOpCodes;
260:
1.153 ! dtucker 261: #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
! 262: #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
! 263: #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
! 264:
1.1 deraadt 265: /* Textual representation of the tokens. */
1.25 markus 266: static struct {
267: const char *name;
268: ServerOpCodes opcode;
1.153 ! dtucker 269: u_int flags;
1.25 markus 270: } keywords[] = {
1.153 ! dtucker 271: { "port", sPort, SSHCFG_GLOBAL },
! 272: { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
! 273: { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
! 274: { "pidfile", sPidFile, SSHCFG_GLOBAL },
! 275: { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
! 276: { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
! 277: { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
! 278: { "permitrootlogin", sPermitRootLogin, SSHCFG_GLOBAL },
! 279: { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
! 280: { "loglevel", sLogLevel, SSHCFG_GLOBAL },
! 281: { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
! 282: { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_GLOBAL },
! 283: { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_GLOBAL },
! 284: { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_GLOBAL },
! 285: { "rsaauthentication", sRSAAuthentication, SSHCFG_GLOBAL },
! 286: { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL },
! 287: { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
1.123 markus 288: #ifdef KRB5
1.153 ! dtucker 289: { "kerberosauthentication", sKerberosAuthentication, SSHCFG_GLOBAL },
! 290: { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
! 291: { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
! 292: { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
1.121 jakob 293: #else
1.153 ! dtucker 294: { "kerberosauthentication", sUnsupported, SSHCFG_GLOBAL },
! 295: { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
! 296: { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
! 297: { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
1.126 markus 298: #endif
1.153 ! dtucker 299: { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
! 300: { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
1.125 markus 301: #ifdef GSSAPI
1.153 ! dtucker 302: { "gssapiauthentication", sGssAuthentication, SSHCFG_GLOBAL },
! 303: { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
1.125 markus 304: #else
1.153 ! dtucker 305: { "gssapiauthentication", sUnsupported, SSHCFG_GLOBAL },
! 306: { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
1.125 markus 307: #endif
1.153 ! dtucker 308: { "passwordauthentication", sPasswordAuthentication, SSHCFG_GLOBAL },
! 309: { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_GLOBAL },
! 310: { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
! 311: { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
! 312: { "checkmail", sDeprecated, SSHCFG_GLOBAL },
! 313: { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
! 314: { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
! 315: { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
! 316: { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
! 317: { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
! 318: { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
! 319: { "x11forwarding", sX11Forwarding, SSHCFG_GLOBAL },
! 320: { "x11displayoffset", sX11DisplayOffset, SSHCFG_GLOBAL },
! 321: { "x11uselocalhost", sX11UseLocalhost, SSHCFG_GLOBAL },
! 322: { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
! 323: { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
! 324: { "permitemptypasswords", sEmptyPasswd, SSHCFG_GLOBAL },
! 325: { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
! 326: { "uselogin", sUseLogin, SSHCFG_GLOBAL },
! 327: { "compression", sCompression, SSHCFG_GLOBAL },
! 328: { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
! 329: { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
! 330: { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
! 331: { "allowusers", sAllowUsers, SSHCFG_GLOBAL },
! 332: { "denyusers", sDenyUsers, SSHCFG_GLOBAL },
! 333: { "allowgroups", sAllowGroups, SSHCFG_GLOBAL },
! 334: { "denygroups", sDenyGroups, SSHCFG_GLOBAL },
! 335: { "ciphers", sCiphers, SSHCFG_GLOBAL },
! 336: { "macs", sMacs, SSHCFG_GLOBAL },
! 337: { "protocol", sProtocol, SSHCFG_GLOBAL },
! 338: { "gatewayports", sGatewayPorts, SSHCFG_ALL },
! 339: { "subsystem", sSubsystem, SSHCFG_GLOBAL },
! 340: { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
! 341: { "maxauthtries", sMaxAuthTries, SSHCFG_GLOBAL },
! 342: { "banner", sBanner, SSHCFG_GLOBAL },
! 343: { "usedns", sUseDNS, SSHCFG_GLOBAL },
! 344: { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
! 345: { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
! 346: { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
! 347: { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
! 348: { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL },
! 349: { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL },
! 350: { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
! 351: { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
! 352: { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL },
! 353: { "match", sMatch, SSHCFG_ALL },
! 354: { NULL, sBadOption, 0 }
1.1 deraadt 355: };
356:
1.27 markus 357: /*
1.73 stevesk 358: * Returns the number of the token pointed to by cp or sBadOption.
1.27 markus 359: */
1.1 deraadt 360:
1.34 markus 361: static ServerOpCodes
1.25 markus 362: parse_token(const char *cp, const char *filename,
1.153 ! dtucker 363: int linenum, u_int *flags)
1.1 deraadt 364: {
1.55 markus 365: u_int i;
1.1 deraadt 366:
1.25 markus 367: for (i = 0; keywords[i].name; i++)
1.153 ! dtucker 368: if (strcasecmp(cp, keywords[i].name) == 0) {
! 369: *flags = keywords[i].flags;
1.25 markus 370: return keywords[i].opcode;
1.153 ! dtucker 371: }
1.25 markus 372:
1.78 stevesk 373: error("%s: line %d: Bad configuration option: %s",
374: filename, linenum, cp);
1.25 markus 375: return sBadOption;
1.1 deraadt 376: }
377:
1.84 itojun 378: static void
1.76 stevesk 379: add_listen_addr(ServerOptions *options, char *addr, u_short port)
1.74 stevesk 380: {
1.142 djm 381: u_int i;
1.74 stevesk 382:
383: if (options->num_ports == 0)
384: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
1.138 djm 385: if (options->address_family == -1)
386: options->address_family = AF_UNSPEC;
1.76 stevesk 387: if (port == 0)
1.74 stevesk 388: for (i = 0; i < options->num_ports; i++)
389: add_one_listen_addr(options, addr, options->ports[i]);
390: else
1.76 stevesk 391: add_one_listen_addr(options, addr, port);
1.74 stevesk 392: }
393:
1.84 itojun 394: static void
1.74 stevesk 395: add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
1.29 markus 396: {
397: struct addrinfo hints, *ai, *aitop;
398: char strport[NI_MAXSERV];
399: int gaierr;
400:
1.74 stevesk 401: memset(&hints, 0, sizeof(hints));
1.138 djm 402: hints.ai_family = options->address_family;
1.74 stevesk 403: hints.ai_socktype = SOCK_STREAM;
404: hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
1.112 deraadt 405: snprintf(strport, sizeof strport, "%u", port);
1.74 stevesk 406: if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
407: fatal("bad addr or host: %s (%s)",
408: addr ? addr : "<NULL>",
409: gai_strerror(gaierr));
410: for (ai = aitop; ai->ai_next; ai = ai->ai_next)
411: ;
412: ai->ai_next = options->listen_addrs;
413: options->listen_addrs = aitop;
1.29 markus 414: }
415:
1.153 ! dtucker 416: /*
! 417: * The strategy for the Match blocks is that the config file is parsed twice.
! 418: *
! 419: * The first time is at startup. activep is initialized to 1 and the
! 420: * directives in the global context are processed and acted on. Hitting a
! 421: * Match directive unsets activep and the directives inside the block are
! 422: * checked for syntax only.
! 423: *
! 424: * The second time is after a connection has been established but before
! 425: * authentication. activep is initialized to 2 and global config directives
! 426: * are ignored since they have already been processed. If the criteria in a
! 427: * Match block is met, activep is set and the subsequent directives
! 428: * processed and actioned until EOF or another Match block unsets it. Any
! 429: * options set are copied into the main server config.
! 430: *
! 431: * Potential additions/improvements:
! 432: * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
! 433: *
! 434: * - Add a Tag directive (idea from David Leonard) ala pf, eg:
! 435: * Match Address 192.168.0.*
! 436: * Tag trusted
! 437: * Match Group wheel
! 438: * Tag trusted
! 439: * Match Tag trusted
! 440: * AllowTcpForwarding yes
! 441: * GatewayPorts clientspecified
! 442: * [...]
! 443: *
! 444: * - Add a PermittedChannelRequests directive
! 445: * Match Group shell
! 446: * PermittedChannelRequests session,forwarded-tcpip
! 447: */
! 448:
! 449: static int
! 450: match_cfg_line(char **condition, int line, const char *user, const char *host,
! 451: const char *address)
! 452: {
! 453: int result = 1;
! 454: char *arg, *attrib, *cp = *condition;
! 455: size_t len;
! 456:
! 457: if (user == NULL)
! 458: debug3("checking syntax for 'Match %s'", cp);
! 459: else
! 460: debug3("checking match for '%s' user %s host %s addr %s", cp,
! 461: user ? user : "(null)", host ? host : "(null)",
! 462: address ? address : "(null)");
! 463:
! 464: while ((attrib = strdelim(&cp)) && *attrib != '\0') {
! 465: if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
! 466: error("Missing Match criteria for %s", attrib);
! 467: return -1;
! 468: }
! 469: len = strlen(arg);
! 470: if (strcasecmp(attrib, "user") == 0) {
! 471: if (!user) {
! 472: result = 0;
! 473: continue;
! 474: }
! 475: if (match_pattern_list(user, arg, len, 0) != 1)
! 476: result = 0;
! 477: else
! 478: debug("user %.100s matched 'User %.100s' at "
! 479: "line %d", user, arg, line);
! 480: } else if (strcasecmp(attrib, "host") == 0) {
! 481: if (!host) {
! 482: result = 0;
! 483: continue;
! 484: }
! 485: if (match_hostname(host, arg, len) != 1)
! 486: result = 0;
! 487: else
! 488: debug("connection from %.100s matched 'Host "
! 489: "%.100s' at line %d", host, arg, line);
! 490: } else if (strcasecmp(attrib, "address") == 0) {
! 491: debug("address '%s' arg '%s'", address, arg);
! 492: if (!address) {
! 493: result = 0;
! 494: continue;
! 495: }
! 496: if (match_hostname(address, arg, len) != 1)
! 497: result = 0;
! 498: else
! 499: debug("connection from %.100s matched 'Address "
! 500: "%.100s' at line %d", address, arg, line);
! 501: } else {
! 502: error("Unsupported Match attribute %s", attrib);
! 503: return -1;
! 504: }
! 505: }
! 506: if (user != NULL)
! 507: debug3("match %sfound", result ? "" : "not ");
! 508: *condition = cp;
! 509: return result;
! 510: }
! 511:
1.94 markus 512: int
513: process_server_config_line(ServerOptions *options, char *line,
1.153 ! dtucker 514: const char *filename, int linenum, int *activep, const char *user,
! 515: const char *host, const char *address)
1.1 deraadt 516: {
1.74 stevesk 517: char *cp, **charptr, *arg, *p;
1.153 ! dtucker 518: int cmdline = 0, *intptr, value, n;
1.25 markus 519: ServerOpCodes opcode;
1.139 djm 520: u_short port;
1.153 ! dtucker 521: u_int i, flags = 0;
1.151 djm 522: size_t len;
1.25 markus 523:
1.94 markus 524: cp = line;
1.148 dtucker 525: if ((arg = strdelim(&cp)) == NULL)
1.147 djm 526: return 0;
1.94 markus 527: /* Ignore leading whitespace */
528: if (*arg == '\0')
529: arg = strdelim(&cp);
530: if (!arg || !*arg || *arg == '#')
531: return 0;
532: intptr = NULL;
533: charptr = NULL;
1.153 ! dtucker 534: opcode = parse_token(arg, filename, linenum, &flags);
! 535:
! 536: if (activep == NULL) { /* We are processing a command line directive */
! 537: cmdline = 1;
! 538: activep = &cmdline;
! 539: }
! 540: if (*activep && opcode != sMatch)
! 541: debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
! 542: if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
! 543: if (user == NULL) {
! 544: fatal("%s line %d: Directive '%s' is not allowed "
! 545: "within a Match block", filename, linenum, arg);
! 546: } else { /* this is a directive we have already processed */
! 547: while (arg)
! 548: arg = strdelim(&cp);
! 549: return 0;
! 550: }
! 551: }
! 552:
1.94 markus 553: switch (opcode) {
554: case sBadOption:
555: return -1;
556: case sPort:
557: /* ignore ports from configfile if cmdline specifies ports */
558: if (options->ports_from_cmdline)
559: return 0;
560: if (options->listen_addrs != NULL)
561: fatal("%s line %d: ports must be specified before "
1.98 stevesk 562: "ListenAddress.", filename, linenum);
1.94 markus 563: if (options->num_ports >= MAX_PORTS)
564: fatal("%s line %d: too many ports.",
565: filename, linenum);
1.48 provos 566: arg = strdelim(&cp);
1.94 markus 567: if (!arg || *arg == '\0')
568: fatal("%s line %d: missing port number.",
569: filename, linenum);
570: options->ports[options->num_ports++] = a2port(arg);
571: if (options->ports[options->num_ports-1] == 0)
572: fatal("%s line %d: Badly formatted port number.",
573: filename, linenum);
574: break;
1.29 markus 575:
1.94 markus 576: case sServerKeyBits:
577: intptr = &options->server_key_bits;
1.25 markus 578: parse_int:
1.94 markus 579: arg = strdelim(&cp);
580: if (!arg || *arg == '\0')
581: fatal("%s line %d: missing integer value.",
582: filename, linenum);
583: value = atoi(arg);
1.153 ! dtucker 584: if (*activep && *intptr == -1)
1.94 markus 585: *intptr = value;
586: break;
1.25 markus 587:
1.94 markus 588: case sLoginGraceTime:
589: intptr = &options->login_grace_time;
1.81 stevesk 590: parse_time:
1.94 markus 591: arg = strdelim(&cp);
592: if (!arg || *arg == '\0')
593: fatal("%s line %d: missing time value.",
594: filename, linenum);
595: if ((value = convtime(arg)) == -1)
596: fatal("%s line %d: invalid time value.",
597: filename, linenum);
598: if (*intptr == -1)
599: *intptr = value;
600: break;
601:
602: case sKeyRegenerationTime:
603: intptr = &options->key_regeneration_time;
604: goto parse_time;
605:
606: case sListenAddress:
607: arg = strdelim(&cp);
1.139 djm 608: if (arg == NULL || *arg == '\0')
609: fatal("%s line %d: missing address",
1.94 markus 610: filename, linenum);
1.144 dtucker 611: /* check for bare IPv6 address: no "[]" and 2 or more ":" */
612: if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
613: && strchr(p+1, ':') != NULL) {
614: add_listen_addr(options, arg, 0);
615: break;
616: }
1.139 djm 617: p = hpdelim(&arg);
618: if (p == NULL)
619: fatal("%s line %d: bad address:port usage",
620: filename, linenum);
621: p = cleanhostname(p);
622: if (arg == NULL)
623: port = 0;
624: else if ((port = a2port(arg)) == 0)
625: fatal("%s line %d: bad port number", filename, linenum);
626:
627: add_listen_addr(options, p, port);
1.25 markus 628:
1.138 djm 629: break;
630:
631: case sAddressFamily:
632: arg = strdelim(&cp);
1.141 markus 633: if (!arg || *arg == '\0')
634: fatal("%s line %d: missing address family.",
635: filename, linenum);
1.138 djm 636: intptr = &options->address_family;
637: if (options->listen_addrs != NULL)
638: fatal("%s line %d: address family must be specified before "
639: "ListenAddress.", filename, linenum);
640: if (strcasecmp(arg, "inet") == 0)
641: value = AF_INET;
642: else if (strcasecmp(arg, "inet6") == 0)
643: value = AF_INET6;
644: else if (strcasecmp(arg, "any") == 0)
645: value = AF_UNSPEC;
646: else
647: fatal("%s line %d: unsupported address family \"%s\".",
648: filename, linenum, arg);
649: if (*intptr == -1)
650: *intptr = value;
1.94 markus 651: break;
652:
653: case sHostKeyFile:
654: intptr = &options->num_host_key_files;
655: if (*intptr >= MAX_HOSTKEYS)
656: fatal("%s line %d: too many host keys specified (max %d).",
657: filename, linenum, MAX_HOSTKEYS);
658: charptr = &options->host_key_files[*intptr];
659: parse_filename:
660: arg = strdelim(&cp);
661: if (!arg || *arg == '\0')
662: fatal("%s line %d: missing file name.",
663: filename, linenum);
1.153 ! dtucker 664: if (*activep && *charptr == NULL) {
1.94 markus 665: *charptr = tilde_expand_filename(arg, getuid());
666: /* increase optional counter */
667: if (intptr != NULL)
668: *intptr = *intptr + 1;
669: }
670: break;
1.76 stevesk 671:
1.94 markus 672: case sPidFile:
673: charptr = &options->pid_file;
674: goto parse_filename;
1.25 markus 675:
1.94 markus 676: case sPermitRootLogin:
677: intptr = &options->permit_root_login;
678: arg = strdelim(&cp);
679: if (!arg || *arg == '\0')
680: fatal("%s line %d: missing yes/"
681: "without-password/forced-commands-only/no "
682: "argument.", filename, linenum);
683: value = 0; /* silence compiler */
684: if (strcmp(arg, "without-password") == 0)
685: value = PERMIT_NO_PASSWD;
686: else if (strcmp(arg, "forced-commands-only") == 0)
687: value = PERMIT_FORCED_ONLY;
688: else if (strcmp(arg, "yes") == 0)
689: value = PERMIT_YES;
690: else if (strcmp(arg, "no") == 0)
691: value = PERMIT_NO;
692: else
693: fatal("%s line %d: Bad yes/"
694: "without-password/forced-commands-only/no "
695: "argument: %s", filename, linenum, arg);
696: if (*intptr == -1)
697: *intptr = value;
698: break;
1.36 markus 699:
1.94 markus 700: case sIgnoreRhosts:
701: intptr = &options->ignore_rhosts;
1.25 markus 702: parse_flag:
1.94 markus 703: arg = strdelim(&cp);
704: if (!arg || *arg == '\0')
705: fatal("%s line %d: missing yes/no argument.",
706: filename, linenum);
707: value = 0; /* silence compiler */
708: if (strcmp(arg, "yes") == 0)
709: value = 1;
710: else if (strcmp(arg, "no") == 0)
711: value = 0;
712: else
713: fatal("%s line %d: Bad yes/no argument: %s",
714: filename, linenum, arg);
1.153 ! dtucker 715: if (*activep && *intptr == -1)
1.94 markus 716: *intptr = value;
717: break;
718:
719: case sIgnoreUserKnownHosts:
720: intptr = &options->ignore_user_known_hosts;
721: goto parse_flag;
722:
723: case sRhostsRSAAuthentication:
724: intptr = &options->rhosts_rsa_authentication;
725: goto parse_flag;
726:
727: case sHostbasedAuthentication:
728: intptr = &options->hostbased_authentication;
729: goto parse_flag;
730:
731: case sHostbasedUsesNameFromPacketOnly:
732: intptr = &options->hostbased_uses_name_from_packet_only;
733: goto parse_flag;
734:
735: case sRSAAuthentication:
736: intptr = &options->rsa_authentication;
737: goto parse_flag;
738:
739: case sPubkeyAuthentication:
740: intptr = &options->pubkey_authentication;
741: goto parse_flag;
1.119 jakob 742:
1.94 markus 743: case sKerberosAuthentication:
744: intptr = &options->kerberos_authentication;
745: goto parse_flag;
746:
747: case sKerberosOrLocalPasswd:
748: intptr = &options->kerberos_or_local_passwd;
749: goto parse_flag;
750:
751: case sKerberosTicketCleanup:
752: intptr = &options->kerberos_ticket_cleanup;
1.130 jakob 753: goto parse_flag;
754:
755: case sKerberosGetAFSToken:
756: intptr = &options->kerberos_get_afs_token;
1.125 markus 757: goto parse_flag;
758:
759: case sGssAuthentication:
760: intptr = &options->gss_authentication;
761: goto parse_flag;
762:
763: case sGssCleanupCreds:
764: intptr = &options->gss_cleanup_creds;
1.94 markus 765: goto parse_flag;
766:
767: case sPasswordAuthentication:
768: intptr = &options->password_authentication;
769: goto parse_flag;
770:
771: case sKbdInteractiveAuthentication:
772: intptr = &options->kbd_interactive_authentication;
773: goto parse_flag;
774:
775: case sChallengeResponseAuthentication:
776: intptr = &options->challenge_response_authentication;
777: goto parse_flag;
778:
779: case sPrintMotd:
780: intptr = &options->print_motd;
781: goto parse_flag;
782:
783: case sPrintLastLog:
784: intptr = &options->print_lastlog;
785: goto parse_flag;
786:
787: case sX11Forwarding:
788: intptr = &options->x11_forwarding;
789: goto parse_flag;
790:
791: case sX11DisplayOffset:
792: intptr = &options->x11_display_offset;
793: goto parse_int;
1.99 stevesk 794:
795: case sX11UseLocalhost:
796: intptr = &options->x11_use_localhost;
797: goto parse_flag;
1.94 markus 798:
799: case sXAuthLocation:
800: charptr = &options->xauth_location;
801: goto parse_filename;
802:
803: case sStrictModes:
804: intptr = &options->strict_modes;
805: goto parse_flag;
806:
1.129 markus 807: case sTCPKeepAlive:
808: intptr = &options->tcp_keep_alive;
1.94 markus 809: goto parse_flag;
810:
811: case sEmptyPasswd:
812: intptr = &options->permit_empty_passwd;
1.113 markus 813: goto parse_flag;
814:
815: case sPermitUserEnvironment:
816: intptr = &options->permit_user_env;
1.94 markus 817: goto parse_flag;
818:
819: case sUseLogin:
820: intptr = &options->use_login;
1.111 markus 821: goto parse_flag;
822:
823: case sCompression:
824: intptr = &options->compression;
1.143 markus 825: arg = strdelim(&cp);
826: if (!arg || *arg == '\0')
827: fatal("%s line %d: missing yes/no/delayed "
828: "argument.", filename, linenum);
829: value = 0; /* silence compiler */
830: if (strcmp(arg, "delayed") == 0)
831: value = COMP_DELAYED;
832: else if (strcmp(arg, "yes") == 0)
833: value = COMP_ZLIB;
834: else if (strcmp(arg, "no") == 0)
835: value = COMP_NONE;
836: else
837: fatal("%s line %d: Bad yes/no/delayed "
838: "argument: %s", filename, linenum, arg);
839: if (*intptr == -1)
840: *intptr = value;
841: break;
1.94 markus 842:
843: case sGatewayPorts:
844: intptr = &options->gateway_ports;
1.139 djm 845: arg = strdelim(&cp);
846: if (!arg || *arg == '\0')
847: fatal("%s line %d: missing yes/no/clientspecified "
848: "argument.", filename, linenum);
849: value = 0; /* silence compiler */
850: if (strcmp(arg, "clientspecified") == 0)
851: value = 2;
852: else if (strcmp(arg, "yes") == 0)
853: value = 1;
854: else if (strcmp(arg, "no") == 0)
855: value = 0;
856: else
857: fatal("%s line %d: Bad yes/no/clientspecified "
858: "argument: %s", filename, linenum, arg);
859: if (*intptr == -1)
860: *intptr = value;
861: break;
1.25 markus 862:
1.122 markus 863: case sUseDNS:
864: intptr = &options->use_dns;
1.94 markus 865: goto parse_flag;
1.53 markus 866:
1.94 markus 867: case sLogFacility:
868: intptr = (int *) &options->log_facility;
869: arg = strdelim(&cp);
870: value = log_facility_number(arg);
1.101 markus 871: if (value == SYSLOG_FACILITY_NOT_SET)
1.94 markus 872: fatal("%.200s line %d: unsupported log facility '%s'",
873: filename, linenum, arg ? arg : "<NONE>");
874: if (*intptr == -1)
875: *intptr = (SyslogFacility) value;
876: break;
1.25 markus 877:
1.94 markus 878: case sLogLevel:
879: intptr = (int *) &options->log_level;
880: arg = strdelim(&cp);
881: value = log_level_number(arg);
1.101 markus 882: if (value == SYSLOG_LEVEL_NOT_SET)
1.94 markus 883: fatal("%.200s line %d: unsupported log level '%s'",
884: filename, linenum, arg ? arg : "<NONE>");
885: if (*intptr == -1)
886: *intptr = (LogLevel) value;
887: break;
888:
889: case sAllowTcpForwarding:
890: intptr = &options->allow_tcp_forwarding;
891: goto parse_flag;
1.102 provos 892:
893: case sUsePrivilegeSeparation:
894: intptr = &use_privsep;
895: goto parse_flag;
1.94 markus 896:
897: case sAllowUsers:
898: while ((arg = strdelim(&cp)) && *arg != '\0') {
899: if (options->num_allow_users >= MAX_ALLOW_USERS)
900: fatal("%s line %d: too many allow users.",
901: filename, linenum);
1.112 deraadt 902: options->allow_users[options->num_allow_users++] =
903: xstrdup(arg);
1.94 markus 904: }
905: break;
1.25 markus 906:
1.94 markus 907: case sDenyUsers:
908: while ((arg = strdelim(&cp)) && *arg != '\0') {
909: if (options->num_deny_users >= MAX_DENY_USERS)
910: fatal( "%s line %d: too many deny users.",
911: filename, linenum);
1.112 deraadt 912: options->deny_users[options->num_deny_users++] =
913: xstrdup(arg);
1.94 markus 914: }
915: break;
1.25 markus 916:
1.94 markus 917: case sAllowGroups:
918: while ((arg = strdelim(&cp)) && *arg != '\0') {
919: if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
920: fatal("%s line %d: too many allow groups.",
921: filename, linenum);
1.112 deraadt 922: options->allow_groups[options->num_allow_groups++] =
923: xstrdup(arg);
1.94 markus 924: }
925: break;
1.33 markus 926:
1.94 markus 927: case sDenyGroups:
928: while ((arg = strdelim(&cp)) && *arg != '\0') {
929: if (options->num_deny_groups >= MAX_DENY_GROUPS)
930: fatal("%s line %d: too many deny groups.",
931: filename, linenum);
932: options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
933: }
934: break;
1.66 markus 935:
1.94 markus 936: case sCiphers:
937: arg = strdelim(&cp);
938: if (!arg || *arg == '\0')
939: fatal("%s line %d: Missing argument.", filename, linenum);
940: if (!ciphers_valid(arg))
941: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
942: filename, linenum, arg ? arg : "<NONE>");
943: if (options->ciphers == NULL)
944: options->ciphers = xstrdup(arg);
945: break;
1.33 markus 946:
1.94 markus 947: case sMacs:
948: arg = strdelim(&cp);
949: if (!arg || *arg == '\0')
950: fatal("%s line %d: Missing argument.", filename, linenum);
951: if (!mac_valid(arg))
952: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
953: filename, linenum, arg ? arg : "<NONE>");
954: if (options->macs == NULL)
955: options->macs = xstrdup(arg);
956: break;
1.43 jakob 957:
1.94 markus 958: case sProtocol:
959: intptr = &options->protocol;
960: arg = strdelim(&cp);
961: if (!arg || *arg == '\0')
962: fatal("%s line %d: Missing argument.", filename, linenum);
963: value = proto_spec(arg);
964: if (value == SSH_PROTO_UNKNOWN)
965: fatal("%s line %d: Bad protocol spec '%s'.",
1.95 deraadt 966: filename, linenum, arg ? arg : "<NONE>");
1.94 markus 967: if (*intptr == SSH_PROTO_UNKNOWN)
968: *intptr = value;
969: break;
970:
971: case sSubsystem:
972: if (options->num_subsystems >= MAX_SUBSYSTEMS) {
973: fatal("%s line %d: too many subsystems defined.",
1.95 deraadt 974: filename, linenum);
1.94 markus 975: }
976: arg = strdelim(&cp);
977: if (!arg || *arg == '\0')
978: fatal("%s line %d: Missing subsystem name.",
1.95 deraadt 979: filename, linenum);
1.153 ! dtucker 980: if (!*activep) {
! 981: arg = strdelim(&cp);
! 982: break;
! 983: }
1.94 markus 984: for (i = 0; i < options->num_subsystems; i++)
985: if (strcmp(arg, options->subsystem_name[i]) == 0)
986: fatal("%s line %d: Subsystem '%s' already defined.",
1.95 deraadt 987: filename, linenum, arg);
1.94 markus 988: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
989: arg = strdelim(&cp);
990: if (!arg || *arg == '\0')
991: fatal("%s line %d: Missing subsystem command.",
1.95 deraadt 992: filename, linenum);
1.94 markus 993: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151 djm 994:
995: /* Collect arguments (separate to executable) */
996: p = xstrdup(arg);
997: len = strlen(p) + 1;
998: while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
999: len += 1 + strlen(arg);
1000: p = xrealloc(p, 1, len);
1001: strlcat(p, " ", len);
1002: strlcat(p, arg, len);
1003: }
1004: options->subsystem_args[options->num_subsystems] = p;
1.94 markus 1005: options->num_subsystems++;
1006: break;
1.46 markus 1007:
1.94 markus 1008: case sMaxStartups:
1009: arg = strdelim(&cp);
1010: if (!arg || *arg == '\0')
1011: fatal("%s line %d: Missing MaxStartups spec.",
1.95 deraadt 1012: filename, linenum);
1.94 markus 1013: if ((n = sscanf(arg, "%d:%d:%d",
1014: &options->max_startups_begin,
1015: &options->max_startups_rate,
1016: &options->max_startups)) == 3) {
1017: if (options->max_startups_begin >
1018: options->max_startups ||
1019: options->max_startups_rate > 100 ||
1020: options->max_startups_rate < 1)
1.50 markus 1021: fatal("%s line %d: Illegal MaxStartups spec.",
1.87 stevesk 1022: filename, linenum);
1.94 markus 1023: } else if (n != 1)
1024: fatal("%s line %d: Illegal MaxStartups spec.",
1025: filename, linenum);
1026: else
1027: options->max_startups = options->max_startups_begin;
1028: break;
1.133 dtucker 1029:
1030: case sMaxAuthTries:
1031: intptr = &options->max_authtries;
1032: goto parse_int;
1.94 markus 1033:
1034: case sBanner:
1035: charptr = &options->banner;
1036: goto parse_filename;
1037: /*
1038: * These options can contain %X options expanded at
1039: * connect time, so that you can specify paths like:
1040: *
1041: * AuthorizedKeysFile /etc/ssh_keys/%u
1042: */
1043: case sAuthorizedKeysFile:
1044: case sAuthorizedKeysFile2:
1045: charptr = (opcode == sAuthorizedKeysFile ) ?
1046: &options->authorized_keys_file :
1047: &options->authorized_keys_file2;
1048: goto parse_filename;
1049:
1050: case sClientAliveInterval:
1051: intptr = &options->client_alive_interval;
1052: goto parse_time;
1053:
1054: case sClientAliveCountMax:
1055: intptr = &options->client_alive_count_max;
1056: goto parse_int;
1.131 djm 1057:
1058: case sAcceptEnv:
1059: while ((arg = strdelim(&cp)) && *arg != '\0') {
1060: if (strchr(arg, '=') != NULL)
1061: fatal("%s line %d: Invalid environment name.",
1062: filename, linenum);
1063: if (options->num_accept_env >= MAX_ACCEPT_ENV)
1064: fatal("%s line %d: too many allow env.",
1065: filename, linenum);
1.153 ! dtucker 1066: if (!*activep)
! 1067: break;
1.131 djm 1068: options->accept_env[options->num_accept_env++] =
1069: xstrdup(arg);
1070: }
1071: break;
1.145 reyk 1072:
1073: case sPermitTunnel:
1074: intptr = &options->permit_tun;
1.146 reyk 1075: arg = strdelim(&cp);
1076: if (!arg || *arg == '\0')
1077: fatal("%s line %d: Missing yes/point-to-point/"
1078: "ethernet/no argument.", filename, linenum);
1079: value = 0; /* silence compiler */
1080: if (strcasecmp(arg, "ethernet") == 0)
1081: value = SSH_TUNMODE_ETHERNET;
1082: else if (strcasecmp(arg, "point-to-point") == 0)
1083: value = SSH_TUNMODE_POINTOPOINT;
1084: else if (strcasecmp(arg, "yes") == 0)
1085: value = SSH_TUNMODE_YES;
1086: else if (strcasecmp(arg, "no") == 0)
1087: value = SSH_TUNMODE_NO;
1088: else
1089: fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1090: "no argument: %s", filename, linenum, arg);
1091: if (*intptr == -1)
1092: *intptr = value;
1093: break;
1.94 markus 1094:
1.153 ! dtucker 1095: case sMatch:
! 1096: if (cmdline)
! 1097: fatal("Match directive not supported as a command-line "
! 1098: "option");
! 1099: value = match_cfg_line(&cp, linenum, user, host, address);
! 1100: if (value < 0)
! 1101: fatal("%s line %d: Bad Match condition", filename,
! 1102: linenum);
! 1103: *activep = value;
! 1104: break;
! 1105:
1.94 markus 1106: case sDeprecated:
1.117 itojun 1107: logit("%s line %d: Deprecated option %s",
1.121 jakob 1108: filename, linenum, arg);
1109: while (arg)
1110: arg = strdelim(&cp);
1111: break;
1112:
1113: case sUnsupported:
1114: logit("%s line %d: Unsupported option %s",
1.94 markus 1115: filename, linenum, arg);
1116: while (arg)
1117: arg = strdelim(&cp);
1118: break;
1119:
1120: default:
1121: fatal("%s line %d: Missing handler for opcode %s (%d)",
1122: filename, linenum, arg, opcode);
1123: }
1124: if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1125: fatal("%s line %d: garbage at end of line; \"%.200s\".",
1126: filename, linenum, arg);
1127: return 0;
1128: }
1129:
1130: /* Reads the server configuration file. */
1.25 markus 1131:
1.94 markus 1132: void
1.134 djm 1133: load_server_config(const char *filename, Buffer *conf)
1.94 markus 1134: {
1.134 djm 1135: char line[1024], *cp;
1.94 markus 1136: FILE *f;
1.81 stevesk 1137:
1.134 djm 1138: debug2("%s: filename %s", __func__, filename);
1139: if ((f = fopen(filename, "r")) == NULL) {
1.94 markus 1140: perror(filename);
1141: exit(1);
1142: }
1.134 djm 1143: buffer_clear(conf);
1144: while (fgets(line, sizeof(line), f)) {
1145: /*
1146: * Trim out comments and strip whitespace
1.135 deraadt 1147: * NB - preserve newlines, they are needed to reproduce
1.134 djm 1148: * line numbers later for error messages
1149: */
1150: if ((cp = strchr(line, '#')) != NULL)
1151: memcpy(cp, "\n", 2);
1152: cp = line + strspn(line, " \t\r");
1153:
1154: buffer_append(conf, cp, strlen(cp));
1155: }
1156: buffer_append(conf, "\0", 1);
1157: fclose(f);
1158: debug2("%s: done config len = %d", __func__, buffer_len(conf));
1159: }
1160:
1161: void
1.153 ! dtucker 1162: parse_server_match_config(ServerOptions *options, const char *user,
! 1163: const char *host, const char *address)
! 1164: {
! 1165: ServerOptions mo;
! 1166:
! 1167: initialize_server_options(&mo);
! 1168: parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
! 1169: copy_set_server_options(options, &mo);
! 1170: }
! 1171:
! 1172: /* Copy any (supported) values that are set */
! 1173: void
! 1174: copy_set_server_options(ServerOptions *dst, ServerOptions *src)
! 1175: {
! 1176: if (src->allow_tcp_forwarding != -1)
! 1177: dst->allow_tcp_forwarding = src->allow_tcp_forwarding;
! 1178: if (src->gateway_ports != -1)
! 1179: dst->gateway_ports = src->gateway_ports;
! 1180: }
! 1181:
! 1182: void
! 1183: parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
! 1184: const char *user, const char *host, const char *address)
1.134 djm 1185: {
1.153 ! dtucker 1186: int active, linenum, bad_options = 0;
1.136 dtucker 1187: char *cp, *obuf, *cbuf;
1.134 djm 1188:
1189: debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1190:
1.136 dtucker 1191: obuf = cbuf = xstrdup(buffer_ptr(conf));
1.153 ! dtucker 1192: active = user ? 0 : 1;
1.137 dtucker 1193: linenum = 1;
1.140 deraadt 1194: while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134 djm 1195: if (process_server_config_line(options, cp, filename,
1.153 ! dtucker 1196: linenum++, &active, user, host, address) != 0)
1.94 markus 1197: bad_options++;
1.1 deraadt 1198: }
1.136 dtucker 1199: xfree(obuf);
1.78 stevesk 1200: if (bad_options > 0)
1201: fatal("%s: terminating, %d bad configuration options",
1202: filename, bad_options);
1.1 deraadt 1203: }