[PATCH 1/8] wldap32: Move support for parse functions to the Unix library.

Hans Leidekker hans at codeweavers.com
Mon Apr 19 03:04:47 CDT 2021


Signed-off-by: Hans Leidekker <hans at codeweavers.com>
---
 dlls/wldap32/libldap.c         |  32 ++++
 dlls/wldap32/libldap.h         |  11 ++
 dlls/wldap32/parse.c           | 286 +++++++++++++--------------------
 dlls/wldap32/winldap_private.h |  40 +++++
 4 files changed, 199 insertions(+), 170 deletions(-)

diff --git a/dlls/wldap32/libldap.c b/dlls/wldap32/libldap.c
index 662edb4d365..f71970e2a59 100644
--- a/dlls/wldap32/libldap.c
+++ b/dlls/wldap32/libldap.c
@@ -338,6 +338,11 @@ void CDECL wrap_ldap_control_free( LDAPControlU *control )
     ldap_control_free( (LDAPControl *)control );
 }
 
+void CDECL wrap_ldap_controls_free( LDAPControlU **control )
+{
+    ldap_controls_free( (LDAPControl **)control );
+}
+
 int CDECL wrap_ldap_count_entries( void *ld, void *chain )
 {
     return ldap_count_entries( ld, chain );
@@ -481,12 +486,34 @@ void * CDECL wrap_ldap_next_reference( void *ld, void *entry )
     return ldap_next_reference( ld, entry );
 }
 
+int CDECL wrap_ldap_parse_extended_result( void *ld, void *result, char **retoid, struct bervalU **retdata, int free )
+{
+    return ldap_parse_extended_result( ld, result, retoid, (struct berval **)retdata, free );
+}
+
+int CDECL wrap_ldap_parse_reference( void *ld, void *ref, char ***referrals, LDAPControlU ***serverctrls, int free )
+{
+    return ldap_parse_reference( ld, ref, referrals, (LDAPControl ***)serverctrls, free );
+}
+
 int CDECL wrap_ldap_parse_result( void *ld, void *res, int *errcode, char **matcheddn, char **errmsg,
                                   char ***referrals, LDAPControlU ***serverctrls, int free )
 {
     return ldap_parse_result( ld, res, errcode, matcheddn, errmsg, referrals, (LDAPControl ***)serverctrls, free );
 }
 
