creds: hold credentials

Authorizdation credentials are kept in `struct Curl_creds`. This contains:

* `user`: the username, maybe the empty string
* `passwd`: the password, maybe the empty string
* `sasl_authzid`: the SASL authz value, maybe the empty string
* `oauth_bearer`: the OAUTH bearer token, maybe the empty string
* `source`: where the credentials from from
* `refcount`: a reference counter to link/unkink creds

A `creds` with all values empty is equivalent to NULL, e.g. no `creds`
instance. With reference counting, `creds` can be linked/unlinked
in several places.

See docs/internals/CREDENTIALS.md for use.

Closes #21548
This commit is contained in:
Stefan Eissing 2026-05-11 14:25:52 +02:00 committed by Daniel Stenberg
parent a32a2b0b77
commit 8f71d0fde5
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
47 changed files with 1138 additions and 962 deletions

View file

@ -77,8 +77,7 @@ CURLcode Curl_output_digest(struct Curl_easy *data,
char **allocuserpwd;
/* Point to the name and password for this */
const char *userp;
const char *passwdp;
struct Curl_creds *creds = NULL;
/* Point to the correct struct with this */
struct digestdata *digest;
@ -90,28 +89,19 @@ CURLcode Curl_output_digest(struct Curl_easy *data,
#else
digest = &data->state.proxydigest;
allocuserpwd = &data->req.hd_proxy_auth;
userp = data->state.aptr.proxyuser;
passwdp = data->state.aptr.proxypasswd;
creds = data->conn->http_proxy.creds;
authp = &data->state.authproxy;
#endif
}
else {
digest = &data->state.digest;
allocuserpwd = &data->req.hd_auth;
userp = data->state.aptr.user;
passwdp = data->state.aptr.passwd;
creds = data->state.creds;
authp = &data->state.authhost;
}
curlx_safefree(*allocuserpwd);
/* not set means empty */
if(!userp)
userp = "";
if(!passwdp)
passwdp = "";
#ifdef USE_WINDOWS_SSPI
have_chlg = !!digest->input_token;
#else
@ -123,8 +113,8 @@ CURLcode Curl_output_digest(struct Curl_easy *data,
return CURLE_OK;
}
result = Curl_auth_create_digest_http_message(data, userp, passwdp,
request, uripath, digest,
result = Curl_auth_create_digest_http_message(data, creds, request,
uripath, digest,
&response, &len);
if(result)
return result;