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_searchA (WLDAP32.@)
49 ULONG CDECL
ldap_searchA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
, PCHAR filter
,
50 PCHAR attrs
[], ULONG attrsonly
)
52 ULONG ret
= LDAP_NOT_SUPPORTED
;
54 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
56 ret
= WLDAP32_LDAP_NO_MEMORY
;
58 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld
, debugstr_a(base
),
59 scope
, debugstr_a(filter
), attrs
, attrsonly
);
64 baseW
= strAtoW( base
);
65 if (!baseW
) goto exit
;
68 filterW
= strAtoW( filter
);
69 if (!filterW
) goto exit
;
72 attrsW
= strarrayAtoW( attrs
);
73 if (!attrsW
) goto exit
;
76 ret
= ldap_searchW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
);
81 strarrayfreeW( attrsW
);
87 /***********************************************************************
88 * ldap_searchW (WLDAP32.@)
90 * Search a directory tree (asynchronous operation).
93 * ld [I] Pointer to an LDAP context.
94 * base [I] Starting point for the search.
95 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
96 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
97 * filter [I] Search filter.
98 * attrs [I] Attributes to return.
99 * attrsonly [I] Return no values, only attributes.
102 * Success: Message ID of the search operation.
106 * Call ldap_result with the message ID to get the result of
107 * the operation. Cancel the operation by calling ldap_abandon
108 * with the message ID.
110 ULONG CDECL
ldap_searchW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
, PWCHAR filter
,
111 PWCHAR attrs
[], ULONG attrsonly
)
113 ULONG ret
= LDAP_NOT_SUPPORTED
;
115 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
118 ret
= WLDAP32_LDAP_NO_MEMORY
;
120 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld
, debugstr_w(base
),
121 scope
, debugstr_w(filter
), attrs
, attrsonly
);
123 if (!ld
) return ~0UL;
126 baseU
= strWtoU( base
);
127 if (!baseU
) goto exit
;
130 filterU
= strWtoU( filter
);
131 if (!filterU
) goto exit
;
134 attrsU
= strarrayWtoU( attrs
);
135 if (!attrsU
) goto exit
;
138 ret
= ldap_search_ext( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
139 NULL
, NULL
, NULL
, 0, &msg
);
141 if (ret
== LDAP_SUCCESS
)
149 strarrayfreeU( attrsU
);
155 /***********************************************************************
156 * ldap_search_extA (WLDAP32.@)
158 * See ldap_search_extW.
160 ULONG CDECL
ldap_search_extA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
,
161 PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
, PLDAPControlA
*serverctrls
,
162 PLDAPControlA
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, ULONG
*message
)
164 ULONG ret
= LDAP_NOT_SUPPORTED
;
166 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
167 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
169 ret
= WLDAP32_LDAP_NO_MEMORY
;
171 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, 0x%08lx, 0x%08lx, %p)\n",
172 ld
, debugstr_a(base
), scope
, debugstr_a(filter
), attrs
, attrsonly
,
173 serverctrls
, clientctrls
, timelimit
, sizelimit
, message
);
175 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
178 baseW
= strAtoW( base
);
179 if (!baseW
) goto exit
;
183 filterW
= strAtoW( filter
);
184 if (!filterW
) goto exit
;
187 attrsW
= strarrayAtoW( attrs
);
188 if (!attrsW
) goto exit
;
191 serverctrlsW
= controlarrayAtoW( serverctrls
);
192 if (!serverctrlsW
) goto exit
;
195 clientctrlsW
= controlarrayAtoW( clientctrls
);
196 if (!clientctrlsW
) goto exit
;
199 ret
= ldap_search_extW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
,
200 serverctrlsW
, clientctrlsW
, timelimit
, sizelimit
, message
);
205 strarrayfreeW( attrsW
);
206 controlarrayfreeW( serverctrlsW
);
207 controlarrayfreeW( clientctrlsW
);
213 /***********************************************************************
214 * ldap_search_extW (WLDAP32.@)
216 * Search a directory tree (asynchronous operation).
219 * ld [I] Pointer to an LDAP context.
220 * base [I] Starting point for the search.
221 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
222 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
223 * filter [I] Search filter.
224 * attrs [I] Attributes to return.
225 * attrsonly [I] Return no values, only attributes.
226 * serverctrls [I] Array of LDAP server controls.
227 * clientctrls [I] Array of LDAP client controls.
228 * timelimit [I] Timeout in seconds.
229 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
230 * message [O] Message ID of the search operation.
233 * Success: LDAP_SUCCESS
234 * Failure: An LDAP error code.
237 * Call ldap_result with the message ID to get the result of
238 * the operation. Cancel the operation by calling ldap_abandon
239 * with the message ID.
241 ULONG CDECL
ldap_search_extW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
,
242 PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
, PLDAPControlW
*serverctrls
,
243 PLDAPControlW
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, ULONG
*message
)
245 ULONG ret
= LDAP_NOT_SUPPORTED
;
247 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
248 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
251 ret
= WLDAP32_LDAP_NO_MEMORY
;
253 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, 0x%08lx, 0x%08lx, %p)\n",
254 ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
, attrsonly
,
255 serverctrls
, clientctrls
, timelimit
, sizelimit
, message
);
257 if (!ld
) return ~0UL;
260 baseU
= strWtoU( base
);
261 if (!baseU
) goto exit
;
264 filterU
= strWtoU( filter
);
265 if (!filterU
) goto exit
;
268 attrsU
= strarrayWtoU( attrs
);
269 if (!attrsU
) goto exit
;
272 serverctrlsU
= controlarrayWtoU( serverctrls
);
273 if (!serverctrlsU
) goto exit
;
276 clientctrlsU
= controlarrayWtoU( clientctrls
);
277 if (!clientctrlsU
) goto exit
;
280 tv
.tv_sec
= timelimit
;
283 ret
= ldap_search_ext( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
284 serverctrlsU
, clientctrlsU
, &tv
, sizelimit
, (int *)message
);
289 strarrayfreeU( attrsU
);
290 controlarrayfreeU( serverctrlsU
);
291 controlarrayfreeU( clientctrlsU
);
297 /***********************************************************************
298 * ldap_search_ext_sA (WLDAP32.@)
300 * See ldap_search_ext_sW.
302 ULONG CDECL
ldap_search_ext_sA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
,
303 PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
, PLDAPControlA
*serverctrls
,
304 PLDAPControlA
*clientctrls
, struct l_timeval
* timeout
, ULONG sizelimit
, WLDAP32_LDAPMessage
**res
)
306 ULONG ret
= LDAP_NOT_SUPPORTED
;
308 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
309 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
311 ret
= WLDAP32_LDAP_NO_MEMORY
;
313 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, %p, 0x%08lx, %p)\n",
314 ld
, debugstr_a(base
), scope
, debugstr_a(filter
), attrs
, attrsonly
,
315 serverctrls
, clientctrls
, timeout
, sizelimit
, res
);
317 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
320 baseW
= strAtoW( base
);
321 if (!baseW
) goto exit
;
324 filterW
= strAtoW( filter
);
325 if (!filterW
) goto exit
;
328 attrsW
= strarrayAtoW( attrs
);
329 if (!attrsW
) goto exit
;
332 serverctrlsW
= controlarrayAtoW( serverctrls
);
333 if (!serverctrlsW
) goto exit
;
336 clientctrlsW
= controlarrayAtoW( clientctrls
);
337 if (!clientctrlsW
) goto exit
;
340 ret
= ldap_search_ext_sW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
,
341 serverctrlsW
, clientctrlsW
, timeout
, sizelimit
, res
);
346 strarrayfreeW( attrsW
);
347 controlarrayfreeW( serverctrlsW
);
348 controlarrayfreeW( clientctrlsW
);
354 /***********************************************************************
355 * ldap_search_ext_sW (WLDAP32.@)
357 * Search a directory tree (synchronous operation).
360 * ld [I] Pointer to an LDAP context.
361 * base [I] Starting point for the search.
362 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
363 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
364 * filter [I] Search filter.
365 * attrs [I] Attributes to return.
366 * attrsonly [I] Return no values, only attributes.
367 * serverctrls [I] Array of LDAP server controls.
368 * clientctrls [I] Array of LDAP client controls.
369 * timeout [I] Timeout in seconds.
370 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
371 * res [O] Results of the search operation.
374 * Success: LDAP_SUCCESS
375 * Failure: An LDAP error code.
378 * Call ldap_msgfree to free the results.
380 ULONG CDECL
ldap_search_ext_sW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
,
381 PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
, PLDAPControlW
*serverctrls
,
382 PLDAPControlW
*clientctrls
, struct l_timeval
* timeout
, ULONG sizelimit
, WLDAP32_LDAPMessage
**res
)
384 ULONG ret
= LDAP_NOT_SUPPORTED
;
386 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
387 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
389 ret
= WLDAP32_LDAP_NO_MEMORY
;
391 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, %p, 0x%08lx, %p)\n",
392 ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
, attrsonly
,
393 serverctrls
, clientctrls
, timeout
, sizelimit
, res
);
395 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
398 baseU
= strWtoU( base
);
399 if (!baseU
) goto exit
;
402 filterU
= strWtoU( filter
);
403 if (!filterU
) goto exit
;
406 attrsU
= strarrayWtoU( attrs
);
407 if (!attrsU
) goto exit
;
410 serverctrlsU
= controlarrayWtoU( serverctrls
);
411 if (!serverctrlsU
) goto exit
;
414 clientctrlsU
= controlarrayWtoU( clientctrls
);
415 if (!clientctrlsU
) goto exit
;
418 ret
= ldap_search_ext_s( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
419 serverctrlsU
, clientctrlsU
, (struct timeval
*)timeout
, sizelimit
, res
);
424 strarrayfreeU( attrsU
);
425 controlarrayfreeU( serverctrlsU
);
426 controlarrayfreeU( clientctrlsU
);
432 /***********************************************************************
433 * ldap_search_sA (WLDAP32.@)
435 * See ldap_search_sW.
437 ULONG CDECL
ldap_search_sA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
, PCHAR filter
,
438 PCHAR attrs
[], ULONG attrsonly
, WLDAP32_LDAPMessage
**res
)
440 ULONG ret
= LDAP_NOT_SUPPORTED
;
442 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
444 ret
= WLDAP32_LDAP_NO_MEMORY
;
446 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld
, debugstr_a(base
),
447 scope
, debugstr_a(filter
), attrs
, attrsonly
, res
);
449 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
452 baseW
= strAtoW( base
);
453 if (!baseW
) goto exit
;
456 filterW
= strAtoW( filter
);
457 if (!filterW
) goto exit
;
460 attrsW
= strarrayAtoW( attrs
);
461 if (!attrsW
) goto exit
;
464 ret
= ldap_search_sW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
, res
);
469 strarrayfreeW( attrsW
);
475 /***********************************************************************
476 * ldap_search_sW (WLDAP32.@)
478 * Search a directory tree (synchronous operation).
481 * ld [I] Pointer to an LDAP context.
482 * base [I] Starting point for the search.
483 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
484 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
485 * filter [I] Search filter.
486 * attrs [I] Attributes to return.
487 * attrsonly [I] Return no values, only attributes.
488 * res [O] Results of the search operation.
491 * Success: LDAP_SUCCESS
492 * Failure: An LDAP error code.
495 * Call ldap_msgfree to free the results.
497 ULONG CDECL
ldap_search_sW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
, PWCHAR filter
,
498 PWCHAR attrs
[], ULONG attrsonly
, WLDAP32_LDAPMessage
**res
)
500 ULONG ret
= LDAP_NOT_SUPPORTED
;
502 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
504 ret
= WLDAP32_LDAP_NO_MEMORY
;
506 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld
, debugstr_w(base
),
507 scope
, debugstr_w(filter
), attrs
, attrsonly
, res
);
509 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
512 baseU
= strWtoU( base
);
513 if (!baseU
) goto exit
;
516 filterU
= strWtoU( filter
);
517 if (!filterU
) goto exit
;
520 attrsU
= strarrayWtoU( attrs
);
521 if (!attrsU
) goto exit
;
524 ret
= ldap_search_ext_s( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
525 NULL
, NULL
, NULL
, 0, res
);
530 strarrayfreeU( attrsU
);
536 /***********************************************************************
537 * ldap_search_stA (WLDAP32.@)
539 * See ldap_search_stW.
541 ULONG CDECL
ldap_search_stA( WLDAP32_LDAP
*ld
, const PCHAR base
, ULONG scope
,
542 const PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
,
543 struct l_timeval
*timeout
, WLDAP32_LDAPMessage
**res
)
545 ULONG ret
= LDAP_NOT_SUPPORTED
;
547 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
549 ret
= WLDAP32_LDAP_NO_MEMORY
;
551 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p)\n", ld
,
552 debugstr_a(base
), scope
, debugstr_a(filter
), attrs
,
553 attrsonly
, timeout
, res
);
555 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
558 baseW
= strAtoW( base
);
559 if (!baseW
) goto exit
;
562 filterW
= strAtoW( filter
);
563 if (!filterW
) goto exit
;
566 attrsW
= strarrayAtoW( attrs
);
567 if (!attrsW
) goto exit
;
570 ret
= ldap_search_stW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
,
576 strarrayfreeW( attrsW
);
582 /***********************************************************************
583 * ldap_search_stW (WLDAP32.@)
585 * Search a directory tree (synchronous operation).
588 * ld [I] Pointer to an LDAP context.
589 * base [I] Starting point for the search.
590 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
591 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
592 * filter [I] Search filter.
593 * attrs [I] Attributes to return.
594 * attrsonly [I] Return no values, only attributes.
595 * timeout [I] Timeout in seconds.
596 * res [O] Results of the search operation.
599 * Success: LDAP_SUCCESS
600 * Failure: An LDAP error code.
603 * Call ldap_msgfree to free the results.
605 ULONG CDECL
ldap_search_stW( WLDAP32_LDAP
*ld
, const PWCHAR base
, ULONG scope
,
606 const PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
,
607 struct l_timeval
*timeout
, WLDAP32_LDAPMessage
**res
)
609 ULONG ret
= LDAP_NOT_SUPPORTED
;
611 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
613 ret
= WLDAP32_LDAP_NO_MEMORY
;
615 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p)\n", ld
,
616 debugstr_w(base
), scope
, debugstr_w(filter
), attrs
,
617 attrsonly
, timeout
, res
);
619 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
622 baseU
= strWtoU( base
);
623 if (!baseU
) goto exit
;
626 filterU
= strWtoU( filter
);
627 if (!filterU
) goto exit
;
630 attrsU
= strarrayWtoU( attrs
);
631 if (!attrsU
) goto exit
;
634 ret
= ldap_search_ext_s( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
635 NULL
, NULL
, (struct timeval
*)timeout
, 0, res
);
640 strarrayfreeU( attrsU
);