+int CDECL wrap_ldap_parse_sortresponse_control( void *ld, LDAPControlU *ctrl, int *result, char **attr )
+{
+    return ldap_parse_sortresponse_control( ld, (LDAPControl *)ctrl, result, attr );
+}
+
+int CDECL wrap_ldap_parse_vlvresponse_control( void *ld, LDAPControlU *ctrls, int *target_pos, int *list_count,
+                                               struct bervalU **ctx, int *errcode )
+{
+    return ldap_parse_vlvresponse_control( ld, (LDAPControl *)ctrls, target_pos, list_count, (struct berval **)ctx,
+                                           errcode );
+}
+
 int CDECL wrap_ldap_rename( void *ld, const char *dn, const char *newrdn, const char *newparent, int delete,
                             LDAPControlU **clientctrls, LDAPControlU **serverctrls, ULONG *msg )
 {
@@ -598,6 +625,7 @@ static const struct ldap_funcs funcs =
     wrap_ldap_compare_ext,
     wrap_ldap_compare_ext_s,
     wrap_ldap_control_free,
+    wrap_ldap_controls_free,
     wrap_ldap_count_entries,
     wrap_ldap_count_references,
     wrap_ldap_count_values_len,
@@ -624,7 +652,11 @@ static const struct ldap_funcs funcs =
     wrap_ldap_next_attribute,
     wrap_ldap_next_entry,
     wrap_ldap_next_reference,
+    wrap_ldap_parse_extended_result,
+    wrap_ldap_parse_reference,
     wrap_ldap_parse_result,
+    wrap_ldap_parse_sortresponse_control,
+    wrap_ldap_parse_vlvresponse_control,
     wrap_ldap_rename,
     wrap_ldap_rename_s,
     wrap_ldap_result,
diff --git a/dlls/wldap32/libldap.h b/dlls/wldap32/libldap.h
index 8745eac3abc..1dfadf7e3bc 100644
--- a/dlls/wldap32/libldap.h
+++ b/dlls/wldap32/libldap.h
@@ -123,6 +123,7 @@ extern int CDECL wrap_ldap_compare_ext(void *, const char *, const char *, struc
 extern int CDECL wrap_ldap_compare_ext_s(void *, const char *, const char *, struct bervalU *, LDAPControlU **,
                                          LDAPControlU **) DECLSPEC_HIDDEN;
 extern void CDECL wrap_ldap_control_free(LDAPControlU *) DECLSPEC_HIDDEN;
+extern void CDECL wrap_ldap_controls_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;
@@ -153,8 +154,13 @@ extern int CDECL wrap_ldap_msgfree(void *) DECLSPEC_HIDDEN;
 extern char * CDECL wrap_ldap_next_attribute(void *, void *, void *) DECLSPEC_HIDDEN;
 extern void * CDECL wrap_ldap_next_entry(void *, void *) DECLSPEC_HIDDEN;
 extern void * CDECL wrap_ldap_next_reference(void *, void *) DECLSPEC_HIDDEN;
+extern int CDECL wrap_ldap_parse_extended_result(void *, void *, char **, struct bervalU **, int) DECLSPEC_HIDDEN;
+extern int CDECL wrap_ldap_parse_reference(void *, void *, char ***, LDAPControlU ***, int) DECLSPEC_HIDDEN;
 extern int CDECL wrap_ldap_parse_result(void *, void *, int *, char **, char **, char ***, LDAPControlU ***,
                                         int) DECLSPEC_HIDDEN;
+extern int CDECL wrap_ldap_parse_sortresponse_control(void *, LDAPControlU *, int *, char **) DECLSPEC_HIDDEN;
+extern int CDECL wrap_ldap_parse_vlvresponse_control(void *, LDAPControlU *, int *, int *, struct bervalU **,
+                                                     int *) DECLSPEC_HIDDEN;
 extern int CDECL wrap_ldap_rename(void *, const char *, const char *, const char *, int, LDAPControlU **,
                                   LDAPControlU **, ULONG *) DECLSPEC_HIDDEN;
 extern int CDECL wrap_ldap_rename_s(void *, const char *, const char *, const char *, int, LDAPControlU **,
@@ -199,6 +205,7 @@ struct ldap_funcs
     int (CDECL *ldap_compare_ext_s)(void *, const char *, const char *, struct bervalU *, LDAPControlU **,
                                     LDAPControlU **);
     void (CDECL *ldap_control_free)(LDAPControlU *);
+    void (CDECL *ldap_controls_free)(LDAPControlU **);
     int (CDECL *ldap_count_entries)(void *, void *);
     int (CDECL *ldap_count_references)(void *, void *);
     int (CDECL *ldap_count_values_len)(struct bervalU **);
@@ -227,7 +234,11 @@ struct ldap_funcs
     char * (CDECL *ldap_next_attribute)(void *, void *, void *);
     void * (CDECL *ldap_next_entry)(void *, void *);
     void * (CDECL *ldap_next_reference)(void *, void *);
+    int (CDECL *ldap_parse_extended_result)(void *, void *, char **, struct bervalU **, int);
+    int (CDECL *ldap_parse_reference)(void *, void *, char ***, LDAPControlU ***, int);
     int (CDECL *ldap_parse_result)(void *, void *, int *, char **, char **, char ***, LDAPControlU ***, int);
+    int (CDECL *ldap_parse_sortresponse_control)(void *, LDAPControlU *, int *, char **);
+    int (CDECL *ldap_parse_vlvresponse_control)(void *, LDAPControlU *, int *, int *, struct bervalU **, int *);
     int (CDECL *ldap_rename)(void *, const char *, const char *, const char *, int, LDAPControlU **, LDAPControlU **,
                              ULONG *);
     int (CDECL *ldap_rename_s)(void *, const char *, const char *, const char *, int, LDAPControlU **, LDAPControlU **);
diff --git a/dlls/wldap32/parse.c b/dlls/wldap32/parse.c
index bbaa7b1f842..1b699435223 100644
--- a/dlls/wldap32/parse.c
+++ b/dlls/wldap32/parse.c
@@ -18,36 +18,25 @@
  * 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_parse_extended_resultA     (WLDAP32.@)
  *
  * See ldap_parse_extended_resultW.
  */
-ULONG CDECL ldap_parse_extended_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
-    PCHAR *oid, struct WLDAP32_berval **data, BOOLEAN free )
+ULONG CDECL ldap_parse_extended_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result, char **oid,
+    struct WLDAP32_berval **data, BOOLEAN free )
 {
-    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
-#ifdef HAVE_LDAP
+    ULONG ret;
     WCHAR *oidW = NULL;
 
     TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
@@ -56,21 +45,20 @@ ULONG CDECL ldap_parse_extended_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *
     if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
 
     ret = ldap_parse_extended_resultW( ld, result, &oidW, data, free );
-
-    if (oid) {
-        *oid = strWtoA( oidW );
-        if (!*oid) ret = WLDAP32_LDAP_NO_MEMORY;
+    if (oid && oidW)
+    {
+        char *str;
+        if ((str = strWtoA( oidW ))) *oid = str;
+        else ret = WLDAP32_LDAP_NO_MEMORY;
         ldap_memfreeW( oidW );
     }
-
-#endif
     return ret;
 }
 
 /***********************************************************************
  *      ldap_parse_extended_resultW     (WLDAP32.@)
  *
- * Parse the result of an extended operation. 
+ * Parse the result of an extended operation.
  *
  * PARAMS
  *  ld      [I] Pointer to an LDAP context.
@@ -88,26 +76,33 @@ ULONG CDECL ldap_parse_extended_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *
  *  value for 'free' or call ldap_msgfree to free the result message.
  */
 ULONG CDECL ldap_parse_extended_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
-    PWCHAR *oid, struct WLDAP32_berval **data, BOOLEAN free )
+    WCHAR **oid, struct WLDAP32_berval **data, BOOLEAN free )
 {
-    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
-#ifdef HAVE_LDAP
+    ULONG ret;
     char *oidU = NULL;
+    struct bervalU *dataU = NULL;
 
     TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
 
     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
     if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
 
-    ret = map_error( ldap_parse_extended_result( ld->ld, result->Request, &oidU, (struct berval **)data, free ) );
-
-    if (oid) {
-        *oid = strUtoW( oidU );
-        if (!*oid) ret = WLDAP32_LDAP_NO_MEMORY;
-        ldap_memfree( oidU );
+    ret = map_error( ldap_funcs->ldap_parse_extended_result( ld->ld, result, &oidU, &dataU, free ) );
+    if (oid && oidU)
+    {
+        WCHAR *str;
+        if ((str = strUtoW( oidU ))) *oid = str;
+        else ret = WLDAP32_LDAP_NO_MEMORY;
+        ldap_funcs->ldap_memfree( oidU );
+    }
+    if (data && dataU)
+    {
+        struct WLDAP32_berval *bv;
+        if ((bv = bervalUtoW( dataU ))) *data = bv;
+        else ret = WLDAP32_LDAP_NO_MEMORY;
+        ldap_funcs->ber_bvfree( dataU );
     }
 
-#endif
     return ret;
 }
 
@@ -116,11 +111,9 @@ ULONG CDECL ldap_parse_extended_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *
  *
  * See ldap_parse_referenceW.
  */
-ULONG CDECL ldap_parse_referenceA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message,
-    PCHAR **referrals )
+ULONG CDECL ldap_parse_referenceA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message, char ***referrals )
 {
-    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
-#ifdef HAVE_LDAP
+    ULONG ret;
     WCHAR **referralsW = NULL;
 
     TRACE( "(%p, %p, %p)\n", ld, message, referrals );
@@ -128,11 +121,13 @@ ULONG CDECL ldap_parse_referenceA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *messag
     if (!ld) return ~0u;
 
     ret = ldap_parse_referenceW( ld, message, &referralsW );
-
-    *referrals = strarrayWtoA( referralsW );
-    ldap_value_freeW( referralsW );
-
-#endif 
+    if (referralsW)
+    {
+        char **ref;
+        if ((ref = strarrayWtoA( referralsW ))) *referrals = ref;
+        else ret = WLDAP32_LDAP_NO_MEMORY;
+        ldap_value_freeW( referralsW );
+    }
     return ret;
 }
 
