wer: Add new stubbed wer.dll.
[wine/hramrach.git] / dlls / wldap32 / search.c
blob6b0f4dec81b8e6cb5bd85eaac36dfa712b03529d
1 /*
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 "config.h"
23 #include "wine/port.h"
24 #include "wine/debug.h"
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #endif
36 #include "winldap_private.h"
37 #include "wldap32.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
41 /***********************************************************************
42 * ldap_searchA (WLDAP32.@)
44 * See ldap_searchW.
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;
50 #ifdef HAVE_LDAP
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 );
58 if (!ld) return ~0u;
60 if (base) {
61 baseW = strAtoW( base );
62 if (!baseW) goto exit;
64 if (filter) {
65 filterW = strAtoW( filter );
66 if (!filterW) goto exit;
68 if (attrs) {
69 attrsW = strarrayAtoW( attrs );
70 if (!attrsW) goto exit;
73 ret = ldap_searchW( ld, baseW, scope, filterW, attrsW, attrsonly );
75 exit:
76 strfreeW( baseW );
77 strfreeW( filterW );
78 strarrayfreeW( attrsW );
80 #endif
81 return ret;
84 /***********************************************************************
85 * ldap_searchW (WLDAP32.@)
87 * Search a directory tree (asynchronous operation).
89 * PARAMS
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.
98 * RETURNS
99 * Success: Message ID of the search operation.
100 * Failure: ~0u
102 * NOTES
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;
111 #ifdef HAVE_LDAP
112 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
113 int msg;
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 ~0u;
122 if (base) {
123 baseU = strWtoU( base );
124 if (!baseU) goto exit;
126 if (filter) {
127 filterU = strWtoU( filter );
128 if (!filterU) goto exit;
130 if (attrs) {
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)
139 ret = msg;
140 else
141 ret = ~0u;
143 exit:
144 strfreeU( baseU );
145 strfreeU( filterU );
146 strarrayfreeU( attrsU );
148 #endif
149 return ret;
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;
162 #ifdef HAVE_LDAP
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;
174 if (base) {
175 baseW = strAtoW( base );
176 if (!baseW) goto exit;
178 if (filter)
180 filterW = strAtoW( filter );
181 if (!filterW) goto exit;
183 if (attrs) {
184 attrsW = strarrayAtoW( attrs );
185 if (!attrsW) goto exit;
187 if (serverctrls) {
188 serverctrlsW = controlarrayAtoW( serverctrls );
189 if (!serverctrlsW) goto exit;
191 if (clientctrls) {
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 );
199 exit:
200 strfreeW( baseW );
201 strfreeW( filterW );
202 strarrayfreeW( attrsW );
203 controlarrayfreeW( serverctrlsW );
204 controlarrayfreeW( clientctrlsW );
206 #endif
207 return ret;
210 /***********************************************************************
211 * ldap_search_extW (WLDAP32.@)
213 * Search a directory tree (asynchronous operation).
215 * PARAMS
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.
229 * RETURNS
230 * Success: LDAP_SUCCESS
231 * Failure: An LDAP error code.
233 * NOTES
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;
243 #ifdef HAVE_LDAP
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 );
254 if (!ld) return ~0u;
256 if (base) {
257 baseU = strWtoU( base );
258 if (!baseU) goto exit;
260 if (filter) {
261 filterU = strWtoU( filter );
262 if (!filterU) goto exit;
264 if (attrs) {
265 attrsU = strarrayWtoU( attrs );
266 if (!attrsU) goto exit;
268 if (serverctrls) {
269 serverctrlsU = controlarrayWtoU( serverctrls );
270 if (!serverctrlsU) goto exit;
272 if (clientctrls) {
273 clientctrlsU = controlarrayWtoU( clientctrls );
274 if (!clientctrlsU) goto exit;
277 if (timelimit)
279 tv.tv_sec = timelimit;
280 tv.tv_usec = 0;
281 tvp = &tv;
284 ret = map_error( ldap_search_ext( ld, baseU, scope, filterU, attrsU, attrsonly,
285 serverctrlsU, clientctrlsU, tvp, sizelimit, (int *)message ));
287 exit:
288 strfreeU( baseU );
289 strfreeU( filterU );
290 strarrayfreeU( attrsU );
291 controlarrayfreeU( serverctrlsU );
292 controlarrayfreeU( clientctrlsU );
294 #endif
295 return ret;
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;
308 #ifdef HAVE_LDAP
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;
320 if (base) {
321 baseW = strAtoW( base );
322 if (!baseW) goto exit;
324 if (filter) {
325 filterW = strAtoW( filter );
326 if (!filterW) goto exit;
328 if (attrs) {
329 attrsW = strarrayAtoW( attrs );
330 if (!attrsW) goto exit;
332 if (serverctrls) {
333 serverctrlsW = controlarrayAtoW( serverctrls );
334 if (!serverctrlsW) goto exit;
336 if (clientctrls) {
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 );
344 exit:
345 strfreeW( baseW );
346 strfreeW( filterW );
347 strarrayfreeW( attrsW );
348 controlarrayfreeW( serverctrlsW );
349 controlarrayfreeW( clientctrlsW );
351 #endif
352 return ret;
355 /***********************************************************************
356 * ldap_search_ext_sW (WLDAP32.@)
358 * Search a directory tree (synchronous operation).
360 * PARAMS
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.
374 * RETURNS
375 * Success: LDAP_SUCCESS
376 * Failure: An LDAP error code.
378 * NOTES
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;
386 #ifdef HAVE_LDAP
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;
398 if (base) {
399 baseU = strWtoU( base );
400 if (!baseU) goto exit;
402 if (filter) {
403 filterU = strWtoU( filter );
404 if (!filterU) goto exit;
406 if (attrs) {
407 attrsU = strarrayWtoU( attrs );
408 if (!attrsU) goto exit;
410 if (serverctrls) {
411 serverctrlsU = controlarrayWtoU( serverctrls );
412 if (!serverctrlsU) goto exit;
414 if (clientctrls) {
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,
421 sizelimit, res ));
423 exit:
424 strfreeU( baseU );
425 strfreeU( filterU );
426 strarrayfreeU( attrsU );
427 controlarrayfreeU( serverctrlsU );
428 controlarrayfreeU( clientctrlsU );
430 #endif
431 return ret;
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;
443 #ifdef HAVE_LDAP
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;
453 if (base) {
454 baseW = strAtoW( base );
455 if (!baseW) goto exit;
457 if (filter) {
458 filterW = strAtoW( filter );
459 if (!filterW) goto exit;
461 if (attrs) {
462 attrsW = strarrayAtoW( attrs );
463 if (!attrsW) goto exit;
466 ret = ldap_search_sW( ld, baseW, scope, filterW, attrsW, attrsonly, res );
468 exit:
469 strfreeW( baseW );
470 strfreeW( filterW );
471 strarrayfreeW( attrsW );
473 #endif
474 return ret;
477 /***********************************************************************
478 * ldap_search_sW (WLDAP32.@)
480 * Search a directory tree (synchronous operation).
482 * PARAMS
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.
492 * RETURNS
493 * Success: LDAP_SUCCESS
494 * Failure: An LDAP error code.
496 * NOTES
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;
503 #ifdef HAVE_LDAP
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;
513 if (base) {
514 baseU = strWtoU( base );
515 if (!baseU) goto exit;
517 if (filter) {
518 filterU = strWtoU( filter );
519 if (!filterU) goto exit;
521 if (attrs) {
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 ));
529 exit:
530 strfreeU( baseU );
531 strfreeU( filterU );
532 strarrayfreeU( attrsU );
534 #endif
535 return ret;
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;
548 #ifdef HAVE_LDAP
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;
559 if (base) {
560 baseW = strAtoW( base );
561 if (!baseW) goto exit;
563 if (filter) {
564 filterW = strAtoW( filter );
565 if (!filterW) goto exit;
567 if (attrs) {
568 attrsW = strarrayAtoW( attrs );
569 if (!attrsW) goto exit;
572 ret = ldap_search_stW( ld, baseW, scope, filterW, attrsW, attrsonly,
573 timeout, res );
575 exit:
576 strfreeW( baseW );
577 strfreeW( filterW );
578 strarrayfreeW( attrsW );
580 #endif
581 return ret;
584 /***********************************************************************
585 * ldap_search_stW (WLDAP32.@)
587 * Search a directory tree (synchronous operation).
589 * PARAMS
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.
600 * RETURNS
601 * Success: LDAP_SUCCESS
602 * Failure: An LDAP error code.
604 * NOTES
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;
612 #ifdef HAVE_LDAP
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;
623 if (base) {
624 baseU = strWtoU( base );
625 if (!baseU) goto exit;
627 if (filter) {
628 filterU = strWtoU( filter );
629 if (!filterU) goto exit;
631 if (attrs) {
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 ));
639 exit:
640 strfreeU( baseU );
641 strfreeU( filterU );
642 strarrayfreeU( attrsU );
644 #endif
645 return ret;