2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * Functions for reading the configuration files.
7 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
15 RCSID("$OpenBSD: readconf.c,v 1.121 2003/09/01 18:15:50 markus Exp $");
21 #include "pathnames.h"
29 /* Format of the configuration file:
31 # Configuration data is parsed as follows:
32 # 1. command line options
33 # 2. user-specific file
35 # Any configuration value is only changed the first time it is set.
36 # Thus, host-specific definitions should be at the beginning of the
37 # configuration file, and defaults at the end.
39 # Host-specific declarations. These may override anything above. A single
40 # host may match multiple declarations; these are processed in the order
41 # that they are given in.
47 HostName another.host.name.real.org
54 RemoteForward 9999 shadows.cs.hut.fi:9999
60 PasswordAuthentication no
64 ProxyCommand ssh-proxy %h %p
67 PublicKeyAuthentication no
71 PasswordAuthentication no
73 # Defaults for various options
77 PasswordAuthentication yes
79 RhostsRSAAuthentication yes
80 StrictHostKeyChecking yes
82 IdentityFile ~/.ssh/identity
92 oForwardAgent, oForwardX11, oGatewayPorts,
93 oPasswordAuthentication, oRSAAuthentication,
94 oChallengeResponseAuthentication, oXAuthLocation,
95 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
96 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
97 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
98 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
99 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts,
100 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
101 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
102 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
103 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
104 oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
105 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
106 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
107 oAddressFamily, oGssAuthentication, oGssKeyEx, oGssDelegateCreds,
108 oDeprecated, oUnsupported
111 /* Textual representations of the tokens. */
117 { "forwardagent", oForwardAgent },
118 { "forwardx11", oForwardX11 },
119 { "xauthlocation", oXAuthLocation },
120 { "gatewayports", oGatewayPorts },
121 { "useprivilegedport", oUsePrivilegedPort },
122 { "rhostsauthentication", oDeprecated },
123 { "passwordauthentication", oPasswordAuthentication },
124 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
125 { "kbdinteractivedevices", oKbdInteractiveDevices },
126 { "rsaauthentication", oRSAAuthentication },
127 { "pubkeyauthentication", oPubkeyAuthentication },
128 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
129 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
130 { "hostbasedauthentication", oHostbasedAuthentication },
131 { "challengeresponseauthentication", oChallengeResponseAuthentication },
132 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
133 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
134 { "kerberosauthentication", oUnsupported },
135 { "kerberostgtpassing", oUnsupported },
136 { "afstokenpassing", oUnsupported },
138 { "gssapiauthentication", oGssAuthentication },
139 { "gssapikeyexchange", oGssKeyEx },
140 { "gssapidelegatecredentials", oGssDelegateCreds },
142 { "gssapiauthentication", oUnsupported },
143 { "gssapikeyexchange", oUnsupported },
144 { "gssapidelegatecredentials", oUnsupported },
146 { "fallbacktorsh", oDeprecated },
147 { "usersh", oDeprecated },
148 { "identityfile", oIdentityFile },
149 { "identityfile2", oIdentityFile }, /* alias */
150 { "hostname", oHostName },
151 { "hostkeyalias", oHostKeyAlias },
152 { "proxycommand", oProxyCommand },
154 { "cipher", oCipher },
155 { "ciphers", oCiphers },
157 { "protocol", oProtocol },
158 { "remoteforward", oRemoteForward },
159 { "localforward", oLocalForward },
162 { "escapechar", oEscapeChar },
163 { "globalknownhostsfile", oGlobalKnownHostsFile },
164 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
165 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
166 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
167 { "connectionattempts", oConnectionAttempts },
168 { "batchmode", oBatchMode },
169 { "checkhostip", oCheckHostIP },
170 { "stricthostkeychecking", oStrictHostKeyChecking },
171 { "compression", oCompression },
172 { "compressionlevel", oCompressionLevel },
173 { "keepalive", oKeepAlives },
174 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
175 { "loglevel", oLogLevel },
176 { "dynamicforward", oDynamicForward },
177 { "preferredauthentications", oPreferredAuthentications },
178 { "hostkeyalgorithms", oHostKeyAlgorithms },
179 { "bindaddress", oBindAddress },
181 { "smartcarddevice", oSmartcardDevice },
183 { "smartcarddevice", oUnsupported },
185 { "clearallforwardings", oClearAllForwardings },
186 { "enablesshkeysign", oEnableSSHKeysign },
188 { "verifyhostkeydns", oVerifyHostKeyDNS },
190 { "verifyhostkeydns", oUnsupported },
192 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
193 { "rekeylimit", oRekeyLimit },
194 { "connecttimeout", oConnectTimeout },
195 { "addressfamily", oAddressFamily },
200 * Adds a local TCP/IP port forward to options. Never returns if there is an
205 add_local_forward(Options *options, u_short port, const char *host,
209 #ifndef NO_IPPORT_RESERVED_CONCEPT
210 extern uid_t original_real_uid;
211 if (port < IPPORT_RESERVED && original_real_uid != 0)
212 fatal("Privileged ports can only be forwarded by root.");
214 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
215 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
216 fwd = &options->local_forwards[options->num_local_forwards++];
218 fwd->host = xstrdup(host);
219 fwd->host_port = host_port;
223 * Adds a remote TCP/IP port forward to options. Never returns if there is
228 add_remote_forward(Options *options, u_short port, const char *host,
232 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
233 fatal("Too many remote forwards (max %d).",
234 SSH_MAX_FORWARDS_PER_DIRECTION);
235 fwd = &options->remote_forwards[options->num_remote_forwards++];
237 fwd->host = xstrdup(host);
238 fwd->host_port = host_port;
242 clear_forwardings(Options *options)
246 for (i = 0; i < options->num_local_forwards; i++)
247 xfree(options->local_forwards[i].host);
248 options->num_local_forwards = 0;
249 for (i = 0; i < options->num_remote_forwards; i++)
250 xfree(options->remote_forwards[i].host);
251 options->num_remote_forwards = 0;
255 * Returns the number of the token pointed to by cp or oBadOption.
259 parse_token(const char *cp, const char *filename, int linenum)
263 for (i = 0; keywords[i].name; i++)
264 if (strcasecmp(cp, keywords[i].name) == 0)
265 return keywords[i].opcode;
267 error("%s: line %d: Bad configuration option: %s",
268 filename, linenum, cp);
273 * Processes a single option line as used in the configuration files. This
274 * only sets those values that have not already been set.
276 #define WHITESPACE " \t\r\n"
279 process_config_line(Options *options, const char *host,
280 char *line, const char *filename, int linenum,
283 char buf[256], *s, **charptr, *endofnumber, *keyword, *arg;
284 int opcode, *intptr, value;
286 u_short fwd_port, fwd_host_port;
287 char sfwd_host_port[6];
289 /* Strip trailing whitespace */
290 for(len = strlen(line) - 1; len > 0; len--) {
291 if (strchr(WHITESPACE, line[len]) == NULL)
297 /* Get the keyword. (Each line is supposed to begin with a keyword). */
298 keyword = strdelim(&s);
299 /* Ignore leading whitespace. */
300 if (*keyword == '\0')
301 keyword = strdelim(&s);
302 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
305 opcode = parse_token(keyword, filename, linenum);
309 /* don't panic, but count bad options */
312 case oConnectTimeout:
313 intptr = &options->connection_timeout;
316 if (!arg || *arg == '\0')
317 fatal("%s line %d: missing time value.",
319 if ((value = convtime(arg)) == -1)
320 fatal("%s line %d: invalid time value.",
327 intptr = &options->forward_agent;
330 if (!arg || *arg == '\0')
331 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
332 value = 0; /* To avoid compiler warning... */
333 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
335 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
338 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
339 if (*activep && *intptr == -1)
344 intptr = &options->forward_x11;
348 intptr = &options->gateway_ports;
351 case oUsePrivilegedPort:
352 intptr = &options->use_privileged_port;
355 case oPasswordAuthentication:
356 intptr = &options->password_authentication;
359 case oKbdInteractiveAuthentication:
360 intptr = &options->kbd_interactive_authentication;
363 case oKbdInteractiveDevices:
364 charptr = &options->kbd_interactive_devices;
367 case oPubkeyAuthentication:
368 intptr = &options->pubkey_authentication;
371 case oRSAAuthentication:
372 intptr = &options->rsa_authentication;
375 case oRhostsRSAAuthentication:
376 intptr = &options->rhosts_rsa_authentication;
379 case oHostbasedAuthentication:
380 intptr = &options->hostbased_authentication;
383 case oChallengeResponseAuthentication:
384 intptr = &options->challenge_response_authentication;
387 case oGssAuthentication:
388 intptr = &options->gss_authentication;
392 intptr = &options->gss_keyex;
395 case oGssDelegateCreds:
396 intptr = &options->gss_deleg_creds;
400 intptr = &options->batch_mode;
404 intptr = &options->check_host_ip;
407 case oVerifyHostKeyDNS:
408 intptr = &options->verify_host_key_dns;
411 case oStrictHostKeyChecking:
412 intptr = &options->strict_host_key_checking;
414 if (!arg || *arg == '\0')
415 fatal("%.200s line %d: Missing yes/no/ask argument.",
417 value = 0; /* To avoid compiler warning... */
418 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
420 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
422 else if (strcmp(arg, "ask") == 0)
425 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
426 if (*activep && *intptr == -1)
431 intptr = &options->compression;
435 intptr = &options->keepalives;
438 case oNoHostAuthenticationForLocalhost:
439 intptr = &options->no_host_authentication_for_localhost;
442 case oNumberOfPasswordPrompts:
443 intptr = &options->number_of_password_prompts;
446 case oCompressionLevel:
447 intptr = &options->compression_level;
451 intptr = &options->rekey_limit;
453 if (!arg || *arg == '\0')
454 fatal("%.200s line %d: Missing argument.", filename, linenum);
455 if (arg[0] < '0' || arg[0] > '9')
456 fatal("%.200s line %d: Bad number.", filename, linenum);
457 value = strtol(arg, &endofnumber, 10);
458 if (arg == endofnumber)
459 fatal("%.200s line %d: Bad number.", filename, linenum);
460 switch (toupper(*endofnumber)) {
471 if (*activep && *intptr == -1)
477 if (!arg || *arg == '\0')
478 fatal("%.200s line %d: Missing argument.", filename, linenum);
480 intptr = &options->num_identity_files;
481 if (*intptr >= SSH_MAX_IDENTITY_FILES)
482 fatal("%.200s line %d: Too many identity files specified (max %d).",
483 filename, linenum, SSH_MAX_IDENTITY_FILES);
484 charptr = &options->identity_files[*intptr];
485 *charptr = xstrdup(arg);
486 *intptr = *intptr + 1;
491 charptr=&options->xauth_location;
495 charptr = &options->user;
498 if (!arg || *arg == '\0')
499 fatal("%.200s line %d: Missing argument.", filename, linenum);
500 if (*activep && *charptr == NULL)
501 *charptr = xstrdup(arg);
504 case oGlobalKnownHostsFile:
505 charptr = &options->system_hostfile;
508 case oUserKnownHostsFile:
509 charptr = &options->user_hostfile;
512 case oGlobalKnownHostsFile2:
513 charptr = &options->system_hostfile2;
516 case oUserKnownHostsFile2:
517 charptr = &options->user_hostfile2;
521 charptr = &options->hostname;
525 charptr = &options->host_key_alias;
528 case oPreferredAuthentications:
529 charptr = &options->preferred_authentications;
533 charptr = &options->bind_address;
536 case oSmartcardDevice:
537 charptr = &options->smartcard_device;
542 fatal("%.200s line %d: Missing argument.", filename, linenum);
543 charptr = &options->proxy_command;
544 len = strspn(s, WHITESPACE "=");
545 if (*activep && *charptr == NULL)
546 *charptr = xstrdup(s + len);
550 intptr = &options->port;
553 if (!arg || *arg == '\0')
554 fatal("%.200s line %d: Missing argument.", filename, linenum);
555 if (arg[0] < '0' || arg[0] > '9')
556 fatal("%.200s line %d: Bad number.", filename, linenum);
558 /* Octal, decimal, or hex format? */
559 value = strtol(arg, &endofnumber, 0);
560 if (arg == endofnumber)
561 fatal("%.200s line %d: Bad number.", filename, linenum);
562 if (*activep && *intptr == -1)
566 case oConnectionAttempts:
567 intptr = &options->connection_attempts;
571 intptr = &options->cipher;
573 if (!arg || *arg == '\0')
574 fatal("%.200s line %d: Missing argument.", filename, linenum);
575 value = cipher_number(arg);
577 fatal("%.200s line %d: Bad cipher '%s'.",
578 filename, linenum, arg ? arg : "<NONE>");
579 if (*activep && *intptr == -1)
585 if (!arg || *arg == '\0')
586 fatal("%.200s line %d: Missing argument.", filename, linenum);
587 if (!ciphers_valid(arg))
588 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
589 filename, linenum, arg ? arg : "<NONE>");
590 if (*activep && options->ciphers == NULL)
591 options->ciphers = xstrdup(arg);
596 if (!arg || *arg == '\0')
597 fatal("%.200s line %d: Missing argument.", filename, linenum);
599 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
600 filename, linenum, arg ? arg : "<NONE>");
601 if (*activep && options->macs == NULL)
602 options->macs = xstrdup(arg);
605 case oHostKeyAlgorithms:
607 if (!arg || *arg == '\0')
608 fatal("%.200s line %d: Missing argument.", filename, linenum);
609 if (!key_names_valid2(arg))
610 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
611 filename, linenum, arg ? arg : "<NONE>");
612 if (*activep && options->hostkeyalgorithms == NULL)
613 options->hostkeyalgorithms = xstrdup(arg);
617 intptr = &options->protocol;
619 if (!arg || *arg == '\0')
620 fatal("%.200s line %d: Missing argument.", filename, linenum);
621 value = proto_spec(arg);
622 if (value == SSH_PROTO_UNKNOWN)
623 fatal("%.200s line %d: Bad protocol spec '%s'.",
624 filename, linenum, arg ? arg : "<NONE>");
625 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
630 intptr = (int *) &options->log_level;
632 value = log_level_number(arg);
633 if (value == SYSLOG_LEVEL_NOT_SET)
634 fatal("%.200s line %d: unsupported log level '%s'",
635 filename, linenum, arg ? arg : "<NONE>");
636 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
637 *intptr = (LogLevel) value;
643 if (!arg || *arg == '\0')
644 fatal("%.200s line %d: Missing port argument.",
646 if ((fwd_port = a2port(arg)) == 0)
647 fatal("%.200s line %d: Bad listen port.",
650 if (!arg || *arg == '\0')
651 fatal("%.200s line %d: Missing second argument.",
653 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
654 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
655 fatal("%.200s line %d: Bad forwarding specification.",
657 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
658 fatal("%.200s line %d: Bad forwarding port.",
661 if (opcode == oLocalForward)
662 add_local_forward(options, fwd_port, buf,
664 else if (opcode == oRemoteForward)
665 add_remote_forward(options, fwd_port, buf,
670 case oDynamicForward:
672 if (!arg || *arg == '\0')
673 fatal("%.200s line %d: Missing port argument.",
675 fwd_port = a2port(arg);
677 fatal("%.200s line %d: Badly formatted port number.",
680 add_local_forward(options, fwd_port, "socks", 0);
683 case oClearAllForwardings:
684 intptr = &options->clear_forwardings;
689 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
690 if (match_pattern(host, arg)) {
691 debug("Applying options for %.100s", arg);
695 /* Avoid garbage check below, as strdelim is done. */
699 intptr = &options->escape_char;
701 if (!arg || *arg == '\0')
702 fatal("%.200s line %d: Missing argument.", filename, linenum);
703 if (arg[0] == '^' && arg[2] == 0 &&
704 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
705 value = (u_char) arg[1] & 31;
706 else if (strlen(arg) == 1)
707 value = (u_char) arg[0];
708 else if (strcmp(arg, "none") == 0)
709 value = SSH_ESCAPECHAR_NONE;
711 fatal("%.200s line %d: Bad escape character.",
714 value = 0; /* Avoid compiler warning. */
716 if (*activep && *intptr == -1)
722 intptr = &options->address_family;
723 if (strcasecmp(arg, "inet") == 0)
725 else if (strcasecmp(arg, "inet6") == 0)
727 else if (strcasecmp(arg, "any") == 0)
730 fatal("Unsupported AddressFamily \"%s\"", arg);
731 if (*activep && *intptr == -1)
735 case oEnableSSHKeysign:
736 intptr = &options->enable_ssh_keysign;
740 debug("%s line %d: Deprecated option \"%s\"",
741 filename, linenum, keyword);
745 error("%s line %d: Unsupported option \"%s\"",
746 filename, linenum, keyword);
750 fatal("process_config_line: Unimplemented opcode %d", opcode);
753 /* Check that there is no garbage at end of line. */
754 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
755 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
756 filename, linenum, arg);
763 * Reads the config file and modifies the options accordingly. Options
764 * should already be initialized before this call. This never returns if
765 * there is an error. If the file does not exist, this returns 0.
769 read_config_file(const char *filename, const char *host, Options *options)
777 f = fopen(filename, "r");
781 debug("Reading configuration data %.200s", filename);
784 * Mark that we are now processing the options. This flag is turned
785 * on/off by Host specifications.
789 while (fgets(line, sizeof(line), f)) {
790 /* Update line number counter. */
792 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
797 fatal("%s: terminating, %d bad configuration options",
798 filename, bad_options);
803 * Initializes options to special values that indicate that they have not yet
804 * been set. Read_config_file will only set options with this value. Options
805 * are processed in the following order: command line, user config file,
806 * system config file. Last, fill_default_options is called.
810 initialize_options(Options * options)
812 memset(options, 'X', sizeof(*options));
813 options->forward_agent = -1;
814 options->forward_x11 = -1;
815 options->xauth_location = NULL;
816 options->gateway_ports = -1;
817 options->use_privileged_port = -1;
818 options->rsa_authentication = -1;
819 options->pubkey_authentication = -1;
820 options->challenge_response_authentication = -1;
821 options->gss_authentication = -1;
822 options->gss_keyex = -1;
823 options->gss_deleg_creds = -1;
824 options->password_authentication = -1;
825 options->kbd_interactive_authentication = -1;
826 options->kbd_interactive_devices = NULL;
827 options->rhosts_rsa_authentication = -1;
828 options->hostbased_authentication = -1;
829 options->batch_mode = -1;
830 options->check_host_ip = -1;
831 options->strict_host_key_checking = -1;
832 options->compression = -1;
833 options->keepalives = -1;
834 options->compression_level = -1;
836 options->address_family = -1;
837 options->connection_attempts = -1;
838 options->connection_timeout = -1;
839 options->number_of_password_prompts = -1;
840 options->cipher = -1;
841 options->ciphers = NULL;
842 options->macs = NULL;
843 options->hostkeyalgorithms = NULL;
844 options->protocol = SSH_PROTO_UNKNOWN;
845 options->num_identity_files = 0;
846 options->hostname = NULL;
847 options->host_key_alias = NULL;
848 options->proxy_command = NULL;
849 options->user = NULL;
850 options->escape_char = -1;
851 options->system_hostfile = NULL;
852 options->user_hostfile = NULL;
853 options->system_hostfile2 = NULL;
854 options->user_hostfile2 = NULL;
855 options->num_local_forwards = 0;
856 options->num_remote_forwards = 0;
857 options->clear_forwardings = -1;
858 options->log_level = SYSLOG_LEVEL_NOT_SET;
859 options->preferred_authentications = NULL;
860 options->bind_address = NULL;
861 options->smartcard_device = NULL;
862 options->enable_ssh_keysign = - 1;
863 options->no_host_authentication_for_localhost = - 1;
864 options->rekey_limit = - 1;
865 options->verify_host_key_dns = -1;
869 * Called after processing other sources of option data, this fills those
870 * options for which no value has been specified with their default values.
874 fill_default_options(Options * options)
878 if (options->forward_agent == -1)
879 options->forward_agent = 0;
880 if (options->forward_x11 == -1)
881 options->forward_x11 = 0;
882 if (options->xauth_location == NULL)
883 options->xauth_location = _PATH_XAUTH;
884 if (options->gateway_ports == -1)
885 options->gateway_ports = 0;
886 if (options->use_privileged_port == -1)
887 options->use_privileged_port = 0;
888 if (options->rsa_authentication == -1)
889 options->rsa_authentication = 1;
890 if (options->pubkey_authentication == -1)
891 options->pubkey_authentication = 1;
892 if (options->challenge_response_authentication == -1)
893 options->challenge_response_authentication = 1;
894 if (options->gss_authentication == -1)
895 options->gss_authentication = 1;
896 if (options->gss_keyex == -1)
897 options->gss_keyex = 1;
898 if (options->gss_deleg_creds == -1)
899 options->gss_deleg_creds = 1;
900 if (options->password_authentication == -1)
901 options->password_authentication = 1;
902 if (options->kbd_interactive_authentication == -1)
903 options->kbd_interactive_authentication = 1;
904 if (options->rhosts_rsa_authentication == -1)
905 options->rhosts_rsa_authentication = 0;
906 if (options->hostbased_authentication == -1)
907 options->hostbased_authentication = 0;
908 if (options->batch_mode == -1)
909 options->batch_mode = 0;
910 if (options->check_host_ip == -1)
911 options->check_host_ip = 1;
912 if (options->strict_host_key_checking == -1)
913 options->strict_host_key_checking = 2; /* 2 is default */
914 if (options->compression == -1)
915 options->compression = 0;
916 if (options->keepalives == -1)
917 options->keepalives = 1;
918 if (options->compression_level == -1)
919 options->compression_level = 6;
920 if (options->port == -1)
921 options->port = 0; /* Filled in ssh_connect. */
922 if (options->address_family == -1)
923 options->address_family = AF_UNSPEC;
924 if (options->connection_attempts == -1)
925 options->connection_attempts = 1;
926 if (options->number_of_password_prompts == -1)
927 options->number_of_password_prompts = 3;
928 /* Selected in ssh_login(). */
929 if (options->cipher == -1)
930 options->cipher = SSH_CIPHER_NOT_SET;
931 /* options->ciphers, default set in myproposals.h */
932 /* options->macs, default set in myproposals.h */
933 /* options->hostkeyalgorithms, default set in myproposals.h */
934 if (options->protocol == SSH_PROTO_UNKNOWN)
935 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
936 if (options->num_identity_files == 0) {
937 if (options->protocol & SSH_PROTO_1) {
938 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
939 options->identity_files[options->num_identity_files] =
941 snprintf(options->identity_files[options->num_identity_files++],
942 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
944 if (options->protocol & SSH_PROTO_2) {
945 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
946 options->identity_files[options->num_identity_files] =
948 snprintf(options->identity_files[options->num_identity_files++],
949 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
951 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
952 options->identity_files[options->num_identity_files] =
954 snprintf(options->identity_files[options->num_identity_files++],
955 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
958 if (options->escape_char == -1)
959 options->escape_char = '~';
960 if (options->system_hostfile == NULL)
961 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
962 if (options->user_hostfile == NULL)
963 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
964 if (options->system_hostfile2 == NULL)
965 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
966 if (options->user_hostfile2 == NULL)
967 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
968 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
969 options->log_level = SYSLOG_LEVEL_INFO;
970 if (options->clear_forwardings == 1)
971 clear_forwardings(options);
972 if (options->no_host_authentication_for_localhost == - 1)
973 options->no_host_authentication_for_localhost = 0;
974 if (options->enable_ssh_keysign == -1)
975 options->enable_ssh_keysign = 0;
976 if (options->rekey_limit == -1)
977 options->rekey_limit = 0;
978 if (options->verify_host_key_dns == -1)
979 options->verify_host_key_dns = 0;
980 /* options->proxy_command should not be set by default */
981 /* options->user will be set in the main program if appropriate */
982 /* options->hostname will be set in the main program if appropriate */
983 /* options->host_key_alias should not be set by default */
984 /* options->preferred_authentications will be set in ssh */