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.112 2003/05/16 03:27:12 djm 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 RhostsAuthentication no
61 PasswordAuthentication no
65 ProxyCommand ssh-proxy %h %p
68 PublicKeyAuthentication no
72 PasswordAuthentication no
74 # Defaults for various options
78 RhostsAuthentication yes
79 PasswordAuthentication yes
81 RhostsRSAAuthentication yes
82 StrictHostKeyChecking yes
84 IdentityFile ~/.ssh/identity
94 oForwardAgent, oForwardX11, oGatewayPorts, oRhostsAuthentication,
95 oPasswordAuthentication, oRSAAuthentication,
96 oChallengeResponseAuthentication, oXAuthLocation,
97 oKerberosAuthentication, oKerberosTgtPassing, oAFSTokenPassing,
98 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
99 oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
100 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
101 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
102 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts,
103 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
104 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
105 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
106 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
107 oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
108 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
109 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
111 oDeprecated, oUnsupported
114 /* Textual representations of the tokens. */
120 { "forwardagent", oForwardAgent },
121 { "forwardx11", oForwardX11 },
122 { "xauthlocation", oXAuthLocation },
123 { "gatewayports", oGatewayPorts },
124 { "useprivilegedport", oUsePrivilegedPort },
125 { "rhostsauthentication", oRhostsAuthentication },
126 { "passwordauthentication", oPasswordAuthentication },
127 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
128 { "kbdinteractivedevices", oKbdInteractiveDevices },
129 { "rsaauthentication", oRSAAuthentication },
130 { "pubkeyauthentication", oPubkeyAuthentication },
131 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
132 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
133 { "hostbasedauthentication", oHostbasedAuthentication },
134 { "challengeresponseauthentication", oChallengeResponseAuthentication },
135 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
136 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
137 #if defined(KRB4) || defined(KRB5)
138 { "kerberosauthentication", oKerberosAuthentication },
139 { "kerberostgtpassing", oKerberosTgtPassing },
141 { "kerberosauthentication", oUnsupported },
142 { "kerberostgtpassing", oUnsupported },
145 { "afstokenpassing", oAFSTokenPassing },
147 { "afstokenpassing", oUnsupported },
149 { "fallbacktorsh", oDeprecated },
150 { "usersh", oDeprecated },
151 { "identityfile", oIdentityFile },
152 { "identityfile2", oIdentityFile }, /* alias */
153 { "hostname", oHostName },
154 { "hostkeyalias", oHostKeyAlias },
155 { "proxycommand", oProxyCommand },
157 { "cipher", oCipher },
158 { "ciphers", oCiphers },
160 { "protocol", oProtocol },
161 { "remoteforward", oRemoteForward },
162 { "localforward", oLocalForward },
165 { "escapechar", oEscapeChar },
166 { "globalknownhostsfile", oGlobalKnownHostsFile },
167 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */
168 { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
169 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
170 { "connectionattempts", oConnectionAttempts },
171 { "batchmode", oBatchMode },
172 { "checkhostip", oCheckHostIP },
173 { "stricthostkeychecking", oStrictHostKeyChecking },
174 { "compression", oCompression },
175 { "compressionlevel", oCompressionLevel },
176 { "keepalive", oKeepAlives },
177 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
178 { "loglevel", oLogLevel },
179 { "dynamicforward", oDynamicForward },
180 { "preferredauthentications", oPreferredAuthentications },
181 { "hostkeyalgorithms", oHostKeyAlgorithms },
182 { "bindaddress", oBindAddress },
184 { "smartcarddevice", oSmartcardDevice },
186 { "smartcarddevice", oUnsupported },
188 { "clearallforwardings", oClearAllForwardings },
189 { "enablesshkeysign", oEnableSSHKeysign },
191 { "verifyhostkeydns", oVerifyHostKeyDNS },
193 { "verifyhostkeydns", oUnsupported },
195 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
196 { "rekeylimit", oRekeyLimit },
197 { "connecttimeout", oConnectTimeout },
198 { "addressfamily", oAddressFamily },
203 * Adds a local TCP/IP port forward to options. Never returns if there is an
208 add_local_forward(Options *options, u_short port, const char *host,
212 #ifndef NO_IPPORT_RESERVED_CONCEPT
213 extern uid_t original_real_uid;
214 if (port < IPPORT_RESERVED && original_real_uid != 0)
215 fatal("Privileged ports can only be forwarded by root.");
217 if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
218 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
219 fwd = &options->local_forwards[options->num_local_forwards++];
221 fwd->host = xstrdup(host);
222 fwd->host_port = host_port;
226 * Adds a remote TCP/IP port forward to options. Never returns if there is
231 add_remote_forward(Options *options, u_short port, const char *host,
235 if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
236 fatal("Too many remote forwards (max %d).",
237 SSH_MAX_FORWARDS_PER_DIRECTION);
238 fwd = &options->remote_forwards[options->num_remote_forwards++];
240 fwd->host = xstrdup(host);
241 fwd->host_port = host_port;
245 clear_forwardings(Options *options)
249 for (i = 0; i < options->num_local_forwards; i++)
250 xfree(options->local_forwards[i].host);
251 options->num_local_forwards = 0;
252 for (i = 0; i < options->num_remote_forwards; i++)
253 xfree(options->remote_forwards[i].host);
254 options->num_remote_forwards = 0;
258 * Returns the number of the token pointed to by cp or oBadOption.
262 parse_token(const char *cp, const char *filename, int linenum)
266 for (i = 0; keywords[i].name; i++)
267 if (strcasecmp(cp, keywords[i].name) == 0)
268 return keywords[i].opcode;
270 error("%s: line %d: Bad configuration option: %s",
271 filename, linenum, cp);
276 * Processes a single option line as used in the configuration files. This
277 * only sets those values that have not already been set.
279 #define WHITESPACE " \t\r\n"
282 process_config_line(Options *options, const char *host,
283 char *line, const char *filename, int linenum,
286 char buf[256], *s, **charptr, *endofnumber, *keyword, *arg;
287 int opcode, *intptr, value;
289 u_short fwd_port, fwd_host_port;
290 char sfwd_host_port[6];
293 /* Strip trailing whitespace */
294 for(len = strlen(line) - 1; len > 0; len--) {
295 if (strchr(WHITESPACE, line[len]) == NULL)
301 /* Get the keyword. (Each line is supposed to begin with a keyword). */
302 keyword = strdelim(&s);
303 /* Ignore leading whitespace. */
304 if (*keyword == '\0')
305 keyword = strdelim(&s);
306 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
309 opcode = parse_token(keyword, filename, linenum);
313 /* don't panic, but count bad options */
316 case oConnectTimeout:
317 intptr = &options->connection_timeout;
320 if (!arg || *arg == '\0')
321 fatal("%s line %d: missing time value.",
323 if ((value = convtime(arg)) == -1)
324 fatal("%s line %d: invalid time value.",
331 intptr = &options->forward_agent;
334 if (!arg || *arg == '\0')
335 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
336 value = 0; /* To avoid compiler warning... */
337 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
339 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
342 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
343 if (*activep && *intptr == -1)
348 intptr = &options->forward_x11;
352 intptr = &options->gateway_ports;
355 case oUsePrivilegedPort:
356 intptr = &options->use_privileged_port;
359 case oRhostsAuthentication:
360 intptr = &options->rhosts_authentication;
363 case oPasswordAuthentication:
364 intptr = &options->password_authentication;
367 case oKbdInteractiveAuthentication:
368 intptr = &options->kbd_interactive_authentication;
371 case oKbdInteractiveDevices:
372 charptr = &options->kbd_interactive_devices;
375 case oPubkeyAuthentication:
376 intptr = &options->pubkey_authentication;
379 case oRSAAuthentication:
380 intptr = &options->rsa_authentication;
383 case oRhostsRSAAuthentication:
384 intptr = &options->rhosts_rsa_authentication;
387 case oHostbasedAuthentication:
388 intptr = &options->hostbased_authentication;
391 case oChallengeResponseAuthentication:
392 intptr = &options->challenge_response_authentication;
395 case oKerberosAuthentication:
396 intptr = &options->kerberos_authentication;
399 case oKerberosTgtPassing:
400 intptr = &options->kerberos_tgt_passing;
403 case oAFSTokenPassing:
404 intptr = &options->afs_token_passing;
408 intptr = &options->batch_mode;
412 intptr = &options->check_host_ip;
415 case oVerifyHostKeyDNS:
416 intptr = &options->verify_host_key_dns;
419 case oStrictHostKeyChecking:
420 intptr = &options->strict_host_key_checking;
422 if (!arg || *arg == '\0')
423 fatal("%.200s line %d: Missing yes/no/ask argument.",
425 value = 0; /* To avoid compiler warning... */
426 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
428 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
430 else if (strcmp(arg, "ask") == 0)
433 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
434 if (*activep && *intptr == -1)
439 intptr = &options->compression;
443 intptr = &options->keepalives;
446 case oNoHostAuthenticationForLocalhost:
447 intptr = &options->no_host_authentication_for_localhost;
450 case oNumberOfPasswordPrompts:
451 intptr = &options->number_of_password_prompts;
454 case oCompressionLevel:
455 intptr = &options->compression_level;
459 intptr = &options->rekey_limit;
461 if (!arg || *arg == '\0')
462 fatal("%.200s line %d: Missing argument.", filename, linenum);
463 if (arg[0] < '0' || arg[0] > '9')
464 fatal("%.200s line %d: Bad number.", filename, linenum);
465 value = strtol(arg, &endofnumber, 10);
466 if (arg == endofnumber)
467 fatal("%.200s line %d: Bad number.", filename, linenum);
468 switch (toupper(*endofnumber)) {
479 if (*activep && *intptr == -1)
485 if (!arg || *arg == '\0')
486 fatal("%.200s line %d: Missing argument.", filename, linenum);
488 intptr = &options->num_identity_files;
489 if (*intptr >= SSH_MAX_IDENTITY_FILES)
490 fatal("%.200s line %d: Too many identity files specified (max %d).",
491 filename, linenum, SSH_MAX_IDENTITY_FILES);
492 charptr = &options->identity_files[*intptr];
493 *charptr = xstrdup(arg);
494 *intptr = *intptr + 1;
499 charptr=&options->xauth_location;
503 charptr = &options->user;
506 if (!arg || *arg == '\0')
507 fatal("%.200s line %d: Missing argument.", filename, linenum);
508 if (*activep && *charptr == NULL)
509 *charptr = xstrdup(arg);
512 case oGlobalKnownHostsFile:
513 charptr = &options->system_hostfile;
516 case oUserKnownHostsFile:
517 charptr = &options->user_hostfile;
520 case oGlobalKnownHostsFile2:
521 charptr = &options->system_hostfile2;
524 case oUserKnownHostsFile2:
525 charptr = &options->user_hostfile2;
529 charptr = &options->hostname;
533 charptr = &options->host_key_alias;
536 case oPreferredAuthentications:
537 charptr = &options->preferred_authentications;
541 charptr = &options->bind_address;
544 case oSmartcardDevice:
545 charptr = &options->smartcard_device;
549 charptr = &options->proxy_command;
550 len = strspn(s, WHITESPACE "=");
551 if (*activep && *charptr == NULL)
552 *charptr = xstrdup(s + len);
556 intptr = &options->port;
559 if (!arg || *arg == '\0')
560 fatal("%.200s line %d: Missing argument.", filename, linenum);
561 if (arg[0] < '0' || arg[0] > '9')
562 fatal("%.200s line %d: Bad number.", filename, linenum);
564 /* Octal, decimal, or hex format? */
565 value = strtol(arg, &endofnumber, 0);
566 if (arg == endofnumber)
567 fatal("%.200s line %d: Bad number.", filename, linenum);
568 if (*activep && *intptr == -1)
572 case oConnectionAttempts:
573 intptr = &options->connection_attempts;
577 intptr = &options->cipher;
579 if (!arg || *arg == '\0')
580 fatal("%.200s line %d: Missing argument.", filename, linenum);
581 value = cipher_number(arg);
583 fatal("%.200s line %d: Bad cipher '%s'.",
584 filename, linenum, arg ? arg : "<NONE>");
585 if (*activep && *intptr == -1)
591 if (!arg || *arg == '\0')
592 fatal("%.200s line %d: Missing argument.", filename, linenum);
593 if (!ciphers_valid(arg))
594 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
595 filename, linenum, arg ? arg : "<NONE>");
596 if (*activep && options->ciphers == NULL)
597 options->ciphers = xstrdup(arg);
602 if (!arg || *arg == '\0')
603 fatal("%.200s line %d: Missing argument.", filename, linenum);
605 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
606 filename, linenum, arg ? arg : "<NONE>");
607 if (*activep && options->macs == NULL)
608 options->macs = xstrdup(arg);
611 case oHostKeyAlgorithms:
613 if (!arg || *arg == '\0')
614 fatal("%.200s line %d: Missing argument.", filename, linenum);
615 if (!key_names_valid2(arg))
616 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
617 filename, linenum, arg ? arg : "<NONE>");
618 if (*activep && options->hostkeyalgorithms == NULL)
619 options->hostkeyalgorithms = xstrdup(arg);
623 intptr = &options->protocol;
625 if (!arg || *arg == '\0')
626 fatal("%.200s line %d: Missing argument.", filename, linenum);
627 value = proto_spec(arg);
628 if (value == SSH_PROTO_UNKNOWN)
629 fatal("%.200s line %d: Bad protocol spec '%s'.",
630 filename, linenum, arg ? arg : "<NONE>");
631 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
636 intptr = (int *) &options->log_level;
638 value = log_level_number(arg);
639 if (value == SYSLOG_LEVEL_NOT_SET)
640 fatal("%.200s line %d: unsupported log level '%s'",
641 filename, linenum, arg ? arg : "<NONE>");
642 if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
643 *intptr = (LogLevel) value;
649 if (!arg || *arg == '\0')
650 fatal("%.200s line %d: Missing port argument.",
652 if ((fwd_port = a2port(arg)) == 0)
653 fatal("%.200s line %d: Bad listen port.",
656 if (!arg || *arg == '\0')
657 fatal("%.200s line %d: Missing second argument.",
659 if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
660 sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
661 fatal("%.200s line %d: Bad forwarding specification.",
663 if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
664 fatal("%.200s line %d: Bad forwarding port.",
667 if (opcode == oLocalForward)
668 add_local_forward(options, fwd_port, buf,
670 else if (opcode == oRemoteForward)
671 add_remote_forward(options, fwd_port, buf,
676 case oDynamicForward:
678 if (!arg || *arg == '\0')
679 fatal("%.200s line %d: Missing port argument.",
681 fwd_port = a2port(arg);
683 fatal("%.200s line %d: Badly formatted port number.",
686 add_local_forward(options, fwd_port, "socks4", 0);
689 case oClearAllForwardings:
690 intptr = &options->clear_forwardings;
695 while ((arg = strdelim(&s)) != NULL && *arg != '\0')
696 if (match_pattern(host, arg)) {
697 debug("Applying options for %.100s", arg);
701 /* Avoid garbage check below, as strdelim is done. */
705 intptr = &options->escape_char;
707 if (!arg || *arg == '\0')
708 fatal("%.200s line %d: Missing argument.", filename, linenum);
709 if (arg[0] == '^' && arg[2] == 0 &&
710 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
711 value = (u_char) arg[1] & 31;
712 else if (strlen(arg) == 1)
713 value = (u_char) arg[0];
714 else if (strcmp(arg, "none") == 0)
715 value = SSH_ESCAPECHAR_NONE;
717 fatal("%.200s line %d: Bad escape character.",
720 value = 0; /* Avoid compiler warning. */
722 if (*activep && *intptr == -1)
728 if (strcasecmp(arg, "inet") == 0)
730 else if (strcasecmp(arg, "inet6") == 0)
732 else if (strcasecmp(arg, "any") == 0)
735 fatal("Unsupported AddressFamily \"%s\"", arg);
738 case oEnableSSHKeysign:
739 intptr = &options->enable_ssh_keysign;
743 debug("%s line %d: Deprecated option \"%s\"",
744 filename, linenum, keyword);
748 error("%s line %d: Unsupported option \"%s\"",
749 filename, linenum, keyword);
753 fatal("process_config_line: Unimplemented opcode %d", opcode);
756 /* Check that there is no garbage at end of line. */
757 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
758 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
759 filename, linenum, arg);
766 * Reads the config file and modifies the options accordingly. Options
767 * should already be initialized before this call. This never returns if
768 * there is an error. If the file does not exist, this returns 0.
772 read_config_file(const char *filename, const char *host, Options *options)
780 f = fopen(filename, "r");
784 debug("Reading configuration data %.200s", filename);
787 * Mark that we are now processing the options. This flag is turned
788 * on/off by Host specifications.
792 while (fgets(line, sizeof(line), f)) {
793 /* Update line number counter. */
795 if (process_config_line(options, host, line, filename, linenum, &active) != 0)
800 fatal("%s: terminating, %d bad configuration options",
801 filename, bad_options);
806 * Initializes options to special values that indicate that they have not yet
807 * been set. Read_config_file will only set options with this value. Options
808 * are processed in the following order: command line, user config file,
809 * system config file. Last, fill_default_options is called.
813 initialize_options(Options * options)
815 memset(options, 'X', sizeof(*options));
816 options->forward_agent = -1;
817 options->forward_x11 = -1;
818 options->xauth_location = NULL;
819 options->gateway_ports = -1;
820 options->use_privileged_port = -1;
821 options->rhosts_authentication = -1;
822 options->rsa_authentication = -1;
823 options->pubkey_authentication = -1;
824 options->challenge_response_authentication = -1;
825 options->kerberos_authentication = -1;
826 options->kerberos_tgt_passing = -1;
827 options->afs_token_passing = -1;
828 options->password_authentication = -1;
829 options->kbd_interactive_authentication = -1;
830 options->kbd_interactive_devices = NULL;
831 options->rhosts_rsa_authentication = -1;
832 options->hostbased_authentication = -1;
833 options->batch_mode = -1;
834 options->check_host_ip = -1;
835 options->strict_host_key_checking = -1;
836 options->compression = -1;
837 options->keepalives = -1;
838 options->compression_level = -1;
840 options->connection_attempts = -1;
841 options->connection_timeout = -1;
842 options->number_of_password_prompts = -1;
843 options->cipher = -1;
844 options->ciphers = NULL;
845 options->macs = NULL;
846 options->hostkeyalgorithms = NULL;
847 options->protocol = SSH_PROTO_UNKNOWN;
848 options->num_identity_files = 0;
849 options->hostname = NULL;
850 options->host_key_alias = NULL;
851 options->proxy_command = NULL;
852 options->user = NULL;
853 options->escape_char = -1;
854 options->system_hostfile = NULL;
855 options->user_hostfile = NULL;
856 options->system_hostfile2 = NULL;
857 options->user_hostfile2 = NULL;
858 options->num_local_forwards = 0;
859 options->num_remote_forwards = 0;
860 options->clear_forwardings = -1;
861 options->log_level = SYSLOG_LEVEL_NOT_SET;
862 options->preferred_authentications = NULL;
863 options->bind_address = NULL;
864 options->smartcard_device = NULL;
865 options->enable_ssh_keysign = - 1;
866 options->no_host_authentication_for_localhost = - 1;
867 options->rekey_limit = - 1;
868 options->verify_host_key_dns = -1;
872 * Called after processing other sources of option data, this fills those
873 * options for which no value has been specified with their default values.
877 fill_default_options(Options * options)
881 if (options->forward_agent == -1)
882 options->forward_agent = 0;
883 if (options->forward_x11 == -1)
884 options->forward_x11 = 0;
885 if (options->xauth_location == NULL)
886 options->xauth_location = _PATH_XAUTH;
887 if (options->gateway_ports == -1)
888 options->gateway_ports = 0;
889 if (options->use_privileged_port == -1)
890 options->use_privileged_port = 0;
891 if (options->rhosts_authentication == -1)
892 options->rhosts_authentication = 0;
893 if (options->rsa_authentication == -1)
894 options->rsa_authentication = 1;
895 if (options->pubkey_authentication == -1)
896 options->pubkey_authentication = 1;
897 if (options->challenge_response_authentication == -1)
898 options->challenge_response_authentication = 1;
899 if (options->kerberos_authentication == -1)
900 options->kerberos_authentication = 1;
901 if (options->kerberos_tgt_passing == -1)
902 options->kerberos_tgt_passing = 1;
903 if (options->afs_token_passing == -1)
904 options->afs_token_passing = 1;
905 if (options->password_authentication == -1)
906 options->password_authentication = 1;
907 if (options->kbd_interactive_authentication == -1)
908 options->kbd_interactive_authentication = 1;
909 if (options->rhosts_rsa_authentication == -1)
910 options->rhosts_rsa_authentication = 0;
911 if (options->hostbased_authentication == -1)
912 options->hostbased_authentication = 0;
913 if (options->batch_mode == -1)
914 options->batch_mode = 0;
915 if (options->check_host_ip == -1)
916 options->check_host_ip = 1;
917 if (options->strict_host_key_checking == -1)
918 options->strict_host_key_checking = 2; /* 2 is default */
919 if (options->compression == -1)
920 options->compression = 0;
921 if (options->keepalives == -1)
922 options->keepalives = 1;
923 if (options->compression_level == -1)
924 options->compression_level = 6;
925 if (options->port == -1)
926 options->port = 0; /* Filled in ssh_connect. */
927 if (options->connection_attempts == -1)
928 options->connection_attempts = 1;
929 if (options->number_of_password_prompts == -1)
930 options->number_of_password_prompts = 3;
931 /* Selected in ssh_login(). */
932 if (options->cipher == -1)
933 options->cipher = SSH_CIPHER_NOT_SET;
934 /* options->ciphers, default set in myproposals.h */
935 /* options->macs, default set in myproposals.h */
936 /* options->hostkeyalgorithms, default set in myproposals.h */
937 if (options->protocol == SSH_PROTO_UNKNOWN)
938 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
939 if (options->num_identity_files == 0) {
940 if (options->protocol & SSH_PROTO_1) {
941 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
942 options->identity_files[options->num_identity_files] =
944 snprintf(options->identity_files[options->num_identity_files++],
945 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
947 if (options->protocol & SSH_PROTO_2) {
948 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
949 options->identity_files[options->num_identity_files] =
951 snprintf(options->identity_files[options->num_identity_files++],
952 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
954 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
955 options->identity_files[options->num_identity_files] =
957 snprintf(options->identity_files[options->num_identity_files++],
958 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
961 if (options->escape_char == -1)
962 options->escape_char = '~';
963 if (options->system_hostfile == NULL)
964 options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
965 if (options->user_hostfile == NULL)
966 options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
967 if (options->system_hostfile2 == NULL)
968 options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
969 if (options->user_hostfile2 == NULL)
970 options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
971 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
972 options->log_level = SYSLOG_LEVEL_INFO;
973 if (options->clear_forwardings == 1)
974 clear_forwardings(options);
975 if (options->no_host_authentication_for_localhost == - 1)
976 options->no_host_authentication_for_localhost = 0;
977 if (options->enable_ssh_keysign == -1)
978 options->enable_ssh_keysign = 0;
979 if (options->rekey_limit == -1)
980 options->rekey_limit = 0;
981 if (options->verify_host_key_dns == -1)
982 options->verify_host_key_dns = 0;
983 /* options->proxy_command should not be set by default */
984 /* options->user will be set in the main program if appropriate */
985 /* options->hostname will be set in the main program if appropriate */
986 /* options->host_key_alias should not be set by default */
987 /* options->preferred_authentications will be set in ssh */