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