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