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