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