winex11.drv: Support multiple adapter display settings in registry.
[wine.git] / dlls / wldap32 / bind.c
blob1498dc49fe6edb319ebad95682ae1b1389fcf309
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 "config.h"
22 #include "wine/port.h"
24 #include <stdarg.h>
25 #ifdef HAVE_LDAP_H
26 #include <ldap.h>
27 #endif
28 #ifdef HAVE_SASL_SASL_H
29 #include <sasl/sasl.h>
30 #endif
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winnls.h"
35 #include "rpc.h"
37 #include "winldap_private.h"
38 #include "wldap32.h"
39 #include "wine/debug.h"
41 #ifdef HAVE_LDAP
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
43 #endif
45 /***********************************************************************
46 * ldap_bindA (WLDAP32.@)
48 * See ldap_bindW.
50 ULONG CDECL ldap_bindA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR cred, ULONG method )
52 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
53 #ifdef HAVE_LDAP
54 WCHAR *dnW = NULL, *credW = NULL;
56 ret = WLDAP32_LDAP_NO_MEMORY;
58 TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_a(dn), cred, method );
60 if (!ld) return ~0u;
62 if (dn) {
63 dnW = strAtoW( dn );
64 if (!dnW) goto exit;
66 if (cred) {
67 credW = strAtoW( cred );
68 if (!credW) goto exit;
71 ret = ldap_bindW( ld, dnW, credW, method );
73 exit:
74 strfreeW( dnW );
75 strfreeW( credW );
77 #endif
78 return ret;
81 /***********************************************************************
82 * ldap_bindW (WLDAP32.@)
84 * Authenticate with an LDAP server (asynchronous operation).
86 * PARAMS
87 * ld [I] Pointer to an LDAP context.
88 * dn [I] DN of entry to bind as.
89 * cred [I] Credentials (e.g. password string).
90 * method [I] Authentication method.
92 * RETURNS
93 * Success: Message ID of the bind operation.
94 * Failure: An LDAP error code.
96 * NOTES
97 * Only LDAP_AUTH_SIMPLE is supported (just like native).
99 ULONG CDECL ldap_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
101 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
102 #ifdef HAVE_LDAP
103 char *dnU = NULL, *credU = NULL;
104 struct berval pwd = { 0, NULL };
105 int msg;
107 ret = WLDAP32_LDAP_NO_MEMORY;
109 TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_w(dn), cred, method );
111 if (!ld) return ~0u;
112 if (method != LDAP_AUTH_SIMPLE) return WLDAP32_LDAP_PARAM_ERROR;
114 if (dn) {
115 dnU = strWtoU( dn );
116 if (!dnU) goto exit;
118 if (cred) {
119 credU = strWtoU( cred );
120 if (!credU) goto exit;
122 pwd.bv_len = strlen( credU );
123 pwd.bv_val = credU;
126 ret = ldap_sasl_bind( ld->ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, &msg );
128 if (ret == LDAP_SUCCESS)
129 ret = msg;
130 else
131 ret = ~0u;
133 exit:
134 strfreeU( dnU );
135 strfreeU( credU );
137 #endif
138 return ret;
141 /***********************************************************************
142 * ldap_bind_sA (WLDAP32.@)
144 * See ldap_bind_sW.
146 ULONG CDECL ldap_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR cred, ULONG method )
148 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
149 #ifdef HAVE_LDAP
150 WCHAR *dnW = NULL, *credW = NULL;
152 ret = WLDAP32_LDAP_NO_MEMORY;
154 TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_a(dn), cred, method );
156 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
158 if (dn) {
159 dnW = strAtoW( dn );
160 if (!dnW) goto exit;
162 if (cred) {
163 if (method == LDAP_AUTH_SIMPLE)
165 credW = strAtoW( cred );
166 if (!credW) goto exit;
168 else
169 credW = (WCHAR *)cred /* SEC_WINNT_AUTH_IDENTITY_A */;
172 ret = ldap_bind_sW( ld, dnW, credW, method );
174 exit:
175 strfreeW( dnW );
176 if (credW != (WCHAR *)cred) strfreeW( credW );
178 #endif
179 return ret;
182 #ifdef HAVE_LDAP
184 static int sasl_interact( LDAP *ld, unsigned flags, void *defaults, void *interact )
186 #ifdef HAVE_SASL_SASL_H
187 SEC_WINNT_AUTH_IDENTITY_A *id = defaults;
188 sasl_interact_t *sasl = interact;
190 TRACE( "%p,%08x,%p,%p\n", ld, flags, defaults, interact );
192 while (sasl->id != SASL_CB_LIST_END)
194 TRACE("sasl->id = %04lx\n", sasl->id);
196 if (sasl->id == SASL_CB_GETREALM)
198 sasl->result = id->Domain;
199 sasl->len = id->DomainLength;
201 else if (sasl->id == SASL_CB_USER)
203 sasl->result = id->User;
204 sasl->len = id->UserLength;
206 else if (sasl->id == SASL_CB_PASS)
208 sasl->result = id->Password;
209 sasl->len = id->PasswordLength;
212 sasl++;
215 return LDAP_SUCCESS;
216 #else
217 FIXME( "%p,%08x,%p,%p: stub\n", ld, flags, defaults, interact );
218 return LDAP_SUCCESS;
219 #endif /* HAVE_SASL_SASL_H */
222 #endif /* HAVE_LDAP */
224 /***********************************************************************
225 * ldap_bind_sW (WLDAP32.@)
227 * Authenticate with an LDAP server (synchronous operation).
229 * PARAMS
230 * ld [I] Pointer to an LDAP context.
231 * dn [I] DN of entry to bind as.
232 * cred [I] Credentials (e.g. password string).
233 * method [I] Authentication method.
235 * RETURNS
236 * Success: LDAP_SUCCESS
237 * Failure: An LDAP error code.
239 ULONG CDECL ldap_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
241 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
242 #ifdef HAVE_LDAP
243 char *dnU = NULL, *credU = NULL;
244 struct berval pwd = { 0, NULL };
246 ret = WLDAP32_LDAP_NO_MEMORY;
248 TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_w(dn), cred, method );
250 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
252 if (method == LDAP_AUTH_SIMPLE)
254 if (dn)
256 dnU = strWtoU( dn );
257 if (!dnU) goto exit;
259 if (cred)
261 credU = strWtoU( cred );
262 if (!credU) goto exit;
264 pwd.bv_len = strlen( credU );
265 pwd.bv_val = credU;
268 ret = map_error( ldap_sasl_bind_s( ld->ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, NULL ));
270 else if (method == WLDAP32_LDAP_AUTH_NEGOTIATE)
272 SEC_WINNT_AUTH_IDENTITY_A idU;
273 SEC_WINNT_AUTH_IDENTITY_W idW;
274 SEC_WINNT_AUTH_IDENTITY_W *id = (SEC_WINNT_AUTH_IDENTITY_W *)cred;
276 memset( &idU, 0, sizeof(idU) );
278 if (id)
280 if (id->Flags & SEC_WINNT_AUTH_IDENTITY_ANSI)
282 idW.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
283 idW.Domain = (unsigned short *)strnAtoW( (char *)id->Domain, id->DomainLength, &idW.DomainLength );
284 idW.User = (unsigned short *)strnAtoW( (char *)id->User, id->UserLength, &idW.UserLength );
285 idW.Password = (unsigned short *)strnAtoW( (char *)id->Password, id->PasswordLength, &idW.PasswordLength );
287 id = &idW;
290 idU.Domain = (unsigned char *)strnWtoU( id->Domain, id->DomainLength, &idU.DomainLength );
291 idU.User = (unsigned char *)strnWtoU( id->User, id->UserLength, &idU.UserLength );
292 idU.Password = (unsigned char *)strnWtoU( id->Password, id->PasswordLength, &idU.PasswordLength );
295 ret = map_error( ldap_sasl_interactive_bind_s( ld->ld,
296 NULL /* server will ignore DN anyway */,
297 NULL /* query supportedSASLMechanisms */,
298 NULL, NULL, LDAP_SASL_QUIET, sasl_interact, &idU ));
300 if (id && (id->Flags & SEC_WINNT_AUTH_IDENTITY_ANSI))
302 strfreeW( (WCHAR *)idW.Domain );
303 strfreeW( (WCHAR *)idW.User );
304 strfreeW( (WCHAR *)idW.Password );
307 strfreeU( (char *)idU.Domain );
308 strfreeU( (char *)idU.User );
309 strfreeU( (char *)idU.Password );
311 else
313 FIXME( "method %#x not supported\n", method );
314 return WLDAP32_LDAP_PARAM_ERROR;
317 exit:
318 strfreeU( dnU );
319 strfreeU( credU );
321 #endif
322 return ret;
325 /***********************************************************************
326 * ldap_sasl_bindA (WLDAP32.@)
328 * See ldap_sasl_bindW.
330 ULONG CDECL ldap_sasl_bindA( WLDAP32_LDAP *ld, const PCHAR dn,
331 const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
332 PLDAPControlA *clientctrls, int *message )
334 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
335 #ifdef HAVE_LDAP
336 WCHAR *dnW, *mechanismW = NULL;
337 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
339 ret = WLDAP32_LDAP_NO_MEMORY;
341 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
342 debugstr_a(mechanism), cred, serverctrls, clientctrls, message );
344 if (!ld || !dn || !mechanism || !cred || !message)
345 return WLDAP32_LDAP_PARAM_ERROR;
347 dnW = strAtoW( dn );
348 if (!dnW) goto exit;
350 mechanismW = strAtoW( mechanism );
351 if (!mechanismW) goto exit;
353 if (serverctrls) {
354 serverctrlsW = controlarrayAtoW( serverctrls );
355 if (!serverctrlsW) goto exit;
357 if (clientctrls) {
358 clientctrlsW = controlarrayAtoW( clientctrls );
359 if (!clientctrlsW) goto exit;
362 ret = ldap_sasl_bindW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, message );
364 exit:
365 strfreeW( dnW );
366 strfreeW( mechanismW );
367 controlarrayfreeW( serverctrlsW );
368 controlarrayfreeW( clientctrlsW );
370 #endif
371 return ret;
374 /***********************************************************************
375 * ldap_sasl_bindW (WLDAP32.@)
377 * Authenticate with an LDAP server using SASL (asynchronous operation).
379 * PARAMS
380 * ld [I] Pointer to an LDAP context.
381 * dn [I] DN of entry to bind as.
382 * mechanism [I] Authentication method.
383 * cred [I] Credentials.
384 * serverctrls [I] Array of LDAP server controls.
385 * clientctrls [I] Array of LDAP client controls.
386 * message [O] Message ID of the bind operation.
388 * RETURNS
389 * Success: LDAP_SUCCESS
390 * Failure: An LDAP error code.
392 * NOTES
393 * The serverctrls and clientctrls parameters are optional and should
394 * be set to NULL if not used.
396 ULONG CDECL ldap_sasl_bindW( WLDAP32_LDAP *ld, const PWCHAR dn,
397 const PWCHAR mechanism, const BERVAL *cred, PLDAPControlW *serverctrls,
398 PLDAPControlW *clientctrls, int *message )
400 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
401 #ifdef HAVE_LDAP
402 char *dnU, *mechanismU = NULL;
403 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
404 struct berval credU;
406 ret = WLDAP32_LDAP_NO_MEMORY;
408 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
409 debugstr_w(mechanism), cred, serverctrls, clientctrls, message );
411 if (!ld || !dn || !mechanism || !cred || !message)
412 return WLDAP32_LDAP_PARAM_ERROR;
414 dnU = strWtoU( dn );
415 if (!dnU) goto exit;
417 mechanismU = strWtoU( mechanism );
418 if (!mechanismU) goto exit;
420 if (serverctrls) {
421 serverctrlsU = controlarrayWtoU( serverctrls );
422 if (!serverctrlsU) goto exit;
424 if (clientctrls) {
425 clientctrlsU = controlarrayWtoU( clientctrls );
426 if (!clientctrlsU) goto exit;
429 credU.bv_len = cred->bv_len;
430 credU.bv_val = cred->bv_val;
432 ret = map_error( ldap_sasl_bind( ld->ld, dnU, mechanismU, &credU,
433 serverctrlsU, clientctrlsU, message ));
435 exit:
436 strfreeU( dnU );
437 strfreeU( mechanismU );
438 controlarrayfreeU( serverctrlsU );
439 controlarrayfreeU( clientctrlsU );
441 #endif
442 return ret;
445 /***********************************************************************
446 * ldap_sasl_bind_sA (WLDAP32.@)
448 * See ldap_sasl_bind_sW.
450 ULONG CDECL ldap_sasl_bind_sA( WLDAP32_LDAP *ld, const PCHAR dn,
451 const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
452 PLDAPControlA *clientctrls, PBERVAL *serverdata )
454 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
455 #ifdef HAVE_LDAP
456 WCHAR *dnW, *mechanismW = NULL;
457 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
459 ret = WLDAP32_LDAP_NO_MEMORY;
461 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
462 debugstr_a(mechanism), cred, serverctrls, clientctrls, serverdata );
464 if (!ld || !dn || !mechanism || !cred || !serverdata)
465 return WLDAP32_LDAP_PARAM_ERROR;
467 dnW = strAtoW( dn );
468 if (!dnW) goto exit;
470 mechanismW = strAtoW( mechanism );
471 if (!mechanismW) goto exit;
473 if (serverctrls) {
474 serverctrlsW = controlarrayAtoW( serverctrls );
475 if (!serverctrlsW) goto exit;
477 if (clientctrls) {
478 clientctrlsW = controlarrayAtoW( clientctrls );
479 if (!clientctrlsW) goto exit;
482 ret = ldap_sasl_bind_sW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, serverdata );
484 exit:
485 strfreeW( dnW );
486 strfreeW( mechanismW );
487 controlarrayfreeW( serverctrlsW );
488 controlarrayfreeW( clientctrlsW );
490 #endif
491 return ret;
494 /***********************************************************************
495 * ldap_sasl_bind_sW (WLDAP32.@)
497 * Authenticate with an LDAP server using SASL (synchronous operation).
499 * PARAMS
500 * ld [I] Pointer to an LDAP context.
501 * dn [I] DN of entry to bind as.
502 * mechanism [I] Authentication method.
503 * cred [I] Credentials.
504 * serverctrls [I] Array of LDAP server controls.
505 * clientctrls [I] Array of LDAP client controls.
506 * serverdata [O] Authentication response from the server.
508 * RETURNS
509 * Success: LDAP_SUCCESS
510 * Failure: An LDAP error code.
512 * NOTES
513 * The serverctrls and clientctrls parameters are optional and should
514 * be set to NULL if not used.
516 ULONG CDECL ldap_sasl_bind_sW( WLDAP32_LDAP *ld, const PWCHAR dn,
517 const PWCHAR mechanism, const BERVAL *cred, PLDAPControlW *serverctrls,
518 PLDAPControlW *clientctrls, PBERVAL *serverdata )
520 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
521 #ifdef HAVE_LDAP
522 char *dnU, *mechanismU = NULL;
523 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
524 struct berval credU;
526 ret = WLDAP32_LDAP_NO_MEMORY;
528 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
529 debugstr_w(mechanism), cred, serverctrls, clientctrls, serverdata );
531 if (!ld || !dn || !mechanism || !cred || !serverdata)
532 return WLDAP32_LDAP_PARAM_ERROR;
534 dnU = strWtoU( dn );
535 if (!dnU) goto exit;
537 mechanismU = strWtoU( mechanism );
538 if (!mechanismU) goto exit;
540 if (serverctrls) {
541 serverctrlsU = controlarrayWtoU( serverctrls );
542 if (!serverctrlsU) goto exit;
544 if (clientctrls) {
545 clientctrlsU = controlarrayWtoU( clientctrls );
546 if (!clientctrlsU) goto exit;
549 credU.bv_len = cred->bv_len;
550 credU.bv_val = cred->bv_val;
552 ret = map_error( ldap_sasl_bind_s( ld->ld, dnU, mechanismU, &credU,
553 serverctrlsU, clientctrlsU, (struct berval **)serverdata ));
555 exit:
556 strfreeU( dnU );
557 strfreeU( mechanismU );
558 controlarrayfreeU( serverctrlsU );
559 controlarrayfreeU( clientctrlsU );
561 #endif
562 return ret;
565 /***********************************************************************
566 * ldap_simple_bindA (WLDAP32.@)
568 * See ldap_simple_bindW.
570 ULONG CDECL ldap_simple_bindA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
572 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
573 #ifdef HAVE_LDAP
574 WCHAR *dnW = NULL, *passwdW = NULL;
576 ret = WLDAP32_LDAP_NO_MEMORY;
578 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
580 if (!ld) return ~0u;
582 if (dn) {
583 dnW = strAtoW( dn );
584 if (!dnW) goto exit;
586 if (passwd) {
587 passwdW = strAtoW( passwd );
588 if (!passwdW) goto exit;
591 ret = ldap_simple_bindW( ld, dnW, passwdW );
593 exit:
594 strfreeW( dnW );
595 strfreeW( passwdW );
597 #endif
598 return ret;
601 /***********************************************************************
602 * ldap_simple_bindW (WLDAP32.@)
604 * Authenticate with an LDAP server (asynchronous operation).
606 * PARAMS
607 * ld [I] Pointer to an LDAP context.
608 * dn [I] DN of entry to bind as.
609 * passwd [I] Password string.
611 * RETURNS
612 * Success: Message ID of the bind operation.
613 * Failure: An LDAP error code.
615 * NOTES
616 * Set dn and passwd to NULL to bind as an anonymous user.
618 ULONG CDECL ldap_simple_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
620 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
621 #ifdef HAVE_LDAP
622 char *dnU = NULL, *passwdU = NULL;
623 struct berval pwd = { 0, NULL };
624 int msg;
626 ret = WLDAP32_LDAP_NO_MEMORY;
628 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), passwd );
630 if (!ld) return ~0u;
632 if (dn) {
633 dnU = strWtoU( dn );
634 if (!dnU) goto exit;
636 if (passwd) {
637 passwdU = strWtoU( passwd );
638 if (!passwdU) goto exit;
640 pwd.bv_len = strlen( passwdU );
641 pwd.bv_val = passwdU;
644 ret = ldap_sasl_bind( ld->ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, &msg );
646 if (ret == LDAP_SUCCESS)
647 ret = msg;
648 else
649 ret = ~0u;
651 exit:
652 strfreeU( dnU );
653 strfreeU( passwdU );
655 #endif
656 return ret;
659 /***********************************************************************
660 * ldap_simple_bind_sA (WLDAP32.@)
662 * See ldap_simple_bind_sW.
664 ULONG CDECL ldap_simple_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
666 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
667 #ifdef HAVE_LDAP
668 WCHAR *dnW = NULL, *passwdW = NULL;
670 ret = WLDAP32_LDAP_NO_MEMORY;
672 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
674 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
676 if (dn) {
677 dnW = strAtoW( dn );
678 if (!dnW) goto exit;
680 if (passwd) {
681 passwdW = strAtoW( passwd );
682 if (!passwdW) goto exit;
685 ret = ldap_simple_bind_sW( ld, dnW, passwdW );
687 exit:
688 strfreeW( dnW );
689 strfreeW( passwdW );
691 #endif
692 return ret;
695 /***********************************************************************
696 * ldap_simple_bind_sW (WLDAP32.@)
698 * Authenticate with an LDAP server (synchronous operation).
700 * PARAMS
701 * ld [I] Pointer to an LDAP context.
702 * dn [I] DN of entry to bind as.
703 * passwd [I] Password string.
705 * RETURNS
706 * Success: LDAP_SUCCESS
707 * Failure: An LDAP error code.
709 * NOTES
710 * Set dn and passwd to NULL to bind as an anonymous user.
712 ULONG CDECL ldap_simple_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
714 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
715 #ifdef HAVE_LDAP
716 char *dnU = NULL, *passwdU = NULL;
717 struct berval pwd = { 0, NULL };
719 ret = WLDAP32_LDAP_NO_MEMORY;
721 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), passwd );
723 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
725 if (dn) {
726 dnU = strWtoU( dn );
727 if (!dnU) goto exit;
729 if (passwd) {
730 passwdU = strWtoU( passwd );
731 if (!passwdU) goto exit;
733 pwd.bv_len = strlen( passwdU );
734 pwd.bv_val = passwdU;
737 ret = map_error( ldap_sasl_bind_s( ld->ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, NULL ));
739 exit:
740 strfreeU( dnU );
741 strfreeU( passwdU );
743 #endif
744 return ret;
747 /***********************************************************************
748 * ldap_unbind (WLDAP32.@)
750 * Close LDAP connection and free resources (asynchronous operation).
752 * PARAMS
753 * ld [I] Pointer to an LDAP context.
755 * RETURNS
756 * Success: LDAP_SUCCESS
757 * Failure: An LDAP error code.
759 ULONG CDECL WLDAP32_ldap_unbind( WLDAP32_LDAP *ld )
761 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
762 #ifdef HAVE_LDAP
764 TRACE( "(%p)\n", ld );
766 if (ld)
768 ret = map_error( ldap_unbind_ext( ld->ld, NULL, NULL ));
769 if ( ld->ld_server_ctrls )
770 ldap_value_free_len( ld->ld_server_ctrls );
771 heap_free( ld );
773 else
774 ret = WLDAP32_LDAP_PARAM_ERROR;
776 #endif
777 return ret;
780 /***********************************************************************
781 * ldap_unbind_s (WLDAP32.@)
783 * Close LDAP connection and free resources (synchronous operation).
785 * PARAMS
786 * ld [I] Pointer to an LDAP context.
788 * RETURNS
789 * Success: LDAP_SUCCESS
790 * Failure: An LDAP error code.
792 ULONG CDECL WLDAP32_ldap_unbind_s( WLDAP32_LDAP *ld )
794 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
795 #ifdef HAVE_LDAP
797 TRACE( "(%p)\n", ld );
799 if (ld)
801 ret = map_error( ldap_unbind_ext_s( ld->ld, NULL, NULL ));
802 if ( ld->ld_server_ctrls )
803 ldap_value_free_len( ld->ld_server_ctrls );
804 heap_free( ld );
806 else
807 ret = WLDAP32_LDAP_PARAM_ERROR;
809 #endif
810 return ret;