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"
36 #include "winldap_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
41 /***********************************************************************
42 * ldap_count_values_len (WLDAP32.@)
44 * Count the number of values in an array of berval structures.
47 * vals [I] Pointer to an array of berval structures.
50 * Success: The number of values counted.
54 * Call ldap_count_values_len with the result of a call to
55 * ldap_get_values_len.
57 ULONG CDECL
WLDAP32_ldap_count_values_len( struct WLDAP32_berval
**vals
)
59 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
62 TRACE( "(%p)\n", vals
);
63 ret
= ldap_count_values_len( (struct berval
**)vals
);
69 /***********************************************************************
70 * ldap_count_valuesA (WLDAP32.@)
72 * See ldap_count_valuesW.
74 ULONG CDECL
ldap_count_valuesA( PCHAR
*vals
)
76 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
80 TRACE( "(%p)\n", vals
);
84 valsW
= strarrayAtoW( vals
);
85 if (!valsW
) return WLDAP32_LDAP_NO_MEMORY
;
87 ret
= ldap_count_valuesW( valsW
);
88 strarrayfreeW( valsW
);
94 /***********************************************************************
95 * ldap_count_valuesW (WLDAP32.@)
97 * Count the number of values in a string array.
100 * vals [I] Pointer to an array of strings.
103 * Success: The number of values counted.
107 * Call ldap_count_valuesW with the result of a call to
110 ULONG CDECL
ldap_count_valuesW( PWCHAR
*vals
)
112 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
116 TRACE( "(%p)\n", vals
);
127 /***********************************************************************
128 * ldap_get_valuesA (WLDAP32.@)
130 * See ldap_get_valuesW.
132 PCHAR
* CDECL
ldap_get_valuesA( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*entry
, PCHAR attr
)
136 WCHAR
*attrW
= NULL
, **retW
;
138 TRACE( "(%p, %p, %s)\n", ld
, entry
, debugstr_a(attr
) );
140 if (!ld
|| !entry
|| !attr
) return NULL
;
142 attrW
= strAtoW( attr
);
143 if (!attrW
) return NULL
;
145 retW
= ldap_get_valuesW( ld
, entry
, attrW
);
147 ret
= strarrayWtoA( retW
);
148 ldap_value_freeW( retW
);
156 static char *bv2str( struct berval
*bv
)
159 unsigned int len
= bv
->bv_len
;
161 str
= HeapAlloc( GetProcessHeap(), 0, len
+ 1 );
164 memcpy( str
, bv
->bv_val
, len
);
170 static char **bv2str_array( struct berval
**bv
)
172 unsigned int len
= 0, i
= 0;
173 struct berval
**p
= bv
;
181 str
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(char *) );
182 if (!str
) return NULL
;
187 str
[i
] = bv2str( *p
);
190 while (i
> 0) HeapFree( GetProcessHeap(), 0, str
[--i
] );
191 HeapFree( GetProcessHeap(), 0, str
);
202 /***********************************************************************
203 * ldap_get_valuesW (WLDAP32.@)
205 * Retrieve string values for a given attribute.
208 * ld [I] Pointer to an LDAP context.
209 * entry [I] Entry to retrieve values from.
210 * attr [I] Attribute to retrieve values for.
213 * Success: Pointer to a character array holding the values.
217 * Call ldap_get_valuesW with the result of a call to
218 * ldap_first_entry or ldap_next_entry. Free the returned
219 * array with a call to ldap_value_freeW.
221 PWCHAR
* CDECL
ldap_get_valuesW( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*entry
, PWCHAR attr
)
225 char *attrU
= NULL
, **retU
;
228 TRACE( "(%p, %p, %s)\n", ld
, entry
, debugstr_w(attr
) );
230 if (!ld
|| !entry
|| !attr
) return NULL
;
232 attrU
= strWtoU( attr
);
233 if (!attrU
) return NULL
;
235 bv
= ldap_get_values_len( ld
, entry
, attrU
);
237 retU
= bv2str_array( bv
);
238 ret
= strarrayUtoW( retU
);
240 ldap_value_free_len( bv
);
241 strarrayfreeU( retU
);
248 /***********************************************************************
249 * ldap_get_values_lenA (WLDAP32.@)
251 * See ldap_get_values_lenW.
253 struct WLDAP32_berval
** CDECL
ldap_get_values_lenA( WLDAP32_LDAP
*ld
,
254 WLDAP32_LDAPMessage
*message
, PCHAR attr
)
258 struct WLDAP32_berval
**ret
;
260 TRACE( "(%p, %p, %s)\n", ld
, message
, debugstr_a(attr
) );
262 if (!ld
|| !message
|| !attr
) return NULL
;
264 attrW
= strAtoW( attr
);
265 if (!attrW
) return NULL
;
267 ret
= ldap_get_values_lenW( ld
, message
, attrW
);
277 /***********************************************************************
278 * ldap_get_values_lenW (WLDAP32.@)
280 * Retrieve binary values for a given attribute.
283 * ld [I] Pointer to an LDAP context.
284 * message [I] Entry to retrieve values from.
285 * attr [I] Attribute to retrieve values for.
288 * Success: Pointer to a berval array holding the values.
292 * Call ldap_get_values_lenW with the result of a call to
293 * ldap_first_entry or ldap_next_entry. Free the returned
294 * array with a call to ldap_value_free_len.
296 struct WLDAP32_berval
** CDECL
ldap_get_values_lenW( WLDAP32_LDAP
*ld
,
297 WLDAP32_LDAPMessage
*message
, PWCHAR attr
)
303 TRACE( "(%p, %p, %s)\n", ld
, message
, debugstr_w(attr
) );
305 if (!ld
|| !message
|| !attr
) return NULL
;
307 attrU
= strWtoU( attr
);
308 if (!attrU
) return NULL
;
310 ret
= ldap_get_values_len( ld
, message
, attrU
);
313 return (struct WLDAP32_berval
**)ret
;
320 /***********************************************************************
321 * ldap_value_free_len (WLDAP32.@)
323 * Free an array of berval structures.
326 * vals [I] Array of berval structures.
329 * Success: LDAP_SUCCESS
330 * Failure: An LDAP error code.
332 ULONG CDECL
WLDAP32_ldap_value_free_len( struct WLDAP32_berval
**vals
)
336 TRACE( "(%p)\n", vals
);
337 ldap_value_free_len( (struct berval
**)vals
);
340 return WLDAP32_LDAP_SUCCESS
;
343 /***********************************************************************
344 * ldap_value_freeA (WLDAP32.@)
346 * See ldap_value_freeW.
348 ULONG CDECL
ldap_value_freeA( PCHAR
*vals
)
350 TRACE( "(%p)\n", vals
);
352 strarrayfreeA( vals
);
353 return WLDAP32_LDAP_SUCCESS
;
356 /***********************************************************************
357 * ldap_value_freeW (WLDAP32.@)
359 * Free an array of string values.
362 * vals [I] Array of string values.
365 * Success: LDAP_SUCCESS
366 * Failure: An LDAP error code.
368 ULONG CDECL
ldap_value_freeW( PWCHAR
*vals
)
370 TRACE( "(%p)\n", vals
);
372 strarrayfreeW( vals
);
373 return WLDAP32_LDAP_SUCCESS
;