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-04-14 09:40:26 +02:00
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
if (!(ret = malloc( sizeof(*ret) ))) return NULL;
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!(BER(ret) = ldap_funcs->fn_ber_alloc_t( options )))
|
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
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
return ldap_funcs->fn_ber_first_element( BER(ber), len, opaque );
|
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-02-08 12:33:54 +01:00
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
if (ldap_funcs->fn_ber_flatten( BER(ber), &bervalU )) 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;
|
|
|
|
ldap_funcs->fn_ber_bvfree( bervalU );
|
|
|
|
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-04-19 10:04:54 +02:00
|
|
|
ldap_funcs->fn_ber_free( BER(ber), freebuf );
|
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-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-04-19 10:04:54 +02:00
|
|
|
if (!(BER(ret) = ldap_funcs->fn_ber_init( bervalU )))
|
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
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
return ldap_funcs->fn_ber_next_element( BER(ber), len, opaque );
|
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
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
return ldap_funcs->fn_ber_peek_tag( BER(ber), len );
|
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
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
return ldap_funcs->fn_ber_skip_tag( BER(ber), len );
|
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
|
|
|
{
|
2008-12-31 20:49:07 +01:00
|
|
|
__ms_va_list list;
|
2006-04-18 20:40:40 +02:00
|
|
|
int ret = 0;
|
|
|
|
char new_fmt[2];
|
|
|
|
|
|
|
|
new_fmt[1] = 0;
|
2008-12-31 20:49:07 +01:00
|
|
|
__ms_va_start( list, fmt );
|
2006-04-18 20:40:40 +02:00
|
|
|
while (*fmt)
|
|
|
|
{
|
|
|
|
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-04-14 09:40:26 +02:00
|
|
|
{
|
|
|
|
int i = va_arg( list, int );
|
2021-04-19 10:04:54 +02:00
|
|
|
ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, i );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-04-18 20:40:40 +02:00
|
|
|
case 'o':
|
|
|
|
case 's':
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
|
|
|
char *str = va_arg( list, char * );
|
2021-04-19 10:04:54 +02:00
|
|
|
ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, str );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-04-18 20:40:40 +02:00
|
|
|
case 't':
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
|
|
|
unsigned int tag = va_arg( list, unsigned int );
|
2021-04-19 10:04:54 +02:00
|
|
|
ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, tag );
|
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
|
|
|
{
|
|
|
|
char **array = va_arg( list, char ** );
|
2021-04-19 10:04:54 +02:00
|
|
|
ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, array );
|
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-04-19 10:04:54 +02:00
|
|
|
ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, arrayU );
|
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
|
|
|
{
|
|
|
|
char *str = va_arg( list, char * );
|
|
|
|
int len = va_arg( list, int );
|
|
|
|
new_fmt[0] = 'B'; /* 'X' is deprecated */
|
2021-04-19 10:04:54 +02:00
|
|
|
ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, str, len );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-04-18 20:40:40 +02:00
|
|
|
case 'n':
|
|
|
|
case '{':
|
|
|
|
case '}':
|
|
|
|
case '[':
|
|
|
|
case ']':
|
2021-04-19 10:04:54 +02:00
|
|
|
ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt );
|
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;
|
|
|
|
}
|
2008-12-31 20:49:07 +01:00
|
|
|
__ms_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
|
|
|
{
|
2008-12-31 20:49:07 +01:00
|
|
|
__ms_va_list list;
|
2006-04-18 20:41:03 +02:00
|
|
|
int ret = 0;
|
|
|
|
char new_fmt[2];
|
|
|
|
|
|
|
|
new_fmt[1] = 0;
|
2008-12-31 20:49:07 +01:00
|
|
|
__ms_va_start( list, fmt );
|
2006-04-18 20:41:03 +02:00
|
|
|
while (*fmt)
|
|
|
|
{
|
|
|
|
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-04-19 10:04:54 +02:00
|
|
|
if ((ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, &str )) == -1) break;
|
2021-04-14 09:40:26 +02:00
|
|
|
*ptr = strdupU( str );
|
2021-04-19 10:04:54 +02:00
|
|
|
ldap_funcs->fn_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-04-14 09:40:26 +02:00
|
|
|
{
|
|
|
|
int *i = va_arg( list, int * );
|
2021-04-19 10:04:54 +02:00
|
|
|
ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, i );
|
2021-04-14 09:40:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-04-18 20:41:03 +02:00
|
|
|
case 't':
|
2021-04-14 09:40:26 +02:00
|
|
|
{
|
|
|
|
unsigned int *tag = va_arg( list, unsigned int * );
|
2021-04-19 10:04:54 +02:00
|
|
|
ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, tag );
|
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-04-19 10:04:54 +02:00
|
|
|
if ((ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, &arrayU )) == -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-04-19 10:04:54 +02:00
|
|
|
ldap_funcs->fn_ldap_memfree( str );
|
2021-04-14 09:40:26 +02:00
|
|
|
ptr++;
|
2006-04-18 20:41:03 +02:00
|
|
|
}
|
2021-04-19 10:04:54 +02:00
|
|
|
ldap_funcs->fn_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-04-19 10:04:54 +02:00
|
|
|
if ((ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, &strU, len )) == -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-04-19 10:04:54 +02:00
|
|
|
ldap_funcs->fn_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-04-19 10:04:54 +02:00
|
|
|
if ((ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, &bervalU )) == -1) break;
|
2021-04-14 09:40:26 +02:00
|
|
|
*berval = bervalUtoW( bervalU );
|
2021-04-19 10:04:54 +02:00
|
|
|
ldap_funcs->fn_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-04-19 10:04:54 +02:00
|
|
|
if ((ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, &arrayU )) == -1) break;
|
2021-04-14 09:40:26 +02:00
|
|
|
*array = bvarrayUtoW( arrayU );
|
2021-04-19 10:04:54 +02:00
|
|
|
ldap_funcs->fn_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-04-19 10:04:54 +02:00
|
|
|
ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt );
|
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;
|
|
|
|
}
|
2008-12-31 20:49:07 +01:00
|
|
|
__ms_va_end( list );
|
2006-04-18 20:41:03 +02:00
|
|
|
return ret;
|
2005-07-18 20:06:42 +02:00
|
|
|
}
|