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