@@ -153,23 +148,23 @@ ULONG CDECL ldap_parse_referenceA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *messag
  * NOTES
  *  Free the referrals with ldap_value_free.
  */
-ULONG CDECL ldap_parse_referenceW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
-    PWCHAR **referrals )
+ULONG CDECL ldap_parse_referenceW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message, WCHAR ***referrals )
 {
-    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
-#ifdef HAVE_LDAP_PARSE_REFERENCE
+    ULONG ret;
     char **referralsU = NULL;
 
-    TRACE( "(%p, %p, %p)\n", ld, result, referrals );
+    TRACE( "(%p, %p, %p)\n", ld, message, referrals );
 
     if (!ld) return ~0u;
 
-    ret = map_error( ldap_parse_reference( ld->ld, result->Request, &referralsU, NULL, 0 ));
-
-    *referrals = strarrayUtoW( referralsU );
-    ldap_memfree( referralsU );
-
-#endif
+    ret = map_error( ldap_funcs->ldap_parse_reference( ld->ld, message, &referralsU, NULL, 0 ) );
+    if (referralsU)
+    {
+        WCHAR **ref;
+        if ((ref = strarrayUtoW( referralsU ))) *referrals = ref;
+        else ret = WLDAP32_LDAP_NO_MEMORY;
+        ldap_funcs->ldap_memfree( referralsU );
+    }
     return ret;
 }
 
