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
21 #include "winldap_private.h"
23 /***********************************************************************
24 * ldap_searchA (WLDAP32.@)
28 ULONG CDECL
ldap_searchA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
, PCHAR filter
,
29 PCHAR attrs
[], ULONG attrsonly
)
31 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
33 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
35 ret
= WLDAP32_LDAP_NO_MEMORY
;
37 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld
, debugstr_a(base
),
38 scope
, debugstr_a(filter
), attrs
, attrsonly
);
43 baseW
= strAtoW( base
);
44 if (!baseW
) goto exit
;
47 filterW
= strAtoW( filter
);
48 if (!filterW
) goto exit
;
51 attrsW
= strarrayAtoW( attrs
);
52 if (!attrsW
) goto exit
;
55 ret
= ldap_searchW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
);
60 strarrayfreeW( attrsW
);
66 /***********************************************************************
67 * ldap_searchW (WLDAP32.@)
69 * Search a directory tree (asynchronous operation).
72 * ld [I] Pointer to an LDAP context.
73 * base [I] Starting point for the search.
74 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
75 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
76 * filter [I] Search filter.
77 * attrs [I] Attributes to return.
78 * attrsonly [I] Return no values, only attributes.
81 * Success: Message ID of the search operation.
85 * Call ldap_result with the message ID to get the result of
86 * the operation. Cancel the operation by calling ldap_abandon
87 * with the message ID.
89 ULONG CDECL
ldap_searchW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
, PWCHAR filter
,
90 PWCHAR attrs
[], ULONG attrsonly
)
92 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
94 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
97 ret
= WLDAP32_LDAP_NO_MEMORY
;
99 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld
, debugstr_w(base
),
100 scope
, debugstr_w(filter
), attrs
, attrsonly
);
105 baseU
= strWtoU( base
);
106 if (!baseU
) goto exit
;
109 filterU
= strWtoU( filter
);
110 if (!filterU
) goto exit
;
113 attrsU
= strarrayWtoU( attrs
);
114 if (!attrsU
) goto exit
;
117 ret
= ldap_search_ext( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
118 NULL
, NULL
, NULL
, 0, &msg
);
120 if (ret
== LDAP_SUCCESS
)
128 strarrayfreeU( attrsU
);
134 /***********************************************************************
135 * ldap_search_extA (WLDAP32.@)
137 * See ldap_search_extW.
139 ULONG CDECL
ldap_search_extA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
,
140 PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
, PLDAPControlA
*serverctrls
,
141 PLDAPControlA
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, ULONG
*message
)
143 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
145 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
146 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
148 ret
= WLDAP32_LDAP_NO_MEMORY
;
150 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, 0x%08x, 0x%08x, %p)\n",
151 ld
, debugstr_a(base
), scope
, debugstr_a(filter
), attrs
, attrsonly
,
152 serverctrls
, clientctrls
, timelimit
, sizelimit
, message
);
154 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
157 baseW
= strAtoW( base
);
158 if (!baseW
) goto exit
;
162 filterW
= strAtoW( filter
);
163 if (!filterW
) goto exit
;
166 attrsW
= strarrayAtoW( attrs
);
167 if (!attrsW
) goto exit
;
170 serverctrlsW
= controlarrayAtoW( serverctrls
);
171 if (!serverctrlsW
) goto exit
;
174 clientctrlsW
= controlarrayAtoW( clientctrls
);
175 if (!clientctrlsW
) goto exit
;
178 ret
= ldap_search_extW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
,
179 serverctrlsW
, clientctrlsW
, timelimit
, sizelimit
, message
);
184 strarrayfreeW( attrsW
);
185 controlarrayfreeW( serverctrlsW
);
186 controlarrayfreeW( clientctrlsW
);
192 /***********************************************************************
193 * ldap_search_extW (WLDAP32.@)
195 * Search a directory tree (asynchronous operation).
198 * ld [I] Pointer to an LDAP context.
199 * base [I] Starting point for the search.
200 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
201 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
202 * filter [I] Search filter.
203 * attrs [I] Attributes to return.
204 * attrsonly [I] Return no values, only attributes.
205 * serverctrls [I] Array of LDAP server controls.
206 * clientctrls [I] Array of LDAP client controls.
207 * timelimit [I] Timeout in seconds.
208 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
209 * message [O] Message ID of the search operation.
212 * Success: LDAP_SUCCESS
213 * Failure: An LDAP error code.
216 * Call ldap_result with the message ID to get the result of
217 * the operation. Cancel the operation by calling ldap_abandon
218 * with the message ID.
220 ULONG CDECL
ldap_search_extW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
,
221 PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
, PLDAPControlW
*serverctrls
,
222 PLDAPControlW
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, ULONG
*message
)
224 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
226 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
227 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
228 struct timeval tv
, *tvp
= NULL
;
230 ret
= WLDAP32_LDAP_NO_MEMORY
;
232 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, 0x%08x, 0x%08x, %p)\n",
233 ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
, attrsonly
,
234 serverctrls
, clientctrls
, timelimit
, sizelimit
, message
);
239 baseU
= strWtoU( base
);
240 if (!baseU
) goto exit
;
243 filterU
= strWtoU( filter
);
244 if (!filterU
) goto exit
;
247 attrsU
= strarrayWtoU( attrs
);
248 if (!attrsU
) goto exit
;
251 serverctrlsU
= controlarrayWtoU( serverctrls
);
252 if (!serverctrlsU
) goto exit
;
255 clientctrlsU
= controlarrayWtoU( clientctrls
);
256 if (!clientctrlsU
) goto exit
;
261 tv
.tv_sec
= timelimit
;
266 ret
= map_error( ldap_search_ext( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
267 serverctrlsU
, clientctrlsU
, tvp
, sizelimit
, (int *)message
));
272 strarrayfreeU( attrsU
);
273 controlarrayfreeU( serverctrlsU
);
274 controlarrayfreeU( clientctrlsU
);
280 /***********************************************************************
281 * ldap_search_ext_sA (WLDAP32.@)
283 * See ldap_search_ext_sW.
285 ULONG CDECL
ldap_search_ext_sA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
,
286 PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
, PLDAPControlA
*serverctrls
,
287 PLDAPControlA
*clientctrls
, struct l_timeval
* timeout
, ULONG sizelimit
, WLDAP32_LDAPMessage
**res
)
289 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
291 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
292 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
294 ret
= WLDAP32_LDAP_NO_MEMORY
;
296 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n",
297 ld
, debugstr_a(base
), scope
, debugstr_a(filter
), attrs
, attrsonly
,
298 serverctrls
, clientctrls
, timeout
, sizelimit
, res
);
300 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
303 baseW
= strAtoW( base
);
304 if (!baseW
) goto exit
;
307 filterW
= strAtoW( filter
);
308 if (!filterW
) goto exit
;
311 attrsW
= strarrayAtoW( attrs
);
312 if (!attrsW
) goto exit
;
315 serverctrlsW
= controlarrayAtoW( serverctrls
);
316 if (!serverctrlsW
) goto exit
;
319 clientctrlsW
= controlarrayAtoW( clientctrls
);
320 if (!clientctrlsW
) goto exit
;
323 ret
= ldap_search_ext_sW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
,
324 serverctrlsW
, clientctrlsW
, timeout
, sizelimit
, res
);
329 strarrayfreeW( attrsW
);
330 controlarrayfreeW( serverctrlsW
);
331 controlarrayfreeW( clientctrlsW
);
337 /***********************************************************************
338 * ldap_search_ext_sW (WLDAP32.@)
340 * Search a directory tree (synchronous operation).
343 * ld [I] Pointer to an LDAP context.
344 * base [I] Starting point for the search.
345 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
346 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
347 * filter [I] Search filter.
348 * attrs [I] Attributes to return.
349 * attrsonly [I] Return no values, only attributes.
350 * serverctrls [I] Array of LDAP server controls.
351 * clientctrls [I] Array of LDAP client controls.
352 * timeout [I] Timeout in seconds.
353 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
354 * res [O] Results of the search operation.
357 * Success: LDAP_SUCCESS
358 * Failure: An LDAP error code.
361 * Call ldap_msgfree to free the results.
363 ULONG CDECL
ldap_search_ext_sW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
,
364 PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
, PLDAPControlW
*serverctrls
,
365 PLDAPControlW
*clientctrls
, struct l_timeval
* timeout
, ULONG sizelimit
, WLDAP32_LDAPMessage
**res
)
367 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
369 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
370 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
372 ret
= WLDAP32_LDAP_NO_MEMORY
;
374 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n",
375 ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
, attrsonly
,
376 serverctrls
, clientctrls
, timeout
, sizelimit
, res
);
378 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
381 baseU
= strWtoU( base
);
382 if (!baseU
) goto exit
;
385 filterU
= strWtoU( filter
);
386 if (!filterU
) goto exit
;
389 attrsU
= strarrayWtoU( attrs
);
390 if (!attrsU
) goto exit
;
393 serverctrlsU
= controlarrayWtoU( serverctrls
);
394 if (!serverctrlsU
) goto exit
;
397 clientctrlsU
= controlarrayWtoU( clientctrls
);
398 if (!clientctrlsU
) goto exit
;
401 ret
= map_error( ldap_search_ext_s( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
402 serverctrlsU
, clientctrlsU
, (struct timeval
*)timeout
,
408 strarrayfreeU( attrsU
);
409 controlarrayfreeU( serverctrlsU
);
410 controlarrayfreeU( clientctrlsU
);
416 /***********************************************************************
417 * ldap_search_sA (WLDAP32.@)
419 * See ldap_search_sW.
421 ULONG CDECL
ldap_search_sA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
, PCHAR filter
,
422 PCHAR attrs
[], ULONG attrsonly
, WLDAP32_LDAPMessage
**res
)
424 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
426 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
428 ret
= WLDAP32_LDAP_NO_MEMORY
;
430 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p)\n", ld
, debugstr_a(base
),
431 scope
, debugstr_a(filter
), attrs
, attrsonly
, res
);
433 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
436 baseW
= strAtoW( base
);
437 if (!baseW
) goto exit
;
440 filterW
= strAtoW( filter
);
441 if (!filterW
) goto exit
;
444 attrsW
= strarrayAtoW( attrs
);
445 if (!attrsW
) goto exit
;
448 ret
= ldap_search_sW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
, res
);
453 strarrayfreeW( attrsW
);
459 /***********************************************************************
460 * ldap_search_sW (WLDAP32.@)
462 * Search a directory tree (synchronous operation).
465 * ld [I] Pointer to an LDAP context.
466 * base [I] Starting point for the search.
467 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
468 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
469 * filter [I] Search filter.
470 * attrs [I] Attributes to return.
471 * attrsonly [I] Return no values, only attributes.
472 * res [O] Results of the search operation.
475 * Success: LDAP_SUCCESS
476 * Failure: An LDAP error code.
479 * Call ldap_msgfree to free the results.
481 ULONG CDECL
ldap_search_sW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
, PWCHAR filter
,
482 PWCHAR attrs
[], ULONG attrsonly
, WLDAP32_LDAPMessage
**res
)
484 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
486 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
488 ret
= WLDAP32_LDAP_NO_MEMORY
;
490 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p)\n", ld
, debugstr_w(base
),
491 scope
, debugstr_w(filter
), attrs
, attrsonly
, res
);
493 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
496 baseU
= strWtoU( base
);
497 if (!baseU
) goto exit
;
500 filterU
= strWtoU( filter
);
501 if (!filterU
) goto exit
;
504 attrsU
= strarrayWtoU( attrs
);
505 if (!attrsU
) goto exit
;
508 ret
= map_error( ldap_search_ext_s( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
509 NULL
, NULL
, NULL
, 0, res
));
514 strarrayfreeU( attrsU
);
520 /***********************************************************************
521 * ldap_search_stA (WLDAP32.@)
523 * See ldap_search_stW.
525 ULONG CDECL
ldap_search_stA( WLDAP32_LDAP
*ld
, const PCHAR base
, ULONG scope
,
526 const PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
,
527 struct l_timeval
*timeout
, WLDAP32_LDAPMessage
**res
)
529 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
531 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
533 ret
= WLDAP32_LDAP_NO_MEMORY
;
535 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p)\n", ld
,
536 debugstr_a(base
), scope
, debugstr_a(filter
), attrs
,
537 attrsonly
, timeout
, res
);
539 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
542 baseW
= strAtoW( base
);
543 if (!baseW
) goto exit
;
546 filterW
= strAtoW( filter
);
547 if (!filterW
) goto exit
;
550 attrsW
= strarrayAtoW( attrs
);
551 if (!attrsW
) goto exit
;
554 ret
= ldap_search_stW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
,
560 strarrayfreeW( attrsW
);
566 /***********************************************************************
567 * ldap_search_stW (WLDAP32.@)
569 * Search a directory tree (synchronous operation).
572 * ld [I] Pointer to an LDAP context.
573 * base [I] Starting point for the search.
574 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
575 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
576 * filter [I] Search filter.
577 * attrs [I] Attributes to return.
578 * attrsonly [I] Return no values, only attributes.
579 * timeout [I] Timeout in seconds.
580 * res [O] Results of the search operation.
583 * Success: LDAP_SUCCESS
584 * Failure: An LDAP error code.
587 * Call ldap_msgfree to free the results.
589 ULONG CDECL
ldap_search_stW( WLDAP32_LDAP
*ld
, const PWCHAR base
, ULONG scope
,
590 const PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
,
591 struct l_timeval
*timeout
, WLDAP32_LDAPMessage
**res
)
593 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
595 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
597 ret
= WLDAP32_LDAP_NO_MEMORY
;
599 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p)\n", ld
,
600 debugstr_w(base
), scope
, debugstr_w(filter
), attrs
,
601 attrsonly
, timeout
, res
);
603 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
606 baseU
= strWtoU( base
);
607 if (!baseU
) goto exit
;
610 filterU
= strWtoU( filter
);
611 if (!filterU
) goto exit
;
614 attrsU
= strarrayWtoU( attrs
);
615 if (!attrsU
) goto exit
;
618 ret
= map_error( ldap_search_ext_s( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
619 NULL
, NULL
, (struct timeval
*)timeout
, 0, res
));
624 strarrayfreeU( attrsU
);