mscms: Fix some wine_todo for GetStandardColorSpaceProfile().
[wine.git] / dlls / wldap32 / search.c
blob99304eefb65fb7c733cbf3858352faec7787f1d2
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;
88 int msg;
90 ret = WLDAP32_LDAP_NO_MEMORY;
92 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_w(base),
93 scope, debugstr_w(filter), attrs, attrsonly );
95 if (!ld) return ~0UL;
97 if (base) {
98 baseU = strWtoU( base );
99 if (!baseU) goto exit;
101 if (filter) {
102 filterU = strWtoU( filter );
103 if (!filterU) goto exit;
105 if (attrs) {
106 attrsU = strarrayWtoU( attrs );
107 if (!attrsU) goto exit;
110 ret = ldap_search_ext( ld, baseU, scope, filterU, attrsU, attrsonly,
111 NULL, NULL, NULL, 0, &msg );
113 if (ret == LDAP_SUCCESS)
114 ret = msg;
115 else
116 ret = ~0UL;
118 exit:
119 strfreeU( baseU );
120 strfreeU( filterU );
121 strarrayfreeU( attrsU );
123 #endif
124 return ret;
127 ULONG ldap_search_extA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope,
128 PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
129 PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, ULONG *message )
131 ULONG ret = LDAP_NOT_SUPPORTED;
132 #ifdef HAVE_LDAP
133 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
134 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
136 ret = WLDAP32_LDAP_NO_MEMORY;
138 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, 0x%08lx, 0x%08lx, %p)\n",
139 ld, debugstr_a(base), scope, debugstr_a(filter), attrs, attrsonly,
140 serverctrls, clientctrls, timelimit, sizelimit, message );
142 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
144 if (base) {
145 baseW = strAtoW( base );
146 if (!baseW) goto exit;
148 if (filter)
150 filterW = strAtoW( filter );
151 if (!filterW) goto exit;
153 if (attrs) {
154 attrsW = strarrayAtoW( attrs );
155 if (!attrsW) goto exit;
157 if (serverctrls) {
158 serverctrlsW = controlarrayAtoW( serverctrls );
159 if (!serverctrlsW) goto exit;
161 if (clientctrls) {
162 clientctrlsW = controlarrayAtoW( clientctrls );
163 if (!clientctrlsW) goto exit;
166 ret = ldap_search_extW( ld, baseW, scope, filterW, attrsW, attrsonly,
167 serverctrlsW, clientctrlsW, timelimit, sizelimit, message );
169 exit:
170 strfreeW( baseW );
171 strfreeW( filterW );
172 strarrayfreeW( attrsW );
173 controlarrayfreeW( serverctrlsW );
174 controlarrayfreeW( clientctrlsW );
176 #endif
177 return ret;
180 ULONG ldap_search_extW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope,
181 PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
182 PLDAPControlW *clientctrls, ULONG timelimit, ULONG sizelimit, ULONG *message )
184 ULONG ret = LDAP_NOT_SUPPORTED;
185 #ifdef HAVE_LDAP
186 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
187 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
188 struct timeval tv;
190 ret = WLDAP32_LDAP_NO_MEMORY;
192 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, 0x%08lx, 0x%08lx, %p)\n",
193 ld, debugstr_w(base), scope, debugstr_w(filter), attrs, attrsonly,
194 serverctrls, clientctrls, timelimit, sizelimit, message );
196 if (!ld) return ~0UL;
198 if (base) {
199 baseU = strWtoU( base );
200 if (!baseU) goto exit;
202 if (filter) {
203 filterU = strWtoU( filter );
204 if (!filterU) goto exit;
206 if (attrs) {
207 attrsU = strarrayWtoU( attrs );
208 if (!attrsU) goto exit;
210 if (serverctrls) {
211 serverctrlsU = controlarrayWtoU( serverctrls );
212 if (!serverctrlsU) goto exit;
214 if (clientctrls) {
215 clientctrlsU = controlarrayWtoU( clientctrls );
216 if (!clientctrlsU) goto exit;
219 tv.tv_sec = timelimit;
220 tv.tv_usec = 0;
222 ret = ldap_search_ext( ld, baseU, scope, filterU, attrsU, attrsonly,
223 serverctrlsU, clientctrlsU, &tv, sizelimit, (int *)message );
225 exit:
226 strfreeU( baseU );
227 strfreeU( filterU );
228 strarrayfreeU( attrsU );
229 controlarrayfreeU( serverctrlsU );
230 controlarrayfreeU( clientctrlsU );
232 #endif
233 return ret;
236 ULONG ldap_search_ext_sA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope,
237 PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
238 PLDAPControlA *clientctrls, struct l_timeval* timeout, ULONG sizelimit, WLDAP32_LDAPMessage **res )
240 ULONG ret = LDAP_NOT_SUPPORTED;
241 #ifdef HAVE_LDAP
242 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
243 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
245 ret = WLDAP32_LDAP_NO_MEMORY;
247 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, %p, 0x%08lx, %p)\n",
248 ld, debugstr_a(base), scope, debugstr_a(filter), attrs, attrsonly,
249 serverctrls, clientctrls, timeout, sizelimit, res );
251 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
253 if (base) {
254 baseW = strAtoW( base );
255 if (!baseW) goto exit;
257 if (filter) {
258 filterW = strAtoW( filter );
259 if (!filterW) goto exit;
261 if (attrs) {
262 attrsW = strarrayAtoW( attrs );
263 if (!attrsW) goto exit;
265 if (serverctrls) {
266 serverctrlsW = controlarrayAtoW( serverctrls );
267 if (!serverctrlsW) goto exit;
269 if (clientctrls) {
270 clientctrlsW = controlarrayAtoW( clientctrls );
271 if (!clientctrlsW) goto exit;
274 ret = ldap_search_ext_sW( ld, baseW, scope, filterW, attrsW, attrsonly,
275 serverctrlsW, clientctrlsW, timeout, sizelimit, res );
277 exit:
278 strfreeW( baseW );
279 strfreeW( filterW );
280 strarrayfreeW( attrsW );
281 controlarrayfreeW( serverctrlsW );
282 controlarrayfreeW( clientctrlsW );
284 #endif
285 return ret;
288 ULONG ldap_search_ext_sW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope,
289 PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
290 PLDAPControlW *clientctrls, struct l_timeval* timeout, ULONG sizelimit, WLDAP32_LDAPMessage **res )
292 ULONG ret = LDAP_NOT_SUPPORTED;
293 #ifdef HAVE_LDAP
294 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
295 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
297 ret = WLDAP32_LDAP_NO_MEMORY;
299 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, %p, 0x%08lx, %p)\n",
300 ld, debugstr_w(base), scope, debugstr_w(filter), attrs, attrsonly,
301 serverctrls, clientctrls, timeout, sizelimit, res );
303 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
305 if (base) {
306 baseU = strWtoU( base );
307 if (!baseU) goto exit;
309 if (filter) {
310 filterU = strWtoU( filter );
311 if (!filterU) goto exit;
313 if (attrs) {
314 attrsU = strarrayWtoU( attrs );
315 if (!attrsU) goto exit;
317 if (serverctrls) {
318 serverctrlsU = controlarrayWtoU( serverctrls );
319 if (!serverctrlsU) goto exit;
321 if (clientctrls) {
322 clientctrlsU = controlarrayWtoU( clientctrls );
323 if (!clientctrlsU) goto exit;
326 ret = ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
327 serverctrlsU, clientctrlsU, (struct timeval *)timeout, sizelimit, res );
329 exit:
330 strfreeU( baseU );
331 strfreeU( filterU );
332 strarrayfreeU( attrsU );
333 controlarrayfreeU( serverctrlsU );
334 controlarrayfreeU( clientctrlsU );
336 #endif
337 return ret;
340 ULONG ldap_search_sA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope, PCHAR filter,
341 PCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
343 ULONG ret = LDAP_NOT_SUPPORTED;
344 #ifdef HAVE_LDAP
345 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
347 ret = WLDAP32_LDAP_NO_MEMORY;
349 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld, debugstr_a(base),
350 scope, debugstr_a(filter), attrs, attrsonly, res );
352 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
354 if (base) {
355 baseW = strAtoW( base );
356 if (!baseW) goto exit;
358 if (filter) {
359 filterW = strAtoW( filter );
360 if (!filterW) goto exit;
362 if (attrs) {
363 attrsW = strarrayAtoW( attrs );
364 if (!attrsW) goto exit;
367 ret = ldap_search_sW( ld, baseW, scope, filterW, attrsW, attrsonly, res );
369 exit:
370 strfreeW( baseW );
371 strfreeW( filterW );
372 strarrayfreeW( attrsW );
374 #endif
375 return ret;
378 ULONG ldap_search_sW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
379 PWCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
381 ULONG ret = LDAP_NOT_SUPPORTED;
382 #ifdef HAVE_LDAP
383 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
385 ret = WLDAP32_LDAP_NO_MEMORY;
387 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld, debugstr_w(base),
388 scope, debugstr_w(filter), attrs, attrsonly, res );
390 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
392 if (base) {
393 baseU = strWtoU( base );
394 if (!baseU) goto exit;
396 if (filter) {
397 filterU = strWtoU( filter );
398 if (!filterU) goto exit;
400 if (attrs) {
401 attrsU = strarrayWtoU( attrs );
402 if (!attrsU) goto exit;
405 ret = ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
406 NULL, NULL, NULL, 0, res );
408 exit:
409 strfreeU( baseU );
410 strfreeU( filterU );
411 strarrayfreeU( attrsU );
413 #endif
414 return ret;
417 ULONG ldap_search_stA( WLDAP32_LDAP *ld, const PCHAR base, ULONG scope,
418 const PCHAR filter, PCHAR attrs[], ULONG attrsonly,
419 struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
421 ULONG ret = LDAP_NOT_SUPPORTED;
422 #ifdef HAVE_LDAP
423 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
425 ret = WLDAP32_LDAP_NO_MEMORY;
427 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p)\n", ld,
428 debugstr_a(base), scope, debugstr_a(filter), attrs,
429 attrsonly, timeout, res );
431 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
433 if (base) {
434 baseW = strAtoW( base );
435 if (!baseW) goto exit;
437 if (filter) {
438 filterW = strAtoW( filter );
439 if (!filterW) goto exit;
441 if (attrs) {
442 attrsW = strarrayAtoW( attrs );
443 if (!attrsW) goto exit;
446 ret = ldap_search_stW( ld, baseW, scope, filterW, attrsW, attrsonly,
447 timeout, res );
449 exit:
450 strfreeW( baseW );
451 strfreeW( filterW );
452 strarrayfreeW( attrsW );
454 #endif
455 return ret;
458 ULONG ldap_search_stW( WLDAP32_LDAP *ld, const PWCHAR base, ULONG scope,
459 const PWCHAR filter, PWCHAR attrs[], ULONG attrsonly,
460 struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
462 ULONG ret = LDAP_NOT_SUPPORTED;
463 #ifdef HAVE_LDAP
464 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
466 ret = WLDAP32_LDAP_NO_MEMORY;
468 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p)\n", ld,
469 debugstr_w(base), scope, debugstr_w(filter), attrs,
470 attrsonly, timeout, res );
472 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
474 if (base) {
475 baseU = strWtoU( base );
476 if (!baseU) goto exit;
478 if (filter) {
479 filterU = strWtoU( filter );
480 if (!filterU) goto exit;
482 if (attrs) {
483 attrsU = strarrayWtoU( attrs );
484 if (!attrsU) goto exit;
487 ret = ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
488 NULL, NULL, (struct timeval *)timeout, 0, res );
490 exit:
491 strfreeU( baseU );
492 strfreeU( filterU );
493 strarrayfreeU( attrsU );
495 #endif
496 return ret;