@@ -178,26 +173,22 @@ ULONG CDECL ldap_parse_referenceW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result
  *
  * See ldap_parse_resultW.
  */
-ULONG CDECL ldap_parse_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
-    ULONG *retcode, PCHAR *matched, PCHAR *error, PCHAR **referrals,
-    PLDAPControlA **serverctrls, BOOLEAN free )
+ULONG CDECL ldap_parse_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result, ULONG *retcode, char **matched,
+    char **error, char ***referrals, LDAPControlA ***serverctrls, BOOLEAN free )
 {
-    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
-#ifdef HAVE_LDAP
+    ULONG ret;
     WCHAR *matchedW = NULL, *errorW = NULL, **referralsW = NULL;
     LDAPControlW **serverctrlsW = NULL;
 
-    TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode,
-           matched, error, referrals, serverctrls, free );
+    TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode, matched, error, referrals, serverctrls,
+           free );
 
     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
 
-    ret = ldap_parse_resultW( ld, result, retcode, &matchedW, &errorW,
-                              &referralsW, &serverctrlsW, free );
+    ret = ldap_parse_resultW( ld, result, retcode, &matchedW, &errorW, &referralsW, &serverctrlsW, free );
 
     if (matched) *matched = strWtoA( matchedW );
     if (error) *error = strWtoA( errorW );
-
     if (referrals) *referrals = strarrayWtoA( referralsW );
     if (serverctrls) *serverctrls = controlarrayWtoA( serverctrlsW );
 
@@ -205,15 +196,13 @@ ULONG CDECL ldap_parse_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
     ldap_memfreeW( errorW );
     ldap_value_freeW( referralsW );
     ldap_controls_freeW( serverctrlsW );
-
-#endif
     return ret;
 }
 
 /***********************************************************************
  *      ldap_parse_resultW     (WLDAP32.@)
  *
- * Parse a result message. 
+ * Parse a result message.
  *
  * PARAMS
  *  ld           [I] Pointer to an LDAP context.
@@ -235,35 +224,30 @@ ULONG CDECL ldap_parse_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
  *  ldap_controls_free. Pass a nonzero value for 'free' or call
  *  ldap_msgfree to free the result message.
  */
-ULONG CDECL ldap_parse_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
-    ULONG *retcode, PWCHAR *matched, PWCHAR *error, PWCHAR **referrals,
-    PLDAPControlW **serverctrls, BOOLEAN free )
+ULONG CDECL ldap_parse_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result, ULONG *retcode, WCHAR **matched,
+    WCHAR **error, WCHAR ***referrals, LDAPControlW ***serverctrls, BOOLEAN free )
 {
-    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
-#ifdef HAVE_LDAP
+    ULONG ret;
     char *matchedU = NULL, *errorU = NULL, **referralsU = NULL;
-    LDAPControl **serverctrlsU = NULL;
+    LDAPControlU **serverctrlsU = NULL;
 
-    TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode,
-           matched, error, referrals, serverctrls, free );
+    TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode, matched, error, referrals, serverctrls,
+           free );
 
     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
 
