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