Annotation of src/usr.bin/ssh/readconf.c, Revision 1.171
1.171 ! djm 1: /* $OpenBSD: readconf.c,v 1.170 2008/11/03 02:44:41 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:
254: fwd->listen_host = (newfwd->listen_host == NULL) ?
255: NULL : xstrdup(newfwd->listen_host);
256: fwd->listen_port = newfwd->listen_port;
257: fwd->connect_host = xstrdup(newfwd->connect_host);
258: fwd->connect_port = newfwd->connect_port;
1.1 deraadt 259: }
260:
1.19 markus 261: /*
262: * Adds a remote TCP/IP port forward to options. Never returns if there is
263: * an error.
264: */
1.1 deraadt 265:
1.26 markus 266: void
1.135 djm 267: add_remote_forward(Options *options, const Forward *newfwd)
1.1 deraadt 268: {
1.17 markus 269: Forward *fwd;
270: if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
271: fatal("Too many remote forwards (max %d).",
1.93 deraadt 272: SSH_MAX_FORWARDS_PER_DIRECTION);
1.17 markus 273: fwd = &options->remote_forwards[options->num_remote_forwards++];
1.135 djm 274:
275: fwd->listen_host = (newfwd->listen_host == NULL) ?
276: NULL : xstrdup(newfwd->listen_host);
277: fwd->listen_port = newfwd->listen_port;
278: fwd->connect_host = xstrdup(newfwd->connect_host);
279: fwd->connect_port = newfwd->connect_port;
1.1 deraadt 280: }
281:
1.90 stevesk 282: static void
283: clear_forwardings(Options *options)
284: {
285: int i;
286:
1.135 djm 287: for (i = 0; i < options->num_local_forwards; i++) {
1.138 dtucker 288: if (options->local_forwards[i].listen_host != NULL)
289: xfree(options->local_forwards[i].listen_host);
1.135 djm 290: xfree(options->local_forwards[i].connect_host);
291: }
1.90 stevesk 292: options->num_local_forwards = 0;
1.135 djm 293: for (i = 0; i < options->num_remote_forwards; i++) {
1.138 dtucker 294: if (options->remote_forwards[i].listen_host != NULL)
295: xfree(options->remote_forwards[i].listen_host);
1.135 djm 296: xfree(options->remote_forwards[i].connect_host);
297: }
1.90 stevesk 298: options->num_remote_forwards = 0;
1.145 reyk 299: options->tun_open = SSH_TUNMODE_NO;
1.90 stevesk 300: }
301:
1.19 markus 302: /*
1.70 stevesk 303: * Returns the number of the token pointed to by cp or oBadOption.
1.19 markus 304: */
1.1 deraadt 305:
1.26 markus 306: static OpCodes
1.17 markus 307: parse_token(const char *cp, const char *filename, int linenum)
1.1 deraadt 308: {
1.51 markus 309: u_int i;
1.1 deraadt 310:
1.17 markus 311: for (i = 0; keywords[i].name; i++)
1.20 markus 312: if (strcasecmp(cp, keywords[i].name) == 0)
1.17 markus 313: return keywords[i].opcode;
314:
1.75 stevesk 315: error("%s: line %d: Bad configuration option: %s",
316: filename, linenum, cp);
1.17 markus 317: return oBadOption;
1.1 deraadt 318: }
319:
1.19 markus 320: /*
321: * Processes a single option line as used in the configuration files. This
322: * only sets those values that have not already been set.
323: */
1.102 markus 324: #define WHITESPACE " \t\r\n"
1.1 deraadt 325:
1.14 markus 326: int
327: process_config_line(Options *options, const char *host,
1.17 markus 328: char *line, const char *filename, int linenum,
329: int *activep)
1.1 deraadt 330: {
1.135 djm 331: char *s, **charptr, *endofnumber, *keyword, *arg, *arg2, fwdarg[256];
1.146 djm 332: int opcode, *intptr, value, value2, scale;
1.164 dtucker 333: LogLevel *log_level_ptr;
1.146 djm 334: long long orig, val64;
1.102 markus 335: size_t len;
1.135 djm 336: Forward fwd;
1.106 djm 337:
338: /* Strip trailing whitespace */
1.139 deraadt 339: for (len = strlen(line) - 1; len > 0; len--) {
1.106 djm 340: if (strchr(WHITESPACE, line[len]) == NULL)
341: break;
342: line[len] = '\0';
343: }
1.1 deraadt 344:
1.42 provos 345: s = line;
346: /* Get the keyword. (Each line is supposed to begin with a keyword). */
1.149 djm 347: if ((keyword = strdelim(&s)) == NULL)
348: return 0;
1.42 provos 349: /* Ignore leading whitespace. */
350: if (*keyword == '\0')
1.43 markus 351: keyword = strdelim(&s);
1.56 deraadt 352: if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
1.17 markus 353: return 0;
354:
1.38 provos 355: opcode = parse_token(keyword, filename, linenum);
1.17 markus 356:
357: switch (opcode) {
358: case oBadOption:
1.19 markus 359: /* don't panic, but count bad options */
360: return -1;
1.17 markus 361: /* NOTREACHED */
1.111 djm 362: case oConnectTimeout:
363: intptr = &options->connection_timeout;
1.127 markus 364: parse_time:
1.111 djm 365: arg = strdelim(&s);
366: if (!arg || *arg == '\0')
367: fatal("%s line %d: missing time value.",
368: filename, linenum);
369: if ((value = convtime(arg)) == -1)
370: fatal("%s line %d: invalid time value.",
371: filename, linenum);
1.160 dtucker 372: if (*activep && *intptr == -1)
1.111 djm 373: *intptr = value;
374: break;
375:
1.17 markus 376: case oForwardAgent:
377: intptr = &options->forward_agent;
378: parse_flag:
1.42 provos 379: arg = strdelim(&s);
1.40 ho 380: if (!arg || *arg == '\0')
1.17 markus 381: fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
382: value = 0; /* To avoid compiler warning... */
1.38 provos 383: if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1.17 markus 384: value = 1;
1.38 provos 385: else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1.17 markus 386: value = 0;
387: else
388: fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
389: if (*activep && *intptr == -1)
390: *intptr = value;
391: break;
392:
393: case oForwardX11:
394: intptr = &options->forward_x11;
395: goto parse_flag;
396:
1.123 markus 397: case oForwardX11Trusted:
398: intptr = &options->forward_x11_trusted;
399: goto parse_flag;
400:
1.17 markus 401: case oGatewayPorts:
402: intptr = &options->gateway_ports;
403: goto parse_flag;
404:
1.153 markus 405: case oExitOnForwardFailure:
406: intptr = &options->exit_on_forward_failure;
407: goto parse_flag;
408:
1.17 markus 409: case oUsePrivilegedPort:
410: intptr = &options->use_privileged_port;
411: goto parse_flag;
412:
413: case oPasswordAuthentication:
414: intptr = &options->password_authentication;
415: goto parse_flag;
416:
1.171 ! djm 417: case oZeroKnowledgePasswordAuthentication:
! 418: intptr = &options->zero_knowledge_password_authentication;
! 419: goto parse_flag;
! 420:
1.48 markus 421: case oKbdInteractiveAuthentication:
422: intptr = &options->kbd_interactive_authentication;
423: goto parse_flag;
424:
425: case oKbdInteractiveDevices:
426: charptr = &options->kbd_interactive_devices;
427: goto parse_string;
428:
1.50 markus 429: case oPubkeyAuthentication:
430: intptr = &options->pubkey_authentication;
1.30 markus 431: goto parse_flag;
432:
1.17 markus 433: case oRSAAuthentication:
434: intptr = &options->rsa_authentication;
435: goto parse_flag;
436:
437: case oRhostsRSAAuthentication:
438: intptr = &options->rhosts_rsa_authentication;
439: goto parse_flag;
440:
1.72 markus 441: case oHostbasedAuthentication:
442: intptr = &options->hostbased_authentication;
443: goto parse_flag;
444:
1.59 markus 445: case oChallengeResponseAuthentication:
1.78 markus 446: intptr = &options->challenge_response_authentication;
1.17 markus 447: goto parse_flag;
1.108 jakob 448:
1.118 markus 449: case oGssAuthentication:
450: intptr = &options->gss_authentication;
451: goto parse_flag;
452:
453: case oGssDelegateCreds:
454: intptr = &options->gss_deleg_creds;
455: goto parse_flag;
456:
1.17 markus 457: case oBatchMode:
458: intptr = &options->batch_mode;
459: goto parse_flag;
460:
461: case oCheckHostIP:
462: intptr = &options->check_host_ip;
1.167 grunk 463: goto parse_flag;
1.17 markus 464:
1.107 jakob 465: case oVerifyHostKeyDNS:
466: intptr = &options->verify_host_key_dns;
1.125 jakob 467: goto parse_yesnoask;
1.107 jakob 468:
1.17 markus 469: case oStrictHostKeyChecking:
470: intptr = &options->strict_host_key_checking;
1.125 jakob 471: parse_yesnoask:
1.42 provos 472: arg = strdelim(&s);
1.40 ho 473: if (!arg || *arg == '\0')
1.60 stevesk 474: fatal("%.200s line %d: Missing yes/no/ask argument.",
1.93 deraadt 475: filename, linenum);
1.17 markus 476: value = 0; /* To avoid compiler warning... */
1.38 provos 477: if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1.17 markus 478: value = 1;
1.38 provos 479: else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1.17 markus 480: value = 0;
1.38 provos 481: else if (strcmp(arg, "ask") == 0)
1.17 markus 482: value = 2;
483: else
484: fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
485: if (*activep && *intptr == -1)
486: *intptr = value;
487: break;
488:
489: case oCompression:
490: intptr = &options->compression;
491: goto parse_flag;
492:
1.126 markus 493: case oTCPKeepAlive:
494: intptr = &options->tcp_keep_alive;
1.17 markus 495: goto parse_flag;
496:
1.91 markus 497: case oNoHostAuthenticationForLocalhost:
498: intptr = &options->no_host_authentication_for_localhost;
499: goto parse_flag;
500:
1.17 markus 501: case oNumberOfPasswordPrompts:
502: intptr = &options->number_of_password_prompts;
503: goto parse_int;
504:
505: case oCompressionLevel:
506: intptr = &options->compression_level;
507: goto parse_int;
508:
1.105 markus 509: case oRekeyLimit:
510: arg = strdelim(&s);
511: if (!arg || *arg == '\0')
512: fatal("%.200s line %d: Missing argument.", filename, linenum);
513: if (arg[0] < '0' || arg[0] > '9')
514: fatal("%.200s line %d: Bad number.", filename, linenum);
1.146 djm 515: orig = val64 = strtoll(arg, &endofnumber, 10);
1.105 markus 516: if (arg == endofnumber)
517: fatal("%.200s line %d: Bad number.", filename, linenum);
518: switch (toupper(*endofnumber)) {
1.146 djm 519: case '\0':
520: scale = 1;
521: break;
1.105 markus 522: case 'K':
1.146 djm 523: scale = 1<<10;
1.105 markus 524: break;
525: case 'M':
1.146 djm 526: scale = 1<<20;
1.105 markus 527: break;
528: case 'G':
1.146 djm 529: scale = 1<<30;
1.105 markus 530: break;
1.146 djm 531: default:
532: fatal("%.200s line %d: Invalid RekeyLimit suffix",
533: filename, linenum);
1.105 markus 534: }
1.146 djm 535: val64 *= scale;
536: /* detect integer wrap and too-large limits */
1.165 djm 537: if ((val64 / scale) != orig || val64 > UINT_MAX)
1.146 djm 538: fatal("%.200s line %d: RekeyLimit too large",
539: filename, linenum);
540: if (val64 < 16)
541: fatal("%.200s line %d: RekeyLimit too small",
542: filename, linenum);
1.165 djm 543: if (*activep && options->rekey_limit == -1)
544: options->rekey_limit = (u_int32_t)val64;
1.105 markus 545: break;
546:
1.17 markus 547: case oIdentityFile:
1.42 provos 548: arg = strdelim(&s);
1.40 ho 549: if (!arg || *arg == '\0')
1.17 markus 550: fatal("%.200s line %d: Missing argument.", filename, linenum);
551: if (*activep) {
1.50 markus 552: intptr = &options->num_identity_files;
1.27 markus 553: if (*intptr >= SSH_MAX_IDENTITY_FILES)
1.17 markus 554: fatal("%.200s line %d: Too many identity files specified (max %d).",
1.93 deraadt 555: filename, linenum, SSH_MAX_IDENTITY_FILES);
1.161 stevesk 556: charptr = &options->identity_files[*intptr];
1.38 provos 557: *charptr = xstrdup(arg);
1.27 markus 558: *intptr = *intptr + 1;
1.17 markus 559: }
560: break;
561:
1.34 markus 562: case oXAuthLocation:
563: charptr=&options->xauth_location;
564: goto parse_string;
565:
1.17 markus 566: case oUser:
567: charptr = &options->user;
568: parse_string:
1.42 provos 569: arg = strdelim(&s);
1.40 ho 570: if (!arg || *arg == '\0')
1.17 markus 571: fatal("%.200s line %d: Missing argument.", filename, linenum);
572: if (*activep && *charptr == NULL)
1.38 provos 573: *charptr = xstrdup(arg);
1.17 markus 574: break;
575:
576: case oGlobalKnownHostsFile:
577: charptr = &options->system_hostfile;
578: goto parse_string;
579:
580: case oUserKnownHostsFile:
581: charptr = &options->user_hostfile;
582: goto parse_string;
583:
1.27 markus 584: case oGlobalKnownHostsFile2:
585: charptr = &options->system_hostfile2;
586: goto parse_string;
587:
588: case oUserKnownHostsFile2:
589: charptr = &options->user_hostfile2;
590: goto parse_string;
591:
1.17 markus 592: case oHostName:
593: charptr = &options->hostname;
594: goto parse_string;
595:
1.52 markus 596: case oHostKeyAlias:
597: charptr = &options->host_key_alias;
598: goto parse_string;
599:
1.67 markus 600: case oPreferredAuthentications:
601: charptr = &options->preferred_authentications;
602: goto parse_string;
603:
1.77 markus 604: case oBindAddress:
605: charptr = &options->bind_address;
606: goto parse_string;
607:
1.85 jakob 608: case oSmartcardDevice:
1.86 markus 609: charptr = &options->smartcard_device;
610: goto parse_string;
1.85 jakob 611:
1.17 markus 612: case oProxyCommand:
1.144 reyk 613: charptr = &options->proxy_command;
614: parse_command:
1.113 markus 615: if (s == NULL)
616: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.102 markus 617: len = strspn(s, WHITESPACE "=");
1.17 markus 618: if (*activep && *charptr == NULL)
1.102 markus 619: *charptr = xstrdup(s + len);
1.17 markus 620: return 0;
621:
622: case oPort:
623: intptr = &options->port;
624: parse_int:
1.42 provos 625: arg = strdelim(&s);
1.40 ho 626: if (!arg || *arg == '\0')
1.17 markus 627: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 628: if (arg[0] < '0' || arg[0] > '9')
1.17 markus 629: fatal("%.200s line %d: Bad number.", filename, linenum);
1.21 markus 630:
631: /* Octal, decimal, or hex format? */
1.38 provos 632: value = strtol(arg, &endofnumber, 0);
633: if (arg == endofnumber)
1.21 markus 634: fatal("%.200s line %d: Bad number.", filename, linenum);
1.17 markus 635: if (*activep && *intptr == -1)
636: *intptr = value;
637: break;
638:
639: case oConnectionAttempts:
640: intptr = &options->connection_attempts;
641: goto parse_int;
642:
643: case oCipher:
644: intptr = &options->cipher;
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: value = cipher_number(arg);
1.17 markus 649: if (value == -1)
650: fatal("%.200s line %d: Bad cipher '%s'.",
1.93 deraadt 651: filename, linenum, arg ? arg : "<NONE>");
1.17 markus 652: if (*activep && *intptr == -1)
653: *intptr = value;
654: break;
655:
1.25 markus 656: case oCiphers:
1.42 provos 657: arg = strdelim(&s);
1.40 ho 658: if (!arg || *arg == '\0')
1.32 markus 659: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 660: if (!ciphers_valid(arg))
1.31 markus 661: fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.93 deraadt 662: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 663: if (*activep && options->ciphers == NULL)
1.38 provos 664: options->ciphers = xstrdup(arg);
1.25 markus 665: break;
666:
1.62 markus 667: case oMacs:
668: arg = strdelim(&s);
669: if (!arg || *arg == '\0')
670: fatal("%.200s line %d: Missing argument.", filename, linenum);
671: if (!mac_valid(arg))
672: fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
1.93 deraadt 673: filename, linenum, arg ? arg : "<NONE>");
1.62 markus 674: if (*activep && options->macs == NULL)
675: options->macs = xstrdup(arg);
676: break;
677:
1.76 markus 678: case oHostKeyAlgorithms:
679: arg = strdelim(&s);
680: if (!arg || *arg == '\0')
681: fatal("%.200s line %d: Missing argument.", filename, linenum);
682: if (!key_names_valid2(arg))
683: fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
1.93 deraadt 684: filename, linenum, arg ? arg : "<NONE>");
1.76 markus 685: if (*activep && options->hostkeyalgorithms == NULL)
686: options->hostkeyalgorithms = xstrdup(arg);
687: break;
688:
1.25 markus 689: case oProtocol:
690: intptr = &options->protocol;
1.42 provos 691: arg = strdelim(&s);
1.40 ho 692: if (!arg || *arg == '\0')
1.32 markus 693: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 694: value = proto_spec(arg);
1.25 markus 695: if (value == SSH_PROTO_UNKNOWN)
696: fatal("%.200s line %d: Bad protocol spec '%s'.",
1.93 deraadt 697: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 698: if (*activep && *intptr == SSH_PROTO_UNKNOWN)
699: *intptr = value;
700: break;
701:
1.17 markus 702: case oLogLevel:
1.164 dtucker 703: log_level_ptr = &options->log_level;
1.42 provos 704: arg = strdelim(&s);
1.38 provos 705: value = log_level_number(arg);
1.95 markus 706: if (value == SYSLOG_LEVEL_NOT_SET)
1.64 millert 707: fatal("%.200s line %d: unsupported log level '%s'",
1.93 deraadt 708: filename, linenum, arg ? arg : "<NONE>");
1.164 dtucker 709: if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
710: *log_level_ptr = (LogLevel) value;
1.17 markus 711: break;
712:
1.88 stevesk 713: case oLocalForward:
1.17 markus 714: case oRemoteForward:
1.168 stevesk 715: case oDynamicForward:
1.42 provos 716: arg = strdelim(&s);
1.135 djm 717: if (arg == NULL || *arg == '\0')
1.88 stevesk 718: fatal("%.200s line %d: Missing port argument.",
719: filename, linenum);
1.135 djm 720:
1.168 stevesk 721: if (opcode == oLocalForward ||
722: opcode == oRemoteForward) {
723: arg2 = strdelim(&s);
724: if (arg2 == NULL || *arg2 == '\0')
725: fatal("%.200s line %d: Missing target argument.",
726: filename, linenum);
1.135 djm 727:
1.168 stevesk 728: /* construct a string for parse_forward */
729: snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
730: } else if (opcode == oDynamicForward) {
731: strlcpy(fwdarg, arg, sizeof(fwdarg));
732: }
733:
734: if (parse_forward(&fwd, fwdarg,
735: opcode == oDynamicForward ? 1 : 0) == 0)
1.88 stevesk 736: fatal("%.200s line %d: Bad forwarding specification.",
737: filename, linenum);
1.135 djm 738:
1.88 stevesk 739: if (*activep) {
1.168 stevesk 740: if (opcode == oLocalForward ||
741: opcode == oDynamicForward)
1.135 djm 742: add_local_forward(options, &fwd);
1.88 stevesk 743: else if (opcode == oRemoteForward)
1.135 djm 744: add_remote_forward(options, &fwd);
1.88 stevesk 745: }
1.17 markus 746: break;
1.71 markus 747:
1.90 stevesk 748: case oClearAllForwardings:
749: intptr = &options->clear_forwardings;
750: goto parse_flag;
751:
1.17 markus 752: case oHost:
753: *activep = 0;
1.42 provos 754: while ((arg = strdelim(&s)) != NULL && *arg != '\0')
1.38 provos 755: if (match_pattern(host, arg)) {
756: debug("Applying options for %.100s", arg);
1.17 markus 757: *activep = 1;
758: break;
759: }
1.42 provos 760: /* Avoid garbage check below, as strdelim is done. */
1.17 markus 761: return 0;
762:
763: case oEscapeChar:
764: intptr = &options->escape_char;
1.42 provos 765: arg = strdelim(&s);
1.40 ho 766: if (!arg || *arg == '\0')
1.17 markus 767: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38 provos 768: if (arg[0] == '^' && arg[2] == 0 &&
1.51 markus 769: (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
770: value = (u_char) arg[1] & 31;
1.38 provos 771: else if (strlen(arg) == 1)
1.51 markus 772: value = (u_char) arg[0];
1.38 provos 773: else if (strcmp(arg, "none") == 0)
1.79 stevesk 774: value = SSH_ESCAPECHAR_NONE;
1.17 markus 775: else {
776: fatal("%.200s line %d: Bad escape character.",
1.93 deraadt 777: filename, linenum);
1.17 markus 778: /* NOTREACHED */
779: value = 0; /* Avoid compiler warning. */
780: }
781: if (*activep && *intptr == -1)
782: *intptr = value;
1.112 djm 783: break;
784:
785: case oAddressFamily:
786: arg = strdelim(&s);
1.140 markus 787: if (!arg || *arg == '\0')
788: fatal("%s line %d: missing address family.",
789: filename, linenum);
1.114 djm 790: intptr = &options->address_family;
1.112 djm 791: if (strcasecmp(arg, "inet") == 0)
1.114 djm 792: value = AF_INET;
1.112 djm 793: else if (strcasecmp(arg, "inet6") == 0)
1.114 djm 794: value = AF_INET6;
1.112 djm 795: else if (strcasecmp(arg, "any") == 0)
1.114 djm 796: value = AF_UNSPEC;
1.112 djm 797: else
798: fatal("Unsupported AddressFamily \"%s\"", arg);
1.114 djm 799: if (*activep && *intptr == -1)
800: *intptr = value;
1.17 markus 801: break;
802:
1.101 markus 803: case oEnableSSHKeysign:
804: intptr = &options->enable_ssh_keysign;
805: goto parse_flag;
806:
1.128 markus 807: case oIdentitiesOnly:
808: intptr = &options->identities_only;
809: goto parse_flag;
810:
1.127 markus 811: case oServerAliveInterval:
812: intptr = &options->server_alive_interval;
813: goto parse_time;
814:
815: case oServerAliveCountMax:
816: intptr = &options->server_alive_count_max;
817: goto parse_int;
818:
1.130 djm 819: case oSendEnv:
820: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
821: if (strchr(arg, '=') != NULL)
822: fatal("%s line %d: Invalid environment name.",
823: filename, linenum);
1.137 djm 824: if (!*activep)
825: continue;
1.130 djm 826: if (options->num_send_env >= MAX_SEND_ENV)
827: fatal("%s line %d: too many send env.",
828: filename, linenum);
829: options->send_env[options->num_send_env++] =
830: xstrdup(arg);
831: }
832: break;
833:
1.132 djm 834: case oControlPath:
835: charptr = &options->control_path;
836: goto parse_string;
837:
838: case oControlMaster:
839: intptr = &options->control_master;
1.141 djm 840: arg = strdelim(&s);
841: if (!arg || *arg == '\0')
842: fatal("%.200s line %d: Missing ControlMaster argument.",
843: filename, linenum);
844: value = 0; /* To avoid compiler warning... */
845: if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
846: value = SSHCTL_MASTER_YES;
847: else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
848: value = SSHCTL_MASTER_NO;
849: else if (strcmp(arg, "auto") == 0)
850: value = SSHCTL_MASTER_AUTO;
851: else if (strcmp(arg, "ask") == 0)
852: value = SSHCTL_MASTER_ASK;
853: else if (strcmp(arg, "autoask") == 0)
854: value = SSHCTL_MASTER_AUTO_ASK;
855: else
856: fatal("%.200s line %d: Bad ControlMaster argument.",
857: filename, linenum);
858: if (*activep && *intptr == -1)
859: *intptr = value;
860: break;
1.132 djm 861:
1.136 djm 862: case oHashKnownHosts:
863: intptr = &options->hash_known_hosts;
864: goto parse_flag;
865:
1.144 reyk 866: case oTunnel:
867: intptr = &options->tun_open;
1.145 reyk 868: arg = strdelim(&s);
869: if (!arg || *arg == '\0')
870: fatal("%s line %d: Missing yes/point-to-point/"
871: "ethernet/no argument.", filename, linenum);
872: value = 0; /* silence compiler */
873: if (strcasecmp(arg, "ethernet") == 0)
874: value = SSH_TUNMODE_ETHERNET;
875: else if (strcasecmp(arg, "point-to-point") == 0)
876: value = SSH_TUNMODE_POINTOPOINT;
877: else if (strcasecmp(arg, "yes") == 0)
878: value = SSH_TUNMODE_DEFAULT;
879: else if (strcasecmp(arg, "no") == 0)
880: value = SSH_TUNMODE_NO;
881: else
882: fatal("%s line %d: Bad yes/point-to-point/ethernet/"
883: "no argument: %s", filename, linenum, arg);
884: if (*activep)
885: *intptr = value;
886: break;
1.144 reyk 887:
888: case oTunnelDevice:
889: arg = strdelim(&s);
890: if (!arg || *arg == '\0')
891: fatal("%.200s line %d: Missing argument.", filename, linenum);
892: value = a2tun(arg, &value2);
1.145 reyk 893: if (value == SSH_TUNID_ERR)
1.144 reyk 894: fatal("%.200s line %d: Bad tun device.", filename, linenum);
895: if (*activep) {
896: options->tun_local = value;
897: options->tun_remote = value2;
898: }
899: break;
900:
901: case oLocalCommand:
902: charptr = &options->local_command;
903: goto parse_command;
904:
905: case oPermitLocalCommand:
906: intptr = &options->permit_local_command;
907: goto parse_flag;
908:
1.167 grunk 909: case oVisualHostKey:
910: intptr = &options->visual_host_key;
911: goto parse_flag;
912:
1.96 markus 913: case oDeprecated:
1.98 markus 914: debug("%s line %d: Deprecated option \"%s\"",
1.96 markus 915: filename, linenum, keyword);
1.98 markus 916: return 0;
1.96 markus 917:
1.110 jakob 918: case oUnsupported:
919: error("%s line %d: Unsupported option \"%s\"",
920: filename, linenum, keyword);
921: return 0;
922:
1.17 markus 923: default:
924: fatal("process_config_line: Unimplemented opcode %d", opcode);
925: }
926:
927: /* Check that there is no garbage at end of line. */
1.57 djm 928: if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.39 ho 929: fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
1.142 djm 930: filename, linenum, arg);
1.39 ho 931: }
1.17 markus 932: return 0;
1.1 deraadt 933: }
934:
935:
1.19 markus 936: /*
937: * Reads the config file and modifies the options accordingly. Options
938: * should already be initialized before this call. This never returns if
1.89 stevesk 939: * there is an error. If the file does not exist, this returns 0.
1.19 markus 940: */
1.1 deraadt 941:
1.89 stevesk 942: int
1.134 deraadt 943: read_config_file(const char *filename, const char *host, Options *options,
1.129 djm 944: int checkperm)
1.1 deraadt 945: {
1.17 markus 946: FILE *f;
947: char line[1024];
948: int active, linenum;
949: int bad_options = 0;
950:
1.129 djm 951: if ((f = fopen(filename, "r")) == NULL)
1.89 stevesk 952: return 0;
1.129 djm 953:
954: if (checkperm) {
955: struct stat sb;
1.134 deraadt 956:
1.131 dtucker 957: if (fstat(fileno(f), &sb) == -1)
1.129 djm 958: fatal("fstat %s: %s", filename, strerror(errno));
959: if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1.131 dtucker 960: (sb.st_mode & 022) != 0))
1.129 djm 961: fatal("Bad owner or permissions on %s", filename);
962: }
1.17 markus 963:
964: debug("Reading configuration data %.200s", filename);
965:
1.19 markus 966: /*
967: * Mark that we are now processing the options. This flag is turned
968: * on/off by Host specifications.
969: */
1.17 markus 970: active = 1;
971: linenum = 0;
972: while (fgets(line, sizeof(line), f)) {
973: /* Update line number counter. */
974: linenum++;
975: if (process_config_line(options, host, line, filename, linenum, &active) != 0)
976: bad_options++;
977: }
978: fclose(f);
979: if (bad_options > 0)
1.64 millert 980: fatal("%s: terminating, %d bad configuration options",
1.93 deraadt 981: filename, bad_options);
1.89 stevesk 982: return 1;
1.1 deraadt 983: }
984:
1.19 markus 985: /*
986: * Initializes options to special values that indicate that they have not yet
987: * been set. Read_config_file will only set options with this value. Options
988: * are processed in the following order: command line, user config file,
989: * system config file. Last, fill_default_options is called.
990: */
1.1 deraadt 991:
1.26 markus 992: void
1.17 markus 993: initialize_options(Options * options)
1.1 deraadt 994: {
1.17 markus 995: memset(options, 'X', sizeof(*options));
996: options->forward_agent = -1;
997: options->forward_x11 = -1;
1.123 markus 998: options->forward_x11_trusted = -1;
1.153 markus 999: options->exit_on_forward_failure = -1;
1.34 markus 1000: options->xauth_location = NULL;
1.17 markus 1001: options->gateway_ports = -1;
1002: options->use_privileged_port = -1;
1003: options->rsa_authentication = -1;
1.50 markus 1004: options->pubkey_authentication = -1;
1.78 markus 1005: options->challenge_response_authentication = -1;
1.118 markus 1006: options->gss_authentication = -1;
1007: options->gss_deleg_creds = -1;
1.17 markus 1008: options->password_authentication = -1;
1.48 markus 1009: options->kbd_interactive_authentication = -1;
1010: options->kbd_interactive_devices = NULL;
1.17 markus 1011: options->rhosts_rsa_authentication = -1;
1.72 markus 1012: options->hostbased_authentication = -1;
1.17 markus 1013: options->batch_mode = -1;
1014: options->check_host_ip = -1;
1015: options->strict_host_key_checking = -1;
1016: options->compression = -1;
1.126 markus 1017: options->tcp_keep_alive = -1;
1.17 markus 1018: options->compression_level = -1;
1019: options->port = -1;
1.114 djm 1020: options->address_family = -1;
1.17 markus 1021: options->connection_attempts = -1;
1.111 djm 1022: options->connection_timeout = -1;
1.17 markus 1023: options->number_of_password_prompts = -1;
1024: options->cipher = -1;
1.25 markus 1025: options->ciphers = NULL;
1.62 markus 1026: options->macs = NULL;
1.76 markus 1027: options->hostkeyalgorithms = NULL;
1.25 markus 1028: options->protocol = SSH_PROTO_UNKNOWN;
1.17 markus 1029: options->num_identity_files = 0;
1030: options->hostname = NULL;
1.52 markus 1031: options->host_key_alias = NULL;
1.17 markus 1032: options->proxy_command = NULL;
1033: options->user = NULL;
1034: options->escape_char = -1;
1035: options->system_hostfile = NULL;
1036: options->user_hostfile = NULL;
1.27 markus 1037: options->system_hostfile2 = NULL;
1038: options->user_hostfile2 = NULL;
1.17 markus 1039: options->num_local_forwards = 0;
1040: options->num_remote_forwards = 0;
1.90 stevesk 1041: options->clear_forwardings = -1;
1.95 markus 1042: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.67 markus 1043: options->preferred_authentications = NULL;
1.77 markus 1044: options->bind_address = NULL;
1.86 markus 1045: options->smartcard_device = NULL;
1.101 markus 1046: options->enable_ssh_keysign = - 1;
1.91 markus 1047: options->no_host_authentication_for_localhost = - 1;
1.128 markus 1048: options->identities_only = - 1;
1.105 markus 1049: options->rekey_limit = - 1;
1.107 jakob 1050: options->verify_host_key_dns = -1;
1.127 markus 1051: options->server_alive_interval = -1;
1052: options->server_alive_count_max = -1;
1.130 djm 1053: options->num_send_env = 0;
1.132 djm 1054: options->control_path = NULL;
1055: options->control_master = -1;
1.136 djm 1056: options->hash_known_hosts = -1;
1.144 reyk 1057: options->tun_open = -1;
1058: options->tun_local = -1;
1059: options->tun_remote = -1;
1060: options->local_command = NULL;
1061: options->permit_local_command = -1;
1.167 grunk 1062: options->visual_host_key = -1;
1.171 ! djm 1063: options->zero_knowledge_password_authentication = -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;
1.167 grunk 1198: if (options->visual_host_key == -1)
1199: options->visual_host_key = 0;
1.171 ! djm 1200: if (options->zero_knowledge_password_authentication == -1)
! 1201: options->zero_knowledge_password_authentication = 0;
1.144 reyk 1202: /* options->local_command should not be set by default */
1.17 markus 1203: /* options->proxy_command should not be set by default */
1204: /* options->user will be set in the main program if appropriate */
1205: /* options->hostname will be set in the main program if appropriate */
1.52 markus 1206: /* options->host_key_alias should not be set by default */
1.67 markus 1207: /* options->preferred_authentications will be set in ssh */
1.135 djm 1208: }
1209:
1210: /*
1211: * parse_forward
1212: * parses a string containing a port forwarding specification of the form:
1.168 stevesk 1213: * dynamicfwd == 0
1.135 djm 1214: * [listenhost:]listenport:connecthost:connectport
1.168 stevesk 1215: * dynamicfwd == 1
1216: * [listenhost:]listenport
1.135 djm 1217: * returns number of arguments parsed or zero on error
1218: */
1219: int
1.168 stevesk 1220: parse_forward(Forward *fwd, const char *fwdspec, int dynamicfwd)
1.135 djm 1221: {
1222: int i;
1223: char *p, *cp, *fwdarg[4];
1224:
1225: memset(fwd, '\0', sizeof(*fwd));
1226:
1227: cp = p = xstrdup(fwdspec);
1228:
1229: /* skip leading spaces */
1.162 tedu 1230: while (isspace(*cp))
1.135 djm 1231: cp++;
1232:
1233: for (i = 0; i < 4; ++i)
1234: if ((fwdarg[i] = hpdelim(&cp)) == NULL)
1235: break;
1236:
1.170 stevesk 1237: /* Check for trailing garbage */
1.135 djm 1238: if (cp != NULL)
1239: i = 0; /* failure */
1240:
1241: switch (i) {
1.168 stevesk 1242: case 1:
1243: fwd->listen_host = NULL;
1244: fwd->listen_port = a2port(fwdarg[0]);
1245: fwd->connect_host = xstrdup("socks");
1246: break;
1247:
1248: case 2:
1249: fwd->listen_host = xstrdup(cleanhostname(fwdarg[0]));
1250: fwd->listen_port = a2port(fwdarg[1]);
1251: fwd->connect_host = xstrdup("socks");
1252: break;
1253:
1.135 djm 1254: case 3:
1255: fwd->listen_host = NULL;
1256: fwd->listen_port = a2port(fwdarg[0]);
1257: fwd->connect_host = xstrdup(cleanhostname(fwdarg[1]));
1258: fwd->connect_port = a2port(fwdarg[2]);
1259: break;
1260:
1261: case 4:
1262: fwd->listen_host = xstrdup(cleanhostname(fwdarg[0]));
1263: fwd->listen_port = a2port(fwdarg[1]);
1264: fwd->connect_host = xstrdup(cleanhostname(fwdarg[2]));
1265: fwd->connect_port = a2port(fwdarg[3]);
1266: break;
1267: default:
1268: i = 0; /* failure */
1269: }
1270:
1271: xfree(p);
1272:
1.168 stevesk 1273: if (dynamicfwd) {
1274: if (!(i == 1 || i == 2))
1275: goto fail_free;
1276: } else {
1277: if (!(i == 3 || i == 4))
1278: goto fail_free;
1279: if (fwd->connect_port == 0)
1280: goto fail_free;
1281: }
1282:
1283: if (fwd->listen_port == 0)
1.135 djm 1284: goto fail_free;
1285:
1286: if (fwd->connect_host != NULL &&
1287: strlen(fwd->connect_host) >= NI_MAXHOST)
1288: goto fail_free;
1289:
1290: return (i);
1291:
1292: fail_free:
1293: if (fwd->connect_host != NULL)
1294: xfree(fwd->connect_host);
1295: if (fwd->listen_host != NULL)
1296: xfree(fwd->listen_host);
1297: return (0);
1.1 deraadt 1298: }