-    ret = map_error( ldap_parse_result( ld->ld, result->Request, (int *)retcode, &matchedU, &errorU,
-                                        &referralsU, &serverctrlsU, free ));
+    ret = map_error( ldap_funcs->ldap_parse_result( ld->ld, result->Request, (int *)retcode, &matchedU, &errorU,
+                                                    &referralsU, &serverctrlsU, free ) );
 
     if (matched) *matched = strUtoW( matchedU );
     if (error) *error = strUtoW( errorU );
-
     if (referrals) *referrals = strarrayUtoW( referralsU );
     if (serverctrls) *serverctrls = controlarrayUtoW( serverctrlsU );
 
-    ldap_memfree( matchedU );
-    ldap_memfree( errorU );
-    ldap_memvfree( (void **)referralsU );
-    ldap_controls_free( serverctrlsU );
-
-#endif
+    ldap_funcs->ldap_memfree( matchedU );
+    ldap_funcs->ldap_memfree( errorU );
+    ldap_funcs->ldap_memvfree( (void **)referralsU );
+    ldap_funcs->ldap_controls_free( serverctrlsU );
     return ret;
 }
 
@@ -272,11 +256,9 @@ ULONG CDECL ldap_parse_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
  *
  * See ldap_parse_sort_controlW.
  */
-ULONG CDECL ldap_parse_sort_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
-    ULONG *result, PCHAR *attr )
+ULONG CDECL ldap_parse_sort_controlA( WLDAP32_LDAP *ld, LDAPControlA **control, ULONG *result, char **attr )
 {
-    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
-#ifdef HAVE_LDAP
+    ULONG ret;
     WCHAR *attrW = NULL;
     LDAPControlW **controlW = NULL;
 
@@ -284,16 +266,12 @@ ULONG CDECL ldap_parse_sort_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
 
     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
     if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
-
-    controlW = controlarrayAtoW( control );
-    if (!controlW) return WLDAP32_LDAP_NO_MEMORY;
+    if (!(controlW = controlarrayAtoW( control ))) return WLDAP32_LDAP_NO_MEMORY;
 
     ret = ldap_parse_sort_controlW( ld, controlW, result, &attrW );
 
     *attr = strWtoA( attrW );
     controlarrayfreeW( controlW );
-
-#endif
     return ret;
 }
 
@@ -315,36 +293,20 @@ ULONG CDECL ldap_parse_sort_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
  * NOTES
  *  If the function fails, free the failing attribute with ldap_memfree.
  */
-ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
-    ULONG *result, PWCHAR *attr )
+ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, LDAPControlW **control, ULONG *result, WCHAR **attr )
 {
-    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
-#ifdef HAVE_LDAP
+    ULONG ret;
     char *attrU = NULL;
-    LDAPControl **controlU = NULL;
-#ifdef HAVE_LDAP_PARSE_SORT_CONTROL
-    unsigned long res;
-#elif defined(HAVE_LDAP_PARSE_SORTRESPONSE_CONTROL)
-    ber_int_t res;
-    LDAPControl *sortcontrol = NULL;
+    LDAPControlU **controlU, *sortcontrol = NULL;
+    int res;
     unsigned int i;
-#endif
 
     TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
 
     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
     if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
+    if (!(controlU = controlarrayWtoU( control ))) return WLDAP32_LDAP_NO_MEMORY;
 
-    controlU = controlarrayWtoU( control );
-    if (!controlU) return WLDAP32_LDAP_NO_MEMORY;
-
-#ifdef HAVE_LDAP_PARSE_SORT_CONTROL
-    if (!(ret = ldap_parse_sort_control( ld->ld, controlU, &res, &attrU )))
-    {
-        *result = res;
-        *attr = strUtoW( attrU );
-    }
-#elif defined(HAVE_LDAP_PARSE_SORTRESPONSE_CONTROL)
     for (i = 0; controlU[i]; i++)
     {
         if (!strcmp( LDAP_SERVER_RESP_SORT_OID, controlU[i]->ldctl_oid ))
@@ -355,16 +317,22 @@ ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
         controlarrayfreeU( controlU );
         return WLDAP32_LDAP_CONTROL_NOT_FOUND;
     }
-    if (!(ret = ldap_parse_sortresponse_control( ld->ld, sortcontrol, &res, &attrU )))
+
+    ret = map_error( ldap_funcs->ldap_parse_sortresponse_control( ld->ld, sortcontrol, &res, &attrU ) );
+    if (ret == WLDAP32_LDAP_SUCCESS)
     {
-        *result = res;
-        *attr = strUtoW( attrU );
+        WCHAR *str;
+        if ((str = strUtoW( attrU )))
+        {
+            *attr = str;
+            *result = res;
+        }
+        else ret = WLDAP32_LDAP_NO_MEMORY;
+        ldap_funcs->ldap_memfree( attrU );
     }
-#endif
-    controlarrayfreeU( controlU );
 
-#endif
-    return map_error( ret );
+    controlarrayfreeU( controlU );
+    return ret;
 }
 
 /***********************************************************************
@@ -372,30 +340,19 @@ ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
  *
  * See ldap_parse_vlv_controlW.
  */
-INT CDECL ldap_parse_vlv_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
-    PULONG targetpos, PULONG listcount,
-    struct WLDAP32_berval **context, PINT errcode )
+int CDECL ldap_parse_vlv_controlA( WLDAP32_LDAP *ld, LDAPControlA **control, ULONG *targetpos, ULONG *listcount,
+    struct WLDAP32_berval **context, int *errcode )
 {
-    int ret = WLDAP32_LDAP_NOT_SUPPORTED;
-#ifdef HAVE_LDAP
+    int ret;
     LDAPControlW **controlW = NULL;
 
-    TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos,
-           listcount, context, errcode );
+    TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos, listcount, context, errcode );
 
     if (!ld) return ~0u;
 
-    if (control) {
-        controlW = controlarrayAtoW( control );
-        if (!controlW) return WLDAP32_LDAP_NO_MEMORY;
-    }
-
-    ret = ldap_parse_vlv_controlW( ld, controlW, targetpos, listcount,
-                                   context, errcode );
-
+    if (control && !(controlW = controlarrayAtoW( control ))) return WLDAP32_LDAP_NO_MEMORY;
+    ret = ldap_parse_vlv_controlW( ld, controlW, targetpos, listcount, context, errcode );
     controlarrayfreeW( controlW );
-
-#endif
     return ret;
 }
 
@@ -419,56 +376,45 @@ INT CDECL ldap_parse_vlv_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
  * NOTES
  *  Free the server context with ber_bvfree.
  */
-INT CDECL ldap_parse_vlv_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
-    PULONG targetpos, PULONG listcount,
-    struct WLDAP32_berval **context, PINT errcode )
+int CDECL ldap_parse_vlv_controlW( WLDAP32_LDAP *ld, LDAPControlW **control, ULONG *targetpos, ULONG *listcount,
+    struct WLDAP32_berval **context, int *errcode )
 {
-    int ret = WLDAP32_LDAP_NOT_SUPPORTED;
-#ifdef HAVE_LDAP
-    LDAPControl **controlU = NULL;
-#ifdef HAVE_LDAP_PARSE_VLV_CONTROL
-    unsigned long pos, count;
-#elif defined(HAVE_LDAP_PARSE_VLVRESPONSE_CONTROL)
-    ber_int_t pos, count;
-    LDAPControl *vlvcontrol = NULL;
+    int ret, pos, count;
+    LDAPControlU **controlU, *vlvcontrolU = NULL;
+    struct bervalU *ctxU;
     unsigned int i;
-#endif
 
-    TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos,
-           listcount, context, errcode );
+    TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos, listcount, context, errcode );
 
     if (!ld || !control) return ~0u;
 
-    controlU = controlarrayWtoU( control );
-    if (!controlU) return WLDAP32_LDAP_NO_MEMORY;
+    if (!(controlU = controlarrayWtoU( control ))) return WLDAP32_LDAP_NO_MEMORY;
 
