Commit 1114f297 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

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

parent 1805b3a1
......@@ -42,6 +42,8 @@
#include "wine/debug.h"
#include "winldap_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
C_ASSERT( sizeof(BerValueU) == sizeof(BerValue) );
C_ASSERT( sizeof(LDAPModU) == sizeof(LDAPMod) );
C_ASSERT( sizeof(LDAPControlU) == sizeof(LDAPControl) );
......@@ -50,6 +52,246 @@ C_ASSERT( sizeof(LDAPVLVInfoU) == sizeof(LDAPVLVInfo) );
static LDAPMod *nullattrs[] = { NULL };
void * CDECL wrap_ber_alloc_t( int options )
{
return ber_alloc_t( options );
}
void CDECL wrap_ber_bvecfree( struct bervalU **berval )
{
ber_bvecfree( (struct berval **)berval );
}
void CDECL wrap_ber_bvfree( struct bervalU *berval )
{
ber_bvfree( (struct berval *)berval );
}
unsigned int CDECL wrap_ber_first_element( void *ber, ULONG *ret_len, char **last )
{
ber_len_t len;
ber_tag_t ret;
if ((ret = ber_first_element( ber, &len, last )) == LBER_ERROR) return WLDAP32_LBER_ERROR;
if (ret > ~0u)
{
ERR( "ret too large\n" );
return WLDAP32_LBER_ERROR;
}
if (len > ~0u)
{
ERR( "len too large\n" );
return WLDAP32_LBER_ERROR;
}
*ret_len = len;
return ret;
}
int CDECL wrap_ber_flatten( void *ber, struct bervalU **berval )
{
return ber_flatten( ber, (struct berval **)berval );
}
void CDECL wrap_ber_free( void *ber, int freebuf )
{
ber_free( ber, freebuf );
}
void * CDECL wrap_ber_init( struct bervalU *berval )
{
return ber_init( (struct berval *)berval );
}
unsigned int CDECL wrap_ber_next_element( void *ber, unsigned int *ret_len, char *last )
{
ber_len_t len;
ber_tag_t ret;
if ((ret = ber_next_element( ber, &len, last )) == LBER_ERROR) return WLDAP32_LBER_ERROR;
if (ret > ~0u)
{
ERR( "ret too large\n" );
return WLDAP32_LBER_ERROR;
}
if (len > ~0u)
{
ERR( "len too large\n" );
return WLDAP32_LBER_ERROR;
}
*ret_len = len;
return ret;
}
unsigned int CDECL wrap_ber_peek_tag( void *ber, unsigned int *ret_len )
{
ber_len_t len;
ber_tag_t ret;
if ((ret = ber_peek_tag( ber, &len )) == LBER_ERROR) return WLDAP32_LBER_ERROR;
if (len > ~0u)
{
ERR( "len too large\n" );
return WLDAP32_LBER_ERROR;
}
*ret_len = len;
return ret;
}
unsigned int CDECL wrap_ber_skip_tag( void *ber, unsigned int *ret_len )
{
ber_len_t len;
ber_tag_t ret;
if ((ret = ber_skip_tag( ber, &len )) == LBER_ERROR) return WLDAP32_LBER_ERROR;
if (len > ~0u)
{
ERR( "len too large\n" );
return WLDAP32_LBER_ERROR;
}
*ret_len = len;
return ret;
}
int WINAPIV wrap_ber_printf( void *ber, char *fmt, ... )
{
int ret;
__ms_va_list args;
assert( strlen(fmt) == 1 );
__ms_va_start( args, fmt );
switch (fmt[0])
{
case 'b':
case 'e':
case 'i':
{
int i = va_arg( args, int );
ret = ber_printf( ber, fmt, i );
break;
}
case 'o':
case 's':
{
char *str = va_arg( args, char * );
ret = ber_printf( ber, fmt, str );
break;
}
case 't':
{
unsigned int tag = va_arg( args, unsigned int );
ret = ber_printf( ber, fmt, tag );
break;
}
case 'v':
{
char **array = va_arg( args, char ** );
ret = ber_printf( ber, fmt, array );
break;
}
case 'V':
{
struct berval **array = va_arg( args, struct berval ** );
ret = ber_printf( ber, fmt, array );
break;
}
case 'B':
{
char *str = va_arg( args, char * );
int len = va_arg( args, int );
ret = ber_printf( ber, fmt, str, len );
break;
}
case 'n':
case '{':
case '}':
case '[':
case ']':
ret = ber_printf( ber, fmt );
break;
default:
assert( 0 );
}
__ms_va_end( args );
return ret;
}
int WINAPIV wrap_ber_scanf( void *ber, char *fmt, ... )
{
int ret;
__ms_va_list args;
assert( strlen(fmt) == 1 );
__ms_va_start( args, fmt );
switch (fmt[0])
{
case 'a':
{
char **str = va_arg( args, char ** );
ret = ber_scanf( ber, fmt, str );
break;
}
case 'b':
case 'e':
case 'i':
{
int *i = va_arg( args, int * );
ret = ber_scanf( ber, fmt, i );
break;
}
case 't':
{
unsigned int *tag = va_arg( args, unsigned int * );
ret = ber_scanf( ber, fmt, tag );
break;
}
case 'v':
{
char ***array = va_arg( args, char *** );
ret = ber_scanf( ber, fmt, array );
break;
}
case 'B':
{
char **str = va_arg( args, char ** );
int *len = va_arg( args, int * );
ret = ber_scanf( ber, fmt, str, len );
break;
}
case 'O':
{
struct berval **berval = va_arg( args, struct berval ** );
ret = ber_scanf( ber, fmt, berval );
break;
}
case 'V':
{
struct berval ***array = va_arg( args, struct berval *** );
ret = ber_scanf( ber, fmt, array );
break;
}
case 'n':
case 'x':
case '{':
case '}':
case '[':
case ']':
ret = ber_scanf( ber, fmt );
break;
default:
assert( 0 );
}
__ms_va_end( args );
return ret;
}
int CDECL wrap_ldap_add_ext( void *ld, char *dn, LDAPModU **attrs, LDAPControlU **serverctrls,
LDAPControlU **clientctrls, ULONG *msg )
{
......@@ -65,10 +307,28 @@ int CDECL wrap_ldap_add_ext_s( void *ld, char *dn, LDAPModU **attrs, LDAPControl
(LDAPControl **)clientctrls );
}
void CDECL wrap_ldap_memfree( void *ptr )
{
return ldap_memfree( ptr );
}
static const struct ldap_funcs funcs =
{
wrap_ber_alloc_t,
wrap_ber_bvecfree,
wrap_ber_bvfree,
wrap_ber_first_element,
wrap_ber_flatten,
wrap_ber_free,
wrap_ber_init,
wrap_ber_next_element,
wrap_ber_peek_tag,
wrap_ber_skip_tag,
wrap_ber_printf,
wrap_ber_scanf,
wrap_ldap_add_ext,
wrap_ldap_add_ext_s,
wrap_ldap_memfree,
};
NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
......
......@@ -60,13 +60,41 @@ typedef struct
void *ldvlv_extradata;
} LDAPVLVInfoU;
extern void * CDECL wrap_ber_alloc_t(int) DECLSPEC_HIDDEN;
extern void CDECL wrap_ber_bvecfree(struct bervalU **) DECLSPEC_HIDDEN;
extern void CDECL wrap_ber_bvfree(struct bervalU *) DECLSPEC_HIDDEN;
extern unsigned int CDECL wrap_ber_first_element(void *, unsigned int *, char **) DECLSPEC_HIDDEN;
extern int CDECL wrap_ber_flatten(void *, struct bervalU **) DECLSPEC_HIDDEN;
extern void CDECL wrap_ber_free(void *, int) DECLSPEC_HIDDEN;
extern void * CDECL wrap_ber_init(struct bervalU *) DECLSPEC_HIDDEN;
extern unsigned int CDECL wrap_ber_next_element(void *, unsigned int *, char *) DECLSPEC_HIDDEN;
extern unsigned int CDECL wrap_ber_peek_tag(void *, unsigned int *) DECLSPEC_HIDDEN;
extern unsigned int CDECL wrap_ber_skip_tag(void *, unsigned int *) DECLSPEC_HIDDEN;
extern int WINAPIV wrap_ber_printf(void *, char *, ...) DECLSPEC_HIDDEN;
extern int WINAPIV wrap_ber_scanf(void *, char *, ...) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_add_ext(void *, char *, LDAPModU **, LDAPControlU **, LDAPControlU **, ULONG *) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_add_ext_s(void *, char *, LDAPModU **, LDAPControlU **, LDAPControlU **) DECLSPEC_HIDDEN;
extern void CDECL wrap_ldap_memfree(void *) DECLSPEC_HIDDEN;
struct ldap_funcs
{
void * (CDECL *ber_alloc_t)(int);
void (CDECL *ber_bvecfree)(struct bervalU **);
void (CDECL *ber_bvfree)(struct bervalU *);
unsigned int (CDECL *ber_first_element)(void *, unsigned int *, char **);
int (CDECL *ber_flatten)(void *, struct bervalU **);
void (CDECL *ber_free)(void *, int);
void * (CDECL *ber_init)(struct bervalU *);
unsigned int (CDECL *ber_next_element)(void *, unsigned int *, char *);
unsigned int (CDECL *ber_peek_tag)(void *, unsigned int *);
unsigned int (CDECL *ber_skip_tag)(void *, unsigned int *);
int (WINAPIV *ber_printf)(void *, char *, ...);
int (WINAPIV *ber_scanf)(void *, char *, ...);
int (CDECL *ldap_add_ext)(void *, char *, LDAPModU **, LDAPControlU **, LDAPControlU **, ULONG *);
int (CDECL *ldap_add_ext_s)(void *, char *, LDAPModU **, LDAPControlU **, LDAPControlU **);
void (CDECL *ldap_memfree)(void *);
};
extern const struct ldap_funcs *ldap_funcs;
......@@ -328,15 +328,22 @@ PWCHAR CDECL ldap_first_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry
{
PWCHAR ret = NULL;
#ifdef HAVE_LDAP
BerElement *berU;
char *retU;
TRACE( "(%p, %p, %p)\n", ld, entry, ptr );
if (!ld || !entry) return NULL;
retU = ldap_first_attribute( ld->ld, entry, ptr );
ret = strUtoW( retU );
ldap_memfree( retU );
retU = ldap_first_attribute( ld->ld, entry, &berU );
if (retU)
{
WLDAP32_BerElement *ber = heap_alloc( sizeof(*ber) );
ber->opaque = (char *)berU;
*ptr = ber;
ret = strUtoW( retU );
ldap_memfree( retU );
}
#endif
return ret;
......@@ -487,19 +494,22 @@ PCHAR CDECL ldap_next_attributeA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry,
* When done iterating and when ptr != NULL, call ber_free( ptr, 0 ).
*/
PWCHAR CDECL ldap_next_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry,
WLDAP32_BerElement *ptr )
WLDAP32_BerElement *ber )
{
PWCHAR ret = NULL;
#ifdef HAVE_LDAP
char *retU;
TRACE( "(%p, %p, %p)\n", ld, entry, ptr );
TRACE( "(%p, %p, %p)\n", ld, entry, ber );
if (!ld || !entry || !ptr) return NULL;
retU = ldap_next_attribute( ld->ld, entry, ptr );
if (!ld || !entry) return NULL;
ret = strUtoW( retU );
ldap_memfree( retU );
retU = ldap_next_attribute( ld->ld, entry, (BerElement *)ber->opaque );
if (retU)
{
ret = strUtoW( retU );
ldap_memfree( retU );
}
#endif
return ret;
......
......@@ -27,6 +27,8 @@
#include "winnls.h"
#include "libldap.h"
#define WLDAP32_LBER_ERROR (~0L)
typedef enum {
WLDAP32_LDAP_SUCCESS = 0x00,
WLDAP32_LDAP_UNWILLING_TO_PERFORM = 0x35,
......@@ -1187,6 +1189,26 @@ static inline WCHAR **strarrayUtoW( char **strarray )
return strarrayW;
}
static inline char **strarrayUtoU( char **strarray )
{
char **strarrayU = NULL;
DWORD size;
if (strarray)
{
size = sizeof(char *) * (strarraylenU( strarray ) + 1);
if ((strarrayU = RtlAllocateHeap( GetProcessHeap(), 0, size )))
{
char **p = strarray;
char **q = strarrayU;
while (*p) *q++ = strdupU( *p++ );
*q = NULL;
}
}
return strarrayU;
}
static inline LDAPControlW *controlUtoW( const LDAPControlU *control )
{
LDAPControlW *controlW;
......
......@@ -27,11 +27,17 @@ typedef unsigned int ber_tag_t;
typedef unsigned int ber_len_t;
BerElement * CDECL ber_alloc_t( int );
BERVAL * CDECL ber_bvdup( BERVAL * );
void CDECL ber_bvecfree( BERVAL ** );
void CDECL ber_bvfree( BERVAL * );
ULONG CDECL ber_first_element( BerElement *, ULONG *, char ** );
int CDECL ber_flatten( BerElement *, BERVAL ** );
void CDECL ber_free( BerElement *, int );
BerElement * CDECL ber_init( BERVAL * );
ULONG CDECL ber_next_element( BerElement *, ULONG *, char ** );
ULONG CDECL ber_peek_tag( BerElement *, ULONG * );
int WINAPIV ber_printf( BerElement *, char *, ... );
ULONG WINAPIV ber_scanf( BerElement *, char *, ... );
ULONG CDECL ber_skip_tag( BerElement *, ULONG * );
#endif /* __WINE_WINBER_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment