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, %#lx, %s, %p, %#lx)\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, %#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
;
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
);
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, %#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
);
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
, ¶ms
));
187 strarrayfreeU( attrsU
);
188 controlarrayfreeU( serverctrlsU
);
189 controlarrayfreeU( clientctrlsU
);
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
,
223 strarrayfreeW( attrsW
);
224 controlarrayfreeW( serverctrlsW
);
225 controlarrayfreeW( clientctrlsW
);
229 /***********************************************************************
230 * ldap_search_ext_sW (WLDAP32.@)
232 * Search a directory tree (synchronous operation).
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.
249 * Success: LDAP_SUCCESS
250 * Failure: An LDAP error code.
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
;
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
;
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
, ¶ms
));
290 LDAPMessage
*msg
= calloc( 1, sizeof(*msg
) );
298 LDAP_CALL( ldap_msgfree
, msgU
);
299 ret
= LDAP_NO_MEMORY
;
306 strarrayfreeU( attrsU
);
307 controlarrayfreeU( serverctrlsU
);
308 controlarrayfreeU( clientctrlsU
);
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
,
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
,
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
);
337 strarrayfreeW( attrsW
);
341 /***********************************************************************
342 * ldap_search_sW (WLDAP32.@)
344 * Search a directory tree (synchronous operation).
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.
357 * Success: LDAP_SUCCESS
358 * Failure: An LDAP error code.
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
,
366 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p)\n", ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
,
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
);
396 strarrayfreeW( attrsW
);
400 /***********************************************************************
401 * ldap_search_stW (WLDAP32.@)
403 * Search a directory tree (synchronous operation).
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.
417 * Success: LDAP_SUCCESS
418 * Failure: An LDAP error code.
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
);