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 for (--i
; i
>= 0; i
--)
194 HeapFree( GetProcessHeap(), 0, str
[i
] );
196 HeapFree( GetProcessHeap(), 0, str
);
207 /***********************************************************************
208 * ldap_get_valuesW (WLDAP32.@)
210 * Retrieve string values for a given attribute.
213 * ld [I] Pointer to an LDAP context.
214 * entry [I] Entry to retrieve values from.
215 * attr [I] Attribute to retrieve values for.
218 * Success: Pointer to a character array holding the values.
222 * Call ldap_get_valuesW with the result of a call to
223 * ldap_first_entry or ldap_next_entry. Free the returned
224 * array with a call to ldap_value_freeW.
226 PWCHAR
* CDECL
ldap_get_valuesW( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*entry
, PWCHAR attr
)
230 char *attrU
= NULL
, **retU
;
233 TRACE( "(%p, %p, %s)\n", ld
, entry
, debugstr_w(attr
) );
235 if (!ld
|| !entry
|| !attr
) return NULL
;
237 attrU
= strWtoU( attr
);
238 if (!attrU
) return NULL
;
240 bv
= ldap_get_values_len( ld
, entry
, attrU
);
242 retU
= bv2str_array( bv
);
243 ret
= strarrayUtoW( retU
);
245 ldap_value_free_len( bv
);
246 strarrayfreeU( retU
);
253 /***********************************************************************
254 * ldap_get_values_lenA (WLDAP32.@)
256 * See ldap_get_values_lenW.
258 struct WLDAP32_berval
** CDECL
ldap_get_values_lenA( WLDAP32_LDAP
*ld
,
259 WLDAP32_LDAPMessage
*message
, PCHAR attr
)
263 struct WLDAP32_berval
**ret
;
265 TRACE( "(%p, %p, %s)\n", ld
, message
, debugstr_a(attr
) );
267 if (!ld
|| !message
|| !attr
) return NULL
;
269 attrW
= strAtoW( attr
);
270 if (!attrW
) return NULL
;
272 ret
= ldap_get_values_lenW( ld
, message
, attrW
);
281 /***********************************************************************
282 * ldap_get_values_lenW (WLDAP32.@)
284 * Retrieve binary values for a given attribute.
287 * ld [I] Pointer to an LDAP context.
288 * message [I] Entry to retrieve values from.
289 * attr [I] Attribute to retrieve values for.
292 * Success: Pointer to a berval array holding the values.
296 * Call ldap_get_values_lenW with the result of a call to
297 * ldap_first_entry or ldap_next_entry. Free the returned
298 * array with a call to ldap_value_free_len.
300 struct WLDAP32_berval
** CDECL
ldap_get_values_lenW( WLDAP32_LDAP
*ld
,
301 WLDAP32_LDAPMessage
*message
, PWCHAR attr
)
307 TRACE( "(%p, %p, %s)\n", ld
, message
, debugstr_w(attr
) );
309 if (!ld
|| !message
|| !attr
) return NULL
;
311 attrU
= strWtoU( attr
);
312 if (!attrU
) return NULL
;
314 ret
= ldap_get_values_len( ld
, message
, attrU
);
317 return (struct WLDAP32_berval
**)ret
;
323 /***********************************************************************
324 * ldap_value_free_len (WLDAP32.@)
326 * Free an array of berval structures.
329 * vals [I] Array of berval structures.
332 * Success: LDAP_SUCCESS
333 * Failure: An LDAP error code.
335 ULONG CDECL
WLDAP32_ldap_value_free_len( struct WLDAP32_berval
**vals
)
339 TRACE( "(%p)\n", vals
);
340 ldap_value_free_len( (struct berval
**)vals
);
346 /***********************************************************************
347 * ldap_value_freeA (WLDAP32.@)
349 * See ldap_value_freeW.
351 ULONG CDECL
ldap_value_freeA( PCHAR
*vals
)
353 TRACE( "(%p)\n", vals
);
355 strarrayfreeA( vals
);
359 /***********************************************************************
360 * ldap_value_freeW (WLDAP32.@)
362 * Free an array of string values.
365 * vals [I] Array of string values.
368 * Success: LDAP_SUCCESS
369 * Failure: An LDAP error code.
371 ULONG CDECL
ldap_value_freeW( PWCHAR
*vals
)
373 TRACE( "(%p)\n", vals
);
375 strarrayfreeW( vals
);