]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
netrc: check %USERPROFILE% as well on Windows
authorWolf Vollprecht <w.vollprecht@gmail.com>
Thu, 2 Jun 2022 07:30:52 +0000 (09:30 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 2 Jun 2022 07:32:51 +0000 (09:32 +0200)
Closes #8855

docs/libcurl/libcurl-env.3
docs/libcurl/libcurl-tutorial.3
docs/libcurl/opts/CURLOPT_NETRC.3
lib/netrc.c

index a33faada9121278ef13a17c3f6f81bf020bef5c9..ad79702aad19bf973a653181a54c788ef669d201 100644 (file)
@@ -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
index 801aea026199cd6a783df864334ebad97188f04f..7bd9c68bab0a7af24a80b08bec39be77bc18315d 100644 (file)
@@ -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
index 993688c895a48048a4b7d273e7ac836484f5306d..738f7526bead9d3bb3efe81e99e6c05d9a6b9053 100644 (file)
@@ -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
index 67aa6a62a48a9c9118e68f21c86f85251a70ad51..2935be0c7110aa0b0f94eea366534defbdd9f7c1 100644 (file)
@@ -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
     }