Annotation of src/usr.bin/ssh/servconf.c, Revision 1.105.2.4
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.105.2.4! jason 13: RCSID("$OpenBSD: servconf.c,v 1.112 2002/06/23 09:46:51 deraadt Exp $");
1.62 markus 14:
1.88 itojun 15: #if defined(KRB4) || defined(KRB5)
1.62 markus 16: #include <krb.h>
1.86 dugsong 17: #endif
18: #ifdef AFS
19: #include <kafs.h>
1.62 markus 20: #endif
1.1 deraadt 21:
22: #include "ssh.h"
1.62 markus 23: #include "log.h"
1.1 deraadt 24: #include "servconf.h"
25: #include "xmalloc.h"
1.33 markus 26: #include "compat.h"
1.60 markus 27: #include "pathnames.h"
1.62 markus 28: #include "tildexpand.h"
29: #include "misc.h"
30: #include "cipher.h"
1.66 markus 31: #include "kex.h"
32: #include "mac.h"
1.1 deraadt 33:
1.84 itojun 34: static void add_listen_addr(ServerOptions *, char *, u_short);
35: static void add_one_listen_addr(ServerOptions *, char *, u_short);
1.29 markus 36:
1.62 markus 37: /* AF_UNSPEC or AF_INET or AF_INET6 */
38: extern int IPv4or6;
1.102 provos 39: /* Use of privilege separation or not */
40: extern int use_privsep;
1.62 markus 41:
1.1 deraadt 42: /* Initializes the server options to their default values. */
43:
1.34 markus 44: void
1.25 markus 45: initialize_server_options(ServerOptions *options)
1.1 deraadt 46: {
1.25 markus 47: memset(options, 0, sizeof(*options));
1.29 markus 48: options->num_ports = 0;
49: options->ports_from_cmdline = 0;
50: options->listen_addrs = NULL;
1.54 markus 51: options->num_host_key_files = 0;
1.36 markus 52: options->pid_file = NULL;
1.25 markus 53: options->server_key_bits = -1;
54: options->login_grace_time = -1;
55: options->key_regeneration_time = -1;
1.67 markus 56: options->permit_root_login = PERMIT_NOT_SET;
1.25 markus 57: options->ignore_rhosts = -1;
58: options->ignore_user_known_hosts = -1;
59: options->print_motd = -1;
1.72 stevesk 60: options->print_lastlog = -1;
1.25 markus 61: options->x11_forwarding = -1;
62: options->x11_display_offset = -1;
1.99 stevesk 63: options->x11_use_localhost = -1;
1.42 markus 64: options->xauth_location = NULL;
1.25 markus 65: options->strict_modes = -1;
66: options->keepalives = -1;
1.101 markus 67: options->log_facility = SYSLOG_FACILITY_NOT_SET;
68: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.25 markus 69: options->rhosts_authentication = -1;
70: options->rhosts_rsa_authentication = -1;
1.75 markus 71: options->hostbased_authentication = -1;
72: options->hostbased_uses_name_from_packet_only = -1;
1.25 markus 73: options->rsa_authentication = -1;
1.54 markus 74: options->pubkey_authentication = -1;
1.85 dugsong 75: #if defined(KRB4) || defined(KRB5)
1.25 markus 76: options->kerberos_authentication = -1;
77: options->kerberos_or_local_passwd = -1;
78: options->kerberos_ticket_cleanup = -1;
1.1 deraadt 79: #endif
1.85 dugsong 80: #if defined(AFS) || defined(KRB5)
81: options->kerberos_tgt_passing = -1;
82: #endif
1.4 dugsong 83: #ifdef AFS
1.25 markus 84: options->afs_token_passing = -1;
1.1 deraadt 85: #endif
1.25 markus 86: options->password_authentication = -1;
1.52 markus 87: options->kbd_interactive_authentication = -1;
1.80 markus 88: options->challenge_response_authentication = -1;
1.25 markus 89: options->permit_empty_passwd = -1;
90: options->use_login = -1;
1.105.2.4! jason 91: options->compression = -1;
1.53 markus 92: options->allow_tcp_forwarding = -1;
1.25 markus 93: options->num_allow_users = 0;
94: options->num_deny_users = 0;
95: options->num_allow_groups = 0;
96: options->num_deny_groups = 0;
1.33 markus 97: options->ciphers = NULL;
1.66 markus 98: options->macs = NULL;
1.33 markus 99: options->protocol = SSH_PROTO_UNKNOWN;
1.38 markus 100: options->gateway_ports = -1;
1.43 jakob 101: options->num_subsystems = 0;
1.50 markus 102: options->max_startups_begin = -1;
103: options->max_startups_rate = -1;
1.46 markus 104: options->max_startups = -1;
1.57 markus 105: options->banner = NULL;
1.100 markus 106: options->verify_reverse_mapping = -1;
1.77 beck 107: options->client_alive_interval = -1;
108: options->client_alive_count_max = -1;
1.82 markus 109: options->authorized_keys_file = NULL;
110: options->authorized_keys_file2 = NULL;
1.102 provos 111:
112: /* Needs to be accessable in many places */
113: use_privsep = -1;
1.1 deraadt 114: }
115:
1.34 markus 116: void
1.25 markus 117: fill_default_server_options(ServerOptions *options)
1.1 deraadt 118: {
1.54 markus 119: if (options->protocol == SSH_PROTO_UNKNOWN)
120: options->protocol = SSH_PROTO_1|SSH_PROTO_2;
121: if (options->num_host_key_files == 0) {
122: /* fill default hostkeys for protocols */
123: if (options->protocol & SSH_PROTO_1)
1.97 stevesk 124: options->host_key_files[options->num_host_key_files++] =
125: _PATH_HOST_KEY_FILE;
126: if (options->protocol & SSH_PROTO_2) {
127: options->host_key_files[options->num_host_key_files++] =
128: _PATH_HOST_RSA_KEY_FILE;
129: options->host_key_files[options->num_host_key_files++] =
130: _PATH_HOST_DSA_KEY_FILE;
131: }
1.54 markus 132: }
1.29 markus 133: if (options->num_ports == 0)
134: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
135: if (options->listen_addrs == NULL)
1.76 stevesk 136: add_listen_addr(options, NULL, 0);
1.36 markus 137: if (options->pid_file == NULL)
1.60 markus 138: options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
1.25 markus 139: if (options->server_key_bits == -1)
140: options->server_key_bits = 768;
141: if (options->login_grace_time == -1)
142: options->login_grace_time = 600;
143: if (options->key_regeneration_time == -1)
144: options->key_regeneration_time = 3600;
1.67 markus 145: if (options->permit_root_login == PERMIT_NOT_SET)
146: options->permit_root_login = PERMIT_YES;
1.25 markus 147: if (options->ignore_rhosts == -1)
1.30 markus 148: options->ignore_rhosts = 1;
1.25 markus 149: if (options->ignore_user_known_hosts == -1)
150: options->ignore_user_known_hosts = 0;
151: if (options->print_motd == -1)
152: options->print_motd = 1;
1.72 stevesk 153: if (options->print_lastlog == -1)
154: options->print_lastlog = 1;
1.25 markus 155: if (options->x11_forwarding == -1)
1.30 markus 156: options->x11_forwarding = 0;
1.25 markus 157: if (options->x11_display_offset == -1)
1.30 markus 158: options->x11_display_offset = 10;
1.99 stevesk 159: if (options->x11_use_localhost == -1)
160: options->x11_use_localhost = 1;
1.42 markus 161: if (options->xauth_location == NULL)
1.83 markus 162: options->xauth_location = _PATH_XAUTH;
1.25 markus 163: if (options->strict_modes == -1)
164: options->strict_modes = 1;
165: if (options->keepalives == -1)
166: options->keepalives = 1;
1.101 markus 167: if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
1.25 markus 168: options->log_facility = SYSLOG_FACILITY_AUTH;
1.101 markus 169: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.58 markus 170: options->log_level = SYSLOG_LEVEL_INFO;
1.25 markus 171: if (options->rhosts_authentication == -1)
172: options->rhosts_authentication = 0;
173: if (options->rhosts_rsa_authentication == -1)
1.30 markus 174: options->rhosts_rsa_authentication = 0;
1.75 markus 175: if (options->hostbased_authentication == -1)
176: options->hostbased_authentication = 0;
177: if (options->hostbased_uses_name_from_packet_only == -1)
178: options->hostbased_uses_name_from_packet_only = 0;
1.25 markus 179: if (options->rsa_authentication == -1)
180: options->rsa_authentication = 1;
1.54 markus 181: if (options->pubkey_authentication == -1)
182: options->pubkey_authentication = 1;
1.85 dugsong 183: #if defined(KRB4) || defined(KRB5)
1.25 markus 184: if (options->kerberos_authentication == -1)
1.105.2.1 jason 185: options->kerberos_authentication = 0;
1.25 markus 186: if (options->kerberos_or_local_passwd == -1)
187: options->kerberos_or_local_passwd = 1;
188: if (options->kerberos_ticket_cleanup == -1)
189: options->kerberos_ticket_cleanup = 1;
1.85 dugsong 190: #endif
191: #if defined(AFS) || defined(KRB5)
1.25 markus 192: if (options->kerberos_tgt_passing == -1)
193: options->kerberos_tgt_passing = 0;
1.85 dugsong 194: #endif
1.95 deraadt 195: #ifdef AFS
1.25 markus 196: if (options->afs_token_passing == -1)
1.105.2.1 jason 197: options->afs_token_passing = 0;
1.85 dugsong 198: #endif
1.25 markus 199: if (options->password_authentication == -1)
200: options->password_authentication = 1;
1.52 markus 201: if (options->kbd_interactive_authentication == -1)
202: options->kbd_interactive_authentication = 0;
1.80 markus 203: if (options->challenge_response_authentication == -1)
204: options->challenge_response_authentication = 1;
1.25 markus 205: if (options->permit_empty_passwd == -1)
1.30 markus 206: options->permit_empty_passwd = 0;
1.25 markus 207: if (options->use_login == -1)
208: options->use_login = 0;
1.105.2.4! jason 209: if (options->compression == -1)
! 210: options->compression = 1;
1.53 markus 211: if (options->allow_tcp_forwarding == -1)
212: options->allow_tcp_forwarding = 1;
1.38 markus 213: if (options->gateway_ports == -1)
214: options->gateway_ports = 0;
1.46 markus 215: if (options->max_startups == -1)
216: options->max_startups = 10;
1.50 markus 217: if (options->max_startups_rate == -1)
218: options->max_startups_rate = 100; /* 100% */
219: if (options->max_startups_begin == -1)
220: options->max_startups_begin = options->max_startups;
1.100 markus 221: if (options->verify_reverse_mapping == -1)
222: options->verify_reverse_mapping = 0;
1.77 beck 223: if (options->client_alive_interval == -1)
1.95 deraadt 224: options->client_alive_interval = 0;
1.77 beck 225: if (options->client_alive_count_max == -1)
226: options->client_alive_count_max = 3;
1.90 markus 227: if (options->authorized_keys_file2 == NULL) {
228: /* authorized_keys_file2 falls back to authorized_keys_file */
229: if (options->authorized_keys_file != NULL)
230: options->authorized_keys_file2 = options->authorized_keys_file;
231: else
232: options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
233: }
234: if (options->authorized_keys_file == NULL)
235: options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
1.102 provos 236:
1.105.2.3 jason 237: /* Turn privilege separation on by default */
1.102 provos 238: if (use_privsep == -1)
1.105.2.3 jason 239: use_privsep = 1;
1.1 deraadt 240: }
241:
242: /* Keyword tokens. */
1.25 markus 243: typedef enum {
244: sBadOption, /* == unknown option */
245: sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
246: sPermitRootLogin, sLogFacility, sLogLevel,
247: sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
1.85 dugsong 248: #if defined(KRB4) || defined(KRB5)
1.25 markus 249: sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.1 deraadt 250: #endif
1.85 dugsong 251: #if defined(AFS) || defined(KRB5)
252: sKerberosTgtPassing,
253: #endif
1.1 deraadt 254: #ifdef AFS
1.85 dugsong 255: sAFSTokenPassing,
1.1 deraadt 256: #endif
1.63 markus 257: sChallengeResponseAuthentication,
1.52 markus 258: sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
1.72 stevesk 259: sPrintMotd, sPrintLastLog, sIgnoreRhosts,
1.99 stevesk 260: sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
1.89 jakob 261: sStrictModes, sEmptyPasswd, sKeepAlives,
1.105.2.4! jason 262: sUseLogin, sAllowTcpForwarding, sCompression,
1.53 markus 263: sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.66 markus 264: sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
1.54 markus 265: sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
1.100 markus 266: sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
1.95 deraadt 267: sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
1.89 jakob 268: sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
1.105 stevesk 269: sUsePrivilegeSeparation,
1.89 jakob 270: sDeprecated
1.1 deraadt 271: } ServerOpCodes;
272:
273: /* Textual representation of the tokens. */
1.25 markus 274: static struct {
275: const char *name;
276: ServerOpCodes opcode;
277: } keywords[] = {
278: { "port", sPort },
279: { "hostkey", sHostKeyFile },
1.54 markus 280: { "hostdsakey", sHostKeyFile }, /* alias */
1.65 stevesk 281: { "pidfile", sPidFile },
1.25 markus 282: { "serverkeybits", sServerKeyBits },
283: { "logingracetime", sLoginGraceTime },
284: { "keyregenerationinterval", sKeyRegenerationTime },
285: { "permitrootlogin", sPermitRootLogin },
286: { "syslogfacility", sLogFacility },
287: { "loglevel", sLogLevel },
288: { "rhostsauthentication", sRhostsAuthentication },
289: { "rhostsrsaauthentication", sRhostsRSAAuthentication },
1.75 markus 290: { "hostbasedauthentication", sHostbasedAuthentication },
291: { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
1.25 markus 292: { "rsaauthentication", sRSAAuthentication },
1.54 markus 293: { "pubkeyauthentication", sPubkeyAuthentication },
294: { "dsaauthentication", sPubkeyAuthentication }, /* alias */
1.85 dugsong 295: #if defined(KRB4) || defined(KRB5)
1.25 markus 296: { "kerberosauthentication", sKerberosAuthentication },
297: { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
298: { "kerberosticketcleanup", sKerberosTicketCleanup },
1.1 deraadt 299: #endif
1.85 dugsong 300: #if defined(AFS) || defined(KRB5)
301: { "kerberostgtpassing", sKerberosTgtPassing },
302: #endif
1.4 dugsong 303: #ifdef AFS
1.25 markus 304: { "afstokenpassing", sAFSTokenPassing },
1.1 deraadt 305: #endif
1.25 markus 306: { "passwordauthentication", sPasswordAuthentication },
1.52 markus 307: { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
1.63 markus 308: { "challengeresponseauthentication", sChallengeResponseAuthentication },
309: { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
1.89 jakob 310: { "checkmail", sDeprecated },
1.25 markus 311: { "listenaddress", sListenAddress },
312: { "printmotd", sPrintMotd },
1.72 stevesk 313: { "printlastlog", sPrintLastLog },
1.25 markus 314: { "ignorerhosts", sIgnoreRhosts },
315: { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
316: { "x11forwarding", sX11Forwarding },
317: { "x11displayoffset", sX11DisplayOffset },
1.99 stevesk 318: { "x11uselocalhost", sX11UseLocalhost },
1.42 markus 319: { "xauthlocation", sXAuthLocation },
1.25 markus 320: { "strictmodes", sStrictModes },
321: { "permitemptypasswords", sEmptyPasswd },
322: { "uselogin", sUseLogin },
1.105.2.4! jason 323: { "compression", sCompression },
1.25 markus 324: { "keepalive", sKeepAlives },
1.53 markus 325: { "allowtcpforwarding", sAllowTcpForwarding },
1.25 markus 326: { "allowusers", sAllowUsers },
327: { "denyusers", sDenyUsers },
328: { "allowgroups", sAllowGroups },
329: { "denygroups", sDenyGroups },
1.33 markus 330: { "ciphers", sCiphers },
1.66 markus 331: { "macs", sMacs },
1.33 markus 332: { "protocol", sProtocol },
1.38 markus 333: { "gatewayports", sGatewayPorts },
1.43 jakob 334: { "subsystem", sSubsystem },
1.46 markus 335: { "maxstartups", sMaxStartups },
1.57 markus 336: { "banner", sBanner },
1.100 markus 337: { "verifyreversemapping", sVerifyReverseMapping },
338: { "reversemappingcheck", sVerifyReverseMapping },
1.77 beck 339: { "clientaliveinterval", sClientAliveInterval },
340: { "clientalivecountmax", sClientAliveCountMax },
1.82 markus 341: { "authorizedkeysfile", sAuthorizedKeysFile },
342: { "authorizedkeysfile2", sAuthorizedKeysFile2 },
1.102 provos 343: { "useprivilegeseparation", sUsePrivilegeSeparation},
1.92 stevesk 344: { NULL, sBadOption }
1.1 deraadt 345: };
346:
1.27 markus 347: /*
1.73 stevesk 348: * Returns the number of the token pointed to by cp or sBadOption.
1.27 markus 349: */
1.1 deraadt 350:
1.34 markus 351: static ServerOpCodes
1.25 markus 352: parse_token(const char *cp, const char *filename,
353: int linenum)
1.1 deraadt 354: {
1.55 markus 355: u_int i;
1.1 deraadt 356:
1.25 markus 357: for (i = 0; keywords[i].name; i++)
1.28 markus 358: if (strcasecmp(cp, keywords[i].name) == 0)
1.25 markus 359: return keywords[i].opcode;
360:
1.78 stevesk 361: error("%s: line %d: Bad configuration option: %s",
362: filename, linenum, cp);
1.25 markus 363: return sBadOption;
1.1 deraadt 364: }
365:
1.84 itojun 366: static void
1.76 stevesk 367: add_listen_addr(ServerOptions *options, char *addr, u_short port)
1.74 stevesk 368: {
369: int i;
370:
371: if (options->num_ports == 0)
372: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
1.76 stevesk 373: if (port == 0)
1.74 stevesk 374: for (i = 0; i < options->num_ports; i++)
375: add_one_listen_addr(options, addr, options->ports[i]);
376: else
1.76 stevesk 377: add_one_listen_addr(options, addr, port);
1.74 stevesk 378: }
379:
1.84 itojun 380: static void
1.74 stevesk 381: add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
1.29 markus 382: {
383: struct addrinfo hints, *ai, *aitop;
384: char strport[NI_MAXSERV];
385: int gaierr;
386:
1.74 stevesk 387: memset(&hints, 0, sizeof(hints));
388: hints.ai_family = IPv4or6;
389: hints.ai_socktype = SOCK_STREAM;
390: hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
1.105.2.4! jason 391: snprintf(strport, sizeof strport, "%u", port);
1.74 stevesk 392: if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
393: fatal("bad addr or host: %s (%s)",
394: addr ? addr : "<NULL>",
395: gai_strerror(gaierr));
396: for (ai = aitop; ai->ai_next; ai = ai->ai_next)
397: ;
398: ai->ai_next = options->listen_addrs;
399: options->listen_addrs = aitop;
1.29 markus 400: }
401:
1.94 markus 402: int
403: process_server_config_line(ServerOptions *options, char *line,
404: const char *filename, int linenum)
1.1 deraadt 405: {
1.74 stevesk 406: char *cp, **charptr, *arg, *p;
1.105.2.4! jason 407: int *intptr, value, i, n;
1.25 markus 408: ServerOpCodes opcode;
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);
475: if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
476: fatal("%s line %d: missing inet addr.",
477: filename, linenum);
478: if (*arg == '[') {
479: if ((p = strchr(arg, ']')) == NULL)
480: fatal("%s line %d: bad ipv6 inet addr usage.",
481: filename, linenum);
482: arg++;
483: memmove(p, p+1, strlen(p+1)+1);
484: } else if (((p = strchr(arg, ':')) == NULL) ||
485: (strchr(p+1, ':') != NULL)) {
486: add_listen_addr(options, arg, 0);
1.81 stevesk 487: break;
1.94 markus 488: }
489: if (*p == ':') {
490: u_short port;
1.25 markus 491:
1.94 markus 492: p++;
493: if (*p == '\0')
494: fatal("%s line %d: bad inet addr:port usage.",
495: filename, linenum);
496: else {
497: *(p-1) = '\0';
498: if ((port = a2port(p)) == 0)
499: fatal("%s line %d: bad port number.",
1.74 stevesk 500: filename, linenum);
1.94 markus 501: add_listen_addr(options, arg, port);
1.74 stevesk 502: }
1.94 markus 503: } else if (*p == '\0')
504: add_listen_addr(options, arg, 0);
505: else
506: fatal("%s line %d: bad inet addr usage.",
507: filename, linenum);
508: break;
509:
510: case sHostKeyFile:
511: intptr = &options->num_host_key_files;
512: if (*intptr >= MAX_HOSTKEYS)
513: fatal("%s line %d: too many host keys specified (max %d).",
514: filename, linenum, MAX_HOSTKEYS);
515: charptr = &options->host_key_files[*intptr];
516: parse_filename:
517: arg = strdelim(&cp);
518: if (!arg || *arg == '\0')
519: fatal("%s line %d: missing file name.",
520: filename, linenum);
521: if (*charptr == NULL) {
522: *charptr = tilde_expand_filename(arg, getuid());
523: /* increase optional counter */
524: if (intptr != NULL)
525: *intptr = *intptr + 1;
526: }
527: break;
1.76 stevesk 528:
1.94 markus 529: case sPidFile:
530: charptr = &options->pid_file;
531: goto parse_filename;
1.25 markus 532:
1.94 markus 533: case sPermitRootLogin:
534: intptr = &options->permit_root_login;
535: arg = strdelim(&cp);
536: if (!arg || *arg == '\0')
537: fatal("%s line %d: missing yes/"
538: "without-password/forced-commands-only/no "
539: "argument.", filename, linenum);
540: value = 0; /* silence compiler */
541: if (strcmp(arg, "without-password") == 0)
542: value = PERMIT_NO_PASSWD;
543: else if (strcmp(arg, "forced-commands-only") == 0)
544: value = PERMIT_FORCED_ONLY;
545: else if (strcmp(arg, "yes") == 0)
546: value = PERMIT_YES;
547: else if (strcmp(arg, "no") == 0)
548: value = PERMIT_NO;
549: else
550: fatal("%s line %d: Bad yes/"
551: "without-password/forced-commands-only/no "
552: "argument: %s", filename, linenum, arg);
553: if (*intptr == -1)
554: *intptr = value;
555: break;
1.36 markus 556:
1.94 markus 557: case sIgnoreRhosts:
558: intptr = &options->ignore_rhosts;
1.25 markus 559: parse_flag:
1.94 markus 560: arg = strdelim(&cp);
561: if (!arg || *arg == '\0')
562: fatal("%s line %d: missing yes/no argument.",
563: filename, linenum);
564: value = 0; /* silence compiler */
565: if (strcmp(arg, "yes") == 0)
566: value = 1;
567: else if (strcmp(arg, "no") == 0)
568: value = 0;
569: else
570: fatal("%s line %d: Bad yes/no argument: %s",
571: filename, linenum, arg);
572: if (*intptr == -1)
573: *intptr = value;
574: break;
575:
576: case sIgnoreUserKnownHosts:
577: intptr = &options->ignore_user_known_hosts;
578: goto parse_flag;
579:
580: case sRhostsAuthentication:
581: intptr = &options->rhosts_authentication;
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.85 dugsong 603: #if defined(KRB4) || defined(KRB5)
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;
614: goto parse_flag;
1.1 deraadt 615: #endif
1.85 dugsong 616: #if defined(AFS) || defined(KRB5)
1.94 markus 617: case sKerberosTgtPassing:
618: intptr = &options->kerberos_tgt_passing;
619: goto parse_flag;
1.85 dugsong 620: #endif
621: #ifdef AFS
1.94 markus 622: case sAFSTokenPassing:
623: intptr = &options->afs_token_passing;
624: goto parse_flag;
625: #endif
626:
627: case sPasswordAuthentication:
628: intptr = &options->password_authentication;
629: goto parse_flag;
630:
631: case sKbdInteractiveAuthentication:
632: intptr = &options->kbd_interactive_authentication;
633: goto parse_flag;
634:
635: case sChallengeResponseAuthentication:
636: intptr = &options->challenge_response_authentication;
637: goto parse_flag;
638:
639: case sPrintMotd:
640: intptr = &options->print_motd;
641: goto parse_flag;
642:
643: case sPrintLastLog:
644: intptr = &options->print_lastlog;
645: goto parse_flag;
646:
647: case sX11Forwarding:
648: intptr = &options->x11_forwarding;
649: goto parse_flag;
650:
651: case sX11DisplayOffset:
652: intptr = &options->x11_display_offset;
653: goto parse_int;
1.99 stevesk 654:
655: case sX11UseLocalhost:
656: intptr = &options->x11_use_localhost;
657: goto parse_flag;
1.94 markus 658:
659: case sXAuthLocation:
660: charptr = &options->xauth_location;
661: goto parse_filename;
662:
663: case sStrictModes:
664: intptr = &options->strict_modes;
665: goto parse_flag;
666:
667: case sKeepAlives:
668: intptr = &options->keepalives;
669: goto parse_flag;
670:
671: case sEmptyPasswd:
672: intptr = &options->permit_empty_passwd;
673: goto parse_flag;
674:
675: case sUseLogin:
676: intptr = &options->use_login;
677: goto parse_flag;
678:
1.105.2.4! jason 679: case sCompression:
! 680: intptr = &options->compression;
! 681: goto parse_flag;
! 682:
1.94 markus 683: case sGatewayPorts:
684: intptr = &options->gateway_ports;
685: goto parse_flag;
1.25 markus 686:
1.100 markus 687: case sVerifyReverseMapping:
688: intptr = &options->verify_reverse_mapping;
1.94 markus 689: goto parse_flag;
1.53 markus 690:
1.94 markus 691: case sLogFacility:
692: intptr = (int *) &options->log_facility;
693: arg = strdelim(&cp);
694: value = log_facility_number(arg);
1.101 markus 695: if (value == SYSLOG_FACILITY_NOT_SET)
1.94 markus 696: fatal("%.200s line %d: unsupported log facility '%s'",
697: filename, linenum, arg ? arg : "<NONE>");
698: if (*intptr == -1)
699: *intptr = (SyslogFacility) value;
700: break;
1.25 markus 701:
1.94 markus 702: case sLogLevel:
703: intptr = (int *) &options->log_level;
704: arg = strdelim(&cp);
705: value = log_level_number(arg);
1.101 markus 706: if (value == SYSLOG_LEVEL_NOT_SET)
1.94 markus 707: fatal("%.200s line %d: unsupported log level '%s'",
708: filename, linenum, arg ? arg : "<NONE>");
709: if (*intptr == -1)
710: *intptr = (LogLevel) value;
711: break;
712:
713: case sAllowTcpForwarding:
714: intptr = &options->allow_tcp_forwarding;
715: goto parse_flag;
1.102 provos 716:
717: case sUsePrivilegeSeparation:
718: intptr = &use_privsep;
719: goto parse_flag;
1.94 markus 720:
721: case sAllowUsers:
722: while ((arg = strdelim(&cp)) && *arg != '\0') {
723: if (options->num_allow_users >= MAX_ALLOW_USERS)
724: fatal("%s line %d: too many allow users.",
725: filename, linenum);
1.105.2.4! jason 726: options->allow_users[options->num_allow_users++] =
! 727: xstrdup(arg);
1.94 markus 728: }
729: break;
1.25 markus 730:
1.94 markus 731: case sDenyUsers:
732: while ((arg = strdelim(&cp)) && *arg != '\0') {
733: if (options->num_deny_users >= MAX_DENY_USERS)
734: fatal( "%s line %d: too many deny users.",
735: filename, linenum);
1.105.2.4! jason 736: options->deny_users[options->num_deny_users++] =
! 737: xstrdup(arg);
1.94 markus 738: }
739: break;
1.25 markus 740:
1.94 markus 741: case sAllowGroups:
742: while ((arg = strdelim(&cp)) && *arg != '\0') {
743: if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
744: fatal("%s line %d: too many allow groups.",
745: filename, linenum);
1.105.2.4! jason 746: options->allow_groups[options->num_allow_groups++] =
! 747: xstrdup(arg);
1.94 markus 748: }
749: break;
1.33 markus 750:
1.94 markus 751: case sDenyGroups:
752: while ((arg = strdelim(&cp)) && *arg != '\0') {
753: if (options->num_deny_groups >= MAX_DENY_GROUPS)
754: fatal("%s line %d: too many deny groups.",
755: filename, linenum);
756: options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
757: }
758: break;
1.66 markus 759:
1.94 markus 760: case sCiphers:
761: arg = strdelim(&cp);
762: if (!arg || *arg == '\0')
763: fatal("%s line %d: Missing argument.", filename, linenum);
764: if (!ciphers_valid(arg))
765: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
766: filename, linenum, arg ? arg : "<NONE>");
767: if (options->ciphers == NULL)
768: options->ciphers = xstrdup(arg);
769: break;
1.33 markus 770:
1.94 markus 771: case sMacs:
772: arg = strdelim(&cp);
773: if (!arg || *arg == '\0')
774: fatal("%s line %d: Missing argument.", filename, linenum);
775: if (!mac_valid(arg))
776: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
777: filename, linenum, arg ? arg : "<NONE>");
778: if (options->macs == NULL)
779: options->macs = xstrdup(arg);
780: break;
1.43 jakob 781:
1.94 markus 782: case sProtocol:
783: intptr = &options->protocol;
784: arg = strdelim(&cp);
785: if (!arg || *arg == '\0')
786: fatal("%s line %d: Missing argument.", filename, linenum);
787: value = proto_spec(arg);
788: if (value == SSH_PROTO_UNKNOWN)
789: fatal("%s line %d: Bad protocol spec '%s'.",
1.95 deraadt 790: filename, linenum, arg ? arg : "<NONE>");
1.94 markus 791: if (*intptr == SSH_PROTO_UNKNOWN)
792: *intptr = value;
793: break;
794:
795: case sSubsystem:
796: if (options->num_subsystems >= MAX_SUBSYSTEMS) {
797: fatal("%s line %d: too many subsystems defined.",
1.95 deraadt 798: filename, linenum);
1.94 markus 799: }
800: arg = strdelim(&cp);
801: if (!arg || *arg == '\0')
802: fatal("%s line %d: Missing subsystem name.",
1.95 deraadt 803: filename, linenum);
1.94 markus 804: for (i = 0; i < options->num_subsystems; i++)
805: if (strcmp(arg, options->subsystem_name[i]) == 0)
806: fatal("%s line %d: Subsystem '%s' already defined.",
1.95 deraadt 807: filename, linenum, arg);
1.94 markus 808: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
809: arg = strdelim(&cp);
810: if (!arg || *arg == '\0')
811: fatal("%s line %d: Missing subsystem command.",
1.95 deraadt 812: filename, linenum);
1.94 markus 813: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
814: options->num_subsystems++;
815: break;
1.46 markus 816:
1.94 markus 817: case sMaxStartups:
818: arg = strdelim(&cp);
819: if (!arg || *arg == '\0')
820: fatal("%s line %d: Missing MaxStartups spec.",
1.95 deraadt 821: filename, linenum);
1.94 markus 822: if ((n = sscanf(arg, "%d:%d:%d",
823: &options->max_startups_begin,
824: &options->max_startups_rate,
825: &options->max_startups)) == 3) {
826: if (options->max_startups_begin >
827: options->max_startups ||
828: options->max_startups_rate > 100 ||
829: options->max_startups_rate < 1)
1.50 markus 830: fatal("%s line %d: Illegal MaxStartups spec.",
1.87 stevesk 831: filename, linenum);
1.94 markus 832: } else if (n != 1)
833: fatal("%s line %d: Illegal MaxStartups spec.",
834: filename, linenum);
835: else
836: options->max_startups = options->max_startups_begin;
837: break;
838:
839: case sBanner:
840: charptr = &options->banner;
841: goto parse_filename;
842: /*
843: * These options can contain %X options expanded at
844: * connect time, so that you can specify paths like:
845: *
846: * AuthorizedKeysFile /etc/ssh_keys/%u
847: */
848: case sAuthorizedKeysFile:
849: case sAuthorizedKeysFile2:
850: charptr = (opcode == sAuthorizedKeysFile ) ?
851: &options->authorized_keys_file :
852: &options->authorized_keys_file2;
853: goto parse_filename;
854:
855: case sClientAliveInterval:
856: intptr = &options->client_alive_interval;
857: goto parse_time;
858:
859: case sClientAliveCountMax:
860: intptr = &options->client_alive_count_max;
861: goto parse_int;
862:
863: case sDeprecated:
864: log("%s line %d: Deprecated option %s",
865: filename, linenum, arg);
866: while (arg)
867: arg = strdelim(&cp);
868: break;
869:
870: default:
871: fatal("%s line %d: Missing handler for opcode %s (%d)",
872: filename, linenum, arg, opcode);
873: }
874: if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
875: fatal("%s line %d: garbage at end of line; \"%.200s\".",
876: filename, linenum, arg);
877: return 0;
878: }
879:
880: /* Reads the server configuration file. */
1.25 markus 881:
1.94 markus 882: void
883: read_server_config(ServerOptions *options, const char *filename)
884: {
1.105.2.4! jason 885: int linenum, bad_options = 0;
1.94 markus 886: char line[1024];
1.105.2.4! jason 887: FILE *f;
1.81 stevesk 888:
1.94 markus 889: f = fopen(filename, "r");
890: if (!f) {
891: perror(filename);
892: exit(1);
893: }
894: linenum = 0;
895: while (fgets(line, sizeof(line), f)) {
896: /* Update line number counter. */
897: linenum++;
898: if (process_server_config_line(options, line, filename, linenum) != 0)
899: bad_options++;
1.1 deraadt 900: }
1.25 markus 901: fclose(f);
1.78 stevesk 902: if (bad_options > 0)
903: fatal("%s: terminating, %d bad configuration options",
904: filename, bad_options);
1.1 deraadt 905: }