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