ntoskrnl.exe/tests: Add some IOCTL_HID_WRITE_REPORT tests.
[wine.git] / dlls / wldap32 / search.c
blobaf5b4ab63d3371dc2e163c8566765894a104bdd8
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 <stdarg.h>
22 #include <stdlib.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winnls.h"
26 #include "winldap.h"
28 #include "wine/debug.h"
29 #include "winldap_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
33 /***********************************************************************
34 * ldap_searchA (WLDAP32.@)
36 * See ldap_searchW.
38 ULONG CDECL ldap_searchA( LDAP *ld, char *base, ULONG scope, char *filter, char **attrs, ULONG attrsonly )
40 ULONG ret = LDAP_NO_MEMORY;
41 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
43 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld, debugstr_a(base), scope, debugstr_a(filter), attrs, attrsonly );
45 if (!ld) return ~0u;
47 if (base && !(baseW = strAtoW( base ))) goto exit;
48 if (filter && !(filterW = strAtoW( filter ))) goto exit;
49 if (attrs && !(attrsW = strarrayAtoW( attrs ))) goto exit;
51 ret = ldap_searchW( ld, baseW, scope, filterW, attrsW, attrsonly );
53 exit:
54 free( baseW );
55 free( filterW );
56 strarrayfreeW( attrsW );
57 return ret;
60 /***********************************************************************
61 * ldap_searchW (WLDAP32.@)
63 * Search a directory tree (asynchronous operation).
65 * PARAMS
66 * ld [I] Pointer to an LDAP context.
67 * base [I] Starting point for the search.
68 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
69 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
70 * filter [I] Search filter.
71 * attrs [I] Attributes to return.
72 * attrsonly [I] Return no values, only attributes.
74 * RETURNS
75 * Success: Message ID of the search operation.
76 * Failure: ~0u
78 * NOTES
79 * Call ldap_result with the message ID to get the result of
80 * the operation. Cancel the operation by calling ldap_abandon
81 * with the message ID.
83 ULONG CDECL ldap_searchW( LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs, ULONG attrsonly )
85 ULONG ret, msg;
86 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld, debugstr_w(base), scope, debugstr_w(filter), attrs, attrsonly );
88 ret = ldap_search_extW( ld, base, scope, filter, attrs, attrsonly, NULL, NULL, 0, 0, &msg );
89 if (ret == LDAP_SUCCESS) return msg;
90 return ~0u;
93 /***********************************************************************
94 * ldap_search_extA (WLDAP32.@)
96 * See ldap_search_extW.
98 ULONG CDECL ldap_search_extA( LDAP *ld, char *base, ULONG scope, char *filter, char **attrs, ULONG attrsonly,
99 LDAPControlA **serverctrls, LDAPControlA **clientctrls, ULONG timelimit, ULONG sizelimit, ULONG *message )
101 ULONG ret = LDAP_NO_MEMORY;
102 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
103 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
105 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, 0x%08x, 0x%08x, %p)\n", ld, debugstr_a(base), scope,
106 debugstr_a(filter), attrs, attrsonly, serverctrls, clientctrls, timelimit, sizelimit, message );
108 if (!ld) return LDAP_PARAM_ERROR;
110 if (base && !(baseW = strAtoW( base ))) goto exit;
111 if (filter && !(filterW = strAtoW( filter ))) goto exit;
112 if (attrs && !(attrsW = strarrayAtoW( attrs ))) goto exit;
113 if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit;
114 if (clientctrls && !(clientctrlsW = controlarrayAtoW( clientctrls ))) goto exit;
116 ret = ldap_search_extW( ld, baseW, scope, filterW, attrsW, attrsonly, serverctrlsW, clientctrlsW, timelimit,
117 sizelimit, message );
119 exit:
120 free( baseW );
121 free( filterW );
122 strarrayfreeW( attrsW );
123 controlarrayfreeW( serverctrlsW );
124 controlarrayfreeW( clientctrlsW );
125 return ret;
128 /***********************************************************************
129 * ldap_search_extW (WLDAP32.@)
131 * Search a directory tree (asynchronous operation).
133 * PARAMS
134 * ld [I] Pointer to an LDAP context.
135 * base [I] Starting point for the search.
136 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
137 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
138 * filter [I] Search filter.
139 * attrs [I] Attributes to return.
140 * attrsonly [I] Return no values, only attributes.
141 * serverctrls [I] Array of LDAP server controls.
142 * clientctrls [I] Array of LDAP client controls.
143 * timelimit [I] Timeout in seconds.
144 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
145 * message [O] Message ID of the search operation.
147 * RETURNS
148 * Success: LDAP_SUCCESS
149 * Failure: An LDAP error code.
151 * NOTES
152 * Call ldap_result with the message ID to get the result of
153 * the operation. Cancel the operation by calling ldap_abandon
154 * with the message ID.
156 ULONG CDECL ldap_search_extW( LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs,
157 ULONG attrsonly, LDAPControlW **serverctrls, LDAPControlW **clientctrls, ULONG timelimit, ULONG sizelimit,
158 ULONG *message )
160 ULONG ret = LDAP_NO_MEMORY;
161 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
162 LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
163 struct timevalU timevalU;
165 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, 0x%08x, 0x%08x, %p)\n", ld, debugstr_w(base), scope,
166 debugstr_w(filter), attrs, attrsonly, serverctrls, clientctrls, timelimit, sizelimit, message );
168 if (!ld) return ~0u;
170 if (base && !(baseU = strWtoU( base ))) goto exit;
171 if (filter && !(filterU = strWtoU( filter ))) goto exit;
172 if (attrs && !(attrsU = strarrayWtoU( attrs ))) goto exit;
173 if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
174 if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
176 timevalU.tv_sec = timelimit;
177 timevalU.tv_usec = 0;
179 ret = map_error( ldap_funcs->fn_ldap_search_ext( CTX(ld), baseU, scope, filterU, attrsU, attrsonly, serverctrlsU,
180 clientctrlsU, timelimit ? &timevalU : NULL, sizelimit, message ) );
181 exit:
182 free( baseU );
183 free( filterU );
184 strarrayfreeU( attrsU );
185 controlarrayfreeU( serverctrlsU );
186 controlarrayfreeU( clientctrlsU );
187 return ret;
190 /***********************************************************************
191 * ldap_search_ext_sA (WLDAP32.@)
193 * See ldap_search_ext_sW.
195 ULONG CDECL ldap_search_ext_sA( LDAP *ld, char *base, ULONG scope, char *filter, char **attrs,
196 ULONG attrsonly, LDAPControlA **serverctrls, LDAPControlA **clientctrls, struct l_timeval *timeout,
197 ULONG sizelimit, LDAPMessage **res )
199 ULONG ret = LDAP_NO_MEMORY;
200 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
201 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
203 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n", ld, debugstr_a(base), scope,
204 debugstr_a(filter), attrs, attrsonly, serverctrls, clientctrls, timeout, sizelimit, res );
206 if (!ld || !res) return LDAP_PARAM_ERROR;
208 if (base && !(baseW = strAtoW( base ))) goto exit;
209 if (filter && !(filterW = strAtoW( filter ))) goto exit;
210 if (attrs && !(attrsW = strarrayAtoW( attrs ))) goto exit;
211 if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit;
212 if (clientctrls && !(clientctrlsW = controlarrayAtoW( clientctrls ))) goto exit;
214 ret = ldap_search_ext_sW( ld, baseW, scope, filterW, attrsW, attrsonly, serverctrlsW, clientctrlsW, timeout,
215 sizelimit, res );
217 exit:
218 free( baseW );
219 free( filterW );
220 strarrayfreeW( attrsW );
221 controlarrayfreeW( serverctrlsW );
222 controlarrayfreeW( clientctrlsW );
223 return ret;
226 /***********************************************************************
227 * ldap_search_ext_sW (WLDAP32.@)
229 * Search a directory tree (synchronous operation).
231 * PARAMS
232 * ld [I] Pointer to an LDAP context.
233 * base [I] Starting point for the search.
234 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
235 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
236 * filter [I] Search filter.
237 * attrs [I] Attributes to return.
238 * attrsonly [I] Return no values, only attributes.
239 * serverctrls [I] Array of LDAP server controls.
240 * clientctrls [I] Array of LDAP client controls.
241 * timeout [I] Timeout in seconds.
242 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
243 * res [O] Results of the search operation.
245 * RETURNS
246 * Success: LDAP_SUCCESS
247 * Failure: An LDAP error code.
249 * NOTES
250 * Call ldap_msgfree to free the results.
252 ULONG CDECL ldap_search_ext_sW( LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs,
253 ULONG attrsonly, LDAPControlW **serverctrls, LDAPControlW **clientctrls, struct l_timeval *timeout,
254 ULONG sizelimit, LDAPMessage **res )
256 ULONG ret = LDAP_NO_MEMORY;
257 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
258 LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
259 struct timevalU timevalU;
260 void *msgU = NULL;
262 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n", ld, debugstr_w(base), scope,
263 debugstr_w(filter), attrs, attrsonly, serverctrls, clientctrls, timeout, sizelimit, res );
265 if (!ld || !res) return LDAP_PARAM_ERROR;
267 if (base && !(baseU = strWtoU( base ))) goto exit;
268 if (filter && !(filterU = strWtoU( filter ))) goto exit;
269 if (attrs && !(attrsU = strarrayWtoU( attrs ))) goto exit;
270 if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
271 if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
273 if (timeout)
275 timevalU.tv_sec = timeout->tv_sec;
276 timevalU.tv_usec = timeout->tv_usec;
279 ret = map_error( ldap_funcs->fn_ldap_search_ext_s( CTX(ld), baseU, scope, filterU, attrsU, attrsonly, serverctrlsU,
280 clientctrlsU, timeout ? &timevalU : NULL, sizelimit, &msgU ) );
281 if (msgU)
283 LDAPMessage *msg = calloc( 1, sizeof(*msg) );
284 if (msg)
286 MSG(msg) = msgU;
287 *res = msg;
289 else
291 ldap_funcs->fn_ldap_msgfree( msgU );
292 ret = LDAP_NO_MEMORY;
296 exit:
297 free( baseU );
298 free( filterU );
299 strarrayfreeU( attrsU );
300 controlarrayfreeU( serverctrlsU );
301 controlarrayfreeU( clientctrlsU );
302 return ret;
305 /***********************************************************************
306 * ldap_search_sA (WLDAP32.@)
308 * See ldap_search_sW.
310 ULONG CDECL ldap_search_sA( LDAP *ld, char *base, ULONG scope, char *filter, char **attrs, ULONG attrsonly,
311 LDAPMessage **res )
313 ULONG ret = LDAP_NO_MEMORY;
314 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
316 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p)\n", ld, debugstr_a(base), scope, debugstr_a(filter), attrs,
317 attrsonly, res );
319 if (!ld || !res) return LDAP_PARAM_ERROR;
321 if (base && !(baseW = strAtoW( base ))) goto exit;
322 if (filter && !(filterW = strAtoW( filter ))) goto exit;
323 if (attrs && !(attrsW = strarrayAtoW( attrs ))) goto exit;
325 ret = ldap_search_sW( ld, baseW, scope, filterW, attrsW, attrsonly, res );
327 exit:
328 free( baseW );
329 free( filterW );
330 strarrayfreeW( attrsW );
331 return ret;
334 /***********************************************************************
335 * ldap_search_sW (WLDAP32.@)
337 * Search a directory tree (synchronous operation).
339 * PARAMS
340 * ld [I] Pointer to an LDAP context.
341 * base [I] Starting point for the search.
342 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
343 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
344 * filter [I] Search filter.
345 * attrs [I] Attributes to return.
346 * attrsonly [I] Return no values, only attributes.
347 * res [O] Results of the search operation.
349 * RETURNS
350 * Success: LDAP_SUCCESS
351 * Failure: An LDAP error code.
353 * NOTES
354 * Call ldap_msgfree to free the results.
356 ULONG CDECL ldap_search_sW( LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs, ULONG attrsonly,
357 LDAPMessage **res )
359 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p)\n", ld, debugstr_w(base), scope, debugstr_w(filter), attrs,
360 attrsonly, res );
361 return ldap_search_ext_sW( ld, base, scope, filter, attrs, attrsonly, NULL, NULL, NULL, 0, res );
364 /***********************************************************************
365 * ldap_search_stA (WLDAP32.@)
367 * See ldap_search_stW.
369 ULONG CDECL ldap_search_stA( LDAP *ld, const PCHAR base, ULONG scope, const PCHAR filter, char **attrs,
370 ULONG attrsonly, struct l_timeval *timeout, LDAPMessage **res )
372 ULONG ret = LDAP_NO_MEMORY;
373 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
375 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p)\n", ld, debugstr_a(base), scope, debugstr_a(filter), attrs,
376 attrsonly, timeout, res );
378 if (!ld || !res) return LDAP_PARAM_ERROR;
380 if (base && !(baseW = strAtoW( base ))) goto exit;
381 if (filter && !(filterW = strAtoW( filter ))) goto exit;
382 if (attrs && !(attrsW = strarrayAtoW( attrs ))) goto exit;
384 ret = ldap_search_stW( ld, baseW, scope, filterW, attrsW, attrsonly, timeout, res );
386 exit:
387 free( baseW );
388 free( filterW );
389 strarrayfreeW( attrsW );
390 return ret;
393 /***********************************************************************
394 * ldap_search_stW (WLDAP32.@)
396 * Search a directory tree (synchronous operation).
398 * PARAMS
399 * ld [I] Pointer to an LDAP context.
400 * base [I] Starting point for the search.
401 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
402 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
403 * filter [I] Search filter.
404 * attrs [I] Attributes to return.
405 * attrsonly [I] Return no values, only attributes.
406 * timeout [I] Timeout in seconds.
407 * res [O] Results of the search operation.
409 * RETURNS
410 * Success: LDAP_SUCCESS
411 * Failure: An LDAP error code.
413 * NOTES
414 * Call ldap_msgfree to free the results.
416 ULONG CDECL ldap_search_stW( LDAP *ld, const PWCHAR base, ULONG scope, const PWCHAR filter, WCHAR **attrs,
417 ULONG attrsonly, struct l_timeval *timeout, LDAPMessage **res )
419 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p)\n", ld, debugstr_w(base), scope, debugstr_w(filter), attrs,
420 attrsonly, timeout, res );
421 return ldap_search_ext_sW( ld, base, scope, filter, attrs, attrsonly, NULL, NULL, timeout, 0, res );