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