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 <stdarg.h>
|
2021-04-19 10:04:52 +02:00
|
|
|
#include <stdlib.h>
|
2005-08-29 16:13:05 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
2021-04-19 10:04:54 +02:00
|
|
|
#include "winldap.h"
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2011-09-05 17:23:34 +02:00
|
|
|
#include "wine/debug.h"
|
2021-04-19 10:04:49 +02:00
|
|
|
#include "winldap_private.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
|
2021-04-19 10:04:49 +02:00
|
|
|
* values [I] Pointer to an array of berval structures.
|
2005-12-31 13:13:13 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_count_values_len( struct berval **values )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2021-04-19 10:04:49 +02:00
|
|
|
ULONG ret = 0;
|
2021-04-19 10:04:54 +02:00
|
|
|
struct berval **ptr = values;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
TRACE( "(%p)\n", values );
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
if (!values) return 0;
|
|
|
|
while (*ptr++) ret++;
|
2005-08-29 16:13:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_count_valuesA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_count_valuesW.
|
|
|
|
*/
|
2021-04-19 10:04:49 +02:00
|
|
|
ULONG CDECL ldap_count_valuesA( char **values )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2021-04-19 10:04:49 +02:00
|
|
|
ULONG ret = 0;
|
|
|
|
char **ptr = values;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
TRACE( "(%p)\n", values );
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
if (!values) return 0;
|
|
|
|
while (*ptr++) ret++;
|
2005-08-29 16:13:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_count_valuesW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Count the number of values in a string array.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2021-04-19 10:04:49 +02:00
|
|
|
* values [I] Pointer to an array of strings.
|
2005-12-31 13:13:13 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The number of values counted.
|
|
|
|
* Failure: 0
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Call ldap_count_valuesW with the result of a call to
|
|
|
|
* ldap_get_valuesW.
|
|
|
|
*/
|
2021-04-19 10:04:49 +02:00
|
|
|
ULONG CDECL ldap_count_valuesW( WCHAR **values )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2021-04-19 10:04:49 +02:00
|
|
|
ULONG ret = 0;
|
|
|
|
WCHAR **p = values;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
TRACE( "(%p)\n", values );
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
if (!values) return 0;
|
2005-12-31 13:13:13 +01:00
|
|
|
while (*p++) ret++;
|
2005-08-29 16:13:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_get_valuesA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_get_valuesW.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
char ** CDECL ldap_get_valuesA( LDAP *ld, LDAPMessage *entry, char *attr )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2021-04-19 10:04:49 +02:00
|
|
|
char **ret;
|
2005-08-29 16:13:05 +02:00
|
|
|
WCHAR *attrW = NULL, **retW;
|
|
|
|
|
|
|
|
TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_a(attr) );
|
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
if (!ld || !entry || !attr || !(attrW = strAtoW( attr ))) return NULL;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
retW = ldap_get_valuesW( ld, entry, attrW );
|
|
|
|
ret = strarrayWtoA( retW );
|
2021-04-19 10:04:49 +02:00
|
|
|
|
2005-08-29 16:13:05 +02:00
|
|
|
ldap_value_freeW( retW );
|
2021-04-19 10:04:52 +02:00
|
|
|
free( attrW );
|
2005-08-29 16:13:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
static char *bv2str( struct bervalU *bv )
|
2005-11-18 17:29:32 +01:00
|
|
|
{
|
|
|
|
char *str = NULL;
|
|
|
|
unsigned int len = bv->bv_len;
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
if ((str = malloc( len + 1 )))
|
2005-11-18 17:29:32 +01:00
|
|
|
{
|
|
|
|
memcpy( str, bv->bv_val, len );
|
|
|
|
str[len] = '\0';
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
static char **bv2str_array( struct bervalU **bv )
|
2005-11-18 17:29:32 +01:00
|
|
|
{
|
|
|
|
unsigned int len = 0, i = 0;
|
2021-04-19 10:04:49 +02:00
|
|
|
struct bervalU **p = bv;
|
2005-11-18 17:29:32 +01:00
|
|
|
char **str;
|
|
|
|
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
len++;
|
|
|
|
p++;
|
|
|
|
}
|
2021-04-19 10:04:52 +02:00
|
|
|
if (!(str = malloc( (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])
|
|
|
|
{
|
2021-04-19 10:04:52 +02:00
|
|
|
while (i > 0) free( str[--i] );
|
|
|
|
free( str );
|
2005-11-18 17:29:32 +01:00
|
|
|
return NULL;
|
2021-04-19 10:04:49 +02:00
|
|
|
}
|
2005-11-18 17:29:32 +01:00
|
|
|
i++;
|
2021-04-19 10:04:49 +02:00
|
|
|
p++;
|
2005-11-18 17:29:32 +01:00
|
|
|
}
|
|
|
|
str[i] = NULL;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
WCHAR ** CDECL ldap_get_valuesW( LDAP *ld, LDAPMessage *entry, WCHAR *attr )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2021-04-19 10:04:49 +02:00
|
|
|
WCHAR **ret = NULL;
|
|
|
|
char *attrU, **retU;
|
|
|
|
struct bervalU **bv;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_w(attr) );
|
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (ld && entry && attr && (attrU = strWtoU( attr )))
|
2020-03-23 14:14:22 +01:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ldap_get_values_len_params params = { CTX(ld), MSG(entry), attrU, &bv };
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (!LDAP_CALL( ldap_get_values_len, ¶ms ))
|
|
|
|
{
|
|
|
|
retU = bv2str_array( bv );
|
|
|
|
ret = strarrayUtoW( retU );
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
LDAP_CALL( ldap_value_free_len, bv );
|
|
|
|
strarrayfreeU( retU );
|
|
|
|
}
|
|
|
|
free( attrU );
|
|
|
|
}
|
2005-08-29 16:13:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:13:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_get_values_lenA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_get_values_lenW.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
struct berval ** CDECL ldap_get_values_lenA( LDAP *ld, LDAPMessage *message, char *attr )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2021-04-19 10:04:49 +02:00
|
|
|
WCHAR *attrW;
|
2021-04-19 10:04:54 +02:00
|
|
|
struct berval **ret;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
TRACE( "(%p, %p, %s)\n", ld, message, debugstr_a(attr) );
|
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
if (!ld || !message || !attr || !(attrW = strAtoW( attr ))) return NULL;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
ret = ldap_get_values_lenW( ld, message, attrW );
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
free( attrW );
|
2005-08-29 16:13:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
struct berval ** CDECL ldap_get_values_lenW( LDAP *ld, LDAPMessage *message, WCHAR *attr )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
|
|
|
char *attrU = NULL;
|
2021-04-19 10:04:49 +02:00
|
|
|
struct bervalU **retU;
|
2021-04-19 10:04:54 +02:00
|
|
|
struct berval **ret = NULL;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
TRACE( "(%p, %p, %s)\n", ld, message, debugstr_w(attr) );
|
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (ld && message && attr && (attrU = strWtoU( attr )))
|
2021-04-19 10:04:49 +02:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ldap_get_values_len_params params = { CTX(ld), MSG(message), attrU, &retU };
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (!LDAP_CALL( ldap_get_values_len, ¶ms ))
|
|
|
|
{
|
|
|
|
ret = bvarrayUtoW( retU );
|
|
|
|
bvarrayfreeU( retU );
|
|
|
|
}
|
|
|
|
|
|
|
|
free( attrU );
|
|
|
|
}
|
2021-04-19 10:04:49 +02:00
|
|
|
return ret;
|
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
|
2021-04-19 10:04:49 +02:00
|
|
|
* values [I] Array of berval structures.
|
2005-12-31 13:13:13 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: LDAP_SUCCESS
|
|
|
|
* Failure: An LDAP error code.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_value_free_len( struct berval **values )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2021-04-19 10:04:49 +02:00
|
|
|
TRACE( "(%p)\n", values );
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
bvarrayfreeW( values );
|
2021-04-19 10:04:54 +02:00
|
|
|
return 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.
|
|
|
|
*/
|
2021-04-19 10:04:49 +02:00
|
|
|
ULONG CDECL ldap_value_freeA( char **values )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2021-04-19 10:04:49 +02:00
|
|
|
TRACE( "(%p)\n", values );
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
strarrayfreeA( values );
|
2021-04-19 10:04:54 +02:00
|
|
|
return 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
|
2021-04-19 10:04:49 +02:00
|
|
|
* values [I] Array of string values.
|
2005-12-31 13:13:13 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: LDAP_SUCCESS
|
|
|
|
* Failure: An LDAP error code.
|
|
|
|
*/
|
2021-04-19 10:04:49 +02:00
|
|
|
ULONG CDECL ldap_value_freeW( WCHAR **values )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2021-04-19 10:04:49 +02:00
|
|
|
TRACE( "(%p)\n", values );
|
2005-08-29 16:13:05 +02:00
|
|
|
|
2021-04-19 10:04:49 +02:00
|
|
|
strarrayfreeW( values );
|
2021-04-19 10:04:54 +02:00
|
|
|
return LDAP_SUCCESS;
|
2005-08-29 16:13:05 +02:00
|
|
|
}
|