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