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