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