1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-06-25 21:37:58 +02:00

dirmngr: Use wrapper function for Windows LDAP peculiarities.

* dirmngr/ks-engine-ldap.c (my_ldap_return_with_check): New.
(my_ldap_parse_result): New.
(my_ldap_parse_page_control): New.
(search_and_parse): Use the wrappers.
--

Updates-commit: b3dc2305e1ca92dfd75c701cca2fb90832abf7e3
This commit is contained in:
Werner Koch 2025-06-24 13:33:31 +02:00
parent b3dc2305e1
commit a354018bf3
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -154,6 +154,9 @@ epoch2ldaptime (time_t stamp)
#endif
/*
* Begin LDAP wrappers
*/
static void
my_ldap_value_free (char **vals)
{
@ -162,6 +165,66 @@ my_ldap_value_free (char **vals)
}
/* LDAP wrappers to cope with the stupid use of ULONG instead of int in
* the Windows LDAP interface. rfc1823 alsways uses int and thus
* ldap_parse_result should also do this. */
#ifdef HAVE_W32_SYSTEM
static int
my_ldap_return_with_check (ULONG l_err)
{
if ((int)l_err < 0)
{
log_error ("oops: LDAP returned a negative error code (0x%lx)\n", l_err);
l_err = LDAP_OTHER;
}
return (int)l_err;
}
#endif
static int
my_ldap_parse_result (LDAP *ld, LDAPMessage *result,
int *errcodep, char **matcheddnp, char **errmsgp,
char ***referralsp, LDAPControl ***serverctrlsp,
int freeit)
{
#ifdef HAVE_W32_SYSTEM
ULONG l_err;
ULONG l_errcode;
l_err = ldap_parse_result (ld, result,
errcodep? &l_errcode : NULL,
matcheddnp, errmsgp,
referralsp, serverctrlsp, freeit);
if (errcodep)
*errcodep = l_errcode;
return my_ldap_return_with_check (l_err);
#else
return ldap_parse_result (ld, result, errcodep, matcheddnp, errmsgp,
referralsp, serverctrlsp, freeit);
#endif
}
static int
my_ldap_parse_page_control (LDAP *ld, LDAPControl **ctrls,
int *count, struct berval **cookie)
{
#ifdef HAVE_W32_SYSTEM
ULONG l_err;
ULONG l_count;
l_err = ldap_parse_page_control (ld, ctrls, count? &l_count: NULL, cookie);
if (count)
*count = l_count;
return my_ldap_return_with_check (l_err);
#else
return ldap_parse_page_control (ld, ctrls, count, cookie);
#endif
}
/*
* End LDAP wrappers
*/
/* Print a description of supported variables. */
void
ks_ldap_help_variables (ctrl_t ctrl)
@ -1357,13 +1420,8 @@ search_and_parse (ctrl_t ctrl, const char *keyspec,
{
gpg_error_t err = 0;
int l_err;
#ifdef HAVE_W32_SYSTEM
ULONG l_reserr;
ULONG totalcount = 0;
#else
int l_reserr;
unsigned int totalcount = 0;
#endif
LDAPControl *srvctrls[2] = { NULL, NULL };
int count;
LDAPControl *pagectrl = NULL;
@ -1405,7 +1463,7 @@ search_and_parse (ctrl_t ctrl, const char *keyspec,
if (ctrl->ks_get_state)
{
l_err = ldap_parse_result (ldap_conn, *r_message, &l_reserr,
l_err = my_ldap_parse_result (ldap_conn, *r_message, &l_reserr,
NULL, NULL, NULL, &resctrls, 0);
if (l_err)
{
@ -1420,7 +1478,7 @@ search_and_parse (ctrl_t ctrl, const char *keyspec,
ber_bvfree (ctrl->ks_get_state->pagecookie);
ctrl->ks_get_state->pagecookie = NULL;
}
l_err = ldap_parse_page_control (ldap_conn, resctrls,
l_err = my_ldap_parse_page_control (ldap_conn, resctrls,
&totalcount,
&ctrl->ks_get_state->pagecookie);
if (l_err)