Annotation of src/usr.bin/ssh/servconf.c, Revision 1.100
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.100 ! markus 13: RCSID("$OpenBSD: servconf.c,v 1.99 2002/01/27 14:57:46 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.100 ! markus 103: options->verify_reverse_mapping = -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.100 ! markus 213: if (options->verify_reverse_mapping == -1)
! 214: options->verify_reverse_mapping = 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.100 ! markus 254: sBanner, sVerifyReverseMapping, 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.100 ! markus 323: { "verifyreversemapping", sVerifyReverseMapping },
! 324: { "reversemappingcheck", sVerifyReverseMapping },
1.77 beck 325: { "clientaliveinterval", sClientAliveInterval },
326: { "clientalivecountmax", sClientAliveCountMax },
1.82 markus 327: { "authorizedkeysfile", sAuthorizedKeysFile },
328: { "authorizedkeysfile2", sAuthorizedKeysFile2 },
1.92 stevesk 329: { NULL, sBadOption }
1.1 deraadt 330: };
331:
1.27 markus 332: /*
1.73 stevesk 333: * Returns the number of the token pointed to by cp or sBadOption.
1.27 markus 334: */
1.1 deraadt 335:
1.34 markus 336: static ServerOpCodes
1.25 markus 337: parse_token(const char *cp, const char *filename,
338: int linenum)
1.1 deraadt 339: {
1.55 markus 340: u_int i;
1.1 deraadt 341:
1.25 markus 342: for (i = 0; keywords[i].name; i++)
1.28 markus 343: if (strcasecmp(cp, keywords[i].name) == 0)
1.25 markus 344: return keywords[i].opcode;
345:
1.78 stevesk 346: error("%s: line %d: Bad configuration option: %s",
347: filename, linenum, cp);
1.25 markus 348: return sBadOption;
1.1 deraadt 349: }
350:
1.84 itojun 351: static void
1.76 stevesk 352: add_listen_addr(ServerOptions *options, char *addr, u_short port)
1.74 stevesk 353: {
354: int i;
355:
356: if (options->num_ports == 0)
357: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
1.76 stevesk 358: if (port == 0)
1.74 stevesk 359: for (i = 0; i < options->num_ports; i++)
360: add_one_listen_addr(options, addr, options->ports[i]);
361: else
1.76 stevesk 362: add_one_listen_addr(options, addr, port);
1.74 stevesk 363: }
364:
1.84 itojun 365: static void
1.74 stevesk 366: add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
1.29 markus 367: {
368: struct addrinfo hints, *ai, *aitop;
369: char strport[NI_MAXSERV];
370: int gaierr;
371:
1.74 stevesk 372: memset(&hints, 0, sizeof(hints));
373: hints.ai_family = IPv4or6;
374: hints.ai_socktype = SOCK_STREAM;
375: hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
376: snprintf(strport, sizeof strport, "%d", port);
377: if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
378: fatal("bad addr or host: %s (%s)",
379: addr ? addr : "<NULL>",
380: gai_strerror(gaierr));
381: for (ai = aitop; ai->ai_next; ai = ai->ai_next)
382: ;
383: ai->ai_next = options->listen_addrs;
384: options->listen_addrs = aitop;
1.29 markus 385: }
386:
1.94 markus 387: int
388: process_server_config_line(ServerOptions *options, char *line,
389: const char *filename, int linenum)
1.1 deraadt 390: {
1.74 stevesk 391: char *cp, **charptr, *arg, *p;
1.94 markus 392: int *intptr, value;
1.25 markus 393: ServerOpCodes opcode;
1.87 stevesk 394: int i, n;
1.25 markus 395:
1.94 markus 396: cp = line;
397: arg = strdelim(&cp);
398: /* Ignore leading whitespace */
399: if (*arg == '\0')
400: arg = strdelim(&cp);
401: if (!arg || !*arg || *arg == '#')
402: return 0;
403: intptr = NULL;
404: charptr = NULL;
405: opcode = parse_token(arg, filename, linenum);
406: switch (opcode) {
407: case sBadOption:
408: return -1;
409: case sPort:
410: /* ignore ports from configfile if cmdline specifies ports */
411: if (options->ports_from_cmdline)
412: return 0;
413: if (options->listen_addrs != NULL)
414: fatal("%s line %d: ports must be specified before "
1.98 stevesk 415: "ListenAddress.", filename, linenum);
1.94 markus 416: if (options->num_ports >= MAX_PORTS)
417: fatal("%s line %d: too many ports.",
418: filename, linenum);
1.48 provos 419: arg = strdelim(&cp);
1.94 markus 420: if (!arg || *arg == '\0')
421: fatal("%s line %d: missing port number.",
422: filename, linenum);
423: options->ports[options->num_ports++] = a2port(arg);
424: if (options->ports[options->num_ports-1] == 0)
425: fatal("%s line %d: Badly formatted port number.",
426: filename, linenum);
427: break;
1.29 markus 428:
1.94 markus 429: case sServerKeyBits:
430: intptr = &options->server_key_bits;
1.25 markus 431: parse_int:
1.94 markus 432: arg = strdelim(&cp);
433: if (!arg || *arg == '\0')
434: fatal("%s line %d: missing integer value.",
435: filename, linenum);
436: value = atoi(arg);
437: if (*intptr == -1)
438: *intptr = value;
439: break;
1.25 markus 440:
1.94 markus 441: case sLoginGraceTime:
442: intptr = &options->login_grace_time;
1.81 stevesk 443: parse_time:
1.94 markus 444: arg = strdelim(&cp);
445: if (!arg || *arg == '\0')
446: fatal("%s line %d: missing time value.",
447: filename, linenum);
448: if ((value = convtime(arg)) == -1)
449: fatal("%s line %d: invalid time value.",
450: filename, linenum);
451: if (*intptr == -1)
452: *intptr = value;
453: break;
454:
455: case sKeyRegenerationTime:
456: intptr = &options->key_regeneration_time;
457: goto parse_time;
458:
459: case sListenAddress:
460: arg = strdelim(&cp);
461: if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
462: fatal("%s line %d: missing inet addr.",
463: filename, linenum);
464: if (*arg == '[') {
465: if ((p = strchr(arg, ']')) == NULL)
466: fatal("%s line %d: bad ipv6 inet addr usage.",
467: filename, linenum);
468: arg++;
469: memmove(p, p+1, strlen(p+1)+1);
470: } else if (((p = strchr(arg, ':')) == NULL) ||
471: (strchr(p+1, ':') != NULL)) {
472: add_listen_addr(options, arg, 0);
1.81 stevesk 473: break;
1.94 markus 474: }
475: if (*p == ':') {
476: u_short port;
1.25 markus 477:
1.94 markus 478: p++;
479: if (*p == '\0')
480: fatal("%s line %d: bad inet addr:port usage.",
481: filename, linenum);
482: else {
483: *(p-1) = '\0';
484: if ((port = a2port(p)) == 0)
485: fatal("%s line %d: bad port number.",
1.74 stevesk 486: filename, linenum);
1.94 markus 487: add_listen_addr(options, arg, port);
1.74 stevesk 488: }
1.94 markus 489: } else if (*p == '\0')
490: add_listen_addr(options, arg, 0);
491: else
492: fatal("%s line %d: bad inet addr usage.",
493: filename, linenum);
494: break;
495:
496: case sHostKeyFile:
497: intptr = &options->num_host_key_files;
498: if (*intptr >= MAX_HOSTKEYS)
499: fatal("%s line %d: too many host keys specified (max %d).",
500: filename, linenum, MAX_HOSTKEYS);
501: charptr = &options->host_key_files[*intptr];
502: parse_filename:
503: arg = strdelim(&cp);
504: if (!arg || *arg == '\0')
505: fatal("%s line %d: missing file name.",
506: filename, linenum);
507: if (*charptr == NULL) {
508: *charptr = tilde_expand_filename(arg, getuid());
509: /* increase optional counter */
510: if (intptr != NULL)
511: *intptr = *intptr + 1;
512: }
513: break;
1.76 stevesk 514:
1.94 markus 515: case sPidFile:
516: charptr = &options->pid_file;
517: goto parse_filename;
1.25 markus 518:
1.94 markus 519: case sPermitRootLogin:
520: intptr = &options->permit_root_login;
521: arg = strdelim(&cp);
522: if (!arg || *arg == '\0')
523: fatal("%s line %d: missing yes/"
524: "without-password/forced-commands-only/no "
525: "argument.", filename, linenum);
526: value = 0; /* silence compiler */
527: if (strcmp(arg, "without-password") == 0)
528: value = PERMIT_NO_PASSWD;
529: else if (strcmp(arg, "forced-commands-only") == 0)
530: value = PERMIT_FORCED_ONLY;
531: else if (strcmp(arg, "yes") == 0)
532: value = PERMIT_YES;
533: else if (strcmp(arg, "no") == 0)
534: value = PERMIT_NO;
535: else
536: fatal("%s line %d: Bad yes/"
537: "without-password/forced-commands-only/no "
538: "argument: %s", filename, linenum, arg);
539: if (*intptr == -1)
540: *intptr = value;
541: break;
1.36 markus 542:
1.94 markus 543: case sIgnoreRhosts:
544: intptr = &options->ignore_rhosts;
1.25 markus 545: parse_flag:
1.94 markus 546: arg = strdelim(&cp);
547: if (!arg || *arg == '\0')
548: fatal("%s line %d: missing yes/no argument.",
549: filename, linenum);
550: value = 0; /* silence compiler */
551: if (strcmp(arg, "yes") == 0)
552: value = 1;
553: else if (strcmp(arg, "no") == 0)
554: value = 0;
555: else
556: fatal("%s line %d: Bad yes/no argument: %s",
557: filename, linenum, arg);
558: if (*intptr == -1)
559: *intptr = value;
560: break;
561:
562: case sIgnoreUserKnownHosts:
563: intptr = &options->ignore_user_known_hosts;
564: goto parse_flag;
565:
566: case sRhostsAuthentication:
567: intptr = &options->rhosts_authentication;
568: goto parse_flag;
569:
570: case sRhostsRSAAuthentication:
571: intptr = &options->rhosts_rsa_authentication;
572: goto parse_flag;
573:
574: case sHostbasedAuthentication:
575: intptr = &options->hostbased_authentication;
576: goto parse_flag;
577:
578: case sHostbasedUsesNameFromPacketOnly:
579: intptr = &options->hostbased_uses_name_from_packet_only;
580: goto parse_flag;
581:
582: case sRSAAuthentication:
583: intptr = &options->rsa_authentication;
584: goto parse_flag;
585:
586: case sPubkeyAuthentication:
587: intptr = &options->pubkey_authentication;
588: goto parse_flag;
1.85 dugsong 589: #if defined(KRB4) || defined(KRB5)
1.94 markus 590: case sKerberosAuthentication:
591: intptr = &options->kerberos_authentication;
592: goto parse_flag;
593:
594: case sKerberosOrLocalPasswd:
595: intptr = &options->kerberos_or_local_passwd;
596: goto parse_flag;
597:
598: case sKerberosTicketCleanup:
599: intptr = &options->kerberos_ticket_cleanup;
600: goto parse_flag;
1.1 deraadt 601: #endif
1.85 dugsong 602: #if defined(AFS) || defined(KRB5)
1.94 markus 603: case sKerberosTgtPassing:
604: intptr = &options->kerberos_tgt_passing;
605: goto parse_flag;
1.85 dugsong 606: #endif
607: #ifdef AFS
1.94 markus 608: case sAFSTokenPassing:
609: intptr = &options->afs_token_passing;
610: goto parse_flag;
611: #endif
612:
613: case sPasswordAuthentication:
614: intptr = &options->password_authentication;
615: goto parse_flag;
616:
617: case sKbdInteractiveAuthentication:
618: intptr = &options->kbd_interactive_authentication;
619: goto parse_flag;
620:
621: case sChallengeResponseAuthentication:
622: intptr = &options->challenge_response_authentication;
623: goto parse_flag;
624:
625: case sPrintMotd:
626: intptr = &options->print_motd;
627: goto parse_flag;
628:
629: case sPrintLastLog:
630: intptr = &options->print_lastlog;
631: goto parse_flag;
632:
633: case sX11Forwarding:
634: intptr = &options->x11_forwarding;
635: goto parse_flag;
636:
637: case sX11DisplayOffset:
638: intptr = &options->x11_display_offset;
639: goto parse_int;
1.99 stevesk 640:
641: case sX11UseLocalhost:
642: intptr = &options->x11_use_localhost;
643: goto parse_flag;
1.94 markus 644:
645: case sXAuthLocation:
646: charptr = &options->xauth_location;
647: goto parse_filename;
648:
649: case sStrictModes:
650: intptr = &options->strict_modes;
651: goto parse_flag;
652:
653: case sKeepAlives:
654: intptr = &options->keepalives;
655: goto parse_flag;
656:
657: case sEmptyPasswd:
658: intptr = &options->permit_empty_passwd;
659: goto parse_flag;
660:
661: case sUseLogin:
662: intptr = &options->use_login;
663: goto parse_flag;
664:
665: case sGatewayPorts:
666: intptr = &options->gateway_ports;
667: goto parse_flag;
1.25 markus 668:
1.100 ! markus 669: case sVerifyReverseMapping:
! 670: intptr = &options->verify_reverse_mapping;
1.94 markus 671: goto parse_flag;
1.53 markus 672:
1.94 markus 673: case sLogFacility:
674: intptr = (int *) &options->log_facility;
675: arg = strdelim(&cp);
676: value = log_facility_number(arg);
677: if (value == (SyslogFacility) - 1)
678: fatal("%.200s line %d: unsupported log facility '%s'",
679: filename, linenum, arg ? arg : "<NONE>");
680: if (*intptr == -1)
681: *intptr = (SyslogFacility) value;
682: break;
1.25 markus 683:
1.94 markus 684: case sLogLevel:
685: intptr = (int *) &options->log_level;
686: arg = strdelim(&cp);
687: value = log_level_number(arg);
688: if (value == (LogLevel) - 1)
689: fatal("%.200s line %d: unsupported log level '%s'",
690: filename, linenum, arg ? arg : "<NONE>");
691: if (*intptr == -1)
692: *intptr = (LogLevel) value;
693: break;
694:
695: case sAllowTcpForwarding:
696: intptr = &options->allow_tcp_forwarding;
697: goto parse_flag;
698:
699: case sAllowUsers:
700: while ((arg = strdelim(&cp)) && *arg != '\0') {
701: if (options->num_allow_users >= MAX_ALLOW_USERS)
702: fatal("%s line %d: too many allow users.",
703: filename, linenum);
704: options->allow_users[options->num_allow_users++] = xstrdup(arg);
705: }
706: break;
1.25 markus 707:
1.94 markus 708: case sDenyUsers:
709: while ((arg = strdelim(&cp)) && *arg != '\0') {
710: if (options->num_deny_users >= MAX_DENY_USERS)
711: fatal( "%s line %d: too many deny users.",
712: filename, linenum);
713: options->deny_users[options->num_deny_users++] = xstrdup(arg);
714: }
715: break;
1.25 markus 716:
1.94 markus 717: case sAllowGroups:
718: while ((arg = strdelim(&cp)) && *arg != '\0') {
719: if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
720: fatal("%s line %d: too many allow groups.",
721: filename, linenum);
722: options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
723: }
724: break;
1.33 markus 725:
1.94 markus 726: case sDenyGroups:
727: while ((arg = strdelim(&cp)) && *arg != '\0') {
728: if (options->num_deny_groups >= MAX_DENY_GROUPS)
729: fatal("%s line %d: too many deny groups.",
730: filename, linenum);
731: options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
732: }
733: break;
1.66 markus 734:
1.94 markus 735: case sCiphers:
736: arg = strdelim(&cp);
737: if (!arg || *arg == '\0')
738: fatal("%s line %d: Missing argument.", filename, linenum);
739: if (!ciphers_valid(arg))
740: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
741: filename, linenum, arg ? arg : "<NONE>");
742: if (options->ciphers == NULL)
743: options->ciphers = xstrdup(arg);
744: break;
1.33 markus 745:
1.94 markus 746: case sMacs:
747: arg = strdelim(&cp);
748: if (!arg || *arg == '\0')
749: fatal("%s line %d: Missing argument.", filename, linenum);
750: if (!mac_valid(arg))
751: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
752: filename, linenum, arg ? arg : "<NONE>");
753: if (options->macs == NULL)
754: options->macs = xstrdup(arg);
755: break;
1.43 jakob 756:
1.94 markus 757: case sProtocol:
758: intptr = &options->protocol;
759: arg = strdelim(&cp);
760: if (!arg || *arg == '\0')
761: fatal("%s line %d: Missing argument.", filename, linenum);
762: value = proto_spec(arg);
763: if (value == SSH_PROTO_UNKNOWN)
764: fatal("%s line %d: Bad protocol spec '%s'.",
1.95 deraadt 765: filename, linenum, arg ? arg : "<NONE>");
1.94 markus 766: if (*intptr == SSH_PROTO_UNKNOWN)
767: *intptr = value;
768: break;
769:
770: case sSubsystem:
771: if (options->num_subsystems >= MAX_SUBSYSTEMS) {
772: fatal("%s line %d: too many subsystems defined.",
1.95 deraadt 773: filename, linenum);
1.94 markus 774: }
775: arg = strdelim(&cp);
776: if (!arg || *arg == '\0')
777: fatal("%s line %d: Missing subsystem name.",
1.95 deraadt 778: filename, linenum);
1.94 markus 779: for (i = 0; i < options->num_subsystems; i++)
780: if (strcmp(arg, options->subsystem_name[i]) == 0)
781: fatal("%s line %d: Subsystem '%s' already defined.",
1.95 deraadt 782: filename, linenum, arg);
1.94 markus 783: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
784: arg = strdelim(&cp);
785: if (!arg || *arg == '\0')
786: fatal("%s line %d: Missing subsystem command.",
1.95 deraadt 787: filename, linenum);
1.94 markus 788: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
789: options->num_subsystems++;
790: break;
1.46 markus 791:
1.94 markus 792: case sMaxStartups:
793: arg = strdelim(&cp);
794: if (!arg || *arg == '\0')
795: fatal("%s line %d: Missing MaxStartups spec.",
1.95 deraadt 796: filename, linenum);
1.94 markus 797: if ((n = sscanf(arg, "%d:%d:%d",
798: &options->max_startups_begin,
799: &options->max_startups_rate,
800: &options->max_startups)) == 3) {
801: if (options->max_startups_begin >
802: options->max_startups ||
803: options->max_startups_rate > 100 ||
804: options->max_startups_rate < 1)
1.50 markus 805: fatal("%s line %d: Illegal MaxStartups spec.",
1.87 stevesk 806: filename, linenum);
1.94 markus 807: } else if (n != 1)
808: fatal("%s line %d: Illegal MaxStartups spec.",
809: filename, linenum);
810: else
811: options->max_startups = options->max_startups_begin;
812: break;
813:
814: case sBanner:
815: charptr = &options->banner;
816: goto parse_filename;
817: /*
818: * These options can contain %X options expanded at
819: * connect time, so that you can specify paths like:
820: *
821: * AuthorizedKeysFile /etc/ssh_keys/%u
822: */
823: case sAuthorizedKeysFile:
824: case sAuthorizedKeysFile2:
825: charptr = (opcode == sAuthorizedKeysFile ) ?
826: &options->authorized_keys_file :
827: &options->authorized_keys_file2;
828: goto parse_filename;
829:
830: case sClientAliveInterval:
831: intptr = &options->client_alive_interval;
832: goto parse_time;
833:
834: case sClientAliveCountMax:
835: intptr = &options->client_alive_count_max;
836: goto parse_int;
837:
838: case sDeprecated:
839: log("%s line %d: Deprecated option %s",
840: filename, linenum, arg);
841: while (arg)
842: arg = strdelim(&cp);
843: break;
844:
845: default:
846: fatal("%s line %d: Missing handler for opcode %s (%d)",
847: filename, linenum, arg, opcode);
848: }
849: if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
850: fatal("%s line %d: garbage at end of line; \"%.200s\".",
851: filename, linenum, arg);
852: return 0;
853: }
854:
855: /* Reads the server configuration file. */
1.25 markus 856:
1.94 markus 857: void
858: read_server_config(ServerOptions *options, const char *filename)
859: {
860: FILE *f;
861: char line[1024];
862: int linenum;
863: int bad_options = 0;
1.81 stevesk 864:
1.94 markus 865: f = fopen(filename, "r");
866: if (!f) {
867: perror(filename);
868: exit(1);
869: }
870: linenum = 0;
871: while (fgets(line, sizeof(line), f)) {
872: /* Update line number counter. */
873: linenum++;
874: if (process_server_config_line(options, line, filename, linenum) != 0)
875: bad_options++;
1.1 deraadt 876: }
1.25 markus 877: fclose(f);
1.78 stevesk 878: if (bad_options > 0)
879: fatal("%s: terminating, %d bad configuration options",
880: filename, bad_options);
1.1 deraadt 881: }