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