summaryrefslogtreecommitdiff
path: root/lib/url.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2022-01-07 17:44:42 +0100
committerDaniel Stenberg <daniel@haxx.se>2022-01-08 15:03:47 +0100
commit3ffca6c903e706a4ffe08ca3168c3521cf51d127 (patch)
tree047aee8d3ee44a401cb8ee9781eb37ed70e2a5a8 /lib/url.c
parent4936e60bb961e6ad7385bd25646e3acd0922f33f (diff)
downloadcurl-3ffca6c903e706a4ffe08ca3168c3521cf51d127.tar.gz
url: given a user in the URL, find pwd for that user in netrcbagder/netrc-user
Add test 380 and 381 to verify, edited test 133 Reported-by: Manfred Schwarb Fixes #8241 Closes #8243
Diffstat (limited to 'lib/url.c')
-rw-r--r--lib/url.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/lib/url.c b/lib/url.c
index 9f1013554..469912272 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2942,6 +2942,13 @@ static CURLcode override_login(struct Curl_easy *data,
bool netrc_user_changed = FALSE;
bool netrc_passwd_changed = FALSE;
int ret;
+ bool url_provided = FALSE;
+
+ if(data->state.up.user) {
+ /* there was a user name in the URL */
+ userp = &data->state.up.user;
+ url_provided = TRUE;
+ }
ret = Curl_parsenetrc(conn->host.name,
userp, passwdp,
@@ -2961,27 +2968,36 @@ static CURLcode override_login(struct Curl_easy *data,
conn->bits.netrc = TRUE;
conn->bits.user_passwd = TRUE; /* enable user+password */
}
+ if(url_provided) {
+ Curl_safefree(conn->user);
+ conn->user = strdup(*userp);
+ if(!conn->user)
+ return CURLE_OUT_OF_MEMORY;
+ /* don't update the user name below */
+ userp = NULL;
+ }
}
#endif
/* for updated strings, we update them in the URL */
- if(*userp) {
- CURLcode result = Curl_setstropt(&data->state.aptr.user, *userp);
- if(result)
- return result;
- }
- if(data->state.aptr.user) {
- uc = curl_url_set(data->state.uh, CURLUPART_USER, data->state.aptr.user,
- CURLU_URLENCODE);
- if(uc)
- return Curl_uc_to_curlcode(uc);
- if(!*userp) {
- *userp = strdup(data->state.aptr.user);
- if(!*userp)
- return CURLE_OUT_OF_MEMORY;
+ if(userp) {
+ if(*userp) {
+ CURLcode result = Curl_setstropt(&data->state.aptr.user, *userp);
+ if(result)
+ return result;
+ }
+ if(data->state.aptr.user) {
+ uc = curl_url_set(data->state.uh, CURLUPART_USER, data->state.aptr.user,
+ CURLU_URLENCODE);
+ if(uc)
+ return Curl_uc_to_curlcode(uc);
+ if(!*userp) {
+ *userp = strdup(data->state.aptr.user);
+ if(!*userp)
+ return CURLE_OUT_OF_MEMORY;
+ }
}
}
-
if(*passwdp) {
CURLcode result = Curl_setstropt(&data->state.aptr.passwd, *passwdp);
if(result)