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