curl: Added --netrc-file.

This enables people to specify a path to the netrc file to use.
The new option override --netrc if both are present. However it
does follow --netrc-optional if specified.
This commit is contained in:
Julien Chaffraix
2011-02-20 21:10:03 -08:00
parent c4369f34b9
commit 06fc3569d2
2 changed files with 23 additions and 1 deletions

View File

@@ -815,6 +815,17 @@ to FTP to the machine host.domain.com with user name \&'myself' and password
.IP "--netrc-optional" .IP "--netrc-optional"
Very similar to \fI--netrc\fP, but this option makes the .netrc usage Very similar to \fI--netrc\fP, but this option makes the .netrc usage
\fBoptional\fP and not mandatory as the \fI--netrc\fP option does. \fBoptional\fP and not mandatory as the \fI--netrc\fP option does.
.IP "--netrc-file"
This option is similar to \fI--netrc\fP, except that you provide the path
(absolute or relative) to the netrc file that Curl should use.
You can only specify one netrc file per invocation. If several
\fI--netrc-file\fP options are provided, only the \fBlast one\fP will be used.
(Added in 7.21.5)
This option overrides any use of \fI--netrc\fP as they are mutually exclusive.
It will also abide by --netrc-optional if specified.
.IP "--negotiate" .IP "--negotiate"
(HTTP) Enables GSS-Negotiate authentication. The GSS-Negotiate method was (HTTP) Enables GSS-Negotiate authentication. The GSS-Negotiate method was
designed by Microsoft and is used in their web applications. It is primarily designed by Microsoft and is used in their web applications. It is primarily

View File

@@ -527,6 +527,7 @@ struct Configurable {
changed */ changed */
bool netrc_opt; bool netrc_opt;
bool netrc; bool netrc;
char *netrc_file;
bool noprogress; bool noprogress;
bool isatty; /* updated internally only if the output is a tty */ bool isatty; /* updated internally only if the output is a tty */
struct getout *url_list; /* point to the first node */ struct getout *url_list; /* point to the first node */
@@ -842,6 +843,7 @@ static void help(void)
" --negotiate Use HTTP Negotiate Authentication (H)", " --negotiate Use HTTP Negotiate Authentication (H)",
" -n/--netrc Must read .netrc for user name and password", " -n/--netrc Must read .netrc for user name and password",
" --netrc-optional Use either .netrc or URL; overrides -n", " --netrc-optional Use either .netrc or URL; overrides -n",
" --netrc-file <file> Set up the netrc filename to use",
" -N/--no-buffer Disable buffering of the output stream", " -N/--no-buffer Disable buffering of the output stream",
" --no-keepalive Disable keepalive use on the connection", " --no-keepalive Disable keepalive use on the connection",
" --no-sessionid Disable SSL session-ID reusing (SSL)", " --no-sessionid Disable SSL session-ID reusing (SSL)",
@@ -1949,6 +1951,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
{"M", "manual", FALSE}, {"M", "manual", FALSE},
{"n", "netrc", FALSE}, {"n", "netrc", FALSE},
{"no", "netrc-optional", FALSE}, {"no", "netrc-optional", FALSE},
{"ne", "netrc-file", TRUE},
{"N", "buffer", FALSE}, /* listed as --no-buffer in the help */ {"N", "buffer", FALSE}, /* listed as --no-buffer in the help */
{"o", "output", TRUE}, {"o", "output", TRUE},
{"O", "remote-name", FALSE}, {"O", "remote-name", FALSE},
@@ -2915,6 +2918,9 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
/* use .netrc or URL */ /* use .netrc or URL */
config->netrc_opt = toggle; config->netrc_opt = toggle;
break; break;
case 'e': /* netrc-file */
GetStr(&config->netrc_file, nextarg);
break;
default: default:
/* pick info from .netrc, if this is used for http, curl will /* pick info from .netrc, if this is used for http, curl will
automatically enfore user+password with the request */ automatically enfore user+password with the request */
@@ -4047,6 +4053,8 @@ static void free_config_fields(struct Configurable *config)
free(config->writeout); free(config->writeout);
if(config->httppost) if(config->httppost)
curl_formfree(config->httppost); curl_formfree(config->httppost);
if(config->netrc_file)
free(config->netrc_file);
if(config->cert) if(config->cert)
free(config->cert); free(config->cert);
if(config->cacert) if(config->cacert)
@@ -5183,11 +5191,14 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
if(config->netrc_opt) if(config->netrc_opt)
my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
else if(config->netrc) else if(config->netrc || config->netrc_file)
my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED); my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
else else
my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_IGNORED); my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_IGNORED);
if(config->netrc_file)
my_setopt(curl, CURLOPT_NETRC_FILE, config->netrc_file);
my_setopt(curl, CURLOPT_FOLLOWLOCATION, config->followlocation); my_setopt(curl, CURLOPT_FOLLOWLOCATION, config->followlocation);
my_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, config->unrestricted_auth); my_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, config->unrestricted_auth);
my_setopt(curl, CURLOPT_TRANSFERTEXT, config->use_ascii); my_setopt(curl, CURLOPT_TRANSFERTEXT, config->use_ascii);