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