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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
24 #include "wine/debug.h"
35 #define LDAP_SUCCESS 0x00
36 #define LDAP_NOT_SUPPORTED 0x5c
39 #include "winldap_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
44 ULONG ldap_searchA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope, PCHAR filter,
45 PCHAR attrs[], ULONG attrsonly )
47 ULONG ret = LDAP_NOT_SUPPORTED;
49 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
52 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_a(base),
53 scope, debugstr_a(filter), attrs, attrsonly );
58 baseW = strAtoW( base );
59 if (!baseW) goto exit;
62 filterW = strAtoW( filter );
63 if (!filterW) goto exit;
66 attrsW = strarrayAtoW( attrs );
67 if (!attrsW) goto exit;
70 ret = ldap_searchW( ld, baseW, scope, filterW, attrsW, attrsonly );
75 strarrayfreeW( attrsW );
81 ULONG ldap_searchW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
82 PWCHAR attrs[], ULONG attrsonly )
84 ULONG ret = LDAP_NOT_SUPPORTED;
86 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
89 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_w(base),
90 scope, debugstr_w(filter), attrs, attrsonly );
95 baseU = strWtoU( base );
96 if (!baseU) goto exit;
99 filterU = strWtoU( filter );
100 if (!filterU) goto exit;
103 attrsU = strarrayWtoU( attrs );
104 if (!attrsU) goto exit;
107 ret = ldap_search( ld, baseU, scope, filterU, attrsU, attrsonly );
112 strarrayfreeU( attrsU );
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 )
122 ULONG ret = LDAP_NOT_SUPPORTED;
124 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
125 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
126 ret = LDAP_NO_MEMORY;
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 );
132 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
135 baseW = strAtoW( base );
136 if (!baseW) goto exit;
140 filterW = strAtoW( filter );
141 if (!filterW) goto exit;
144 attrsW = strarrayAtoW( attrs );
145 if (!attrsW) goto exit;
148 serverctrlsW = controlarrayAtoW( serverctrls );
149 if (!serverctrlsW) goto exit;
152 clientctrlsW = controlarrayAtoW( clientctrls );
153 if (!clientctrlsW) goto exit;
156 ret = ldap_search_extW( ld, baseW, scope, filterW, attrsW, attrsonly,
157 serverctrlsW, clientctrlsW, timelimit, sizelimit, message );
162 strarrayfreeW( attrsW );
163 controlarrayfreeW( serverctrlsW );
164 controlarrayfreeW( clientctrlsW );
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 )
174 ULONG ret = LDAP_NOT_SUPPORTED;
176 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
177 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
180 ret = LDAP_NO_MEMORY;
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 );
186 if (!ld) return ~0UL;
189 baseU = strWtoU( base );
190 if (!baseU) goto exit;
193 filterU = strWtoU( filter );
194 if (!filterU) goto exit;
197 attrsU = strarrayWtoU( attrs );
198 if (!attrsU) goto exit;
201 serverctrlsU = controlarrayWtoU( serverctrls );
202 if (!serverctrlsU) goto exit;
205 clientctrlsU = controlarrayWtoU( clientctrls );
206 if (!clientctrlsU) goto exit;
209 tv.tv_sec = timelimit;
212 ret = ldap_search_ext( ld, baseU, scope, filterU, attrsU, attrsonly,
213 serverctrlsU, clientctrlsU, &tv, sizelimit, (int *)message );
218 strarrayfreeU( attrsU );
219 controlarrayfreeU( serverctrlsU );
220 controlarrayfreeU( clientctrlsU );
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 )
230 ULONG ret = LDAP_NOT_SUPPORTED;
232 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
233 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
234 ret = LDAP_NO_MEMORY;
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 );
240 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
243 baseW = strAtoW( base );
244 if (!baseW) goto exit;
247 filterW = strAtoW( filter );
248 if (!filterW) goto exit;
251 attrsW = strarrayAtoW( attrs );
252 if (!attrsW) goto exit;
255 serverctrlsW = controlarrayAtoW( serverctrls );
256 if (!serverctrlsW) goto exit;
259 clientctrlsW = controlarrayAtoW( clientctrls );
260 if (!clientctrlsW) goto exit;
263 ret = ldap_search_ext_sW( ld, baseW, scope, filterW, attrsW, attrsonly,
264 serverctrlsW, clientctrlsW, timeout, sizelimit, res );
269 strarrayfreeW( attrsW );
270 controlarrayfreeW( serverctrlsW );
271 controlarrayfreeW( clientctrlsW );
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 )
281 ULONG ret = LDAP_NOT_SUPPORTED;
283 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
284 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
285 ret = LDAP_NO_MEMORY;
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 );
291 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
294 baseU = strWtoU( base );
295 if (!baseU) goto exit;
298 filterU = strWtoU( filter );
299 if (!filterU) goto exit;
302 attrsU = strarrayWtoU( attrs );
303 if (!attrsU) goto exit;
306 serverctrlsU = controlarrayWtoU( serverctrls );
307 if (!serverctrlsU) goto exit;
310 clientctrlsU = controlarrayWtoU( clientctrls );
311 if (!clientctrlsU) goto exit;
314 ret = ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
315 serverctrlsU, clientctrlsU, (struct timeval *)timeout, sizelimit, res );
320 strarrayfreeU( attrsU );
321 controlarrayfreeU( serverctrlsU );
322 controlarrayfreeU( clientctrlsU );
328 ULONG ldap_search_sA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope, PCHAR filter,
329 PCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
331 ULONG ret = LDAP_NOT_SUPPORTED;
333 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
334 ret = LDAP_NO_MEMORY;
336 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld, debugstr_a(base),
337 scope, debugstr_a(filter), attrs, attrsonly, res );
339 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
342 baseW = strAtoW( base );
343 if (!baseW) goto exit;
346 filterW = strAtoW( filter );
347 if (!filterW) goto exit;
350 attrsW = strarrayAtoW( attrs );
351 if (!attrsW) goto exit;
354 ret = ldap_search_sW( ld, baseW, scope, filterW, attrsW, attrsonly, res );
359 strarrayfreeW( attrsW );
365 ULONG ldap_search_sW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
366 PWCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
368 ULONG ret = LDAP_NOT_SUPPORTED;
370 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
371 ret = LDAP_NO_MEMORY;
373 TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld, debugstr_w(base),
374 scope, debugstr_w(filter), attrs, attrsonly, res );
376 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
379 baseU = strWtoU( base );
380 if (!baseU) goto exit;
383 filterU = strWtoU( filter );
384 if (!filterU) goto exit;
387 attrsU = strarrayWtoU( attrs );
388 if (!attrsU) goto exit;
391 ret = ldap_search_s( ld, baseU, scope, filterU, attrsU, attrsonly, res );
396 strarrayfreeU( attrsU );
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 )
406 ULONG ret = LDAP_NOT_SUPPORTED;
408 WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
409 ret = LDAP_NO_MEMORY;
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 );
415 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
418 baseW = strAtoW( base );
419 if (!baseW) goto exit;
422 filterW = strAtoW( filter );
423 if (!filterW) goto exit;
426 attrsW = strarrayAtoW( attrs );
427 if (!attrsW) goto exit;
430 ret = ldap_search_stW( ld, baseW, scope, filterW, attrsW, attrsonly,
436 strarrayfreeW( attrsW );
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 )
446 ULONG ret = LDAP_NOT_SUPPORTED;
448 char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
449 ret = LDAP_NO_MEMORY;
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 );
455 if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
458 baseU = strWtoU( base );
459 if (!baseU) goto exit;
462 filterU = strWtoU( filter );
463 if (!filterU) goto exit;
466 attrsU = strarrayWtoU( attrs );
467 if (!attrsU) goto exit;
470 ret = ldap_search_st( ld, baseU, scope, filterU, attrsU, attrsonly,
471 (struct timeval *)timeout, res );
476 strarrayfreeU( attrsU );