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