Commit 1805b3a1 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wldap32: Move support for add functions to a new Unix library.

parent 1c35d29e
......@@ -15,6 +15,7 @@ C_SRCS = \
error.c \
extended.c \
init.c \
libldap.c \
main.c \
misc.c \
modify.c \
......
......@@ -128,11 +128,11 @@ static BOOL has_ldap_scheme( char *url )
static char *join_hostnames( const char *scheme, char **hostnames, ULONG portnumber )
{
char *res, *p, *q, **v;
unsigned int i = 0, size = 0;
unsigned int i = 0, size = 0;
static const char sep[] = " ", fmt[] = ":%d";
char port[7];
sprintf( port, fmt, portnumber );
sprintf( port, fmt, portnumber );
for (v = hostnames; *v; v++)
{
......@@ -147,7 +147,7 @@ static char *join_hostnames( const char *scheme, char **hostnames, ULONG portnum
size += strlen( *v );
if (!strchr( q, ':' ))
if (!strchr( q, ':' ))
size += strlen( port );
i++;
......@@ -212,7 +212,7 @@ static WLDAP32_LDAP *create_context( const char *url )
ld = heap_alloc_zero( sizeof( *ld ));
if (!ld) return NULL;
if (ldap_initialize( &ld->ld, url ) != LDAP_SUCCESS)
if (ldap_initialize( (LDAP **)&ld->ld, url ) != LDAP_SUCCESS)
{
heap_free( ld );
return NULL;
......@@ -307,7 +307,7 @@ exit:
/***********************************************************************
* ldap_connect (WLDAP32.@)
*
* Connect to an LDAP server.
* Connect to an LDAP server.
*
* PARAMS
* ld [I] Pointer to an LDAP context.
......
/*
* Unix interface for libldap
*
* Copyright 2021 Hans Leidekker for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#if 0
#pragma makedep unix
#endif
#include "config.h"
#ifdef HAVE_LDAP
#include <stdarg.h>
#ifdef HAVE_LDAP_H
# include <ldap.h>
#endif
#ifdef HAVE_SASL_SASL_H
# include <sasl/sasl.h>
#endif
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
#include "winternl.h"
#include "winbase.h"
#include "wine/debug.h"
#include "winldap_private.h"
C_ASSERT( sizeof(BerValueU) == sizeof(BerValue) );
C_ASSERT( sizeof(LDAPModU) == sizeof(LDAPMod) );
C_ASSERT( sizeof(LDAPControlU) == sizeof(LDAPControl) );
C_ASSERT( sizeof(LDAPSortKeyU) == sizeof(LDAPSortKey) );
C_ASSERT( sizeof(LDAPVLVInfoU) == sizeof(LDAPVLVInfo) );
static LDAPMod *nullattrs[] = { NULL };
int CDECL wrap_ldap_add_ext( void *ld, char *dn, LDAPModU **attrs, LDAPControlU **serverctrls,
LDAPControlU **clientctrls, ULONG *msg )
{
int dummy;
return ldap_add_ext( ld, dn ? dn : "", attrs ? (LDAPMod **)attrs : nullattrs, (LDAPControl **)serverctrls,
(LDAPControl **)clientctrls, msg ? (int *)msg : &dummy );
}
int CDECL wrap_ldap_add_ext_s( void *ld, char *dn, LDAPModU **attrs, LDAPControlU **serverctrls,
LDAPControlU **clientctrls )
{
return ldap_add_ext_s( ld, dn ? dn : "", attrs ? (LDAPMod **)attrs : nullattrs, (LDAPControl **)serverctrls,
(LDAPControl **)clientctrls );
}
static const struct ldap_funcs funcs =
{
wrap_ldap_add_ext,
wrap_ldap_add_ext_s,
};
NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
{
if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS;
*(const struct ldap_funcs **)ptr_out = &funcs;
return STATUS_SUCCESS;
}
#endif /* HAVE_LDAP */
/*
* Copyright 2021 Hans Leidekker for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* compatible with structures defined in ldap.h */
typedef struct bervalU
{
unsigned long bv_len;
char *bv_val;
} BerValueU;
typedef struct
{
int mod_op;
char *mod_type;
union
{
char **modv_strvals;
struct bervalU **modv_bvals;
} mod_vals;
} LDAPModU;
typedef struct
{
char *ldctl_oid;
struct bervalU ldctl_value;
char ldctl_iscritical;
} LDAPControlU;
typedef struct
{
char *attributeType;
char *orderingRule;
int reverseOrder;
} LDAPSortKeyU;
typedef struct
{
int ldvlv_version;
int ldvlv_before_count;
int ldvlv_after_count;
int ldvlv_offset;
int ldvlv_count;
struct bervalU *ldvlv_attrvalue;
struct bervalU *ldvlv_context;
void *ldvlv_extradata;
} LDAPVLVInfoU;
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;
struct ldap_funcs
{
int (CDECL *ldap_add_ext)(void *, char *, LDAPModU **, LDAPControlU **, LDAPControlU **, ULONG *);
int (CDECL *ldap_add_ext_s)(void *, char *, LDAPModU **, LDAPControlU **, LDAPControlU **);
};
extern const struct ldap_funcs *ldap_funcs;
......@@ -18,18 +18,20 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/debug.h"
#include <stdarg.h>
#include "windef.h"
#include "winternl.h"
#include "winbase.h"
#include "wine/debug.h"
#include "libldap.h"
HINSTANCE hwldap32;
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
const struct ldap_funcs *ldap_funcs = NULL;
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
{
TRACE( "(%p, %d, %p)\n", hinst, reason, reserved );
......@@ -39,6 +41,8 @@ BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
case DLL_PROCESS_ATTACH:
hwldap32 = hinst;
DisableThreadLibraryCalls( hinst );
if (__wine_init_unix_lib( hinst, reason, NULL, &ldap_funcs ))
ERR( "No libldap support, expect problems\n" );
break;
}
return TRUE;
......
......@@ -30,14 +30,7 @@ ULONG map_error( int ) DECLSPEC_HIDDEN;
* to and from ansi (A), wide character (W) and utf8 (U) encodings.
*/
static inline char *strdupU( const char *src )
{
char *dst;
if (!src) return NULL;
if ((dst = heap_alloc( (strlen( src ) + 1) * sizeof(char) ))) strcpy( dst, src );
return dst;
}
#ifdef HAVE_LDAP
static inline WCHAR *strdupW( const WCHAR *src )
{
WCHAR *dst;
......@@ -264,16 +257,6 @@ static inline LPWSTR *strarraydupW( LPWSTR *strarray )
return strarrayW;
}
static inline void strarrayfreeA( LPSTR *strarray )
{
if (strarray)
{
LPSTR *p = strarray;
while (*p) strfreeA( *p++ );
heap_free( strarray );
}
}
static inline void strarrayfreeW( LPWSTR *strarray )
{
if (strarray)
......@@ -316,6 +299,17 @@ static inline void bvarrayfreeW( struct WLDAP32_berval **bv )
while (*p) heap_free( *p++ );
heap_free( bv );
}
#endif
static inline void strarrayfreeA( LPSTR *strarray )
{
if (strarray)
{
LPSTR *p = strarray;
while (*p) strfreeA( *p++ );
heap_free( strarray );
}
}
#ifdef HAVE_LDAP
......
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