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