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
22 #include "wine/port.h"
33 #include "winldap_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
39 /***********************************************************************
40 * ldap_count_values_len (WLDAP32.@)
42 * Count the number of values in an array of berval structures.
45 * vals [I] Pointer to an array of berval structures.
48 * Success: The number of values counted.
52 * Call ldap_count_values_len with the result of a call to
53 * ldap_get_values_len.
55 ULONG CDECL
WLDAP32_ldap_count_values_len( struct WLDAP32_berval
**vals
)
57 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
60 TRACE( "(%p)\n", vals
);
61 ret
= ldap_count_values_len( (struct berval
**)vals
);
67 /***********************************************************************
68 * ldap_count_valuesA (WLDAP32.@)
70 * See ldap_count_valuesW.
72 ULONG CDECL
ldap_count_valuesA( PCHAR
*vals
)
74 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
78 TRACE( "(%p)\n", vals
);
82 valsW
= strarrayAtoW( vals
);
83 if (!valsW
) return WLDAP32_LDAP_NO_MEMORY
;
85 ret
= ldap_count_valuesW( valsW
);
86 strarrayfreeW( valsW
);
92 /***********************************************************************
93 * ldap_count_valuesW (WLDAP32.@)
95 * Count the number of values in a string array.
98 * vals [I] Pointer to an array of strings.
101 * Success: The number of values counted.
105 * Call ldap_count_valuesW with the result of a call to
108 ULONG CDECL
ldap_count_valuesW( PWCHAR
*vals
)
110 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
114 TRACE( "(%p)\n", vals
);
125 /***********************************************************************
126 * ldap_get_valuesA (WLDAP32.@)
128 * See ldap_get_valuesW.
130 PCHAR
* CDECL
ldap_get_valuesA( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*entry
, PCHAR attr
)
134 WCHAR
*attrW
= NULL
, **retW
;
136 TRACE( "(%p, %p, %s)\n", ld
, entry
, debugstr_a(attr
) );
138 if (!ld
|| !entry
|| !attr
) return NULL
;
140 attrW
= strAtoW( attr
);
141 if (!attrW
) return NULL
;
143 retW
= ldap_get_valuesW( ld
, entry
, attrW
);
145 ret
= strarrayWtoA( retW
);
146 ldap_value_freeW( retW
);
154 static char *bv2str( struct berval
*bv
)
157 unsigned int len
= bv
->bv_len
;
159 if ((str
= heap_alloc( len
+ 1 )))
161 memcpy( str
, bv
->bv_val
, len
);
167 static char **bv2str_array( struct berval
**bv
)
169 unsigned int len
= 0, i
= 0;
170 struct berval
**p
= bv
;
178 if (!(str
= heap_alloc( (len
+ 1) * sizeof(char *) ))) return NULL
;
183 str
[i
] = bv2str( *p
);
186 while (i
> 0) heap_free( str
[--i
] );
198 /***********************************************************************
199 * ldap_get_valuesW (WLDAP32.@)
201 * Retrieve string values for a given attribute.
204 * ld [I] Pointer to an LDAP context.
205 * entry [I] Entry to retrieve values from.
206 * attr [I] Attribute to retrieve values for.
209 * Success: Pointer to a character array holding the values.
213 * Call ldap_get_valuesW with the result of a call to
214 * ldap_first_entry or ldap_next_entry. Free the returned
215 * array with a call to ldap_value_freeW.
217 PWCHAR
* CDECL
ldap_get_valuesW( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*entry
, PWCHAR attr
)
221 char *attrU
= NULL
, **retU
;
224 TRACE( "(%p, %p, %s)\n", ld
, entry
, debugstr_w(attr
) );
226 if (!ld
|| !entry
|| !attr
) return NULL
;
228 attrU
= strWtoU( attr
);
229 if (!attrU
) return NULL
;
231 bv
= ldap_get_values_len( ld
, entry
, attrU
);
233 retU
= bv2str_array( bv
);
234 ret
= strarrayUtoW( retU
);
236 ldap_value_free_len( bv
);
237 strarrayfreeU( retU
);
244 /***********************************************************************
245 * ldap_get_values_lenA (WLDAP32.@)
247 * See ldap_get_values_lenW.
249 struct WLDAP32_berval
** CDECL
ldap_get_values_lenA( WLDAP32_LDAP
*ld
,
250 WLDAP32_LDAPMessage
*message
, PCHAR attr
)
254 struct WLDAP32_berval
**ret
;
256 TRACE( "(%p, %p, %s)\n", ld
, message
, debugstr_a(attr
) );
258 if (!ld
|| !message
|| !attr
) return NULL
;
260 attrW
= strAtoW( attr
);
261 if (!attrW
) return NULL
;
263 ret
= ldap_get_values_lenW( ld
, message
, attrW
);
273 /***********************************************************************
274 * ldap_get_values_lenW (WLDAP32.@)
276 * Retrieve binary values for a given attribute.
279 * ld [I] Pointer to an LDAP context.
280 * message [I] Entry to retrieve values from.
281 * attr [I] Attribute to retrieve values for.
284 * Success: Pointer to a berval array holding the values.
288 * Call ldap_get_values_lenW with the result of a call to
289 * ldap_first_entry or ldap_next_entry. Free the returned
290 * array with a call to ldap_value_free_len.
292 struct WLDAP32_berval
** CDECL
ldap_get_values_lenW( WLDAP32_LDAP
*ld
,
293 WLDAP32_LDAPMessage
*message
, PWCHAR attr
)
299 TRACE( "(%p, %p, %s)\n", ld
, message
, debugstr_w(attr
) );
301 if (!ld
|| !message
|| !attr
) return NULL
;
303 attrU
= strWtoU( attr
);
304 if (!attrU
) return NULL
;
306 ret
= ldap_get_values_len( ld
, message
, attrU
);
309 return (struct WLDAP32_berval
**)ret
;
316 /***********************************************************************
317 * ldap_value_free_len (WLDAP32.@)
319 * Free an array of berval structures.
322 * vals [I] Array of berval structures.
325 * Success: LDAP_SUCCESS
326 * Failure: An LDAP error code.
328 ULONG CDECL
WLDAP32_ldap_value_free_len( struct WLDAP32_berval
**vals
)
332 TRACE( "(%p)\n", vals
);
333 ldap_value_free_len( (struct berval
**)vals
);
336 return WLDAP32_LDAP_SUCCESS
;
339 /***********************************************************************
340 * ldap_value_freeA (WLDAP32.@)
342 * See ldap_value_freeW.
344 ULONG CDECL
ldap_value_freeA( PCHAR
*vals
)
346 TRACE( "(%p)\n", vals
);
348 strarrayfreeA( vals
);
349 return WLDAP32_LDAP_SUCCESS
;
352 /***********************************************************************
353 * ldap_value_freeW (WLDAP32.@)
355 * Free an array of string values.
358 * vals [I] Array of string values.
361 * Success: LDAP_SUCCESS
362 * Failure: An LDAP error code.
364 ULONG CDECL
ldap_value_freeW( PWCHAR
*vals
)
366 TRACE( "(%p)\n", vals
);
368 strarrayfreeW( vals
);
369 return WLDAP32_LDAP_SUCCESS
;