Release 20050930.
[wine/gsoc-2012-control.git] / dlls / wldap32 / search.c
blobd5ee3605b75b54793ec3179e7d6bc68fa557d521
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 #else
35 #define LDAP_SUCCESS 0x00
36 #define LDAP_NOT_SUPPORTED 0x5c
37 #endif
39 #include "winldap_private.h"
40 #include "wldap32.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
44 ULONG ldap_searchA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope, PCHAR filter,
45 PCHAR attrs[], ULONG attrsonly )
47 ULONG ret = LDAP_NOT_SUPPORTED;
48 #ifdef HAVE_LDAP
49 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
51 ret = WLDAP32_LDAP_NO_MEMORY;
53 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_a(base),
54 scope, debugstr_a(filter), attrs, attrsonly );
56 if (!ld) return ~0UL;
58 if (base) {
59 baseW = strAtoW( base );
60 if (!baseW) goto exit;
62 if (filter) {
63 filterW = strAtoW( filter );
64 if (!filterW) goto exit;
66 if (attrs) {
67 attrsW = strarrayAtoW( attrs );
68 if (!attrsW) goto exit;
71 ret = ldap_searchW( ld, baseW, scope, filterW, attrsW, attrsonly );
73 exit:
74 strfreeW( baseW );
75 strfreeW( filterW );
76 strarrayfreeW( attrsW );
78 #endif
79 return ret;
82 ULONG ldap_searchW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
83 PWCHAR attrs[], ULONG attrsonly )
85 ULONG ret = LDAP_NOT_SUPPORTED;
86 #ifdef HAVE_LDAP
87 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
89 ret = WLDAP32_LDAP_NO_MEMORY;
91 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_w(base),
92 scope, debugstr_w(filter), attrs, attrsonly );
94 if (!ld) return ~0UL;
96 if (base) {
97 baseU = strWtoU( base );
98 if (!baseU) goto exit;
100 if (filter) {
101 filterU = strWtoU( filter );
102 if (!filterU) goto exit;
104 if (attrs) {
105 attrsU = strarrayWtoU( attrs );
106 if (!attrsU) goto exit;
109 ret = ldap_search( ld, baseU, scope, filterU, attrsU, attrsonly );
111 exit:
112 strfreeU( baseU );
113 strfreeU( filterU );
114 strarrayfreeU( attrsU );
116 #endif
117 return ret;
120 ULONG ldap_search_extA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope,
121 PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
122 PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, ULONG *message )
124 ULONG ret = LDAP_NOT_SUPPORTED;
125 #ifdef HAVE_LDAP
126 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
127 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
129 ret = WLDAP32_LDAP_NO_MEMORY;
131 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, 0x%08lx, 0x%08lx, %p)\n",
132 ld, debugstr_a(base), scope, debugstr_a(filter), attrs, attrsonly,
133 serverctrls, clientctrls, timelimit, sizelimit, message );
135 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
137 if (base) {
138 baseW = strAtoW( base );
139 if (!baseW) goto exit;
141 if (filter)
143 filterW = strAtoW( filter );
144 if (!filterW) goto exit;
146 if (attrs) {
147 attrsW = strarrayAtoW( attrs );
148 if (!attrsW) goto exit;
150 if (serverctrls) {
151 serverctrlsW = controlarrayAtoW( serverctrls );
152 if (!serverctrlsW) goto exit;
154 if (clientctrls) {
155 clientctrlsW = controlarrayAtoW( clientctrls );
156 if (!clientctrlsW) goto exit;
159 ret = ldap_search_extW( ld, baseW, scope, filterW, attrsW, attrsonly,
160 serverctrlsW, clientctrlsW, timelimit, sizelimit, message );
162 exit:
163 strfreeW( baseW );
164 strfreeW( filterW );
165 strarrayfreeW( attrsW );
166 controlarrayfreeW( serverctrlsW );
167 controlarrayfreeW( clientctrlsW );
169 #endif
170 return ret;
173 ULONG ldap_search_extW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope,
174 PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
175 PLDAPControlW *clientctrls, ULONG timelimit, ULONG sizelimit, ULONG *message )
177 ULONG ret = LDAP_NOT_SUPPORTED;
178 #ifdef HAVE_LDAP
179 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
180 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
181 struct timeval tv;
183 ret = WLDAP32_LDAP_NO_MEMORY;
185 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, 0x%08lx, 0x%08lx, %p)\n",
186 ld, debugstr_w(base), scope, debugstr_w(filter), attrs, attrsonly,
187 serverctrls, clientctrls, timelimit, sizelimit, message );
189 if (!ld) return ~0UL;
191 if (base) {
192 baseU = strWtoU( base );
193 if (!baseU) goto exit;
195 if (filter) {
196 filterU = strWtoU( filter );
197 if (!filterU) goto exit;
199 if (attrs) {
200 attrsU = strarrayWtoU( attrs );
201 if (!attrsU) goto exit;
203 if (serverctrls) {
204 serverctrlsU = controlarrayWtoU( serverctrls );
205 if (!serverctrlsU) goto exit;
207 if (clientctrls) {
208 clientctrlsU = controlarrayWtoU( clientctrls );
209 if (!clientctrlsU) goto exit;
212 tv.tv_sec = timelimit;
213 tv.tv_usec = 0;
215 ret = ldap_search_ext( ld, baseU, scope, filterU, attrsU, attrsonly,
216 serverctrlsU, clientctrlsU, &tv, sizelimit, (int *)message );
218 exit:
219 strfreeU( baseU );
220 strfreeU( filterU );
221 strarrayfreeU( attrsU );
222 controlarrayfreeU( serverctrlsU );
223 controlarrayfreeU( clientctrlsU );
225 #endif
226 return ret;
229 ULONG ldap_search_ext_sA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope,
230 PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
231 PLDAPControlA *clientctrls, struct l_timeval* timeout, ULONG sizelimit, WLDAP32_LDAPMessage **res )
233 ULONG ret = LDAP_NOT_SUPPORTED;
234 #ifdef HAVE_LDAP
235 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
236 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
238 ret = WLDAP32_LDAP_NO_MEMORY;
240 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, %p, 0x%08lx, %p)\n",
241 ld, debugstr_a(base), scope, debugstr_a(filter), attrs, attrsonly,
242 serverctrls, clientctrls, timeout, sizelimit, res );
244 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
246 if (base) {
247 baseW = strAtoW( base );
248 if (!baseW) goto exit;
250 if (filter) {
251 filterW = strAtoW( filter );
252 if (!filterW) goto exit;
254 if (attrs) {
255 attrsW = strarrayAtoW( attrs );
256 if (!attrsW) goto exit;
258 if (serverctrls) {
259 serverctrlsW = controlarrayAtoW( serverctrls );
260 if (!serverctrlsW) goto exit;
262 if (clientctrls) {
263 clientctrlsW = controlarrayAtoW( clientctrls );
264 if (!clientctrlsW) goto exit;
267 ret = ldap_search_ext_sW( ld, baseW, scope, filterW, attrsW, attrsonly,
268 serverctrlsW, clientctrlsW, timeout, sizelimit, res );
270 exit:
271 strfreeW( baseW );
272 strfreeW( filterW );
273 strarrayfreeW( attrsW );
274 controlarrayfreeW( serverctrlsW );
275 controlarrayfreeW( clientctrlsW );
277 #endif
278 return ret;
281 ULONG ldap_search_ext_sW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope,
282 PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
283 PLDAPControlW *clientctrls, struct l_timeval* timeout, ULONG sizelimit, WLDAP32_LDAPMessage **res )
285 ULONG ret = LDAP_NOT_SUPPORTED;
286 #ifdef HAVE_LDAP
287 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
288 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
290 ret = WLDAP32_LDAP_NO_MEMORY;
292 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, %p, 0x%08lx, %p)\n",
293 ld, debugstr_w(base), scope, debugstr_w(filter), attrs, attrsonly,
294 serverctrls, clientctrls, timeout, sizelimit, res );
296 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
298 if (base) {
299 baseU = strWtoU( base );
300 if (!baseU) goto exit;
302 if (filter) {
303 filterU = strWtoU( filter );
304 if (!filterU) goto exit;
306 if (attrs) {
307 attrsU = strarrayWtoU( attrs );
308 if (!attrsU) goto exit;
310 if (serverctrls) {
311 serverctrlsU = controlarrayWtoU( serverctrls );
312 if (!serverctrlsU) goto exit;
314 if (clientctrls) {
315 clientctrlsU = controlarrayWtoU( clientctrls );
316 if (!clientctrlsU) goto exit;
319 ret = ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
320 serverctrlsU, clientctrlsU, (struct timeval *)timeout, sizelimit, res );
322 exit:
323 strfreeU( baseU );
324 strfreeU( filterU );
325 strarrayfreeU( attrsU );
326 controlarrayfreeU( serverctrlsU );
327 controlarrayfreeU( clientctrlsU );
329 #endif
330 return ret;
333 ULONG ldap_search_sA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope, PCHAR filter,
334 PCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
336 ULONG ret = LDAP_NOT_SUPPORTED;
337 #ifdef HAVE_LDAP
338 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
340 ret = WLDAP32_LDAP_NO_MEMORY;
342 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld, debugstr_a(base),
343 scope, debugstr_a(filter), attrs, attrsonly, res );
345 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
347 if (base) {
348 baseW = strAtoW( base );
349 if (!baseW) goto exit;
351 if (filter) {
352 filterW = strAtoW( filter );
353 if (!filterW) goto exit;
355 if (attrs) {
356 attrsW = strarrayAtoW( attrs );
357 if (!attrsW) goto exit;
360 ret = ldap_search_sW( ld, baseW, scope, filterW, attrsW, attrsonly, res );
362 exit:
363 strfreeW( baseW );
364 strfreeW( filterW );
365 strarrayfreeW( attrsW );
367 #endif
368 return ret;
371 ULONG ldap_search_sW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
372 PWCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
374 ULONG ret = LDAP_NOT_SUPPORTED;
375 #ifdef HAVE_LDAP
376 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
378 ret = WLDAP32_LDAP_NO_MEMORY;
380 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld, debugstr_w(base),
381 scope, debugstr_w(filter), attrs, attrsonly, res );
383 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
385 if (base) {
386 baseU = strWtoU( base );
387 if (!baseU) goto exit;
389 if (filter) {
390 filterU = strWtoU( filter );
391 if (!filterU) goto exit;
393 if (attrs) {
394 attrsU = strarrayWtoU( attrs );
395 if (!attrsU) goto exit;
398 ret = ldap_search_s( ld, baseU, scope, filterU, attrsU, attrsonly, res );
400 exit:
401 strfreeU( baseU );
402 strfreeU( filterU );
403 strarrayfreeU( attrsU );
405 #endif
406 return ret;
409 ULONG ldap_search_stA( WLDAP32_LDAP *ld, const PCHAR base, ULONG scope,
410 const PCHAR filter, PCHAR attrs[], ULONG attrsonly,
411 struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
413 ULONG ret = LDAP_NOT_SUPPORTED;
414 #ifdef HAVE_LDAP
415 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
417 ret = WLDAP32_LDAP_NO_MEMORY;
419 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p)\n", ld,
420 debugstr_a(base), scope, debugstr_a(filter), attrs,
421 attrsonly, timeout, res );
423 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
425 if (base) {
426 baseW = strAtoW( base );
427 if (!baseW) goto exit;
429 if (filter) {
430 filterW = strAtoW( filter );
431 if (!filterW) goto exit;
433 if (attrs) {
434 attrsW = strarrayAtoW( attrs );
435 if (!attrsW) goto exit;
438 ret = ldap_search_stW( ld, baseW, scope, filterW, attrsW, attrsonly,
439 timeout, res );
441 exit:
442 strfreeW( baseW );
443 strfreeW( filterW );
444 strarrayfreeW( attrsW );
446 #endif
447 return ret;
450 ULONG ldap_search_stW( WLDAP32_LDAP *ld, const PWCHAR base, ULONG scope,
451 const PWCHAR filter, PWCHAR attrs[], ULONG attrsonly,
452 struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
454 ULONG ret = LDAP_NOT_SUPPORTED;
455 #ifdef HAVE_LDAP
456 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
458 ret = WLDAP32_LDAP_NO_MEMORY;
460 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p)\n", ld,
461 debugstr_w(base), scope, debugstr_w(filter), attrs,
462 attrsonly, timeout, res );
464 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
466 if (base) {
467 baseU = strWtoU( base );
468 if (!baseU) goto exit;
470 if (filter) {
471 filterU = strWtoU( filter );
472 if (!filterU) goto exit;
474 if (attrs) {
475 attrsU = strarrayWtoU( attrs );
476 if (!attrsU) goto exit;
479 ret = ldap_search_st( ld, baseU, scope, filterU, attrsU, attrsonly,
480 (struct timeval *)timeout, res );
482 exit:
483 strfreeU( baseU );
484 strfreeU( filterU );
485 strarrayfreeU( attrsU );
487 #endif
488 return ret;