url: given a user in the URL, find pwd for that user in netrc

Add test 380 and 381 to verify, edited test 133

Reported-by: Manfred Schwarb
Fixes #8241
Closes #8243
This commit is contained in:
Daniel Stenberg 2022-01-07 17:44:42 +01:00
parent 919baa5802
commit d1237ac906
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 179 additions and 36 deletions

View file

@ -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)