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
22 #include "wine/port.h"
33 #include "winldap_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
39 /***********************************************************************
40 * ldap_bindA (WLDAP32.@)
44 ULONG CDECL ldap_bindA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR cred, ULONG method )
46 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
48 WCHAR *dnW = NULL, *credW = NULL;
50 ret = WLDAP32_LDAP_NO_MEMORY;
52 TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_a(dn), cred, method );
61 credW = strAtoW( cred );
62 if (!credW) goto exit;
65 ret = ldap_bindW( ld, dnW, credW, method );
75 /***********************************************************************
76 * ldap_bindW (WLDAP32.@)
78 * Authenticate with an LDAP server (asynchronous operation).
81 * ld [I] Pointer to an LDAP context.
82 * dn [I] DN of entry to bind as.
83 * cred [I] Credentials (e.g. password string).
84 * method [I] Authentication method.
87 * Success: Message ID of the bind operation.
88 * Failure: An LDAP error code.
91 * Only LDAP_AUTH_SIMPLE is supported (just like native).
93 ULONG CDECL ldap_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
95 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
97 char *dnU = NULL, *credU = NULL;
98 struct berval pwd = { 0, NULL };
101 ret = WLDAP32_LDAP_NO_MEMORY;
103 TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_w(dn), cred, method );
106 if (method != LDAP_AUTH_SIMPLE) return WLDAP32_LDAP_PARAM_ERROR;
113 credU = strWtoU( cred );
114 if (!credU) goto exit;
116 pwd.bv_len = strlen( credU );
120 ret = ldap_sasl_bind( ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, &msg );
122 if (ret == LDAP_SUCCESS)
135 /***********************************************************************
136 * ldap_bind_sA (WLDAP32.@)
140 ULONG CDECL ldap_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR cred, ULONG method )
142 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
144 WCHAR *dnW = NULL, *credW = NULL;
146 ret = WLDAP32_LDAP_NO_MEMORY;
148 TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_a(dn), cred, method );
150 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
157 credW = strAtoW( cred );
158 if (!credW) goto exit;
161 ret = ldap_bind_sW( ld, dnW, credW, method );
171 /***********************************************************************
172 * ldap_bind_sW (WLDAP32.@)
174 * Authenticate with an LDAP server (synchronous operation).
177 * ld [I] Pointer to an LDAP context.
178 * dn [I] DN of entry to bind as.
179 * cred [I] Credentials (e.g. password string).
180 * method [I] Authentication method.
183 * Success: LDAP_SUCCESS
184 * Failure: An LDAP error code.
186 ULONG CDECL ldap_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
188 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
190 char *dnU = NULL, *credU = NULL;
191 struct berval pwd = { 0, NULL };
193 ret = WLDAP32_LDAP_NO_MEMORY;
195 TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_w(dn), cred, method );
197 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
198 if (method != LDAP_AUTH_SIMPLE) return WLDAP32_LDAP_PARAM_ERROR;
205 credU = strWtoU( cred );
206 if (!credU) goto exit;
208 pwd.bv_len = strlen( credU );
212 ret = map_error( ldap_sasl_bind_s( ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, NULL ));
222 /***********************************************************************
223 * ldap_sasl_bindA (WLDAP32.@)
225 * See ldap_sasl_bindW.
227 ULONG CDECL ldap_sasl_bindA( WLDAP32_LDAP *ld, const PCHAR dn,
228 const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
229 PLDAPControlA *clientctrls, int *message )
231 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
233 WCHAR *dnW, *mechanismW = NULL;
234 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
236 ret = WLDAP32_LDAP_NO_MEMORY;
238 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
239 debugstr_a(mechanism), cred, serverctrls, clientctrls, message );
241 if (!ld || !dn || !mechanism || !cred || !message)
242 return WLDAP32_LDAP_PARAM_ERROR;
247 mechanismW = strAtoW( mechanism );
248 if (!mechanismW) goto exit;
251 serverctrlsW = controlarrayAtoW( serverctrls );
252 if (!serverctrlsW) goto exit;
255 clientctrlsW = controlarrayAtoW( clientctrls );
256 if (!clientctrlsW) goto exit;
259 ret = ldap_sasl_bindW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, message );
263 strfreeW( mechanismW );
264 controlarrayfreeW( serverctrlsW );
265 controlarrayfreeW( clientctrlsW );
271 /***********************************************************************
272 * ldap_sasl_bindW (WLDAP32.@)
274 * Authenticate with an LDAP server using SASL (asynchronous operation).
277 * ld [I] Pointer to an LDAP context.
278 * dn [I] DN of entry to bind as.
279 * mechanism [I] Authentication method.
280 * cred [I] Credentials.
281 * serverctrls [I] Array of LDAP server controls.
282 * clientctrls [I] Array of LDAP client controls.
283 * message [O] Message ID of the bind operation.
286 * Success: LDAP_SUCCESS
287 * Failure: An LDAP error code.
290 * The serverctrls and clientctrls parameters are optional and should
291 * be set to NULL if not used.
293 ULONG CDECL ldap_sasl_bindW( WLDAP32_LDAP *ld, const PWCHAR dn,
294 const PWCHAR mechanism, const BERVAL *cred, PLDAPControlW *serverctrls,
295 PLDAPControlW *clientctrls, int *message )
297 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
299 char *dnU, *mechanismU = NULL;
300 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
303 ret = WLDAP32_LDAP_NO_MEMORY;
305 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
306 debugstr_w(mechanism), cred, serverctrls, clientctrls, message );
308 if (!ld || !dn || !mechanism || !cred || !message)
309 return WLDAP32_LDAP_PARAM_ERROR;
314 mechanismU = strWtoU( mechanism );
315 if (!mechanismU) goto exit;
318 serverctrlsU = controlarrayWtoU( serverctrls );
319 if (!serverctrlsU) goto exit;
322 clientctrlsU = controlarrayWtoU( clientctrls );
323 if (!clientctrlsU) goto exit;
326 credU.bv_len = cred->bv_len;
327 credU.bv_val = cred->bv_val;
329 ret = map_error( ldap_sasl_bind( ld, dnU, mechanismU, &credU,
330 serverctrlsU, clientctrlsU, message ));
334 strfreeU( mechanismU );
335 controlarrayfreeU( serverctrlsU );
336 controlarrayfreeU( clientctrlsU );
342 /***********************************************************************
343 * ldap_sasl_bind_sA (WLDAP32.@)
345 * See ldap_sasl_bind_sW.
347 ULONG CDECL ldap_sasl_bind_sA( WLDAP32_LDAP *ld, const PCHAR dn,
348 const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
349 PLDAPControlA *clientctrls, PBERVAL *serverdata )
351 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
353 WCHAR *dnW, *mechanismW = NULL;
354 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
356 ret = WLDAP32_LDAP_NO_MEMORY;
358 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
359 debugstr_a(mechanism), cred, serverctrls, clientctrls, serverdata );
361 if (!ld || !dn || !mechanism || !cred || !serverdata)
362 return WLDAP32_LDAP_PARAM_ERROR;
367 mechanismW = strAtoW( mechanism );
368 if (!mechanismW) goto exit;
371 serverctrlsW = controlarrayAtoW( serverctrls );
372 if (!serverctrlsW) goto exit;
375 clientctrlsW = controlarrayAtoW( clientctrls );
376 if (!clientctrlsW) goto exit;
379 ret = ldap_sasl_bind_sW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, serverdata );
383 strfreeW( mechanismW );
384 controlarrayfreeW( serverctrlsW );
385 controlarrayfreeW( clientctrlsW );
391 /***********************************************************************
392 * ldap_sasl_bind_sW (WLDAP32.@)
394 * Authenticate with an LDAP server using SASL (synchronous operation).
397 * ld [I] Pointer to an LDAP context.
398 * dn [I] DN of entry to bind as.
399 * mechanism [I] Authentication method.
400 * cred [I] Credentials.
401 * serverctrls [I] Array of LDAP server controls.
402 * clientctrls [I] Array of LDAP client controls.
403 * serverdata [O] Authentication response from the server.
406 * Success: LDAP_SUCCESS
407 * Failure: An LDAP error code.
410 * The serverctrls and clientctrls parameters are optional and should
411 * be set to NULL if not used.
413 ULONG CDECL ldap_sasl_bind_sW( WLDAP32_LDAP *ld, const PWCHAR dn,
414 const PWCHAR mechanism, const BERVAL *cred, PLDAPControlW *serverctrls,
415 PLDAPControlW *clientctrls, PBERVAL *serverdata )
417 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
419 char *dnU, *mechanismU = NULL;
420 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
423 ret = WLDAP32_LDAP_NO_MEMORY;
425 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
426 debugstr_w(mechanism), cred, serverctrls, clientctrls, serverdata );
428 if (!ld || !dn || !mechanism || !cred || !serverdata)
429 return WLDAP32_LDAP_PARAM_ERROR;
434 mechanismU = strWtoU( mechanism );
435 if (!mechanismU) goto exit;
438 serverctrlsU = controlarrayWtoU( serverctrls );
439 if (!serverctrlsU) goto exit;
442 clientctrlsU = controlarrayWtoU( clientctrls );
443 if (!clientctrlsU) goto exit;
446 credU.bv_len = cred->bv_len;
447 credU.bv_val = cred->bv_val;
449 ret = map_error( ldap_sasl_bind_s( ld, dnU, mechanismU, &credU,
450 serverctrlsU, clientctrlsU, (struct berval **)serverdata ));
454 strfreeU( mechanismU );
455 controlarrayfreeU( serverctrlsU );
456 controlarrayfreeU( clientctrlsU );
462 /***********************************************************************
463 * ldap_simple_bindA (WLDAP32.@)
465 * See ldap_simple_bindW.
467 ULONG CDECL ldap_simple_bindA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
469 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
471 WCHAR *dnW = NULL, *passwdW = NULL;
473 ret = WLDAP32_LDAP_NO_MEMORY;
475 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
484 passwdW = strAtoW( passwd );
485 if (!passwdW) goto exit;
488 ret = ldap_simple_bindW( ld, dnW, passwdW );
498 /***********************************************************************
499 * ldap_simple_bindW (WLDAP32.@)
501 * Authenticate with an LDAP server (asynchronous operation).
504 * ld [I] Pointer to an LDAP context.
505 * dn [I] DN of entry to bind as.
506 * passwd [I] Password string.
509 * Success: Message ID of the bind operation.
510 * Failure: An LDAP error code.
513 * Set dn and passwd to NULL to bind as an anonymous user.
515 ULONG CDECL ldap_simple_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
517 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
519 char *dnU = NULL, *passwdU = NULL;
520 struct berval pwd = { 0, NULL };
523 ret = WLDAP32_LDAP_NO_MEMORY;
525 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), passwd );
534 passwdU = strWtoU( passwd );
535 if (!passwdU) goto exit;
537 pwd.bv_len = strlen( passwdU );
538 pwd.bv_val = passwdU;
541 ret = ldap_sasl_bind( ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, &msg );
543 if (ret == LDAP_SUCCESS)
556 /***********************************************************************
557 * ldap_simple_bind_sA (WLDAP32.@)
559 * See ldap_simple_bind_sW.
561 ULONG CDECL ldap_simple_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
563 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
565 WCHAR *dnW = NULL, *passwdW = NULL;
567 ret = WLDAP32_LDAP_NO_MEMORY;
569 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
571 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
578 passwdW = strAtoW( passwd );
579 if (!passwdW) goto exit;
582 ret = ldap_simple_bind_sW( ld, dnW, passwdW );
592 /***********************************************************************
593 * ldap_simple_bind_sW (WLDAP32.@)
595 * Authenticate with an LDAP server (synchronous operation).
598 * ld [I] Pointer to an LDAP context.
599 * dn [I] DN of entry to bind as.
600 * passwd [I] Password string.
603 * Success: LDAP_SUCCESS
604 * Failure: An LDAP error code.
607 * Set dn and passwd to NULL to bind as an anonymous user.
609 ULONG CDECL ldap_simple_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
611 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
613 char *dnU = NULL, *passwdU = NULL;
614 struct berval pwd = { 0, NULL };
616 ret = WLDAP32_LDAP_NO_MEMORY;
618 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), passwd );
620 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
627 passwdU = strWtoU( passwd );
628 if (!passwdU) goto exit;
630 pwd.bv_len = strlen( passwdU );
631 pwd.bv_val = passwdU;
634 ret = map_error( ldap_sasl_bind_s( ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, NULL ));
644 /***********************************************************************
645 * ldap_unbind (WLDAP32.@)
647 * Close LDAP connection and free resources (asynchronous operation).
650 * ld [I] Pointer to an LDAP context.
653 * Success: LDAP_SUCCESS
654 * Failure: An LDAP error code.
656 ULONG CDECL WLDAP32_ldap_unbind( WLDAP32_LDAP *ld )
658 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
661 TRACE( "(%p)\n", ld );
664 ret = map_error( ldap_unbind_ext( ld, NULL, NULL ));
666 ret = WLDAP32_LDAP_PARAM_ERROR;
672 /***********************************************************************
673 * ldap_unbind_s (WLDAP32.@)
675 * Close LDAP connection and free resources (synchronous operation).
678 * ld [I] Pointer to an LDAP context.
681 * Success: LDAP_SUCCESS
682 * Failure: An LDAP error code.
684 ULONG CDECL WLDAP32_ldap_unbind_s( WLDAP32_LDAP *ld )
686 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
689 TRACE( "(%p)\n", ld );
692 ret = map_error( ldap_unbind_ext_s( ld, NULL, NULL ));
694 ret = WLDAP32_LDAP_PARAM_ERROR;