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
...@@ -18,24 +18,16 @@ ...@@ -18,24 +18,16 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include "config.h"
#include <stdarg.h> #include <stdarg.h>
#ifdef HAVE_LDAP_H
#include <ldap.h>
#endif
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winldap_private.h" #include "winnls.h"
#include "wldap32.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "wine/heap.h"
#include "winldap_private.h"
#ifdef HAVE_LDAP
WINE_DEFAULT_DEBUG_CHANNEL(wldap32); WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
#endif
#define WLDAP32_LBER_ERROR (~0U)
/*********************************************************************** /***********************************************************************
* ber_alloc_t (WLDAP32.@) * ber_alloc_t (WLDAP32.@)
...@@ -52,13 +44,17 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32); ...@@ -52,13 +44,17 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
* NOTES * NOTES
* Free the berelement structure with ber_free. * Free the berelement structure with ber_free.
*/ */
WLDAP32_BerElement * CDECL WLDAP32_ber_alloc_t( INT options ) WLDAP32_BerElement * CDECL WLDAP32_ber_alloc_t( int options )
{ {
#ifdef HAVE_LDAP WLDAP32_BerElement *ret;
return ber_alloc_t( options );
#else if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
return NULL; if (!(ret->opaque = ldap_funcs->ber_alloc_t( options )))
#endif {
heap_free( ret );
return NULL;
}
return ret;
} }
...@@ -98,7 +94,7 @@ BERVAL * CDECL WLDAP32_ber_bvdup( BERVAL *berval ) ...@@ -98,7 +94,7 @@ BERVAL * CDECL WLDAP32_ber_bvdup( BERVAL *berval )
* Use this function only to free an array of berval structures * Use this function only to free an array of berval structures
* returned by a call to ber_scanf with a 'V' in the format string. * returned by a call to ber_scanf with a 'V' in the format string.
*/ */
void CDECL WLDAP32_ber_bvecfree( PBERVAL *berval ) void CDECL WLDAP32_ber_bvecfree( BERVAL **berval )
{ {
bvarrayfreeW( berval ); bvarrayfreeW( berval );
} }
...@@ -142,26 +138,9 @@ void CDECL WLDAP32_ber_bvfree( BERVAL *berval ) ...@@ -142,26 +138,9 @@ void CDECL WLDAP32_ber_bvfree( BERVAL *berval )
* NOTES * NOTES
* len and cookie should be passed to ber_next_element. * len and cookie should be passed to ber_next_element.
*/ */
ULONG CDECL WLDAP32_ber_first_element( WLDAP32_BerElement *berelement, ULONG *ret_len, CHAR **opaque ) ULONG CDECL WLDAP32_ber_first_element( WLDAP32_BerElement *ber, ULONG *len, char **opaque )
{ {
#ifdef HAVE_LDAP return ldap_funcs->ber_first_element( ber->opaque, len, opaque );
ber_len_t len;
ber_tag_t ret;
if ((ret = ber_first_element( berelement, &len, opaque )) != LBER_ERROR)
{
if (len > ~0u)
{
ERR( "len too large\n" );
return WLDAP32_LBER_ERROR;
}
*ret_len = len;
}
return ret;
#else
return WLDAP32_LBER_ERROR;
#endif
} }
...@@ -181,23 +160,18 @@ ULONG CDECL WLDAP32_ber_first_element( WLDAP32_BerElement *berelement, ULONG *re ...@@ -181,23 +160,18 @@ ULONG CDECL WLDAP32_ber_first_element( WLDAP32_BerElement *berelement, ULONG *re
* NOTES * NOTES
* Free the berval structure with ber_bvfree. * Free the berval structure with ber_bvfree.
*/ */
INT CDECL WLDAP32_ber_flatten( WLDAP32_BerElement *berelement, PBERVAL *berval ) int CDECL WLDAP32_ber_flatten( WLDAP32_BerElement *ber, BERVAL **berval )
{ {
#ifdef HAVE_LDAP struct bervalU *bervalU;
struct berval *bervalU;
struct WLDAP32_berval *bervalW; struct WLDAP32_berval *bervalW;
if (ber_flatten( berelement, &bervalU )) return WLDAP32_LBER_ERROR; if (ldap_funcs->ber_flatten( ber->opaque, &bervalU )) return WLDAP32_LBER_ERROR;
bervalW = bervalUtoW( bervalU ); if (!(bervalW = bervalUtoW( bervalU ))) return WLDAP32_LBER_ERROR;
ber_bvfree( bervalU ); ldap_funcs->ber_bvfree( bervalU );
if (!bervalW) return WLDAP32_LBER_ERROR; if (!bervalW) return WLDAP32_LBER_ERROR;
*berval = bervalW; *berval = bervalW;
return 0; return 0;
#else
return WLDAP32_LBER_ERROR;
#endif
} }
...@@ -217,11 +191,10 @@ INT CDECL WLDAP32_ber_flatten( WLDAP32_BerElement *berelement, PBERVAL *berval ) ...@@ -217,11 +191,10 @@ INT CDECL WLDAP32_ber_flatten( WLDAP32_BerElement *berelement, PBERVAL *berval )
* Set buf to 0 if the berelement was allocated with ldap_first_attribute * Set buf to 0 if the berelement was allocated with ldap_first_attribute
* or ldap_next_attribute, otherwise set it to 1. * or ldap_next_attribute, otherwise set it to 1.
*/ */
void CDECL WLDAP32_ber_free( WLDAP32_BerElement *berelement, INT buf ) void CDECL WLDAP32_ber_free( WLDAP32_BerElement *ber, int freebuf )
{ {
#ifdef HAVE_LDAP ldap_funcs->ber_free( ber->opaque, freebuf );
ber_free( berelement, buf ); heap_free( ber );
#endif
} }
...@@ -242,17 +215,22 @@ void CDECL WLDAP32_ber_free( WLDAP32_BerElement *berelement, INT buf ) ...@@ -242,17 +215,22 @@ void CDECL WLDAP32_ber_free( WLDAP32_BerElement *berelement, INT buf )
*/ */
WLDAP32_BerElement * CDECL WLDAP32_ber_init( BERVAL *berval ) WLDAP32_BerElement * CDECL WLDAP32_ber_init( BERVAL *berval )
{ {
#ifdef HAVE_LDAP struct bervalU *bervalU;
struct berval *bervalU;
WLDAP32_BerElement *ret; WLDAP32_BerElement *ret;
if (!(bervalU = bervalWtoU( berval ))) return NULL; if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
ret = ber_init( bervalU ); if (!(bervalU = bervalWtoU( berval )))
{
heap_free( ret );
return NULL;
}
if (!(ret->opaque = ldap_funcs->ber_init( bervalU )))
{
heap_free( ret );
ret = NULL;
}
heap_free( bervalU ); heap_free( bervalU );
return ret; return ret;
#else
return NULL;
#endif
} }
...@@ -274,26 +252,9 @@ WLDAP32_BerElement * CDECL WLDAP32_ber_init( BERVAL *berval ) ...@@ -274,26 +252,9 @@ WLDAP32_BerElement * CDECL WLDAP32_ber_init( BERVAL *berval )
* len and cookie are initialized by ber_first_element and should * len and cookie are initialized by ber_first_element and should
* be passed on in subsequent calls to ber_next_element. * be passed on in subsequent calls to ber_next_element.
*/ */
ULONG CDECL WLDAP32_ber_next_element( WLDAP32_BerElement *berelement, ULONG *ret_len, CHAR *opaque ) ULONG CDECL WLDAP32_ber_next_element( WLDAP32_BerElement *ber, ULONG *len, char *opaque )
{ {
#ifdef HAVE_LDAP return ldap_funcs->ber_next_element( ber->opaque, len, opaque );
ber_len_t len;
ber_tag_t ret;
if ((ret = ber_next_element( berelement, &len, opaque )) != LBER_ERROR)
{
if (len > ~0u)
{
ERR( "len too large\n" );
return WLDAP32_LBER_ERROR;
}
*ret_len = len;
}
return ret;
#else
return WLDAP32_LBER_ERROR;
#endif
} }
...@@ -310,26 +271,9 @@ ULONG CDECL WLDAP32_ber_next_element( WLDAP32_BerElement *berelement, ULONG *ret ...@@ -310,26 +271,9 @@ ULONG CDECL WLDAP32_ber_next_element( WLDAP32_BerElement *berelement, ULONG *ret
* Success: Tag of the next element. * Success: Tag of the next element.
* Failure: LBER_DEFAULT (no more data). * Failure: LBER_DEFAULT (no more data).
*/ */
ULONG CDECL WLDAP32_ber_peek_tag( WLDAP32_BerElement *berelement, ULONG *ret_len ) ULONG CDECL WLDAP32_ber_peek_tag( WLDAP32_BerElement *ber, ULONG *len )
{ {
#ifdef HAVE_LDAP return ldap_funcs->ber_peek_tag( ber->opaque, len );
ber_len_t len;
ber_tag_t ret;
if ((ret = ber_peek_tag( berelement, &len )) != LBER_ERROR)
{
if (len > ~0u)
{
ERR( "len too large\n" );
return WLDAP32_LBER_ERROR;
}
*ret_len = len;
}
return ret;
#else
return WLDAP32_LBER_ERROR;
#endif
} }
...@@ -346,26 +290,9 @@ ULONG CDECL WLDAP32_ber_peek_tag( WLDAP32_BerElement *berelement, ULONG *ret_len ...@@ -346,26 +290,9 @@ ULONG CDECL WLDAP32_ber_peek_tag( WLDAP32_BerElement *berelement, ULONG *ret_len
* Success: Tag of the next element. * Success: Tag of the next element.
* Failure: LBER_DEFAULT (no more data). * Failure: LBER_DEFAULT (no more data).
*/ */
ULONG CDECL WLDAP32_ber_skip_tag( WLDAP32_BerElement *berelement, ULONG *ret_len ) ULONG CDECL WLDAP32_ber_skip_tag( WLDAP32_BerElement *ber, ULONG *len )
{ {
#ifdef HAVE_LDAP return ldap_funcs->ber_skip_tag( ber->opaque, len );
ber_len_t len;
ber_tag_t ret;
if ((ret = ber_skip_tag( berelement, &len )) != LBER_ERROR)
{
if (len > ~0u)
{
ERR( "len too large\n" );
return WLDAP32_LBER_ERROR;
}
*ret_len = len;
}
return ret;
#else
return WLDAP32_LBER_ERROR;
#endif
} }
...@@ -380,16 +307,15 @@ ULONG CDECL WLDAP32_ber_skip_tag( WLDAP32_BerElement *berelement, ULONG *ret_len ...@@ -380,16 +307,15 @@ ULONG CDECL WLDAP32_ber_skip_tag( WLDAP32_BerElement *berelement, ULONG *ret_len
* ... [I] Values to encode. * ... [I] Values to encode.
* *
* RETURNS * RETURNS
* Success: Non-negative number. * Success: Non-negative number.
* Failure: LBER_ERROR * Failure: LBER_ERROR
* *
* NOTES * NOTES
* berelement must have been allocated with ber_alloc_t. This function * berelement must have been allocated with ber_alloc_t. This function
* can be called multiple times to append data. * can be called multiple times to append data.
*/ */
INT WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *berelement, PCHAR fmt, ... ) int WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *ber, char *fmt, ... )
{ {
#ifdef HAVE_LDAP
__ms_va_list list; __ms_va_list list;
int ret = 0; int ret = 0;
char new_fmt[2]; char new_fmt[2];
...@@ -399,63 +325,64 @@ INT WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *berelement, PCHAR fmt, ... ) ...@@ -399,63 +325,64 @@ INT WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *berelement, PCHAR fmt, ... )
while (*fmt) while (*fmt)
{ {
new_fmt[0] = *fmt++; new_fmt[0] = *fmt++;
switch(new_fmt[0]) switch (new_fmt[0])
{ {
case 'b': case 'b':
case 'e': case 'e':
case 'i': case 'i':
{ {
int i = va_arg( list, int ); int i = va_arg( list, int );
ret = ber_printf( berelement, new_fmt, i ); ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, i );
break; break;
} }
case 'o': case 'o':
case 's': case 's':
{ {
char *str = va_arg( list, char * ); char *str = va_arg( list, char * );
ret = ber_printf( berelement, new_fmt, str ); ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, str );
break; break;
} }
case 't': case 't':
{ {
unsigned int tag = va_arg( list, unsigned int ); unsigned int tag = va_arg( list, unsigned int );
ret = ber_printf( berelement, new_fmt, tag ); ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, tag );
break; break;
} }
case 'v': case 'v':
{ {
char **array = va_arg( list, char ** ); char **array = va_arg( list, char ** );
ret = ber_printf( berelement, new_fmt, array ); ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, array );
break; break;
} }
case 'V': case 'V':
{
struct WLDAP32_berval **array = va_arg( list, struct WLDAP32_berval ** );
struct bervalU **arrayU;
if (!(arrayU = bvarrayWtoU( array )))
{ {
struct WLDAP32_berval **array = va_arg( list, struct WLDAP32_berval ** ); ret = -1;
struct berval **arrayU;
if (!(arrayU = bvarrayWtoU( array )))
{
ret = -1;
break;
}
ret = ber_printf( berelement, new_fmt, arrayU );
bvarrayfreeU( arrayU );
break; break;
} }
ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, arrayU );
bvarrayfreeU( arrayU );
break;
}
case 'X': case 'X':
{ {
char *str = va_arg( list, char * ); char *str = va_arg( list, char * );
int len = va_arg( list, int ); int len = va_arg( list, int );
new_fmt[0] = 'B'; /* 'X' is deprecated */ new_fmt[0] = 'B'; /* 'X' is deprecated */
ret = ber_printf( berelement, new_fmt, str, len ); ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, str, len );
break; break;
} }
case 'n': case 'n':
case '{': case '{':
case '}': case '}':
case '[': case '[':
case ']': case ']':
ret = ber_printf( berelement, new_fmt ); ret = ldap_funcs->ber_printf( ber->opaque, new_fmt );
break; break;
default: default:
FIXME( "Unknown format '%c'\n", new_fmt[0] ); FIXME( "Unknown format '%c'\n", new_fmt[0] );
ret = -1; ret = -1;
...@@ -465,9 +392,6 @@ INT WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *berelement, PCHAR fmt, ... ) ...@@ -465,9 +392,6 @@ INT WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *berelement, PCHAR fmt, ... )
} }
__ms_va_end( list ); __ms_va_end( list );
return ret; return ret;
#else
return WLDAP32_LBER_ERROR;
#endif
} }
...@@ -482,16 +406,15 @@ INT WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *berelement, PCHAR fmt, ... ) ...@@ -482,16 +406,15 @@ INT WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *berelement, PCHAR fmt, ... )
* ... [I] Pointers to values to be decoded. * ... [I] Pointers to values to be decoded.
* *
* RETURNS * RETURNS
* Success: Non-negative number. * Success: Non-negative number.
* Failure: LBER_ERROR * Failure: LBER_ERROR
* *
* NOTES * NOTES
* berelement must have been allocated with ber_init. This function * berelement must have been allocated with ber_init. This function
* can be called multiple times to decode data. * can be called multiple times to decode data.
*/ */
INT WINAPIV WLDAP32_ber_scanf( WLDAP32_BerElement *berelement, PCHAR fmt, ... ) int WINAPIV WLDAP32_ber_scanf( WLDAP32_BerElement *ber, char *fmt, ... )
{ {
#ifdef HAVE_LDAP
__ms_va_list list; __ms_va_list list;
int ret = 0; int ret = 0;
char new_fmt[2]; char new_fmt[2];
...@@ -501,65 +424,81 @@ INT WINAPIV WLDAP32_ber_scanf( WLDAP32_BerElement *berelement, PCHAR fmt, ... ) ...@@ -501,65 +424,81 @@ INT WINAPIV WLDAP32_ber_scanf( WLDAP32_BerElement *berelement, PCHAR fmt, ... )
while (*fmt) while (*fmt)
{ {
new_fmt[0] = *fmt++; new_fmt[0] = *fmt++;
switch(new_fmt[0]) switch (new_fmt[0])
{ {
case 'a': case 'a':
{ {
char **ptr = va_arg( list, char ** ); char *str, **ptr = va_arg( list, char ** );
ret = ber_scanf( berelement, new_fmt, ptr ); if ((ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, &str )) == -1) break;
break; *ptr = strdupU( str );
} ldap_funcs->ldap_memfree( str );
break;
}
case 'b': case 'b':
case 'e': case 'e':
case 'i': case 'i':
{ {
int *i = va_arg( list, int * ); int *i = va_arg( list, int * );
ret = ber_scanf( berelement, new_fmt, i ); ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, i );
break; break;
} }
case 't': case 't':
{ {
unsigned int *tag = va_arg( list, unsigned int * ); unsigned int *tag = va_arg( list, unsigned int * );
ret = ber_scanf( berelement, new_fmt, tag ); ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, tag );
break; break;
} }
case 'v': case 'v':
{
char *str, **arrayU, **ptr, ***array = va_arg( list, char *** );
if ((ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, &arrayU )) == -1) break;
*array = strarrayUtoU( arrayU );
ptr = arrayU;
while ((str = *ptr))
{ {
char ***array = va_arg( list, char *** ); ldap_funcs->ldap_memfree( str );
ret = ber_scanf( berelement, new_fmt, array ); ptr++;
break;
} }
ldap_funcs->ldap_memfree( arrayU );
break;
}
case 'B': case 'B':
{ {
char **str = va_arg( list, char ** ); char *strU, **str = va_arg( list, char ** );
int *len = va_arg( list, int * ); int *len = va_arg( list, int * );
ret = ber_scanf( berelement, new_fmt, str, len ); if ((ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, &strU, len )) == -1) break;
break; *str = heap_alloc( *len );
} memcpy( *str, strU, *len );
ldap_funcs->ldap_memfree( strU );
break;
}
case 'O': case 'O':
{ {
struct berval **ptr = va_arg( list, struct berval ** ); struct WLDAP32_berval **berval = va_arg( list, struct WLDAP32_berval ** );
ret = ber_scanf( berelement, new_fmt, ptr ); struct bervalU *bervalU;
break; if ((ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, &bervalU )) == -1) break;
} *berval = bervalUtoW( bervalU );
ldap_funcs->ber_bvfree( bervalU );
break;
}
case 'V': case 'V':
{ {
struct WLDAP32_berval **arrayW, ***array = va_arg( list, struct WLDAP32_berval *** ); struct WLDAP32_berval ***array = va_arg( list, struct WLDAP32_berval *** );
struct berval **arrayU; struct bervalU **arrayU;
if ((ret = ber_scanf( berelement, new_fmt, &arrayU )) == -1) break; if ((ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, &arrayU )) == -1) break;
if ((arrayW = bvarrayUtoW( arrayU ))) *array = arrayW; *array = bvarrayUtoW( arrayU );
else ret = -1; ldap_funcs->ber_bvecfree( arrayU );
bvarrayfreeU( arrayU ); break;
break; }
}
case 'n': case 'n':
case 'x': case 'x':
case '{': case '{':
case '}': case '}':
case '[': case '[':
case ']': case ']':
ret = ber_scanf( berelement, new_fmt ); ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt );
break; break;
default: default:
FIXME( "Unknown format '%c'\n", new_fmt[0] ); FIXME( "Unknown format '%c'\n", new_fmt[0] );
ret = -1; ret = -1;
...@@ -569,7 +508,4 @@ INT WINAPIV WLDAP32_ber_scanf( WLDAP32_BerElement *berelement, PCHAR fmt, ... ) ...@@ -569,7 +508,4 @@ INT WINAPIV WLDAP32_ber_scanf( WLDAP32_BerElement *berelement, PCHAR fmt, ... )
} }
__ms_va_end( list ); __ms_va_end( list );
return ret; return ret;
#else
return WLDAP32_LBER_ERROR;
#endif
} }
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#include "wine/debug.h" #include "wine/debug.h"
#include "winldap_private.h" #include "winldap_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
C_ASSERT( sizeof(BerValueU) == sizeof(BerValue) ); C_ASSERT( sizeof(BerValueU) == sizeof(BerValue) );
C_ASSERT( sizeof(LDAPModU) == sizeof(LDAPMod) ); C_ASSERT( sizeof(LDAPModU) == sizeof(LDAPMod) );
C_ASSERT( sizeof(LDAPControlU) == sizeof(LDAPControl) ); C_ASSERT( sizeof(LDAPControlU) == sizeof(LDAPControl) );
...@@ -50,6 +52,246 @@ C_ASSERT( sizeof(LDAPVLVInfoU) == sizeof(LDAPVLVInfo) ); ...@@ -50,6 +52,246 @@ C_ASSERT( sizeof(LDAPVLVInfoU) == sizeof(LDAPVLVInfo) );
static LDAPMod *nullattrs[] = { NULL }; 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, int CDECL wrap_ldap_add_ext( void *ld, char *dn, LDAPModU **attrs, LDAPControlU **serverctrls,
LDAPControlU **clientctrls, ULONG *msg ) LDAPControlU **clientctrls, ULONG *msg )
{ {
...@@ -65,10 +307,28 @@ int CDECL wrap_ldap_add_ext_s( void *ld, char *dn, LDAPModU **attrs, LDAPControl ...@@ -65,10 +307,28 @@ int CDECL wrap_ldap_add_ext_s( void *ld, char *dn, LDAPModU **attrs, LDAPControl
(LDAPControl **)clientctrls ); (LDAPControl **)clientctrls );
} }
void CDECL wrap_ldap_memfree( void *ptr )
{
return ldap_memfree( ptr );
}
static const struct ldap_funcs funcs = 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,
wrap_ldap_add_ext_s, 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 ) NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
......
...@@ -60,13 +60,41 @@ typedef struct ...@@ -60,13 +60,41 @@ typedef struct
void *ldvlv_extradata; void *ldvlv_extradata;
} LDAPVLVInfoU; } 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(void *, char *, LDAPModU **, LDAPControlU **, LDAPControlU **, ULONG *) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_add_ext_s(void *, char *, LDAPModU **, LDAPControlU **, LDAPControlU **) 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 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)(void *, char *, LDAPModU **, LDAPControlU **, LDAPControlU **, ULONG *);
int (CDECL *ldap_add_ext_s)(void *, char *, LDAPModU **, LDAPControlU **, LDAPControlU **); int (CDECL *ldap_add_ext_s)(void *, char *, LDAPModU **, LDAPControlU **, LDAPControlU **);
void (CDECL *ldap_memfree)(void *);
}; };
extern const struct ldap_funcs *ldap_funcs; extern const struct ldap_funcs *ldap_funcs;
...@@ -328,15 +328,22 @@ PWCHAR CDECL ldap_first_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry ...@@ -328,15 +328,22 @@ PWCHAR CDECL ldap_first_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry
{ {
PWCHAR ret = NULL; PWCHAR ret = NULL;
#ifdef HAVE_LDAP #ifdef HAVE_LDAP
BerElement *berU;
char *retU; char *retU;
TRACE( "(%p, %p, %p)\n", ld, entry, ptr ); TRACE( "(%p, %p, %p)\n", ld, entry, ptr );
if (!ld || !entry) return NULL; if (!ld || !entry) return NULL;
retU = ldap_first_attribute( ld->ld, entry, ptr );
ret = strUtoW( retU ); retU = ldap_first_attribute( ld->ld, entry, &berU );
ldap_memfree( retU ); if (retU)
{
WLDAP32_BerElement *ber = heap_alloc( sizeof(*ber) );
ber->opaque = (char *)berU;
*ptr = ber;
ret = strUtoW( retU );
ldap_memfree( retU );
}
#endif #endif
return ret; return ret;
...@@ -487,19 +494,22 @@ PCHAR CDECL ldap_next_attributeA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, ...@@ -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 ). * When done iterating and when ptr != NULL, call ber_free( ptr, 0 ).
*/ */
PWCHAR CDECL ldap_next_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PWCHAR CDECL ldap_next_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry,
WLDAP32_BerElement *ptr ) WLDAP32_BerElement *ber )
{ {
PWCHAR ret = NULL; PWCHAR ret = NULL;
#ifdef HAVE_LDAP #ifdef HAVE_LDAP
char *retU; char *retU;
TRACE( "(%p, %p, %p)\n", ld, entry, ptr ); TRACE( "(%p, %p, %p)\n", ld, entry, ber );
if (!ld || !entry || !ptr) return NULL; if (!ld || !entry) return NULL;
retU = ldap_next_attribute( ld->ld, entry, ptr );
ret = strUtoW( retU ); retU = ldap_next_attribute( ld->ld, entry, (BerElement *)ber->opaque );
ldap_memfree( retU ); if (retU)
{
ret = strUtoW( retU );
ldap_memfree( retU );
}
#endif #endif
return ret; return ret;
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include "winnls.h" #include "winnls.h"
#include "libldap.h" #include "libldap.h"
#define WLDAP32_LBER_ERROR (~0L)
typedef enum { typedef enum {
WLDAP32_LDAP_SUCCESS = 0x00, WLDAP32_LDAP_SUCCESS = 0x00,
WLDAP32_LDAP_UNWILLING_TO_PERFORM = 0x35, WLDAP32_LDAP_UNWILLING_TO_PERFORM = 0x35,
...@@ -1187,6 +1189,26 @@ static inline WCHAR **strarrayUtoW( char **strarray ) ...@@ -1187,6 +1189,26 @@ static inline WCHAR **strarrayUtoW( char **strarray )
return strarrayW; 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 ) static inline LDAPControlW *controlUtoW( const LDAPControlU *control )
{ {
LDAPControlW *controlW; LDAPControlW *controlW;
......
...@@ -27,11 +27,17 @@ typedef unsigned int ber_tag_t; ...@@ -27,11 +27,17 @@ typedef unsigned int ber_tag_t;
typedef unsigned int ber_len_t; typedef unsigned int ber_len_t;
BerElement * CDECL ber_alloc_t( int ); BerElement * CDECL ber_alloc_t( int );
BERVAL * CDECL ber_bvdup( BERVAL * );
void CDECL ber_bvecfree( BERVAL ** );
void CDECL ber_bvfree( BERVAL * ); void CDECL ber_bvfree( BERVAL * );
ULONG CDECL ber_first_element( BerElement *, ULONG *, char ** );
int CDECL ber_flatten( BerElement *, BERVAL ** ); int CDECL ber_flatten( BerElement *, BERVAL ** );
void CDECL ber_free( BerElement *, int ); void CDECL ber_free( BerElement *, int );
BerElement * CDECL ber_init( BERVAL * ); 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 *, ... ); int WINAPIV ber_printf( BerElement *, char *, ... );
ULONG WINAPIV ber_scanf( BerElement *, char *, ... ); ULONG WINAPIV ber_scanf( BerElement *, char *, ... );
ULONG CDECL ber_skip_tag( BerElement *, ULONG * );
#endif /* __WINE_WINBER_H */ #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