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