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