2005-08-03 12:58:14 +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-03 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2021-04-19 10:04:52 +02:00
|
|
|
#include <stdlib.h>
|
2005-08-03 12:58:14 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
2021-04-19 10:04:54 +02:00
|
|
|
#include "winldap.h"
|
2005-08-03 12:58:14 +02:00
|
|
|
|
2011-09-05 17:23:34 +02:00
|
|
|
#include "wine/debug.h"
|
2021-04-15 12:20:05 +02:00
|
|
|
#include "winldap_private.h"
|
2005-08-03 12:58:14 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_abandon (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Cancel an asynchronous operation.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* msgid [I] ID of the operation to cancel.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: LDAP_SUCCESS
|
|
|
|
* Failure: An LDAP error code.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_abandon( LDAP *ld, ULONG msgid )
|
2005-08-22 20:56:54 +02:00
|
|
|
{
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%p, 0x%08x)\n", ld, msgid );
|
2005-08-22 20:56:54 +02:00
|
|
|
|
2009-01-05 12:40:28 +01:00
|
|
|
if (!ld) return ~0u;
|
2021-11-04 11:09:04 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ldap_abandon_ext_params params = { CTX(ld), msgid };
|
|
|
|
return map_error( LDAP_CALL( ldap_abandon_ext, ¶ms ));
|
|
|
|
}
|
2005-08-22 20:56:54 +02:00
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_check_filterA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_check_filterW.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_check_filterA( LDAP *ld, char *filter )
|
2005-08-22 20:56:54 +02:00
|
|
|
{
|
|
|
|
ULONG ret;
|
|
|
|
WCHAR *filterW = NULL;
|
|
|
|
|
|
|
|
TRACE( "(%p, %s)\n", ld, debugstr_a(filter) );
|
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!ld) return LDAP_PARAM_ERROR;
|
|
|
|
if (filter && !(filterW = strAtoW( filter ))) return LDAP_NO_MEMORY;
|
2005-08-22 20:56:54 +02:00
|
|
|
|
|
|
|
ret = ldap_check_filterW( ld, filterW );
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
free( filterW );
|
2005-08-22 20:56:54 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_check_filterW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Check filter syntax.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* filter [I] Filter string.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: LDAP_SUCCESS
|
|
|
|
* Failure: An LDAP error code.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_check_filterW( LDAP *ld, WCHAR *filter )
|
2005-08-22 20:56:54 +02:00
|
|
|
{
|
|
|
|
TRACE( "(%p, %s)\n", ld, debugstr_w(filter) );
|
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!ld) return LDAP_PARAM_ERROR;
|
|
|
|
return LDAP_SUCCESS; /* FIXME: do some checks */
|
2005-08-22 20:56:54 +02:00
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_cleanup (WLDAP32.@)
|
|
|
|
*/
|
2006-06-12 21:34:46 +02:00
|
|
|
ULONG CDECL ldap_cleanup( HANDLE instance )
|
2005-08-22 20:56:54 +02:00
|
|
|
{
|
|
|
|
TRACE( "(%p)\n", instance );
|
2021-04-19 10:04:54 +02:00
|
|
|
return LDAP_SUCCESS;
|
2005-08-22 20:56:54 +02:00
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_conn_from_msg (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Get the LDAP context for a given message.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* res [I] LDAP message.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to an LDAP context.
|
|
|
|
* Failure: NULL
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP * CDECL ldap_conn_from_msg( LDAP *ld, LDAPMessage *res )
|
2005-08-22 20:56:54 +02:00
|
|
|
{
|
|
|
|
TRACE( "(%p, %p)\n", ld, res );
|
|
|
|
|
|
|
|
if (!ld || !res) return NULL;
|
|
|
|
return ld; /* FIXME: not always correct */
|
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_count_entries (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Count the number of entries returned from a search.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* res [I] LDAP message.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The number of entries.
|
2009-01-05 12:40:28 +01:00
|
|
|
* Failure: ~0u
|
2006-04-14 18:56:21 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_count_entries( LDAP *ld, LDAPMessage *res )
|
2005-08-30 10:52:39 +02:00
|
|
|
{
|
|
|
|
TRACE( "(%p, %p)\n", ld, res );
|
|
|
|
|
2009-01-05 12:40:28 +01:00
|
|
|
if (!ld) return ~0u;
|
2021-11-04 11:09:04 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ldap_count_entries_params params = { CTX(ld), MSG(res) };
|
|
|
|
return LDAP_CALL( ldap_count_entries, ¶ms );
|
|
|
|
}
|
2005-08-30 10:52:39 +02:00
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_count_references (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Count the number of references returned from a search.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* res [I] LDAP message.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The number of references.
|
2009-01-05 12:40:28 +01:00
|
|
|
* Failure: ~0u
|
2006-04-14 18:56:21 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_count_references( LDAP *ld, LDAPMessage *res )
|
2005-08-30 10:52:39 +02:00
|
|
|
{
|
|
|
|
TRACE( "(%p, %p)\n", ld, res );
|
|
|
|
|
|
|
|
if (!ld) return 0;
|
2021-11-04 11:09:04 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ldap_count_references_params params = { CTX(ld), MSG(res) };
|
|
|
|
return LDAP_CALL( ldap_count_references, ¶ms );
|
|
|
|
}
|
2005-08-30 10:52:39 +02:00
|
|
|
}
|
|
|
|
|
2005-09-07 11:24:50 +02:00
|
|
|
static ULONG get_escape_size( PCHAR src, ULONG srclen )
|
|
|
|
{
|
|
|
|
ULONG i, size = 0;
|
|
|
|
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
for (i = 0; i < srclen; i++)
|
|
|
|
{
|
|
|
|
if ((src[i] >= '0' && src[i] <= '9') ||
|
|
|
|
(src[i] >= 'A' && src[i] <= 'Z') ||
|
|
|
|
(src[i] >= 'a' && src[i] <= 'z'))
|
|
|
|
size++;
|
|
|
|
else
|
|
|
|
size += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return size + 1;
|
|
|
|
}
|
|
|
|
|
2021-04-15 12:20:05 +02:00
|
|
|
static void escape_filter_element( char *src, ULONG srclen, char *dst )
|
2005-09-07 11:24:50 +02:00
|
|
|
{
|
|
|
|
ULONG i;
|
2006-04-14 18:56:21 +02:00
|
|
|
static const char fmt[] = "\\%02X";
|
2005-09-07 11:24:50 +02:00
|
|
|
char *d = dst;
|
|
|
|
|
|
|
|
for (i = 0; i < srclen; i++)
|
|
|
|
{
|
|
|
|
if ((src[i] >= '0' && src[i] <= '9') ||
|
|
|
|
(src[i] >= 'A' && src[i] <= 'Z') ||
|
|
|
|
(src[i] >= 'a' && src[i] <= 'z'))
|
|
|
|
*d++ = src[i];
|
|
|
|
else
|
2016-11-12 09:57:42 +01:00
|
|
|
d += sprintf( d, fmt, (unsigned char)src[i] );
|
2005-09-07 11:24:50 +02:00
|
|
|
}
|
|
|
|
*++d = 0;
|
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_escape_filter_elementA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_escape_filter_elementW.
|
|
|
|
*/
|
2021-04-15 12:20:05 +02:00
|
|
|
ULONG CDECL ldap_escape_filter_elementA( char *src, ULONG srclen, char *dst, ULONG dstlen )
|
2005-09-07 11:24:50 +02:00
|
|
|
{
|
2021-04-15 12:20:05 +02:00
|
|
|
ULONG len = get_escape_size( src, srclen );
|
2005-09-07 11:24:50 +02:00
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%p, 0x%08x, %p, 0x%08x)\n", src, srclen, dst, dstlen );
|
2005-09-07 11:24:50 +02:00
|
|
|
|
|
|
|
if (!dst) return len;
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!src || dstlen < len) return LDAP_PARAM_ERROR;
|
2005-09-07 11:24:50 +02:00
|
|
|
|
2021-04-15 12:20:05 +02:00
|
|
|
escape_filter_element( src, srclen, dst );
|
2021-04-19 10:04:54 +02:00
|
|
|
return LDAP_SUCCESS;
|
2005-09-07 11:24:50 +02:00
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_escape_filter_elementW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Escape binary data for safe passing in filters.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* src [I] Filter element to be escaped.
|
|
|
|
* srclen [I] Length in bytes of the filter element.
|
|
|
|
* dst [O] Destination buffer for the escaped filter element.
|
|
|
|
* dstlen [I] Length in bytes of the destination buffer.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: LDAP_SUCCESS
|
|
|
|
* Failure: An LDAP error code.
|
|
|
|
*/
|
2021-04-15 12:20:05 +02:00
|
|
|
ULONG CDECL ldap_escape_filter_elementW( char *src, ULONG srclen, WCHAR *dst, ULONG dstlen )
|
2005-09-07 11:24:50 +02:00
|
|
|
{
|
2021-04-15 12:20:05 +02:00
|
|
|
ULONG len = get_escape_size( src, srclen );
|
2005-09-07 11:24:50 +02:00
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%p, 0x%08x, %p, 0x%08x)\n", src, srclen, dst, dstlen );
|
2005-09-07 11:24:50 +02:00
|
|
|
|
|
|
|
if (!dst) return len;
|
|
|
|
|
|
|
|
/* no matter what you throw at it, this is what native returns */
|
2021-04-19 10:04:54 +02:00
|
|
|
return LDAP_PARAM_ERROR;
|
2005-09-07 11:24:50 +02:00
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_first_attributeA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_first_attributeW.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
char * CDECL ldap_first_attributeA( LDAP *ld, LDAPMessage *entry, BerElement **ber )
|
2005-08-30 10:52:39 +02:00
|
|
|
{
|
2021-04-15 12:20:05 +02:00
|
|
|
char *ret = NULL;
|
2005-08-30 10:52:39 +02:00
|
|
|
WCHAR *retW;
|
|
|
|
|
2021-04-15 12:20:05 +02:00
|
|
|
TRACE( "(%p, %p, %p)\n", ld, entry, ber );
|
2005-08-30 10:52:39 +02:00
|
|
|
|
|
|
|
if (!ld || !entry) return NULL;
|
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
retW = ldap_first_attributeW( ld, entry, ber );
|
2021-04-15 12:20:05 +02:00
|
|
|
if (retW)
|
|
|
|
{
|
|
|
|
ret = strWtoA( retW );
|
|
|
|
ldap_memfreeW( retW );
|
|
|
|
}
|
2005-08-30 10:52:39 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_first_attributeW (WLDAP32.@)
|
|
|
|
*
|
2021-04-15 12:20:05 +02:00
|
|
|
* Get the first attribute for a given entry.
|
2006-04-14 18:56:21 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* entry [I] Entry to retrieve attribute for.
|
|
|
|
* ptr [O] Position pointer.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Name of the first attribute.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Use ldap_memfree to free the returned string.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
WCHAR * CDECL ldap_first_attributeW( LDAP *ld, LDAPMessage *entry, BerElement **ptr )
|
2005-08-30 10:52:39 +02:00
|
|
|
{
|
2021-04-15 12:20:05 +02:00
|
|
|
WCHAR *ret = NULL;
|
2021-04-19 10:04:54 +02:00
|
|
|
BerElement *ber;
|
2005-08-30 10:52:39 +02:00
|
|
|
char *retU;
|
2021-04-15 12:20:05 +02:00
|
|
|
void *berU;
|
2005-08-30 10:52:39 +02:00
|
|
|
|
|
|
|
TRACE( "(%p, %p, %p)\n", ld, entry, ptr );
|
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (ld && entry)
|
|
|
|
{
|
|
|
|
struct ldap_first_attribute_params params = { CTX(ld), MSG(entry), &berU, &retU };
|
|
|
|
LDAP_CALL( ldap_first_attribute, ¶ms );
|
|
|
|
}
|
|
|
|
else return NULL;
|
2005-08-30 10:52:39 +02:00
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
if (retU && (ber = malloc( sizeof(*ber) )))
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
BER(ber) = (char *)berU;
|
2021-04-14 09:40:26 +02:00
|
|
|
*ptr = ber;
|
|
|
|
ret = strUtoW( retU );
|
|
|
|
}
|
2005-08-30 10:52:39 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
LDAP_CALL( ldap_memfree, retU );
|
2005-08-30 10:52:39 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_first_entry (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Get the first entry from a result message.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* res [I] Search result message.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The first entry.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
2021-04-15 12:20:05 +02:00
|
|
|
* The returned entry will be freed when the message is freed.
|
2006-04-14 18:56:21 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAPMessage * CDECL ldap_first_entry( LDAP *ld, LDAPMessage *res )
|
2005-08-30 10:52:39 +02:00
|
|
|
{
|
2021-04-15 12:20:05 +02:00
|
|
|
void *msgU;
|
2005-08-30 10:52:39 +02:00
|
|
|
|
|
|
|
TRACE( "(%p, %p)\n", ld, res );
|
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (ld && res)
|
2021-04-15 12:20:05 +02:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ldap_first_entry_params params = { CTX(ld), MSG(res), &msgU };
|
|
|
|
if (!LDAP_CALL( ldap_first_entry, ¶ms ))
|
|
|
|
{
|
|
|
|
assert( msgU == MSG(res) );
|
|
|
|
return res;
|
|
|
|
}
|
2021-04-15 12:20:05 +02:00
|
|
|
}
|
2005-08-30 10:52:39 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_first_reference (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Get the first reference from a result message.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* res [I] Search result message.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The first reference.
|
|
|
|
* Failure: NULL
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAPMessage * CDECL ldap_first_reference( LDAP *ld, LDAPMessage *res )
|
2005-08-30 10:52:39 +02:00
|
|
|
{
|
2021-04-15 12:20:05 +02:00
|
|
|
void *msgU;
|
2005-08-30 10:52:39 +02:00
|
|
|
|
|
|
|
TRACE( "(%p, %p)\n", ld, res );
|
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (ld)
|
2021-04-15 12:20:05 +02:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ldap_first_reference_params params = { CTX(ld), MSG(res), &msgU };
|
|
|
|
if (!LDAP_CALL( ldap_first_reference, ¶ms ))
|
|
|
|
{
|
|
|
|
assert( msgU == MSG(res) );
|
|
|
|
return res;
|
|
|
|
}
|
2021-04-15 12:20:05 +02:00
|
|
|
}
|
2005-08-30 10:52:39 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_memfreeA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_memfreeW.
|
|
|
|
*/
|
2021-04-15 12:20:05 +02:00
|
|
|
void CDECL ldap_memfreeA( char *block )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
|
|
|
TRACE( "(%p)\n", block );
|
2021-04-19 10:04:52 +02:00
|
|
|
free( block );
|
2005-08-03 12:58:14 +02:00
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_memfreeW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Free a block of memory.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* block [I] Pointer to memory block to be freed.
|
|
|
|
*/
|
2021-04-15 12:20:05 +02:00
|
|
|
void CDECL ldap_memfreeW( WCHAR *block )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
|
|
|
TRACE( "(%p)\n", block );
|
2021-04-19 10:04:52 +02:00
|
|
|
free( block );
|
2005-08-03 12:58:14 +02:00
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_msgfree (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Free a message.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* res [I] Message to be freed.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_msgfree( LDAPMessage *res )
|
2005-08-29 16:13:05 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAPMessage *entry, *list = res;
|
2005-08-29 16:13:05 +02:00
|
|
|
|
|
|
|
TRACE( "(%p)\n", res );
|
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!res) return LDAP_SUCCESS;
|
2021-04-15 12:20:05 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
LDAP_CALL( ldap_msgfree, MSG(res) );
|
2021-04-15 12:20:05 +02:00
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
entry = list;
|
|
|
|
list = entry->lm_next;
|
2021-04-19 10:04:52 +02:00
|
|
|
free( entry );
|
2021-04-15 12:20:05 +02:00
|
|
|
}
|
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
return LDAP_SUCCESS;
|
2005-08-29 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_next_attributeA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_next_attributeW.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
char * CDECL ldap_next_attributeA( LDAP *ld, LDAPMessage *entry, BerElement *ptr )
|
2005-08-30 10:52:39 +02:00
|
|
|
{
|
2021-04-15 12:20:05 +02:00
|
|
|
char *ret = NULL;
|
2005-08-30 10:52:39 +02:00
|
|
|
WCHAR *retW;
|
|
|
|
|
|
|
|
TRACE( "(%p, %p, %p)\n", ld, entry, ptr );
|
|
|
|
|
|
|
|
if (!ld || !entry || !ptr) return NULL;
|
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
retW = ldap_next_attributeW( ld, entry, ptr );
|
2021-04-15 12:20:05 +02:00
|
|
|
if (retW)
|
|
|
|
{
|
|
|
|
ret = strWtoA( retW );
|
|
|
|
ldap_memfreeW( retW );
|
|
|
|
}
|
2005-08-30 10:52:39 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_next_attributeW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Get the next attribute for a given entry.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* entry [I] Entry to retrieve attribute for.
|
|
|
|
* ptr [I/O] Position pointer.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The name of the next attribute.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Free the returned string after each iteration with ldap_memfree.
|
|
|
|
* When done iterating and when ptr != NULL, call ber_free( ptr, 0 ).
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
WCHAR * CDECL ldap_next_attributeW( LDAP *ld, LDAPMessage *entry, BerElement *ptr )
|
2005-08-30 10:52:39 +02:00
|
|
|
{
|
2021-04-15 12:20:05 +02:00
|
|
|
WCHAR *ret = NULL;
|
2005-08-30 10:52:39 +02:00
|
|
|
char *retU;
|
|
|
|
|
2021-04-15 12:20:05 +02:00
|
|
|
TRACE( "(%p, %p, %p)\n", ld, entry, ptr );
|
2005-08-30 10:52:39 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (ld && entry && ptr)
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ldap_next_attribute_params params = { CTX(ld), MSG(entry), BER(ptr), &retU };
|
|
|
|
if (!LDAP_CALL( ldap_next_attribute, ¶ms ))
|
|
|
|
{
|
|
|
|
ret = strUtoW( retU );
|
|
|
|
LDAP_CALL( ldap_memfree, retU );
|
|
|
|
}
|
2021-04-14 09:40:26 +02:00
|
|
|
}
|
2005-08-30 10:52:39 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_next_entry (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Get the next entry from a result message.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* entry [I] Entry returned by a previous call.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The next entry.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The returned entry will be freed when the message is freed.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAPMessage * CDECL ldap_next_entry( LDAP *ld, LDAPMessage *entry )
|
2005-08-30 10:52:39 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAPMessage *msg = NULL;
|
2021-04-15 12:20:05 +02:00
|
|
|
void *msgU;
|
2005-08-30 10:52:39 +02:00
|
|
|
|
|
|
|
TRACE( "(%p, %p)\n", ld, entry );
|
|
|
|
|
|
|
|
if (!ld || !entry) return NULL;
|
|
|
|
|
2021-04-15 12:20:05 +02:00
|
|
|
if (entry->lm_next) return entry->lm_next;
|
2021-11-04 11:09:04 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ldap_next_entry_params params = { CTX(ld), MSG(entry), &msgU };
|
|
|
|
LDAP_CALL( ldap_next_entry, ¶ms );
|
|
|
|
}
|
2021-04-15 12:20:05 +02:00
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
if (msgU && (msg = calloc( 1, sizeof(*msg) )))
|
2021-04-15 12:20:05 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
MSG(msg) = msgU;
|
2021-04-15 12:20:05 +02:00
|
|
|
entry->lm_next = msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
2005-08-30 10:52:39 +02:00
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_next_reference (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Get the next reference from a result message.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* entry [I] Entry returned by a previous call.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The next reference.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The returned entry will be freed when the message is freed.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAPMessage * CDECL ldap_next_reference( LDAP *ld, LDAPMessage *entry )
|
2005-08-30 10:52:39 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAPMessage *msg = NULL;
|
2021-04-15 12:20:05 +02:00
|
|
|
void *msgU;
|
2005-08-30 10:52:39 +02:00
|
|
|
|
|
|
|
TRACE( "(%p, %p)\n", ld, entry );
|
|
|
|
|
|
|
|
if (!ld || !entry) return NULL;
|
|
|
|
|
2021-04-15 12:20:05 +02:00
|
|
|
if (entry->lm_next) return entry->lm_next;
|
2021-11-04 11:09:04 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ldap_next_reference_params params = { CTX(ld), MSG(entry), &msgU };
|
|
|
|
LDAP_CALL( ldap_next_reference, ¶ms );
|
|
|
|
}
|
2021-04-19 10:04:52 +02:00
|
|
|
if (msgU && (msg = calloc( 1, sizeof(*msg) )))
|
2021-04-15 12:20:05 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
MSG(msg) = msgU;
|
2021-04-15 12:20:05 +02:00
|
|
|
entry->lm_next = msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
2005-08-30 10:52:39 +02:00
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_result (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Get the result of an asynchronous operation.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* msgid [I] Message ID of the operation.
|
|
|
|
* all [I] How many results should be returned?
|
|
|
|
* timeout [I] How long to wait for the results?
|
|
|
|
* res [O] Result message for the operation.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: One of the following values:
|
|
|
|
*
|
|
|
|
* LDAP_RES_ADD
|
|
|
|
* LDAP_RES_BIND
|
|
|
|
* LDAP_RES_COMPARE
|
|
|
|
* LDAP_RES_DELETE
|
|
|
|
* LDAP_RES_EXTENDED
|
|
|
|
* LDAP_RES_MODIFY
|
|
|
|
* LDAP_RES_MODRDN
|
|
|
|
* LDAP_RES_REFERRAL
|
|
|
|
* LDAP_RES_SEARCH_ENTRY
|
|
|
|
* LDAP_RES_SEARCH_RESULT
|
|
|
|
*
|
2009-01-05 12:40:28 +01:00
|
|
|
* Failure: ~0u
|
2006-04-14 18:56:21 +02:00
|
|
|
*
|
|
|
|
* This function returns 0 when the timeout has expired.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* A NULL timeout pointer causes the function to block waiting
|
|
|
|
* for results to arrive. A timeout value of 0 causes the function
|
|
|
|
* to immediately return any available results. Free returned results
|
|
|
|
* with ldap_msgfree.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_result( LDAP *ld, ULONG msgid, ULONG all, struct l_timeval *timeout, LDAPMessage **res )
|
2005-08-15 16:46:42 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAPMessage *msg;
|
2021-04-15 12:20:05 +02:00
|
|
|
struct timevalU timeval;
|
|
|
|
void *msgU = NULL;
|
2021-11-04 11:09:04 +01:00
|
|
|
ULONG ret = ~0u;
|
2005-08-15 16:46:42 +02:00
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%p, 0x%08x, 0x%08x, %p, %p)\n", ld, msgid, all, timeout, res );
|
2005-08-15 16:46:42 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (ld && res && msgid != ~0u)
|
2021-04-15 12:20:05 +02:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ldap_result_params params = { CTX(ld), msgid, all, timeout ? &timeval : NULL, &msgU };
|
2021-04-15 12:20:05 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (timeout)
|
|
|
|
{
|
|
|
|
timeval.tv_sec = timeout->tv_sec;
|
|
|
|
timeval.tv_usec = timeout->tv_usec;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = LDAP_CALL( ldap_result, ¶ms );
|
|
|
|
}
|
2021-04-19 10:04:52 +02:00
|
|
|
if (msgU && (msg = calloc( 1, sizeof(*msg) )))
|
2021-04-15 12:20:05 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
MSG(msg) = msgU;
|
2021-04-15 12:20:05 +02:00
|
|
|
*res = msg;
|
|
|
|
}
|
|
|
|
|
2005-08-15 16:46:42 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* LdapUnicodeToUTF8 (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Convert a wide character string to a UTF8 string.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* src [I] Wide character string to convert.
|
|
|
|
* srclen [I] Size of string to convert, in characters.
|
|
|
|
* dst [O] Pointer to a buffer that receives the converted string.
|
2021-04-15 12:20:05 +02:00
|
|
|
* dstlen [I] Size of the destination buffer in characters.
|
2006-04-14 18:56:21 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The number of characters written into the destination buffer.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Set dstlen to zero to ask for the required buffer size.
|
|
|
|
*/
|
2021-04-15 12:20:05 +02:00
|
|
|
int CDECL LdapUnicodeToUTF8( const WCHAR *src, int srclen, char *dst, int dstlen )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
|
|
|
return WideCharToMultiByte( CP_UTF8, 0, src, srclen, dst, dstlen, NULL, NULL );
|
|
|
|
}
|
|
|
|
|
2006-04-14 18:56:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* LdapUTF8ToUnicode (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Convert a UTF8 string to a wide character string.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* src [I] UTF8 string to convert.
|
|
|
|
* srclen [I] Size of string to convert, in characters.
|
|
|
|
* dst [O] Pointer to a buffer that receives the converted string.
|
2021-04-15 12:20:05 +02:00
|
|
|
* dstlen [I] Size of the destination buffer in characters.
|
2006-04-14 18:56:21 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The number of characters written into the destination buffer.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Set dstlen to zero to ask for the required buffer size.
|
|
|
|
*/
|
2021-04-15 12:20:05 +02:00
|
|
|
int CDECL LdapUTF8ToUnicode( const char *src, int srclen, WCHAR *dst, int dstlen )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
|
|
|
return MultiByteToWideChar( CP_UTF8, 0, src, srclen, dst, dstlen );
|
|
|
|
}
|