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_searchA (WLDAP32.@)
46 ULONG CDECL
ldap_searchA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
, PCHAR filter
,
47 PCHAR attrs
[], ULONG attrsonly
)
49 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
51 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
53 ret
= WLDAP32_LDAP_NO_MEMORY
;
55 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld
, debugstr_a(base
),
56 scope
, debugstr_a(filter
), attrs
, attrsonly
);
61 baseW
= strAtoW( base
);
62 if (!baseW
) goto exit
;
65 filterW
= strAtoW( filter
);
66 if (!filterW
) goto exit
;
69 attrsW
= strarrayAtoW( attrs
);
70 if (!attrsW
) goto exit
;
73 ret
= ldap_searchW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
);
78 strarrayfreeW( attrsW
);
84 /***********************************************************************
85 * ldap_searchW (WLDAP32.@)
87 * Search a directory tree (asynchronous operation).
90 * ld [I] Pointer to an LDAP context.
91 * base [I] Starting point for the search.
92 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
93 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
94 * filter [I] Search filter.
95 * attrs [I] Attributes to return.
96 * attrsonly [I] Return no values, only attributes.
99 * Success: Message ID of the search operation.
103 * Call ldap_result with the message ID to get the result of
104 * the operation. Cancel the operation by calling ldap_abandon
105 * with the message ID.
107 ULONG CDECL
ldap_searchW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
, PWCHAR filter
,
108 PWCHAR attrs
[], ULONG attrsonly
)
110 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
112 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
115 ret
= WLDAP32_LDAP_NO_MEMORY
;
117 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld
, debugstr_w(base
),
118 scope
, debugstr_w(filter
), attrs
, attrsonly
);
120 if (!ld
) return ~0UL;
123 baseU
= strWtoU( base
);
124 if (!baseU
) goto exit
;
127 filterU
= strWtoU( filter
);
128 if (!filterU
) goto exit
;
131 attrsU
= strarrayWtoU( attrs
);
132 if (!attrsU
) goto exit
;
135 ret
= ldap_search_ext( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
136 NULL
, NULL
, NULL
, 0, &msg
);
138 if (ret
== LDAP_SUCCESS
)
146 strarrayfreeU( attrsU
);
152 /***********************************************************************
153 * ldap_search_extA (WLDAP32.@)
155 * See ldap_search_extW.
157 ULONG CDECL
ldap_search_extA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
,
158 PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
, PLDAPControlA
*serverctrls
,
159 PLDAPControlA
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, ULONG
*message
)
161 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
163 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
164 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
166 ret
= WLDAP32_LDAP_NO_MEMORY
;
168 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, 0x%08x, 0x%08x, %p)\n",
169 ld
, debugstr_a(base
), scope
, debugstr_a(filter
), attrs
, attrsonly
,
170 serverctrls
, clientctrls
, timelimit
, sizelimit
, message
);
172 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
175 baseW
= strAtoW( base
);
176 if (!baseW
) goto exit
;
180 filterW
= strAtoW( filter
);
181 if (!filterW
) goto exit
;
184 attrsW
= strarrayAtoW( attrs
);
185 if (!attrsW
) goto exit
;
188 serverctrlsW
= controlarrayAtoW( serverctrls
);
189 if (!serverctrlsW
) goto exit
;
192 clientctrlsW
= controlarrayAtoW( clientctrls
);
193 if (!clientctrlsW
) goto exit
;
196 ret
= ldap_search_extW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
,
197 serverctrlsW
, clientctrlsW
, timelimit
, sizelimit
, message
);
202 strarrayfreeW( attrsW
);
203 controlarrayfreeW( serverctrlsW
);
204 controlarrayfreeW( clientctrlsW
);
210 /***********************************************************************
211 * ldap_search_extW (WLDAP32.@)
213 * Search a directory tree (asynchronous operation).
216 * ld [I] Pointer to an LDAP context.
217 * base [I] Starting point for the search.
218 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
219 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
220 * filter [I] Search filter.
221 * attrs [I] Attributes to return.
222 * attrsonly [I] Return no values, only attributes.
223 * serverctrls [I] Array of LDAP server controls.
224 * clientctrls [I] Array of LDAP client controls.
225 * timelimit [I] Timeout in seconds.
226 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
227 * message [O] Message ID of the search operation.
230 * Success: LDAP_SUCCESS
231 * Failure: An LDAP error code.
234 * Call ldap_result with the message ID to get the result of
235 * the operation. Cancel the operation by calling ldap_abandon
236 * with the message ID.
238 ULONG CDECL
ldap_search_extW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
,
239 PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
, PLDAPControlW
*serverctrls
,
240 PLDAPControlW
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, ULONG
*message
)
242 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
244 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
245 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
248 ret
= WLDAP32_LDAP_NO_MEMORY
;
250 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, 0x%08x, 0x%08x, %p)\n",
251 ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
, attrsonly
,
252 serverctrls
, clientctrls
, timelimit
, sizelimit
, message
);
254 if (!ld
) return ~0UL;
257 baseU
= strWtoU( base
);
258 if (!baseU
) goto exit
;
261 filterU
= strWtoU( filter
);
262 if (!filterU
) goto exit
;
265 attrsU
= strarrayWtoU( attrs
);
266 if (!attrsU
) goto exit
;
269 serverctrlsU
= controlarrayWtoU( serverctrls
);
270 if (!serverctrlsU
) goto exit
;
273 clientctrlsU
= controlarrayWtoU( clientctrls
);
274 if (!clientctrlsU
) goto exit
;
277 tv
.tv_sec
= timelimit
;
280 ret
= map_error( ldap_search_ext( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
281 serverctrlsU
, clientctrlsU
, &tv
, sizelimit
, (int *)message
));
286 strarrayfreeU( attrsU
);
287 controlarrayfreeU( serverctrlsU
);
288 controlarrayfreeU( clientctrlsU
);
294 /***********************************************************************
295 * ldap_search_ext_sA (WLDAP32.@)
297 * See ldap_search_ext_sW.
299 ULONG CDECL
ldap_search_ext_sA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
,
300 PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
, PLDAPControlA
*serverctrls
,
301 PLDAPControlA
*clientctrls
, struct l_timeval
* timeout
, ULONG sizelimit
, WLDAP32_LDAPMessage
**res
)
303 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
305 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
306 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
308 ret
= WLDAP32_LDAP_NO_MEMORY
;
310 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n",
311 ld
, debugstr_a(base
), scope
, debugstr_a(filter
), attrs
, attrsonly
,
312 serverctrls
, clientctrls
, timeout
, sizelimit
, res
);
314 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
317 baseW
= strAtoW( base
);
318 if (!baseW
) goto exit
;
321 filterW
= strAtoW( filter
);
322 if (!filterW
) goto exit
;
325 attrsW
= strarrayAtoW( attrs
);
326 if (!attrsW
) goto exit
;
329 serverctrlsW
= controlarrayAtoW( serverctrls
);
330 if (!serverctrlsW
) goto exit
;
333 clientctrlsW
= controlarrayAtoW( clientctrls
);
334 if (!clientctrlsW
) goto exit
;
337 ret
= ldap_search_ext_sW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
,
338 serverctrlsW
, clientctrlsW
, timeout
, sizelimit
, res
);
343 strarrayfreeW( attrsW
);
344 controlarrayfreeW( serverctrlsW
);
345 controlarrayfreeW( clientctrlsW
);
351 /***********************************************************************
352 * ldap_search_ext_sW (WLDAP32.@)
354 * Search a directory tree (synchronous operation).
357 * ld [I] Pointer to an LDAP context.
358 * base [I] Starting point for the search.
359 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
360 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
361 * filter [I] Search filter.
362 * attrs [I] Attributes to return.
363 * attrsonly [I] Return no values, only attributes.
364 * serverctrls [I] Array of LDAP server controls.
365 * clientctrls [I] Array of LDAP client controls.
366 * timeout [I] Timeout in seconds.
367 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
368 * res [O] Results of the search operation.
371 * Success: LDAP_SUCCESS
372 * Failure: An LDAP error code.
375 * Call ldap_msgfree to free the results.
377 ULONG CDECL
ldap_search_ext_sW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
,
378 PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
, PLDAPControlW
*serverctrls
,
379 PLDAPControlW
*clientctrls
, struct l_timeval
* timeout
, ULONG sizelimit
, WLDAP32_LDAPMessage
**res
)
381 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
383 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
384 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
386 ret
= WLDAP32_LDAP_NO_MEMORY
;
388 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n",
389 ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
, attrsonly
,
390 serverctrls
, clientctrls
, timeout
, sizelimit
, res
);
392 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
395 baseU
= strWtoU( base
);
396 if (!baseU
) goto exit
;
399 filterU
= strWtoU( filter
);
400 if (!filterU
) goto exit
;
403 attrsU
= strarrayWtoU( attrs
);
404 if (!attrsU
) goto exit
;
407 serverctrlsU
= controlarrayWtoU( serverctrls
);
408 if (!serverctrlsU
) goto exit
;
411 clientctrlsU
= controlarrayWtoU( clientctrls
);
412 if (!clientctrlsU
) goto exit
;
415 ret
= map_error( ldap_search_ext_s( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
416 serverctrlsU
, clientctrlsU
, (struct timeval
*)timeout
,
422 strarrayfreeU( attrsU
);
423 controlarrayfreeU( serverctrlsU
);
424 controlarrayfreeU( clientctrlsU
);
430 /***********************************************************************
431 * ldap_search_sA (WLDAP32.@)
433 * See ldap_search_sW.
435 ULONG CDECL
ldap_search_sA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
, PCHAR filter
,
436 PCHAR attrs
[], ULONG attrsonly
, WLDAP32_LDAPMessage
**res
)
438 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
440 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
442 ret
= WLDAP32_LDAP_NO_MEMORY
;
444 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p)\n", ld
, debugstr_a(base
),
445 scope
, debugstr_a(filter
), attrs
, attrsonly
, res
);
447 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
450 baseW
= strAtoW( base
);
451 if (!baseW
) goto exit
;
454 filterW
= strAtoW( filter
);
455 if (!filterW
) goto exit
;
458 attrsW
= strarrayAtoW( attrs
);
459 if (!attrsW
) goto exit
;
462 ret
= ldap_search_sW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
, res
);
467 strarrayfreeW( attrsW
);
473 /***********************************************************************
474 * ldap_search_sW (WLDAP32.@)
476 * Search a directory tree (synchronous operation).
479 * ld [I] Pointer to an LDAP context.
480 * base [I] Starting point for the search.
481 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
482 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
483 * filter [I] Search filter.
484 * attrs [I] Attributes to return.
485 * attrsonly [I] Return no values, only attributes.
486 * res [O] Results of the search operation.
489 * Success: LDAP_SUCCESS
490 * Failure: An LDAP error code.
493 * Call ldap_msgfree to free the results.
495 ULONG CDECL
ldap_search_sW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
, PWCHAR filter
,
496 PWCHAR attrs
[], ULONG attrsonly
, WLDAP32_LDAPMessage
**res
)
498 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
500 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
502 ret
= WLDAP32_LDAP_NO_MEMORY
;
504 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p)\n", ld
, debugstr_w(base
),
505 scope
, debugstr_w(filter
), attrs
, attrsonly
, res
);
507 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
510 baseU
= strWtoU( base
);
511 if (!baseU
) goto exit
;
514 filterU
= strWtoU( filter
);
515 if (!filterU
) goto exit
;
518 attrsU
= strarrayWtoU( attrs
);
519 if (!attrsU
) goto exit
;
522 ret
= map_error( ldap_search_ext_s( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
523 NULL
, NULL
, NULL
, 0, res
));
528 strarrayfreeU( attrsU
);
534 /***********************************************************************
535 * ldap_search_stA (WLDAP32.@)
537 * See ldap_search_stW.
539 ULONG CDECL
ldap_search_stA( WLDAP32_LDAP
*ld
, const PCHAR base
, ULONG scope
,
540 const PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
,
541 struct l_timeval
*timeout
, WLDAP32_LDAPMessage
**res
)
543 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
545 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
547 ret
= WLDAP32_LDAP_NO_MEMORY
;
549 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p)\n", ld
,
550 debugstr_a(base
), scope
, debugstr_a(filter
), attrs
,
551 attrsonly
, timeout
, res
);
553 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
556 baseW
= strAtoW( base
);
557 if (!baseW
) goto exit
;
560 filterW
= strAtoW( filter
);
561 if (!filterW
) goto exit
;
564 attrsW
= strarrayAtoW( attrs
);
565 if (!attrsW
) goto exit
;
568 ret
= ldap_search_stW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
,
574 strarrayfreeW( attrsW
);
580 /***********************************************************************
581 * ldap_search_stW (WLDAP32.@)
583 * Search a directory tree (synchronous operation).
586 * ld [I] Pointer to an LDAP context.
587 * base [I] Starting point for the search.
588 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
589 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
590 * filter [I] Search filter.
591 * attrs [I] Attributes to return.
592 * attrsonly [I] Return no values, only attributes.
593 * timeout [I] Timeout in seconds.
594 * res [O] Results of the search operation.
597 * Success: LDAP_SUCCESS
598 * Failure: An LDAP error code.
601 * Call ldap_msgfree to free the results.
603 ULONG CDECL
ldap_search_stW( WLDAP32_LDAP
*ld
, const PWCHAR base
, ULONG scope
,
604 const PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
,
605 struct l_timeval
*timeout
, WLDAP32_LDAPMessage
**res
)
607 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
609 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
611 ret
= WLDAP32_LDAP_NO_MEMORY
;
613 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p)\n", ld
,
614 debugstr_w(base
), scope
, debugstr_w(filter
), attrs
,
615 attrsonly
, timeout
, res
);
617 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
620 baseU
= strWtoU( base
);
621 if (!baseU
) goto exit
;
624 filterU
= strWtoU( filter
);
625 if (!filterU
) goto exit
;
628 attrsU
= strarrayWtoU( attrs
);
629 if (!attrsU
) goto exit
;
632 ret
= map_error( ldap_search_ext_s( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
633 NULL
, NULL
, (struct timeval
*)timeout
, 0, res
));
638 strarrayfreeU( attrsU
);