Better stick to the PSDK types.
[wine] / dlls / wldap32 / search.c
1 /*
2  * WLDAP32 - LDAP support for Wine
3  *
4  * Copyright 2005 Hans Leidekker
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include "wine/port.h"
24 #include "wine/debug.h"
25
26 #include <stdarg.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #else
35 #define LDAP_SUCCESS        0x00
36 #define LDAP_NOT_SUPPORTED  0x5c
37 #endif
38
39 #include "winldap_private.h"
40 #include "wldap32.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
43
44 ULONG ldap_search_abandon_page( WLDAP32_LDAP *ld, PLDAPSearch search )
45 {
46     FIXME( "(%p, %p)\n", ld, search );
47
48     if (!ld) return ~0UL;
49     return LDAP_SUCCESS;
50 }
51
52 ULONG ldap_searchA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope, PCHAR filter,
53     PCHAR attrs[], ULONG attrsonly )
54 {
55     ULONG ret = LDAP_NOT_SUPPORTED;
56 #ifdef HAVE_LDAP
57     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
58
59     ret = WLDAP32_LDAP_NO_MEMORY;
60
61     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_a(base),
62            scope, debugstr_a(filter), attrs, attrsonly );
63
64     if (!ld) return ~0UL;
65
66     if (base) {
67         baseW = strAtoW( base );
68         if (!baseW) goto exit;
69     }
70     if (filter) {
71         filterW = strAtoW( filter );
72         if (!filterW) goto exit;
73     }
74     if (attrs) {
75         attrsW = strarrayAtoW( attrs );
76         if (!attrsW) goto exit;
77     }
78
79     ret = ldap_searchW( ld, baseW, scope, filterW, attrsW, attrsonly );
80
81 exit:
82     strfreeW( baseW );
83     strfreeW( filterW );
84     strarrayfreeW( attrsW );
85
86 #endif
87     return ret;
88 }
89
90 ULONG ldap_searchW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
91     PWCHAR attrs[], ULONG attrsonly )
92 {
93     ULONG ret = LDAP_NOT_SUPPORTED;
94 #ifdef HAVE_LDAP
95     char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
96     int msg;
97
98     ret = WLDAP32_LDAP_NO_MEMORY;
99
100     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_w(base),
101            scope, debugstr_w(filter), attrs, attrsonly );
102
103     if (!ld) return ~0UL;
104
105     if (base) {
106         baseU = strWtoU( base );
107         if (!baseU) goto exit;
108     }
109     if (filter) {
110         filterU = strWtoU( filter );
111         if (!filterU) goto exit;
112     }
113     if (attrs) {
114         attrsU = strarrayWtoU( attrs );
115         if (!attrsU) goto exit;
116     }
117
118     ret = ldap_search_ext( ld, baseU, scope, filterU, attrsU, attrsonly,
119                            NULL, NULL, NULL, 0, &msg );
120
121     if (ret == LDAP_SUCCESS)
122         ret = msg;
123     else
124         ret = ~0UL;
125
126 exit:
127     strfreeU( baseU );
128     strfreeU( filterU );
129     strarrayfreeU( attrsU );
130
131 #endif
132     return ret;
133 }
134
135 ULONG ldap_search_extA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope,
136     PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
137     PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, ULONG *message )
138 {
139     ULONG ret = LDAP_NOT_SUPPORTED;
140 #ifdef HAVE_LDAP
141     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
142     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
143
144     ret = WLDAP32_LDAP_NO_MEMORY;
145
146     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, 0x%08lx, 0x%08lx, %p)\n",
147            ld, debugstr_a(base), scope, debugstr_a(filter), attrs, attrsonly,
148            serverctrls, clientctrls, timelimit, sizelimit, message );
149
150     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
151
152     if (base) {
153         baseW = strAtoW( base );
154         if (!baseW) goto exit;
155     }
156     if (filter)
157     {
158         filterW = strAtoW( filter );
159         if (!filterW) goto exit;
160     }
161     if (attrs) {
162         attrsW = strarrayAtoW( attrs );
163         if (!attrsW) goto exit;
164     }
165     if (serverctrls) {
166         serverctrlsW = controlarrayAtoW( serverctrls );
167         if (!serverctrlsW) goto exit;
168     }
169     if (clientctrls) {
170         clientctrlsW = controlarrayAtoW( clientctrls );
171         if (!clientctrlsW) goto exit;
172     }
173
174     ret = ldap_search_extW( ld, baseW, scope, filterW, attrsW, attrsonly,
175                             serverctrlsW, clientctrlsW, timelimit, sizelimit, message );
176
177 exit:
178     strfreeW( baseW );
179     strfreeW( filterW );
180     strarrayfreeW( attrsW );
181     controlarrayfreeW( serverctrlsW );
182     controlarrayfreeW( clientctrlsW );
183
184 #endif
185     return ret;
186 }
187
188 ULONG ldap_search_extW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope,
189     PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
190     PLDAPControlW *clientctrls, ULONG timelimit, ULONG sizelimit, ULONG *message )
191 {
192     ULONG ret = LDAP_NOT_SUPPORTED;
193 #ifdef HAVE_LDAP
194     char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
195     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
196     struct timeval tv;
197
198     ret = WLDAP32_LDAP_NO_MEMORY;
199
200     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, 0x%08lx, 0x%08lx, %p)\n",
201            ld, debugstr_w(base), scope, debugstr_w(filter), attrs, attrsonly,
202            serverctrls, clientctrls, timelimit, sizelimit, message );
203
204     if (!ld) return ~0UL;
205
206     if (base) {
207         baseU = strWtoU( base );
208         if (!baseU) goto exit;
209     }
210     if (filter) {
211         filterU = strWtoU( filter );
212         if (!filterU) goto exit;
213     }
214     if (attrs) {
215         attrsU = strarrayWtoU( attrs );
216         if (!attrsU) goto exit;
217     }
218     if (serverctrls) {
219         serverctrlsU = controlarrayWtoU( serverctrls );
220         if (!serverctrlsU) goto exit;
221     }
222     if (clientctrls) {
223         clientctrlsU = controlarrayWtoU( clientctrls );
224         if (!clientctrlsU) goto exit;
225     }
226
227     tv.tv_sec = timelimit;
228     tv.tv_usec = 0;
229
230     ret = ldap_search_ext( ld, baseU, scope, filterU, attrsU, attrsonly,
231                            serverctrlsU, clientctrlsU, &tv, sizelimit, (int *)message );
232
233 exit:
234     strfreeU( baseU );
235     strfreeU( filterU );
236     strarrayfreeU( attrsU );
237     controlarrayfreeU( serverctrlsU );
238     controlarrayfreeU( clientctrlsU );
239
240 #endif
241     return ret;
242 }
243
244 ULONG ldap_search_ext_sA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope,
245     PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
246     PLDAPControlA *clientctrls, struct l_timeval* timeout, ULONG sizelimit, WLDAP32_LDAPMessage **res )
247 {
248     ULONG ret = LDAP_NOT_SUPPORTED;
249 #ifdef HAVE_LDAP
250     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
251     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
252
253     ret = WLDAP32_LDAP_NO_MEMORY;
254
255     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, %p, 0x%08lx, %p)\n",
256            ld, debugstr_a(base), scope, debugstr_a(filter), attrs, attrsonly,
257            serverctrls, clientctrls, timeout, sizelimit, res );
258
259     if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
260
261     if (base) {
262         baseW = strAtoW( base );
263         if (!baseW) goto exit;
264     }
265     if (filter) {
266         filterW = strAtoW( filter );
267         if (!filterW) goto exit;
268     }
269     if (attrs) {
270         attrsW = strarrayAtoW( attrs );
271         if (!attrsW) goto exit;
272     }
273     if (serverctrls) {
274         serverctrlsW = controlarrayAtoW( serverctrls );
275         if (!serverctrlsW) goto exit;
276     }
277     if (clientctrls) {
278         clientctrlsW = controlarrayAtoW( clientctrls );
279         if (!clientctrlsW) goto exit;
280     }
281
282     ret = ldap_search_ext_sW( ld, baseW, scope, filterW, attrsW, attrsonly,
283                               serverctrlsW, clientctrlsW, timeout, sizelimit, res );
284
285 exit:
286     strfreeW( baseW );
287     strfreeW( filterW );
288     strarrayfreeW( attrsW );
289     controlarrayfreeW( serverctrlsW );
290     controlarrayfreeW( clientctrlsW );
291
292 #endif
293     return ret;
294 }
295
296 ULONG ldap_search_ext_sW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope,
297     PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
298     PLDAPControlW *clientctrls, struct l_timeval* timeout, ULONG sizelimit, WLDAP32_LDAPMessage **res )
299 {
300     ULONG ret = LDAP_NOT_SUPPORTED;
301 #ifdef HAVE_LDAP
302     char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
303     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
304
305     ret = WLDAP32_LDAP_NO_MEMORY;
306
307     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p, %p, 0x%08lx, %p)\n",
308            ld, debugstr_w(base), scope, debugstr_w(filter), attrs, attrsonly,
309            serverctrls, clientctrls, timeout, sizelimit, res );
310
311     if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
312
313     if (base) {
314         baseU = strWtoU( base );
315         if (!baseU) goto exit;
316     }
317     if (filter) {
318         filterU = strWtoU( filter );
319         if (!filterU) goto exit;
320     }
321     if (attrs) {
322         attrsU = strarrayWtoU( attrs );
323         if (!attrsU) goto exit;
324     }
325     if (serverctrls) {
326         serverctrlsU = controlarrayWtoU( serverctrls );
327         if (!serverctrlsU) goto exit;
328     }
329     if (clientctrls) {
330         clientctrlsU = controlarrayWtoU( clientctrls );
331         if (!clientctrlsU) goto exit;
332     }
333
334     ret = ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
335                              serverctrlsU, clientctrlsU, (struct timeval *)timeout, sizelimit, res );
336
337 exit:
338     strfreeU( baseU );
339     strfreeU( filterU );
340     strarrayfreeU( attrsU );
341     controlarrayfreeU( serverctrlsU );
342     controlarrayfreeU( clientctrlsU );
343
344 #endif
345     return ret;
346 }
347
348 PLDAPSearch ldap_search_init_pageA( WLDAP32_LDAP *ld, PCHAR dn, ULONG scope,
349     PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
350     PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyA *sortkeys )
351 {
352     FIXME( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_a(dn),
353            scope, debugstr_a(filter), attrs, attrsonly );
354     return NULL;
355 }
356
357 PLDAPSearch ldap_search_init_pageW( WLDAP32_LDAP *ld, PWCHAR dn, ULONG scope,
358     PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
359     PLDAPControlW *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyW *sortkeys )
360 {
361     FIXME( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_w(dn),
362            scope, debugstr_w(filter), attrs, attrsonly );
363     return NULL;
364 }
365
366 ULONG ldap_search_sA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope, PCHAR filter,
367     PCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
368 {
369     ULONG ret = LDAP_NOT_SUPPORTED;
370 #ifdef HAVE_LDAP
371     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
372
373     ret = WLDAP32_LDAP_NO_MEMORY;
374
375     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld, debugstr_a(base),
376            scope, debugstr_a(filter), attrs, attrsonly, res );
377
378     if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
379
380     if (base) {
381         baseW = strAtoW( base );
382         if (!baseW) goto exit;
383     }
384     if (filter) {
385         filterW = strAtoW( filter );
386         if (!filterW) goto exit;
387     }
388     if (attrs) {
389         attrsW = strarrayAtoW( attrs );
390         if (!attrsW) goto exit;
391     }
392
393     ret = ldap_search_sW( ld, baseW, scope, filterW, attrsW, attrsonly, res );
394
395 exit:
396     strfreeW( baseW );
397     strfreeW( filterW );
398     strarrayfreeW( attrsW );
399
400 #endif
401     return ret;
402 }
403
404 ULONG ldap_search_sW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
405     PWCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
406 {
407     ULONG ret = LDAP_NOT_SUPPORTED;
408 #ifdef HAVE_LDAP
409     char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
410
411     ret = WLDAP32_LDAP_NO_MEMORY;
412
413     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld, debugstr_w(base),
414            scope, debugstr_w(filter), attrs, attrsonly, res );
415
416     if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
417
418     if (base) {
419         baseU = strWtoU( base );
420         if (!baseU) goto exit;
421     }
422     if (filter) {
423         filterU = strWtoU( filter );
424         if (!filterU) goto exit;
425     }
426     if (attrs) {
427         attrsU = strarrayWtoU( attrs );
428         if (!attrsU) goto exit;
429     }
430
431     ret = ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
432                              NULL, NULL, NULL, 0, res );
433
434 exit:
435     strfreeU( baseU );
436     strfreeU( filterU );
437     strarrayfreeU( attrsU );
438
439 #endif
440     return ret;
441 }
442
443 ULONG ldap_search_stA( WLDAP32_LDAP *ld, const PCHAR base, ULONG scope,
444     const PCHAR filter, PCHAR attrs[], ULONG attrsonly,
445     struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
446 {
447     ULONG ret = LDAP_NOT_SUPPORTED;
448 #ifdef HAVE_LDAP
449     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
450
451     ret = WLDAP32_LDAP_NO_MEMORY;
452
453     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p)\n", ld,
454            debugstr_a(base), scope, debugstr_a(filter), attrs,
455            attrsonly, timeout, res );
456
457     if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
458
459     if (base) {
460         baseW = strAtoW( base );
461         if (!baseW) goto exit;
462     }
463     if (filter) {
464         filterW = strAtoW( filter );
465         if (!filterW) goto exit;
466     }
467     if (attrs) {
468         attrsW = strarrayAtoW( attrs );
469         if (!attrsW) goto exit;
470     }
471
472     ret = ldap_search_stW( ld, baseW, scope, filterW, attrsW, attrsonly,
473                            timeout, res );
474
475 exit:
476     strfreeW( baseW );
477     strfreeW( filterW );
478     strarrayfreeW( attrsW );
479
480 #endif
481     return ret;
482 }
483
484 ULONG ldap_search_stW( WLDAP32_LDAP *ld, const PWCHAR base, ULONG scope,
485     const PWCHAR filter, PWCHAR attrs[], ULONG attrsonly,
486     struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
487 {
488     ULONG ret = LDAP_NOT_SUPPORTED;
489 #ifdef HAVE_LDAP
490     char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
491
492     ret = WLDAP32_LDAP_NO_MEMORY;
493
494     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p)\n", ld,
495            debugstr_w(base), scope, debugstr_w(filter), attrs,
496            attrsonly, timeout, res );
497
498     if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
499
500     if (base) {
501         baseU = strWtoU( base );
502         if (!baseU) goto exit;
503     }
504     if (filter) {
505         filterU = strWtoU( filter );
506         if (!filterU) goto exit;
507     }
508     if (attrs) {
509         attrsU = strarrayWtoU( attrs );
510         if (!attrsU) goto exit;
511     }
512
513     ret = ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
514                              NULL, NULL, (struct timeval *)timeout, 0, res );
515
516 exit:
517     strfreeU( baseU );
518     strfreeU( filterU );
519     strarrayfreeU( attrsU );
520
521 #endif
522     return ret;
523 }