2 * WLDAP32 - LDAP support for Wine
4 * Copyright 2005 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
24 #include "wine/debug.h"
35 #define LDAP_SUCCESS 0x00
36 #define LDAP_NOT_SUPPORTED 0x5c
39 #include "winldap_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
44 /***********************************************************************
45 * ldap_count_values_len (WLDAP32.@)
47 * Count the number of values in an array of berval structures.
50 * vals [I] Pointer to an array of berval structures.
53 * Success: The number of values counted.
57 * Call ldap_count_values_len with the result of a call to
58 * ldap_get_values_len.
60 ULONG CDECL WLDAP32_ldap_count_values_len( struct WLDAP32_berval **vals )
62 ULONG ret = LDAP_NOT_SUPPORTED;
65 TRACE( "(%p)\n", vals );
66 ret = ldap_count_values_len( (struct berval **)vals );
72 /***********************************************************************
73 * ldap_count_valuesA (WLDAP32.@)
75 * See ldap_count_valuesW.
77 ULONG CDECL ldap_count_valuesA( PCHAR *vals )
79 ULONG ret = LDAP_NOT_SUPPORTED;
83 TRACE( "(%p)\n", vals );
87 valsW = strarrayAtoW( vals );
88 if (!valsW) return WLDAP32_LDAP_NO_MEMORY;
90 ret = ldap_count_valuesW( valsW );
91 strarrayfreeW( valsW );
97 /***********************************************************************
98 * ldap_count_valuesW (WLDAP32.@)
100 * Count the number of values in a string array.
103 * vals [I] Pointer to an array of strings.
106 * Success: The number of values counted.
110 * Call ldap_count_valuesW with the result of a call to
113 ULONG CDECL ldap_count_valuesW( PWCHAR *vals )
115 ULONG ret = LDAP_NOT_SUPPORTED;
119 TRACE( "(%p)\n", vals );
130 /***********************************************************************
131 * ldap_get_valuesA (WLDAP32.@)
133 * See ldap_get_valuesW.
135 PCHAR * CDECL ldap_get_valuesA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PCHAR attr )
139 WCHAR *attrW = NULL, **retW;
141 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_a(attr) );
143 if (!ld || !entry || !attr) return NULL;
145 attrW = strAtoW( attr );
146 if (!attrW) return NULL;
148 retW = ldap_get_valuesW( ld, entry, attrW );
150 ret = strarrayWtoA( retW );
151 ldap_value_freeW( retW );
159 static char *bv2str( struct berval *bv )
162 unsigned int len = bv->bv_len;
164 str = HeapAlloc( GetProcessHeap(), 0, len + 1 );
167 memcpy( str, bv->bv_val, len );
173 static char **bv2str_array( struct berval **bv )
175 unsigned int len = 0, i = 0;
176 struct berval **p = bv;
184 str = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(char *) );
185 if (!str) return NULL;
190 str[i] = bv2str( *p );
193 while (i > 0) HeapFree( GetProcessHeap(), 0, str[--i] );
194 HeapFree( GetProcessHeap(), 0, str );
205 /***********************************************************************
206 * ldap_get_valuesW (WLDAP32.@)
208 * Retrieve string values for a given attribute.
211 * ld [I] Pointer to an LDAP context.
212 * entry [I] Entry to retrieve values from.
213 * attr [I] Attribute to retrieve values for.
216 * Success: Pointer to a character array holding the values.
220 * Call ldap_get_valuesW with the result of a call to
221 * ldap_first_entry or ldap_next_entry. Free the returned
222 * array with a call to ldap_value_freeW.
224 PWCHAR * CDECL ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PWCHAR attr )
228 char *attrU = NULL, **retU;
231 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_w(attr) );
233 if (!ld || !entry || !attr) return NULL;
235 attrU = strWtoU( attr );
236 if (!attrU) return NULL;
238 bv = ldap_get_values_len( ld, entry, attrU );
240 retU = bv2str_array( bv );
241 ret = strarrayUtoW( retU );
243 ldap_value_free_len( bv );
244 strarrayfreeU( retU );
251 /***********************************************************************
252 * ldap_get_values_lenA (WLDAP32.@)
254 * See ldap_get_values_lenW.
256 struct WLDAP32_berval ** CDECL ldap_get_values_lenA( WLDAP32_LDAP *ld,
257 WLDAP32_LDAPMessage *message, PCHAR attr )
261 struct WLDAP32_berval **ret;
263 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_a(attr) );
265 if (!ld || !message || !attr) return NULL;
267 attrW = strAtoW( attr );
268 if (!attrW) return NULL;
270 ret = ldap_get_values_lenW( ld, message, attrW );
279 /***********************************************************************
280 * ldap_get_values_lenW (WLDAP32.@)
282 * Retrieve binary values for a given attribute.
285 * ld [I] Pointer to an LDAP context.
286 * message [I] Entry to retrieve values from.
287 * attr [I] Attribute to retrieve values for.
290 * Success: Pointer to a berval array holding the values.
294 * Call ldap_get_values_lenW with the result of a call to
295 * ldap_first_entry or ldap_next_entry. Free the returned
296 * array with a call to ldap_value_free_len.
298 struct WLDAP32_berval ** CDECL ldap_get_values_lenW( WLDAP32_LDAP *ld,
299 WLDAP32_LDAPMessage *message, PWCHAR attr )
305 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_w(attr) );
307 if (!ld || !message || !attr) return NULL;
309 attrU = strWtoU( attr );
310 if (!attrU) return NULL;
312 ret = ldap_get_values_len( ld, message, attrU );
315 return (struct WLDAP32_berval **)ret;
321 /***********************************************************************
322 * ldap_value_free_len (WLDAP32.@)
324 * Free an array of berval structures.
327 * vals [I] Array of berval structures.
330 * Success: LDAP_SUCCESS
331 * Failure: An LDAP error code.
333 ULONG CDECL WLDAP32_ldap_value_free_len( struct WLDAP32_berval **vals )
337 TRACE( "(%p)\n", vals );
338 ldap_value_free_len( (struct berval **)vals );
344 /***********************************************************************
345 * ldap_value_freeA (WLDAP32.@)
347 * See ldap_value_freeW.
349 ULONG CDECL ldap_value_freeA( PCHAR *vals )
351 TRACE( "(%p)\n", vals );
353 strarrayfreeA( vals );
357 /***********************************************************************
358 * ldap_value_freeW (WLDAP32.@)
360 * Free an array of string values.
363 * vals [I] Array of string values.
366 * Success: LDAP_SUCCESS
367 * Failure: An LDAP error code.
369 ULONG CDECL ldap_value_freeW( PWCHAR *vals )
371 TRACE( "(%p)\n", vals );
373 strarrayfreeW( vals );