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_searchA (WLDAP32.@)
44 ULONG CDECL
ldap_searchA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
, PCHAR filter
,
45 PCHAR attrs
[], ULONG attrsonly
)
47 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
49 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
51 ret
= WLDAP32_LDAP_NO_MEMORY
;
53 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld
, debugstr_a(base
),
54 scope
, debugstr_a(filter
), attrs
, attrsonly
);
59 baseW
= strAtoW( base
);
60 if (!baseW
) goto exit
;
63 filterW
= strAtoW( filter
);
64 if (!filterW
) goto exit
;
67 attrsW
= strarrayAtoW( attrs
);
68 if (!attrsW
) goto exit
;
71 ret
= ldap_searchW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
);
76 strarrayfreeW( attrsW
);
82 /***********************************************************************
83 * ldap_searchW (WLDAP32.@)
85 * Search a directory tree (asynchronous operation).
88 * ld [I] Pointer to an LDAP context.
89 * base [I] Starting point for the search.
90 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
91 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
92 * filter [I] Search filter.
93 * attrs [I] Attributes to return.
94 * attrsonly [I] Return no values, only attributes.
97 * Success: Message ID of the search operation.
101 * Call ldap_result with the message ID to get the result of
102 * the operation. Cancel the operation by calling ldap_abandon
103 * with the message ID.
105 ULONG CDECL
ldap_searchW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
, PWCHAR filter
,
106 PWCHAR attrs
[], ULONG attrsonly
)
108 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
110 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
113 ret
= WLDAP32_LDAP_NO_MEMORY
;
115 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld
, debugstr_w(base
),
116 scope
, debugstr_w(filter
), attrs
, attrsonly
);
121 baseU
= strWtoU( base
);
122 if (!baseU
) goto exit
;
125 filterU
= strWtoU( filter
);
126 if (!filterU
) goto exit
;
129 attrsU
= strarrayWtoU( attrs
);
130 if (!attrsU
) goto exit
;
133 ret
= ldap_search_ext( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
134 NULL
, NULL
, NULL
, 0, &msg
);
136 if (ret
== LDAP_SUCCESS
)
144 strarrayfreeU( attrsU
);
150 /***********************************************************************
151 * ldap_search_extA (WLDAP32.@)
153 * See ldap_search_extW.
155 ULONG CDECL
ldap_search_extA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
,
156 PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
, PLDAPControlA
*serverctrls
,
157 PLDAPControlA
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, ULONG
*message
)
159 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
161 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
162 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
164 ret
= WLDAP32_LDAP_NO_MEMORY
;
166 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, 0x%08x, 0x%08x, %p)\n",
167 ld
, debugstr_a(base
), scope
, debugstr_a(filter
), attrs
, attrsonly
,
168 serverctrls
, clientctrls
, timelimit
, sizelimit
, message
);
170 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
173 baseW
= strAtoW( base
);
174 if (!baseW
) goto exit
;
178 filterW
= strAtoW( filter
);
179 if (!filterW
) goto exit
;
182 attrsW
= strarrayAtoW( attrs
);
183 if (!attrsW
) goto exit
;
186 serverctrlsW
= controlarrayAtoW( serverctrls
);
187 if (!serverctrlsW
) goto exit
;
190 clientctrlsW
= controlarrayAtoW( clientctrls
);
191 if (!clientctrlsW
) goto exit
;
194 ret
= ldap_search_extW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
,
195 serverctrlsW
, clientctrlsW
, timelimit
, sizelimit
, message
);
200 strarrayfreeW( attrsW
);
201 controlarrayfreeW( serverctrlsW
);
202 controlarrayfreeW( clientctrlsW
);
208 /***********************************************************************
209 * ldap_search_extW (WLDAP32.@)
211 * Search a directory tree (asynchronous operation).
214 * ld [I] Pointer to an LDAP context.
215 * base [I] Starting point for the search.
216 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
217 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
218 * filter [I] Search filter.
219 * attrs [I] Attributes to return.
220 * attrsonly [I] Return no values, only attributes.
221 * serverctrls [I] Array of LDAP server controls.
222 * clientctrls [I] Array of LDAP client controls.
223 * timelimit [I] Timeout in seconds.
224 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
225 * message [O] Message ID of the search operation.
228 * Success: LDAP_SUCCESS
229 * Failure: An LDAP error code.
232 * Call ldap_result with the message ID to get the result of
233 * the operation. Cancel the operation by calling ldap_abandon
234 * with the message ID.
236 ULONG CDECL
ldap_search_extW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
,
237 PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
, PLDAPControlW
*serverctrls
,
238 PLDAPControlW
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, ULONG
*message
)
240 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
242 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
243 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
244 struct timeval tv
, *tvp
= NULL
;
246 ret
= WLDAP32_LDAP_NO_MEMORY
;
248 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, 0x%08x, 0x%08x, %p)\n",
249 ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
, attrsonly
,
250 serverctrls
, clientctrls
, timelimit
, sizelimit
, message
);
255 baseU
= strWtoU( base
);
256 if (!baseU
) goto exit
;
259 filterU
= strWtoU( filter
);
260 if (!filterU
) goto exit
;
263 attrsU
= strarrayWtoU( attrs
);
264 if (!attrsU
) goto exit
;
267 serverctrlsU
= controlarrayWtoU( serverctrls
);
268 if (!serverctrlsU
) goto exit
;
271 clientctrlsU
= controlarrayWtoU( clientctrls
);
272 if (!clientctrlsU
) goto exit
;
277 tv
.tv_sec
= timelimit
;
282 ret
= map_error( ldap_search_ext( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
283 serverctrlsU
, clientctrlsU
, tvp
, sizelimit
, (int *)message
));
288 strarrayfreeU( attrsU
);
289 controlarrayfreeU( serverctrlsU
);
290 controlarrayfreeU( clientctrlsU
);
296 /***********************************************************************
297 * ldap_search_ext_sA (WLDAP32.@)
299 * See ldap_search_ext_sW.
301 ULONG CDECL
ldap_search_ext_sA( WLDAP32_LDAP
*ld
, PCHAR base
, ULONG scope
,
302 PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
, PLDAPControlA
*serverctrls
,
303 PLDAPControlA
*clientctrls
, struct l_timeval
* timeout
, ULONG sizelimit
, WLDAP32_LDAPMessage
**res
)
305 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
307 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
308 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
310 ret
= WLDAP32_LDAP_NO_MEMORY
;
312 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n",
313 ld
, debugstr_a(base
), scope
, debugstr_a(filter
), attrs
, attrsonly
,
314 serverctrls
, clientctrls
, timeout
, sizelimit
, res
);
316 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
319 baseW
= strAtoW( base
);
320 if (!baseW
) goto exit
;
323 filterW
= strAtoW( filter
);
324 if (!filterW
) goto exit
;
327 attrsW
= strarrayAtoW( attrs
);
328 if (!attrsW
) goto exit
;
331 serverctrlsW
= controlarrayAtoW( serverctrls
);
332 if (!serverctrlsW
) goto exit
;
335 clientctrlsW
= controlarrayAtoW( clientctrls
);
336 if (!clientctrlsW
) goto exit
;
339 ret
= ldap_search_ext_sW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
,
340 serverctrlsW
, clientctrlsW
, timeout
, sizelimit
, res
);
345 strarrayfreeW( attrsW
);
346 controlarrayfreeW( serverctrlsW
);
347 controlarrayfreeW( clientctrlsW
);
353 /***********************************************************************
354 * ldap_search_ext_sW (WLDAP32.@)
356 * Search a directory tree (synchronous operation).
359 * ld [I] Pointer to an LDAP context.
360 * base [I] Starting point for the search.
361 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
362 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
363 * filter [I] Search filter.
364 * attrs [I] Attributes to return.
365 * attrsonly [I] Return no values, only attributes.
366 * serverctrls [I] Array of LDAP server controls.
367 * clientctrls [I] Array of LDAP client controls.
368 * timeout [I] Timeout in seconds.
369 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
370 * res [O] Results of the search operation.
373 * Success: LDAP_SUCCESS
374 * Failure: An LDAP error code.
377 * Call ldap_msgfree to free the results.
379 ULONG CDECL
ldap_search_ext_sW( WLDAP32_LDAP
*ld
, PWCHAR base
, ULONG scope
,
380 PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
, PLDAPControlW
*serverctrls
,
381 PLDAPControlW
*clientctrls
, struct l_timeval
* timeout
, ULONG sizelimit
, WLDAP32_LDAPMessage
**res
)
383 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
385 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
386 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
388 ret
= WLDAP32_LDAP_NO_MEMORY
;
390 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n",
391 ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
, attrsonly
,
392 serverctrls
, clientctrls
, timeout
, sizelimit
, res
);
394 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
397 baseU
= strWtoU( base
);
398 if (!baseU
) goto exit
;
401 filterU
= strWtoU( filter
);
402 if (!filterU
) goto exit
;
405 attrsU
= strarrayWtoU( attrs
);
406 if (!attrsU
) goto exit
;
409 serverctrlsU
= controlarrayWtoU( serverctrls
);
410 if (!serverctrlsU
) goto exit
;
413 clientctrlsU
= controlarrayWtoU( clientctrls
);
414 if (!clientctrlsU
) goto exit
;
417 ret
= map_error( ldap_search_ext_s( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
418 serverctrlsU
, clientctrlsU
, (struct timeval
*)timeout
,
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
= WLDAP32_LDAP_NOT_SUPPORTED
;
442 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
444 ret
= WLDAP32_LDAP_NO_MEMORY
;
446 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %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
= WLDAP32_LDAP_NOT_SUPPORTED
;
502 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
504 ret
= WLDAP32_LDAP_NO_MEMORY
;
506 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %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
= map_error( 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
= WLDAP32_LDAP_NOT_SUPPORTED
;
547 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
549 ret
= WLDAP32_LDAP_NO_MEMORY
;
551 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %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
= WLDAP32_LDAP_NOT_SUPPORTED
;
611 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
613 ret
= WLDAP32_LDAP_NO_MEMORY
;
615 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %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
= map_error( ldap_search_ext_s( ld
, baseU
, scope
, filterU
, attrsU
, attrsonly
,
635 NULL
, NULL
, (struct timeval
*)timeout
, 0, res
));
640 strarrayfreeU( attrsU
);