Commit e21c9596 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

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

parent 22b26a20
...@@ -18,49 +18,35 @@ ...@@ -18,49 +18,35 @@
* 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 "wine/port.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 "winnls.h" #include "winnls.h"
#include "winldap_private.h"
#include "wldap32.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "winldap_private.h"
#ifdef HAVE_LDAP
WINE_DEFAULT_DEBUG_CHANNEL(wldap32); WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
#endif
/*********************************************************************** /***********************************************************************
* ldap_dn2ufnA (WLDAP32.@) * ldap_dn2ufnA (WLDAP32.@)
* *
* See ldap_dn2ufnW. * See ldap_dn2ufnW.
*/ */
PCHAR CDECL ldap_dn2ufnA( PCHAR dn ) char * CDECL ldap_dn2ufnA( char *dn )
{ {
PCHAR ret = NULL; char *ret;
#ifdef HAVE_LDAP
WCHAR *dnW, *retW; WCHAR *dnW, *retW;
TRACE( "(%s)\n", debugstr_a(dn) ); TRACE( "(%s)\n", debugstr_a(dn) );
dnW = strAtoW( dn ); if (!(dnW = strAtoW( dn ))) return NULL;
if (!dnW) return NULL;
retW = ldap_dn2ufnW( dnW ); retW = ldap_dn2ufnW( dnW );
ret = strWtoA( retW ); ret = strWtoA( retW );
strfreeW( dnW ); strfreeW( dnW );
ldap_memfreeW( retW ); ldap_memfreeW( retW );
#endif
return ret; return ret;
} }
...@@ -73,30 +59,26 @@ PCHAR CDECL ldap_dn2ufnA( PCHAR dn ) ...@@ -73,30 +59,26 @@ PCHAR CDECL ldap_dn2ufnA( PCHAR dn )
* dn [I] DN to convert. * dn [I] DN to convert.
* *
* RETURNS * RETURNS
* Success: Pointer to a string containing the user-friendly name. * Success: Pointer to a string containing the user-friendly name.
* Failure: NULL * Failure: NULL
* *
* NOTES * NOTES
* Free the string with ldap_memfree. * Free the string with ldap_memfree.
*/ */
PWCHAR CDECL ldap_dn2ufnW( PWCHAR dn ) WCHAR * CDECL ldap_dn2ufnW( WCHAR *dn )
{ {
PWCHAR ret = NULL; WCHAR *ret;
#ifdef HAVE_LDAP
char *dnU, *retU; char *dnU, *retU;
TRACE( "(%s)\n", debugstr_w(dn) ); TRACE( "(%s)\n", debugstr_w(dn) );
dnU = strWtoU( dn ); if (!(dnU = strWtoU( dn ))) return NULL;
if (!dnU) return NULL;
retU = ldap_dn2ufn( dnU ); retU = ldap_funcs->ldap_dn2ufn( dnU );
ret = strUtoW( retU ); ret = strUtoW( retU );
strfreeU( dnU ); strfreeU( dnU );
ldap_memfree( retU ); ldap_funcs->ldap_memfree( retU );
#endif
return ret; return ret;
} }
...@@ -105,24 +87,20 @@ PWCHAR CDECL ldap_dn2ufnW( PWCHAR dn ) ...@@ -105,24 +87,20 @@ PWCHAR CDECL ldap_dn2ufnW( PWCHAR dn )
* *
* See ldap_explode_dnW. * See ldap_explode_dnW.
*/ */
PCHAR * CDECL ldap_explode_dnA( PCHAR dn, ULONG notypes ) char ** CDECL ldap_explode_dnA( char *dn, ULONG notypes )
{ {
PCHAR *ret = NULL; char **ret;
#ifdef HAVE_LDAP
WCHAR *dnW, **retW; WCHAR *dnW, **retW;
TRACE( "(%s, 0x%08x)\n", debugstr_a(dn), notypes ); TRACE( "(%s, 0x%08x)\n", debugstr_a(dn), notypes );
dnW = strAtoW( dn ); if (!(dnW = strAtoW( dn ))) return NULL;
if (!dnW) return NULL;
retW = ldap_explode_dnW( dnW, notypes ); retW = ldap_explode_dnW( dnW, notypes );
ret = strarrayWtoA( retW ); ret = strarrayWtoA( retW );
strfreeW( dnW ); strfreeW( dnW );
ldap_value_freeW( retW ); ldap_value_freeW( retW );
#endif
return ret; return ret;
} }
...@@ -137,30 +115,26 @@ PCHAR * CDECL ldap_explode_dnA( PCHAR dn, ULONG notypes ) ...@@ -137,30 +115,26 @@ PCHAR * CDECL ldap_explode_dnA( PCHAR dn, ULONG notypes )
* *
* RETURNS * RETURNS
* Success: Pointer to a NULL-terminated array that contains the DN * Success: Pointer to a NULL-terminated array that contains the DN
* components. * components.
* Failure: NULL * Failure: NULL
* *
* NOTES * NOTES
* Free the string array with ldap_value_free. * Free the string array with ldap_value_free.
*/ */
PWCHAR * CDECL ldap_explode_dnW( PWCHAR dn, ULONG notypes ) WCHAR ** CDECL ldap_explode_dnW( WCHAR *dn, ULONG notypes )
{ {
PWCHAR *ret = NULL; WCHAR **ret;
#ifdef HAVE_LDAP
char *dnU, **retU; char *dnU, **retU;
TRACE( "(%s, 0x%08x)\n", debugstr_w(dn), notypes ); TRACE( "(%s, 0x%08x)\n", debugstr_w(dn), notypes );
dnU = strWtoU( dn ); if (!(dnU = strWtoU( dn ))) return NULL;
if (!dnU) return NULL;
retU = ldap_explode_dn( dnU, notypes ); retU = ldap_funcs->ldap_explode_dn( dnU, notypes );
ret = strarrayUtoW( retU ); ret = strarrayUtoW( retU );
strfreeU( dnU ); strfreeU( dnU );
ldap_memvfree( (void **)retU ); ldap_funcs->ldap_memvfree( (void **)retU );
#endif
return ret; return ret;
} }
...@@ -169,11 +143,10 @@ PWCHAR * CDECL ldap_explode_dnW( PWCHAR dn, ULONG notypes ) ...@@ -169,11 +143,10 @@ PWCHAR * CDECL ldap_explode_dnW( PWCHAR dn, ULONG notypes )
* *
* See ldap_get_dnW. * See ldap_get_dnW.
*/ */
PCHAR CDECL ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry ) char * CDECL ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
{ {
PCHAR ret = NULL; char *ret;
#ifdef HAVE_LDAP WCHAR *retW;
PWCHAR retW;
TRACE( "(%p, %p)\n", ld, entry ); TRACE( "(%p, %p)\n", ld, entry );
...@@ -183,8 +156,6 @@ PCHAR CDECL ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry ) ...@@ -183,8 +156,6 @@ PCHAR CDECL ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
ret = strWtoA( retW ); ret = strWtoA( retW );
ldap_memfreeW( retW ); ldap_memfreeW( retW );
#endif
return ret; return ret;
} }
...@@ -204,22 +175,19 @@ PCHAR CDECL ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry ) ...@@ -204,22 +175,19 @@ PCHAR CDECL ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
* NOTES * NOTES
* Free the string with ldap_memfree. * Free the string with ldap_memfree.
*/ */
PWCHAR CDECL ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry ) WCHAR * CDECL ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
{ {
PWCHAR ret = NULL; WCHAR *ret;
#ifdef HAVE_LDAP
char *retU; char *retU;
TRACE( "(%p, %p)\n", ld, entry ); TRACE( "(%p, %p)\n", ld, entry );
if (!ld || !entry) return NULL; if (!ld || !entry) return NULL;
retU = ldap_get_dn( ld->ld, entry->Request ); retU = ldap_funcs->ldap_get_dn( ld->ld, entry->Request );
ret = strUtoW( retU ); ret = strUtoW( retU );
ldap_memfree( retU ); ldap_funcs->ldap_memfree( retU );
#endif
return ret; return ret;
} }
...@@ -228,34 +196,28 @@ PWCHAR CDECL ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry ) ...@@ -228,34 +196,28 @@ PWCHAR CDECL ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
* *
* See ldap_ufn2dnW. * See ldap_ufn2dnW.
*/ */
ULONG CDECL ldap_ufn2dnA( PCHAR ufn, PCHAR *dn ) ULONG CDECL ldap_ufn2dnA( char *ufn, char **dn )
{ {
ULONG ret = WLDAP32_LDAP_SUCCESS; ULONG ret;
#ifdef HAVE_LDAP WCHAR *ufnW = NULL, *dnW = NULL;
PWCHAR ufnW = NULL, dnW = NULL;
TRACE( "(%s, %p)\n", debugstr_a(ufn), dn ); TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
if (!dn) return WLDAP32_LDAP_PARAM_ERROR; if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
*dn = NULL; *dn = NULL;
if (ufn && !(ufnW = strAtoW( ufn ))) return WLDAP32_LDAP_NO_MEMORY;
if (ufn) {
ufnW = strAtoW( ufn );
if (!ufnW) return WLDAP32_LDAP_NO_MEMORY;
}
ret = ldap_ufn2dnW( ufnW, &dnW ); ret = ldap_ufn2dnW( ufnW, &dnW );
if (dnW)
if (dnW) { {
*dn = strWtoA( dnW ); char *str;
if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY; if (!(str = strWtoA( dnW ))) ret = WLDAP32_LDAP_NO_MEMORY;
else *dn = str;
} }
strfreeW( ufnW ); strfreeW( ufnW );
ldap_memfreeW( dnW ); ldap_memfreeW( dnW );
#endif
return ret; return ret;
} }
...@@ -266,7 +228,7 @@ ULONG CDECL ldap_ufn2dnA( PCHAR ufn, PCHAR *dn ) ...@@ -266,7 +228,7 @@ ULONG CDECL ldap_ufn2dnA( PCHAR ufn, PCHAR *dn )
* *
* PARAMS * PARAMS
* ufn [I] User-friendly name to convert. * ufn [I] User-friendly name to convert.
* dn [O] Receives a pointer to a string containing the DN. * dn [O] Receives a pointer to a string containing the DN.
* *
* RETURNS * RETURNS
* Success: LDAP_SUCCESS * Success: LDAP_SUCCESS
...@@ -275,10 +237,9 @@ ULONG CDECL ldap_ufn2dnA( PCHAR ufn, PCHAR *dn ) ...@@ -275,10 +237,9 @@ ULONG CDECL ldap_ufn2dnA( PCHAR ufn, PCHAR *dn )
* NOTES * NOTES
* Free the string with ldap_memfree. * Free the string with ldap_memfree.
*/ */
ULONG CDECL ldap_ufn2dnW( PWCHAR ufn, PWCHAR *dn ) ULONG CDECL ldap_ufn2dnW( WCHAR *ufn, WCHAR **dn )
{ {
ULONG ret = WLDAP32_LDAP_SUCCESS; ULONG ret = WLDAP32_LDAP_SUCCESS;
#ifdef HAVE_LDAP
char *ufnU = NULL; char *ufnU = NULL;
TRACE( "(%s, %p)\n", debugstr_w(ufn), dn ); TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
...@@ -286,18 +247,16 @@ ULONG CDECL ldap_ufn2dnW( PWCHAR ufn, PWCHAR *dn ) ...@@ -286,18 +247,16 @@ ULONG CDECL ldap_ufn2dnW( PWCHAR ufn, PWCHAR *dn )
if (!dn) return WLDAP32_LDAP_PARAM_ERROR; if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
*dn = NULL; *dn = NULL;
if (ufn)
if (ufn) { {
ufnU = strWtoU( ufn ); WCHAR *str;
if (!ufnU) return WLDAP32_LDAP_NO_MEMORY; if (!(ufnU = strWtoU( ufn ))) return WLDAP32_LDAP_NO_MEMORY;
/* FIXME: do more than just a copy */ /* FIXME: do more than just a copy */
*dn = strUtoW( ufnU ); if (!(str = strUtoW( ufnU ))) ret = WLDAP32_LDAP_NO_MEMORY;
if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY; else *dn = str;
} }
strfreeU( ufnU ); strfreeU( ufnU );
#endif
return ret; return ret;
} }
...@@ -369,6 +369,21 @@ int CDECL wrap_ldap_delete_ext_s( void *ld, const char *dn, LDAPControlU **serve ...@@ -369,6 +369,21 @@ int CDECL wrap_ldap_delete_ext_s( void *ld, const char *dn, LDAPControlU **serve
return ldap_delete_ext_s( ld, dn ? dn : "", (LDAPControl **)serverctrls, (LDAPControl **)clientctrls ); return ldap_delete_ext_s( ld, dn ? dn : "", (LDAPControl **)serverctrls, (LDAPControl **)clientctrls );
} }
char * CDECL wrap_ldap_dn2ufn( const char *dn )
{
return ldap_dn2ufn( dn );
}
char ** CDECL wrap_ldap_explode_dn( const char *dn, int notypes )
{
return ldap_explode_dn( dn, notypes );
}
char * CDECL wrap_ldap_get_dn( void *ld, void *entry )
{
return ldap_get_dn( ld, entry );
}
char * CDECL wrap_ldap_first_attribute( void *ld, void *entry, void **ber ) char * CDECL wrap_ldap_first_attribute( void *ld, void *entry, void **ber )
{ {
return ldap_first_attribute( ld, entry, (BerElement **)ber ); return ldap_first_attribute( ld, entry, (BerElement **)ber );
...@@ -389,6 +404,11 @@ void CDECL wrap_ldap_memfree( void *ptr ) ...@@ -389,6 +404,11 @@ void CDECL wrap_ldap_memfree( void *ptr )
return ldap_memfree( ptr ); return ldap_memfree( ptr );
} }
void CDECL wrap_ldap_memvfree( void **ptr )
{
ldap_memvfree( ptr );
}
int CDECL wrap_ldap_msgfree( void *msg ) int CDECL wrap_ldap_msgfree( void *msg )
{ {
return ldap_msgfree( msg ); return ldap_msgfree( msg );
...@@ -508,10 +528,14 @@ static const struct ldap_funcs funcs = ...@@ -508,10 +528,14 @@ static const struct ldap_funcs funcs =
wrap_ldap_create_vlv_control, wrap_ldap_create_vlv_control,
wrap_ldap_delete_ext, wrap_ldap_delete_ext,
wrap_ldap_delete_ext_s, wrap_ldap_delete_ext_s,
wrap_ldap_dn2ufn,
wrap_ldap_explode_dn,
wrap_ldap_get_dn,
wrap_ldap_first_attribute, wrap_ldap_first_attribute,
wrap_ldap_first_entry, wrap_ldap_first_entry,
wrap_ldap_first_reference, wrap_ldap_first_reference,
wrap_ldap_memfree, wrap_ldap_memfree,
wrap_ldap_memvfree,
wrap_ldap_msgfree, wrap_ldap_msgfree,
wrap_ldap_next_attribute, wrap_ldap_next_attribute,
wrap_ldap_next_entry, wrap_ldap_next_entry,
......
...@@ -112,10 +112,14 @@ extern int CDECL wrap_ldap_create_sort_control(void *, LDAPSortKeyU **, int, LDA ...@@ -112,10 +112,14 @@ extern int CDECL wrap_ldap_create_sort_control(void *, LDAPSortKeyU **, int, LDA
extern int CDECL wrap_ldap_create_vlv_control(void *, LDAPVLVInfoU *, LDAPControlU **) DECLSPEC_HIDDEN; extern int CDECL wrap_ldap_create_vlv_control(void *, LDAPVLVInfoU *, LDAPControlU **) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_delete_ext(void *, const char *, LDAPControlU **, LDAPControlU **, ULONG *) DECLSPEC_HIDDEN; extern int CDECL wrap_ldap_delete_ext(void *, const char *, LDAPControlU **, LDAPControlU **, ULONG *) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_delete_ext_s(void *, const char *, LDAPControlU **, LDAPControlU **) DECLSPEC_HIDDEN; extern int CDECL wrap_ldap_delete_ext_s(void *, const char *, LDAPControlU **, LDAPControlU **) DECLSPEC_HIDDEN;
extern char * CDECL wrap_ldap_dn2ufn(const char *) DECLSPEC_HIDDEN;
extern char ** CDECL wrap_ldap_explode_dn(const char *, int) DECLSPEC_HIDDEN;
extern char * CDECL wrap_ldap_get_dn(void *, void *) DECLSPEC_HIDDEN;
extern char * CDECL wrap_ldap_first_attribute(void *, void *, void **) 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_entry(void *, void *) DECLSPEC_HIDDEN;
extern void * CDECL wrap_ldap_first_reference(void *, void *) DECLSPEC_HIDDEN; extern void * CDECL wrap_ldap_first_reference(void *, void *) DECLSPEC_HIDDEN;
extern void CDECL wrap_ldap_memfree(void *) DECLSPEC_HIDDEN; extern void CDECL wrap_ldap_memfree(void *) DECLSPEC_HIDDEN;
extern void CDECL wrap_ldap_memvfree(void **) DECLSPEC_HIDDEN;
extern int CDECL wrap_ldap_msgfree(void *) DECLSPEC_HIDDEN; extern int CDECL wrap_ldap_msgfree(void *) DECLSPEC_HIDDEN;
extern char * CDECL wrap_ldap_next_attribute(void *, void *, 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_entry(void *, void *) DECLSPEC_HIDDEN;
...@@ -166,10 +170,14 @@ struct ldap_funcs ...@@ -166,10 +170,14 @@ struct ldap_funcs
int (CDECL *ldap_create_vlv_control)(void *, LDAPVLVInfoU *, LDAPControlU **); int (CDECL *ldap_create_vlv_control)(void *, LDAPVLVInfoU *, LDAPControlU **);
int (CDECL *ldap_delete_ext)(void *, const char *, LDAPControlU **, LDAPControlU **, ULONG *); int (CDECL *ldap_delete_ext)(void *, const char *, LDAPControlU **, LDAPControlU **, ULONG *);
int (CDECL *ldap_delete_ext_s)(void *, const char *, LDAPControlU **, LDAPControlU **); int (CDECL *ldap_delete_ext_s)(void *, const char *, LDAPControlU **, LDAPControlU **);
char * (CDECL *ldap_dn2ufn)(const char *);
char ** (CDECL *ldap_explode_dn)(const char *, int);
char * (CDECL *ldap_get_dn)(void *, void *);
char * (CDECL *ldap_first_attribute)(void *, void *, void **); char * (CDECL *ldap_first_attribute)(void *, void *, void **);
void * (CDECL *ldap_first_entry)(void *, void *); void * (CDECL *ldap_first_entry)(void *, void *);
void * (CDECL *ldap_first_reference)(void *, void *); void * (CDECL *ldap_first_reference)(void *, void *);
void (CDECL *ldap_memfree)(void *); void (CDECL *ldap_memfree)(void *);
void (CDECL *ldap_memvfree)(void **);
int (CDECL *ldap_msgfree)(void *); int (CDECL *ldap_msgfree)(void *);
char * (CDECL *ldap_next_attribute)(void *, void *, void *); char * (CDECL *ldap_next_attribute)(void *, void *, void *);
void * (CDECL *ldap_next_entry)(void *, void *); void * (CDECL *ldap_next_entry)(void *, void *);
......
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