Signed-off-by: Hans Leidekker hans@codeweavers.com --- dlls/wldap32/init.c | 218 ++++++++------------------------- dlls/wldap32/libldap.c | 18 +++ dlls/wldap32/libldap.h | 6 + dlls/wldap32/winldap_private.h | 4 + 4 files changed, 78 insertions(+), 168 deletions(-)
diff --git a/dlls/wldap32/init.c b/dlls/wldap32/init.c index 6586caa0ef5..d65554afb3c 100644 --- a/dlls/wldap32/init.c +++ b/dlls/wldap32/init.c @@ -18,25 +18,18 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
-#include "config.h" -#include "wine/port.h" - -#include <stdio.h> #include <stdarg.h> -#ifdef HAVE_LDAP_H -#include <ldap.h> -#endif - #include "windef.h" #include "winbase.h" #include "winnls.h" #include "winternl.h"
-#include "winldap_private.h" -#include "wldap32.h" #include "wine/debug.h" +#include "wine/heap.h" +#include "winldap_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
-#ifdef HAVE_LDAP /* Should eventually be determined by the algorithm documented on MSDN. */ static const WCHAR defaulthost[] = { 'l','o','c','a','l','h','o','s','t',0 };
@@ -200,55 +193,41 @@ static char *urlify_hostnames( const char *scheme, char *hostnames, ULONG port ) strarrayfreeU( strarray ); return url; } -#endif
-WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
-#ifdef HAVE_LDAP static WLDAP32_LDAP *create_context( const char *url ) { WLDAP32_LDAP *ld; - int version = LDAP_VERSION3; + int version = WLDAP32_LDAP_VERSION3;
- ld = heap_alloc_zero( sizeof( *ld )); - if (!ld) return NULL; - if (ldap_initialize( (LDAP **)&ld->ld, url ) != LDAP_SUCCESS) + if (!(ld = heap_alloc_zero( sizeof( *ld )))) return NULL; + if (map_error( ldap_funcs->ldap_initialize( &ld->ld, url ) ) != WLDAP32_LDAP_SUCCESS) { heap_free( ld ); return NULL; } - ldap_set_option( ld->ld, LDAP_OPT_PROTOCOL_VERSION, &version ); + ldap_funcs->ldap_set_option( ld->ld, WLDAP32_LDAP_OPT_PROTOCOL_VERSION, &version ); return ld; } -#endif
/*********************************************************************** * cldap_openA (WLDAP32.@) * * See cldap_openW. */ -WLDAP32_LDAP * CDECL cldap_openA( PCHAR hostname, ULONG portnumber ) +WLDAP32_LDAP * CDECL cldap_openA( char *hostname, ULONG portnumber ) { -#ifdef HAVE_LDAP - WLDAP32_LDAP *ld = NULL; + WLDAP32_LDAP *ld; WCHAR *hostnameW = NULL;
TRACE( "(%s, %d)\n", debugstr_a(hostname), portnumber );
- if (hostname) { - hostnameW = strAtoW( hostname ); - if (!hostnameW) goto exit; - } + if (hostname && !(hostnameW = strAtoW( hostname ))) return NULL;
ld = cldap_openW( hostnameW, portnumber );
-exit: strfreeW( hostnameW ); return ld; - -#else - return NULL; -#endif }
/*********************************************************************** @@ -272,25 +251,15 @@ exit: * will take precedence over the port number supplied as a parameter * to this function. */ -WLDAP32_LDAP * CDECL cldap_openW( PWCHAR hostname, ULONG portnumber ) +WLDAP32_LDAP * CDECL cldap_openW( WCHAR *hostname, ULONG portnumber ) { -#ifdef HAVE_LDAP WLDAP32_LDAP *ld = NULL; - char *hostnameU = NULL, *url = NULL; + char *hostnameU, *url = NULL;
TRACE( "(%s, %d)\n", debugstr_w(hostname), portnumber );
- if (hostname) { - hostnameU = strWtoU( hostname ); - if (!hostnameU) goto exit; - } - else { - hostnameU = strWtoU( defaulthost ); - if (!hostnameU) goto exit; - } - - url = urlify_hostnames( "cldap://", hostnameU, portnumber ); - if (!url) goto exit; + if (!(hostnameU = strWtoU( hostname ? hostname : defaulthost ))) return NULL; + if (!(url = urlify_hostnames( "cldap://", hostnameU, portnumber ))) goto exit;
ld = create_context( url );
@@ -298,10 +267,6 @@ exit: strfreeU( hostnameU ); strfreeU( url ); return ld; - -#else - return NULL; -#endif }
/*********************************************************************** @@ -337,26 +302,17 @@ ULONG CDECL ldap_connect( WLDAP32_LDAP *ld, struct l_timeval *timeout ) */ WLDAP32_LDAP * CDECL ldap_initA( const PCHAR hostname, ULONG portnumber ) { -#ifdef HAVE_LDAP - WLDAP32_LDAP *ld = NULL; + WLDAP32_LDAP *ld; WCHAR *hostnameW = NULL;
TRACE( "(%s, %d)\n", debugstr_a(hostname), portnumber );
- if (hostname) { - hostnameW = strAtoW( hostname ); - if (!hostnameW) goto exit; - } + if (hostname && !(hostnameW = strAtoW( hostname ))) return NULL;
ld = ldap_initW( hostnameW, portnumber );
-exit: strfreeW( hostnameW ); return ld; - -#else - return NULL; -#endif }
/*********************************************************************** @@ -383,23 +339,13 @@ exit: */ WLDAP32_LDAP * CDECL ldap_initW( const PWCHAR hostname, ULONG portnumber ) { -#ifdef HAVE_LDAP WLDAP32_LDAP *ld = NULL; - char *hostnameU = NULL, *url = NULL; + char *hostnameU, *url = NULL;
TRACE( "(%s, %d)\n", debugstr_w(hostname), portnumber );
- if (hostname) { - hostnameU = strWtoU( hostname ); - if (!hostnameU) goto exit; - } - else { - hostnameU = strWtoU( defaulthost ); - if (!hostnameU) goto exit; - } - - url = urlify_hostnames( "ldap://", hostnameU, portnumber ); - if (!url) goto exit; + if (!(hostnameU = strWtoU( hostname ? hostname : defaulthost ))) return NULL; + if (!(url = urlify_hostnames( "ldap://", hostnameU, portnumber ))) goto exit;
ld = create_context( url );
@@ -407,10 +353,6 @@ exit: strfreeU( hostnameU ); strfreeU( url ); return ld; - -#else - return NULL; -#endif }
/*********************************************************************** @@ -418,28 +360,19 @@ exit: * * See ldap_openW. */ -WLDAP32_LDAP * CDECL ldap_openA( PCHAR hostname, ULONG portnumber ) +WLDAP32_LDAP * CDECL ldap_openA( char *hostname, ULONG portnumber ) { -#ifdef HAVE_LDAP - WLDAP32_LDAP *ld = NULL; + WLDAP32_LDAP *ld; WCHAR *hostnameW = NULL;
TRACE( "(%s, %d)\n", debugstr_a(hostname), portnumber );
- if (hostname) { - hostnameW = strAtoW( hostname ); - if (!hostnameW) goto exit; - } + if (hostname && !(hostnameW = strAtoW( hostname ))) return NULL;
ld = ldap_openW( hostnameW, portnumber );
-exit: strfreeW( hostnameW ); return ld; - -#else - return NULL; -#endif }
/*********************************************************************** @@ -463,25 +396,15 @@ exit: * will take precedence over the port number supplied as a parameter * to this function. */ -WLDAP32_LDAP * CDECL ldap_openW( PWCHAR hostname, ULONG portnumber ) +WLDAP32_LDAP * CDECL ldap_openW( WCHAR *hostname, ULONG portnumber ) { -#ifdef HAVE_LDAP WLDAP32_LDAP *ld = NULL; - char *hostnameU = NULL, *url = NULL; + char *hostnameU, *url = NULL;
TRACE( "(%s, %d)\n", debugstr_w(hostname), portnumber );
- if (hostname) { - hostnameU = strWtoU( hostname ); - if (!hostnameU) goto exit; - } - else { - hostnameU = strWtoU( defaulthost ); - if (!hostnameU) goto exit; - } - - url = urlify_hostnames( "ldap://", hostnameU, portnumber ); - if (!url) goto exit; + if (!(hostnameU = strWtoU( hostname ? hostname : defaulthost ))) return NULL; + if (!(url = urlify_hostnames( "ldap://", hostnameU, portnumber ))) goto exit;
ld = create_context( url );
@@ -489,10 +412,6 @@ exit: strfreeU( hostnameU ); strfreeU( url ); return ld; - -#else - return NULL; -#endif }
/*********************************************************************** @@ -500,27 +419,19 @@ exit: * * See ldap_sslinitW. */ -WLDAP32_LDAP * CDECL ldap_sslinitA( PCHAR hostname, ULONG portnumber, int secure ) +WLDAP32_LDAP * CDECL ldap_sslinitA( char *hostname, ULONG portnumber, int secure ) { -#ifdef HAVE_LDAP WLDAP32_LDAP *ld; WCHAR *hostnameW = NULL;
TRACE( "(%s, %d, 0x%08x)\n", debugstr_a(hostname), portnumber, secure );
- if (hostname) { - hostnameW = strAtoW( hostname ); - if (!hostnameW) return NULL; - } + if (hostname && !(hostnameW = strAtoW( hostname ))) return NULL;
ld = ldap_sslinitW( hostnameW, portnumber, secure );
strfreeW( hostnameW ); return ld; - -#else - return NULL; -#endif }
/*********************************************************************** @@ -546,22 +457,14 @@ WLDAP32_LDAP * CDECL ldap_sslinitA( PCHAR hostname, ULONG portnumber, int secure * to this function. The connection will not be made until the first * LDAP function that needs it is called. */ -WLDAP32_LDAP * CDECL ldap_sslinitW( PWCHAR hostname, ULONG portnumber, int secure ) +WLDAP32_LDAP * CDECL ldap_sslinitW( WCHAR *hostname, ULONG portnumber, int secure ) { -#ifdef HAVE_LDAP WLDAP32_LDAP *ld = NULL; - char *hostnameU = NULL, *url = NULL; + char *hostnameU, *url = NULL;
TRACE( "(%s, %d, 0x%08x)\n", debugstr_w(hostname), portnumber, secure );
- if (hostname) { - hostnameU = strWtoU( hostname ); - if (!hostnameU) goto exit; - } - else { - hostnameU = strWtoU( defaulthost ); - if (!hostnameU) goto exit; - } + if (!(hostnameU = strWtoU( hostname ? hostname : defaulthost ))) return NULL;
if (secure) url = urlify_hostnames( "ldaps://", hostnameU, portnumber ); @@ -575,10 +478,6 @@ exit: strfreeU( hostnameU ); strfreeU( url ); return ld; - -#else - return NULL; -#endif }
/*********************************************************************** @@ -586,35 +485,24 @@ exit: * * See ldap_start_tls_sW. */ -ULONG CDECL ldap_start_tls_sA( WLDAP32_LDAP *ld, PULONG retval, WLDAP32_LDAPMessage **result, - PLDAPControlA *serverctrls, PLDAPControlA *clientctrls ) +ULONG CDECL ldap_start_tls_sA( WLDAP32_LDAP *ld, ULONG *retval, WLDAP32_LDAPMessage **result, + LDAPControlA **serverctrls, LDAPControlA **clientctrls ) { - ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; -#ifdef HAVE_LDAP + ULONG ret = WLDAP32_LDAP_NO_MEMORY; LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
- ret = WLDAP32_LDAP_NO_MEMORY; - TRACE( "(%p, %p, %p, %p, %p)\n", ld, retval, result, serverctrls, clientctrls );
if (!ld) return ~0u;
- if (serverctrls) { - serverctrlsW = controlarrayAtoW( serverctrls ); - if (!serverctrlsW) goto exit; - } - if (clientctrls) { - clientctrlsW = controlarrayAtoW( clientctrls ); - if (!clientctrlsW) goto exit; - } + if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit; + if (clientctrls && !(clientctrlsW = controlarrayAtoW( clientctrls ))) goto exit;
ret = ldap_start_tls_sW( ld, retval, result, serverctrlsW, clientctrlsW );
exit: controlarrayfreeW( serverctrlsW ); controlarrayfreeW( clientctrlsW ); - -#endif return ret; }
@@ -637,42 +525,36 @@ exit: * NOTES * LDAP function that needs it is called. */ -ULONG CDECL ldap_start_tls_sW( WLDAP32_LDAP *ld, PULONG retval, WLDAP32_LDAPMessage **result, - PLDAPControlW *serverctrls, PLDAPControlW *clientctrls ) +ULONG CDECL ldap_start_tls_sW( WLDAP32_LDAP *ld, ULONG *retval, WLDAP32_LDAPMessage **result, + LDAPControlW **serverctrls, LDAPControlW **clientctrls ) { - ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; -#ifdef HAVE_LDAP - LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL; - - ret = WLDAP32_LDAP_NO_MEMORY; + ULONG ret = WLDAP32_LDAP_NO_MEMORY; + LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
TRACE( "(%p, %p, %p, %p, %p)\n", ld, retval, result, serverctrls, clientctrls ); + if (result) + { + FIXME( "result message not supported\n" ); + *result = NULL; + }
if (!ld) return ~0u;
- if (serverctrls) { - serverctrlsU = controlarrayWtoU( serverctrls ); - if (!serverctrlsU) goto exit; - } - if (clientctrls) { - clientctrlsU = controlarrayWtoU( clientctrls ); - if (!clientctrlsU) goto exit; - } + if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit; + if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
- ret = map_error( ldap_start_tls_s( ld->ld, serverctrlsU, clientctrlsU )); + ret = map_error( ldap_funcs->ldap_start_tls_s( ld->ld, serverctrlsU, clientctrlsU ) );
exit: controlarrayfreeU( serverctrlsU ); controlarrayfreeU( clientctrlsU ); - -#endif return ret; }
/*********************************************************************** * ldap_startup (WLDAP32.@) */ -ULONG CDECL ldap_startup( PLDAP_VERSION_INFO version, HANDLE *instance ) +ULONG CDECL ldap_startup( LDAP_VERSION_INFO *version, HANDLE *instance ) { TRACE( "(%p, %p)\n", version, instance ); return WLDAP32_LDAP_SUCCESS; diff --git a/dlls/wldap32/libldap.c b/dlls/wldap32/libldap.c index de6974570f6..cf2c2b7e38c 100644 --- a/dlls/wldap32/libldap.c +++ b/dlls/wldap32/libldap.c @@ -414,6 +414,11 @@ void * CDECL wrap_ldap_first_reference( void *ld, void *chain ) return ldap_first_reference( ld, chain ); }
+int CDECL wrap_ldap_initialize( void **ld, const char *url ) +{ + return ldap_initialize( (LDAP **)ld, url ); +} + void CDECL wrap_ldap_memfree( void *ptr ) { return ldap_memfree( ptr ); @@ -502,6 +507,16 @@ int CDECL wrap_ldap_search_ext_s( void *ld, const char *base, int scope, const c (LDAPMessage **)result ); }
+int CDECL wrap_ldap_set_option( void *ld, int option, const void *value ) +{ + return ldap_set_option( ld, option, value ); +} + +int CDECL wrap_ldap_start_tls_s( void *ld, LDAPControlU **serverctrls, LDAPControlU **clientctrls ) +{ + return ldap_start_tls_s( ld, (LDAPControl **)serverctrls, (LDAPControl **)clientctrls ); +} + int CDECL wrap_ldap_unbind_ext( void *ld, LDAPControlU **serverctrls, LDAPControlU **clientctrls ) { return ldap_unbind_ext( ld, (LDAPControl **)serverctrls, (LDAPControl **)clientctrls ); @@ -548,6 +563,7 @@ static const struct ldap_funcs funcs = wrap_ldap_extended_operation, wrap_ldap_extended_operation_s, wrap_ldap_get_dn, + wrap_ldap_initialize, wrap_ldap_first_attribute, wrap_ldap_first_entry, wrap_ldap_first_reference, @@ -564,6 +580,8 @@ static const struct ldap_funcs funcs = wrap_ldap_sasl_interactive_bind_s, wrap_ldap_search_ext, wrap_ldap_search_ext_s, + wrap_ldap_set_option, + wrap_ldap_start_tls_s, wrap_ldap_unbind_ext, wrap_ldap_unbind_ext_s, wrap_ldap_value_free_len, diff --git a/dlls/wldap32/libldap.h b/dlls/wldap32/libldap.h index f3fc5796fdc..9f26704d053 100644 --- a/dlls/wldap32/libldap.h +++ b/dlls/wldap32/libldap.h @@ -119,6 +119,7 @@ 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_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; extern void * CDECL wrap_ldap_first_reference(void *, void *) DECLSPEC_HIDDEN; @@ -141,6 +142,8 @@ extern int CDECL wrap_ldap_search_ext(void *, const char *, int, const char *, c LDAPControlU **, struct timevalU *, int, ULONG *) DECLSPEC_HIDDEN; extern int CDECL wrap_ldap_search_ext_s(void *, const char *, int, const char *, char **, int, LDAPControlU **, LDAPControlU **, struct timevalU *, int, void **) DECLSPEC_HIDDEN; +extern int CDECL wrap_ldap_set_option(void *, int, const void *) DECLSPEC_HIDDEN; +extern int CDECL wrap_ldap_start_tls_s(void *, LDAPControlU **, LDAPControlU **) DECLSPEC_HIDDEN; extern int CDECL wrap_ldap_unbind_ext(void *, LDAPControlU **, LDAPControlU **) DECLSPEC_HIDDEN; extern int CDECL wrap_ldap_unbind_ext_s(void *, LDAPControlU **, LDAPControlU **) DECLSPEC_HIDDEN; extern void CDECL wrap_ldap_value_free_len(struct bervalU **) DECLSPEC_HIDDEN; @@ -181,6 +184,7 @@ 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_initialize)(void **, const char *); char * (CDECL *ldap_first_attribute)(void *, void *, void **); void * (CDECL *ldap_first_entry)(void *, void *); void * (CDECL *ldap_first_reference)(void *, void *); @@ -202,6 +206,8 @@ struct ldap_funcs LDAPControlU **, struct timevalU *, int, ULONG *); int (CDECL *ldap_search_ext_s)(void *, const char *, int, const char *, char **, int, LDAPControlU **, LDAPControlU **, struct timevalU *, int, void **); + int (CDECL *ldap_set_option)(void *, int, const void *); + int (CDECL *ldap_start_tls_s)(void *, LDAPControlU **, LDAPControlU **); int (CDECL *ldap_unbind_ext)(void *, LDAPControlU **, LDAPControlU **); int (CDECL *ldap_unbind_ext_s)(void *, LDAPControlU **, LDAPControlU **); void (CDECL *ldap_value_free_len)(struct bervalU **); diff --git a/dlls/wldap32/winldap_private.h b/dlls/wldap32/winldap_private.h index 20fc676c7e2..7ac7e5a3f41 100644 --- a/dlls/wldap32/winldap_private.h +++ b/dlls/wldap32/winldap_private.h @@ -29,6 +29,10 @@
#define WLDAP32_LBER_ERROR (~0L)
+#define WLDAP32_LDAP_VERSION1 1 +#define WLDAP32_LDAP_VERSION2 2 +#define WLDAP32_LDAP_VERSION3 3 + typedef enum { WLDAP32_LDAP_SUCCESS = 0x00, WLDAP32_LDAP_UNWILLING_TO_PERFORM = 0x35,