Annotation of src/usr.bin/ssh/readconf.c, Revision 1.196
1.196 ! dtucker 1: /* $OpenBSD: readconf.c,v 1.195 2013/02/17 23:16:57 dtucker Exp $ */
1.1 deraadt 2: /*
1.18 deraadt 3: * Author: Tatu Ylonen <ylo@cs.hut.fi>
4: * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5: * All rights reserved
6: * Functions for reading the configuration files.
1.26 markus 7: *
1.46 deraadt 8: * As far as I am concerned, the code I have written for this software
9: * can be used freely for any purpose. Any derived versions of this
10: * software must be clearly marked as such, and if the derived work is
11: * incompatible with the protocol description in the RFC file, it must be
12: * called by a name other than "ssh" or "Secure Shell".
1.18 deraadt 13: */
1.1 deraadt 14:
1.147 stevesk 15: #include <sys/types.h>
16: #include <sys/stat.h>
1.152 stevesk 17: #include <sys/socket.h>
18:
19: #include <netinet/in.h>
1.190 djm 20: #include <netinet/in_systm.h>
21: #include <netinet/ip.h>
1.148 stevesk 22:
23: #include <ctype.h>
1.154 stevesk 24: #include <errno.h>
1.155 stevesk 25: #include <netdb.h>
1.159 deraadt 26: #include <signal.h>
1.158 stevesk 27: #include <stdio.h>
1.157 stevesk 28: #include <string.h>
1.156 stevesk 29: #include <unistd.h>
1.1 deraadt 30:
1.159 deraadt 31: #include "xmalloc.h"
1.1 deraadt 32: #include "ssh.h"
1.25 markus 33: #include "compat.h"
1.58 markus 34: #include "cipher.h"
1.55 markus 35: #include "pathnames.h"
1.58 markus 36: #include "log.h"
1.159 deraadt 37: #include "key.h"
1.58 markus 38: #include "readconf.h"
39: #include "match.h"
40: #include "misc.h"
1.159 deraadt 41: #include "buffer.h"
1.62 markus 42: #include "kex.h"
43: #include "mac.h"
1.1 deraadt 44:
45: /* Format of the configuration file:
46:
47: # Configuration data is parsed as follows:
48: # 1. command line options
49: # 2. user-specific file
50: # 3. system-wide file
51: # Any configuration value is only changed the first time it is set.
52: # Thus, host-specific definitions should be at the beginning of the
53: # configuration file, and defaults at the end.
54:
55: # Host-specific declarations. These may override anything above. A single
56: # host may match multiple declarations; these are processed in the order
57: # that they are given in.
58:
59: Host *.ngs.fi ngs.fi
1.96 markus 60: User foo
1.1 deraadt 61:
62: Host fake.com
63: HostName another.host.name.real.org
64: User blaah
65: Port 34289
66: ForwardX11 no
67: ForwardAgent no
68:
69: Host books.com
70: RemoteForward 9999 shadows.cs.hut.fi:9999
71: Cipher 3des
72:
73: Host fascist.blob.com
74: Port 23123
75: User tylonen
76: PasswordAuthentication no
77:
78: Host puukko.hut.fi
79: User t35124p
80: ProxyCommand ssh-proxy %h %p
81:
82: Host *.fr
1.96 markus 83: PublicKeyAuthentication no
1.1 deraadt 84:
85: Host *.su
86: Cipher none
87: PasswordAuthentication no
88:
1.144 reyk 89: Host vpn.fake.com
90: Tunnel yes
91: TunnelDevice 3
92:
1.1 deraadt 93: # Defaults for various options
94: Host *
95: ForwardAgent no
1.50 markus 96: ForwardX11 no
1.1 deraadt 97: PasswordAuthentication yes
98: RSAAuthentication yes
99: RhostsRSAAuthentication yes
100: StrictHostKeyChecking yes
1.126 markus 101: TcpKeepAlive no
1.1 deraadt 102: IdentityFile ~/.ssh/identity
103: Port 22
104: EscapeChar ~
105:
106: */
107:
108: /* Keyword tokens. */
109:
1.17 markus 110: typedef enum {
111: oBadOption,
1.186 djm 112: oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
113: oGatewayPorts, oExitOnForwardFailure,
1.100 deraadt 114: oPasswordAuthentication, oRSAAuthentication,
1.59 markus 115: oChallengeResponseAuthentication, oXAuthLocation,
1.17 markus 116: oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
117: oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
118: oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
119: oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
1.126 markus 120: oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
1.62 markus 121: oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
1.50 markus 122: oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
1.67 markus 123: oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
1.76 markus 124: oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
1.183 markus 125: oHostKeyAlgorithms, oBindAddress, oPKCS11Provider,
1.96 markus 126: oClearAllForwardings, oNoHostAuthenticationForLocalhost,
1.111 djm 127: oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
1.118 markus 128: oAddressFamily, oGssAuthentication, oGssDelegateCreds,
1.128 markus 129: oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
1.187 djm 130: oSendEnv, oControlPath, oControlMaster, oControlPersist,
131: oHashKnownHosts,
1.144 reyk 132: oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
1.182 dtucker 133: oVisualHostKey, oUseRoaming, oZeroKnowledgePasswordAuthentication,
1.192 djm 134: oKexAlgorithms, oIPQoS, oRequestTTY,
1.182 dtucker 135: oDeprecated, oUnsupported
1.1 deraadt 136: } OpCodes;
137:
138: /* Textual representations of the tokens. */
139:
1.17 markus 140: static struct {
141: const char *name;
142: OpCodes opcode;
143: } keywords[] = {
144: { "forwardagent", oForwardAgent },
145: { "forwardx11", oForwardX11 },
1.123 markus 146: { "forwardx11trusted", oForwardX11Trusted },
1.186 djm 147: { "forwardx11timeout", oForwardX11Timeout },
1.153 markus 148: { "exitonforwardfailure", oExitOnForwardFailure },
1.34 markus 149: { "xauthlocation", oXAuthLocation },
1.17 markus 150: { "gatewayports", oGatewayPorts },
151: { "useprivilegedport", oUsePrivilegedPort },
1.116 markus 152: { "rhostsauthentication", oDeprecated },
1.17 markus 153: { "passwordauthentication", oPasswordAuthentication },
1.48 markus 154: { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
155: { "kbdinteractivedevices", oKbdInteractiveDevices },
1.17 markus 156: { "rsaauthentication", oRSAAuthentication },
1.50 markus 157: { "pubkeyauthentication", oPubkeyAuthentication },
1.59 markus 158: { "dsaauthentication", oPubkeyAuthentication }, /* alias */
1.72 markus 159: { "rhostsrsaauthentication", oRhostsRSAAuthentication },
1.73 markus 160: { "hostbasedauthentication", oHostbasedAuthentication },
1.59 markus 161: { "challengeresponseauthentication", oChallengeResponseAuthentication },
162: { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
163: { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
1.110 jakob 164: { "kerberosauthentication", oUnsupported },
165: { "kerberostgtpassing", oUnsupported },
166: { "afstokenpassing", oUnsupported },
1.118 markus 167: #if defined(GSSAPI)
168: { "gssapiauthentication", oGssAuthentication },
169: { "gssapidelegatecredentials", oGssDelegateCreds },
170: #else
171: { "gssapiauthentication", oUnsupported },
172: { "gssapidelegatecredentials", oUnsupported },
173: #endif
1.96 markus 174: { "fallbacktorsh", oDeprecated },
175: { "usersh", oDeprecated },
1.17 markus 176: { "identityfile", oIdentityFile },
1.174 stevesk 177: { "identityfile2", oIdentityFile }, /* obsolete */
1.128 markus 178: { "identitiesonly", oIdentitiesOnly },
1.17 markus 179: { "hostname", oHostName },
1.52 markus 180: { "hostkeyalias", oHostKeyAlias },
1.17 markus 181: { "proxycommand", oProxyCommand },
182: { "port", oPort },
183: { "cipher", oCipher },
1.25 markus 184: { "ciphers", oCiphers },
1.62 markus 185: { "macs", oMacs },
1.25 markus 186: { "protocol", oProtocol },
1.17 markus 187: { "remoteforward", oRemoteForward },
188: { "localforward", oLocalForward },
189: { "user", oUser },
190: { "host", oHost },
191: { "escapechar", oEscapeChar },
192: { "globalknownhostsfile", oGlobalKnownHostsFile },
1.193 djm 193: { "globalknownhostsfile2", oDeprecated },
1.174 stevesk 194: { "userknownhostsfile", oUserKnownHostsFile },
1.193 djm 195: { "userknownhostsfile2", oDeprecated },
1.17 markus 196: { "connectionattempts", oConnectionAttempts },
197: { "batchmode", oBatchMode },
198: { "checkhostip", oCheckHostIP },
199: { "stricthostkeychecking", oStrictHostKeyChecking },
200: { "compression", oCompression },
201: { "compressionlevel", oCompressionLevel },
1.126 markus 202: { "tcpkeepalive", oTCPKeepAlive },
203: { "keepalive", oTCPKeepAlive }, /* obsolete */
1.17 markus 204: { "numberofpasswordprompts", oNumberOfPasswordPrompts },
205: { "loglevel", oLogLevel },
1.71 markus 206: { "dynamicforward", oDynamicForward },
1.67 markus 207: { "preferredauthentications", oPreferredAuthentications },
1.76 markus 208: { "hostkeyalgorithms", oHostKeyAlgorithms },
1.77 markus 209: { "bindaddress", oBindAddress },
1.183 markus 210: #ifdef ENABLE_PKCS11
211: { "smartcarddevice", oPKCS11Provider },
212: { "pkcs11provider", oPKCS11Provider },
1.110 jakob 213: #else
214: { "smartcarddevice", oUnsupported },
1.183 markus 215: { "pkcs11provider", oUnsupported },
1.110 jakob 216: #endif
1.93 deraadt 217: { "clearallforwardings", oClearAllForwardings },
1.101 markus 218: { "enablesshkeysign", oEnableSSHKeysign },
1.107 jakob 219: { "verifyhostkeydns", oVerifyHostKeyDNS },
1.93 deraadt 220: { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
1.105 markus 221: { "rekeylimit", oRekeyLimit },
1.111 djm 222: { "connecttimeout", oConnectTimeout },
1.112 djm 223: { "addressfamily", oAddressFamily },
1.127 markus 224: { "serveraliveinterval", oServerAliveInterval },
225: { "serveralivecountmax", oServerAliveCountMax },
1.130 djm 226: { "sendenv", oSendEnv },
1.132 djm 227: { "controlpath", oControlPath },
228: { "controlmaster", oControlMaster },
1.187 djm 229: { "controlpersist", oControlPersist },
1.136 djm 230: { "hashknownhosts", oHashKnownHosts },
1.144 reyk 231: { "tunnel", oTunnel },
232: { "tunneldevice", oTunnelDevice },
233: { "localcommand", oLocalCommand },
234: { "permitlocalcommand", oPermitLocalCommand },
1.167 grunk 235: { "visualhostkey", oVisualHostKey },
1.177 andreas 236: { "useroaming", oUseRoaming },
1.171 djm 237: #ifdef JPAKE
238: { "zeroknowledgepasswordauthentication",
239: oZeroKnowledgePasswordAuthentication },
240: #else
241: { "zeroknowledgepasswordauthentication", oUnsupported },
242: #endif
1.189 djm 243: { "kexalgorithms", oKexAlgorithms },
1.190 djm 244: { "ipqos", oIPQoS },
1.192 djm 245: { "requesttty", oRequestTTY },
1.171 djm 246:
1.92 stevesk 247: { NULL, oBadOption }
1.13 markus 248: };
249:
1.19 markus 250: /*
251: * Adds a local TCP/IP port forward to options. Never returns if there is an
252: * error.
253: */
1.1 deraadt 254:
1.26 markus 255: void
1.135 djm 256: add_local_forward(Options *options, const Forward *newfwd)
1.1 deraadt 257: {
1.17 markus 258: Forward *fwd;
259: extern uid_t original_real_uid;
1.185 djm 260:
1.135 djm 261: if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0)
1.64 millert 262: fatal("Privileged ports can only be forwarded by root.");
1.185 djm 263: options->local_forwards = xrealloc(options->local_forwards,
264: options->num_local_forwards + 1,
265: sizeof(*options->local_forwards));
1.17 markus 266: fwd = &options->local_forwards[options->num_local_forwards++];
1.135 djm 267:
1.172 stevesk 268: fwd->listen_host = newfwd->listen_host;
1.135 djm 269: fwd->listen_port = newfwd->listen_port;
1.172 stevesk 270: fwd->connect_host = newfwd->connect_host;
1.135 djm 271: fwd->connect_port = newfwd->connect_port;
1.1 deraadt 272: }
273:
1.19 markus 274: /*
275: * Adds a remote TCP/IP port forward to options. Never returns if there is
276: * an error.
277: */
1.1 deraadt 278:
1.26 markus 279: void
1.135 djm 280: add_remote_forward(Options *options, const Forward *newfwd)
1.1 deraadt 281: {
1.17 markus 282: Forward *fwd;
1.185 djm 283:
284: options->remote_forwards = xrealloc(options->remote_forwards,
285: options->num_remote_forwards + 1,
286: sizeof(*options->remote_forwards));
1.17 markus 287: fwd = &options->remote_forwards[options->num_remote_forwards++];
1.135 djm 288:
1.172 stevesk 289: fwd->listen_host = newfwd->listen_host;
1.135 djm 290: fwd->listen_port = newfwd->listen_port;
1.172 stevesk 291: fwd->connect_host = newfwd->connect_host;
1.135 djm 292: fwd->connect_port = newfwd->connect_port;
1.194 markus 293: fwd->handle = newfwd->handle;
1.184 markus 294: fwd->allocated_port = 0;
1.1 deraadt 295: }
296:
1.90 stevesk 297: static void
298: clear_forwardings(Options *options)
299: {
300: int i;
301:
1.135 djm 302: for (i = 0; i < options->num_local_forwards; i++) {
1.138 dtucker 303: if (options->local_forwards[i].listen_host != NULL)
304: xfree(options->local_forwards[i].listen_host);
1.135 djm 305: xfree(options->local_forwards[i].connect_host);
306: }
1.185 djm 307: if (options->num_local_forwards > 0) {
308: xfree(options->local_forwards);
309: options->local_forwards = NULL;
310: }
1.90 stevesk 311: options->num_local_forwards = 0;
1.135 djm 312: for (i = 0; i < options->num_remote_forwards; i++) {
1.138 dtucker 313: if (options->remote_forwards[i].listen_host != NULL)
314: xfree(options->remote_forwards[i].listen_host);
1.135 djm 315: xfree(options->remote_forwards[i].connect_host);
316: }
1.185 djm 317: if (options->num_remote_forwards > 0) {
318: xfree(options->remote_forwards);
319: options->remote_forwards = NULL;
320: }
1.90 stevesk 321: options->num_remote_forwards = 0;
1.145 reyk 322: options->tun_open = SSH_TUNMODE_NO;
1.90 stevesk 323: }
324:
1.195 dtucker 325: void
326: add_identity_file(Options *options, const char *dir, const char *filename,
327: int userprovided)
328: {
329: char *path;
330:
331: if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
332: fatal("Too many identity files specified (max %d)",
333: SSH_MAX_IDENTITY_FILES);
334:
335: if (dir == NULL) /* no dir, filename is absolute */
336: path = xstrdup(filename);
337: else
338: (void)xasprintf(&path, "%.100s%.100s", dir, filename);
339:
340: options->identity_file_userprovided[options->num_identity_files] =
341: userprovided;
342: options->identity_files[options->num_identity_files++] = path;
343: }
344:
1.19 markus 345: /*
1.70 stevesk 346: * Returns the number of the token pointed to by cp or oBadOption.
1.19 markus 347: */
1.1 deraadt 348:
1.26 markus 349: static OpCodes
1.17 markus 350: parse_token(const char *cp, const char *filename, int linenum)
1.1 deraadt 351: {
1.51 markus 352: u_int i;
1.1 deraadt 353:
1.17 markus 354: for (i = 0; keywords[i].name; i++)
1.20 markus 355: if (strcasecmp(cp, keywords[i].name) == 0)
1.17 markus 356: return keywords[i].opcode;
357:
1.75 stevesk 358: error("%s: line %d: Bad configuration option: %s",
359: filename, linenum, cp);
1.17 markus 360: return oBadOption;
1.1 deraadt 361: }
362:
1.19 markus 363: /*
364: * Processes a single option line as used in the configuration files. This
365: * only sets those values that have not already been set.
366: */
1.102 markus 367: #define WHITESPACE " \t\r\n"
1.1 deraadt 368:
1.14 markus 369: int
370: process_config_line(Options *options, const char *host,
1.17 markus 371: char *line, const char *filename, int linenum,
1.196 ! dtucker 372: int *activep, int userconfig)
1.1 deraadt 373: {
1.193 djm 374: char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
375: char **cpptr, fwdarg[256];
376: u_int *uintptr, max_entries = 0;
1.191 djm 377: int negated, opcode, *intptr, value, value2, scale;
1.164 dtucker 378: LogLevel *log_level_ptr;
1.146 djm 379: long long orig, val64;
1.102 markus 380: size_t len;
1.135 djm 381: Forward fwd;
1.106 djm 382:
383: /* Strip trailing whitespace */
1.139 deraadt 384: for (len = strlen(line) - 1; len > 0; len--) {
1.106 djm 385: if (strchr(WHITESPACE, line[len]) == NULL)
386: break;
387: line[len] = '\0';
388: }
1.1 deraadt 389:
1.42 provos 390: s = line;
391: /* Get the keyword. (Each line is supposed to begin with a keyword). */
1.149 djm 392: if ((keyword = strdelim(&s)) == NULL)
393: return 0;
1.42 provos 394: /* Ignore leading whitespace. */
395: if (*keyword == '\0')
1.43 markus 396: keyword = strdelim(&s);
1.56 deraadt 397: if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
1.17 markus 398: return 0;
399:
1.38 provos 400: opcode = parse_token(keyword, filename, linenum);
1.17 markus 401:
402: switch (opcode) {
403: case oBadOption:
1.19 markus 404: /* don't panic, but count bad options */
405: return -1;
1.17 markus 406: /* NOTREACHED */
1.111 djm 407: case oConnectTimeout:
408: intptr = &options->connection_timeout;
1.127 markus 409: parse_time:
1.111 djm 410: arg = strdelim(&s);
411: if (!arg || *arg == '\0')
412: fatal("%s line %d: missing time value.",
413: filename, linenum);
414: if ((value = convtime(arg)) == -1)
415: fatal("%s line %d: invalid time value.",
416: filename, linenum);
1.160 dtucker 417: if (*activep && *intptr == -1)
1.111 djm 418: *intptr = value;
419: break;
420:
1.17 markus 421: case oForwardAgent:
422: intptr = &options->forward_agent;
423: parse_flag:
1.42 provos 424: arg = strdelim(&s);
1.40 ho 425: if (!arg || *arg == '\0')
1.17 markus 426: fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
427: value = 0; /* To avoid compiler warning... */
1.38 provos 428: if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1.17 markus 429: value = 1;
1.38 provos 430: else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1.17 markus 431: value = 0;
432: else
433: fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
434: if (*activep && *intptr == -1)
435: *intptr = value;
436: break;
437:
438: case oForwardX11:
439: intptr = &options->forward_x11;
440: goto parse_flag;
441:
1.123 markus 442: case oForwardX11Trusted:
443: intptr = &options->forward_x11_trusted;
444: goto parse_flag;
1.186 djm 445:
446: case oForwardX11Timeout:
447: intptr = &options->forward_x11_timeout;
448: goto parse_time;
1.123 markus 449:
1.17 markus 450: case oGatewayPorts:
451: intptr = &options->gateway_ports;
452: goto parse_flag;
453:
1.153 markus 454: case oExitOnForwardFailure:
455: intptr = &options->exit_on_forward_failure;
456: goto parse_flag;
457:
1.17 markus 458: case oUsePrivilegedPort:
459: intptr = &options->use_privileged_port;
460: goto parse_flag;
461:
462: case oPasswordAuthentication:
463: intptr = &options->password_authentication;
464: goto parse_flag;
465:
1.171 djm 466: case oZeroKnowledgePasswordAuthentication:
467: intptr = &options->zero_knowledge_password_authentication;
468: goto parse_flag;
469:
1.48 markus 470: case oKbdInteractiveAuthentication:
471: intptr = &options->kbd_interactive_authentication;
472: goto parse_flag;
473:
474: case oKbdInteractiveDevices:
475: charptr = &options->kbd_interactive_devices;
476: goto parse_string;
477:
1.50 markus 478: case oPubkeyAuthentication:
479: intptr = &options->pubkey_authentication;
1.30 markus 480: goto parse_flag;
481:
1.17 markus 482: case oRSAAuthentication:
483: intptr = &options->rsa_authentication;
484: goto parse_flag;
485:
486: case oRhostsRSAAuthentication:
487: intptr = &options->rhosts_rsa_authentication;
488: goto parse_flag;
489:
1.72 markus 490: case oHostbasedAuthentication:
491: intptr = &options->hostbased_authentication;
492: goto parse_flag;
493:
1.59 markus 494: case oChallengeResponseAuthentication:
1.78 markus 495: intptr = &options->challenge_response_authentication;
1.17 markus 496: goto parse_flag;
1.108 jakob 497:
1.118 markus 498: case oGssAuthentication:
499: intptr = &options->gss_authentication;
500: goto parse_flag;
501:
502: case oGssDelegateCreds:
503: intptr = &options->gss_deleg_creds;
504: goto parse_flag;
505:
1.17 markus 506: case oBatchMode:
507: intptr = &options->batch_mode;
508: goto parse_flag;
509:
510: case oCheckHostIP:
511: intptr = &options->check_host_ip;
1.167 grunk 512: goto parse_flag;
1.17 markus 513:
1.107 jakob 514: case oVerifyHostKeyDNS:
515: intptr = &options->verify_host_key_dns;
1.125 jakob 516: goto parse_yesnoask;
1.107 jakob 517:
1.17 markus 518: case oStrictHostKeyChecking:
519: intptr = &options->strict_host_key_checking;
1.125 jakob 520: parse_yesnoask:
1.42 provos 521: arg = strdelim(&s);
1.40 ho 522: if (!arg || *arg == '\0')
1.60 stevesk 523: fatal("%.200s line %d: Missing yes/no/ask argument.",
1.93 deraadt 524: filename, linenum);
1.17 markus 525: value = 0; /* To avoid compiler warning... */
1.38 provos 526: if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1.17 markus 527: value = 1;
1.38 provos 528: else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1.17 markus 529: value = 0;
1.38 provos 530: else if (strcmp(arg, "ask") == 0)
1.17 markus 531: value = 2;
532: else
533: fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
534: if (*activep && *intptr == -1)
535: *intptr = value;
536: break;
537:
538: case oCompression:
539: intptr = &options->compression;
540: goto parse_flag;
541:
1.126 markus 542: case oTCPKeepAlive:
543: intptr = &options->tcp_keep_alive;
1.17 markus 544: goto parse_flag;
545:
1.91 markus 546: case oNoHostAuthenticationForLocalhost:
547: intptr = &options->no_host_authentication_for_localhost;
548: goto parse_flag;
549:
1.17 markus 550: case oNumberOfPasswordPrompts:
551: intptr = &options->number_of_password_prompts;
552: goto parse_int;
553:
554: case oCompressionLevel:
555: intptr = &options->compression_level;
556: goto parse_int;
557:
1.105 markus 558: case oRekeyLimit:
559: arg = strdelim(&s);
560: if (!arg || *arg == '\0')
561: fatal("%.200s line %d: Missing argument.", filename, linenum);
562: if (arg[0] < '0' || arg[0] > '9')
563: fatal("%.200s line %d: Bad number.", filename, linenum);
1.146 djm 564: orig = val64 = strtoll(arg, &endofnumber, 10);
1.105 markus 565: if (arg == endofnumber)
566: fatal("%.200s line %d: Bad number.", filename, linenum);
567: switch (toupper(*endofnumber)) {
1.146 djm 568: case '\0':
569: scale = 1;
570: break;
1.105 markus 571: case 'K':
1.146 djm 572: scale = 1<<10;
1.105 markus 573: break;
574: case 'M':
1.146 djm 575: scale = 1<<20;
1.105 markus 576: break;
577: case 'G':
1.146 djm 578: scale = 1<<30;
1.105 markus 579: break;
1.146 djm 580: default:
581: fatal("%.200s line %d: Invalid RekeyLimit suffix",
582: filename, linenum);
1.105 markus 583: }
1.146 djm 584: val64 *= scale;
585: /* detect integer wrap and too-large limits */
1.165 djm 586: if ((val64 / scale) != orig || val64 > UINT_MAX)
1.146 djm 587: fatal("%.200s line %d: RekeyLimit too large",
588: filename, linenum);
589: if (val64 < 16)
590: fatal("%.200s line %d: RekeyLimit too small",
591: filename, linenum);
1.165 djm 592: if (*activep && options->rekey_limit == -1)
593: options->rekey_limit = (u_int32_t)val64;
1.105 markus 594: break;
595:
1.17 markus 596: case oIdentityFile:
1.42 provos 597: arg = strdelim(&s);
1.40 ho 598: if (!arg || *arg == '\0')
1.17 markus 599: fatal("%.200s line %d: Missing argument.", filename, linenum);
600: if (*activep) {
1.50 markus 601: intptr = &options->num_identity_files;
1.27 markus 602: if (*intptr >= SSH_MAX_IDENTITY_FILES)
1.17 markus 603: fatal("%.200s line %d: Too many identity files specified (max %d).",
1.93 deraadt 604: filename, linenum, SSH_MAX_IDENTITY_FILES);
1.196 ! dtucker 605: add_identity_file(options, NULL, arg, userconfig);
1.17 markus 606: }
607: break;
608:
1.34 markus 609: case oXAuthLocation:
610: charptr=&options->xauth_location;
611: goto parse_string;
612:
1.17 markus 613: case oUser:
614: charptr = &options->user;
615: parse_string:
1.42 provos 616: arg = strdelim(&s);
1.40 ho 617: if (!arg || *arg == '\0')
1.193 djm 618: fatal("%.200s line %d: Missing argument.",
619: filename, linenum);
1.17 markus 620: if (*activep && *charptr == NULL)
1.38 provos 621: *charptr = xstrdup(arg);
1.17 markus 622: break;
623:
624: case oGlobalKnownHostsFile:
1.193 djm 625: cpptr = (char **)&options->system_hostfiles;
626: uintptr = &options->num_system_hostfiles;
627: max_entries = SSH_MAX_HOSTS_FILES;
628: parse_char_array:
629: if (*activep && *uintptr == 0) {
630: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
631: if ((*uintptr) >= max_entries)
632: fatal("%s line %d: "
633: "too many authorized keys files.",
634: filename, linenum);
635: cpptr[(*uintptr)++] = xstrdup(arg);
636: }
637: }
638: return 0;
1.17 markus 639:
640: case oUserKnownHostsFile:
1.193 djm 641: cpptr = (char **)&options->user_hostfiles;
642: uintptr = &options->num_user_hostfiles;
643: max_entries = SSH_MAX_HOSTS_FILES;
644: goto parse_char_array;
1.27 markus 645:
1.17 markus 646: case oHostName:
647: charptr = &options->hostname;
648: goto parse_string;
649:
1.52 markus 650: case oHostKeyAlias:
651: charptr = &options->host_key_alias;
652: goto parse_string;
653:
1.67 markus 654: case oPreferredAuthentications:
655: charptr = &options->preferred_authentications;
656: goto parse_string;
657:
1.77 markus 658: case oBindAddress:
659: charptr = &options->bind_address;
660: goto parse_string;
661:
1.183 markus 662: case oPKCS11Provider:
663: charptr = &options->pkcs11_provider;
1.86 markus 664: goto parse_string;
1.85 jakob 665:
1.17 markus 666: case oProxyCommand:
1.144 reyk 667: charptr = &options->proxy_command;
668: parse_command:
1.113 markus 669: if (s == NULL)
670: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.102 markus 671: len = strspn(s, WHITESPACE "=");
1.17 markus 672: if (*activep && *charptr == NULL)
1.102 markus 673: *charptr = xstrdup(s + len);
1.17 markus 674: return 0;
675:
676: case oPort:
677: intptr = &options->port;
678: parse_int:
1.42 provos 679: arg = strdelim(&s);
1.40 ho 680: if (!arg || *arg == '\0')
1.17 markus 681: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 682: if (arg[0] < '0' || arg[0] > '9')
1.17 markus 683: fatal("%.200s line %d: Bad number.", filename, linenum);
1.21 markus 684:
685: /* Octal, decimal, or hex format? */
1.38 provos 686: value = strtol(arg, &endofnumber, 0);
687: if (arg == endofnumber)
1.21 markus 688: fatal("%.200s line %d: Bad number.", filename, linenum);
1.17 markus 689: if (*activep && *intptr == -1)
690: *intptr = value;
691: break;
692:
693: case oConnectionAttempts:
694: intptr = &options->connection_attempts;
695: goto parse_int;
696:
697: case oCipher:
698: intptr = &options->cipher;
1.42 provos 699: arg = strdelim(&s);
1.40 ho 700: if (!arg || *arg == '\0')
1.32 markus 701: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 702: value = cipher_number(arg);
1.17 markus 703: if (value == -1)
704: fatal("%.200s line %d: Bad cipher '%s'.",
1.93 deraadt 705: filename, linenum, arg ? arg : "<NONE>");
1.17 markus 706: if (*activep && *intptr == -1)
707: *intptr = value;
708: break;
709:
1.25 markus 710: case oCiphers:
1.42 provos 711: arg = strdelim(&s);
1.40 ho 712: if (!arg || *arg == '\0')
1.32 markus 713: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 714: if (!ciphers_valid(arg))
1.31 markus 715: fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.93 deraadt 716: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 717: if (*activep && options->ciphers == NULL)
1.38 provos 718: options->ciphers = xstrdup(arg);
1.25 markus 719: break;
720:
1.62 markus 721: case oMacs:
722: arg = strdelim(&s);
723: if (!arg || *arg == '\0')
724: fatal("%.200s line %d: Missing argument.", filename, linenum);
725: if (!mac_valid(arg))
726: fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
1.93 deraadt 727: filename, linenum, arg ? arg : "<NONE>");
1.62 markus 728: if (*activep && options->macs == NULL)
729: options->macs = xstrdup(arg);
730: break;
731:
1.189 djm 732: case oKexAlgorithms:
733: arg = strdelim(&s);
734: if (!arg || *arg == '\0')
735: fatal("%.200s line %d: Missing argument.",
736: filename, linenum);
737: if (!kex_names_valid(arg))
738: fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
739: filename, linenum, arg ? arg : "<NONE>");
740: if (*activep && options->kex_algorithms == NULL)
741: options->kex_algorithms = xstrdup(arg);
742: break;
743:
1.76 markus 744: case oHostKeyAlgorithms:
745: arg = strdelim(&s);
746: if (!arg || *arg == '\0')
747: fatal("%.200s line %d: Missing argument.", filename, linenum);
748: if (!key_names_valid2(arg))
749: fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
1.93 deraadt 750: filename, linenum, arg ? arg : "<NONE>");
1.76 markus 751: if (*activep && options->hostkeyalgorithms == NULL)
752: options->hostkeyalgorithms = xstrdup(arg);
753: break;
754:
1.25 markus 755: case oProtocol:
756: intptr = &options->protocol;
1.42 provos 757: arg = strdelim(&s);
1.40 ho 758: if (!arg || *arg == '\0')
1.32 markus 759: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 760: value = proto_spec(arg);
1.25 markus 761: if (value == SSH_PROTO_UNKNOWN)
762: fatal("%.200s line %d: Bad protocol spec '%s'.",
1.93 deraadt 763: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 764: if (*activep && *intptr == SSH_PROTO_UNKNOWN)
765: *intptr = value;
766: break;
767:
1.17 markus 768: case oLogLevel:
1.164 dtucker 769: log_level_ptr = &options->log_level;
1.42 provos 770: arg = strdelim(&s);
1.38 provos 771: value = log_level_number(arg);
1.95 markus 772: if (value == SYSLOG_LEVEL_NOT_SET)
1.64 millert 773: fatal("%.200s line %d: unsupported log level '%s'",
1.93 deraadt 774: filename, linenum, arg ? arg : "<NONE>");
1.164 dtucker 775: if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
776: *log_level_ptr = (LogLevel) value;
1.17 markus 777: break;
778:
1.88 stevesk 779: case oLocalForward:
1.17 markus 780: case oRemoteForward:
1.168 stevesk 781: case oDynamicForward:
1.42 provos 782: arg = strdelim(&s);
1.135 djm 783: if (arg == NULL || *arg == '\0')
1.88 stevesk 784: fatal("%.200s line %d: Missing port argument.",
785: filename, linenum);
1.135 djm 786:
1.168 stevesk 787: if (opcode == oLocalForward ||
788: opcode == oRemoteForward) {
789: arg2 = strdelim(&s);
790: if (arg2 == NULL || *arg2 == '\0')
791: fatal("%.200s line %d: Missing target argument.",
792: filename, linenum);
1.135 djm 793:
1.168 stevesk 794: /* construct a string for parse_forward */
795: snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
796: } else if (opcode == oDynamicForward) {
797: strlcpy(fwdarg, arg, sizeof(fwdarg));
798: }
799:
800: if (parse_forward(&fwd, fwdarg,
1.176 djm 801: opcode == oDynamicForward ? 1 : 0,
802: opcode == oRemoteForward ? 1 : 0) == 0)
1.88 stevesk 803: fatal("%.200s line %d: Bad forwarding specification.",
804: filename, linenum);
1.135 djm 805:
1.88 stevesk 806: if (*activep) {
1.168 stevesk 807: if (opcode == oLocalForward ||
808: opcode == oDynamicForward)
1.135 djm 809: add_local_forward(options, &fwd);
1.88 stevesk 810: else if (opcode == oRemoteForward)
1.135 djm 811: add_remote_forward(options, &fwd);
1.88 stevesk 812: }
1.17 markus 813: break;
1.71 markus 814:
1.90 stevesk 815: case oClearAllForwardings:
816: intptr = &options->clear_forwardings;
817: goto parse_flag;
818:
1.17 markus 819: case oHost:
820: *activep = 0;
1.191 djm 821: arg2 = NULL;
822: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
823: negated = *arg == '!';
824: if (negated)
825: arg++;
1.38 provos 826: if (match_pattern(host, arg)) {
1.191 djm 827: if (negated) {
828: debug("%.200s line %d: Skipping Host "
829: "block because of negated match "
830: "for %.100s", filename, linenum,
831: arg);
832: *activep = 0;
833: break;
834: }
835: if (!*activep)
836: arg2 = arg; /* logged below */
1.17 markus 837: *activep = 1;
838: }
1.191 djm 839: }
840: if (*activep)
841: debug("%.200s line %d: Applying options for %.100s",
842: filename, linenum, arg2);
1.42 provos 843: /* Avoid garbage check below, as strdelim is done. */
1.17 markus 844: return 0;
845:
846: case oEscapeChar:
847: intptr = &options->escape_char;
1.42 provos 848: arg = strdelim(&s);
1.40 ho 849: if (!arg || *arg == '\0')
1.17 markus 850: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 851: if (arg[0] == '^' && arg[2] == 0 &&
1.51 markus 852: (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
853: value = (u_char) arg[1] & 31;
1.38 provos 854: else if (strlen(arg) == 1)
1.51 markus 855: value = (u_char) arg[0];
1.38 provos 856: else if (strcmp(arg, "none") == 0)
1.79 stevesk 857: value = SSH_ESCAPECHAR_NONE;
1.17 markus 858: else {
859: fatal("%.200s line %d: Bad escape character.",
1.93 deraadt 860: filename, linenum);
1.17 markus 861: /* NOTREACHED */
862: value = 0; /* Avoid compiler warning. */
863: }
864: if (*activep && *intptr == -1)
865: *intptr = value;
1.112 djm 866: break;
867:
868: case oAddressFamily:
869: arg = strdelim(&s);
1.140 markus 870: if (!arg || *arg == '\0')
871: fatal("%s line %d: missing address family.",
872: filename, linenum);
1.114 djm 873: intptr = &options->address_family;
1.112 djm 874: if (strcasecmp(arg, "inet") == 0)
1.114 djm 875: value = AF_INET;
1.112 djm 876: else if (strcasecmp(arg, "inet6") == 0)
1.114 djm 877: value = AF_INET6;
1.112 djm 878: else if (strcasecmp(arg, "any") == 0)
1.114 djm 879: value = AF_UNSPEC;
1.112 djm 880: else
881: fatal("Unsupported AddressFamily \"%s\"", arg);
1.114 djm 882: if (*activep && *intptr == -1)
883: *intptr = value;
1.17 markus 884: break;
885:
1.101 markus 886: case oEnableSSHKeysign:
887: intptr = &options->enable_ssh_keysign;
888: goto parse_flag;
889:
1.128 markus 890: case oIdentitiesOnly:
891: intptr = &options->identities_only;
892: goto parse_flag;
893:
1.127 markus 894: case oServerAliveInterval:
895: intptr = &options->server_alive_interval;
896: goto parse_time;
897:
898: case oServerAliveCountMax:
899: intptr = &options->server_alive_count_max;
900: goto parse_int;
901:
1.130 djm 902: case oSendEnv:
903: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
904: if (strchr(arg, '=') != NULL)
905: fatal("%s line %d: Invalid environment name.",
906: filename, linenum);
1.137 djm 907: if (!*activep)
908: continue;
1.130 djm 909: if (options->num_send_env >= MAX_SEND_ENV)
910: fatal("%s line %d: too many send env.",
911: filename, linenum);
912: options->send_env[options->num_send_env++] =
913: xstrdup(arg);
914: }
915: break;
916:
1.132 djm 917: case oControlPath:
918: charptr = &options->control_path;
919: goto parse_string;
920:
921: case oControlMaster:
922: intptr = &options->control_master;
1.141 djm 923: arg = strdelim(&s);
924: if (!arg || *arg == '\0')
925: fatal("%.200s line %d: Missing ControlMaster argument.",
926: filename, linenum);
927: value = 0; /* To avoid compiler warning... */
928: if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
929: value = SSHCTL_MASTER_YES;
930: else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
931: value = SSHCTL_MASTER_NO;
932: else if (strcmp(arg, "auto") == 0)
933: value = SSHCTL_MASTER_AUTO;
934: else if (strcmp(arg, "ask") == 0)
935: value = SSHCTL_MASTER_ASK;
936: else if (strcmp(arg, "autoask") == 0)
937: value = SSHCTL_MASTER_AUTO_ASK;
938: else
939: fatal("%.200s line %d: Bad ControlMaster argument.",
940: filename, linenum);
941: if (*activep && *intptr == -1)
942: *intptr = value;
943: break;
1.132 djm 944:
1.187 djm 945: case oControlPersist:
946: /* no/false/yes/true, or a time spec */
947: intptr = &options->control_persist;
948: arg = strdelim(&s);
949: if (!arg || *arg == '\0')
950: fatal("%.200s line %d: Missing ControlPersist"
951: " argument.", filename, linenum);
952: value = 0;
953: value2 = 0; /* timeout */
954: if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
955: value = 0;
956: else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
957: value = 1;
958: else if ((value2 = convtime(arg)) >= 0)
959: value = 1;
960: else
961: fatal("%.200s line %d: Bad ControlPersist argument.",
962: filename, linenum);
963: if (*activep && *intptr == -1) {
964: *intptr = value;
965: options->control_persist_timeout = value2;
966: }
967: break;
968:
1.136 djm 969: case oHashKnownHosts:
970: intptr = &options->hash_known_hosts;
971: goto parse_flag;
972:
1.144 reyk 973: case oTunnel:
974: intptr = &options->tun_open;
1.145 reyk 975: arg = strdelim(&s);
976: if (!arg || *arg == '\0')
977: fatal("%s line %d: Missing yes/point-to-point/"
978: "ethernet/no argument.", filename, linenum);
979: value = 0; /* silence compiler */
980: if (strcasecmp(arg, "ethernet") == 0)
981: value = SSH_TUNMODE_ETHERNET;
982: else if (strcasecmp(arg, "point-to-point") == 0)
983: value = SSH_TUNMODE_POINTOPOINT;
984: else if (strcasecmp(arg, "yes") == 0)
985: value = SSH_TUNMODE_DEFAULT;
986: else if (strcasecmp(arg, "no") == 0)
987: value = SSH_TUNMODE_NO;
988: else
989: fatal("%s line %d: Bad yes/point-to-point/ethernet/"
990: "no argument: %s", filename, linenum, arg);
991: if (*activep)
992: *intptr = value;
993: break;
1.144 reyk 994:
995: case oTunnelDevice:
996: arg = strdelim(&s);
997: if (!arg || *arg == '\0')
998: fatal("%.200s line %d: Missing argument.", filename, linenum);
999: value = a2tun(arg, &value2);
1.145 reyk 1000: if (value == SSH_TUNID_ERR)
1.144 reyk 1001: fatal("%.200s line %d: Bad tun device.", filename, linenum);
1002: if (*activep) {
1003: options->tun_local = value;
1004: options->tun_remote = value2;
1005: }
1006: break;
1007:
1008: case oLocalCommand:
1009: charptr = &options->local_command;
1010: goto parse_command;
1011:
1012: case oPermitLocalCommand:
1013: intptr = &options->permit_local_command;
1014: goto parse_flag;
1015:
1.167 grunk 1016: case oVisualHostKey:
1017: intptr = &options->visual_host_key;
1018: goto parse_flag;
1019:
1.190 djm 1020: case oIPQoS:
1021: arg = strdelim(&s);
1022: if ((value = parse_ipqos(arg)) == -1)
1023: fatal("%s line %d: Bad IPQoS value: %s",
1024: filename, linenum, arg);
1025: arg = strdelim(&s);
1026: if (arg == NULL)
1027: value2 = value;
1028: else if ((value2 = parse_ipqos(arg)) == -1)
1029: fatal("%s line %d: Bad IPQoS value: %s",
1030: filename, linenum, arg);
1031: if (*activep) {
1032: options->ip_qos_interactive = value;
1033: options->ip_qos_bulk = value2;
1034: }
1035: break;
1036:
1.177 andreas 1037: case oUseRoaming:
1038: intptr = &options->use_roaming;
1039: goto parse_flag;
1040:
1.192 djm 1041: case oRequestTTY:
1042: arg = strdelim(&s);
1043: if (!arg || *arg == '\0')
1044: fatal("%s line %d: missing argument.",
1045: filename, linenum);
1046: intptr = &options->request_tty;
1047: if (strcasecmp(arg, "yes") == 0)
1048: value = REQUEST_TTY_YES;
1049: else if (strcasecmp(arg, "no") == 0)
1050: value = REQUEST_TTY_NO;
1051: else if (strcasecmp(arg, "force") == 0)
1052: value = REQUEST_TTY_FORCE;
1053: else if (strcasecmp(arg, "auto") == 0)
1054: value = REQUEST_TTY_AUTO;
1055: else
1056: fatal("Unsupported RequestTTY \"%s\"", arg);
1057: if (*activep && *intptr == -1)
1058: *intptr = value;
1059: break;
1060:
1.96 markus 1061: case oDeprecated:
1.98 markus 1062: debug("%s line %d: Deprecated option \"%s\"",
1.96 markus 1063: filename, linenum, keyword);
1.98 markus 1064: return 0;
1.96 markus 1065:
1.110 jakob 1066: case oUnsupported:
1067: error("%s line %d: Unsupported option \"%s\"",
1068: filename, linenum, keyword);
1069: return 0;
1070:
1.17 markus 1071: default:
1072: fatal("process_config_line: Unimplemented opcode %d", opcode);
1073: }
1074:
1075: /* Check that there is no garbage at end of line. */
1.57 djm 1076: if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.39 ho 1077: fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
1.142 djm 1078: filename, linenum, arg);
1.39 ho 1079: }
1.17 markus 1080: return 0;
1.1 deraadt 1081: }
1082:
1083:
1.19 markus 1084: /*
1085: * Reads the config file and modifies the options accordingly. Options
1086: * should already be initialized before this call. This never returns if
1.89 stevesk 1087: * there is an error. If the file does not exist, this returns 0.
1.19 markus 1088: */
1.1 deraadt 1089:
1.89 stevesk 1090: int
1.134 deraadt 1091: read_config_file(const char *filename, const char *host, Options *options,
1.196 ! dtucker 1092: int flags)
1.1 deraadt 1093: {
1.17 markus 1094: FILE *f;
1095: char line[1024];
1096: int active, linenum;
1097: int bad_options = 0;
1098:
1.129 djm 1099: if ((f = fopen(filename, "r")) == NULL)
1.89 stevesk 1100: return 0;
1.129 djm 1101:
1.196 ! dtucker 1102: if (flags & SSHCONF_CHECKPERM) {
1.129 djm 1103: struct stat sb;
1.134 deraadt 1104:
1.131 dtucker 1105: if (fstat(fileno(f), &sb) == -1)
1.129 djm 1106: fatal("fstat %s: %s", filename, strerror(errno));
1107: if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1.131 dtucker 1108: (sb.st_mode & 022) != 0))
1.129 djm 1109: fatal("Bad owner or permissions on %s", filename);
1110: }
1.17 markus 1111:
1112: debug("Reading configuration data %.200s", filename);
1113:
1.19 markus 1114: /*
1115: * Mark that we are now processing the options. This flag is turned
1116: * on/off by Host specifications.
1117: */
1.17 markus 1118: active = 1;
1119: linenum = 0;
1120: while (fgets(line, sizeof(line), f)) {
1121: /* Update line number counter. */
1122: linenum++;
1.196 ! dtucker 1123: if (process_config_line(options, host, line, filename, linenum,
! 1124: &active, flags & SSHCONF_USERCONF) != 0)
1.17 markus 1125: bad_options++;
1126: }
1127: fclose(f);
1128: if (bad_options > 0)
1.64 millert 1129: fatal("%s: terminating, %d bad configuration options",
1.93 deraadt 1130: filename, bad_options);
1.89 stevesk 1131: return 1;
1.1 deraadt 1132: }
1133:
1.19 markus 1134: /*
1135: * Initializes options to special values that indicate that they have not yet
1136: * been set. Read_config_file will only set options with this value. Options
1137: * are processed in the following order: command line, user config file,
1138: * system config file. Last, fill_default_options is called.
1139: */
1.1 deraadt 1140:
1.26 markus 1141: void
1.17 markus 1142: initialize_options(Options * options)
1.1 deraadt 1143: {
1.17 markus 1144: memset(options, 'X', sizeof(*options));
1145: options->forward_agent = -1;
1146: options->forward_x11 = -1;
1.123 markus 1147: options->forward_x11_trusted = -1;
1.186 djm 1148: options->forward_x11_timeout = -1;
1.153 markus 1149: options->exit_on_forward_failure = -1;
1.34 markus 1150: options->xauth_location = NULL;
1.17 markus 1151: options->gateway_ports = -1;
1152: options->use_privileged_port = -1;
1153: options->rsa_authentication = -1;
1.50 markus 1154: options->pubkey_authentication = -1;
1.78 markus 1155: options->challenge_response_authentication = -1;
1.118 markus 1156: options->gss_authentication = -1;
1157: options->gss_deleg_creds = -1;
1.17 markus 1158: options->password_authentication = -1;
1.48 markus 1159: options->kbd_interactive_authentication = -1;
1160: options->kbd_interactive_devices = NULL;
1.17 markus 1161: options->rhosts_rsa_authentication = -1;
1.72 markus 1162: options->hostbased_authentication = -1;
1.17 markus 1163: options->batch_mode = -1;
1164: options->check_host_ip = -1;
1165: options->strict_host_key_checking = -1;
1166: options->compression = -1;
1.126 markus 1167: options->tcp_keep_alive = -1;
1.17 markus 1168: options->compression_level = -1;
1169: options->port = -1;
1.114 djm 1170: options->address_family = -1;
1.17 markus 1171: options->connection_attempts = -1;
1.111 djm 1172: options->connection_timeout = -1;
1.17 markus 1173: options->number_of_password_prompts = -1;
1174: options->cipher = -1;
1.25 markus 1175: options->ciphers = NULL;
1.62 markus 1176: options->macs = NULL;
1.189 djm 1177: options->kex_algorithms = NULL;
1.76 markus 1178: options->hostkeyalgorithms = NULL;
1.25 markus 1179: options->protocol = SSH_PROTO_UNKNOWN;
1.17 markus 1180: options->num_identity_files = 0;
1181: options->hostname = NULL;
1.52 markus 1182: options->host_key_alias = NULL;
1.17 markus 1183: options->proxy_command = NULL;
1184: options->user = NULL;
1185: options->escape_char = -1;
1.193 djm 1186: options->num_system_hostfiles = 0;
1187: options->num_user_hostfiles = 0;
1.185 djm 1188: options->local_forwards = NULL;
1.17 markus 1189: options->num_local_forwards = 0;
1.185 djm 1190: options->remote_forwards = NULL;
1.17 markus 1191: options->num_remote_forwards = 0;
1.90 stevesk 1192: options->clear_forwardings = -1;
1.95 markus 1193: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.67 markus 1194: options->preferred_authentications = NULL;
1.77 markus 1195: options->bind_address = NULL;
1.183 markus 1196: options->pkcs11_provider = NULL;
1.101 markus 1197: options->enable_ssh_keysign = - 1;
1.91 markus 1198: options->no_host_authentication_for_localhost = - 1;
1.128 markus 1199: options->identities_only = - 1;
1.105 markus 1200: options->rekey_limit = - 1;
1.107 jakob 1201: options->verify_host_key_dns = -1;
1.127 markus 1202: options->server_alive_interval = -1;
1203: options->server_alive_count_max = -1;
1.130 djm 1204: options->num_send_env = 0;
1.132 djm 1205: options->control_path = NULL;
1206: options->control_master = -1;
1.187 djm 1207: options->control_persist = -1;
1208: options->control_persist_timeout = 0;
1.136 djm 1209: options->hash_known_hosts = -1;
1.144 reyk 1210: options->tun_open = -1;
1211: options->tun_local = -1;
1212: options->tun_remote = -1;
1213: options->local_command = NULL;
1214: options->permit_local_command = -1;
1.177 andreas 1215: options->use_roaming = -1;
1.167 grunk 1216: options->visual_host_key = -1;
1.171 djm 1217: options->zero_knowledge_password_authentication = -1;
1.190 djm 1218: options->ip_qos_interactive = -1;
1219: options->ip_qos_bulk = -1;
1.192 djm 1220: options->request_tty = -1;
1.1 deraadt 1221: }
1222:
1.19 markus 1223: /*
1224: * Called after processing other sources of option data, this fills those
1225: * options for which no value has been specified with their default values.
1226: */
1.1 deraadt 1227:
1.26 markus 1228: void
1.17 markus 1229: fill_default_options(Options * options)
1.1 deraadt 1230: {
1.61 deraadt 1231: int len;
1232:
1.17 markus 1233: if (options->forward_agent == -1)
1.33 markus 1234: options->forward_agent = 0;
1.17 markus 1235: if (options->forward_x11 == -1)
1.23 markus 1236: options->forward_x11 = 0;
1.123 markus 1237: if (options->forward_x11_trusted == -1)
1238: options->forward_x11_trusted = 0;
1.186 djm 1239: if (options->forward_x11_timeout == -1)
1240: options->forward_x11_timeout = 1200;
1.153 markus 1241: if (options->exit_on_forward_failure == -1)
1242: options->exit_on_forward_failure = 0;
1.34 markus 1243: if (options->xauth_location == NULL)
1.80 markus 1244: options->xauth_location = _PATH_XAUTH;
1.17 markus 1245: if (options->gateway_ports == -1)
1246: options->gateway_ports = 0;
1247: if (options->use_privileged_port == -1)
1.65 markus 1248: options->use_privileged_port = 0;
1.17 markus 1249: if (options->rsa_authentication == -1)
1250: options->rsa_authentication = 1;
1.50 markus 1251: if (options->pubkey_authentication == -1)
1252: options->pubkey_authentication = 1;
1.78 markus 1253: if (options->challenge_response_authentication == -1)
1.83 markus 1254: options->challenge_response_authentication = 1;
1.118 markus 1255: if (options->gss_authentication == -1)
1.122 markus 1256: options->gss_authentication = 0;
1.118 markus 1257: if (options->gss_deleg_creds == -1)
1258: options->gss_deleg_creds = 0;
1.17 markus 1259: if (options->password_authentication == -1)
1260: options->password_authentication = 1;
1.48 markus 1261: if (options->kbd_interactive_authentication == -1)
1.59 markus 1262: options->kbd_interactive_authentication = 1;
1.17 markus 1263: if (options->rhosts_rsa_authentication == -1)
1.99 stevesk 1264: options->rhosts_rsa_authentication = 0;
1.72 markus 1265: if (options->hostbased_authentication == -1)
1266: options->hostbased_authentication = 0;
1.17 markus 1267: if (options->batch_mode == -1)
1268: options->batch_mode = 0;
1269: if (options->check_host_ip == -1)
1270: options->check_host_ip = 1;
1271: if (options->strict_host_key_checking == -1)
1272: options->strict_host_key_checking = 2; /* 2 is default */
1273: if (options->compression == -1)
1274: options->compression = 0;
1.126 markus 1275: if (options->tcp_keep_alive == -1)
1276: options->tcp_keep_alive = 1;
1.17 markus 1277: if (options->compression_level == -1)
1278: options->compression_level = 6;
1279: if (options->port == -1)
1280: options->port = 0; /* Filled in ssh_connect. */
1.114 djm 1281: if (options->address_family == -1)
1282: options->address_family = AF_UNSPEC;
1.17 markus 1283: if (options->connection_attempts == -1)
1.84 markus 1284: options->connection_attempts = 1;
1.17 markus 1285: if (options->number_of_password_prompts == -1)
1286: options->number_of_password_prompts = 3;
1287: /* Selected in ssh_login(). */
1288: if (options->cipher == -1)
1289: options->cipher = SSH_CIPHER_NOT_SET;
1.31 markus 1290: /* options->ciphers, default set in myproposals.h */
1.62 markus 1291: /* options->macs, default set in myproposals.h */
1.189 djm 1292: /* options->kex_algorithms, default set in myproposals.h */
1.76 markus 1293: /* options->hostkeyalgorithms, default set in myproposals.h */
1.25 markus 1294: if (options->protocol == SSH_PROTO_UNKNOWN)
1.178 markus 1295: options->protocol = SSH_PROTO_2;
1.17 markus 1296: if (options->num_identity_files == 0) {
1.50 markus 1297: if (options->protocol & SSH_PROTO_1) {
1.195 dtucker 1298: add_identity_file(options, "~/",
1299: _PATH_SSH_CLIENT_IDENTITY, 0);
1.50 markus 1300: }
1301: if (options->protocol & SSH_PROTO_2) {
1.195 dtucker 1302: add_identity_file(options, "~/",
1303: _PATH_SSH_CLIENT_ID_RSA, 0);
1304: add_identity_file(options, "~/",
1305: _PATH_SSH_CLIENT_ID_DSA, 0);
1306: add_identity_file(options, "~/",
1307: _PATH_SSH_CLIENT_ID_ECDSA, 0);
1.50 markus 1308: }
1.27 markus 1309: }
1.17 markus 1310: if (options->escape_char == -1)
1311: options->escape_char = '~';
1.193 djm 1312: if (options->num_system_hostfiles == 0) {
1313: options->system_hostfiles[options->num_system_hostfiles++] =
1314: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
1315: options->system_hostfiles[options->num_system_hostfiles++] =
1316: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
1317: }
1318: if (options->num_user_hostfiles == 0) {
1319: options->user_hostfiles[options->num_user_hostfiles++] =
1320: xstrdup(_PATH_SSH_USER_HOSTFILE);
1321: options->user_hostfiles[options->num_user_hostfiles++] =
1322: xstrdup(_PATH_SSH_USER_HOSTFILE2);
1323: }
1.95 markus 1324: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.54 markus 1325: options->log_level = SYSLOG_LEVEL_INFO;
1.90 stevesk 1326: if (options->clear_forwardings == 1)
1327: clear_forwardings(options);
1.91 markus 1328: if (options->no_host_authentication_for_localhost == - 1)
1329: options->no_host_authentication_for_localhost = 0;
1.128 markus 1330: if (options->identities_only == -1)
1331: options->identities_only = 0;
1.101 markus 1332: if (options->enable_ssh_keysign == -1)
1333: options->enable_ssh_keysign = 0;
1.105 markus 1334: if (options->rekey_limit == -1)
1335: options->rekey_limit = 0;
1.107 jakob 1336: if (options->verify_host_key_dns == -1)
1337: options->verify_host_key_dns = 0;
1.127 markus 1338: if (options->server_alive_interval == -1)
1339: options->server_alive_interval = 0;
1340: if (options->server_alive_count_max == -1)
1341: options->server_alive_count_max = 3;
1.132 djm 1342: if (options->control_master == -1)
1343: options->control_master = 0;
1.187 djm 1344: if (options->control_persist == -1) {
1345: options->control_persist = 0;
1346: options->control_persist_timeout = 0;
1347: }
1.136 djm 1348: if (options->hash_known_hosts == -1)
1349: options->hash_known_hosts = 0;
1.144 reyk 1350: if (options->tun_open == -1)
1.145 reyk 1351: options->tun_open = SSH_TUNMODE_NO;
1352: if (options->tun_local == -1)
1353: options->tun_local = SSH_TUNID_ANY;
1354: if (options->tun_remote == -1)
1355: options->tun_remote = SSH_TUNID_ANY;
1.144 reyk 1356: if (options->permit_local_command == -1)
1357: options->permit_local_command = 0;
1.177 andreas 1358: if (options->use_roaming == -1)
1359: options->use_roaming = 1;
1.167 grunk 1360: if (options->visual_host_key == -1)
1361: options->visual_host_key = 0;
1.171 djm 1362: if (options->zero_knowledge_password_authentication == -1)
1363: options->zero_knowledge_password_authentication = 0;
1.190 djm 1364: if (options->ip_qos_interactive == -1)
1365: options->ip_qos_interactive = IPTOS_LOWDELAY;
1366: if (options->ip_qos_bulk == -1)
1367: options->ip_qos_bulk = IPTOS_THROUGHPUT;
1.192 djm 1368: if (options->request_tty == -1)
1369: options->request_tty = REQUEST_TTY_AUTO;
1.144 reyk 1370: /* options->local_command should not be set by default */
1.17 markus 1371: /* options->proxy_command should not be set by default */
1372: /* options->user will be set in the main program if appropriate */
1373: /* options->hostname will be set in the main program if appropriate */
1.52 markus 1374: /* options->host_key_alias should not be set by default */
1.67 markus 1375: /* options->preferred_authentications will be set in ssh */
1.135 djm 1376: }
1377:
1378: /*
1379: * parse_forward
1380: * parses a string containing a port forwarding specification of the form:
1.168 stevesk 1381: * dynamicfwd == 0
1.135 djm 1382: * [listenhost:]listenport:connecthost:connectport
1.168 stevesk 1383: * dynamicfwd == 1
1384: * [listenhost:]listenport
1.135 djm 1385: * returns number of arguments parsed or zero on error
1386: */
1387: int
1.176 djm 1388: parse_forward(Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
1.135 djm 1389: {
1390: int i;
1391: char *p, *cp, *fwdarg[4];
1392:
1393: memset(fwd, '\0', sizeof(*fwd));
1394:
1395: cp = p = xstrdup(fwdspec);
1396:
1397: /* skip leading spaces */
1.162 tedu 1398: while (isspace(*cp))
1.135 djm 1399: cp++;
1400:
1401: for (i = 0; i < 4; ++i)
1402: if ((fwdarg[i] = hpdelim(&cp)) == NULL)
1403: break;
1404:
1.170 stevesk 1405: /* Check for trailing garbage */
1.135 djm 1406: if (cp != NULL)
1407: i = 0; /* failure */
1408:
1409: switch (i) {
1.168 stevesk 1410: case 1:
1411: fwd->listen_host = NULL;
1412: fwd->listen_port = a2port(fwdarg[0]);
1413: fwd->connect_host = xstrdup("socks");
1414: break;
1415:
1416: case 2:
1417: fwd->listen_host = xstrdup(cleanhostname(fwdarg[0]));
1418: fwd->listen_port = a2port(fwdarg[1]);
1419: fwd->connect_host = xstrdup("socks");
1420: break;
1421:
1.135 djm 1422: case 3:
1423: fwd->listen_host = NULL;
1424: fwd->listen_port = a2port(fwdarg[0]);
1425: fwd->connect_host = xstrdup(cleanhostname(fwdarg[1]));
1426: fwd->connect_port = a2port(fwdarg[2]);
1427: break;
1428:
1429: case 4:
1430: fwd->listen_host = xstrdup(cleanhostname(fwdarg[0]));
1431: fwd->listen_port = a2port(fwdarg[1]);
1432: fwd->connect_host = xstrdup(cleanhostname(fwdarg[2]));
1433: fwd->connect_port = a2port(fwdarg[3]);
1434: break;
1435: default:
1436: i = 0; /* failure */
1437: }
1438:
1439: xfree(p);
1440:
1.168 stevesk 1441: if (dynamicfwd) {
1442: if (!(i == 1 || i == 2))
1443: goto fail_free;
1444: } else {
1445: if (!(i == 3 || i == 4))
1446: goto fail_free;
1.175 djm 1447: if (fwd->connect_port <= 0)
1.168 stevesk 1448: goto fail_free;
1449: }
1450:
1.176 djm 1451: if (fwd->listen_port < 0 || (!remotefwd && fwd->listen_port == 0))
1.135 djm 1452: goto fail_free;
1453:
1454: if (fwd->connect_host != NULL &&
1455: strlen(fwd->connect_host) >= NI_MAXHOST)
1456: goto fail_free;
1.176 djm 1457: if (fwd->listen_host != NULL &&
1458: strlen(fwd->listen_host) >= NI_MAXHOST)
1459: goto fail_free;
1460:
1.135 djm 1461:
1462: return (i);
1463:
1464: fail_free:
1.173 djm 1465: if (fwd->connect_host != NULL) {
1.135 djm 1466: xfree(fwd->connect_host);
1.173 djm 1467: fwd->connect_host = NULL;
1468: }
1469: if (fwd->listen_host != NULL) {
1.135 djm 1470: xfree(fwd->listen_host);
1.173 djm 1471: fwd->listen_host = NULL;
1472: }
1.135 djm 1473: return (0);
1.1 deraadt 1474: }