Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 2 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 4 | * All rights reserved |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 5 | * Functions for reading the configuration files. |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 6 | * |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 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". |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 12 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 13 | |
| 14 | #include "includes.h" |
Ben Lindstrom | 19066a1 | 2001-04-12 23:39:26 +0000 | [diff] [blame^] | 15 | RCSID("$OpenBSD: readconf.c,v 1.74 2001/04/12 20:09:37 stevesk Exp $"); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 16 | |
| 17 | #include "ssh.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 18 | #include "xmalloc.h" |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 19 | #include "compat.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 20 | #include "cipher.h" |
| 21 | #include "pathnames.h" |
| 22 | #include "log.h" |
| 23 | #include "readconf.h" |
| 24 | #include "match.h" |
| 25 | #include "misc.h" |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 26 | #include "kex.h" |
| 27 | #include "mac.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 28 | |
| 29 | /* Format of the configuration file: |
| 30 | |
| 31 | # Configuration data is parsed as follows: |
| 32 | # 1. command line options |
| 33 | # 2. user-specific file |
| 34 | # 3. system-wide 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. |
| 38 | |
| 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. |
| 42 | |
| 43 | Host *.ngs.fi ngs.fi |
| 44 | FallBackToRsh no |
| 45 | |
| 46 | Host fake.com |
| 47 | HostName another.host.name.real.org |
| 48 | User blaah |
| 49 | Port 34289 |
| 50 | ForwardX11 no |
| 51 | ForwardAgent no |
| 52 | |
| 53 | Host books.com |
| 54 | RemoteForward 9999 shadows.cs.hut.fi:9999 |
| 55 | Cipher 3des |
| 56 | |
| 57 | Host fascist.blob.com |
| 58 | Port 23123 |
| 59 | User tylonen |
| 60 | RhostsAuthentication no |
| 61 | PasswordAuthentication no |
| 62 | |
| 63 | Host puukko.hut.fi |
| 64 | User t35124p |
| 65 | ProxyCommand ssh-proxy %h %p |
| 66 | |
| 67 | Host *.fr |
| 68 | UseRsh yes |
| 69 | |
| 70 | Host *.su |
| 71 | Cipher none |
| 72 | PasswordAuthentication no |
| 73 | |
| 74 | # Defaults for various options |
| 75 | Host * |
| 76 | ForwardAgent no |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 77 | ForwardX11 no |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 78 | RhostsAuthentication yes |
| 79 | PasswordAuthentication yes |
| 80 | RSAAuthentication yes |
| 81 | RhostsRSAAuthentication yes |
| 82 | FallBackToRsh no |
| 83 | UseRsh no |
| 84 | StrictHostKeyChecking yes |
| 85 | KeepAlives no |
| 86 | IdentityFile ~/.ssh/identity |
| 87 | Port 22 |
| 88 | EscapeChar ~ |
| 89 | |
| 90 | */ |
| 91 | |
| 92 | /* Keyword tokens. */ |
| 93 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 94 | typedef enum { |
| 95 | oBadOption, |
| 96 | oForwardAgent, oForwardX11, oGatewayPorts, oRhostsAuthentication, |
| 97 | oPasswordAuthentication, oRSAAuthentication, oFallBackToRsh, oUseRsh, |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 98 | oChallengeResponseAuthentication, oXAuthLocation, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 99 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 100 | oKerberosAuthentication, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 101 | #endif /* KRB4 */ |
| 102 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 103 | oKerberosTgtPassing, oAFSTokenPassing, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 104 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 105 | oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward, |
| 106 | oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand, |
| 107 | oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts, |
| 108 | oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression, |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 109 | oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts, |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 110 | oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs, |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 111 | oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication, |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 112 | oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias, |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 113 | oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 114 | } OpCodes; |
| 115 | |
| 116 | /* Textual representations of the tokens. */ |
| 117 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 118 | static struct { |
| 119 | const char *name; |
| 120 | OpCodes opcode; |
| 121 | } keywords[] = { |
| 122 | { "forwardagent", oForwardAgent }, |
| 123 | { "forwardx11", oForwardX11 }, |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 124 | { "xauthlocation", oXAuthLocation }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 125 | { "gatewayports", oGatewayPorts }, |
| 126 | { "useprivilegedport", oUsePrivilegedPort }, |
| 127 | { "rhostsauthentication", oRhostsAuthentication }, |
| 128 | { "passwordauthentication", oPasswordAuthentication }, |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 129 | { "kbdinteractiveauthentication", oKbdInteractiveAuthentication }, |
| 130 | { "kbdinteractivedevices", oKbdInteractiveDevices }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 131 | { "rsaauthentication", oRSAAuthentication }, |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 132 | { "pubkeyauthentication", oPubkeyAuthentication }, |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 133 | { "dsaauthentication", oPubkeyAuthentication }, /* alias */ |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 134 | { "rhostsrsaauthentication", oRhostsRSAAuthentication }, |
Ben Lindstrom | d69dab3 | 2001-04-12 23:36:05 +0000 | [diff] [blame] | 135 | { "hostbasedauthentication", oHostbasedAuthentication }, |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 136 | { "challengeresponseauthentication", oChallengeResponseAuthentication }, |
| 137 | { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */ |
| 138 | { "tisauthentication", oChallengeResponseAuthentication }, /* alias */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 139 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 140 | { "kerberosauthentication", oKerberosAuthentication }, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 141 | #endif /* KRB4 */ |
| 142 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 143 | { "kerberostgtpassing", oKerberosTgtPassing }, |
| 144 | { "afstokenpassing", oAFSTokenPassing }, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 145 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 146 | { "fallbacktorsh", oFallBackToRsh }, |
| 147 | { "usersh", oUseRsh }, |
| 148 | { "identityfile", oIdentityFile }, |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 149 | { "identityfile2", oIdentityFile }, /* alias */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 150 | { "hostname", oHostName }, |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 151 | { "hostkeyalias", oHostKeyAlias }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 152 | { "proxycommand", oProxyCommand }, |
| 153 | { "port", oPort }, |
| 154 | { "cipher", oCipher }, |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 155 | { "ciphers", oCiphers }, |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 156 | { "macs", oMacs }, |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 157 | { "protocol", oProtocol }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 158 | { "remoteforward", oRemoteForward }, |
| 159 | { "localforward", oLocalForward }, |
| 160 | { "user", oUser }, |
| 161 | { "host", oHost }, |
| 162 | { "escapechar", oEscapeChar }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 163 | { "globalknownhostsfile", oGlobalKnownHostsFile }, |
| 164 | { "userknownhostsfile", oUserKnownHostsFile }, |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 165 | { "globalknownhostsfile2", oGlobalKnownHostsFile2 }, |
| 166 | { "userknownhostsfile2", oUserKnownHostsFile2 }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 167 | { "connectionattempts", oConnectionAttempts }, |
| 168 | { "batchmode", oBatchMode }, |
| 169 | { "checkhostip", oCheckHostIP }, |
| 170 | { "stricthostkeychecking", oStrictHostKeyChecking }, |
| 171 | { "compression", oCompression }, |
| 172 | { "compressionlevel", oCompressionLevel }, |
| 173 | { "keepalive", oKeepAlives }, |
| 174 | { "numberofpasswordprompts", oNumberOfPasswordPrompts }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 175 | { "loglevel", oLogLevel }, |
Ben Lindstrom | 3bb4f9d | 2001-04-08 18:30:26 +0000 | [diff] [blame] | 176 | { "dynamicforward", oDynamicForward }, |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 177 | { "preferredauthentications", oPreferredAuthentications }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 178 | { NULL, 0 } |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 179 | }; |
| 180 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 181 | /* |
| 182 | * Adds a local TCP/IP port forward to options. Never returns if there is an |
| 183 | * error. |
| 184 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 185 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 186 | void |
Damien Miller | aae6c61 | 1999-12-06 11:47:28 +1100 | [diff] [blame] | 187 | add_local_forward(Options *options, u_short port, const char *host, |
| 188 | u_short host_port) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 189 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 190 | Forward *fwd; |
Damien Miller | bac2d8a | 2000-09-05 16:13:06 +1100 | [diff] [blame] | 191 | #ifndef HAVE_CYGWIN |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 192 | extern uid_t original_real_uid; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 193 | if (port < IPPORT_RESERVED && original_real_uid != 0) |
Ben Lindstrom | 6df8ef4 | 2001-03-05 07:47:23 +0000 | [diff] [blame] | 194 | fatal("Privileged ports can only be forwarded by root."); |
Damien Miller | bac2d8a | 2000-09-05 16:13:06 +1100 | [diff] [blame] | 195 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 196 | if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION) |
| 197 | fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION); |
| 198 | fwd = &options->local_forwards[options->num_local_forwards++]; |
| 199 | fwd->port = port; |
| 200 | fwd->host = xstrdup(host); |
| 201 | fwd->host_port = host_port; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 202 | } |
| 203 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 204 | /* |
| 205 | * Adds a remote TCP/IP port forward to options. Never returns if there is |
| 206 | * an error. |
| 207 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 208 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 209 | void |
Damien Miller | aae6c61 | 1999-12-06 11:47:28 +1100 | [diff] [blame] | 210 | add_remote_forward(Options *options, u_short port, const char *host, |
| 211 | u_short host_port) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 212 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 213 | Forward *fwd; |
| 214 | if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION) |
| 215 | fatal("Too many remote forwards (max %d).", |
| 216 | SSH_MAX_FORWARDS_PER_DIRECTION); |
| 217 | fwd = &options->remote_forwards[options->num_remote_forwards++]; |
| 218 | fwd->port = port; |
| 219 | fwd->host = xstrdup(host); |
| 220 | fwd->host_port = host_port; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 221 | } |
| 222 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 223 | /* |
Ben Lindstrom | 3704c26 | 2001-04-02 18:20:03 +0000 | [diff] [blame] | 224 | * Returns the number of the token pointed to by cp or oBadOption. |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 225 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 226 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 227 | static OpCodes |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 228 | parse_token(const char *cp, const char *filename, int linenum) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 229 | { |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 230 | u_int i; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 231 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 232 | for (i = 0; keywords[i].name; i++) |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 233 | if (strcasecmp(cp, keywords[i].name) == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 234 | return keywords[i].opcode; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 235 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 236 | fprintf(stderr, "%s: line %d: Bad configuration option: %s\n", |
| 237 | filename, linenum, cp); |
| 238 | return oBadOption; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 239 | } |
| 240 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 241 | /* |
| 242 | * Processes a single option line as used in the configuration files. This |
| 243 | * only sets those values that have not already been set. |
| 244 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 245 | |
Damien Miller | 2ccf661 | 1999-11-15 15:25:10 +1100 | [diff] [blame] | 246 | int |
| 247 | process_config_line(Options *options, const char *host, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 248 | char *line, const char *filename, int linenum, |
| 249 | int *activep) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 250 | { |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 251 | char buf[256], *s, *string, **charptr, *endofnumber, *keyword, *arg; |
Damien Miller | aae6c61 | 1999-12-06 11:47:28 +1100 | [diff] [blame] | 252 | int opcode, *intptr, value; |
| 253 | u_short fwd_port, fwd_host_port; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 254 | |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 255 | s = line; |
| 256 | /* Get the keyword. (Each line is supposed to begin with a keyword). */ |
| 257 | keyword = strdelim(&s); |
| 258 | /* Ignore leading whitespace. */ |
| 259 | if (*keyword == '\0') |
| 260 | keyword = strdelim(&s); |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 261 | if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 262 | return 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 263 | |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 264 | opcode = parse_token(keyword, filename, linenum); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 265 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 266 | switch (opcode) { |
| 267 | case oBadOption: |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 268 | /* don't panic, but count bad options */ |
| 269 | return -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 270 | /* NOTREACHED */ |
| 271 | case oForwardAgent: |
| 272 | intptr = &options->forward_agent; |
| 273 | parse_flag: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 274 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 275 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 276 | fatal("%.200s line %d: Missing yes/no argument.", filename, linenum); |
| 277 | value = 0; /* To avoid compiler warning... */ |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 278 | if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 279 | value = 1; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 280 | else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 281 | value = 0; |
| 282 | else |
| 283 | fatal("%.200s line %d: Bad yes/no argument.", filename, linenum); |
| 284 | if (*activep && *intptr == -1) |
| 285 | *intptr = value; |
| 286 | break; |
| 287 | |
| 288 | case oForwardX11: |
| 289 | intptr = &options->forward_x11; |
| 290 | goto parse_flag; |
| 291 | |
| 292 | case oGatewayPorts: |
| 293 | intptr = &options->gateway_ports; |
| 294 | goto parse_flag; |
| 295 | |
| 296 | case oUsePrivilegedPort: |
| 297 | intptr = &options->use_privileged_port; |
| 298 | goto parse_flag; |
| 299 | |
| 300 | case oRhostsAuthentication: |
| 301 | intptr = &options->rhosts_authentication; |
| 302 | goto parse_flag; |
| 303 | |
| 304 | case oPasswordAuthentication: |
| 305 | intptr = &options->password_authentication; |
| 306 | goto parse_flag; |
| 307 | |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 308 | case oKbdInteractiveAuthentication: |
| 309 | intptr = &options->kbd_interactive_authentication; |
| 310 | goto parse_flag; |
| 311 | |
| 312 | case oKbdInteractiveDevices: |
| 313 | charptr = &options->kbd_interactive_devices; |
| 314 | goto parse_string; |
| 315 | |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 316 | case oPubkeyAuthentication: |
| 317 | intptr = &options->pubkey_authentication; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 318 | goto parse_flag; |
| 319 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 320 | case oRSAAuthentication: |
| 321 | intptr = &options->rsa_authentication; |
| 322 | goto parse_flag; |
| 323 | |
| 324 | case oRhostsRSAAuthentication: |
| 325 | intptr = &options->rhosts_rsa_authentication; |
| 326 | goto parse_flag; |
| 327 | |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 328 | case oHostbasedAuthentication: |
| 329 | intptr = &options->hostbased_authentication; |
| 330 | goto parse_flag; |
| 331 | |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 332 | case oChallengeResponseAuthentication: |
| 333 | intptr = &options->challenge_reponse_authentication; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 334 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 335 | |
| 336 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 337 | case oKerberosAuthentication: |
| 338 | intptr = &options->kerberos_authentication; |
| 339 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 340 | #endif /* KRB4 */ |
| 341 | |
| 342 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 343 | case oKerberosTgtPassing: |
| 344 | intptr = &options->kerberos_tgt_passing; |
| 345 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 346 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 347 | case oAFSTokenPassing: |
| 348 | intptr = &options->afs_token_passing; |
| 349 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 350 | #endif |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 351 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 352 | case oFallBackToRsh: |
| 353 | intptr = &options->fallback_to_rsh; |
| 354 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 355 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 356 | case oUseRsh: |
| 357 | intptr = &options->use_rsh; |
| 358 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 359 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 360 | case oBatchMode: |
| 361 | intptr = &options->batch_mode; |
| 362 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 363 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 364 | case oCheckHostIP: |
| 365 | intptr = &options->check_host_ip; |
| 366 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 367 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 368 | case oStrictHostKeyChecking: |
| 369 | intptr = &options->strict_host_key_checking; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 370 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 371 | if (!arg || *arg == '\0') |
Ben Lindstrom | 5ed8acd | 2001-01-29 08:00:54 +0000 | [diff] [blame] | 372 | fatal("%.200s line %d: Missing yes/no/ask argument.", |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 373 | filename, linenum); |
| 374 | value = 0; /* To avoid compiler warning... */ |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 375 | if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 376 | value = 1; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 377 | else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 378 | value = 0; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 379 | else if (strcmp(arg, "ask") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 380 | value = 2; |
| 381 | else |
| 382 | fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum); |
| 383 | if (*activep && *intptr == -1) |
| 384 | *intptr = value; |
| 385 | break; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 386 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 387 | case oCompression: |
| 388 | intptr = &options->compression; |
| 389 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 390 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 391 | case oKeepAlives: |
| 392 | intptr = &options->keepalives; |
| 393 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 394 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 395 | case oNumberOfPasswordPrompts: |
| 396 | intptr = &options->number_of_password_prompts; |
| 397 | goto parse_int; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 398 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 399 | case oCompressionLevel: |
| 400 | intptr = &options->compression_level; |
| 401 | goto parse_int; |
| 402 | |
| 403 | case oIdentityFile: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 404 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 405 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 406 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 407 | if (*activep) { |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 408 | intptr = &options->num_identity_files; |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 409 | if (*intptr >= SSH_MAX_IDENTITY_FILES) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 410 | fatal("%.200s line %d: Too many identity files specified (max %d).", |
| 411 | filename, linenum, SSH_MAX_IDENTITY_FILES); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 412 | charptr = &options->identity_files[*intptr]; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 413 | *charptr = xstrdup(arg); |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 414 | *intptr = *intptr + 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 415 | } |
| 416 | break; |
| 417 | |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 418 | case oXAuthLocation: |
| 419 | charptr=&options->xauth_location; |
| 420 | goto parse_string; |
| 421 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 422 | case oUser: |
| 423 | charptr = &options->user; |
| 424 | parse_string: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 425 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 426 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 427 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 428 | if (*activep && *charptr == NULL) |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 429 | *charptr = xstrdup(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 430 | break; |
| 431 | |
| 432 | case oGlobalKnownHostsFile: |
| 433 | charptr = &options->system_hostfile; |
| 434 | goto parse_string; |
| 435 | |
| 436 | case oUserKnownHostsFile: |
| 437 | charptr = &options->user_hostfile; |
| 438 | goto parse_string; |
| 439 | |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 440 | case oGlobalKnownHostsFile2: |
| 441 | charptr = &options->system_hostfile2; |
| 442 | goto parse_string; |
| 443 | |
| 444 | case oUserKnownHostsFile2: |
| 445 | charptr = &options->user_hostfile2; |
| 446 | goto parse_string; |
| 447 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 448 | case oHostName: |
| 449 | charptr = &options->hostname; |
| 450 | goto parse_string; |
| 451 | |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 452 | case oHostKeyAlias: |
| 453 | charptr = &options->host_key_alias; |
| 454 | goto parse_string; |
| 455 | |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 456 | case oPreferredAuthentications: |
| 457 | charptr = &options->preferred_authentications; |
| 458 | goto parse_string; |
| 459 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 460 | case oProxyCommand: |
| 461 | charptr = &options->proxy_command; |
| 462 | string = xstrdup(""); |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 463 | while ((arg = strdelim(&s)) != NULL && *arg != '\0') { |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 464 | string = xrealloc(string, strlen(string) + strlen(arg) + 2); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 465 | strcat(string, " "); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 466 | strcat(string, arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 467 | } |
| 468 | if (*activep && *charptr == NULL) |
| 469 | *charptr = string; |
| 470 | else |
| 471 | xfree(string); |
| 472 | return 0; |
| 473 | |
| 474 | case oPort: |
| 475 | intptr = &options->port; |
| 476 | parse_int: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 477 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 478 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 479 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 480 | if (arg[0] < '0' || arg[0] > '9') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 481 | fatal("%.200s line %d: Bad number.", filename, linenum); |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 482 | |
| 483 | /* Octal, decimal, or hex format? */ |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 484 | value = strtol(arg, &endofnumber, 0); |
| 485 | if (arg == endofnumber) |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 486 | fatal("%.200s line %d: Bad number.", filename, linenum); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 487 | if (*activep && *intptr == -1) |
| 488 | *intptr = value; |
| 489 | break; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 490 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 491 | case oConnectionAttempts: |
| 492 | intptr = &options->connection_attempts; |
| 493 | goto parse_int; |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 494 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 495 | case oCipher: |
| 496 | intptr = &options->cipher; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 497 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 498 | if (!arg || *arg == '\0') |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 499 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 500 | value = cipher_number(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 501 | if (value == -1) |
| 502 | fatal("%.200s line %d: Bad cipher '%s'.", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 503 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 504 | if (*activep && *intptr == -1) |
| 505 | *intptr = value; |
| 506 | break; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 507 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 508 | case oCiphers: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 509 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 510 | if (!arg || *arg == '\0') |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 511 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 512 | if (!ciphers_valid(arg)) |
Damien Miller | 30c3d42 | 2000-05-09 11:02:59 +1000 | [diff] [blame] | 513 | fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 514 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 515 | if (*activep && options->ciphers == NULL) |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 516 | options->ciphers = xstrdup(arg); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 517 | break; |
| 518 | |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 519 | case oMacs: |
| 520 | arg = strdelim(&s); |
| 521 | if (!arg || *arg == '\0') |
| 522 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 523 | if (!mac_valid(arg)) |
| 524 | fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.", |
| 525 | filename, linenum, arg ? arg : "<NONE>"); |
| 526 | if (*activep && options->macs == NULL) |
| 527 | options->macs = xstrdup(arg); |
| 528 | break; |
| 529 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 530 | case oProtocol: |
| 531 | intptr = &options->protocol; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 532 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 533 | if (!arg || *arg == '\0') |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 534 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 535 | value = proto_spec(arg); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 536 | if (value == SSH_PROTO_UNKNOWN) |
| 537 | fatal("%.200s line %d: Bad protocol spec '%s'.", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 538 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 539 | if (*activep && *intptr == SSH_PROTO_UNKNOWN) |
| 540 | *intptr = value; |
| 541 | break; |
| 542 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 543 | case oLogLevel: |
| 544 | intptr = (int *) &options->log_level; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 545 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 546 | value = log_level_number(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 547 | if (value == (LogLevel) - 1) |
Ben Lindstrom | 6df8ef4 | 2001-03-05 07:47:23 +0000 | [diff] [blame] | 548 | fatal("%.200s line %d: unsupported log level '%s'", |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 549 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 550 | if (*activep && (LogLevel) * intptr == -1) |
| 551 | *intptr = (LogLevel) value; |
| 552 | break; |
| 553 | |
| 554 | case oRemoteForward: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 555 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 556 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 557 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Ben Lindstrom | 19066a1 | 2001-04-12 23:39:26 +0000 | [diff] [blame^] | 558 | fwd_port = a2port(arg); |
| 559 | if (fwd_port == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 560 | fatal("%.200s line %d: Badly formatted port number.", |
| 561 | filename, linenum); |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 562 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 563 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 564 | fatal("%.200s line %d: Missing second argument.", |
| 565 | filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 566 | if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 567 | fatal("%.200s line %d: Badly formatted host:port.", |
| 568 | filename, linenum); |
| 569 | if (*activep) |
| 570 | add_remote_forward(options, fwd_port, buf, fwd_host_port); |
| 571 | break; |
| 572 | |
| 573 | case oLocalForward: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 574 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 575 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 576 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Ben Lindstrom | 19066a1 | 2001-04-12 23:39:26 +0000 | [diff] [blame^] | 577 | fwd_port = a2port(arg); |
| 578 | if (fwd_port == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 579 | fatal("%.200s line %d: Badly formatted port number.", |
| 580 | filename, linenum); |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 581 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 582 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 583 | fatal("%.200s line %d: Missing second argument.", |
| 584 | filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 585 | if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 586 | fatal("%.200s line %d: Badly formatted host:port.", |
| 587 | filename, linenum); |
| 588 | if (*activep) |
| 589 | add_local_forward(options, fwd_port, buf, fwd_host_port); |
| 590 | break; |
| 591 | |
Ben Lindstrom | 3bb4f9d | 2001-04-08 18:30:26 +0000 | [diff] [blame] | 592 | case oDynamicForward: |
| 593 | arg = strdelim(&s); |
| 594 | if (!arg || *arg == '\0') |
| 595 | fatal("%.200s line %d: Missing port argument.", |
| 596 | filename, linenum); |
Ben Lindstrom | 19066a1 | 2001-04-12 23:39:26 +0000 | [diff] [blame^] | 597 | fwd_port = a2port(arg); |
| 598 | if (fwd_port == 0) |
Ben Lindstrom | 3bb4f9d | 2001-04-08 18:30:26 +0000 | [diff] [blame] | 599 | fatal("%.200s line %d: Badly formatted port number.", |
| 600 | filename, linenum); |
Ben Lindstrom | 3bb4f9d | 2001-04-08 18:30:26 +0000 | [diff] [blame] | 601 | add_local_forward(options, fwd_port, "socks4", 0); |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 602 | break; |
Ben Lindstrom | 3bb4f9d | 2001-04-08 18:30:26 +0000 | [diff] [blame] | 603 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 604 | case oHost: |
| 605 | *activep = 0; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 606 | while ((arg = strdelim(&s)) != NULL && *arg != '\0') |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 607 | if (match_pattern(host, arg)) { |
| 608 | debug("Applying options for %.100s", arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 609 | *activep = 1; |
| 610 | break; |
| 611 | } |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 612 | /* Avoid garbage check below, as strdelim is done. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 613 | return 0; |
| 614 | |
| 615 | case oEscapeChar: |
| 616 | intptr = &options->escape_char; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 617 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 618 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 619 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 620 | if (arg[0] == '^' && arg[2] == 0 && |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 621 | (u_char) arg[1] >= 64 && (u_char) arg[1] < 128) |
| 622 | value = (u_char) arg[1] & 31; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 623 | else if (strlen(arg) == 1) |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 624 | value = (u_char) arg[0]; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 625 | else if (strcmp(arg, "none") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 626 | value = -2; |
| 627 | else { |
| 628 | fatal("%.200s line %d: Bad escape character.", |
| 629 | filename, linenum); |
| 630 | /* NOTREACHED */ |
| 631 | value = 0; /* Avoid compiler warning. */ |
| 632 | } |
| 633 | if (*activep && *intptr == -1) |
| 634 | *intptr = value; |
| 635 | break; |
| 636 | |
| 637 | default: |
| 638 | fatal("process_config_line: Unimplemented opcode %d", opcode); |
| 639 | } |
| 640 | |
| 641 | /* Check that there is no garbage at end of line. */ |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 642 | if ((arg = strdelim(&s)) != NULL && *arg != '\0') { |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 643 | fatal("%.200s line %d: garbage at end of line; \"%.200s\".", |
| 644 | filename, linenum, arg); |
| 645 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 646 | return 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 650 | /* |
| 651 | * Reads the config file and modifies the options accordingly. Options |
| 652 | * should already be initialized before this call. This never returns if |
| 653 | * there is an error. If the file does not exist, this returns immediately. |
| 654 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 655 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 656 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 657 | read_config_file(const char *filename, const char *host, Options *options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 658 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 659 | FILE *f; |
| 660 | char line[1024]; |
| 661 | int active, linenum; |
| 662 | int bad_options = 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 663 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 664 | /* Open the file. */ |
| 665 | f = fopen(filename, "r"); |
| 666 | if (!f) |
| 667 | return; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 668 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 669 | debug("Reading configuration data %.200s", filename); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 670 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 671 | /* |
| 672 | * Mark that we are now processing the options. This flag is turned |
| 673 | * on/off by Host specifications. |
| 674 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 675 | active = 1; |
| 676 | linenum = 0; |
| 677 | while (fgets(line, sizeof(line), f)) { |
| 678 | /* Update line number counter. */ |
| 679 | linenum++; |
| 680 | if (process_config_line(options, host, line, filename, linenum, &active) != 0) |
| 681 | bad_options++; |
| 682 | } |
| 683 | fclose(f); |
| 684 | if (bad_options > 0) |
Ben Lindstrom | 6df8ef4 | 2001-03-05 07:47:23 +0000 | [diff] [blame] | 685 | fatal("%s: terminating, %d bad configuration options", |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 686 | filename, bad_options); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 687 | } |
| 688 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 689 | /* |
| 690 | * Initializes options to special values that indicate that they have not yet |
| 691 | * been set. Read_config_file will only set options with this value. Options |
| 692 | * are processed in the following order: command line, user config file, |
| 693 | * system config file. Last, fill_default_options is called. |
| 694 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 695 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 696 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 697 | initialize_options(Options * options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 698 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 699 | memset(options, 'X', sizeof(*options)); |
| 700 | options->forward_agent = -1; |
| 701 | options->forward_x11 = -1; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 702 | options->xauth_location = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 703 | options->gateway_ports = -1; |
| 704 | options->use_privileged_port = -1; |
| 705 | options->rhosts_authentication = -1; |
| 706 | options->rsa_authentication = -1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 707 | options->pubkey_authentication = -1; |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 708 | options->challenge_reponse_authentication = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 709 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 710 | options->kerberos_authentication = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 711 | #endif |
| 712 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 713 | options->kerberos_tgt_passing = -1; |
| 714 | options->afs_token_passing = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 715 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 716 | options->password_authentication = -1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 717 | options->kbd_interactive_authentication = -1; |
| 718 | options->kbd_interactive_devices = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 719 | options->rhosts_rsa_authentication = -1; |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 720 | options->hostbased_authentication = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 721 | options->fallback_to_rsh = -1; |
| 722 | options->use_rsh = -1; |
| 723 | options->batch_mode = -1; |
| 724 | options->check_host_ip = -1; |
| 725 | options->strict_host_key_checking = -1; |
| 726 | options->compression = -1; |
| 727 | options->keepalives = -1; |
| 728 | options->compression_level = -1; |
| 729 | options->port = -1; |
| 730 | options->connection_attempts = -1; |
| 731 | options->number_of_password_prompts = -1; |
| 732 | options->cipher = -1; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 733 | options->ciphers = NULL; |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 734 | options->macs = NULL; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 735 | options->protocol = SSH_PROTO_UNKNOWN; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 736 | options->num_identity_files = 0; |
| 737 | options->hostname = NULL; |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 738 | options->host_key_alias = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 739 | options->proxy_command = NULL; |
| 740 | options->user = NULL; |
| 741 | options->escape_char = -1; |
| 742 | options->system_hostfile = NULL; |
| 743 | options->user_hostfile = NULL; |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 744 | options->system_hostfile2 = NULL; |
| 745 | options->user_hostfile2 = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 746 | options->num_local_forwards = 0; |
| 747 | options->num_remote_forwards = 0; |
| 748 | options->log_level = (LogLevel) - 1; |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 749 | options->preferred_authentications = NULL; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 750 | } |
| 751 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 752 | /* |
| 753 | * Called after processing other sources of option data, this fills those |
| 754 | * options for which no value has been specified with their default values. |
| 755 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 756 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 757 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 758 | fill_default_options(Options * options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 759 | { |
Ben Lindstrom | 4f7a64a | 2001-02-10 22:50:09 +0000 | [diff] [blame] | 760 | int len; |
| 761 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 762 | if (options->forward_agent == -1) |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 763 | options->forward_agent = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 764 | if (options->forward_x11 == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 765 | options->forward_x11 = 0; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 766 | #ifdef XAUTH_PATH |
| 767 | if (options->xauth_location == NULL) |
| 768 | options->xauth_location = XAUTH_PATH; |
| 769 | #endif /* XAUTH_PATH */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 770 | if (options->gateway_ports == -1) |
| 771 | options->gateway_ports = 0; |
| 772 | if (options->use_privileged_port == -1) |
Ben Lindstrom | cebc858 | 2001-03-08 03:39:10 +0000 | [diff] [blame] | 773 | options->use_privileged_port = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 774 | if (options->rhosts_authentication == -1) |
| 775 | options->rhosts_authentication = 1; |
| 776 | if (options->rsa_authentication == -1) |
| 777 | options->rsa_authentication = 1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 778 | if (options->pubkey_authentication == -1) |
| 779 | options->pubkey_authentication = 1; |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 780 | if (options->challenge_reponse_authentication == -1) |
| 781 | options->challenge_reponse_authentication = 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 782 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 783 | if (options->kerberos_authentication == -1) |
| 784 | options->kerberos_authentication = 1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 785 | #endif /* KRB4 */ |
| 786 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 787 | if (options->kerberos_tgt_passing == -1) |
| 788 | options->kerberos_tgt_passing = 1; |
| 789 | if (options->afs_token_passing == -1) |
| 790 | options->afs_token_passing = 1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 791 | #endif /* AFS */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 792 | if (options->password_authentication == -1) |
| 793 | options->password_authentication = 1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 794 | if (options->kbd_interactive_authentication == -1) |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 795 | options->kbd_interactive_authentication = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 796 | if (options->rhosts_rsa_authentication == -1) |
| 797 | options->rhosts_rsa_authentication = 1; |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 798 | if (options->hostbased_authentication == -1) |
| 799 | options->hostbased_authentication = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 800 | if (options->fallback_to_rsh == -1) |
Damien Miller | 182ee6e | 2000-07-12 09:45:27 +1000 | [diff] [blame] | 801 | options->fallback_to_rsh = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 802 | if (options->use_rsh == -1) |
| 803 | options->use_rsh = 0; |
| 804 | if (options->batch_mode == -1) |
| 805 | options->batch_mode = 0; |
| 806 | if (options->check_host_ip == -1) |
| 807 | options->check_host_ip = 1; |
| 808 | if (options->strict_host_key_checking == -1) |
| 809 | options->strict_host_key_checking = 2; /* 2 is default */ |
| 810 | if (options->compression == -1) |
| 811 | options->compression = 0; |
| 812 | if (options->keepalives == -1) |
| 813 | options->keepalives = 1; |
| 814 | if (options->compression_level == -1) |
| 815 | options->compression_level = 6; |
| 816 | if (options->port == -1) |
| 817 | options->port = 0; /* Filled in ssh_connect. */ |
| 818 | if (options->connection_attempts == -1) |
| 819 | options->connection_attempts = 4; |
| 820 | if (options->number_of_password_prompts == -1) |
| 821 | options->number_of_password_prompts = 3; |
| 822 | /* Selected in ssh_login(). */ |
| 823 | if (options->cipher == -1) |
| 824 | options->cipher = SSH_CIPHER_NOT_SET; |
Damien Miller | 30c3d42 | 2000-05-09 11:02:59 +1000 | [diff] [blame] | 825 | /* options->ciphers, default set in myproposals.h */ |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 826 | /* options->macs, default set in myproposals.h */ |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 827 | if (options->protocol == SSH_PROTO_UNKNOWN) |
Ben Lindstrom | 6b77643 | 2001-03-22 01:24:04 +0000 | [diff] [blame] | 828 | options->protocol = SSH_PROTO_1|SSH_PROTO_2; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 829 | if (options->num_identity_files == 0) { |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 830 | if (options->protocol & SSH_PROTO_1) { |
Ben Lindstrom | 4f7a64a | 2001-02-10 22:50:09 +0000 | [diff] [blame] | 831 | len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 832 | options->identity_files[options->num_identity_files] = |
Ben Lindstrom | 4f7a64a | 2001-02-10 22:50:09 +0000 | [diff] [blame] | 833 | xmalloc(len); |
| 834 | snprintf(options->identity_files[options->num_identity_files++], |
| 835 | len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 836 | } |
| 837 | if (options->protocol & SSH_PROTO_2) { |
Ben Lindstrom | b00d4fb | 2001-03-05 06:03:03 +0000 | [diff] [blame] | 838 | len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1; |
| 839 | options->identity_files[options->num_identity_files] = |
| 840 | xmalloc(len); |
| 841 | snprintf(options->identity_files[options->num_identity_files++], |
| 842 | len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA); |
| 843 | |
Ben Lindstrom | 4f7a64a | 2001-02-10 22:50:09 +0000 | [diff] [blame] | 844 | len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 845 | options->identity_files[options->num_identity_files] = |
Ben Lindstrom | 4f7a64a | 2001-02-10 22:50:09 +0000 | [diff] [blame] | 846 | xmalloc(len); |
| 847 | snprintf(options->identity_files[options->num_identity_files++], |
| 848 | len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 849 | } |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 850 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 851 | if (options->escape_char == -1) |
| 852 | options->escape_char = '~'; |
| 853 | if (options->system_hostfile == NULL) |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 854 | options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 855 | if (options->user_hostfile == NULL) |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 856 | options->user_hostfile = _PATH_SSH_USER_HOSTFILE; |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 857 | if (options->system_hostfile2 == NULL) |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 858 | options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2; |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 859 | if (options->user_hostfile2 == NULL) |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 860 | options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 861 | if (options->log_level == (LogLevel) - 1) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 862 | options->log_level = SYSLOG_LEVEL_INFO; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 863 | /* options->proxy_command should not be set by default */ |
| 864 | /* options->user will be set in the main program if appropriate */ |
| 865 | /* options->hostname will be set in the main program if appropriate */ |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 866 | /* options->host_key_alias should not be set by default */ |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 867 | /* options->preferred_authentications will be set in ssh */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 868 | } |