-#ifdef HAVE_LDAP_PARSE_VLV_CONTROL
-    if (!(ret = ldap_parse_vlv_control( ld->ld, controlU, &pos, &count,
-                                        (struct berval **)context, errcode )))
-    {
-        *targetpos = pos;
-        *listcount = count;
-    }
-#elif defined(HAVE_LDAP_PARSE_VLVRESPONSE_CONTROL)
     for (i = 0; controlU[i]; i++)
     {
         if (!strcmp( LDAP_CONTROL_VLVRESPONSE, controlU[i]->ldctl_oid ))
-            vlvcontrol = controlU[i];
+            vlvcontrolU = controlU[i];
     }
-    if (!vlvcontrol)
+    if (!vlvcontrolU)
     {
         controlarrayfreeU( controlU );
         return WLDAP32_LDAP_CONTROL_NOT_FOUND;
     }
-    if (!(ret = ldap_parse_vlvresponse_control( ld->ld, vlvcontrol, &pos, &count,
-                                                (struct berval **)context, errcode )))
+
+    ret = map_error( ldap_funcs->ldap_parse_vlvresponse_control( ld->ld, vlvcontrolU, &pos, &count, &ctxU, errcode ) );
+    if (ret == WLDAP32_LDAP_SUCCESS)
     {
-        *targetpos = pos;
-        *listcount = count;
+        struct WLDAP32_berval *bv;
+        if ((bv = bervalUtoW( ctxU )))
+        {
+            *context = bv;
+            *targetpos = pos;
+            *listcount = count;
+        }
+        else ret = WLDAP32_LDAP_NO_MEMORY;
+        ldap_funcs->ber_bvfree( ctxU );
     }
-#endif
-    controlarrayfreeU( controlU );
 
-#endif
-    return map_error( ret );
+    controlarrayfreeU( controlU );
+    return ret;
 }
diff --git a/dlls/wldap32/winldap_private.h b/dlls/wldap32/winldap_private.h
index e488db954c8..c8040149290 100644
--- a/dlls/wldap32/winldap_private.h
+++ b/dlls/wldap32/winldap_private.h
@@ -1237,6 +1237,26 @@ static inline LDAPControlW **controlarraydupW( LDAPControlW **controlarray )
     return controlarrayW;
 }
 
+static inline LDAPControlA **controlarrayWtoA( LDAPControlW **controlarray )
+{
+    LDAPControlA **controlarrayA = NULL;
+    DWORD size;
+
+    if (controlarray)
+    {
+        size = sizeof(LDAPControlA *) * (controlarraylenW( controlarray ) + 1);
+        if ((controlarrayA = RtlAllocateHeap( GetProcessHeap(), 0, size )))
+        {
+            LDAPControlW **p = controlarray;
+            LDAPControlA **q = controlarrayA;
+
+            while (*p) *q++ = controlWtoA( *p++ );
+            *q = NULL;
+        }
+    }
+    return controlarrayA;
+}
+
 static inline WCHAR *strUtoW( const char *str )
 {
     WCHAR *ret = NULL;
@@ -1322,6 +1342,26 @@ static inline LDAPControlW *controlUtoW( const LDAPControlU *control )
     return controlW;
 }
 
+static inline LDAPControlW **controlarrayUtoW( LDAPControlU **controlarray )
+{
+    LDAPControlW **controlarrayW = NULL;
+    DWORD size;
+
+    if (controlarray)
+    {
+        size = sizeof(LDAPControlW *) * (controlarraylenU( controlarray ) + 1);
+        if ((controlarrayW = RtlAllocateHeap( GetProcessHeap(), 0, size )))
+        {
+            LDAPControlU **p = controlarray;
+            LDAPControlW **q = controlarrayW;
+
+            while (*p) *q++ = controlUtoW( *p++ );
+            *q = NULL;
+        }
+    }
+    return controlarrayW;
+}
+
 static inline DWORD sortkeyarraylenA( LDAPSortKeyA **sortkeyarray )
 {
     LDAPSortKeyA **p = sortkeyarray;
-- 
2.30.2




More information about the wine-devel mailing list