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
28 #include "wine/debug.h"
29 #include "winldap_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
33 /***********************************************************************
34 * ldap_searchA (WLDAP32.@)
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
);
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
);
56 strarrayfreeW( attrsW
);
60 /***********************************************************************
61 * ldap_searchW (WLDAP32.@)
63 * Search a directory tree (asynchronous operation).
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.
75 * Success: Message ID of the search operation.
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
)
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
;
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
);
122 strarrayfreeW( attrsW
);
123 controlarrayfreeW( serverctrlsW
);
124 controlarrayfreeW( clientctrlsW
);
128 /***********************************************************************
129 * ldap_search_extW (WLDAP32.@)
131 * Search a directory tree (asynchronous operation).
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.
148 * Success: LDAP_SUCCESS
149 * Failure: An LDAP error code.
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
,
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
);
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
) );
184 strarrayfreeU( attrsU
);
185 controlarrayfreeU( serverctrlsU
);
186 controlarrayfreeU( clientctrlsU
);
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
,
220 strarrayfreeW( attrsW
);
221 controlarrayfreeW( serverctrlsW
);
222 controlarrayfreeW( clientctrlsW
);
226 /***********************************************************************
227 * ldap_search_ext_sW (WLDAP32.@)
229 * Search a directory tree (synchronous operation).
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.
246 * Success: LDAP_SUCCESS
247 * Failure: An LDAP error code.
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
;
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
;
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
) );
283 LDAPMessage
*msg
= calloc( 1, sizeof(*msg
) );
291 ldap_funcs
->fn_ldap_msgfree( msgU
);
292 ret
= LDAP_NO_MEMORY
;
299 strarrayfreeU( attrsU
);
300 controlarrayfreeU( serverctrlsU
);
301 controlarrayfreeU( clientctrlsU
);
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
,
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
,
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
);
330 strarrayfreeW( attrsW
);
334 /***********************************************************************
335 * ldap_search_sW (WLDAP32.@)
337 * Search a directory tree (synchronous operation).
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.
350 * Success: LDAP_SUCCESS
351 * Failure: An LDAP error code.
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
,
359 TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p)\n", ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
,
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
);
389 strarrayfreeW( attrsW
);
393 /***********************************************************************
394 * ldap_search_stW (WLDAP32.@)
396 * Search a directory tree (synchronous operation).
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.
410 * Success: LDAP_SUCCESS
411 * Failure: An LDAP error code.
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
);