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