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