xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * _ _ ____ _ |
| 3 | * Project ___| | | | _ \| | |
| 4 | * / __| | | | |_) | | |
| 5 | * | (__| |_| | _ <| |___ |
| 6 | * \___|\___/|_| \_\_____| |
| 7 | * |
| 8 | * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al. |
| 9 | * |
| 10 | * This software is licensed as described in the file COPYING, which |
| 11 | * you should have received as part of this distribution. The terms |
| 12 | * are also available at https://curl.se/docs/copyright.html. |
| 13 | * |
| 14 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
| 15 | * copies of the Software, and permit persons to whom the Software is |
| 16 | * furnished to do so, under the terms of the COPYING file. |
| 17 | * |
| 18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 | * KIND, either express or implied. |
| 20 | * |
| 21 | * SPDX-License-Identifier: curl |
| 22 | * |
| 23 | ***************************************************************************/ |
| 24 | #include "tool_setup.h" |
| 25 | |
| 26 | #include "strcase.h" |
| 27 | |
| 28 | #define ENABLE_CURLX_PRINTF |
| 29 | /* use our own printf() functions */ |
| 30 | #include "curlx.h" |
| 31 | |
| 32 | #include "tool_binmode.h" |
| 33 | #include "tool_cfgable.h" |
| 34 | #include "tool_cb_prg.h" |
| 35 | #include "tool_filetime.h" |
| 36 | #include "tool_formparse.h" |
| 37 | #include "tool_getparam.h" |
| 38 | #include "tool_helpers.h" |
| 39 | #include "tool_libinfo.h" |
| 40 | #include "tool_msgs.h" |
| 41 | #include "tool_paramhlp.h" |
| 42 | #include "tool_parsecfg.h" |
| 43 | #include "tool_main.h" |
| 44 | |
| 45 | #include "memdebug.h" /* keep this as LAST include */ |
| 46 | |
| 47 | #ifdef MSDOS |
| 48 | # define USE_WATT32 |
| 49 | #endif |
| 50 | |
| 51 | #define GetStr(str,val) do { \ |
| 52 | if(*(str)) { \ |
| 53 | free(*(str)); \ |
| 54 | *(str) = NULL; \ |
| 55 | } \ |
| 56 | if((val)) { \ |
| 57 | *(str) = strdup((val)); \ |
| 58 | if(!(*(str))) \ |
| 59 | return PARAM_NO_MEM; \ |
| 60 | } \ |
| 61 | } while(0) |
| 62 | |
| 63 | struct LongShort { |
| 64 | const char *letter; /* short name option */ |
| 65 | const char *lname; /* long name option */ |
| 66 | enum { |
| 67 | ARG_NONE, /* stand-alone but not a boolean */ |
| 68 | ARG_BOOL, /* accepts a --no-[name] prefix */ |
| 69 | ARG_STRING, /* requires an argument */ |
| 70 | ARG_FILENAME /* requires an argument, usually a file name */ |
| 71 | } desc; |
| 72 | }; |
| 73 | |
| 74 | static const struct LongShort aliases[]= { |
| 75 | /* 'letter' strings with more than one character have *no* short option to |
| 76 | mention. */ |
| 77 | {"*@", "url", ARG_STRING}, |
| 78 | {"*4", "dns-ipv4-addr", ARG_STRING}, |
| 79 | {"*6", "dns-ipv6-addr", ARG_STRING}, |
| 80 | {"*a", "random-file", ARG_FILENAME}, |
| 81 | {"*b", "egd-file", ARG_STRING}, |
| 82 | {"*B", "oauth2-bearer", ARG_STRING}, |
| 83 | {"*c", "connect-timeout", ARG_STRING}, |
| 84 | {"*C", "doh-url" , ARG_STRING}, |
| 85 | {"*d", "ciphers", ARG_STRING}, |
| 86 | {"*D", "dns-interface", ARG_STRING}, |
| 87 | {"*e", "disable-epsv", ARG_BOOL}, |
| 88 | {"*f", "disallow-username-in-url", ARG_BOOL}, |
| 89 | {"*E", "epsv", ARG_BOOL}, |
| 90 | /* 'epsv' made like this to make --no-epsv and --epsv to work |
| 91 | although --disable-epsv is the documented option */ |
| 92 | {"*F", "dns-servers", ARG_STRING}, |
| 93 | {"*g", "trace", ARG_FILENAME}, |
| 94 | {"*G", "npn", ARG_BOOL}, |
| 95 | {"*h", "trace-ascii", ARG_FILENAME}, |
| 96 | {"*H", "alpn", ARG_BOOL}, |
| 97 | {"*i", "limit-rate", ARG_STRING}, |
| 98 | {"*I", "rate", ARG_STRING}, |
| 99 | {"*j", "compressed", ARG_BOOL}, |
| 100 | {"*J", "tr-encoding", ARG_BOOL}, |
| 101 | {"*k", "digest", ARG_BOOL}, |
| 102 | {"*l", "negotiate", ARG_BOOL}, |
| 103 | {"*m", "ntlm", ARG_BOOL}, |
| 104 | {"*M", "ntlm-wb", ARG_BOOL}, |
| 105 | {"*n", "basic", ARG_BOOL}, |
| 106 | {"*o", "anyauth", ARG_BOOL}, |
| 107 | #ifdef USE_WATT32 |
| 108 | {"*p", "wdebug", ARG_BOOL}, |
| 109 | #endif |
| 110 | {"*q", "ftp-create-dirs", ARG_BOOL}, |
| 111 | {"*r", "create-dirs", ARG_BOOL}, |
| 112 | {"*R", "create-file-mode", ARG_STRING}, |
| 113 | {"*s", "max-redirs", ARG_STRING}, |
| 114 | {"*t", "proxy-ntlm", ARG_BOOL}, |
| 115 | {"*u", "crlf", ARG_BOOL}, |
| 116 | {"*v", "stderr", ARG_FILENAME}, |
| 117 | {"*V", "aws-sigv4", ARG_STRING}, |
| 118 | {"*w", "interface", ARG_STRING}, |
| 119 | {"*x", "krb", ARG_STRING}, |
| 120 | {"*x", "krb4", ARG_STRING}, |
| 121 | /* 'krb4' is the previous name */ |
| 122 | {"*X", "haproxy-protocol", ARG_BOOL}, |
| 123 | {"*y", "max-filesize", ARG_STRING}, |
| 124 | {"*z", "disable-eprt", ARG_BOOL}, |
| 125 | {"*Z", "eprt", ARG_BOOL}, |
| 126 | /* 'eprt' made like this to make --no-eprt and --eprt to work |
| 127 | although --disable-eprt is the documented option */ |
| 128 | {"*~", "xattr", ARG_BOOL}, |
| 129 | {"$a", "ftp-ssl", ARG_BOOL}, |
| 130 | /* 'ftp-ssl' deprecated name since 7.20.0 */ |
| 131 | {"$a", "ssl", ARG_BOOL}, |
| 132 | /* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */ |
| 133 | {"$b", "ftp-pasv", ARG_BOOL}, |
| 134 | {"$c", "socks5", ARG_STRING}, |
| 135 | {"$d", "tcp-nodelay", ARG_BOOL}, |
| 136 | {"$e", "proxy-digest", ARG_BOOL}, |
| 137 | {"$f", "proxy-basic", ARG_BOOL}, |
| 138 | {"$g", "retry", ARG_STRING}, |
| 139 | {"$V", "retry-connrefused", ARG_BOOL}, |
| 140 | {"$h", "retry-delay", ARG_STRING}, |
| 141 | {"$i", "retry-max-time", ARG_STRING}, |
| 142 | {"$k", "proxy-negotiate", ARG_BOOL}, |
| 143 | {"$l", "form-escape", ARG_BOOL}, |
| 144 | {"$m", "ftp-account", ARG_STRING}, |
| 145 | {"$n", "proxy-anyauth", ARG_BOOL}, |
| 146 | {"$o", "trace-time", ARG_BOOL}, |
| 147 | {"$p", "ignore-content-length", ARG_BOOL}, |
| 148 | {"$q", "ftp-skip-pasv-ip", ARG_BOOL}, |
| 149 | {"$r", "ftp-method", ARG_STRING}, |
| 150 | {"$s", "local-port", ARG_STRING}, |
| 151 | {"$t", "socks4", ARG_STRING}, |
| 152 | {"$T", "socks4a", ARG_STRING}, |
| 153 | {"$u", "ftp-alternative-to-user", ARG_STRING}, |
| 154 | {"$v", "ftp-ssl-reqd", ARG_BOOL}, |
| 155 | /* 'ftp-ssl-reqd' deprecated name since 7.20.0 */ |
| 156 | {"$v", "ssl-reqd", ARG_BOOL}, |
| 157 | /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */ |
| 158 | {"$w", "sessionid", ARG_BOOL}, |
| 159 | /* 'sessionid' listed as --no-sessionid in the help */ |
| 160 | {"$x", "ftp-ssl-control", ARG_BOOL}, |
| 161 | {"$y", "ftp-ssl-ccc", ARG_BOOL}, |
| 162 | {"$j", "ftp-ssl-ccc-mode", ARG_STRING}, |
| 163 | {"$z", "libcurl", ARG_STRING}, |
| 164 | {"$#", "raw", ARG_BOOL}, |
| 165 | {"$0", "post301", ARG_BOOL}, |
| 166 | {"$1", "keepalive", ARG_BOOL}, |
| 167 | /* 'keepalive' listed as --no-keepalive in the help */ |
| 168 | {"$2", "socks5-hostname", ARG_STRING}, |
| 169 | {"$3", "keepalive-time", ARG_STRING}, |
| 170 | {"$4", "post302", ARG_BOOL}, |
| 171 | {"$5", "noproxy", ARG_STRING}, |
| 172 | {"$7", "socks5-gssapi-nec", ARG_BOOL}, |
| 173 | {"$8", "proxy1.0", ARG_STRING}, |
| 174 | {"$9", "tftp-blksize", ARG_STRING}, |
| 175 | {"$A", "mail-from", ARG_STRING}, |
| 176 | {"$B", "mail-rcpt", ARG_STRING}, |
| 177 | {"$C", "ftp-pret", ARG_BOOL}, |
| 178 | {"$D", "proto", ARG_STRING}, |
| 179 | {"$E", "proto-redir", ARG_STRING}, |
| 180 | {"$F", "resolve", ARG_STRING}, |
| 181 | {"$G", "delegation", ARG_STRING}, |
| 182 | {"$H", "mail-auth", ARG_STRING}, |
| 183 | {"$I", "post303", ARG_BOOL}, |
| 184 | {"$J", "metalink", ARG_BOOL}, |
| 185 | {"$6", "sasl-authzid", ARG_STRING}, |
| 186 | {"$K", "sasl-ir", ARG_BOOL }, |
| 187 | {"$L", "test-event", ARG_BOOL}, |
| 188 | {"$M", "unix-socket", ARG_FILENAME}, |
| 189 | {"$N", "path-as-is", ARG_BOOL}, |
| 190 | {"$O", "socks5-gssapi-service", ARG_STRING}, |
| 191 | /* 'socks5-gssapi-service' merged with'proxy-service-name' and |
| 192 | deprecated since 7.49.0 */ |
| 193 | {"$O", "proxy-service-name", ARG_STRING}, |
| 194 | {"$P", "service-name", ARG_STRING}, |
| 195 | {"$Q", "proto-default", ARG_STRING}, |
| 196 | {"$R", "expect100-timeout", ARG_STRING}, |
| 197 | {"$S", "tftp-no-options", ARG_BOOL}, |
| 198 | {"$U", "connect-to", ARG_STRING}, |
| 199 | {"$W", "abstract-unix-socket", ARG_FILENAME}, |
| 200 | {"$X", "tls-max", ARG_STRING}, |
| 201 | {"$Y", "suppress-connect-headers", ARG_BOOL}, |
| 202 | {"$Z", "compressed-ssh", ARG_BOOL}, |
| 203 | {"$~", "happy-eyeballs-timeout-ms", ARG_STRING}, |
| 204 | {"$!", "retry-all-errors", ARG_BOOL}, |
| 205 | {"0", "http1.0", ARG_NONE}, |
| 206 | {"01", "http1.1", ARG_NONE}, |
| 207 | {"02", "http2", ARG_NONE}, |
| 208 | {"03", "http2-prior-knowledge", ARG_NONE}, |
| 209 | {"04", "http3", ARG_NONE}, |
| 210 | {"09", "http0.9", ARG_BOOL}, |
| 211 | {"1", "tlsv1", ARG_NONE}, |
| 212 | {"10", "tlsv1.0", ARG_NONE}, |
| 213 | {"11", "tlsv1.1", ARG_NONE}, |
| 214 | {"12", "tlsv1.2", ARG_NONE}, |
| 215 | {"13", "tlsv1.3", ARG_NONE}, |
| 216 | {"1A", "tls13-ciphers", ARG_STRING}, |
| 217 | {"1B", "proxy-tls13-ciphers", ARG_STRING}, |
| 218 | {"2", "sslv2", ARG_NONE}, |
| 219 | {"3", "sslv3", ARG_NONE}, |
| 220 | {"4", "ipv4", ARG_NONE}, |
| 221 | {"6", "ipv6", ARG_NONE}, |
| 222 | {"a", "append", ARG_BOOL}, |
| 223 | {"A", "user-agent", ARG_STRING}, |
| 224 | {"b", "cookie", ARG_STRING}, |
| 225 | {"ba", "alt-svc", ARG_STRING}, |
| 226 | {"bb", "hsts", ARG_STRING}, |
| 227 | {"B", "use-ascii", ARG_BOOL}, |
| 228 | {"c", "cookie-jar", ARG_STRING}, |
| 229 | {"C", "continue-at", ARG_STRING}, |
| 230 | {"d", "data", ARG_STRING}, |
| 231 | {"dr", "data-raw", ARG_STRING}, |
| 232 | {"da", "data-ascii", ARG_STRING}, |
| 233 | {"db", "data-binary", ARG_STRING}, |
| 234 | {"de", "data-urlencode", ARG_STRING}, |
| 235 | {"df", "json", ARG_STRING}, |
| 236 | {"D", "dump-header", ARG_FILENAME}, |
| 237 | {"e", "referer", ARG_STRING}, |
| 238 | {"E", "cert", ARG_FILENAME}, |
| 239 | {"Ea", "cacert", ARG_FILENAME}, |
| 240 | {"Eb", "cert-type", ARG_STRING}, |
| 241 | {"Ec", "key", ARG_FILENAME}, |
| 242 | {"Ed", "key-type", ARG_STRING}, |
| 243 | {"Ee", "pass", ARG_STRING}, |
| 244 | {"Ef", "engine", ARG_STRING}, |
| 245 | {"Eg", "capath", ARG_FILENAME}, |
| 246 | {"Eh", "pubkey", ARG_STRING}, |
| 247 | {"Ei", "hostpubmd5", ARG_STRING}, |
| 248 | {"EF", "hostpubsha256", ARG_STRING}, |
| 249 | {"Ej", "crlfile", ARG_FILENAME}, |
| 250 | {"Ek", "tlsuser", ARG_STRING}, |
| 251 | {"El", "tlspassword", ARG_STRING}, |
| 252 | {"Em", "tlsauthtype", ARG_STRING}, |
| 253 | {"En", "ssl-allow-beast", ARG_BOOL}, |
| 254 | {"Eo", "ssl-auto-client-cert", ARG_BOOL}, |
| 255 | {"EO", "proxy-ssl-auto-client-cert", ARG_BOOL}, |
| 256 | {"Ep", "pinnedpubkey", ARG_STRING}, |
| 257 | {"EP", "proxy-pinnedpubkey", ARG_STRING}, |
| 258 | {"Eq", "cert-status", ARG_BOOL}, |
| 259 | {"EQ", "doh-cert-status", ARG_BOOL}, |
| 260 | {"Er", "false-start", ARG_BOOL}, |
| 261 | {"Es", "ssl-no-revoke", ARG_BOOL}, |
| 262 | {"ES", "ssl-revoke-best-effort", ARG_BOOL}, |
| 263 | {"Et", "tcp-fastopen", ARG_BOOL}, |
| 264 | {"Eu", "proxy-tlsuser", ARG_STRING}, |
| 265 | {"Ev", "proxy-tlspassword", ARG_STRING}, |
| 266 | {"Ew", "proxy-tlsauthtype", ARG_STRING}, |
| 267 | {"Ex", "proxy-cert", ARG_FILENAME}, |
| 268 | {"Ey", "proxy-cert-type", ARG_STRING}, |
| 269 | {"Ez", "proxy-key", ARG_FILENAME}, |
| 270 | {"E0", "proxy-key-type", ARG_STRING}, |
| 271 | {"E1", "proxy-pass", ARG_STRING}, |
| 272 | {"E2", "proxy-ciphers", ARG_STRING}, |
| 273 | {"E3", "proxy-crlfile", ARG_FILENAME}, |
| 274 | {"E4", "proxy-ssl-allow-beast", ARG_BOOL}, |
| 275 | {"E5", "login-options", ARG_STRING}, |
| 276 | {"E6", "proxy-cacert", ARG_FILENAME}, |
| 277 | {"E7", "proxy-capath", ARG_FILENAME}, |
| 278 | {"E8", "proxy-insecure", ARG_BOOL}, |
| 279 | {"E9", "proxy-tlsv1", ARG_NONE}, |
| 280 | {"EA", "socks5-basic", ARG_BOOL}, |
| 281 | {"EB", "socks5-gssapi", ARG_BOOL}, |
| 282 | {"EC", "etag-save", ARG_FILENAME}, |
| 283 | {"ED", "etag-compare", ARG_FILENAME}, |
| 284 | {"EE", "curves", ARG_STRING}, |
| 285 | {"f", "fail", ARG_BOOL}, |
| 286 | {"fa", "fail-early", ARG_BOOL}, |
| 287 | {"fb", "styled-output", ARG_BOOL}, |
| 288 | {"fc", "mail-rcpt-allowfails", ARG_BOOL}, |
| 289 | {"fd", "fail-with-body", ARG_BOOL}, |
| 290 | {"fe", "remove-on-error", ARG_BOOL}, |
| 291 | {"F", "form", ARG_STRING}, |
| 292 | {"Fs", "form-string", ARG_STRING}, |
| 293 | {"g", "globoff", ARG_BOOL}, |
| 294 | {"G", "get", ARG_NONE}, |
| 295 | {"Ga", "request-target", ARG_STRING}, |
| 296 | {"h", "help", ARG_BOOL}, |
| 297 | {"H", "header", ARG_STRING}, |
| 298 | {"Hp", "proxy-header", ARG_STRING}, |
| 299 | {"i", "include", ARG_BOOL}, |
| 300 | {"I", "head", ARG_BOOL}, |
| 301 | {"j", "junk-session-cookies", ARG_BOOL}, |
| 302 | {"J", "remote-header-name", ARG_BOOL}, |
| 303 | {"k", "insecure", ARG_BOOL}, |
| 304 | {"kd", "doh-insecure", ARG_BOOL}, |
| 305 | {"K", "config", ARG_FILENAME}, |
| 306 | {"l", "list-only", ARG_BOOL}, |
| 307 | {"L", "location", ARG_BOOL}, |
| 308 | {"Lt", "location-trusted", ARG_BOOL}, |
| 309 | {"m", "max-time", ARG_STRING}, |
| 310 | {"M", "manual", ARG_BOOL}, |
| 311 | {"n", "netrc", ARG_BOOL}, |
| 312 | {"no", "netrc-optional", ARG_BOOL}, |
| 313 | {"ne", "netrc-file", ARG_FILENAME}, |
| 314 | {"N", "buffer", ARG_BOOL}, |
| 315 | /* 'buffer' listed as --no-buffer in the help */ |
| 316 | {"o", "output", ARG_FILENAME}, |
| 317 | {"O", "remote-name", ARG_BOOL}, |
| 318 | {"Oa", "remote-name-all", ARG_BOOL}, |
| 319 | {"Ob", "output-dir", ARG_STRING}, |
| 320 | {"Oc", "clobber", ARG_BOOL}, |
| 321 | {"p", "proxytunnel", ARG_BOOL}, |
| 322 | {"P", "ftp-port", ARG_STRING}, |
| 323 | {"q", "disable", ARG_BOOL}, |
| 324 | {"Q", "quote", ARG_STRING}, |
| 325 | {"r", "range", ARG_STRING}, |
| 326 | {"R", "remote-time", ARG_BOOL}, |
| 327 | {"s", "silent", ARG_BOOL}, |
| 328 | {"S", "show-error", ARG_BOOL}, |
| 329 | {"t", "telnet-option", ARG_STRING}, |
| 330 | {"T", "upload-file", ARG_FILENAME}, |
| 331 | {"u", "user", ARG_STRING}, |
| 332 | {"U", "proxy-user", ARG_STRING}, |
| 333 | {"v", "verbose", ARG_BOOL}, |
| 334 | {"V", "version", ARG_BOOL}, |
| 335 | {"w", "write-out", ARG_STRING}, |
| 336 | {"x", "proxy", ARG_STRING}, |
| 337 | {"xa", "preproxy", ARG_STRING}, |
| 338 | {"X", "request", ARG_STRING}, |
| 339 | {"Y", "speed-limit", ARG_STRING}, |
| 340 | {"y", "speed-time", ARG_STRING}, |
| 341 | {"z", "time-cond", ARG_STRING}, |
| 342 | {"Z", "parallel", ARG_BOOL}, |
| 343 | {"Zb", "parallel-max", ARG_STRING}, |
| 344 | {"Zc", "parallel-immediate", ARG_BOOL}, |
| 345 | {"#", "progress-bar", ARG_BOOL}, |
| 346 | {"#m", "progress-meter", ARG_BOOL}, |
| 347 | {":", "next", ARG_NONE}, |
| 348 | }; |
| 349 | |
| 350 | /* Split the argument of -E to 'certname' and 'passphrase' separated by colon. |
| 351 | * We allow ':' and '\' to be escaped by '\' so that we can use certificate |
| 352 | * nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/> |
| 353 | * for details. */ |
| 354 | #ifndef UNITTESTS |
| 355 | static |
| 356 | #endif |
| 357 | void parse_cert_parameter(const char *cert_parameter, |
| 358 | char **certname, |
| 359 | char **passphrase) |
| 360 | { |
| 361 | size_t param_length = strlen(cert_parameter); |
| 362 | size_t span; |
| 363 | const char *param_place = NULL; |
| 364 | char *certname_place = NULL; |
| 365 | *certname = NULL; |
| 366 | *passphrase = NULL; |
| 367 | |
| 368 | /* most trivial assumption: cert_parameter is empty */ |
| 369 | if(param_length == 0) |
| 370 | return; |
| 371 | |
| 372 | /* next less trivial: cert_parameter starts 'pkcs11:' and thus |
| 373 | * looks like a RFC7512 PKCS#11 URI which can be used as-is. |
| 374 | * Also if cert_parameter contains no colon nor backslash, this |
| 375 | * means no passphrase was given and no characters escaped */ |
| 376 | if(curl_strnequal(cert_parameter, "pkcs11:", 7) || |
| 377 | !strpbrk(cert_parameter, ":\\")) { |
| 378 | *certname = strdup(cert_parameter); |
| 379 | return; |
| 380 | } |
| 381 | /* deal with escaped chars; find unescaped colon if it exists */ |
| 382 | certname_place = malloc(param_length + 1); |
| 383 | if(!certname_place) |
| 384 | return; |
| 385 | |
| 386 | *certname = certname_place; |
| 387 | param_place = cert_parameter; |
| 388 | while(*param_place) { |
| 389 | span = strcspn(param_place, ":\\"); |
| 390 | strncpy(certname_place, param_place, span); |
| 391 | param_place += span; |
| 392 | certname_place += span; |
| 393 | /* we just ate all the non-special chars. now we're on either a special |
| 394 | * char or the end of the string. */ |
| 395 | switch(*param_place) { |
| 396 | case '\0': |
| 397 | break; |
| 398 | case '\\': |
| 399 | param_place++; |
| 400 | switch(*param_place) { |
| 401 | case '\0': |
| 402 | *certname_place++ = '\\'; |
| 403 | break; |
| 404 | case '\\': |
| 405 | *certname_place++ = '\\'; |
| 406 | param_place++; |
| 407 | break; |
| 408 | case ':': |
| 409 | *certname_place++ = ':'; |
| 410 | param_place++; |
| 411 | break; |
| 412 | default: |
| 413 | *certname_place++ = '\\'; |
| 414 | *certname_place++ = *param_place; |
| 415 | param_place++; |
| 416 | break; |
| 417 | } |
| 418 | break; |
| 419 | case ':': |
| 420 | /* Since we live in a world of weirdness and confusion, the win32 |
| 421 | dudes can use : when using drive letters and thus c:\file:password |
| 422 | needs to work. In order not to break compatibility, we still use : as |
| 423 | separator, but we try to detect when it is used for a file name! On |
| 424 | windows. */ |
| 425 | #ifdef WIN32 |
| 426 | if((param_place == &cert_parameter[1]) && |
| 427 | (cert_parameter[2] == '\\' || cert_parameter[2] == '/') && |
| 428 | (ISALPHA(cert_parameter[0])) ) { |
| 429 | /* colon in the second column, followed by a backslash, and the |
| 430 | first character is an alphabetic letter: |
| 431 | |
| 432 | this is a drive letter colon */ |
| 433 | *certname_place++ = ':'; |
| 434 | param_place++; |
| 435 | break; |
| 436 | } |
| 437 | #endif |
| 438 | /* escaped colons and Windows drive letter colons were handled |
| 439 | * above; if we're still here, this is a separating colon */ |
| 440 | param_place++; |
| 441 | if(*param_place) { |
| 442 | *passphrase = strdup(param_place); |
| 443 | } |
| 444 | goto done; |
| 445 | } |
| 446 | } |
| 447 | done: |
| 448 | *certname_place = '\0'; |
| 449 | } |
| 450 | |
| 451 | /* Replace (in-place) '%20' by '+' according to RFC1866 */ |
| 452 | static size_t replace_url_encoded_space_by_plus(char *url) |
| 453 | { |
| 454 | size_t orig_len = strlen(url); |
| 455 | size_t orig_index = 0; |
| 456 | size_t new_index = 0; |
| 457 | |
| 458 | while(orig_index < orig_len) { |
| 459 | if((url[orig_index] == '%') && |
| 460 | (url[orig_index + 1] == '2') && |
| 461 | (url[orig_index + 2] == '0')) { |
| 462 | url[new_index] = '+'; |
| 463 | orig_index += 3; |
| 464 | } |
| 465 | else{ |
| 466 | if(new_index != orig_index) { |
| 467 | url[new_index] = url[orig_index]; |
| 468 | } |
| 469 | orig_index++; |
| 470 | } |
| 471 | new_index++; |
| 472 | } |
| 473 | |
| 474 | url[new_index] = 0; /* terminate string */ |
| 475 | |
| 476 | return new_index; /* new size */ |
| 477 | } |
| 478 | |
| 479 | static void |
| 480 | GetFileAndPassword(char *nextarg, char **file, char **password) |
| 481 | { |
| 482 | char *certname, *passphrase; |
| 483 | parse_cert_parameter(nextarg, &certname, &passphrase); |
| 484 | Curl_safefree(*file); |
| 485 | *file = certname; |
| 486 | if(passphrase) { |
| 487 | Curl_safefree(*password); |
| 488 | *password = passphrase; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /* Get a size parameter for '--limit-rate' or '--max-filesize'. |
| 493 | * We support a 'G', 'M' or 'K' suffix too. |
| 494 | */ |
| 495 | static ParameterError GetSizeParameter(struct GlobalConfig *global, |
| 496 | const char *arg, |
| 497 | const char *which, |
| 498 | curl_off_t *value_out) |
| 499 | { |
| 500 | char *unit; |
| 501 | curl_off_t value; |
| 502 | |
| 503 | if(curlx_strtoofft(arg, &unit, 0, &value)) { |
| 504 | warnf(global, "invalid number specified for %s\n", which); |
| 505 | return PARAM_BAD_USE; |
| 506 | } |
| 507 | |
| 508 | if(!*unit) |
| 509 | unit = (char *)"b"; |
| 510 | else if(strlen(unit) > 1) |
| 511 | unit = (char *)"w"; /* unsupported */ |
| 512 | |
| 513 | switch(*unit) { |
| 514 | case 'G': |
| 515 | case 'g': |
| 516 | if(value > (CURL_OFF_T_MAX / (1024*1024*1024))) |
| 517 | return PARAM_NUMBER_TOO_LARGE; |
| 518 | value *= 1024*1024*1024; |
| 519 | break; |
| 520 | case 'M': |
| 521 | case 'm': |
| 522 | if(value > (CURL_OFF_T_MAX / (1024*1024))) |
| 523 | return PARAM_NUMBER_TOO_LARGE; |
| 524 | value *= 1024*1024; |
| 525 | break; |
| 526 | case 'K': |
| 527 | case 'k': |
| 528 | if(value > (CURL_OFF_T_MAX / 1024)) |
| 529 | return PARAM_NUMBER_TOO_LARGE; |
| 530 | value *= 1024; |
| 531 | break; |
| 532 | case 'b': |
| 533 | case 'B': |
| 534 | /* for plain bytes, leave as-is */ |
| 535 | break; |
| 536 | default: |
| 537 | warnf(global, "unsupported %s unit. Use G, M, K or B!\n", which); |
| 538 | return PARAM_BAD_USE; |
| 539 | } |
| 540 | *value_out = value; |
| 541 | return PARAM_OK; |
| 542 | } |
| 543 | |
| 544 | #ifdef HAVE_WRITABLE_ARGV |
| 545 | static void cleanarg(argv_item_t str) |
| 546 | { |
| 547 | /* now that GetStr has copied the contents of nextarg, wipe the next |
| 548 | * argument out so that the username:password isn't displayed in the |
| 549 | * system process list */ |
| 550 | if(str) { |
| 551 | size_t len = strlen(str); |
| 552 | memset(str, ' ', len); |
| 553 | } |
| 554 | } |
| 555 | #else |
| 556 | #define cleanarg(x) |
| 557 | #endif |
| 558 | |
| 559 | /* --data-urlencode */ |
| 560 | static ParameterError data_urlencode(struct GlobalConfig *global, |
| 561 | char *nextarg, |
| 562 | char **postp, |
| 563 | size_t *lenp) |
| 564 | { |
| 565 | /* [name]=[content], we encode the content part only |
| 566 | * [name]@[file name] |
| 567 | * |
| 568 | * Case 2: we first load the file using that name and then encode |
| 569 | * the content. |
| 570 | */ |
| 571 | ParameterError err; |
| 572 | const char *p = strchr(nextarg, '='); |
| 573 | size_t nlen; |
| 574 | char is_file; |
| 575 | char *postdata = NULL; |
| 576 | size_t size = 0; |
| 577 | if(!p) |
| 578 | /* there was no '=' letter, check for a '@' instead */ |
| 579 | p = strchr(nextarg, '@'); |
| 580 | if(p) { |
| 581 | nlen = p - nextarg; /* length of the name part */ |
| 582 | is_file = *p++; /* pass the separator */ |
| 583 | } |
| 584 | else { |
| 585 | /* neither @ nor =, so no name and it isn't a file */ |
| 586 | nlen = is_file = 0; |
| 587 | p = nextarg; |
| 588 | } |
| 589 | if('@' == is_file) { |
| 590 | FILE *file; |
| 591 | /* a '@' letter, it means that a file name or - (stdin) follows */ |
| 592 | if(!strcmp("-", p)) { |
| 593 | file = stdin; |
| 594 | set_binmode(stdin); |
| 595 | } |
| 596 | else { |
| 597 | file = fopen(p, "rb"); |
| 598 | if(!file) |
| 599 | warnf(global, |
| 600 | "Couldn't read data from file \"%s\", this makes " |
| 601 | "an empty POST.\n", nextarg); |
| 602 | } |
| 603 | |
| 604 | err = file2memory(&postdata, &size, file); |
| 605 | |
| 606 | if(file && (file != stdin)) |
| 607 | fclose(file); |
| 608 | if(err) |
| 609 | return err; |
| 610 | } |
| 611 | else { |
| 612 | GetStr(&postdata, p); |
| 613 | if(postdata) |
| 614 | size = strlen(postdata); |
| 615 | } |
| 616 | |
| 617 | if(!postdata) { |
| 618 | /* no data from the file, point to a zero byte string to make this |
| 619 | get sent as a POST anyway */ |
| 620 | postdata = strdup(""); |
| 621 | if(!postdata) |
| 622 | return PARAM_NO_MEM; |
| 623 | size = 0; |
| 624 | } |
| 625 | else { |
| 626 | char *enc = curl_easy_escape(NULL, postdata, (int)size); |
| 627 | Curl_safefree(postdata); /* no matter if it worked or not */ |
| 628 | if(enc) { |
| 629 | /* replace (in-place) '%20' by '+' according to RFC1866 */ |
| 630 | size_t enclen = replace_url_encoded_space_by_plus(enc); |
| 631 | /* now make a string with the name from above and append the |
| 632 | encoded string */ |
| 633 | size_t outlen = nlen + enclen + 2; |
| 634 | char *n = malloc(outlen); |
| 635 | if(!n) { |
| 636 | curl_free(enc); |
| 637 | return PARAM_NO_MEM; |
| 638 | } |
| 639 | if(nlen > 0) { /* only append '=' if we have a name */ |
| 640 | msnprintf(n, outlen, "%.*s=%s", (int)nlen, nextarg, enc); |
| 641 | size = outlen-1; |
| 642 | } |
| 643 | else { |
| 644 | strcpy(n, enc); |
| 645 | size = outlen-2; /* since no '=' was inserted */ |
| 646 | } |
| 647 | curl_free(enc); |
| 648 | postdata = n; |
| 649 | } |
| 650 | else |
| 651 | return PARAM_NO_MEM; |
| 652 | } |
| 653 | *postp = postdata; |
| 654 | *lenp = size; |
| 655 | return PARAM_OK; |
| 656 | } |
| 657 | |
| 658 | |
| 659 | ParameterError getparameter(const char *flag, /* f or -long-flag */ |
| 660 | char *nextarg, /* NULL if unset */ |
| 661 | bool *usedarg, /* set to TRUE if the arg |
| 662 | has been used */ |
| 663 | struct GlobalConfig *global, |
| 664 | struct OperationConfig *config) |
| 665 | { |
| 666 | char letter; |
| 667 | char subletter = '\0'; /* subletters can only occur on long options */ |
| 668 | int rc; |
| 669 | const char *parse = NULL; |
| 670 | unsigned int j; |
| 671 | time_t now; |
| 672 | int hit = -1; |
| 673 | bool longopt = FALSE; |
| 674 | bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */ |
| 675 | ParameterError err; |
| 676 | bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled |
| 677 | by using --OPTION or --no-OPTION */ |
| 678 | #ifdef HAVE_WRITABLE_ARGV |
| 679 | argv_item_t clearthis = NULL; |
| 680 | #endif |
| 681 | |
| 682 | static const char *redir_protos[] = { |
| 683 | "http", |
| 684 | "https", |
| 685 | "ftp", |
| 686 | "ftps", |
| 687 | NULL |
| 688 | }; |
| 689 | |
| 690 | *usedarg = FALSE; /* default is that we don't use the arg */ |
| 691 | |
| 692 | if(('-' != flag[0]) || ('-' == flag[1])) { |
| 693 | /* this should be a long name */ |
| 694 | const char *word = ('-' == flag[0]) ? flag + 2 : flag; |
| 695 | size_t fnam = strlen(word); |
| 696 | int numhits = 0; |
| 697 | bool noflagged = FALSE; |
| 698 | |
| 699 | if(!strncmp(word, "no-", 3)) { |
| 700 | /* disable this option but ignore the "no-" part when looking for it */ |
| 701 | word += 3; |
| 702 | toggle = FALSE; |
| 703 | noflagged = TRUE; |
| 704 | } |
| 705 | |
| 706 | for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) { |
| 707 | if(curl_strnequal(aliases[j].lname, word, fnam)) { |
| 708 | longopt = TRUE; |
| 709 | numhits++; |
| 710 | if(curl_strequal(aliases[j].lname, word)) { |
| 711 | parse = aliases[j].letter; |
| 712 | hit = j; |
| 713 | numhits = 1; /* a single unique hit */ |
| 714 | break; |
| 715 | } |
| 716 | parse = aliases[j].letter; |
| 717 | hit = j; |
| 718 | } |
| 719 | } |
| 720 | if(numhits > 1) { |
| 721 | /* this is at least the second match! */ |
| 722 | return PARAM_OPTION_AMBIGUOUS; |
| 723 | } |
| 724 | if(hit < 0) { |
| 725 | return PARAM_OPTION_UNKNOWN; |
| 726 | } |
| 727 | if(noflagged && (aliases[hit].desc != ARG_BOOL)) |
| 728 | /* --no- prefixed an option that isn't boolean! */ |
| 729 | return PARAM_NO_NOT_BOOLEAN; |
| 730 | } |
| 731 | else { |
| 732 | flag++; /* prefixed with one dash, pass it */ |
| 733 | hit = -1; |
| 734 | parse = flag; |
| 735 | } |
| 736 | |
| 737 | do { |
| 738 | /* we can loop here if we have multiple single-letters */ |
| 739 | |
| 740 | if(!longopt) { |
| 741 | letter = (char)*parse; |
| 742 | subletter = '\0'; |
| 743 | } |
| 744 | else { |
| 745 | letter = parse[0]; |
| 746 | subletter = parse[1]; |
| 747 | } |
| 748 | |
| 749 | if(hit < 0) { |
| 750 | for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) { |
| 751 | if(letter == aliases[j].letter[0]) { |
| 752 | hit = j; |
| 753 | break; |
| 754 | } |
| 755 | } |
| 756 | if(hit < 0) { |
| 757 | return PARAM_OPTION_UNKNOWN; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | if(aliases[hit].desc >= ARG_STRING) { |
| 762 | /* this option requires an extra parameter */ |
| 763 | if(!longopt && parse[1]) { |
| 764 | nextarg = (char *)&parse[1]; /* this is the actual extra parameter */ |
| 765 | #ifdef HAVE_WRITABLE_ARGV |
| 766 | clearthis = nextarg; |
| 767 | #endif |
| 768 | singleopt = TRUE; /* don't loop anymore after this */ |
| 769 | } |
| 770 | else if(!nextarg) |
| 771 | return PARAM_REQUIRES_PARAMETER; |
| 772 | else |
| 773 | *usedarg = TRUE; /* mark it as used */ |
| 774 | |
| 775 | if((aliases[hit].desc == ARG_FILENAME) && |
| 776 | (nextarg[0] == '-') && nextarg[1]) { |
| 777 | /* if the file name looks like a command line option */ |
| 778 | warnf(global, "The file name argument '%s' looks like a flag.\n", |
| 779 | nextarg); |
| 780 | } |
| 781 | } |
| 782 | else if((aliases[hit].desc == ARG_NONE) && !toggle) |
| 783 | return PARAM_NO_PREFIX; |
| 784 | |
| 785 | switch(letter) { |
| 786 | case '*': /* options without a short option */ |
| 787 | switch(subletter) { |
| 788 | case '4': /* --dns-ipv4-addr */ |
| 789 | if(!curlinfo->ares_num) /* c-ares is needed for this */ |
| 790 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 791 | /* addr in dot notation */ |
| 792 | GetStr(&config->dns_ipv4_addr, nextarg); |
| 793 | break; |
| 794 | case '6': /* --dns-ipv6-addr */ |
| 795 | if(!curlinfo->ares_num) /* c-ares is needed for this */ |
| 796 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 797 | /* addr in dot notation */ |
| 798 | GetStr(&config->dns_ipv6_addr, nextarg); |
| 799 | break; |
| 800 | case 'a': /* random-file */ |
| 801 | break; |
| 802 | case 'b': /* egd-file */ |
| 803 | break; |
| 804 | case 'B': /* OAuth 2.0 bearer token */ |
| 805 | GetStr(&config->oauth_bearer, nextarg); |
| 806 | cleanarg(clearthis); |
| 807 | config->authtype |= CURLAUTH_BEARER; |
| 808 | break; |
| 809 | case 'c': /* connect-timeout */ |
| 810 | err = str2udouble(&config->connecttimeout, nextarg, |
| 811 | (double)LONG_MAX/1000); |
| 812 | if(err) |
| 813 | return err; |
| 814 | break; |
| 815 | case 'C': /* doh-url */ |
| 816 | GetStr(&config->doh_url, nextarg); |
| 817 | if(config->doh_url && !config->doh_url[0]) |
| 818 | /* if given a blank string, we make it NULL again */ |
| 819 | Curl_safefree(config->doh_url); |
| 820 | break; |
| 821 | case 'd': /* ciphers */ |
| 822 | GetStr(&config->cipher_list, nextarg); |
| 823 | break; |
| 824 | case 'D': /* --dns-interface */ |
| 825 | if(!curlinfo->ares_num) /* c-ares is needed for this */ |
| 826 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 827 | /* interface name */ |
| 828 | GetStr(&config->dns_interface, nextarg); |
| 829 | break; |
| 830 | case 'e': /* --disable-epsv */ |
| 831 | config->disable_epsv = toggle; |
| 832 | break; |
| 833 | case 'f': /* --disallow-username-in-url */ |
| 834 | config->disallow_username_in_url = toggle; |
| 835 | break; |
| 836 | case 'E': /* --epsv */ |
| 837 | config->disable_epsv = (!toggle)?TRUE:FALSE; |
| 838 | break; |
| 839 | case 'F': /* --dns-servers */ |
| 840 | if(!curlinfo->ares_num) /* c-ares is needed for this */ |
| 841 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 842 | /* IP addrs of DNS servers */ |
| 843 | GetStr(&config->dns_servers, nextarg); |
| 844 | break; |
| 845 | case 'g': /* --trace */ |
| 846 | GetStr(&global->trace_dump, nextarg); |
| 847 | if(global->tracetype && (global->tracetype != TRACE_BIN)) |
| 848 | warnf(global, "--trace overrides an earlier trace/verbose option\n"); |
| 849 | global->tracetype = TRACE_BIN; |
| 850 | break; |
| 851 | case 'G': /* --npn */ |
| 852 | warnf(global, "--npn is no longer supported\n"); |
| 853 | break; |
| 854 | case 'h': /* --trace-ascii */ |
| 855 | GetStr(&global->trace_dump, nextarg); |
| 856 | if(global->tracetype && (global->tracetype != TRACE_ASCII)) |
| 857 | warnf(global, |
| 858 | "--trace-ascii overrides an earlier trace/verbose option\n"); |
| 859 | global->tracetype = TRACE_ASCII; |
| 860 | break; |
| 861 | case 'H': /* --alpn */ |
| 862 | config->noalpn = (!toggle)?TRUE:FALSE; |
| 863 | break; |
| 864 | case 'i': /* --limit-rate */ |
| 865 | { |
| 866 | curl_off_t value; |
| 867 | ParameterError pe = GetSizeParameter(global, nextarg, "rate", &value); |
| 868 | |
| 869 | if(pe != PARAM_OK) |
| 870 | return pe; |
| 871 | config->recvpersecond = value; |
| 872 | config->sendpersecond = value; |
| 873 | } |
| 874 | break; |
| 875 | case 'I': /* --rate (request rate) */ |
| 876 | { |
| 877 | /* support a few different suffixes, extract the suffix first, then |
| 878 | get the number and convert to per hour. |
| 879 | /s == per second |
| 880 | /m == per minute |
| 881 | /h == per hour (default) |
| 882 | /d == per day (24 hours) |
| 883 | */ |
| 884 | char *div = strchr(nextarg, '/'); |
| 885 | char number[26]; |
| 886 | long denominator; |
| 887 | long numerator = 60*60*1000; /* default per hour */ |
| 888 | size_t numlen = div ? (size_t)(div - nextarg) : strlen(nextarg); |
| 889 | if(numlen > sizeof(number)-1) |
| 890 | return PARAM_NUMBER_TOO_LARGE; |
| 891 | strncpy(number, nextarg, numlen); |
| 892 | number[numlen] = 0; |
| 893 | err = str2unum(&denominator, number); |
| 894 | if(err) |
| 895 | return err; |
| 896 | if(denominator < 1) |
| 897 | return PARAM_BAD_USE; |
| 898 | if(div) { |
| 899 | char unit = div[1]; |
| 900 | switch(unit) { |
| 901 | case 's': /* per second */ |
| 902 | numerator = 1000; |
| 903 | break; |
| 904 | case 'm': /* per minute */ |
| 905 | numerator = 60*1000; |
| 906 | break; |
| 907 | case 'h': /* per hour */ |
| 908 | break; |
| 909 | case 'd': /* per day */ |
| 910 | numerator = 24*60*60*1000; |
| 911 | break; |
| 912 | default: |
| 913 | errorf(global, "unsupported --rate unit\n"); |
| 914 | return PARAM_BAD_USE; |
| 915 | } |
| 916 | } |
| 917 | global->ms_per_transfer = numerator/denominator; |
| 918 | } |
| 919 | break; |
| 920 | |
| 921 | case 'j': /* --compressed */ |
| 922 | if(toggle && |
| 923 | !(curlinfo->features & (CURL_VERSION_LIBZ | |
| 924 | CURL_VERSION_BROTLI | CURL_VERSION_ZSTD))) |
| 925 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 926 | config->encoding = toggle; |
| 927 | break; |
| 928 | |
| 929 | case 'J': /* --tr-encoding */ |
| 930 | config->tr_encoding = toggle; |
| 931 | break; |
| 932 | |
| 933 | case 'k': /* --digest */ |
| 934 | if(toggle) |
| 935 | config->authtype |= CURLAUTH_DIGEST; |
| 936 | else |
| 937 | config->authtype &= ~CURLAUTH_DIGEST; |
| 938 | break; |
| 939 | |
| 940 | case 'l': /* --negotiate */ |
| 941 | if(toggle) { |
| 942 | if(curlinfo->features & CURL_VERSION_SPNEGO) |
| 943 | config->authtype |= CURLAUTH_NEGOTIATE; |
| 944 | else |
| 945 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 946 | } |
| 947 | else |
| 948 | config->authtype &= ~CURLAUTH_NEGOTIATE; |
| 949 | break; |
| 950 | |
| 951 | case 'm': /* --ntlm */ |
| 952 | if(toggle) { |
| 953 | if(curlinfo->features & CURL_VERSION_NTLM) |
| 954 | config->authtype |= CURLAUTH_NTLM; |
| 955 | else |
| 956 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 957 | } |
| 958 | else |
| 959 | config->authtype &= ~CURLAUTH_NTLM; |
| 960 | break; |
| 961 | |
| 962 | case 'M': /* --ntlm-wb */ |
| 963 | if(toggle) { |
| 964 | if(curlinfo->features & CURL_VERSION_NTLM_WB) |
| 965 | config->authtype |= CURLAUTH_NTLM_WB; |
| 966 | else |
| 967 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 968 | } |
| 969 | else |
| 970 | config->authtype &= ~CURLAUTH_NTLM_WB; |
| 971 | break; |
| 972 | |
| 973 | case 'n': /* --basic for completeness */ |
| 974 | if(toggle) |
| 975 | config->authtype |= CURLAUTH_BASIC; |
| 976 | else |
| 977 | config->authtype &= ~CURLAUTH_BASIC; |
| 978 | break; |
| 979 | |
| 980 | case 'o': /* --anyauth, let libcurl pick it */ |
| 981 | if(toggle) |
| 982 | config->authtype = CURLAUTH_ANY; |
| 983 | /* --no-anyauth simply doesn't touch it */ |
| 984 | break; |
| 985 | |
| 986 | #ifdef USE_WATT32 |
| 987 | case 'p': /* --wdebug */ |
| 988 | dbug_init(); |
| 989 | break; |
| 990 | #endif |
| 991 | case 'q': /* --ftp-create-dirs */ |
| 992 | config->ftp_create_dirs = toggle; |
| 993 | break; |
| 994 | |
| 995 | case 'r': /* --create-dirs */ |
| 996 | config->create_dirs = toggle; |
| 997 | break; |
| 998 | |
| 999 | case 'R': /* --create-file-mode */ |
| 1000 | err = oct2nummax(&config->create_file_mode, nextarg, 0777); |
| 1001 | if(err) |
| 1002 | return err; |
| 1003 | break; |
| 1004 | |
| 1005 | case 's': /* --max-redirs */ |
| 1006 | /* specified max no of redirects (http(s)), this accepts -1 as a |
| 1007 | special condition */ |
| 1008 | err = str2num(&config->maxredirs, nextarg); |
| 1009 | if(err) |
| 1010 | return err; |
| 1011 | if(config->maxredirs < -1) |
| 1012 | return PARAM_BAD_NUMERIC; |
| 1013 | break; |
| 1014 | |
| 1015 | case 't': /* --proxy-ntlm */ |
| 1016 | if(curlinfo->features & CURL_VERSION_NTLM) |
| 1017 | config->proxyntlm = toggle; |
| 1018 | else |
| 1019 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1020 | break; |
| 1021 | |
| 1022 | case 'u': /* --crlf */ |
| 1023 | /* LF -> CRLF conversion? */ |
| 1024 | config->crlf = toggle; |
| 1025 | break; |
| 1026 | |
| 1027 | case 'V': /* --aws-sigv4 */ |
| 1028 | config->authtype |= CURLAUTH_AWS_SIGV4; |
| 1029 | GetStr(&config->aws_sigv4, nextarg); |
| 1030 | break; |
| 1031 | |
| 1032 | case 'v': /* --stderr */ |
| 1033 | if(strcmp(nextarg, "-")) { |
| 1034 | FILE *newfile = fopen(nextarg, FOPEN_WRITETEXT); |
| 1035 | if(!newfile) |
| 1036 | warnf(global, "Failed to open %s!\n", nextarg); |
| 1037 | else { |
| 1038 | if(global->errors_fopened) |
| 1039 | fclose(global->errors); |
| 1040 | global->errors = newfile; |
| 1041 | global->errors_fopened = TRUE; |
| 1042 | } |
| 1043 | } |
| 1044 | else |
| 1045 | global->errors = stdout; |
| 1046 | break; |
| 1047 | case 'w': /* --interface */ |
| 1048 | /* interface */ |
| 1049 | GetStr(&config->iface, nextarg); |
| 1050 | break; |
| 1051 | case 'x': /* --krb */ |
| 1052 | /* kerberos level string */ |
| 1053 | if(curlinfo->features & CURL_VERSION_SPNEGO) |
| 1054 | GetStr(&config->krblevel, nextarg); |
| 1055 | else |
| 1056 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1057 | break; |
| 1058 | case 'X': /* --haproxy-protocol */ |
| 1059 | config->haproxy_protocol = toggle; |
| 1060 | break; |
| 1061 | case 'y': /* --max-filesize */ |
| 1062 | { |
| 1063 | curl_off_t value; |
| 1064 | ParameterError pe = |
| 1065 | GetSizeParameter(global, nextarg, "max-filesize", &value); |
| 1066 | |
| 1067 | if(pe != PARAM_OK) |
| 1068 | return pe; |
| 1069 | config->max_filesize = value; |
| 1070 | } |
| 1071 | break; |
| 1072 | case 'z': /* --disable-eprt */ |
| 1073 | config->disable_eprt = toggle; |
| 1074 | break; |
| 1075 | case 'Z': /* --eprt */ |
| 1076 | config->disable_eprt = (!toggle)?TRUE:FALSE; |
| 1077 | break; |
| 1078 | case '~': /* --xattr */ |
| 1079 | config->xattr = toggle; |
| 1080 | break; |
| 1081 | case '@': /* the URL! */ |
| 1082 | { |
| 1083 | struct getout *url; |
| 1084 | |
| 1085 | if(!config->url_get) |
| 1086 | config->url_get = config->url_list; |
| 1087 | |
| 1088 | if(config->url_get) { |
| 1089 | /* there's a node here, if it already is filled-in continue to find |
| 1090 | an "empty" node */ |
| 1091 | while(config->url_get && (config->url_get->flags & GETOUT_URL)) |
| 1092 | config->url_get = config->url_get->next; |
| 1093 | } |
| 1094 | |
| 1095 | /* now there might or might not be an available node to fill in! */ |
| 1096 | |
| 1097 | if(config->url_get) |
| 1098 | /* existing node */ |
| 1099 | url = config->url_get; |
| 1100 | else |
| 1101 | /* there was no free node, create one! */ |
| 1102 | config->url_get = url = new_getout(config); |
| 1103 | |
| 1104 | if(!url) |
| 1105 | return PARAM_NO_MEM; |
| 1106 | |
| 1107 | /* fill in the URL */ |
| 1108 | GetStr(&url->url, nextarg); |
| 1109 | url->flags |= GETOUT_URL; |
| 1110 | } |
| 1111 | } |
| 1112 | break; |
| 1113 | case '$': /* more options without a short option */ |
| 1114 | switch(subletter) { |
| 1115 | case 'a': /* --ssl */ |
| 1116 | if(toggle && !(curlinfo->features & CURL_VERSION_SSL)) |
| 1117 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1118 | config->ftp_ssl = toggle; |
| 1119 | if(config->ftp_ssl) |
| 1120 | warnf(global, |
| 1121 | "--ssl is an insecure option, consider --ssl-reqd instead\n"); |
| 1122 | break; |
| 1123 | case 'b': /* --ftp-pasv */ |
| 1124 | Curl_safefree(config->ftpport); |
| 1125 | break; |
| 1126 | case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves |
| 1127 | the name locally and passes on the resolved address */ |
| 1128 | GetStr(&config->proxy, nextarg); |
| 1129 | config->proxyver = CURLPROXY_SOCKS5; |
| 1130 | break; |
| 1131 | case 't': /* --socks4 specifies a socks4 proxy to use */ |
| 1132 | GetStr(&config->proxy, nextarg); |
| 1133 | config->proxyver = CURLPROXY_SOCKS4; |
| 1134 | break; |
| 1135 | case 'T': /* --socks4a specifies a socks4a proxy to use */ |
| 1136 | GetStr(&config->proxy, nextarg); |
| 1137 | config->proxyver = CURLPROXY_SOCKS4A; |
| 1138 | break; |
| 1139 | case '2': /* --socks5-hostname specifies a socks5 proxy and enables name |
| 1140 | resolving with the proxy */ |
| 1141 | GetStr(&config->proxy, nextarg); |
| 1142 | config->proxyver = CURLPROXY_SOCKS5_HOSTNAME; |
| 1143 | break; |
| 1144 | case 'd': /* --tcp-nodelay option */ |
| 1145 | config->tcp_nodelay = toggle; |
| 1146 | break; |
| 1147 | case 'e': /* --proxy-digest */ |
| 1148 | config->proxydigest = toggle; |
| 1149 | break; |
| 1150 | case 'f': /* --proxy-basic */ |
| 1151 | config->proxybasic = toggle; |
| 1152 | break; |
| 1153 | case 'g': /* --retry */ |
| 1154 | err = str2unum(&config->req_retry, nextarg); |
| 1155 | if(err) |
| 1156 | return err; |
| 1157 | break; |
| 1158 | case 'V': /* --retry-connrefused */ |
| 1159 | config->retry_connrefused = toggle; |
| 1160 | break; |
| 1161 | case 'h': /* --retry-delay */ |
| 1162 | err = str2unummax(&config->retry_delay, nextarg, LONG_MAX/1000); |
| 1163 | if(err) |
| 1164 | return err; |
| 1165 | break; |
| 1166 | case 'i': /* --retry-max-time */ |
| 1167 | err = str2unummax(&config->retry_maxtime, nextarg, LONG_MAX/1000); |
| 1168 | if(err) |
| 1169 | return err; |
| 1170 | break; |
| 1171 | case '!': /* --retry-all-errors */ |
| 1172 | config->retry_all_errors = toggle; |
| 1173 | break; |
| 1174 | |
| 1175 | case 'k': /* --proxy-negotiate */ |
| 1176 | if(curlinfo->features & CURL_VERSION_SPNEGO) |
| 1177 | config->proxynegotiate = toggle; |
| 1178 | else |
| 1179 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1180 | break; |
| 1181 | |
| 1182 | case 'l': /* --form-escape */ |
| 1183 | config->mime_options &= ~CURLMIMEOPT_FORMESCAPE; |
| 1184 | if(toggle) |
| 1185 | config->mime_options |= CURLMIMEOPT_FORMESCAPE; |
| 1186 | break; |
| 1187 | |
| 1188 | case 'm': /* --ftp-account */ |
| 1189 | GetStr(&config->ftp_account, nextarg); |
| 1190 | break; |
| 1191 | case 'n': /* --proxy-anyauth */ |
| 1192 | config->proxyanyauth = toggle; |
| 1193 | break; |
| 1194 | case 'o': /* --trace-time */ |
| 1195 | global->tracetime = toggle; |
| 1196 | break; |
| 1197 | case 'p': /* --ignore-content-length */ |
| 1198 | config->ignorecl = toggle; |
| 1199 | break; |
| 1200 | case 'q': /* --ftp-skip-pasv-ip */ |
| 1201 | config->ftp_skip_ip = toggle; |
| 1202 | break; |
| 1203 | case 'r': /* --ftp-method (undocumented at this point) */ |
| 1204 | config->ftp_filemethod = ftpfilemethod(config, nextarg); |
| 1205 | break; |
| 1206 | case 's': { /* --local-port */ |
| 1207 | /* 16bit base 10 is 5 digits, but we allow 6 so that this catches |
| 1208 | overflows, not just truncates */ |
| 1209 | char lrange[7]=""; |
| 1210 | char *p = nextarg; |
| 1211 | while(ISDIGIT(*p)) |
| 1212 | p++; |
| 1213 | if(*p) { |
| 1214 | /* if there's anything more than a plain decimal number */ |
| 1215 | rc = sscanf(p, " - %6s", lrange); |
| 1216 | *p = 0; /* null-terminate to make str2unum() work below */ |
| 1217 | } |
| 1218 | else |
| 1219 | rc = 0; |
| 1220 | |
| 1221 | err = str2unum(&config->localport, nextarg); |
| 1222 | if(err || (config->localport > 65535)) |
| 1223 | return PARAM_BAD_USE; |
| 1224 | if(!rc) |
| 1225 | config->localportrange = 1; /* default number of ports to try */ |
| 1226 | else { |
| 1227 | err = str2unum(&config->localportrange, lrange); |
| 1228 | if(err || (config->localportrange > 65535)) |
| 1229 | return PARAM_BAD_USE; |
| 1230 | config->localportrange -= (config->localport-1); |
| 1231 | if(config->localportrange < 1) |
| 1232 | return PARAM_BAD_USE; |
| 1233 | } |
| 1234 | break; |
| 1235 | } |
| 1236 | case 'u': /* --ftp-alternative-to-user */ |
| 1237 | GetStr(&config->ftp_alternative_to_user, nextarg); |
| 1238 | break; |
| 1239 | case 'v': /* --ssl-reqd */ |
| 1240 | if(toggle && !(curlinfo->features & CURL_VERSION_SSL)) |
| 1241 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1242 | config->ftp_ssl_reqd = toggle; |
| 1243 | break; |
| 1244 | case 'w': /* --no-sessionid */ |
| 1245 | config->disable_sessionid = (!toggle)?TRUE:FALSE; |
| 1246 | break; |
| 1247 | case 'x': /* --ftp-ssl-control */ |
| 1248 | if(toggle && !(curlinfo->features & CURL_VERSION_SSL)) |
| 1249 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1250 | config->ftp_ssl_control = toggle; |
| 1251 | break; |
| 1252 | case 'y': /* --ftp-ssl-ccc */ |
| 1253 | config->ftp_ssl_ccc = toggle; |
| 1254 | if(!config->ftp_ssl_ccc_mode) |
| 1255 | config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE; |
| 1256 | break; |
| 1257 | case 'j': /* --ftp-ssl-ccc-mode */ |
| 1258 | config->ftp_ssl_ccc = TRUE; |
| 1259 | config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg); |
| 1260 | break; |
| 1261 | case 'z': /* --libcurl */ |
| 1262 | #ifdef CURL_DISABLE_LIBCURL_OPTION |
| 1263 | warnf(global, |
| 1264 | "--libcurl option was disabled at build-time!\n"); |
| 1265 | return PARAM_OPTION_UNKNOWN; |
| 1266 | #else |
| 1267 | GetStr(&global->libcurl, nextarg); |
| 1268 | break; |
| 1269 | #endif |
| 1270 | case '#': /* --raw */ |
| 1271 | config->raw = toggle; |
| 1272 | break; |
| 1273 | case '0': /* --post301 */ |
| 1274 | config->post301 = toggle; |
| 1275 | break; |
| 1276 | case '1': /* --no-keepalive */ |
| 1277 | config->nokeepalive = (!toggle)?TRUE:FALSE; |
| 1278 | break; |
| 1279 | case '3': /* --keepalive-time */ |
| 1280 | err = str2unum(&config->alivetime, nextarg); |
| 1281 | if(err) |
| 1282 | return err; |
| 1283 | break; |
| 1284 | case '4': /* --post302 */ |
| 1285 | config->post302 = toggle; |
| 1286 | break; |
| 1287 | case 'I': /* --post303 */ |
| 1288 | config->post303 = toggle; |
| 1289 | break; |
| 1290 | case '5': /* --noproxy */ |
| 1291 | /* This specifies the noproxy list */ |
| 1292 | GetStr(&config->noproxy, nextarg); |
| 1293 | break; |
| 1294 | case '7': /* --socks5-gssapi-nec*/ |
| 1295 | config->socks5_gssapi_nec = toggle; |
| 1296 | break; |
| 1297 | case '8': /* --proxy1.0 */ |
| 1298 | /* http 1.0 proxy */ |
| 1299 | GetStr(&config->proxy, nextarg); |
| 1300 | config->proxyver = CURLPROXY_HTTP_1_0; |
| 1301 | break; |
| 1302 | case '9': /* --tftp-blksize */ |
| 1303 | err = str2unum(&config->tftp_blksize, nextarg); |
| 1304 | if(err) |
| 1305 | return err; |
| 1306 | break; |
| 1307 | case 'A': /* --mail-from */ |
| 1308 | GetStr(&config->mail_from, nextarg); |
| 1309 | break; |
| 1310 | case 'B': /* --mail-rcpt */ |
| 1311 | /* append receiver to a list */ |
| 1312 | err = add2list(&config->mail_rcpt, nextarg); |
| 1313 | if(err) |
| 1314 | return err; |
| 1315 | break; |
| 1316 | case 'C': /* --ftp-pret */ |
| 1317 | config->ftp_pret = toggle; |
| 1318 | break; |
| 1319 | case 'D': /* --proto */ |
| 1320 | config->proto_present = TRUE; |
| 1321 | err = proto2num(config, built_in_protos, &config->proto_str, nextarg); |
| 1322 | if(err) |
| 1323 | return err; |
| 1324 | break; |
| 1325 | case 'E': /* --proto-redir */ |
| 1326 | config->proto_redir_present = TRUE; |
| 1327 | if(proto2num(config, redir_protos, &config->proto_redir_str, nextarg)) |
| 1328 | return PARAM_BAD_USE; |
| 1329 | break; |
| 1330 | case 'F': /* --resolve */ |
| 1331 | err = add2list(&config->resolve, nextarg); |
| 1332 | if(err) |
| 1333 | return err; |
| 1334 | break; |
| 1335 | case 'G': /* --delegation LEVEL */ |
| 1336 | config->gssapi_delegation = delegation(config, nextarg); |
| 1337 | break; |
| 1338 | case 'H': /* --mail-auth */ |
| 1339 | GetStr(&config->mail_auth, nextarg); |
| 1340 | break; |
| 1341 | case 'J': /* --metalink */ |
| 1342 | errorf(global, "--metalink is disabled\n"); |
| 1343 | return PARAM_BAD_USE; |
| 1344 | case '6': /* --sasl-authzid */ |
| 1345 | GetStr(&config->sasl_authzid, nextarg); |
| 1346 | break; |
| 1347 | case 'K': /* --sasl-ir */ |
| 1348 | config->sasl_ir = toggle; |
| 1349 | break; |
| 1350 | case 'L': /* --test-event */ |
| 1351 | #ifdef CURLDEBUG |
| 1352 | global->test_event_based = toggle; |
| 1353 | #else |
| 1354 | warnf(global, "--test-event is ignored unless a debug build!\n"); |
| 1355 | #endif |
| 1356 | break; |
| 1357 | case 'M': /* --unix-socket */ |
| 1358 | config->abstract_unix_socket = FALSE; |
| 1359 | GetStr(&config->unix_socket_path, nextarg); |
| 1360 | break; |
| 1361 | case 'N': /* --path-as-is */ |
| 1362 | config->path_as_is = toggle; |
| 1363 | break; |
| 1364 | case 'O': /* --proxy-service-name */ |
| 1365 | GetStr(&config->proxy_service_name, nextarg); |
| 1366 | break; |
| 1367 | case 'P': /* --service-name */ |
| 1368 | GetStr(&config->service_name, nextarg); |
| 1369 | break; |
| 1370 | case 'Q': /* --proto-default */ |
| 1371 | GetStr(&config->proto_default, nextarg); |
| 1372 | err = check_protocol(config->proto_default); |
| 1373 | if(err) |
| 1374 | return err; |
| 1375 | break; |
| 1376 | case 'R': /* --expect100-timeout */ |
| 1377 | err = str2udouble(&config->expect100timeout, nextarg, |
| 1378 | (double)LONG_MAX/1000); |
| 1379 | if(err) |
| 1380 | return err; |
| 1381 | break; |
| 1382 | case 'S': /* --tftp-no-options */ |
| 1383 | config->tftp_no_options = toggle; |
| 1384 | break; |
| 1385 | case 'U': /* --connect-to */ |
| 1386 | err = add2list(&config->connect_to, nextarg); |
| 1387 | if(err) |
| 1388 | return err; |
| 1389 | break; |
| 1390 | case 'W': /* --abstract-unix-socket */ |
| 1391 | config->abstract_unix_socket = TRUE; |
| 1392 | GetStr(&config->unix_socket_path, nextarg); |
| 1393 | break; |
| 1394 | case 'X': /* --tls-max */ |
| 1395 | err = str2tls_max(&config->ssl_version_max, nextarg); |
| 1396 | if(err) |
| 1397 | return err; |
| 1398 | break; |
| 1399 | case 'Y': /* --suppress-connect-headers */ |
| 1400 | config->suppress_connect_headers = toggle; |
| 1401 | break; |
| 1402 | case 'Z': /* --compressed-ssh */ |
| 1403 | config->ssh_compression = toggle; |
| 1404 | break; |
| 1405 | case '~': /* --happy-eyeballs-timeout-ms */ |
| 1406 | err = str2unum(&config->happy_eyeballs_timeout_ms, nextarg); |
| 1407 | if(err) |
| 1408 | return err; |
| 1409 | /* 0 is a valid value for this timeout */ |
| 1410 | break; |
| 1411 | } |
| 1412 | break; |
| 1413 | case '#': |
| 1414 | switch(subletter) { |
| 1415 | case 'm': /* --progress-meter */ |
| 1416 | global->noprogress = !toggle; |
| 1417 | break; |
| 1418 | default: /* --progress-bar */ |
| 1419 | global->progressmode = |
| 1420 | toggle ? CURL_PROGRESS_BAR : CURL_PROGRESS_STATS; |
| 1421 | break; |
| 1422 | } |
| 1423 | break; |
| 1424 | case ':': /* --next */ |
| 1425 | return PARAM_NEXT_OPERATION; |
| 1426 | case '0': /* --http* options */ |
| 1427 | switch(subletter) { |
| 1428 | case '\0': |
| 1429 | /* HTTP version 1.0 */ |
| 1430 | config->httpversion = CURL_HTTP_VERSION_1_0; |
| 1431 | break; |
| 1432 | case '1': |
| 1433 | /* HTTP version 1.1 */ |
| 1434 | config->httpversion = CURL_HTTP_VERSION_1_1; |
| 1435 | break; |
| 1436 | case '2': |
| 1437 | /* HTTP version 2.0 */ |
| 1438 | config->httpversion = CURL_HTTP_VERSION_2_0; |
| 1439 | break; |
| 1440 | case '3': /* --http2-prior-knowledge */ |
| 1441 | /* HTTP version 2.0 over clean TCP*/ |
| 1442 | config->httpversion = CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE; |
| 1443 | break; |
| 1444 | case '4': /* --http3 */ |
| 1445 | /* HTTP version 3 go over QUIC - at once */ |
| 1446 | if(curlinfo->features & CURL_VERSION_HTTP3) |
| 1447 | config->httpversion = CURL_HTTP_VERSION_3; |
| 1448 | else |
| 1449 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1450 | break; |
| 1451 | case '9': |
| 1452 | /* Allow HTTP/0.9 responses! */ |
| 1453 | config->http09_allowed = toggle; |
| 1454 | break; |
| 1455 | } |
| 1456 | break; |
| 1457 | case '1': /* --tlsv1* options */ |
| 1458 | switch(subletter) { |
| 1459 | case '\0': |
| 1460 | /* TLS version 1.x */ |
| 1461 | config->ssl_version = CURL_SSLVERSION_TLSv1; |
| 1462 | break; |
| 1463 | case '0': |
| 1464 | /* TLS version 1.0 */ |
| 1465 | config->ssl_version = CURL_SSLVERSION_TLSv1_0; |
| 1466 | break; |
| 1467 | case '1': |
| 1468 | /* TLS version 1.1 */ |
| 1469 | config->ssl_version = CURL_SSLVERSION_TLSv1_1; |
| 1470 | break; |
| 1471 | case '2': |
| 1472 | /* TLS version 1.2 */ |
| 1473 | config->ssl_version = CURL_SSLVERSION_TLSv1_2; |
| 1474 | break; |
| 1475 | case '3': |
| 1476 | /* TLS version 1.3 */ |
| 1477 | config->ssl_version = CURL_SSLVERSION_TLSv1_3; |
| 1478 | break; |
| 1479 | case 'A': /* --tls13-ciphers */ |
| 1480 | GetStr(&config->cipher13_list, nextarg); |
| 1481 | break; |
| 1482 | case 'B': /* --proxy-tls13-ciphers */ |
| 1483 | GetStr(&config->proxy_cipher13_list, nextarg); |
| 1484 | break; |
| 1485 | } |
| 1486 | break; |
| 1487 | case '2': |
| 1488 | /* SSL version 2 */ |
| 1489 | warnf(global, "Ignores instruction to use SSLv2\n"); |
| 1490 | break; |
| 1491 | case '3': |
| 1492 | /* SSL version 3 */ |
| 1493 | warnf(global, "Ignores instruction to use SSLv3\n"); |
| 1494 | break; |
| 1495 | case '4': |
| 1496 | /* IPv4 */ |
| 1497 | config->ip_version = CURL_IPRESOLVE_V4; |
| 1498 | break; |
| 1499 | case '6': |
| 1500 | /* IPv6 */ |
| 1501 | config->ip_version = CURL_IPRESOLVE_V6; |
| 1502 | break; |
| 1503 | case 'a': |
| 1504 | /* This makes the FTP sessions use APPE instead of STOR */ |
| 1505 | config->ftp_append = toggle; |
| 1506 | break; |
| 1507 | case 'A': |
| 1508 | /* This specifies the User-Agent name */ |
| 1509 | GetStr(&config->useragent, nextarg); |
| 1510 | break; |
| 1511 | case 'b': |
| 1512 | switch(subletter) { |
| 1513 | case 'a': /* --alt-svc */ |
| 1514 | if(curlinfo->features & CURL_VERSION_ALTSVC) |
| 1515 | GetStr(&config->altsvc, nextarg); |
| 1516 | else |
| 1517 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1518 | break; |
| 1519 | case 'b': /* --hsts */ |
| 1520 | if(curlinfo->features & CURL_VERSION_HSTS) |
| 1521 | GetStr(&config->hsts, nextarg); |
| 1522 | else |
| 1523 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1524 | break; |
| 1525 | default: /* --cookie string coming up: */ |
| 1526 | if(nextarg[0] == '@') { |
| 1527 | nextarg++; |
| 1528 | } |
| 1529 | else if(strchr(nextarg, '=')) { |
| 1530 | /* A cookie string must have a =-letter */ |
| 1531 | err = add2list(&config->cookies, nextarg); |
| 1532 | if(err) |
| 1533 | return err; |
| 1534 | break; |
| 1535 | } |
| 1536 | /* We have a cookie file to read from! */ |
| 1537 | err = add2list(&config->cookiefiles, nextarg); |
| 1538 | if(err) |
| 1539 | return err; |
| 1540 | } |
| 1541 | break; |
| 1542 | case 'B': |
| 1543 | /* use ASCII/text when transferring */ |
| 1544 | config->use_ascii = toggle; |
| 1545 | break; |
| 1546 | case 'c': |
| 1547 | /* get the file name to dump all cookies in */ |
| 1548 | GetStr(&config->cookiejar, nextarg); |
| 1549 | break; |
| 1550 | case 'C': |
| 1551 | /* This makes us continue an ftp transfer at given position */ |
| 1552 | if(strcmp(nextarg, "-")) { |
| 1553 | err = str2offset(&config->resume_from, nextarg); |
| 1554 | if(err) |
| 1555 | return err; |
| 1556 | config->resume_from_current = FALSE; |
| 1557 | } |
| 1558 | else { |
| 1559 | config->resume_from_current = TRUE; |
| 1560 | config->resume_from = 0; |
| 1561 | } |
| 1562 | config->use_resume = TRUE; |
| 1563 | break; |
| 1564 | case 'd': |
| 1565 | /* postfield data */ |
| 1566 | { |
| 1567 | char *postdata = NULL; |
| 1568 | FILE *file; |
| 1569 | size_t size = 0; |
| 1570 | bool raw_mode = (subletter == 'r'); |
| 1571 | |
| 1572 | if(subletter == 'e') { /* --data-urlencode */ |
| 1573 | err = data_urlencode(global, nextarg, &postdata, &size); |
| 1574 | if(err) |
| 1575 | return err; |
| 1576 | } |
| 1577 | else if('@' == *nextarg && !raw_mode) { |
| 1578 | /* the data begins with a '@' letter, it means that a file name |
| 1579 | or - (stdin) follows */ |
| 1580 | nextarg++; /* pass the @ */ |
| 1581 | |
| 1582 | if(!strcmp("-", nextarg)) { |
| 1583 | file = stdin; |
| 1584 | if(subletter == 'b') /* forced data-binary */ |
| 1585 | set_binmode(stdin); |
| 1586 | } |
| 1587 | else { |
| 1588 | file = fopen(nextarg, "rb"); |
| 1589 | if(!file) |
| 1590 | warnf(global, "Couldn't read data from file \"%s\", this makes " |
| 1591 | "an empty POST.\n", nextarg); |
| 1592 | } |
| 1593 | |
| 1594 | if((subletter == 'b') || /* --data-binary */ |
| 1595 | (subletter == 'f') /* --json */) |
| 1596 | /* forced binary */ |
| 1597 | err = file2memory(&postdata, &size, file); |
| 1598 | else { |
| 1599 | err = file2string(&postdata, file); |
| 1600 | if(postdata) |
| 1601 | size = strlen(postdata); |
| 1602 | } |
| 1603 | |
| 1604 | if(file && (file != stdin)) |
| 1605 | fclose(file); |
| 1606 | if(err) |
| 1607 | return err; |
| 1608 | |
| 1609 | if(!postdata) { |
| 1610 | /* no data from the file, point to a zero byte string to make this |
| 1611 | get sent as a POST anyway */ |
| 1612 | postdata = strdup(""); |
| 1613 | if(!postdata) |
| 1614 | return PARAM_NO_MEM; |
| 1615 | } |
| 1616 | } |
| 1617 | else { |
| 1618 | GetStr(&postdata, nextarg); |
| 1619 | if(postdata) |
| 1620 | size = strlen(postdata); |
| 1621 | } |
| 1622 | if(subletter == 'f') |
| 1623 | config->jsoned = TRUE; |
| 1624 | |
| 1625 | if(config->postfields) { |
| 1626 | /* we already have a string, we append this one with a separating |
| 1627 | &-letter */ |
| 1628 | char *oldpost = config->postfields; |
| 1629 | curl_off_t oldlen = config->postfieldsize; |
| 1630 | curl_off_t newlen = oldlen + curlx_uztoso(size) + 2; |
| 1631 | config->postfields = malloc((size_t)newlen); |
| 1632 | if(!config->postfields) { |
| 1633 | Curl_safefree(oldpost); |
| 1634 | Curl_safefree(postdata); |
| 1635 | return PARAM_NO_MEM; |
| 1636 | } |
| 1637 | memcpy(config->postfields, oldpost, (size_t)oldlen); |
| 1638 | if(subletter != 'f') { |
| 1639 | /* skip this treatment for --json */ |
| 1640 | /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */ |
| 1641 | config->postfields[oldlen] = '\x26'; |
| 1642 | memcpy(&config->postfields[oldlen + 1], postdata, size); |
| 1643 | config->postfields[oldlen + 1 + size] = '\0'; |
| 1644 | config->postfieldsize += size + 1; |
| 1645 | } |
| 1646 | else { |
| 1647 | memcpy(&config->postfields[oldlen], postdata, size); |
| 1648 | config->postfields[oldlen + size] = '\0'; |
| 1649 | config->postfieldsize += size; |
| 1650 | } |
| 1651 | Curl_safefree(oldpost); |
| 1652 | Curl_safefree(postdata); |
| 1653 | } |
| 1654 | else { |
| 1655 | config->postfields = postdata; |
| 1656 | config->postfieldsize = curlx_uztoso(size); |
| 1657 | } |
| 1658 | } |
| 1659 | /* |
| 1660 | We can't set the request type here, as this data might be used in |
| 1661 | a simple GET if -G is used. Already or soon. |
| 1662 | |
| 1663 | if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) { |
| 1664 | Curl_safefree(postdata); |
| 1665 | return PARAM_BAD_USE; |
| 1666 | } |
| 1667 | */ |
| 1668 | break; |
| 1669 | case 'D': |
| 1670 | /* dump-header to given file name */ |
| 1671 | GetStr(&config->headerfile, nextarg); |
| 1672 | break; |
| 1673 | case 'e': |
| 1674 | { |
| 1675 | char *ptr = strstr(nextarg, ";auto"); |
| 1676 | if(ptr) { |
| 1677 | /* Automatic referer requested, this may be combined with a |
| 1678 | set initial one */ |
| 1679 | config->autoreferer = TRUE; |
| 1680 | *ptr = 0; /* null-terminate here */ |
| 1681 | } |
| 1682 | else |
| 1683 | config->autoreferer = FALSE; |
| 1684 | ptr = *nextarg ? nextarg : NULL; |
| 1685 | GetStr(&config->referer, ptr); |
| 1686 | } |
| 1687 | break; |
| 1688 | case 'E': |
| 1689 | switch(subletter) { |
| 1690 | case '\0': /* certificate file */ |
| 1691 | cleanarg(clearthis); |
| 1692 | GetFileAndPassword(nextarg, &config->cert, &config->key_passwd); |
| 1693 | break; |
| 1694 | case 'a': /* CA info PEM file */ |
| 1695 | GetStr(&config->cacert, nextarg); |
| 1696 | break; |
| 1697 | case 'b': /* cert file type */ |
| 1698 | GetStr(&config->cert_type, nextarg); |
| 1699 | break; |
| 1700 | case 'c': /* private key file */ |
| 1701 | GetStr(&config->key, nextarg); |
| 1702 | break; |
| 1703 | case 'd': /* private key file type */ |
| 1704 | GetStr(&config->key_type, nextarg); |
| 1705 | break; |
| 1706 | case 'e': /* private key passphrase */ |
| 1707 | GetStr(&config->key_passwd, nextarg); |
| 1708 | cleanarg(clearthis); |
| 1709 | break; |
| 1710 | case 'f': /* crypto engine */ |
| 1711 | GetStr(&config->engine, nextarg); |
| 1712 | if(config->engine && curl_strequal(config->engine, "list")) |
| 1713 | return PARAM_ENGINES_REQUESTED; |
| 1714 | break; |
| 1715 | case 'g': /* CA cert directory */ |
| 1716 | GetStr(&config->capath, nextarg); |
| 1717 | break; |
| 1718 | case 'h': /* --pubkey public key file */ |
| 1719 | GetStr(&config->pubkey, nextarg); |
| 1720 | break; |
| 1721 | case 'i': /* --hostpubmd5 md5 of the host public key */ |
| 1722 | GetStr(&config->hostpubmd5, nextarg); |
| 1723 | if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32) |
| 1724 | return PARAM_BAD_USE; |
| 1725 | break; |
| 1726 | case 'F': /* --hostpubsha256 sha256 of the host public key */ |
| 1727 | GetStr(&config->hostpubsha256, nextarg); |
| 1728 | break; |
| 1729 | case 'j': /* CRL file */ |
| 1730 | GetStr(&config->crlfile, nextarg); |
| 1731 | break; |
| 1732 | case 'k': /* TLS username */ |
| 1733 | if(!(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)) { |
| 1734 | cleanarg(clearthis); |
| 1735 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1736 | } |
| 1737 | GetStr(&config->tls_username, nextarg); |
| 1738 | cleanarg(clearthis); |
| 1739 | break; |
| 1740 | case 'l': /* TLS password */ |
| 1741 | if(!(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)) { |
| 1742 | cleanarg(clearthis); |
| 1743 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1744 | } |
| 1745 | GetStr(&config->tls_password, nextarg); |
| 1746 | cleanarg(clearthis); |
| 1747 | break; |
| 1748 | case 'm': /* TLS authentication type */ |
| 1749 | if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) { |
| 1750 | GetStr(&config->tls_authtype, nextarg); |
| 1751 | if(!curl_strequal(config->tls_authtype, "SRP")) |
| 1752 | return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */ |
| 1753 | } |
| 1754 | else |
| 1755 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1756 | break; |
| 1757 | case 'n': /* no empty SSL fragments, --ssl-allow-beast */ |
| 1758 | if(curlinfo->features & CURL_VERSION_SSL) |
| 1759 | config->ssl_allow_beast = toggle; |
| 1760 | break; |
| 1761 | |
| 1762 | case 'o': /* --ssl-auto-client-cert */ |
| 1763 | if(curlinfo->features & CURL_VERSION_SSL) |
| 1764 | config->ssl_auto_client_cert = toggle; |
| 1765 | break; |
| 1766 | |
| 1767 | case 'O': /* --proxy-ssl-auto-client-cert */ |
| 1768 | if(curlinfo->features & CURL_VERSION_SSL) |
| 1769 | config->proxy_ssl_auto_client_cert = toggle; |
| 1770 | break; |
| 1771 | |
| 1772 | case 'p': /* Pinned public key DER file */ |
| 1773 | GetStr(&config->pinnedpubkey, nextarg); |
| 1774 | break; |
| 1775 | |
| 1776 | case 'P': /* proxy pinned public key */ |
| 1777 | GetStr(&config->proxy_pinnedpubkey, nextarg); |
| 1778 | break; |
| 1779 | |
| 1780 | case 'q': /* --cert-status */ |
| 1781 | config->verifystatus = TRUE; |
| 1782 | break; |
| 1783 | |
| 1784 | case 'Q': /* --doh-cert-status */ |
| 1785 | config->doh_verifystatus = TRUE; |
| 1786 | break; |
| 1787 | |
| 1788 | case 'r': /* --false-start */ |
| 1789 | config->falsestart = TRUE; |
| 1790 | break; |
| 1791 | |
| 1792 | case 's': /* --ssl-no-revoke */ |
| 1793 | if(curlinfo->features & CURL_VERSION_SSL) |
| 1794 | config->ssl_no_revoke = TRUE; |
| 1795 | break; |
| 1796 | |
| 1797 | case 'S': /* --ssl-revoke-best-effort */ |
| 1798 | if(curlinfo->features & CURL_VERSION_SSL) |
| 1799 | config->ssl_revoke_best_effort = TRUE; |
| 1800 | break; |
| 1801 | |
| 1802 | case 't': /* --tcp-fastopen */ |
| 1803 | config->tcp_fastopen = TRUE; |
| 1804 | break; |
| 1805 | |
| 1806 | case 'u': /* TLS username for proxy */ |
| 1807 | cleanarg(clearthis); |
| 1808 | if(!(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)) { |
| 1809 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1810 | } |
| 1811 | GetStr(&config->proxy_tls_username, nextarg); |
| 1812 | break; |
| 1813 | |
| 1814 | case 'v': /* TLS password for proxy */ |
| 1815 | cleanarg(clearthis); |
| 1816 | if(!(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)) { |
| 1817 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1818 | } |
| 1819 | GetStr(&config->proxy_tls_password, nextarg); |
| 1820 | break; |
| 1821 | |
| 1822 | case 'w': /* TLS authentication type for proxy */ |
| 1823 | if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) { |
| 1824 | GetStr(&config->proxy_tls_authtype, nextarg); |
| 1825 | if(!curl_strequal(config->proxy_tls_authtype, "SRP")) |
| 1826 | return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */ |
| 1827 | } |
| 1828 | else |
| 1829 | return PARAM_LIBCURL_DOESNT_SUPPORT; |
| 1830 | break; |
| 1831 | |
| 1832 | case 'x': /* certificate file for proxy */ |
| 1833 | cleanarg(clearthis); |
| 1834 | GetFileAndPassword(nextarg, &config->proxy_cert, |
| 1835 | &config->proxy_key_passwd); |
| 1836 | break; |
| 1837 | |
| 1838 | case 'y': /* cert file type for proxy */ |
| 1839 | GetStr(&config->proxy_cert_type, nextarg); |
| 1840 | break; |
| 1841 | |
| 1842 | case 'z': /* private key file for proxy */ |
| 1843 | GetStr(&config->proxy_key, nextarg); |
| 1844 | break; |
| 1845 | |
| 1846 | case '0': /* private key file type for proxy */ |
| 1847 | GetStr(&config->proxy_key_type, nextarg); |
| 1848 | break; |
| 1849 | |
| 1850 | case '1': /* private key passphrase for proxy */ |
| 1851 | GetStr(&config->proxy_key_passwd, nextarg); |
| 1852 | cleanarg(clearthis); |
| 1853 | break; |
| 1854 | |
| 1855 | case '2': /* ciphers for proxy */ |
| 1856 | GetStr(&config->proxy_cipher_list, nextarg); |
| 1857 | break; |
| 1858 | |
| 1859 | case '3': /* CRL file for proxy */ |
| 1860 | GetStr(&config->proxy_crlfile, nextarg); |
| 1861 | break; |
| 1862 | |
| 1863 | case '4': /* no empty SSL fragments for proxy */ |
| 1864 | if(curlinfo->features & CURL_VERSION_SSL) |
| 1865 | config->proxy_ssl_allow_beast = toggle; |
| 1866 | break; |
| 1867 | |
| 1868 | case '5': /* --login-options */ |
| 1869 | GetStr(&config->login_options, nextarg); |
| 1870 | break; |
| 1871 | |
| 1872 | case '6': /* CA info PEM file for proxy */ |
| 1873 | GetStr(&config->proxy_cacert, nextarg); |
| 1874 | break; |
| 1875 | |
| 1876 | case '7': /* CA cert directory for proxy */ |
| 1877 | GetStr(&config->proxy_capath, nextarg); |
| 1878 | break; |
| 1879 | |
| 1880 | case '8': /* allow insecure SSL connects for proxy */ |
| 1881 | config->proxy_insecure_ok = toggle; |
| 1882 | break; |
| 1883 | |
| 1884 | case '9': /* --proxy-tlsv1 */ |
| 1885 | /* TLS version 1 for proxy */ |
| 1886 | config->proxy_ssl_version = CURL_SSLVERSION_TLSv1; |
| 1887 | break; |
| 1888 | |
| 1889 | case 'A': |
| 1890 | /* --socks5-basic */ |
| 1891 | if(toggle) |
| 1892 | config->socks5_auth |= CURLAUTH_BASIC; |
| 1893 | else |
| 1894 | config->socks5_auth &= ~CURLAUTH_BASIC; |
| 1895 | break; |
| 1896 | |
| 1897 | case 'B': |
| 1898 | /* --socks5-gssapi */ |
| 1899 | if(toggle) |
| 1900 | config->socks5_auth |= CURLAUTH_GSSAPI; |
| 1901 | else |
| 1902 | config->socks5_auth &= ~CURLAUTH_GSSAPI; |
| 1903 | break; |
| 1904 | |
| 1905 | case 'C': |
| 1906 | GetStr(&config->etag_save_file, nextarg); |
| 1907 | break; |
| 1908 | |
| 1909 | case 'D': |
| 1910 | GetStr(&config->etag_compare_file, nextarg); |
| 1911 | break; |
| 1912 | |
| 1913 | case 'E': |
| 1914 | GetStr(&config->ssl_ec_curves, nextarg); |
| 1915 | break; |
| 1916 | |
| 1917 | default: /* unknown flag */ |
| 1918 | return PARAM_OPTION_UNKNOWN; |
| 1919 | } |
| 1920 | break; |
| 1921 | case 'f': |
| 1922 | switch(subletter) { |
| 1923 | case 'a': /* --fail-early */ |
| 1924 | global->fail_early = toggle; |
| 1925 | break; |
| 1926 | case 'b': /* --styled-output */ |
| 1927 | global->styled_output = toggle; |
| 1928 | break; |
| 1929 | case 'c': /* --mail-rcpt-allowfails */ |
| 1930 | config->mail_rcpt_allowfails = toggle; |
| 1931 | break; |
| 1932 | case 'd': /* --fail-with-body */ |
| 1933 | config->failwithbody = toggle; |
| 1934 | break; |
| 1935 | case 'e': /* --remove-on-error */ |
| 1936 | config->rm_partial = toggle; |
| 1937 | break; |
| 1938 | default: /* --fail (hard on errors) */ |
| 1939 | config->failonerror = toggle; |
| 1940 | break; |
| 1941 | } |
| 1942 | if(config->failonerror && config->failwithbody) { |
| 1943 | errorf(config->global, "You must select either --fail or " |
| 1944 | "--fail-with-body, not both.\n"); |
| 1945 | return PARAM_BAD_USE; |
| 1946 | } |
| 1947 | break; |
| 1948 | case 'F': |
| 1949 | /* "form data" simulation, this is a little advanced so lets do our best |
| 1950 | to sort this out slowly and carefully */ |
| 1951 | if(formparse(config, |
| 1952 | nextarg, |
| 1953 | &config->mimeroot, |
| 1954 | &config->mimecurrent, |
| 1955 | (subletter == 's')?TRUE:FALSE)) /* 's' is literal string */ |
| 1956 | return PARAM_BAD_USE; |
| 1957 | if(SetHTTPrequest(config, HTTPREQ_MIMEPOST, &config->httpreq)) |
| 1958 | return PARAM_BAD_USE; |
| 1959 | break; |
| 1960 | |
| 1961 | case 'g': /* g disables URLglobbing */ |
| 1962 | config->globoff = toggle; |
| 1963 | break; |
| 1964 | |
| 1965 | case 'G': /* HTTP GET */ |
| 1966 | if(subletter == 'a') { /* --request-target */ |
| 1967 | GetStr(&config->request_target, nextarg); |
| 1968 | } |
| 1969 | else |
| 1970 | config->use_httpget = TRUE; |
| 1971 | break; |
| 1972 | |
| 1973 | case 'h': /* h for help */ |
| 1974 | if(toggle) { |
| 1975 | if(nextarg) { |
| 1976 | global->help_category = strdup(nextarg); |
| 1977 | if(!global->help_category) |
| 1978 | return PARAM_NO_MEM; |
| 1979 | } |
| 1980 | return PARAM_HELP_REQUESTED; |
| 1981 | } |
| 1982 | /* we now actually support --no-help too! */ |
| 1983 | break; |
| 1984 | case 'H': |
| 1985 | /* A custom header to append to a list */ |
| 1986 | if(nextarg[0] == '@') { |
| 1987 | /* read many headers from a file or stdin */ |
| 1988 | char *string; |
| 1989 | size_t len; |
| 1990 | bool use_stdin = !strcmp(&nextarg[1], "-"); |
| 1991 | FILE *file = use_stdin?stdin:fopen(&nextarg[1], FOPEN_READTEXT); |
| 1992 | if(!file) |
| 1993 | warnf(global, "Failed to open %s!\n", &nextarg[1]); |
| 1994 | else { |
| 1995 | err = file2memory(&string, &len, file); |
| 1996 | if(!err && string) { |
| 1997 | /* Allow strtok() here since this isn't used threaded */ |
| 1998 | /* !checksrc! disable BANNEDFUNC 2 */ |
| 1999 | char *h = strtok(string, "\r\n"); |
| 2000 | while(h) { |
| 2001 | if(subletter == 'p') /* --proxy-header */ |
| 2002 | err = add2list(&config->proxyheaders, h); |
| 2003 | else |
| 2004 | err = add2list(&config->headers, h); |
| 2005 | if(err) |
| 2006 | break; |
| 2007 | h = strtok(NULL, "\r\n"); |
| 2008 | } |
| 2009 | free(string); |
| 2010 | } |
| 2011 | if(!use_stdin) |
| 2012 | fclose(file); |
| 2013 | if(err) |
| 2014 | return err; |
| 2015 | } |
| 2016 | } |
| 2017 | else { |
| 2018 | if(subletter == 'p') /* --proxy-header */ |
| 2019 | err = add2list(&config->proxyheaders, nextarg); |
| 2020 | else |
| 2021 | err = add2list(&config->headers, nextarg); |
| 2022 | if(err) |
| 2023 | return err; |
| 2024 | } |
| 2025 | break; |
| 2026 | case 'i': |
| 2027 | config->show_headers = toggle; /* show the headers as well in the |
| 2028 | general output stream */ |
| 2029 | break; |
| 2030 | case 'j': |
| 2031 | config->cookiesession = toggle; |
| 2032 | break; |
| 2033 | case 'I': /* --head */ |
| 2034 | config->no_body = toggle; |
| 2035 | config->show_headers = toggle; |
| 2036 | if(SetHTTPrequest(config, |
| 2037 | (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET, |
| 2038 | &config->httpreq)) |
| 2039 | return PARAM_BAD_USE; |
| 2040 | break; |
| 2041 | case 'J': /* --remote-header-name */ |
| 2042 | config->content_disposition = toggle; |
| 2043 | break; |
| 2044 | case 'k': /* allow insecure SSL connects */ |
| 2045 | if(subletter == 'd') /* --doh-insecure */ |
| 2046 | config->doh_insecure_ok = toggle; |
| 2047 | else |
| 2048 | config->insecure_ok = toggle; |
| 2049 | break; |
| 2050 | case 'K': /* parse config file */ |
| 2051 | if(parseconfig(nextarg, global)) { |
| 2052 | errorf(global, "cannot read config from '%s'\n", nextarg); |
| 2053 | return PARAM_READ_ERROR; |
| 2054 | } |
| 2055 | break; |
| 2056 | case 'l': |
| 2057 | config->dirlistonly = toggle; /* only list the names of the FTP dir */ |
| 2058 | break; |
| 2059 | case 'L': |
| 2060 | config->followlocation = toggle; /* Follow Location: HTTP headers */ |
| 2061 | switch(subletter) { |
| 2062 | case 't': |
| 2063 | /* Continue to send authentication (user+password) when following |
| 2064 | * locations, even when hostname changed */ |
| 2065 | config->unrestricted_auth = toggle; |
| 2066 | break; |
| 2067 | } |
| 2068 | break; |
| 2069 | case 'm': |
| 2070 | /* specified max time */ |
| 2071 | err = str2udouble(&config->timeout, nextarg, (double)LONG_MAX/1000); |
| 2072 | if(err) |
| 2073 | return err; |
| 2074 | break; |
| 2075 | case 'M': /* M for manual, huge help */ |
| 2076 | if(toggle) { /* --no-manual shows no manual... */ |
| 2077 | #ifndef USE_MANUAL |
| 2078 | warnf(global, |
| 2079 | "built-in manual was disabled at build-time!\n"); |
| 2080 | #endif |
| 2081 | return PARAM_MANUAL_REQUESTED; |
| 2082 | } |
| 2083 | break; |
| 2084 | case 'n': |
| 2085 | switch(subletter) { |
| 2086 | case 'o': /* use .netrc or URL */ |
| 2087 | config->netrc_opt = toggle; |
| 2088 | break; |
| 2089 | case 'e': /* netrc-file */ |
| 2090 | GetStr(&config->netrc_file, nextarg); |
| 2091 | break; |
| 2092 | default: |
| 2093 | /* pick info from .netrc, if this is used for http, curl will |
| 2094 | automatically enforce user+password with the request */ |
| 2095 | config->netrc = toggle; |
| 2096 | break; |
| 2097 | } |
| 2098 | break; |
| 2099 | case 'N': |
| 2100 | /* disable the output I/O buffering. note that the option is called |
| 2101 | --buffer but is mostly used in the negative form: --no-buffer */ |
| 2102 | config->nobuffer = longopt ? !toggle : TRUE; |
| 2103 | break; |
| 2104 | case 'O': /* --remote-name */ |
| 2105 | if(subletter == 'a') { /* --remote-name-all */ |
| 2106 | config->default_node_flags = toggle?GETOUT_USEREMOTE:0; |
| 2107 | break; |
| 2108 | } |
| 2109 | else if(subletter == 'b') { /* --output-dir */ |
| 2110 | GetStr(&config->output_dir, nextarg); |
| 2111 | break; |
| 2112 | } |
| 2113 | else if(subletter == 'c') { /* --clobber / --no-clobber */ |
| 2114 | config->file_clobber_mode = toggle ? CLOBBER_ALWAYS : CLOBBER_NEVER; |
| 2115 | break; |
| 2116 | } |
| 2117 | /* FALLTHROUGH */ |
| 2118 | case 'o': /* --output */ |
| 2119 | /* output file */ |
| 2120 | { |
| 2121 | struct getout *url; |
| 2122 | if(!config->url_out) |
| 2123 | config->url_out = config->url_list; |
| 2124 | if(config->url_out) { |
| 2125 | /* there's a node here, if it already is filled-in continue to find |
| 2126 | an "empty" node */ |
| 2127 | while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE)) |
| 2128 | config->url_out = config->url_out->next; |
| 2129 | } |
| 2130 | |
| 2131 | /* now there might or might not be an available node to fill in! */ |
| 2132 | |
| 2133 | if(config->url_out) |
| 2134 | /* existing node */ |
| 2135 | url = config->url_out; |
| 2136 | else |
| 2137 | /* there was no free node, create one! */ |
| 2138 | config->url_out = url = new_getout(config); |
| 2139 | |
| 2140 | if(!url) |
| 2141 | return PARAM_NO_MEM; |
| 2142 | |
| 2143 | /* fill in the outfile */ |
| 2144 | if('o' == letter) { |
| 2145 | if(!*nextarg) { |
| 2146 | warnf(global, "output file name has no length\n"); |
| 2147 | return PARAM_BAD_USE; |
| 2148 | } |
| 2149 | GetStr(&url->outfile, nextarg); |
| 2150 | url->flags &= ~GETOUT_USEREMOTE; /* switch off */ |
| 2151 | } |
| 2152 | else { |
| 2153 | url->outfile = NULL; /* leave it */ |
| 2154 | if(toggle) |
| 2155 | url->flags |= GETOUT_USEREMOTE; /* switch on */ |
| 2156 | else |
| 2157 | url->flags &= ~GETOUT_USEREMOTE; /* switch off */ |
| 2158 | } |
| 2159 | url->flags |= GETOUT_OUTFILE; |
| 2160 | } |
| 2161 | break; |
| 2162 | case 'P': |
| 2163 | /* This makes the FTP sessions use PORT instead of PASV */ |
| 2164 | /* use <eth0> or <192.168.10.10> style addresses. Anything except |
| 2165 | this will make us try to get the "default" address. |
| 2166 | NOTE: this is a changed behavior since the released 4.1! |
| 2167 | */ |
| 2168 | GetStr(&config->ftpport, nextarg); |
| 2169 | break; |
| 2170 | case 'p': |
| 2171 | /* proxy tunnel for non-http protocols */ |
| 2172 | config->proxytunnel = toggle; |
| 2173 | break; |
| 2174 | |
| 2175 | case 'q': /* if used first, already taken care of, we do it like |
| 2176 | this so we don't cause an error! */ |
| 2177 | break; |
| 2178 | case 'Q': |
| 2179 | /* QUOTE command to send to FTP server */ |
| 2180 | switch(nextarg[0]) { |
| 2181 | case '-': |
| 2182 | /* prefixed with a dash makes it a POST TRANSFER one */ |
| 2183 | nextarg++; |
| 2184 | err = add2list(&config->postquote, nextarg); |
| 2185 | break; |
| 2186 | case '+': |
| 2187 | /* prefixed with a plus makes it a just-before-transfer one */ |
| 2188 | nextarg++; |
| 2189 | err = add2list(&config->prequote, nextarg); |
| 2190 | break; |
| 2191 | default: |
| 2192 | err = add2list(&config->quote, nextarg); |
| 2193 | break; |
| 2194 | } |
| 2195 | if(err) |
| 2196 | return err; |
| 2197 | break; |
| 2198 | case 'r': |
| 2199 | /* Specifying a range WITHOUT A DASH will create an illegal HTTP range |
| 2200 | (and won't actually be range by definition). The man page previously |
| 2201 | claimed that to be a good way, why this code is added to work-around |
| 2202 | it. */ |
| 2203 | if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) { |
| 2204 | char buffer[32]; |
| 2205 | curl_off_t off; |
| 2206 | if(curlx_strtoofft(nextarg, NULL, 10, &off)) { |
| 2207 | warnf(global, "unsupported range point\n"); |
| 2208 | return PARAM_BAD_USE; |
| 2209 | } |
| 2210 | warnf(global, |
| 2211 | "A specified range MUST include at least one dash (-). " |
| 2212 | "Appending one for you!\n"); |
| 2213 | msnprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off); |
| 2214 | Curl_safefree(config->range); |
| 2215 | config->range = strdup(buffer); |
| 2216 | if(!config->range) |
| 2217 | return PARAM_NO_MEM; |
| 2218 | } |
| 2219 | else { |
| 2220 | /* byte range requested */ |
| 2221 | const char *tmp_range = nextarg; |
| 2222 | while(*tmp_range != '\0') { |
| 2223 | if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') { |
| 2224 | warnf(global, "Invalid character is found in given range. " |
| 2225 | "A specified range MUST have only digits in " |
| 2226 | "\'start\'-\'stop\'. The server's response to this " |
| 2227 | "request is uncertain.\n"); |
| 2228 | break; |
| 2229 | } |
| 2230 | tmp_range++; |
| 2231 | } |
| 2232 | GetStr(&config->range, nextarg); |
| 2233 | } |
| 2234 | break; |
| 2235 | case 'R': |
| 2236 | /* use remote file's time */ |
| 2237 | config->remote_time = toggle; |
| 2238 | break; |
| 2239 | case 's': |
| 2240 | /* don't show progress meter, don't show errors : */ |
| 2241 | if(toggle) |
| 2242 | global->mute = global->noprogress = TRUE; |
| 2243 | else |
| 2244 | global->mute = global->noprogress = FALSE; |
| 2245 | if(global->showerror < 0) |
| 2246 | /* if still on the default value, set showerror to the reverse of |
| 2247 | toggle. This is to allow -S and -s to be used in an independent |
| 2248 | order but still have the same effect. */ |
| 2249 | global->showerror = (!toggle)?TRUE:FALSE; /* toggle off */ |
| 2250 | break; |
| 2251 | case 'S': |
| 2252 | /* show errors */ |
| 2253 | global->showerror = toggle?1:0; /* toggle on if used with -s */ |
| 2254 | break; |
| 2255 | case 't': |
| 2256 | /* Telnet options */ |
| 2257 | err = add2list(&config->telnet_options, nextarg); |
| 2258 | if(err) |
| 2259 | return err; |
| 2260 | break; |
| 2261 | case 'T': |
| 2262 | /* we are uploading */ |
| 2263 | { |
| 2264 | struct getout *url; |
| 2265 | if(!config->url_ul) |
| 2266 | config->url_ul = config->url_list; |
| 2267 | if(config->url_ul) { |
| 2268 | /* there's a node here, if it already is filled-in continue to find |
| 2269 | an "empty" node */ |
| 2270 | while(config->url_ul && (config->url_ul->flags & GETOUT_UPLOAD)) |
| 2271 | config->url_ul = config->url_ul->next; |
| 2272 | } |
| 2273 | |
| 2274 | /* now there might or might not be an available node to fill in! */ |
| 2275 | |
| 2276 | if(config->url_ul) |
| 2277 | /* existing node */ |
| 2278 | url = config->url_ul; |
| 2279 | else |
| 2280 | /* there was no free node, create one! */ |
| 2281 | config->url_ul = url = new_getout(config); |
| 2282 | |
| 2283 | if(!url) |
| 2284 | return PARAM_NO_MEM; |
| 2285 | |
| 2286 | url->flags |= GETOUT_UPLOAD; /* mark -T used */ |
| 2287 | if(!*nextarg) |
| 2288 | url->flags |= GETOUT_NOUPLOAD; |
| 2289 | else { |
| 2290 | /* "-" equals stdin, but keep the string around for now */ |
| 2291 | GetStr(&url->infile, nextarg); |
| 2292 | } |
| 2293 | } |
| 2294 | break; |
| 2295 | case 'u': |
| 2296 | /* user:password */ |
| 2297 | GetStr(&config->userpwd, nextarg); |
| 2298 | cleanarg(clearthis); |
| 2299 | break; |
| 2300 | case 'U': |
| 2301 | /* Proxy user:password */ |
| 2302 | GetStr(&config->proxyuserpwd, nextarg); |
| 2303 | cleanarg(clearthis); |
| 2304 | break; |
| 2305 | case 'v': |
| 2306 | if(toggle) { |
| 2307 | /* the '%' thing here will cause the trace get sent to stderr */ |
| 2308 | Curl_safefree(global->trace_dump); |
| 2309 | global->trace_dump = strdup("%"); |
| 2310 | if(!global->trace_dump) |
| 2311 | return PARAM_NO_MEM; |
| 2312 | if(global->tracetype && (global->tracetype != TRACE_PLAIN)) |
| 2313 | warnf(global, |
| 2314 | "-v, --verbose overrides an earlier trace/verbose option\n"); |
| 2315 | global->tracetype = TRACE_PLAIN; |
| 2316 | } |
| 2317 | else |
| 2318 | /* verbose is disabled here */ |
| 2319 | global->tracetype = TRACE_NONE; |
| 2320 | break; |
| 2321 | case 'V': |
| 2322 | if(toggle) /* --no-version yields no output! */ |
| 2323 | return PARAM_VERSION_INFO_REQUESTED; |
| 2324 | break; |
| 2325 | |
| 2326 | case 'w': |
| 2327 | /* get the output string */ |
| 2328 | if('@' == *nextarg) { |
| 2329 | /* the data begins with a '@' letter, it means that a file name |
| 2330 | or - (stdin) follows */ |
| 2331 | FILE *file; |
| 2332 | const char *fname; |
| 2333 | nextarg++; /* pass the @ */ |
| 2334 | if(!strcmp("-", nextarg)) { |
| 2335 | fname = "<stdin>"; |
| 2336 | file = stdin; |
| 2337 | } |
| 2338 | else { |
| 2339 | fname = nextarg; |
| 2340 | file = fopen(nextarg, FOPEN_READTEXT); |
| 2341 | } |
| 2342 | Curl_safefree(config->writeout); |
| 2343 | err = file2string(&config->writeout, file); |
| 2344 | if(file && (file != stdin)) |
| 2345 | fclose(file); |
| 2346 | if(err) |
| 2347 | return err; |
| 2348 | if(!config->writeout) |
| 2349 | warnf(global, "Failed to read %s", fname); |
| 2350 | } |
| 2351 | else |
| 2352 | GetStr(&config->writeout, nextarg); |
| 2353 | break; |
| 2354 | case 'x': |
| 2355 | switch(subletter) { |
| 2356 | case 'a': /* --preproxy */ |
| 2357 | GetStr(&config->preproxy, nextarg); |
| 2358 | break; |
| 2359 | default: |
| 2360 | /* --proxy */ |
| 2361 | GetStr(&config->proxy, nextarg); |
| 2362 | config->proxyver = CURLPROXY_HTTP; |
| 2363 | break; |
| 2364 | } |
| 2365 | break; |
| 2366 | case 'X': |
| 2367 | /* set custom request */ |
| 2368 | GetStr(&config->customrequest, nextarg); |
| 2369 | break; |
| 2370 | case 'y': |
| 2371 | /* low speed time */ |
| 2372 | err = str2unum(&config->low_speed_time, nextarg); |
| 2373 | if(err) |
| 2374 | return err; |
| 2375 | if(!config->low_speed_limit) |
| 2376 | config->low_speed_limit = 1; |
| 2377 | break; |
| 2378 | case 'Y': |
| 2379 | /* low speed limit */ |
| 2380 | err = str2unum(&config->low_speed_limit, nextarg); |
| 2381 | if(err) |
| 2382 | return err; |
| 2383 | if(!config->low_speed_time) |
| 2384 | config->low_speed_time = 30; |
| 2385 | break; |
| 2386 | case 'Z': |
| 2387 | switch(subletter) { |
| 2388 | case '\0': /* --parallel */ |
| 2389 | global->parallel = toggle; |
| 2390 | break; |
| 2391 | case 'b': /* --parallel-max */ |
| 2392 | err = str2unum(&global->parallel_max, nextarg); |
| 2393 | if(err) |
| 2394 | return err; |
| 2395 | if(global->parallel_max > MAX_PARALLEL) |
| 2396 | global->parallel_max = MAX_PARALLEL; |
| 2397 | else if(global->parallel_max < 1) |
| 2398 | global->parallel_max = PARALLEL_DEFAULT; |
| 2399 | break; |
| 2400 | case 'c': /* --parallel-connect */ |
| 2401 | global->parallel_connect = toggle; |
| 2402 | break; |
| 2403 | } |
| 2404 | break; |
| 2405 | case 'z': /* time condition coming up */ |
| 2406 | switch(*nextarg) { |
| 2407 | case '+': |
| 2408 | nextarg++; |
| 2409 | /* FALLTHROUGH */ |
| 2410 | default: |
| 2411 | /* If-Modified-Since: (section 14.28 in RFC2068) */ |
| 2412 | config->timecond = CURL_TIMECOND_IFMODSINCE; |
| 2413 | break; |
| 2414 | case '-': |
| 2415 | /* If-Unmodified-Since: (section 14.24 in RFC2068) */ |
| 2416 | config->timecond = CURL_TIMECOND_IFUNMODSINCE; |
| 2417 | nextarg++; |
| 2418 | break; |
| 2419 | case '=': |
| 2420 | /* Last-Modified: (section 14.29 in RFC2068) */ |
| 2421 | config->timecond = CURL_TIMECOND_LASTMOD; |
| 2422 | nextarg++; |
| 2423 | break; |
| 2424 | } |
| 2425 | now = time(NULL); |
| 2426 | config->condtime = (curl_off_t)curl_getdate(nextarg, &now); |
| 2427 | if(-1 == config->condtime) { |
| 2428 | /* now let's see if it is a file name to get the time from instead! */ |
| 2429 | curl_off_t filetime = getfiletime(nextarg, global); |
| 2430 | if(filetime >= 0) { |
| 2431 | /* pull the time out from the file */ |
| 2432 | config->condtime = filetime; |
| 2433 | } |
| 2434 | else { |
| 2435 | /* failed, remove time condition */ |
| 2436 | config->timecond = CURL_TIMECOND_NONE; |
| 2437 | warnf(global, |
| 2438 | "Illegal date format for -z, --time-cond (and not " |
| 2439 | "a file name). Disabling time condition. " |
| 2440 | "See curl_getdate(3) for valid date syntax.\n"); |
| 2441 | } |
| 2442 | } |
| 2443 | break; |
| 2444 | default: /* unknown flag */ |
| 2445 | return PARAM_OPTION_UNKNOWN; |
| 2446 | } |
| 2447 | hit = -1; |
| 2448 | |
| 2449 | } while(!longopt && !singleopt && *++parse && !*usedarg); |
| 2450 | |
| 2451 | return PARAM_OK; |
| 2452 | } |
| 2453 | |
| 2454 | ParameterError parse_args(struct GlobalConfig *global, int argc, |
| 2455 | argv_item_t argv[]) |
| 2456 | { |
| 2457 | int i; |
| 2458 | bool stillflags; |
| 2459 | char *orig_opt = NULL; |
| 2460 | ParameterError result = PARAM_OK; |
| 2461 | struct OperationConfig *config = global->first; |
| 2462 | |
| 2463 | for(i = 1, stillflags = TRUE; i < argc && !result; i++) { |
| 2464 | orig_opt = curlx_convert_tchar_to_UTF8(argv[i]); |
| 2465 | if(!orig_opt) |
| 2466 | return PARAM_NO_MEM; |
| 2467 | |
| 2468 | if(stillflags && ('-' == orig_opt[0])) { |
| 2469 | bool passarg; |
| 2470 | |
| 2471 | if(!strcmp("--", orig_opt)) |
| 2472 | /* This indicates the end of the flags and thus enables the |
| 2473 | following (URL) argument to start with -. */ |
| 2474 | stillflags = FALSE; |
| 2475 | else { |
| 2476 | char *nextarg = NULL; |
| 2477 | if(i < (argc - 1)) { |
| 2478 | nextarg = curlx_convert_tchar_to_UTF8(argv[i + 1]); |
| 2479 | if(!nextarg) { |
| 2480 | curlx_unicodefree(orig_opt); |
| 2481 | return PARAM_NO_MEM; |
| 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | result = getparameter(orig_opt, nextarg, &passarg, |
| 2486 | global, config); |
| 2487 | |
| 2488 | curlx_unicodefree(nextarg); |
| 2489 | config = global->last; |
| 2490 | if(result == PARAM_NEXT_OPERATION) { |
| 2491 | /* Reset result as PARAM_NEXT_OPERATION is only used here and not |
| 2492 | returned from this function */ |
| 2493 | result = PARAM_OK; |
| 2494 | |
| 2495 | if(config->url_list && config->url_list->url) { |
| 2496 | /* Allocate the next config */ |
| 2497 | config->next = malloc(sizeof(struct OperationConfig)); |
| 2498 | if(config->next) { |
| 2499 | /* Initialise the newly created config */ |
| 2500 | config_init(config->next); |
| 2501 | |
| 2502 | /* Set the global config pointer */ |
| 2503 | config->next->global = global; |
| 2504 | |
| 2505 | /* Update the last config pointer */ |
| 2506 | global->last = config->next; |
| 2507 | |
| 2508 | /* Move onto the new config */ |
| 2509 | config->next->prev = config; |
| 2510 | config = config->next; |
| 2511 | } |
| 2512 | else |
| 2513 | result = PARAM_NO_MEM; |
| 2514 | } |
| 2515 | } |
| 2516 | else if(!result && passarg) |
| 2517 | i++; /* we're supposed to skip this */ |
| 2518 | } |
| 2519 | } |
| 2520 | else { |
| 2521 | bool used; |
| 2522 | |
| 2523 | /* Just add the URL please */ |
| 2524 | result = getparameter("--url", orig_opt, &used, global, config); |
| 2525 | } |
| 2526 | |
| 2527 | if(!result) |
| 2528 | curlx_unicodefree(orig_opt); |
| 2529 | } |
| 2530 | |
| 2531 | if(!result && config->content_disposition) { |
| 2532 | if(config->show_headers) |
| 2533 | result = PARAM_CONTDISP_SHOW_HEADER; |
| 2534 | else if(config->resume_from_current) |
| 2535 | result = PARAM_CONTDISP_RESUME_FROM; |
| 2536 | } |
| 2537 | |
| 2538 | if(result && result != PARAM_HELP_REQUESTED && |
| 2539 | result != PARAM_MANUAL_REQUESTED && |
| 2540 | result != PARAM_VERSION_INFO_REQUESTED && |
| 2541 | result != PARAM_ENGINES_REQUESTED) { |
| 2542 | const char *reason = param2text(result); |
| 2543 | |
| 2544 | if(orig_opt && strcmp(":", orig_opt)) |
| 2545 | helpf(global->errors, "option %s: %s\n", orig_opt, reason); |
| 2546 | else |
| 2547 | helpf(global->errors, "%s\n", reason); |
| 2548 | } |
| 2549 | |
| 2550 | curlx_unicodefree(orig_opt); |
| 2551 | return result; |
| 2552 | } |