2005-07-18 20:06:42 +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-07-18 20:06:42 +02:00
|
|
|
*/
|
|
|
|
|
2005-11-24 19:21:49 +01:00
|
|
|
#include <stdarg.h>
|
2021-04-19 10:04:52 +02:00
|
|
|
#include <stdlib.h>
|
2005-07-18 20:06:42 +02:00
|
|
|
#include "windef.h"
|
2005-11-24 19:21:49 +01:00
|
|
|
#include "winbase.h"
|
2021-04-14 09:40:26 +02:00
|
|
|
#include "winnls.h"
|
2021-04-19 10:04:54 +02:00
|
|
|
#include "winldap.h"
|
|
|
|
#include "winber.h"
|
2021-04-14 09:40:26 +02:00
|
|
|
|
2006-04-18 20:40:40 +02:00
|
|
|
#include "wine/debug.h"
|
2021-04-14 09:40:26 +02:00
|
|
|
#include "winldap_private.h"
|
2006-04-18 20:40:40 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
|
2005-07-18 20:06:42 +02:00
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ber_alloc_t (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Allocate a berelement structure.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* options [I] Must be LBER_USE_DER.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to an allocated berelement structure.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Free the berelement structure with ber_free.
|
2006-04-18 20:38:43 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
BerElement * CDECL ber_alloc_t( int options )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
BerElement *ret;
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ber_alloc_t_params params;
|
2021-04-14 09:40:26 +02:00
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
if (!(ret = malloc( sizeof(*ret) ))) return NULL;
|
2021-11-04 11:09:04 +01:00
|
|
|
params.options = options;
|
|
|
|
params.ret = (void **)&BER(ret);
|
|
|
|
if (LDAP_CALL( ber_alloc_t, ¶ms ))
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
2021-04-19 10:04:52 +02:00
|
|
|
free( ret );
|
2021-04-14 09:40:26 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ber_bvdup (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Copy a berval structure.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* berval [I] Pointer to the berval structure to be copied.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to a copy of the berval structure.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Free the copy with ber_bvfree.
|
2006-04-18 20:38:43 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
BERVAL * CDECL ber_bvdup( BERVAL *berval )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2021-02-08 12:33:54 +01:00
|
|
|
return bervalWtoW( berval );
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ber_bvecfree (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Free an array of berval structures.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* berval [I] Pointer to an array of berval structures.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Use this function only to free an array of berval structures
|
|
|
|
* returned by a call to ber_scanf with a 'V' in the format string.
|
2006-04-18 20:38:43 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
void CDECL ber_bvecfree( BERVAL **berval )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2021-02-08 12:33:54 +01:00
|
|
|
bvarrayfreeW( berval );
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ber_bvfree (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Free a berval structure.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* berval [I] Pointer to a berval structure.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Use this function only to free berval structures allocated by
|
|
|
|
* an LDAP API.
|
2006-04-18 20:38:43 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
void CDECL ber_bvfree( BERVAL *berval )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2021-04-19 10:04:52 +02:00
|
|
|
free( berval );
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ber_first_element (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Return the tag of the first element in a set or sequence.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* berelement [I] Pointer to a berelement structure.
|
|
|
|
* len [O] Receives the length of the first element.
|
|
|
|
* opaque [O] Receives a pointer to a cookie.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Tag of the first element.
|
|
|
|
* Failure: LBER_DEFAULT (no more data).
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* len and cookie should be passed to ber_next_element.
|
2006-04-18 20:38:43 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ber_first_element( BerElement *ber, ULONG *len, char **opaque )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2022-02-03 11:50:00 +01:00
|
|
|
struct ber_first_element_params params = { BER(ber), (unsigned int *)len, opaque };
|
2021-11-04 11:09:04 +01:00
|
|
|
return LDAP_CALL( ber_first_element, ¶ms );
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ber_flatten (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Flatten a berelement structure into a berval structure.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2008-01-03 18:04:28 +01:00
|
|
|
* berelement [I] Pointer to a berelement structure.
|
2006-07-10 22:18:40 +02:00
|
|
|
* berval [O] Pointer to a berval structure.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0
|
|
|
|
* Failure: LBER_ERROR
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Free the berval structure with ber_bvfree.
|
2006-04-18 20:38:43 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
int CDECL ber_flatten( BerElement *ber, BERVAL **berval )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2021-04-14 09:40:26 +02:00
|
|
|
struct bervalU *bervalU;
|
2021-04-19 10:04:54 +02:00
|
|
|
struct berval *bervalW;
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ber_flatten_params params = { BER(ber), &bervalU };
|
2021-02-08 12:33:54 +01:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (LDAP_CALL( ber_flatten, ¶ms )) return LBER_ERROR;
|
2021-02-08 12:33:54 +01:00
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!(bervalW = bervalUtoW( bervalU ))) return LBER_ERROR;
|
2021-11-04 11:09:04 +01:00
|
|
|
LDAP_CALL( ber_bvfree, bervalU );
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!bervalW) return LBER_ERROR;
|
2021-02-08 12:33:54 +01:00
|
|
|
*berval = bervalW;
|
|
|
|
return 0;
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ber_free (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Free a berelement structure.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2008-01-03 18:04:28 +01:00
|
|
|
* berelement [I] Pointer to the berelement structure to be freed.
|
2006-07-10 22:18:40 +02:00
|
|
|
* buf [I] Flag.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Set buf to 0 if the berelement was allocated with ldap_first_attribute
|
|
|
|
* or ldap_next_attribute, otherwise set it to 1.
|
2006-04-18 20:38:43 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
void CDECL ber_free( BerElement *ber, int freebuf )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ber_free_params params = { BER(ber), freebuf };
|
|
|
|
LDAP_CALL( ber_free, ¶ms );
|
2021-04-19 10:04:52 +02:00
|
|
|
free( ber );
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ber_init (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Initialise a berelement structure from a berval structure.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* berval [I] Pointer to a berval structure.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to a berelement structure.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Call ber_free to free the returned berelement structure.
|
2006-04-18 20:38:43 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
BerElement * CDECL ber_init( BERVAL *berval )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2021-04-14 09:40:26 +02:00
|
|
|
struct bervalU *bervalU;
|
2021-04-19 10:04:54 +02:00
|
|
|
BerElement *ret;
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ber_init_params params;
|
2021-02-08 12:33:54 +01:00
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
if (!(ret = malloc( sizeof(*ret) ))) return NULL;
|
2021-04-14 09:40:26 +02:00
|
|
|
if (!(bervalU = bervalWtoU( berval )))
|
|
|
|
{
|
2021-04-19 10:04:52 +02:00
|
|
|
free( ret );
|
2021-04-14 09:40:26 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2021-11-04 11:09:04 +01:00
|
|
|
params.berval = bervalU;
|
|
|
|
params.ret = (void **)&BER(ret);
|
|
|
|
if (LDAP_CALL( ber_init, ¶ms ))
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
2021-04-19 10:04:52 +02:00
|
|
|
free( ret );
|
2021-04-14 09:40:26 +02:00
|
|
|
ret = NULL;
|
|
|
|
}
|
2021-04-19 10:04:52 +02:00
|
|
|
free( bervalU );
|
2021-02-08 12:33:54 +01:00
|
|
|
return ret;
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ber_next_element (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Return the tag of the next element in a set or sequence.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* berelement [I] Pointer to a berelement structure.
|
|
|
|
* len [I/O] Receives the length of the next element.
|
|
|
|
* opaque [I/O] Pointer to a cookie.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Tag of the next element.
|
|
|
|
* Failure: LBER_DEFAULT (no more data).
|
|
|
|
*
|
|
|
|
* NOTES
|
2008-01-03 18:04:28 +01:00
|
|
|
* len and cookie are initialized by ber_first_element and should
|
2006-07-10 22:18:40 +02:00
|
|
|
* be passed on in subsequent calls to ber_next_element.
|
2006-04-18 20:38:43 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ber_next_element( BerElement *ber, ULONG *len, char *opaque )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2022-02-03 11:50:00 +01:00
|
|
|
struct ber_next_element_params params = { BER(ber), (unsigned int *)len, opaque };
|
2021-11-04 11:09:04 +01:00
|
|
|
return LDAP_CALL( ber_next_element, ¶ms );
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ber_peek_tag (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Return the tag of the next element.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* berelement [I] Pointer to a berelement structure.
|
|
|
|
* len [O] Receives the length of the next element.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Tag of the next element.
|
|
|
|
* Failure: LBER_DEFAULT (no more data).
|
2006-04-18 20:38:43 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ber_peek_tag( BerElement *ber, ULONG *len )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2022-02-03 11:50:00 +01:00
|
|
|
struct ber_peek_tag_params params = { BER(ber), (unsigned int *)len };
|
2021-11-04 11:09:04 +01:00
|
|
|
return LDAP_CALL( ber_peek_tag, ¶ms );
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ber_skip_tag (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Skip the current tag and return the tag of the next element.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* berelement [I] Pointer to a berelement structure.
|
|
|
|
* len [O] Receives the length of the skipped element.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Tag of the next element.
|
|
|
|
* Failure: LBER_DEFAULT (no more data).
|
2006-04-18 20:38:43 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ber_skip_tag( BerElement *ber, ULONG *len )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2022-02-03 11:50:00 +01:00
|
|
|
struct ber_skip_tag_params params = { BER(ber), (unsigned int *)len };
|
2021-11-04 11:09:04 +01:00
|
|
|
return LDAP_CALL( ber_skip_tag, ¶ms );
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:38:43 +02:00
|
|
|
|
2006-04-18 20:40:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ber_printf (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Encode a berelement structure.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* berelement [I/O] Pointer to a berelement structure.
|
|
|
|
* fmt [I] Format string.
|
|
|
|
* ... [I] Values to encode.
|
|
|
|
*
|
|
|
|
* RETURNS
|
2021-04-14 09:40:26 +02:00
|
|
|
* Success: Non-negative number.
|
2006-07-10 22:18:40 +02:00
|
|
|
* Failure: LBER_ERROR
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* berelement must have been allocated with ber_alloc_t. This function
|
|
|
|
* can be called multiple times to append data.
|
2006-04-18 20:40:40 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
int WINAPIV ber_printf( BerElement *ber, char *fmt, ... )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2021-10-22 11:13:06 +02:00
|
|
|
va_list list;
|
2006-04-18 20:40:40 +02:00
|
|
|
int ret = 0;
|
|
|
|
char new_fmt[2];
|
|
|
|
|
|
|
|
new_fmt[1] = 0;
|
2021-10-22 11:13:06 +02:00
|
|
|
va_start( list, fmt );
|
2006-04-18 20:40:40 +02:00
|
|
|
while (*fmt)
|
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ber_printf_params params = { BER(ber), new_fmt };
|
2006-04-18 20:40:40 +02:00
|
|
|
new_fmt[0] = *fmt++;
|
2021-04-14 09:40:26 +02:00
|
|
|
switch (new_fmt[0])
|
2006-04-18 20:40:40 +02:00
|
|
|
{
|
|
|
|
case 'b':
|
|
|
|
case 'e':
|
|
|
|
case 'i':
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = va_arg( list, int );
|
|
|
|
ret = LDAP_CALL( ber_printf, ¶ms );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
2006-04-18 20:40:40 +02:00
|
|
|
case 'o':
|
|
|
|
case 's':
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = (ULONG_PTR)va_arg( list, char * );
|
|
|
|
ret = LDAP_CALL( ber_printf, ¶ms );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
2006-04-18 20:40:40 +02:00
|
|
|
case 't':
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = va_arg( list, unsigned int );
|
|
|
|
ret = LDAP_CALL( ber_printf, ¶ms );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
2006-04-18 20:40:40 +02:00
|
|
|
case 'v':
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = (ULONG_PTR)va_arg( list, char ** );
|
|
|
|
ret = LDAP_CALL( ber_printf, ¶ms );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
2006-04-18 20:40:40 +02:00
|
|
|
case 'V':
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
struct berval **array = va_arg( list, struct berval ** );
|
2021-04-14 09:40:26 +02:00
|
|
|
struct bervalU **arrayU;
|
|
|
|
if (!(arrayU = bvarrayWtoU( array )))
|
2006-04-18 20:40:40 +02:00
|
|
|
{
|
2021-04-14 09:40:26 +02:00
|
|
|
ret = -1;
|
2006-04-18 20:40:40 +02:00
|
|
|
break;
|
|
|
|
}
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = (ULONG_PTR)arrayU;
|
|
|
|
ret = LDAP_CALL( ber_printf, ¶ms );
|
2021-04-14 09:40:26 +02:00
|
|
|
bvarrayfreeU( arrayU );
|
|
|
|
break;
|
|
|
|
}
|
2006-04-18 20:40:40 +02:00
|
|
|
case 'X':
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = (ULONG_PTR)va_arg( list, char * );
|
|
|
|
params.arg2 = va_arg( list, int );
|
2021-04-14 09:40:26 +02:00
|
|
|
new_fmt[0] = 'B'; /* 'X' is deprecated */
|
2021-11-04 11:09:04 +01:00
|
|
|
ret = LDAP_CALL( ber_printf, ¶ms );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-04-18 20:40:40 +02:00
|
|
|
case 'n':
|
|
|
|
case '{':
|
|
|
|
case '}':
|
|
|
|
case '[':
|
|
|
|
case ']':
|
2021-11-04 11:09:04 +01:00
|
|
|
ret = LDAP_CALL( ber_printf, ¶ms );
|
2006-04-18 20:40:40 +02:00
|
|
|
break;
|
2021-04-14 09:40:26 +02:00
|
|
|
|
2006-04-18 20:40:40 +02:00
|
|
|
default:
|
|
|
|
FIXME( "Unknown format '%c'\n", new_fmt[0] );
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret == -1) break;
|
|
|
|
}
|
2021-10-22 11:13:06 +02:00
|
|
|
va_end( list );
|
2006-04-18 20:40:40 +02:00
|
|
|
return ret;
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2006-04-18 20:40:40 +02:00
|
|
|
|
2006-04-18 20:41:03 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ber_scanf (WLDAP32.@)
|
2006-07-10 22:18:40 +02:00
|
|
|
*
|
|
|
|
* Decode a berelement structure.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* berelement [I/O] Pointer to a berelement structure.
|
|
|
|
* fmt [I] Format string.
|
|
|
|
* ... [I] Pointers to values to be decoded.
|
|
|
|
*
|
|
|
|
* RETURNS
|
2021-04-14 09:40:26 +02:00
|
|
|
* Success: Non-negative number.
|
2006-07-10 22:18:40 +02:00
|
|
|
* Failure: LBER_ERROR
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* berelement must have been allocated with ber_init. This function
|
|
|
|
* can be called multiple times to decode data.
|
2006-04-18 20:41:03 +02:00
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG WINAPIV ber_scanf( BerElement *ber, char *fmt, ... )
|
2005-07-18 20:06:42 +02:00
|
|
|
{
|
2021-10-22 11:13:06 +02:00
|
|
|
va_list list;
|
2006-04-18 20:41:03 +02:00
|
|
|
int ret = 0;
|
|
|
|
char new_fmt[2];
|
|
|
|
|
|
|
|
new_fmt[1] = 0;
|
2021-10-22 11:13:06 +02:00
|
|
|
va_start( list, fmt );
|
2006-04-18 20:41:03 +02:00
|
|
|
while (*fmt)
|
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
struct ber_scanf_params params = { BER(ber), new_fmt };
|
2006-04-18 20:41:03 +02:00
|
|
|
new_fmt[0] = *fmt++;
|
2021-04-14 09:40:26 +02:00
|
|
|
switch (new_fmt[0])
|
2006-04-18 20:41:03 +02:00
|
|
|
{
|
|
|
|
case 'a':
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
|
|
|
char *str, **ptr = va_arg( list, char ** );
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = &str;
|
|
|
|
if ((ret = LDAP_CALL( ber_scanf, ¶ms )) == -1) break;
|
2021-04-14 09:40:26 +02:00
|
|
|
*ptr = strdupU( str );
|
2021-11-04 11:09:04 +01:00
|
|
|
LDAP_CALL( ldap_memfree, str );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-04-18 20:41:03 +02:00
|
|
|
case 'b':
|
|
|
|
case 'e':
|
|
|
|
case 'i':
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = va_arg( list, int * );
|
|
|
|
ret = LDAP_CALL( ber_scanf, ¶ms );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
2006-04-18 20:41:03 +02:00
|
|
|
case 't':
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = va_arg( list, unsigned int * );
|
|
|
|
ret = LDAP_CALL( ber_scanf, ¶ms );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
2006-04-18 20:41:03 +02:00
|
|
|
case 'v':
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
|
|
|
char *str, **arrayU, **ptr, ***array = va_arg( list, char *** );
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = &arrayU;
|
|
|
|
if ((ret = LDAP_CALL( ber_scanf, ¶ms )) == -1) break;
|
2021-04-14 09:40:26 +02:00
|
|
|
*array = strarrayUtoU( arrayU );
|
|
|
|
ptr = arrayU;
|
|
|
|
while ((str = *ptr))
|
2006-04-18 20:41:03 +02:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
LDAP_CALL( ldap_memfree, str );
|
2021-04-14 09:40:26 +02:00
|
|
|
ptr++;
|
2006-04-18 20:41:03 +02:00
|
|
|
}
|
2021-11-04 11:09:04 +01:00
|
|
|
LDAP_CALL( ldap_memfree, arrayU );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-04-18 20:41:03 +02:00
|
|
|
case 'B':
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
|
|
|
char *strU, **str = va_arg( list, char ** );
|
|
|
|
int *len = va_arg( list, int * );
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = &strU;
|
|
|
|
params.arg2 = len;
|
|
|
|
if ((ret = LDAP_CALL( ber_scanf, ¶ms )) == -1) break;
|
2021-04-19 10:04:52 +02:00
|
|
|
*str = malloc( *len );
|
2021-04-14 09:40:26 +02:00
|
|
|
memcpy( *str, strU, *len );
|
2021-11-04 11:09:04 +01:00
|
|
|
LDAP_CALL( ldap_memfree, strU );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-04-18 20:41:03 +02:00
|
|
|
case 'O':
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
struct berval **berval = va_arg( list, struct berval ** );
|
2021-04-14 09:40:26 +02:00
|
|
|
struct bervalU *bervalU;
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = &bervalU;
|
|
|
|
if ((ret = LDAP_CALL( ber_scanf, ¶ms )) == -1) break;
|
2021-04-14 09:40:26 +02:00
|
|
|
*berval = bervalUtoW( bervalU );
|
2021-11-04 11:09:04 +01:00
|
|
|
LDAP_CALL( ber_bvfree, bervalU );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-04-18 20:41:03 +02:00
|
|
|
case 'V':
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
struct berval ***array = va_arg( list, struct berval *** );
|
2021-04-14 09:40:26 +02:00
|
|
|
struct bervalU **arrayU;
|
2021-11-04 11:09:04 +01:00
|
|
|
params.arg1 = &arrayU;
|
|
|
|
if ((ret = LDAP_CALL( ber_scanf, ¶ms )) == -1) break;
|
2021-04-14 09:40:26 +02:00
|
|
|
*array = bvarrayUtoW( arrayU );
|
2021-11-04 11:09:04 +01:00
|
|
|
LDAP_CALL( ber_bvecfree, arrayU );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-04-18 20:41:03 +02:00
|
|
|
case 'n':
|
|
|
|
case 'x':
|
|
|
|
case '{':
|
|
|
|
case '}':
|
|
|
|
case '[':
|
|
|
|
case ']':
|
2021-11-04 11:09:04 +01:00
|
|
|
ret = LDAP_CALL( ber_scanf, ¶ms );
|
2006-04-18 20:41:03 +02:00
|
|
|
break;
|
2021-04-14 09:40:26 +02:00
|
|
|
|
2006-04-18 20:41:03 +02:00
|
|
|
default:
|
|
|
|
FIXME( "Unknown format '%c'\n", new_fmt[0] );
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret == -1) break;
|
|
|
|
}
|
2021-10-22 11:13:06 +02:00
|
|
|
va_end( list );
|
2006-04-18 20:41:03 +02:00
|
|
|
return ret;
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|