Annotation of src/usr.bin/ssh/servconf.c, Revision 1.143
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.143 ! markus 13: RCSID("$OpenBSD: servconf.c,v 1.142 2005/06/17 02:44:33 djm 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.143 ! markus 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.142 djm 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.142 djm 406: int *intptr, value, n;
1.25 markus 407: ServerOpCodes opcode;
1.139 djm 408: u_short port;
1.142 djm 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.139 djm 479: p = hpdelim(&arg);
480: if (p == NULL)
481: fatal("%s line %d: bad address:port usage",
482: filename, linenum);
483: p = cleanhostname(p);
484: if (arg == NULL)
485: port = 0;
486: else if ((port = a2port(arg)) == 0)
487: fatal("%s line %d: bad port number", filename, linenum);
488:
489: add_listen_addr(options, p, port);
1.25 markus 490:
1.138 djm 491: break;
492:
493: case sAddressFamily:
494: arg = strdelim(&cp);
1.141 markus 495: if (!arg || *arg == '\0')
496: fatal("%s line %d: missing address family.",
497: filename, linenum);
1.138 djm 498: intptr = &options->address_family;
499: if (options->listen_addrs != NULL)
500: fatal("%s line %d: address family must be specified before "
501: "ListenAddress.", filename, linenum);
502: if (strcasecmp(arg, "inet") == 0)
503: value = AF_INET;
504: else if (strcasecmp(arg, "inet6") == 0)
505: value = AF_INET6;
506: else if (strcasecmp(arg, "any") == 0)
507: value = AF_UNSPEC;
508: else
509: fatal("%s line %d: unsupported address family \"%s\".",
510: filename, linenum, arg);
511: if (*intptr == -1)
512: *intptr = value;
1.94 markus 513: break;
514:
515: case sHostKeyFile:
516: intptr = &options->num_host_key_files;
517: if (*intptr >= MAX_HOSTKEYS)
518: fatal("%s line %d: too many host keys specified (max %d).",
519: filename, linenum, MAX_HOSTKEYS);
520: charptr = &options->host_key_files[*intptr];
521: parse_filename:
522: arg = strdelim(&cp);
523: if (!arg || *arg == '\0')
524: fatal("%s line %d: missing file name.",
525: filename, linenum);
526: if (*charptr == NULL) {
527: *charptr = tilde_expand_filename(arg, getuid());
528: /* increase optional counter */
529: if (intptr != NULL)
530: *intptr = *intptr + 1;
531: }
532: break;
1.76 stevesk 533:
1.94 markus 534: case sPidFile:
535: charptr = &options->pid_file;
536: goto parse_filename;
1.25 markus 537:
1.94 markus 538: case sPermitRootLogin:
539: intptr = &options->permit_root_login;
540: arg = strdelim(&cp);
541: if (!arg || *arg == '\0')
542: fatal("%s line %d: missing yes/"
543: "without-password/forced-commands-only/no "
544: "argument.", filename, linenum);
545: value = 0; /* silence compiler */
546: if (strcmp(arg, "without-password") == 0)
547: value = PERMIT_NO_PASSWD;
548: else if (strcmp(arg, "forced-commands-only") == 0)
549: value = PERMIT_FORCED_ONLY;
550: else if (strcmp(arg, "yes") == 0)
551: value = PERMIT_YES;
552: else if (strcmp(arg, "no") == 0)
553: value = PERMIT_NO;
554: else
555: fatal("%s line %d: Bad yes/"
556: "without-password/forced-commands-only/no "
557: "argument: %s", filename, linenum, arg);
558: if (*intptr == -1)
559: *intptr = value;
560: break;
1.36 markus 561:
1.94 markus 562: case sIgnoreRhosts:
563: intptr = &options->ignore_rhosts;
1.25 markus 564: parse_flag:
1.94 markus 565: arg = strdelim(&cp);
566: if (!arg || *arg == '\0')
567: fatal("%s line %d: missing yes/no argument.",
568: filename, linenum);
569: value = 0; /* silence compiler */
570: if (strcmp(arg, "yes") == 0)
571: value = 1;
572: else if (strcmp(arg, "no") == 0)
573: value = 0;
574: else
575: fatal("%s line %d: Bad yes/no argument: %s",
576: filename, linenum, arg);
577: if (*intptr == -1)
578: *intptr = value;
579: break;
580:
581: case sIgnoreUserKnownHosts:
582: intptr = &options->ignore_user_known_hosts;
583: goto parse_flag;
584:
585: case sRhostsRSAAuthentication:
586: intptr = &options->rhosts_rsa_authentication;
587: goto parse_flag;
588:
589: case sHostbasedAuthentication:
590: intptr = &options->hostbased_authentication;
591: goto parse_flag;
592:
593: case sHostbasedUsesNameFromPacketOnly:
594: intptr = &options->hostbased_uses_name_from_packet_only;
595: goto parse_flag;
596:
597: case sRSAAuthentication:
598: intptr = &options->rsa_authentication;
599: goto parse_flag;
600:
601: case sPubkeyAuthentication:
602: intptr = &options->pubkey_authentication;
603: goto parse_flag;
1.119 jakob 604:
1.94 markus 605: case sKerberosAuthentication:
606: intptr = &options->kerberos_authentication;
607: goto parse_flag;
608:
609: case sKerberosOrLocalPasswd:
610: intptr = &options->kerberos_or_local_passwd;
611: goto parse_flag;
612:
613: case sKerberosTicketCleanup:
614: intptr = &options->kerberos_ticket_cleanup;
1.130 jakob 615: goto parse_flag;
616:
617: case sKerberosGetAFSToken:
618: intptr = &options->kerberos_get_afs_token;
1.125 markus 619: goto parse_flag;
620:
621: case sGssAuthentication:
622: intptr = &options->gss_authentication;
623: goto parse_flag;
624:
625: case sGssCleanupCreds:
626: intptr = &options->gss_cleanup_creds;
1.94 markus 627: goto parse_flag;
628:
629: case sPasswordAuthentication:
630: intptr = &options->password_authentication;
631: goto parse_flag;
632:
633: case sKbdInteractiveAuthentication:
634: intptr = &options->kbd_interactive_authentication;
635: goto parse_flag;
636:
637: case sChallengeResponseAuthentication:
638: intptr = &options->challenge_response_authentication;
639: goto parse_flag;
640:
641: case sPrintMotd:
642: intptr = &options->print_motd;
643: goto parse_flag;
644:
645: case sPrintLastLog:
646: intptr = &options->print_lastlog;
647: goto parse_flag;
648:
649: case sX11Forwarding:
650: intptr = &options->x11_forwarding;
651: goto parse_flag;
652:
653: case sX11DisplayOffset:
654: intptr = &options->x11_display_offset;
655: goto parse_int;
1.99 stevesk 656:
657: case sX11UseLocalhost:
658: intptr = &options->x11_use_localhost;
659: goto parse_flag;
1.94 markus 660:
661: case sXAuthLocation:
662: charptr = &options->xauth_location;
663: goto parse_filename;
664:
665: case sStrictModes:
666: intptr = &options->strict_modes;
667: goto parse_flag;
668:
1.129 markus 669: case sTCPKeepAlive:
670: intptr = &options->tcp_keep_alive;
1.94 markus 671: goto parse_flag;
672:
673: case sEmptyPasswd:
674: intptr = &options->permit_empty_passwd;
1.113 markus 675: goto parse_flag;
676:
677: case sPermitUserEnvironment:
678: intptr = &options->permit_user_env;
1.94 markus 679: goto parse_flag;
680:
681: case sUseLogin:
682: intptr = &options->use_login;
1.111 markus 683: goto parse_flag;
684:
685: case sCompression:
686: intptr = &options->compression;
1.143 ! markus 687: arg = strdelim(&cp);
! 688: if (!arg || *arg == '\0')
! 689: fatal("%s line %d: missing yes/no/delayed "
! 690: "argument.", filename, linenum);
! 691: value = 0; /* silence compiler */
! 692: if (strcmp(arg, "delayed") == 0)
! 693: value = COMP_DELAYED;
! 694: else if (strcmp(arg, "yes") == 0)
! 695: value = COMP_ZLIB;
! 696: else if (strcmp(arg, "no") == 0)
! 697: value = COMP_NONE;
! 698: else
! 699: fatal("%s line %d: Bad yes/no/delayed "
! 700: "argument: %s", filename, linenum, arg);
! 701: if (*intptr == -1)
! 702: *intptr = value;
! 703: break;
1.94 markus 704:
705: case sGatewayPorts:
706: intptr = &options->gateway_ports;
1.139 djm 707: arg = strdelim(&cp);
708: if (!arg || *arg == '\0')
709: fatal("%s line %d: missing yes/no/clientspecified "
710: "argument.", filename, linenum);
711: value = 0; /* silence compiler */
712: if (strcmp(arg, "clientspecified") == 0)
713: value = 2;
714: else if (strcmp(arg, "yes") == 0)
715: value = 1;
716: else if (strcmp(arg, "no") == 0)
717: value = 0;
718: else
719: fatal("%s line %d: Bad yes/no/clientspecified "
720: "argument: %s", filename, linenum, arg);
721: if (*intptr == -1)
722: *intptr = value;
723: break;
1.25 markus 724:
1.122 markus 725: case sUseDNS:
726: intptr = &options->use_dns;
1.94 markus 727: goto parse_flag;
1.53 markus 728:
1.94 markus 729: case sLogFacility:
730: intptr = (int *) &options->log_facility;
731: arg = strdelim(&cp);
732: value = log_facility_number(arg);
1.101 markus 733: if (value == SYSLOG_FACILITY_NOT_SET)
1.94 markus 734: fatal("%.200s line %d: unsupported log facility '%s'",
735: filename, linenum, arg ? arg : "<NONE>");
736: if (*intptr == -1)
737: *intptr = (SyslogFacility) value;
738: break;
1.25 markus 739:
1.94 markus 740: case sLogLevel:
741: intptr = (int *) &options->log_level;
742: arg = strdelim(&cp);
743: value = log_level_number(arg);
1.101 markus 744: if (value == SYSLOG_LEVEL_NOT_SET)
1.94 markus 745: fatal("%.200s line %d: unsupported log level '%s'",
746: filename, linenum, arg ? arg : "<NONE>");
747: if (*intptr == -1)
748: *intptr = (LogLevel) value;
749: break;
750:
751: case sAllowTcpForwarding:
752: intptr = &options->allow_tcp_forwarding;
753: goto parse_flag;
1.102 provos 754:
755: case sUsePrivilegeSeparation:
756: intptr = &use_privsep;
757: goto parse_flag;
1.94 markus 758:
759: case sAllowUsers:
760: while ((arg = strdelim(&cp)) && *arg != '\0') {
761: if (options->num_allow_users >= MAX_ALLOW_USERS)
762: fatal("%s line %d: too many allow users.",
763: filename, linenum);
1.112 deraadt 764: options->allow_users[options->num_allow_users++] =
765: xstrdup(arg);
1.94 markus 766: }
767: break;
1.25 markus 768:
1.94 markus 769: case sDenyUsers:
770: while ((arg = strdelim(&cp)) && *arg != '\0') {
771: if (options->num_deny_users >= MAX_DENY_USERS)
772: fatal( "%s line %d: too many deny users.",
773: filename, linenum);
1.112 deraadt 774: options->deny_users[options->num_deny_users++] =
775: xstrdup(arg);
1.94 markus 776: }
777: break;
1.25 markus 778:
1.94 markus 779: case sAllowGroups:
780: while ((arg = strdelim(&cp)) && *arg != '\0') {
781: if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
782: fatal("%s line %d: too many allow groups.",
783: filename, linenum);
1.112 deraadt 784: options->allow_groups[options->num_allow_groups++] =
785: xstrdup(arg);
1.94 markus 786: }
787: break;
1.33 markus 788:
1.94 markus 789: case sDenyGroups:
790: while ((arg = strdelim(&cp)) && *arg != '\0') {
791: if (options->num_deny_groups >= MAX_DENY_GROUPS)
792: fatal("%s line %d: too many deny groups.",
793: filename, linenum);
794: options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
795: }
796: break;
1.66 markus 797:
1.94 markus 798: case sCiphers:
799: arg = strdelim(&cp);
800: if (!arg || *arg == '\0')
801: fatal("%s line %d: Missing argument.", filename, linenum);
802: if (!ciphers_valid(arg))
803: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
804: filename, linenum, arg ? arg : "<NONE>");
805: if (options->ciphers == NULL)
806: options->ciphers = xstrdup(arg);
807: break;
1.33 markus 808:
1.94 markus 809: case sMacs:
810: arg = strdelim(&cp);
811: if (!arg || *arg == '\0')
812: fatal("%s line %d: Missing argument.", filename, linenum);
813: if (!mac_valid(arg))
814: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
815: filename, linenum, arg ? arg : "<NONE>");
816: if (options->macs == NULL)
817: options->macs = xstrdup(arg);
818: break;
1.43 jakob 819:
1.94 markus 820: case sProtocol:
821: intptr = &options->protocol;
822: arg = strdelim(&cp);
823: if (!arg || *arg == '\0')
824: fatal("%s line %d: Missing argument.", filename, linenum);
825: value = proto_spec(arg);
826: if (value == SSH_PROTO_UNKNOWN)
827: fatal("%s line %d: Bad protocol spec '%s'.",
1.95 deraadt 828: filename, linenum, arg ? arg : "<NONE>");
1.94 markus 829: if (*intptr == SSH_PROTO_UNKNOWN)
830: *intptr = value;
831: break;
832:
833: case sSubsystem:
834: if (options->num_subsystems >= MAX_SUBSYSTEMS) {
835: fatal("%s line %d: too many subsystems defined.",
1.95 deraadt 836: filename, linenum);
1.94 markus 837: }
838: arg = strdelim(&cp);
839: if (!arg || *arg == '\0')
840: fatal("%s line %d: Missing subsystem name.",
1.95 deraadt 841: filename, linenum);
1.94 markus 842: for (i = 0; i < options->num_subsystems; i++)
843: if (strcmp(arg, options->subsystem_name[i]) == 0)
844: fatal("%s line %d: Subsystem '%s' already defined.",
1.95 deraadt 845: filename, linenum, arg);
1.94 markus 846: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
847: arg = strdelim(&cp);
848: if (!arg || *arg == '\0')
849: fatal("%s line %d: Missing subsystem command.",
1.95 deraadt 850: filename, linenum);
1.94 markus 851: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
852: options->num_subsystems++;
853: break;
1.46 markus 854:
1.94 markus 855: case sMaxStartups:
856: arg = strdelim(&cp);
857: if (!arg || *arg == '\0')
858: fatal("%s line %d: Missing MaxStartups spec.",
1.95 deraadt 859: filename, linenum);
1.94 markus 860: if ((n = sscanf(arg, "%d:%d:%d",
861: &options->max_startups_begin,
862: &options->max_startups_rate,
863: &options->max_startups)) == 3) {
864: if (options->max_startups_begin >
865: options->max_startups ||
866: options->max_startups_rate > 100 ||
867: options->max_startups_rate < 1)
1.50 markus 868: fatal("%s line %d: Illegal MaxStartups spec.",
1.87 stevesk 869: filename, linenum);
1.94 markus 870: } else if (n != 1)
871: fatal("%s line %d: Illegal MaxStartups spec.",
872: filename, linenum);
873: else
874: options->max_startups = options->max_startups_begin;
875: break;
1.133 dtucker 876:
877: case sMaxAuthTries:
878: intptr = &options->max_authtries;
879: goto parse_int;
1.94 markus 880:
881: case sBanner:
882: charptr = &options->banner;
883: goto parse_filename;
884: /*
885: * These options can contain %X options expanded at
886: * connect time, so that you can specify paths like:
887: *
888: * AuthorizedKeysFile /etc/ssh_keys/%u
889: */
890: case sAuthorizedKeysFile:
891: case sAuthorizedKeysFile2:
892: charptr = (opcode == sAuthorizedKeysFile ) ?
893: &options->authorized_keys_file :
894: &options->authorized_keys_file2;
895: goto parse_filename;
896:
897: case sClientAliveInterval:
898: intptr = &options->client_alive_interval;
899: goto parse_time;
900:
901: case sClientAliveCountMax:
902: intptr = &options->client_alive_count_max;
903: goto parse_int;
1.131 djm 904:
905: case sAcceptEnv:
906: while ((arg = strdelim(&cp)) && *arg != '\0') {
907: if (strchr(arg, '=') != NULL)
908: fatal("%s line %d: Invalid environment name.",
909: filename, linenum);
910: if (options->num_accept_env >= MAX_ACCEPT_ENV)
911: fatal("%s line %d: too many allow env.",
912: filename, linenum);
913: options->accept_env[options->num_accept_env++] =
914: xstrdup(arg);
915: }
916: break;
1.94 markus 917:
918: case sDeprecated:
1.117 itojun 919: logit("%s line %d: Deprecated option %s",
1.121 jakob 920: filename, linenum, arg);
921: while (arg)
922: arg = strdelim(&cp);
923: break;
924:
925: case sUnsupported:
926: logit("%s line %d: Unsupported option %s",
1.94 markus 927: filename, linenum, arg);
928: while (arg)
929: arg = strdelim(&cp);
930: break;
931:
932: default:
933: fatal("%s line %d: Missing handler for opcode %s (%d)",
934: filename, linenum, arg, opcode);
935: }
936: if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
937: fatal("%s line %d: garbage at end of line; \"%.200s\".",
938: filename, linenum, arg);
939: return 0;
940: }
941:
942: /* Reads the server configuration file. */
1.25 markus 943:
1.94 markus 944: void
1.134 djm 945: load_server_config(const char *filename, Buffer *conf)
1.94 markus 946: {
1.134 djm 947: char line[1024], *cp;
1.94 markus 948: FILE *f;
1.81 stevesk 949:
1.134 djm 950: debug2("%s: filename %s", __func__, filename);
951: if ((f = fopen(filename, "r")) == NULL) {
1.94 markus 952: perror(filename);
953: exit(1);
954: }
1.134 djm 955: buffer_clear(conf);
956: while (fgets(line, sizeof(line), f)) {
957: /*
958: * Trim out comments and strip whitespace
1.135 deraadt 959: * NB - preserve newlines, they are needed to reproduce
1.134 djm 960: * line numbers later for error messages
961: */
962: if ((cp = strchr(line, '#')) != NULL)
963: memcpy(cp, "\n", 2);
964: cp = line + strspn(line, " \t\r");
965:
966: buffer_append(conf, cp, strlen(cp));
967: }
968: buffer_append(conf, "\0", 1);
969: fclose(f);
970: debug2("%s: done config len = %d", __func__, buffer_len(conf));
971: }
972:
973: void
974: parse_server_config(ServerOptions *options, const char *filename, Buffer *conf)
975: {
976: int linenum, bad_options = 0;
1.136 dtucker 977: char *cp, *obuf, *cbuf;
1.134 djm 978:
979: debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
980:
1.136 dtucker 981: obuf = cbuf = xstrdup(buffer_ptr(conf));
1.137 dtucker 982: linenum = 1;
1.140 deraadt 983: while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134 djm 984: if (process_server_config_line(options, cp, filename,
985: linenum++) != 0)
1.94 markus 986: bad_options++;
1.1 deraadt 987: }
1.136 dtucker 988: xfree(obuf);
1.78 stevesk 989: if (bad_options > 0)
990: fatal("%s: terminating, %d bad configuration options",
991: filename, bad_options);
1.1 deraadt 992: }