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