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