2005-08-29 16:13:05 +02:00
|
|
|
/*
|
|
|
|
* WLDAP32 - LDAP support for Wine
|
|
|
|
*
|
|
|
|
* Copyright 2005 Hans Leidekker
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-08-29 16:13:05 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2011-09-05 17:23:34 +02:00
|
|
|
#ifdef HAVE_LDAP_H
|
|
|
|
#include <ldap.h>
|
|
|
|
#endif
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
|
|
|
|
#include "winldap_private.h"
|
|
|
|
#include "wldap32.h"
|
2011-09-05 17:23:34 +02:00
|
|
|
#include "wine/debug.h"
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_count_values_len (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Count the number of values in an array of berval structures.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* vals [I] Pointer to an array of berval structures.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The number of values counted.
|
|
|
|
* Failure: 0
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Call ldap_count_values_len with the result of a call to
|
|
|
|
* ldap_get_values_len.
|
|
|
|
*/
|
2006-06-12 21:34:46 +02:00
|
|
|
ULONG CDECL WLDAP32_ldap_count_values_len( struct WLDAP32_berval **vals )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2007-11-08 13:11:34 +01:00
|
|
|
ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
|
2005-08-29 16:13:05 +02:00
|
|
|
#ifdef HAVE_LDAP
|
|
|
|
|
|
|
|
TRACE( "(%p)\n", vals );
|
|
|
|
ret = ldap_count_values_len( (struct berval **)vals );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_count_valuesA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_count_valuesW.
|
|
|
|
*/
|
2006-06-12 21:34:46 +02:00
|
|
|
ULONG CDECL ldap_count_valuesA( PCHAR *vals )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2007-11-08 13:11:34 +01:00
|
|
|
ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
|
2005-08-29 16:13:05 +02:00
|
|
|
#ifdef HAVE_LDAP
|
|
|
|
WCHAR **valsW = NULL;
|
|
|
|
|
|
|
|
TRACE( "(%p)\n", vals );
|
|
|
|
|
2005-11-18 17:29:32 +01:00
|
|
|
if (!vals) return 0;
|
|
|
|
|
|
|
|
valsW = strarrayAtoW( vals );
|
|
|
|
if (!valsW) return WLDAP32_LDAP_NO_MEMORY;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
ret = ldap_count_valuesW( valsW );
|
|
|
|
strarrayfreeW( valsW );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_count_valuesW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Count the number of values in a string array.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* vals [I] Pointer to an array of strings.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The number of values counted.
|
|
|
|
* Failure: 0
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Call ldap_count_valuesW with the result of a call to
|
|
|
|
* ldap_get_valuesW.
|
|
|
|
*/
|
2006-06-12 21:34:46 +02:00
|
|
|
ULONG CDECL ldap_count_valuesW( PWCHAR *vals )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2007-11-08 13:11:34 +01:00
|
|
|
ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
|
2005-08-29 16:13:05 +02:00
|
|
|
#ifdef HAVE_LDAP
|
2005-11-18 17:29:32 +01:00
|
|
|
WCHAR **p = vals;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
TRACE( "(%p)\n", vals );
|
|
|
|
|
2005-11-18 17:29:32 +01:00
|
|
|
if (!vals) return 0;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2005-11-18 17:29:32 +01:00
|
|
|
ret = 0;
|
2005-12-31 13:13:13 +01:00
|
|
|
while (*p++) ret++;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_get_valuesA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_get_valuesW.
|
|
|
|
*/
|
2006-06-12 21:34:46 +02:00
|
|
|
PCHAR * CDECL ldap_get_valuesA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PCHAR attr )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
|
|
|
PCHAR *ret = NULL;
|
|
|
|
#ifdef HAVE_LDAP
|
|
|
|
WCHAR *attrW = NULL, **retW;
|
|
|
|
|
|
|
|
TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_a(attr) );
|
|
|
|
|
|
|
|
if (!ld || !entry || !attr) return NULL;
|
|
|
|
|
|
|
|
attrW = strAtoW( attr );
|
|
|
|
if (!attrW) return NULL;
|
|
|
|
|
|
|
|
retW = ldap_get_valuesW( ld, entry, attrW );
|
|
|
|
|
|
|
|
ret = strarrayWtoA( retW );
|
|
|
|
ldap_value_freeW( retW );
|
|
|
|
strfreeW( attrW );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-11-21 12:57:52 +01:00
|
|
|
#ifdef HAVE_LDAP
|
2005-11-18 17:29:32 +01:00
|
|
|
static char *bv2str( struct berval *bv )
|
|
|
|
{
|
|
|
|
char *str = NULL;
|
|
|
|
unsigned int len = bv->bv_len;
|
|
|
|
|
2018-02-20 12:06:10 +01:00
|
|
|
if ((str = heap_alloc( len + 1 )))
|
2005-11-18 17:29:32 +01:00
|
|
|
{
|
|
|
|
memcpy( str, bv->bv_val, len );
|
|
|
|
str[len] = '\0';
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char **bv2str_array( struct berval **bv )
|
|
|
|
{
|
|
|
|
unsigned int len = 0, i = 0;
|
|
|
|
struct berval **p = bv;
|
|
|
|
char **str;
|
|
|
|
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
len++;
|
|
|
|
p++;
|
|
|
|
}
|
2018-02-20 12:06:10 +01:00
|
|
|
if (!(str = heap_alloc( (len + 1) * sizeof(char *) ))) return NULL;
|
2005-11-18 17:29:32 +01:00
|
|
|
|
|
|
|
p = bv;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
str[i] = bv2str( *p );
|
|
|
|
if (!str[i])
|
|
|
|
{
|
2018-02-20 12:06:10 +01:00
|
|
|
while (i > 0) heap_free( str[--i] );
|
|
|
|
heap_free( str );
|
2005-11-18 17:29:32 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
str[i] = NULL;
|
|
|
|
return str;
|
|
|
|
}
|
2005-11-21 12:57:52 +01:00
|
|
|
#endif
|
2005-11-18 17:29:32 +01:00
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_get_valuesW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Retrieve string values for a given attribute.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* entry [I] Entry to retrieve values from.
|
|
|
|
* attr [I] Attribute to retrieve values for.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to a character array holding the values.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Call ldap_get_valuesW with the result of a call to
|
|
|
|
* ldap_first_entry or ldap_next_entry. Free the returned
|
|
|
|
* array with a call to ldap_value_freeW.
|
|
|
|
*/
|
2006-06-12 21:34:46 +02:00
|
|
|
PWCHAR * CDECL ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PWCHAR attr )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
|
|
|
PWCHAR *ret = NULL;
|
|
|
|
#ifdef HAVE_LDAP
|
|
|
|
char *attrU = NULL, **retU;
|
2005-11-18 17:29:32 +01:00
|
|
|
struct berval **bv;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_w(attr) );
|
|
|
|
|
|
|
|
if (!ld || !entry || !attr) return NULL;
|
|
|
|
|
|
|
|
attrU = strWtoU( attr );
|
|
|
|
if (!attrU) return NULL;
|
|
|
|
|
2020-04-03 10:56:57 +02:00
|
|
|
bv = ldap_get_values_len( ld->ld, entry, attrU );
|
2020-03-23 14:14:22 +01:00
|
|
|
if (bv)
|
|
|
|
{
|
|
|
|
retU = bv2str_array( bv );
|
|
|
|
ret = strarrayUtoW( retU );
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2020-03-23 14:14:22 +01:00
|
|
|
ldap_value_free_len( bv );
|
|
|
|
strarrayfreeU( retU );
|
|
|
|
}
|
2005-08-29 16:13:05 +02:00
|
|
|
strfreeU( attrU );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_get_values_lenA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_get_values_lenW.
|
|
|
|
*/
|
2006-06-12 21:34:46 +02:00
|
|
|
struct WLDAP32_berval ** CDECL ldap_get_values_lenA( WLDAP32_LDAP *ld,
|
2005-12-31 13:13:13 +01:00
|
|
|
WLDAP32_LDAPMessage *message, PCHAR attr )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LDAP
|
|
|
|
WCHAR *attrW = NULL;
|
|
|
|
struct WLDAP32_berval **ret;
|
|
|
|
|
|
|
|
TRACE( "(%p, %p, %s)\n", ld, message, debugstr_a(attr) );
|
|
|
|
|
|
|
|
if (!ld || !message || !attr) return NULL;
|
|
|
|
|
|
|
|
attrW = strAtoW( attr );
|
|
|
|
if (!attrW) return NULL;
|
|
|
|
|
|
|
|
ret = ldap_get_values_lenW( ld, message, attrW );
|
|
|
|
|
|
|
|
strfreeW( attrW );
|
|
|
|
return ret;
|
|
|
|
|
2007-07-23 22:25:50 +02:00
|
|
|
#else
|
2005-08-29 16:13:05 +02:00
|
|
|
return NULL;
|
2007-07-23 22:25:50 +02:00
|
|
|
#endif
|
2005-08-29 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_get_values_lenW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Retrieve binary values for a given attribute.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* message [I] Entry to retrieve values from.
|
|
|
|
* attr [I] Attribute to retrieve values for.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to a berval array holding the values.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Call ldap_get_values_lenW with the result of a call to
|
|
|
|
* ldap_first_entry or ldap_next_entry. Free the returned
|
|
|
|
* array with a call to ldap_value_free_len.
|
|
|
|
*/
|
2006-06-12 21:34:46 +02:00
|
|
|
struct WLDAP32_berval ** CDECL ldap_get_values_lenW( WLDAP32_LDAP *ld,
|
2005-12-31 13:13:13 +01:00
|
|
|
WLDAP32_LDAPMessage *message, PWCHAR attr )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LDAP
|
|
|
|
char *attrU = NULL;
|
|
|
|
struct berval **ret;
|
|
|
|
|
|
|
|
TRACE( "(%p, %p, %s)\n", ld, message, debugstr_w(attr) );
|
|
|
|
|
|
|
|
if (!ld || !message || !attr) return NULL;
|
|
|
|
|
|
|
|
attrU = strWtoU( attr );
|
|
|
|
if (!attrU) return NULL;
|
|
|
|
|
2020-04-03 10:56:57 +02:00
|
|
|
ret = ldap_get_values_len( ld->ld, message, attrU );
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
strfreeU( attrU );
|
|
|
|
return (struct WLDAP32_berval **)ret;
|
|
|
|
|
2007-07-23 22:25:50 +02:00
|
|
|
#else
|
2005-08-29 16:13:05 +02:00
|
|
|
return NULL;
|
2007-07-23 22:25:50 +02:00
|
|
|
#endif
|
2005-08-29 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_value_free_len (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Free an array of berval structures.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* vals [I] Array of berval structures.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: LDAP_SUCCESS
|
|
|
|
* Failure: An LDAP error code.
|
|
|
|
*/
|
2006-06-12 21:34:46 +02:00
|
|
|
ULONG CDECL WLDAP32_ldap_value_free_len( struct WLDAP32_berval **vals )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LDAP
|
|
|
|
|
|
|
|
TRACE( "(%p)\n", vals );
|
|
|
|
ldap_value_free_len( (struct berval **)vals );
|
|
|
|
|
|
|
|
#endif
|
2007-11-08 13:11:34 +01:00
|
|
|
return WLDAP32_LDAP_SUCCESS;
|
2005-08-29 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_value_freeA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_value_freeW.
|
|
|
|
*/
|
2006-06-12 21:34:46 +02:00
|
|
|
ULONG CDECL ldap_value_freeA( PCHAR *vals )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
|
|
|
TRACE( "(%p)\n", vals );
|
|
|
|
|
|
|
|
strarrayfreeA( vals );
|
2007-11-08 13:11:34 +01:00
|
|
|
return WLDAP32_LDAP_SUCCESS;
|
2005-08-29 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_value_freeW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Free an array of string values.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* vals [I] Array of string values.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: LDAP_SUCCESS
|
|
|
|
* Failure: An LDAP error code.
|
|
|
|
*/
|
2006-06-12 21:34:46 +02:00
|
|
|
ULONG CDECL ldap_value_freeW( PWCHAR *vals )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
|
|
|
TRACE( "(%p)\n", vals );
|
|
|
|
|
|
|
|
strarrayfreeW( vals );
|
2007-11-08 13:11:34 +01:00
|
|
|
return WLDAP32_LDAP_SUCCESS;
|
2005-08-29 16:13:05 +02:00
|
|
|
}
|