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