dwmapi: Clear DWM_TIMING_INFO structure before returning.
[wine.git] / dlls / wldap32 / search.c
bloba673851b148ef9517762f3578100a5881543dbf9
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, %#lx, %s, %p, %#lx)\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, %#lx, %s, %p, %#lx)\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, %#lx, %s, %p, %#lx, %p, %p, %#lx, %#lx, %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, %#lx, %s, %p, %#lx, %p, %p, %#lx, %#lx, %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;
180 struct ldap_search_ext_params params = { CTX(ld), baseU, scope, filterU, attrsU, attrsonly,
181 serverctrlsU, clientctrlsU, timelimit ? &timevalU : NULL, sizelimit, message };
182 ret = map_error( LDAP_CALL( ldap_search_ext, &params ));
184 exit:
185 free( baseU );
186 free( filterU );
187 strarrayfreeU( attrsU );
188 controlarrayfreeU( serverctrlsU );
189 controlarrayfreeU( clientctrlsU );
190 return ret;
193 /***********************************************************************
194 * ldap_search_ext_sA (WLDAP32.@)
196 * See ldap_search_ext_sW.
198 ULONG CDECL ldap_search_ext_sA( LDAP *ld, char *base, ULONG scope, char *filter, char **attrs,
199 ULONG attrsonly, LDAPControlA **serverctrls, LDAPControlA **clientctrls, struct l_timeval *timeout,
200 ULONG sizelimit, LDAPMessage **res )
202 ULONG ret = LDAP_NO_MEMORY;
203 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
204 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
206 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p, %p, %p, %#lx, %p)\n", ld, debugstr_a(base), scope,
207 debugstr_a(filter), attrs, attrsonly, serverctrls, clientctrls, timeout, sizelimit, res );
209 if (!ld || !res) return LDAP_PARAM_ERROR;
211 if (base && !(baseW = strAtoW( base ))) goto exit;
212 if (filter && !(filterW = strAtoW( filter ))) goto exit;
213 if (attrs && !(attrsW = strarrayAtoW( attrs ))) goto exit;
214 if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit;
215 if (clientctrls && !(clientctrlsW = controlarrayAtoW( clientctrls ))) goto exit;
217 ret = ldap_search_ext_sW( ld, baseW, scope, filterW, attrsW, attrsonly, serverctrlsW, clientctrlsW, timeout,
218 sizelimit, res );
220 exit:
221 free( baseW );
222 free( filterW );
223 strarrayfreeW( attrsW );
224 controlarrayfreeW( serverctrlsW );
225 controlarrayfreeW( clientctrlsW );
226 return ret;
229 /***********************************************************************
230 * ldap_search_ext_sW (WLDAP32.@)
232 * Search a directory tree (synchronous operation).
234 * PARAMS
235 * ld [I] Pointer to an LDAP context.
236 * base [I] Starting point for the search.
237 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
238 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
239 * filter [I] Search filter.
240 * attrs [I] Attributes to return.
241 * attrsonly [I] Return no values, only attributes.
242 * serverctrls [I] Array of LDAP server controls.
243 * clientctrls [I] Array of LDAP client controls.
244 * timeout [I] Timeout in seconds.
245 * sizelimit [I] Maximum number of entries to return. Zero means unlimited.
246 * res [O] Results of the search operation.
248 * RETURNS
249 * Success: LDAP_SUCCESS
250 * Failure: An LDAP error code.
252 * NOTES
253 * Call ldap_msgfree to free the results.
255 ULONG CDECL ldap_search_ext_sW( LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs,
256 ULONG attrsonly, LDAPControlW **serverctrls, LDAPControlW **clientctrls, struct l_timeval *timeout,
257 ULONG sizelimit, LDAPMessage **res )
259 ULONG ret = LDAP_NO_MEMORY;
260 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
261 LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
262 struct timevalU timevalU;
263 void *msgU = NULL;
265 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p, %p, %p, %#lx, %p)\n", ld, debugstr_w(base), scope,
266 debugstr_w(filter), attrs, attrsonly, serverctrls, clientctrls, timeout, sizelimit, res );
268 if (!ld || !res) return LDAP_PARAM_ERROR;
270 if (base && !(baseU = strWtoU( base ))) goto exit;
271 if (filter && !(filterU = strWtoU( filter ))) goto exit;
272 if (attrs && !(attrsU = strarrayWtoU( attrs ))) goto exit;
273 if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
274 if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
276 if (timeout)
278 timevalU.tv_sec = timeout->tv_sec;
279 timevalU.tv_usec = timeout->tv_usec;
283 struct ldap_search_ext_s_params params = { CTX(ld), baseU, scope, filterU, attrsU, attrsonly,
284 serverctrlsU, clientctrlsU, timeout ? &timevalU : NULL, sizelimit, &msgU };
285 ret = map_error( LDAP_CALL( ldap_search_ext_s, &params ));
288 if (msgU)
290 LDAPMessage *msg = calloc( 1, sizeof(*msg) );
291 if (msg)
293 MSG(msg) = msgU;
294 *res = msg;
296 else
298 LDAP_CALL( ldap_msgfree, msgU );
299 ret = LDAP_NO_MEMORY;
303 exit:
304 free( baseU );
305 free( filterU );
306 strarrayfreeU( attrsU );
307 controlarrayfreeU( serverctrlsU );
308 controlarrayfreeU( clientctrlsU );
309 return ret;
312 /***********************************************************************
313 * ldap_search_sA (WLDAP32.@)
315 * See ldap_search_sW.
317 ULONG CDECL ldap_search_sA( LDAP *ld, char *base, ULONG scope, char *filter, char **attrs, ULONG attrsonly,
318 LDAPMessage **res )
320 ULONG ret = LDAP_NO_MEMORY;
321 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
323 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p)\n", ld, debugstr_a(base), scope, debugstr_a(filter), attrs,
324 attrsonly, res );
326 if (!ld || !res) return LDAP_PARAM_ERROR;
328 if (base && !(baseW = strAtoW( base ))) goto exit;
329 if (filter && !(filterW = strAtoW( filter ))) goto exit;
330 if (attrs && !(attrsW = strarrayAtoW( attrs ))) goto exit;
332 ret = ldap_search_sW( ld, baseW, scope, filterW, attrsW, attrsonly, res );
334 exit:
335 free( baseW );
336 free( filterW );
337 strarrayfreeW( attrsW );
338 return ret;
341 /***********************************************************************
342 * ldap_search_sW (WLDAP32.@)
344 * Search a directory tree (synchronous operation).
346 * PARAMS
347 * ld [I] Pointer to an LDAP context.
348 * base [I] Starting point for the search.
349 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
350 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
351 * filter [I] Search filter.
352 * attrs [I] Attributes to return.
353 * attrsonly [I] Return no values, only attributes.
354 * res [O] Results of the search operation.
356 * RETURNS
357 * Success: LDAP_SUCCESS
358 * Failure: An LDAP error code.
360 * NOTES
361 * Call ldap_msgfree to free the results.
363 ULONG CDECL ldap_search_sW( LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs, ULONG attrsonly,
364 LDAPMessage **res )
366 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p)\n", ld, debugstr_w(base), scope, debugstr_w(filter), attrs,
367 attrsonly, res );
368 return ldap_search_ext_sW( ld, base, scope, filter, attrs, attrsonly, NULL, NULL, NULL, 0, res );
371 /***********************************************************************
372 * ldap_search_stA (WLDAP32.@)
374 * See ldap_search_stW.
376 ULONG CDECL ldap_search_stA( LDAP *ld, const PCHAR base, ULONG scope, const PCHAR filter, char **attrs,
377 ULONG attrsonly, struct l_timeval *timeout, LDAPMessage **res )
379 ULONG ret = LDAP_NO_MEMORY;
380 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
382 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p, %p)\n", ld, debugstr_a(base), scope, debugstr_a(filter), attrs,
383 attrsonly, timeout, res );
385 if (!ld || !res) return LDAP_PARAM_ERROR;
387 if (base && !(baseW = strAtoW( base ))) goto exit;
388 if (filter && !(filterW = strAtoW( filter ))) goto exit;
389 if (attrs && !(attrsW = strarrayAtoW( attrs ))) goto exit;
391 ret = ldap_search_stW( ld, baseW, scope, filterW, attrsW, attrsonly, timeout, res );
393 exit:
394 free( baseW );
395 free( filterW );
396 strarrayfreeW( attrsW );
397 return ret;
400 /***********************************************************************
401 * ldap_search_stW (WLDAP32.@)
403 * Search a directory tree (synchronous operation).
405 * PARAMS
406 * ld [I] Pointer to an LDAP context.
407 * base [I] Starting point for the search.
408 * scope [I] Search scope. One of LDAP_SCOPE_BASE,
409 * LDAP_SCOPE_ONELEVEL and LDAP_SCOPE_SUBTREE.
410 * filter [I] Search filter.
411 * attrs [I] Attributes to return.
412 * attrsonly [I] Return no values, only attributes.
413 * timeout [I] Timeout in seconds.
414 * res [O] Results of the search operation.
416 * RETURNS
417 * Success: LDAP_SUCCESS
418 * Failure: An LDAP error code.
420 * NOTES
421 * Call ldap_msgfree to free the results.
423 ULONG CDECL ldap_search_stW( LDAP *ld, const PWCHAR base, ULONG scope, const PWCHAR filter, WCHAR **attrs,
424 ULONG attrsonly, struct l_timeval *timeout, LDAPMessage **res )
426 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p, %p)\n", ld, debugstr_w(base), scope, debugstr_w(filter), attrs,
427 attrsonly, timeout, res );
428 return ldap_search_ext_sW( ld, base, scope, filter, attrs, attrsonly, NULL, NULL, timeout, 0, res );