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