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