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 );
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;
246 struct timeval tv, *tvp = 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 );
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;
279 tv.tv_sec = timelimit;
284 ret = map_error( ldap_search_ext( ld, baseU, scope, filterU, attrsU, attrsonly,
285 serverctrlsU, clientctrlsU, tvp, sizelimit, (int *)message ));
290 strarrayfreeU( attrsU );
291 controlarrayfreeU( serverctrlsU );
292 controlarrayfreeU( clientctrlsU );
298 /***********************************************************************
299 * ldap_search_ext_sA (WLDAP32.@)
301 * See ldap_search_ext_sW.
303 ULONG CDECL ldap_search_ext_sA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope,
304 PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
305 PLDAPControlA *clientctrls, struct l_timeval* timeout, ULONG sizelimit, WLDAP32_LDAPMessage **res )
307 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
309 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
310 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
312 ret = WLDAP32_LDAP_NO_MEMORY;
314 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n",
315 ld, debugstr_a(base), scope, debugstr_a(filter), attrs, attrsonly,
316 serverctrls, clientctrls, timeout, sizelimit, res );
318 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
321 baseW = strAtoW( base );
322 if (!baseW) goto exit;
325 filterW = strAtoW( filter );
326 if (!filterW) goto exit;
329 attrsW = strarrayAtoW( attrs );
330 if (!attrsW) goto exit;
333 serverctrlsW = controlarrayAtoW( serverctrls );
334 if (!serverctrlsW) goto exit;
337 clientctrlsW = controlarrayAtoW( clientctrls );
338 if (!clientctrlsW) goto exit;
341 ret = ldap_search_ext_sW( ld, baseW, scope, filterW, attrsW, attrsonly,
342 serverctrlsW, clientctrlsW, timeout, sizelimit, res );
347 strarrayfreeW( attrsW );
348 controlarrayfreeW( serverctrlsW );
349 controlarrayfreeW( clientctrlsW );
355 /***********************************************************************
356 * ldap_search_ext_sW (WLDAP32.@)
358 * Search a directory tree (synchronous operation).
361 * ld [I] Pointer to an LDAP context.
362 * base [I] Starting point for the search.
363 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
364 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
365 * filter [I] Search filter.
366 * attrs [I] Attributes to return.
367 * attrsonly [I] Return no values, only attributes.
368 * serverctrls [I] Array of LDAP server controls.
369 * clientctrls [I] Array of LDAP client controls.
370 * timeout [I] Timeout in seconds.
371 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
372 * res [O] Results of the search operation.
375 * Success: LDAP_SUCCESS
376 * Failure: An LDAP error code.
379 * Call ldap_msgfree to free the results.
381 ULONG CDECL ldap_search_ext_sW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope,
382 PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
383 PLDAPControlW *clientctrls, struct l_timeval* timeout, ULONG sizelimit, WLDAP32_LDAPMessage **res )
385 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
387 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
388 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
390 ret = WLDAP32_LDAP_NO_MEMORY;
392 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n",
393 ld, debugstr_w(base), scope, debugstr_w(filter), attrs, attrsonly,
394 serverctrls, clientctrls, timeout, sizelimit, res );
396 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
399 baseU = strWtoU( base );
400 if (!baseU) goto exit;
403 filterU = strWtoU( filter );
404 if (!filterU) goto exit;
407 attrsU = strarrayWtoU( attrs );
408 if (!attrsU) goto exit;
411 serverctrlsU = controlarrayWtoU( serverctrls );
412 if (!serverctrlsU) goto exit;
415 clientctrlsU = controlarrayWtoU( clientctrls );
416 if (!clientctrlsU) goto exit;
419 ret = map_error( ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
420 serverctrlsU, clientctrlsU, (struct timeval *)timeout,
426 strarrayfreeU( attrsU );
427 controlarrayfreeU( serverctrlsU );
428 controlarrayfreeU( clientctrlsU );
434 /***********************************************************************
435 * ldap_search_sA (WLDAP32.@)
437 * See ldap_search_sW.
439 ULONG CDECL ldap_search_sA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope, PCHAR filter,
440 PCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
442 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
444 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
446 ret = WLDAP32_LDAP_NO_MEMORY;
448 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p)\n", ld, debugstr_a(base),
449 scope, debugstr_a(filter), attrs, attrsonly, res );
451 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
454 baseW = strAtoW( base );
455 if (!baseW) goto exit;
458 filterW = strAtoW( filter );
459 if (!filterW) goto exit;
462 attrsW = strarrayAtoW( attrs );
463 if (!attrsW) goto exit;
466 ret = ldap_search_sW( ld, baseW, scope, filterW, attrsW, attrsonly, res );
471 strarrayfreeW( attrsW );
477 /***********************************************************************
478 * ldap_search_sW (WLDAP32.@)
480 * Search a directory tree (synchronous operation).
483 * ld [I] Pointer to an LDAP context.
484 * base [I] Starting point for the search.
485 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
486 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
487 * filter [I] Search filter.
488 * attrs [I] Attributes to return.
489 * attrsonly [I] Return no values, only attributes.
490 * res [O] Results of the search operation.
493 * Success: LDAP_SUCCESS
494 * Failure: An LDAP error code.
497 * Call ldap_msgfree to free the results.
499 ULONG CDECL ldap_search_sW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
500 PWCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
502 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
504 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
506 ret = WLDAP32_LDAP_NO_MEMORY;
508 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p)\n", ld, debugstr_w(base),
509 scope, debugstr_w(filter), attrs, attrsonly, res );
511 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
514 baseU = strWtoU( base );
515 if (!baseU) goto exit;
518 filterU = strWtoU( filter );
519 if (!filterU) goto exit;
522 attrsU = strarrayWtoU( attrs );
523 if (!attrsU) goto exit;
526 ret = map_error( ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
527 NULL, NULL, NULL, 0, res ));
532 strarrayfreeU( attrsU );
538 /***********************************************************************
539 * ldap_search_stA (WLDAP32.@)
541 * See ldap_search_stW.
543 ULONG CDECL ldap_search_stA( WLDAP32_LDAP *ld, const PCHAR base, ULONG scope,
544 const PCHAR filter, PCHAR attrs[], ULONG attrsonly,
545 struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
547 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
549 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
551 ret = WLDAP32_LDAP_NO_MEMORY;
553 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p)\n", ld,
554 debugstr_a(base), scope, debugstr_a(filter), attrs,
555 attrsonly, timeout, res );
557 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
560 baseW = strAtoW( base );
561 if (!baseW) goto exit;
564 filterW = strAtoW( filter );
565 if (!filterW) goto exit;
568 attrsW = strarrayAtoW( attrs );
569 if (!attrsW) goto exit;
572 ret = ldap_search_stW( ld, baseW, scope, filterW, attrsW, attrsonly,
578 strarrayfreeW( attrsW );
584 /***********************************************************************
585 * ldap_search_stW (WLDAP32.@)
587 * Search a directory tree (synchronous operation).
590 * ld [I] Pointer to an LDAP context.
591 * base [I] Starting point for the search.
592 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
593 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
594 * filter [I] Search filter.
595 * attrs [I] Attributes to return.
596 * attrsonly [I] Return no values, only attributes.
597 * timeout [I] Timeout in seconds.
598 * res [O] Results of the search operation.
601 * Success: LDAP_SUCCESS
602 * Failure: An LDAP error code.
605 * Call ldap_msgfree to free the results.
607 ULONG CDECL ldap_search_stW( WLDAP32_LDAP *ld, const PWCHAR base, ULONG scope,
608 const PWCHAR filter, PWCHAR attrs[], ULONG attrsonly,
609 struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
611 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
613 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
615 ret = WLDAP32_LDAP_NO_MEMORY;
617 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p)\n", ld,
618 debugstr_w(base), scope, debugstr_w(filter), attrs,
619 attrsonly, timeout, res );
621 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
624 baseU = strWtoU( base );
625 if (!baseU) goto exit;
628 filterU = strWtoU( filter );
629 if (!filterU) goto exit;
632 attrsU = strarrayWtoU( attrs );
633 if (!attrsU) goto exit;
636 ret = map_error( ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
637 NULL, NULL, (struct timeval *)timeout, 0, res ));
642 strarrayfreeU( attrsU );