From: Wolf Vollprecht Date: Thu, 2 Jun 2022 07:30:52 +0000 (+0200) Subject: netrc: check %USERPROFILE% as well on Windows X-Git-Tag: curl-7_84_0~94 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4d4eb8e587a23e565e3886b56ef6c9b471fc91a3;p=thirdparty%2Fcurl.git netrc: check %USERPROFILE% as well on Windows Closes #8855 --- diff --git a/docs/libcurl/libcurl-env.3 b/docs/libcurl/libcurl-env.3 index a33faada91..ad79702aad 100644 --- a/docs/libcurl/libcurl-env.3 +++ b/docs/libcurl/libcurl-env.3 @@ -54,6 +54,10 @@ nss, openssl, rustls, schannel, secure-transport, wolfssl When the netrc feature is used (\fICURLOPT_NETRC(3)\fP), this variable is checked as the primary way to find the "current" home directory in which the .netrc file is likely to exist. +.IP USERPROFILE +When the netrc feature is used (\fICURLOPT_NETRC(3)\fP), this variable is +checked as the secondary way to find the "current" home directory (on Windows +only) in which the .netrc file is likely to exist. .IP LOGNAME User name to use when invoking the ntlm-wb tool, if NTLMUSER was not set. .IP NO_PROXY diff --git a/docs/libcurl/libcurl-tutorial.3 b/docs/libcurl/libcurl-tutorial.3 index 801aea0261..7bd9c68bab 100644 --- a/docs/libcurl/libcurl-tutorial.3 +++ b/docs/libcurl/libcurl-tutorial.3 @@ -361,9 +361,11 @@ similar to the \fICURLOPT_USERPWD(3)\fP option like this: curl_easy_setopt(easyhandle, CURLOPT_PROXYUSERPWD, "myname:thesecret"); There's a long time Unix "standard" way of storing FTP user names and -passwords, namely in the $HOME/.netrc file. The file should be made private -so that only the user may read it (see also the "Security Considerations" -chapter), as it might contain the password in plain text. libcurl has the +passwords, namely in the $HOME/.netrc file (on Windows, libcurl also checks +the %USERPROFILE% environment variable if %HOME% is unset, and tries +_netrc as name). The file should be made private so that only the user may +read it (see also the "Security Considerations" chapter), +as it might contain the password in plain text. libcurl has the ability to use this file to figure out what set of user name and password to use for a particular host. As an extension to the normal functionality, libcurl also supports this file for non-FTP protocols such as HTTP. To make diff --git a/docs/libcurl/opts/CURLOPT_NETRC.3 b/docs/libcurl/opts/CURLOPT_NETRC.3 index 993688c895..738f7526be 100644 --- a/docs/libcurl/opts/CURLOPT_NETRC.3 +++ b/docs/libcurl/opts/CURLOPT_NETRC.3 @@ -32,9 +32,13 @@ CURLcode curl_easy_setopt(CURL *handle, CURLOPT_NETRC, long level); .SH DESCRIPTION This parameter controls the preference \fIlevel\fP of libcurl between using user names and passwords from your \fI~/.netrc\fP file, relative to user names -and passwords in the URL supplied with \fICURLOPT_URL(3)\fP. On Windows, -libcurl will use the file as \fI%HOME%/_netrc\fP, but you can also tell -libcurl a different file name to use with \fICURLOPT_NETRC_FILE(3)\fP. +and passwords in the URL supplied with \fICURLOPT_URL(3)\fP. + +On Windows, libcurl will use the file as \fI%HOME%/_netrc\fP. If \fI%HOME%\fP +is not set on Windows, libcurl falls back to \fI%USERPROFILE%\fP. + +You can also tell libcurl a different file name to use with +\fICURLOPT_NETRC_FILE(3)\fP. libcurl uses a user name (and supplied or prompted password) supplied with \fICURLOPT_USERPWD(3)\fP or \fICURLOPT_USERNAME(3)\fP in preference to any of diff --git a/lib/netrc.c b/lib/netrc.c index 67aa6a62a4..2935be0c71 100644 --- a/lib/netrc.c +++ b/lib/netrc.c @@ -313,6 +313,13 @@ int Curl_parsenetrc(const char *host, if(pw) { home = pw->pw_dir; } +#elif defined(_WIN32) + } + else { + homea = curl_getenv("USERPROFILE"); + if(homea) { + home = homea; + } #endif }