pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/curl/curl/pull/22196

dia="all" rel="stylesheet" href="https://github.githubassets.com/assets/pull-requests-be6017ec12798e73.css" /> ldap: support empty username and password by jay · Pull Request #22196 · curl/curl · GitHub
Skip to content

ldap: support empty username and password - #22196

Open
jay wants to merge 1 commit into
curl:masterfrom
jay:ldap_allow_empty_userpass
Open

ldap: support empty username and password#22196
jay wants to merge 1 commit into
curl:masterfrom
jay:ldap_allow_empty_userpass

Conversation

@jay

@jay jay commented Jun 26, 2026

Copy link
Copy Markdown
Member

Prior to this change an empty username or password was passed to the LDAP bind function as NULL instead of an empty string.

Regression since 8f71d0f.

Reported-by: Yoshiro Yoneya

Fixes #22162
Closes #xxxx

@jay

jay commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

I'm not entirely sure my use of Curl_creds_user/passwd was correct because if credentials doesn't exist then an empty username and password would be used. But if there are no credentials, then the user didn't specify an empty user pass right?

curl/lib/creds.h

Lines 80 to 81 in 68720b4

#define Curl_creds_user(c) ((c) ? (c)->user : "")
#define Curl_creds_passwd(c) ((c) ? (c)->passwd : "")

To really get the old behavior there doesn't seem to be a macro for that, so I'm changing my proposal:

diff --git a/lib/ldap.c b/lib/ldap.c
index e385245..ae12727 100644
--- a/lib/ldap.c
+++ b/lib/ldap.c
@@ -282,8 +282,8 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done)
 #else
   char *host = NULL;
 #endif
-  const char *user = Curl_creds_user(data->state.creds);
-  const char *passwd = Curl_creds_passwd(data->state.creds);
+  const char *user = data->state.creds ? data->state.creds->user : NULL;
+  const char *passwd = data->state.creds ? data->state.creds->passwd : NULL;
   struct ip_quadruple ipquad;
   bool is_ipv6;
   BerElement *ber = NULL;

@icing

icing commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Originally, the was how Curl_creds was supposed to work, yes. But that broke -u : spnego/negotiate backward compat. So now, Curl_creds do exist with empty username and password.

It's a funny world...

I'll update CREDS.md that still describes the old behaviour.

Comment thread lib/ldap.c
data->state.creds->user : NULL;
const char *passwd = Curl_creds_has_passwd(data->state.creds) ?
data->state.creds->passwd : NULL;
const char *user = data->state.creds ? data->state.creds->user : NULL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, user is alwas passed to ldap_win_bind() and the reporter says that passing NULL does not work. (probably the reason why they use -u : in the first place?

Maybe always using Curl_creds_user() is best here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe always using Curl_creds_user() is best here?

Ref: https://github.com/curl/curl/blob/curl-8_21_0/lib/ldap.c#L153-L231

For Windows native LDAP builds of curl the behavior of the NULL, NULL seems to be dependent on whether or not it was also built with Windows SSPI support. If it was then the NULL, NULL will cause the current user's Windows credentials to be used:

curl/lib/ldap.c

Lines 197 to 201 in 68720b4

else {
/* proceed with current user credentials */
method = LDAP_AUTH_NEGOTIATE;
rc = ldap_bind_s(server, NULL, NULL, method);
}

I think we'd have to keep the old behavior and not use Curl_creds_user, since if there is no creds struct then we'd still want to pass on NULL to get to that block?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever works. You have a better idea of this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the behavior is not entirely correct for the SSPI case but it would need a different fix. My plan is this PR would restore the old behavior and then I'd fix the -u : case for SSPI with some auth (negotiate, etc) separately. It's a little more complicated than I thought, see #22230

Prior to this change an empty username or password was passed to the
LDAP bind function as NULL instead of an empty string.

Regression since 8f71d0f.

Reported-by: Yoshiro Yoneya

Fixes curl#22162
Closes #xxxx
@jay
jay force-pushed the ldap_allow_empty_userpass branch from 5373059 to 9466b72 Compare July 1, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

can't specify empty username/password to ldap server

2 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy