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