wldap32: Move support for option functions to the Unix library.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2021-04-16 09:59:17 +02:00 committed by Alexandre Julliard
parent d48a9495ce
commit da4d701bb7
4 changed files with 112 additions and 108 deletions

View File

@ -50,6 +50,8 @@ C_ASSERT( sizeof(LDAPModU) == sizeof(LDAPMod) );
C_ASSERT( sizeof(LDAPControlU) == sizeof(LDAPControl) );
C_ASSERT( sizeof(LDAPSortKeyU) == sizeof(LDAPSortKey) );
C_ASSERT( sizeof(LDAPVLVInfoU) == sizeof(LDAPVLVInfo) );
C_ASSERT( sizeof(LDAPAPIInfoU) == sizeof(LDAPAPIInfo) );
C_ASSERT( sizeof(LDAPAPIFeatureInfoU) == sizeof(LDAPAPIFeatureInfo) );
C_ASSERT( sizeof(struct timevalU) == sizeof(struct timeval) );
static LDAPMod *nullmods[] = { NULL };
@ -346,6 +348,11 @@ int CDECL wrap_ldap_count_references( void *ld, void *chain )
return ldap_count_references( ld, chain );
}
int CDECL wrap_ldap_count_values_len( struct bervalU **values )
{
return ldap_count_values_len( (struct berval **)values );
}
int CDECL wrap_ldap_create_sort_control( void *ld, LDAPSortKeyU **keylist, int critical, LDAPControlU **control )
{
return ldap_create_sort_control( ld, (LDAPSortKey **)keylist, critical, (LDAPControl **)control );
@ -414,6 +421,16 @@ void * CDECL wrap_ldap_first_reference( void *ld, void *chain )
return ldap_first_reference( ld, chain );
}
int CDECL wrap_ldap_get_option( void *ld, int option, void *value )
{
return ldap_get_option( ld, option, value );
}
struct bervalU ** CDECL wrap_ldap_get_values_len( void *ld, void *entry, const char *attr )
{
return (struct bervalU **)ldap_get_values_len( ld, entry, attr );
}
int CDECL wrap_ldap_initialize( void **ld, const char *url )
{
return ldap_initialize( (LDAP **)ld, url );
@ -583,6 +600,7 @@ static const struct ldap_funcs funcs =
wrap_ldap_control_free,
wrap_ldap_count_entries,
wrap_ldap_count_references,
wrap_ldap_count_values_len,
wrap_ldap_create_sort_control,
wrap_ldap_create_vlv_control,
wrap_ldap_delete_ext,
@ -592,6 +610,8 @@ static const struct ldap_funcs funcs =
wrap_ldap_extended_operation,
wrap_ldap_extended_operation_s,
wrap_ldap_get_dn,
wrap_ldap_get_option,
wrap_ldap_get_values_len,
wrap_ldap_initialize,
wrap_ldap_first_attribute,
wrap_ldap_first_entry,

View File

@ -60,6 +60,23 @@ typedef struct
void *ldvlv_extradata;
} LDAPVLVInfoU;
typedef struct
{
int ldapai_info_version;
int ldapai_api_version;
int ldapai_protocol_version;
char **ldapai_extensions;
char *ldapai_vendor_name;
int ldapai_vendor_version;
} LDAPAPIInfoU;
typedef struct
{
int ldapaif_info_version;
char *ldapaif_name;
int ldapaif_version;
} LDAPAPIFeatureInfoU;
typedef struct timevalU
{
unsigned long tv_sec;
@ -108,6 +125,7 @@ extern int CDECL wrap_ldap_compare_ext_s(void *, const char *, const char *, str
extern void CDECL wrap_ldap_control_free(LDAPControlU *) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_count_entries(void *, void *) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_count_references(void *, void *) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_count_values_len(struct bervalU **) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_create_sort_control(void *, LDAPSortKeyU **, int, LDAPControlU **) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_create_vlv_control(void *, LDAPVLVInfoU *, LDAPControlU **) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_delete_ext(void *, const char *, LDAPControlU **, LDAPControlU **, ULONG *) DECLSPEC_HIDDEN;
@ -119,6 +137,8 @@ extern int CDECL wrap_ldap_extended_operation(void *, const char *, struct berva
extern int CDECL wrap_ldap_extended_operation_s(void *, const char *, struct bervalU *, LDAPControlU **,
LDAPControlU **, char **, struct bervalU **) DECLSPEC_HIDDEN;
extern char * CDECL wrap_ldap_get_dn(void *, void *) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_get_option(void *, int, void *) DECLSPEC_HIDDEN;
extern struct bervalU ** CDECL wrap_ldap_get_values_len(void *, void *, const char *) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_initialize(void **, const char *) DECLSPEC_HIDDEN;
extern char * CDECL wrap_ldap_first_attribute(void *, void *, void **) DECLSPEC_HIDDEN;
extern void * CDECL wrap_ldap_first_entry(void *, void *) DECLSPEC_HIDDEN;
@ -181,6 +201,7 @@ struct ldap_funcs
void (CDECL *ldap_control_free)(LDAPControlU *);
int (CDECL *ldap_count_entries)(void *, void *);
int (CDECL *ldap_count_references)(void *, void *);
int (CDECL *ldap_count_values_len)(struct bervalU **);
int (CDECL *ldap_create_sort_control)(void *, LDAPSortKeyU **, int, LDAPControlU **);
int (CDECL *ldap_create_vlv_control)(void *, LDAPVLVInfoU *, LDAPControlU **);
int (CDECL *ldap_delete_ext)(void *, const char *, LDAPControlU **, LDAPControlU **, ULONG *);
@ -192,6 +213,8 @@ struct ldap_funcs
int (CDECL *ldap_extended_operation_s)(void *, const char *, struct bervalU *, LDAPControlU **,
LDAPControlU **, char **, struct bervalU **);
char * (CDECL *ldap_get_dn)(void *, void *);
int (CDECL *ldap_get_option)(void *, int, void *);
struct bervalU ** (CDECL *ldap_get_values_len)(void *, void *, const char *);
int (CDECL *ldap_initialize)(void **, const char *);
char * (CDECL *ldap_first_attribute)(void *, void *, void **);
void * (CDECL *ldap_first_entry)(void *, void *);

View File

@ -18,25 +18,15 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#ifdef HAVE_LDAP_H
#include <ldap.h>
#endif
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "winldap_private.h"
#include "wldap32.h"
#include "wine/debug.h"
#include "winldap_private.h"
#ifdef HAVE_LDAP
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
#endif
/***********************************************************************
* ldap_get_optionA (WLDAP32.@)
@ -45,8 +35,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
*/
ULONG CDECL ldap_get_optionA( WLDAP32_LDAP *ld, int option, void *value )
{
ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
ULONG ret;
TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
@ -62,14 +51,12 @@ ULONG CDECL ldap_get_optionA( WLDAP32_LDAP *ld, int option, void *value )
if (!featureA->ldapaif_name) return WLDAP32_LDAP_PARAM_ERROR;
featureW.ldapaif_info_version = featureA->ldapaif_info_version;
featureW.ldapaif_name = strAtoW( featureA->ldapaif_name );
if (!(featureW.ldapaif_name = strAtoW( featureA->ldapaif_name ))) return WLDAP32_LDAP_NO_MEMORY;
featureW.ldapaif_version = 0;
if (!featureW.ldapaif_name) return WLDAP32_LDAP_NO_MEMORY;
ret = ldap_get_optionW( ld, option, &featureW );
featureA->ldapaif_version = featureW.ldapaif_version;
if (ret == WLDAP32_LDAP_SUCCESS) featureA->ldapaif_version = featureW.ldapaif_version;
strfreeW( featureW.ldapaif_name );
return ret;
}
@ -78,32 +65,27 @@ ULONG CDECL ldap_get_optionA( WLDAP32_LDAP *ld, int option, void *value )
LDAPAPIInfoW infoW;
LDAPAPIInfoA *infoA = value;
memset( &infoW, 0, sizeof(LDAPAPIInfoW) );
memset( &infoW, 0, sizeof(infoW) );
infoW.ldapai_info_version = infoA->ldapai_info_version;
ret = ldap_get_optionW( ld, option, &infoW );
if (ret == WLDAP32_LDAP_SUCCESS)
{
infoA->ldapai_api_version = infoW.ldapai_api_version;
infoA->ldapai_protocol_version = infoW.ldapai_protocol_version;
if (infoW.ldapai_extensions)
{
infoA->ldapai_extensions = strarrayWtoA( infoW.ldapai_extensions );
if (!infoA->ldapai_extensions) return WLDAP32_LDAP_NO_MEMORY;
}
if (infoW.ldapai_vendor_name)
{
infoA->ldapai_vendor_name = strWtoA( infoW.ldapai_vendor_name );
if (!infoA->ldapai_vendor_name)
if (infoW.ldapai_extensions && !(infoA->ldapai_extensions = strarrayWtoA( infoW.ldapai_extensions )))
return WLDAP32_LDAP_NO_MEMORY;
if (infoW.ldapai_vendor_name && !(infoA->ldapai_vendor_name = strWtoA( infoW.ldapai_vendor_name )))
{
ldap_value_freeW( infoW.ldapai_extensions );
return WLDAP32_LDAP_NO_MEMORY;
}
}
infoA->ldapai_vendor_version = infoW.ldapai_vendor_version;
ldap_value_freeW( infoW.ldapai_extensions );
ldap_memfreeW( infoW.ldapai_vendor_name );
}
return ret;
}
@ -124,7 +106,7 @@ ULONG CDECL ldap_get_optionA( WLDAP32_LDAP *ld, int option, void *value )
case WLDAP32_LDAP_OPT_REBIND_FN:
case WLDAP32_LDAP_OPT_RESTART:
case WLDAP32_LDAP_OPT_THREAD_FN_PTRS:
return LDAP_LOCAL_ERROR;
return WLDAP32_LDAP_LOCAL_ERROR;
case WLDAP32_LDAP_OPT_AREC_EXCLUSIVE:
case WLDAP32_LDAP_OPT_AUTO_RECONNECT:
@ -163,9 +145,6 @@ ULONG CDECL ldap_get_optionA( WLDAP32_LDAP *ld, int option, void *value )
FIXME( "Unknown option: 0x%02x\n", option );
return WLDAP32_LDAP_LOCAL_ERROR;
}
#endif
return ret;
}
/***********************************************************************
@ -184,8 +163,7 @@ ULONG CDECL ldap_get_optionA( WLDAP32_LDAP *ld, int option, void *value )
*/
ULONG CDECL ldap_get_optionW( WLDAP32_LDAP *ld, int option, void *value )
{
ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
ULONG ret;
TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
@ -195,54 +173,47 @@ ULONG CDECL ldap_get_optionW( WLDAP32_LDAP *ld, int option, void *value )
{
case WLDAP32_LDAP_OPT_API_FEATURE_INFO:
{
LDAPAPIFeatureInfo featureU;
LDAPAPIFeatureInfoU featureU;
LDAPAPIFeatureInfoW *featureW = value;
if (!featureW->ldapaif_name) return WLDAP32_LDAP_PARAM_ERROR;
featureU.ldapaif_info_version = featureW->ldapaif_info_version;
featureU.ldapaif_name = strWtoU( featureW->ldapaif_name );
if (!(featureU.ldapaif_name = strWtoU( featureW->ldapaif_name ))) return WLDAP32_LDAP_NO_MEMORY;
featureU.ldapaif_version = 0;
if (!featureU.ldapaif_name) return WLDAP32_LDAP_NO_MEMORY;
ret = map_error( ldap_funcs->ldap_get_option( ld->ld, option, &featureU ) );
ret = map_error( ldap_get_option( ld->ld, option, &featureU ));
featureW->ldapaif_version = featureU.ldapaif_version;
if (ret == WLDAP32_LDAP_SUCCESS) featureW->ldapaif_version = featureU.ldapaif_version;
strfreeU( featureU.ldapaif_name );
return ret;
}
case WLDAP32_LDAP_OPT_API_INFO:
{
LDAPAPIInfo infoU;
LDAPAPIInfoU infoU;
LDAPAPIInfoW *infoW = value;
memset( &infoU, 0, sizeof(LDAPAPIInfo) );
memset( &infoU, 0, sizeof(infoU) );
infoU.ldapai_info_version = infoW->ldapai_info_version;
ret = map_error( ldap_get_option( ld->ld, option, &infoU ));
ret = map_error( ldap_funcs->ldap_get_option( ld->ld, option, &infoU ) );
if (ret == WLDAP32_LDAP_SUCCESS)
{
infoW->ldapai_api_version = infoU.ldapai_api_version;
infoW->ldapai_protocol_version = infoU.ldapai_protocol_version;
if (infoU.ldapai_extensions)
{
infoW->ldapai_extensions = strarrayUtoW( infoU.ldapai_extensions );
if (!infoW->ldapai_extensions) return WLDAP32_LDAP_NO_MEMORY;
}
if (infoU.ldapai_vendor_name)
{
infoW->ldapai_vendor_name = strUtoW( infoU.ldapai_vendor_name );
if (!infoW->ldapai_vendor_name)
{
ldap_memvfree( (void **)infoU.ldapai_extensions );
if (infoU.ldapai_extensions && !(infoW->ldapai_extensions = strarrayUtoW( infoU.ldapai_extensions )))
return WLDAP32_LDAP_NO_MEMORY;
if (infoU.ldapai_vendor_name && !(infoW->ldapai_vendor_name = strUtoW( infoU.ldapai_vendor_name )))
{
ldap_funcs->ldap_memvfree( (void **)infoU.ldapai_extensions );
return WLDAP32_LDAP_NO_MEMORY;
}
}
infoW->ldapai_vendor_version = infoU.ldapai_vendor_version;
ldap_memvfree( (void **)infoU.ldapai_extensions );
ldap_memfree( infoU.ldapai_vendor_name );
ldap_funcs->ldap_memvfree( (void **)infoU.ldapai_extensions );
ldap_funcs->ldap_memfree( infoU.ldapai_vendor_name );
}
return ret;
}
@ -253,7 +224,7 @@ ULONG CDECL ldap_get_optionW( WLDAP32_LDAP *ld, int option, void *value )
case WLDAP32_LDAP_OPT_REFERRALS:
case WLDAP32_LDAP_OPT_SIZELIMIT:
case WLDAP32_LDAP_OPT_TIMELIMIT:
return map_error( ldap_get_option( ld->ld, option, value ));
return map_error( ldap_funcs->ldap_get_option( ld->ld, option, value ));
case WLDAP32_LDAP_OPT_CACHE_ENABLE:
case WLDAP32_LDAP_OPT_CACHE_FN_PTRS:
@ -302,9 +273,6 @@ ULONG CDECL ldap_get_optionW( WLDAP32_LDAP *ld, int option, void *value )
FIXME( "Unknown option: 0x%02x\n", option );
return WLDAP32_LDAP_LOCAL_ERROR;
}
#endif
return ret;
}
/***********************************************************************
@ -314,8 +282,7 @@ ULONG CDECL ldap_get_optionW( WLDAP32_LDAP *ld, int option, void *value )
*/
ULONG CDECL ldap_set_optionA( WLDAP32_LDAP *ld, int option, void *value )
{
ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
ULONG ret;
TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
@ -326,10 +293,7 @@ ULONG CDECL ldap_set_optionA( WLDAP32_LDAP *ld, int option, void *value )
case WLDAP32_LDAP_OPT_SERVER_CONTROLS:
{
LDAPControlW **ctrlsW;
ctrlsW = controlarrayAtoW( value );
if (!ctrlsW) return WLDAP32_LDAP_NO_MEMORY;
if (!(ctrlsW = controlarrayAtoW( value ))) return WLDAP32_LDAP_NO_MEMORY;
ret = ldap_set_optionW( ld, option, ctrlsW );
controlarrayfreeW( ctrlsW );
return ret;
@ -393,41 +357,37 @@ ULONG CDECL ldap_set_optionA( WLDAP32_LDAP *ld, int option, void *value )
FIXME( "Unknown option: 0x%02x\n", option );
return WLDAP32_LDAP_LOCAL_ERROR;
}
#endif
return ret;
}
#ifdef HAVE_LDAP
static BOOL query_supported_server_ctrls( WLDAP32_LDAP *ld )
{
char *attrs[] = { (char *)"supportedControl", NULL };
LDAPMessage *res, *entry;
void *res, *entry;
ULONG ret;
if ( ld->ld_server_ctrls ) return TRUE;
if (ld->ld_server_ctrls) return TRUE;
if (ldap_search_ext_s( ld->ld, (char *)"", LDAP_SCOPE_BASE, (char *)"(objectClass=*)", attrs, FALSE,
NULL, NULL, NULL, 0, &res ) != LDAP_SUCCESS)
return FALSE;
ret = map_error( ldap_funcs->ldap_search_ext_s( ld->ld, (char *)"", WLDAP32_LDAP_SCOPE_BASE,
(char *)"(objectClass=*)", attrs, FALSE, NULL, NULL, NULL, 0, &res ) );
if (ret != WLDAP32_LDAP_SUCCESS) return FALSE;
entry = ldap_first_entry( ld->ld, res );
entry = ldap_funcs->ldap_first_entry( ld->ld, res );
if (entry)
{
ULONG count, i;
ld->ld_server_ctrls = (struct bervalU **)ldap_get_values_len( ld->ld, entry, attrs[0] );
count = ldap_count_values_len( (struct berval **)ld->ld_server_ctrls );
ld->ld_server_ctrls = ldap_funcs->ldap_get_values_len( ld->ld, entry, attrs[0] );
count = ldap_funcs->ldap_count_values_len( ld->ld_server_ctrls );
for (i = 0; i < count; i++)
TRACE("%u: %s\n", i, debugstr_an( ld->ld_server_ctrls[i]->bv_val, ld->ld_server_ctrls[i]->bv_len ));
}
ldap_msgfree( res );
ldap_funcs->ldap_msgfree( res );
return ld->ld_server_ctrls != NULL;
}
static BOOL is_supported_server_ctrls( WLDAP32_LDAP *ld, LDAPControl **ctrls )
static BOOL is_supported_server_ctrls( WLDAP32_LDAP *ld, LDAPControlU **ctrls )
{
ULONG user_count, server_count, i, n, supported = 0;
@ -435,7 +395,7 @@ static BOOL is_supported_server_ctrls( WLDAP32_LDAP *ld, LDAPControl **ctrls )
return TRUE; /* can't verify, let the server handle it on next query */
user_count = controlarraylenU( ctrls );
server_count = ldap_count_values_len( (struct berval **)ld->ld_server_ctrls );
server_count = ldap_funcs->ldap_count_values_len( ld->ld_server_ctrls );
for (n = 0; n < user_count; n++)
{
@ -453,7 +413,6 @@ static BOOL is_supported_server_ctrls( WLDAP32_LDAP *ld, LDAPControl **ctrls )
return supported == user_count;
}
#endif
/***********************************************************************
* ldap_set_optionW (WLDAP32.@)
@ -474,8 +433,7 @@ static BOOL is_supported_server_ctrls( WLDAP32_LDAP *ld, LDAPControl **ctrls )
*/
ULONG CDECL ldap_set_optionW( WLDAP32_LDAP *ld, int option, void *value )
{
ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
ULONG ret;
TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
@ -485,26 +443,25 @@ ULONG CDECL ldap_set_optionW( WLDAP32_LDAP *ld, int option, void *value )
{
case WLDAP32_LDAP_OPT_SERVER_CONTROLS:
{
LDAPControl **ctrlsU;
LDAPControlU **ctrlsU;
ctrlsU = controlarrayWtoU( value );
if (!ctrlsU) return WLDAP32_LDAP_NO_MEMORY;
if (!(ctrlsU = controlarrayWtoU( value ))) return WLDAP32_LDAP_NO_MEMORY;
if (!is_supported_server_ctrls( ld, ctrlsU ))
ret = WLDAP32_LDAP_PARAM_ERROR;
else
ret = map_error( ldap_set_option( ld->ld, option, ctrlsU ));
ret = map_error( ldap_funcs->ldap_set_option( ld->ld, option, ctrlsU ) );
controlarrayfreeU( ctrlsU );
return ret;
}
case WLDAP32_LDAP_OPT_REFERRALS:
{
void *openldap_referral = LDAP_OPT_ON;
if (value == LDAP_OPT_OFF)
openldap_referral = LDAP_OPT_OFF;
void *openldap_referral = WLDAP32_LDAP_OPT_ON;
if (value == WLDAP32_LDAP_OPT_OFF)
openldap_referral = WLDAP32_LDAP_OPT_OFF;
else
FIXME("upgrading referral value %p to LDAP_OPT_ON (OpenLDAP lacks sufficient granularity)\n", value);
return map_error( ldap_set_option( ld->ld, option, openldap_referral ));
return map_error( ldap_funcs->ldap_set_option( ld->ld, option, openldap_referral ) );
break;
}
case WLDAP32_LDAP_OPT_DEREF:
@ -513,7 +470,7 @@ ULONG CDECL ldap_set_optionW( WLDAP32_LDAP *ld, int option, void *value )
case WLDAP32_LDAP_OPT_PROTOCOL_VERSION:
case WLDAP32_LDAP_OPT_SIZELIMIT:
case WLDAP32_LDAP_OPT_TIMELIMIT:
return map_error( ldap_set_option( ld->ld, option, value ));
return map_error( ldap_funcs->ldap_set_option( ld->ld, option, value ));
case WLDAP32_LDAP_OPT_CACHE_ENABLE:
case WLDAP32_LDAP_OPT_CACHE_FN_PTRS:
@ -565,7 +522,4 @@ ULONG CDECL ldap_set_optionW( WLDAP32_LDAP *ld, int option, void *value )
FIXME( "Unknown option: 0x%02x\n", option );
return WLDAP32_LDAP_LOCAL_ERROR;
}
#endif
return ret;
}

View File

@ -33,6 +33,13 @@
#define WLDAP32_LDAP_VERSION2 2
#define WLDAP32_LDAP_VERSION3 3
#define WLDAP32_LDAP_OPT_ON ((void *)1)
#define WLDAP32_LDAP_OPT_OFF ((void *)0)
#define WLDAP32_LDAP_SCOPE_BASE 0x00
#define WLDAP32_LDAP_SCOPE_ONELEVEL 0x01
#define WLDAP32_LDAP_SCOPE_SUBTREE 0x02
typedef enum {
WLDAP32_LDAP_SUCCESS = 0x00,
WLDAP32_LDAP_UNWILLING_TO_PERFORM = 0x35,