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
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 /***********************************************************************
45 * ldap_bindA (WLDAP32.@)
49 ULONG CDECL
ldap_bindA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR cred
, ULONG method
)
51 ULONG ret
= LDAP_NOT_SUPPORTED
;
53 WCHAR
*dnW
= NULL
, *credW
= NULL
;
55 ret
= WLDAP32_LDAP_NO_MEMORY
;
57 TRACE( "(%p, %s, %p, 0x%08x)\n", ld
, debugstr_a(dn
), cred
, method
);
66 credW
= strAtoW( cred
);
67 if (!credW
) goto exit
;
70 ret
= ldap_bindW( ld
, dnW
, credW
, method
);
80 /***********************************************************************
81 * ldap_bindW (WLDAP32.@)
83 * Authenticate with an LDAP server (asynchronous operation).
86 * ld [I] Pointer to an LDAP context.
87 * dn [I] DN of entry to bind as.
88 * cred [I] Credentials (e.g. password string).
89 * method [I] Authentication method.
92 * Success: Message ID of the bind operation.
93 * Failure: An LDAP error code.
96 * Only LDAP_AUTH_SIMPLE is supported (just like native).
98 ULONG CDECL
ldap_bindW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR cred
, ULONG method
)
100 ULONG ret
= LDAP_NOT_SUPPORTED
;
102 char *dnU
= NULL
, *credU
= NULL
;
103 struct berval pwd
= { 0, NULL
};
106 ret
= WLDAP32_LDAP_NO_MEMORY
;
108 TRACE( "(%p, %s, %p, 0x%08x)\n", ld
, debugstr_w(dn
), cred
, method
);
110 if (!ld
) return ~0UL;
111 if (method
!= LDAP_AUTH_SIMPLE
) return WLDAP32_LDAP_PARAM_ERROR
;
118 credU
= strWtoU( cred
);
119 if (!credU
) goto exit
;
121 pwd
.bv_len
= strlen( credU
);
125 ret
= ldap_sasl_bind( ld
, dnU
, LDAP_SASL_SIMPLE
, &pwd
, NULL
, NULL
, &msg
);
127 if (ret
== LDAP_SUCCESS
)
140 /***********************************************************************
141 * ldap_bind_sA (WLDAP32.@)
145 ULONG CDECL
ldap_bind_sA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR cred
, ULONG method
)
147 ULONG ret
= LDAP_NOT_SUPPORTED
;
149 WCHAR
*dnW
= NULL
, *credW
= NULL
;
151 ret
= WLDAP32_LDAP_NO_MEMORY
;
153 TRACE( "(%p, %s, %p, 0x%08x)\n", ld
, debugstr_a(dn
), cred
, method
);
155 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
162 credW
= strAtoW( cred
);
163 if (!credW
) goto exit
;
166 ret
= ldap_bind_sW( ld
, dnW
, credW
, method
);
176 /***********************************************************************
177 * ldap_bind_sW (WLDAP32.@)
179 * Authenticate with an LDAP server (synchronous operation).
182 * ld [I] Pointer to an LDAP context.
183 * dn [I] DN of entry to bind as.
184 * cred [I] Credentials (e.g. password string).
185 * method [I] Authentication method.
188 * Success: LDAP_SUCCESS
189 * Failure: An LDAP error code.
191 ULONG CDECL
ldap_bind_sW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR cred
, ULONG method
)
193 ULONG ret
= LDAP_NOT_SUPPORTED
;
195 char *dnU
= NULL
, *credU
= NULL
;
196 struct berval pwd
= { 0, NULL
};
198 ret
= WLDAP32_LDAP_NO_MEMORY
;
200 TRACE( "(%p, %s, %p, 0x%08x)\n", ld
, debugstr_w(dn
), cred
, method
);
202 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
203 if (method
!= LDAP_AUTH_SIMPLE
) return WLDAP32_LDAP_PARAM_ERROR
;
210 credU
= strWtoU( cred
);
211 if (!credU
) goto exit
;
213 pwd
.bv_len
= strlen( credU
);
217 ret
= ldap_sasl_bind_s( ld
, dnU
, LDAP_SASL_SIMPLE
, &pwd
, NULL
, NULL
, NULL
);
227 /***********************************************************************
228 * ldap_sasl_bindA (WLDAP32.@)
230 * See ldap_sasl_bindW.
232 ULONG CDECL
ldap_sasl_bindA( WLDAP32_LDAP
*ld
, const PCHAR dn
,
233 const PCHAR mechanism
, const BERVAL
*cred
, PLDAPControlA
*serverctrls
,
234 PLDAPControlA
*clientctrls
, int *message
)
236 ULONG ret
= LDAP_NOT_SUPPORTED
;
238 WCHAR
*dnW
, *mechanismW
= NULL
;
239 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
241 ret
= WLDAP32_LDAP_NO_MEMORY
;
243 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_a(dn
),
244 debugstr_a(mechanism
), cred
, serverctrls
, clientctrls
, message
);
246 if (!ld
|| !dn
|| !mechanism
|| !cred
|| !message
)
247 return WLDAP32_LDAP_PARAM_ERROR
;
252 mechanismW
= strAtoW( mechanism
);
253 if (!mechanismW
) goto exit
;
256 serverctrlsW
= controlarrayAtoW( serverctrls
);
257 if (!serverctrlsW
) goto exit
;
260 clientctrlsW
= controlarrayAtoW( clientctrls
);
261 if (!clientctrlsW
) goto exit
;
264 ret
= ldap_sasl_bindW( ld
, dnW
, mechanismW
, cred
, serverctrlsW
, clientctrlsW
, message
);
268 strfreeW( mechanismW
);
269 controlarrayfreeW( serverctrlsW
);
270 controlarrayfreeW( clientctrlsW
);
276 /***********************************************************************
277 * ldap_sasl_bindW (WLDAP32.@)
279 * Authenticate with an LDAP server using SASL (asynchronous operation).
282 * ld [I] Pointer to an LDAP context.
283 * dn [I] DN of entry to bind as.
284 * mechanism [I] Authentication method.
285 * cred [I] Credentials.
286 * serverctrls [I] Array of LDAP server controls.
287 * clientctrls [I] Array of LDAP client controls.
288 * message [O] Message ID of the bind operation.
291 * Success: LDAP_SUCCESS
292 * Failure: An LDAP error code.
295 * The serverctrls and clientctrls parameters are optional and should
296 * be set to NULL if not used.
298 ULONG CDECL
ldap_sasl_bindW( WLDAP32_LDAP
*ld
, const PWCHAR dn
,
299 const PWCHAR mechanism
, const BERVAL
*cred
, PLDAPControlW
*serverctrls
,
300 PLDAPControlW
*clientctrls
, int *message
)
302 ULONG ret
= LDAP_NOT_SUPPORTED
;
304 char *dnU
, *mechanismU
= NULL
;
305 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
308 ret
= WLDAP32_LDAP_NO_MEMORY
;
310 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_w(dn
),
311 debugstr_w(mechanism
), cred
, serverctrls
, clientctrls
, message
);
313 if (!ld
|| !dn
|| !mechanism
|| !cred
|| !message
)
314 return WLDAP32_LDAP_PARAM_ERROR
;
319 mechanismU
= strWtoU( mechanism
);
320 if (!mechanismU
) goto exit
;
323 serverctrlsU
= controlarrayWtoU( serverctrls
);
324 if (!serverctrlsU
) goto exit
;
327 clientctrlsU
= controlarrayWtoU( clientctrls
);
328 if (!clientctrlsU
) goto exit
;
331 credU
.bv_len
= cred
->bv_len
;
332 credU
.bv_val
= cred
->bv_val
;
334 ret
= ldap_sasl_bind( ld
, dnU
, mechanismU
, &credU
,
335 serverctrlsU
, clientctrlsU
, message
);
339 strfreeU( mechanismU
);
340 controlarrayfreeU( serverctrlsU
);
341 controlarrayfreeU( clientctrlsU
);
347 /***********************************************************************
348 * ldap_sasl_bind_sA (WLDAP32.@)
350 * See ldap_sasl_bind_sW.
352 ULONG CDECL
ldap_sasl_bind_sA( WLDAP32_LDAP
*ld
, const PCHAR dn
,
353 const PCHAR mechanism
, const BERVAL
*cred
, PLDAPControlA
*serverctrls
,
354 PLDAPControlA
*clientctrls
, PBERVAL
*serverdata
)
356 ULONG ret
= LDAP_NOT_SUPPORTED
;
358 WCHAR
*dnW
, *mechanismW
= NULL
;
359 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
361 ret
= WLDAP32_LDAP_NO_MEMORY
;
363 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_a(dn
),
364 debugstr_a(mechanism
), cred
, serverctrls
, clientctrls
, serverdata
);
366 if (!ld
|| !dn
|| !mechanism
|| !cred
|| !serverdata
)
367 return WLDAP32_LDAP_PARAM_ERROR
;
372 mechanismW
= strAtoW( mechanism
);
373 if (!mechanismW
) goto exit
;
376 serverctrlsW
= controlarrayAtoW( serverctrls
);
377 if (!serverctrlsW
) goto exit
;
380 clientctrlsW
= controlarrayAtoW( clientctrls
);
381 if (!clientctrlsW
) goto exit
;
384 ret
= ldap_sasl_bind_sW( ld
, dnW
, mechanismW
, cred
, serverctrlsW
, clientctrlsW
, serverdata
);
388 strfreeW( mechanismW
);
389 controlarrayfreeW( serverctrlsW
);
390 controlarrayfreeW( clientctrlsW
);
396 /***********************************************************************
397 * ldap_sasl_bind_sW (WLDAP32.@)
399 * Authenticate with an LDAP server using SASL (synchronous operation).
402 * ld [I] Pointer to an LDAP context.
403 * dn [I] DN of entry to bind as.
404 * mechanism [I] Authentication method.
405 * cred [I] Credentials.
406 * serverctrls [I] Array of LDAP server controls.
407 * clientctrls [I] Array of LDAP client controls.
408 * serverdata [O] Authentication response from the server.
411 * Success: LDAP_SUCCESS
412 * Failure: An LDAP error code.
415 * The serverctrls and clientctrls parameters are optional and should
416 * be set to NULL if not used.
418 ULONG CDECL
ldap_sasl_bind_sW( WLDAP32_LDAP
*ld
, const PWCHAR dn
,
419 const PWCHAR mechanism
, const BERVAL
*cred
, PLDAPControlW
*serverctrls
,
420 PLDAPControlW
*clientctrls
, PBERVAL
*serverdata
)
422 ULONG ret
= LDAP_NOT_SUPPORTED
;
424 char *dnU
, *mechanismU
= NULL
;
425 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
428 ret
= WLDAP32_LDAP_NO_MEMORY
;
430 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_w(dn
),
431 debugstr_w(mechanism
), cred
, serverctrls
, clientctrls
, serverdata
);
433 if (!ld
|| !dn
|| !mechanism
|| !cred
|| !serverdata
)
434 return WLDAP32_LDAP_PARAM_ERROR
;
439 mechanismU
= strWtoU( mechanism
);
440 if (!mechanismU
) goto exit
;
443 serverctrlsU
= controlarrayWtoU( serverctrls
);
444 if (!serverctrlsU
) goto exit
;
447 clientctrlsU
= controlarrayWtoU( clientctrls
);
448 if (!clientctrlsU
) goto exit
;
451 credU
.bv_len
= cred
->bv_len
;
452 credU
.bv_val
= cred
->bv_val
;
454 ret
= ldap_sasl_bind_s( ld
, dnU
, mechanismU
, &credU
,
455 serverctrlsU
, clientctrlsU
, (struct berval
**)serverdata
);
459 strfreeU( mechanismU
);
460 controlarrayfreeU( serverctrlsU
);
461 controlarrayfreeU( clientctrlsU
);
467 /***********************************************************************
468 * ldap_simple_bindA (WLDAP32.@)
470 * See ldap_simple_bindW.
472 ULONG CDECL
ldap_simple_bindA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR passwd
)
474 ULONG ret
= LDAP_NOT_SUPPORTED
;
476 WCHAR
*dnW
= NULL
, *passwdW
= NULL
;
478 ret
= WLDAP32_LDAP_NO_MEMORY
;
480 TRACE( "(%p, %s, %p)\n", ld
, debugstr_a(dn
), passwd
);
482 if (!ld
) return ~0UL;
489 passwdW
= strAtoW( passwd
);
490 if (!passwdW
) goto exit
;
493 ret
= ldap_simple_bindW( ld
, dnW
, passwdW
);
503 /***********************************************************************
504 * ldap_simple_bindW (WLDAP32.@)
506 * Authenticate with an LDAP server (asynchronous operation).
509 * ld [I] Pointer to an LDAP context.
510 * dn [I] DN of entry to bind as.
511 * passwd [I] Password string.
514 * Success: Message ID of the bind operation.
515 * Failure: An LDAP error code.
518 * Set dn and passwd to NULL to bind as an anonymous user.
520 ULONG CDECL
ldap_simple_bindW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR passwd
)
522 ULONG ret
= LDAP_NOT_SUPPORTED
;
524 char *dnU
= NULL
, *passwdU
= NULL
;
525 struct berval pwd
= { 0, NULL
};
528 ret
= WLDAP32_LDAP_NO_MEMORY
;
530 TRACE( "(%p, %s, %p)\n", ld
, debugstr_w(dn
), passwd
);
532 if (!ld
) return ~0UL;
539 passwdU
= strWtoU( passwd
);
540 if (!passwdU
) goto exit
;
542 pwd
.bv_len
= strlen( passwdU
);
543 pwd
.bv_val
= passwdU
;
546 ret
= ldap_sasl_bind( ld
, dnU
, LDAP_SASL_SIMPLE
, &pwd
, NULL
, NULL
, &msg
);
548 if (ret
== LDAP_SUCCESS
)
561 /***********************************************************************
562 * ldap_simple_bind_sA (WLDAP32.@)
564 * See ldap_simple_bind_sW.
566 ULONG CDECL
ldap_simple_bind_sA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR passwd
)
568 ULONG ret
= LDAP_NOT_SUPPORTED
;
570 WCHAR
*dnW
= NULL
, *passwdW
= NULL
;
572 ret
= WLDAP32_LDAP_NO_MEMORY
;
574 TRACE( "(%p, %s, %p)\n", ld
, debugstr_a(dn
), passwd
);
576 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
583 passwdW
= strAtoW( passwd
);
584 if (!passwdW
) goto exit
;
587 ret
= ldap_simple_bind_sW( ld
, dnW
, passwdW
);
597 /***********************************************************************
598 * ldap_simple_bind_sW (WLDAP32.@)
600 * Authenticate with an LDAP server (synchronous operation).
603 * ld [I] Pointer to an LDAP context.
604 * dn [I] DN of entry to bind as.
605 * passwd [I] Password string.
608 * Success: LDAP_SUCCESS
609 * Failure: An LDAP error code.
612 * Set dn and passwd to NULL to bind as an anonymous user.
614 ULONG CDECL
ldap_simple_bind_sW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR passwd
)
616 ULONG ret
= LDAP_NOT_SUPPORTED
;
618 char *dnU
= NULL
, *passwdU
= NULL
;
619 struct berval pwd
= { 0, NULL
};
621 ret
= WLDAP32_LDAP_NO_MEMORY
;
623 TRACE( "(%p, %s, %p)\n", ld
, debugstr_w(dn
), passwd
);
625 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
632 passwdU
= strWtoU( passwd
);
633 if (!passwdU
) goto exit
;
635 pwd
.bv_len
= strlen( passwdU
);
636 pwd
.bv_val
= passwdU
;
639 ret
= ldap_sasl_bind_s( ld
, dnU
, LDAP_SASL_SIMPLE
, &pwd
, NULL
, NULL
, NULL
);
649 /***********************************************************************
650 * ldap_unbind (WLDAP32.@)
652 * Close LDAP connection and free resources (asynchronous operation).
655 * ld [I] Pointer to an LDAP context.
658 * Success: LDAP_SUCCESS
659 * Failure: An LDAP error code.
661 ULONG CDECL
WLDAP32_ldap_unbind( WLDAP32_LDAP
*ld
)
663 ULONG ret
= LDAP_NOT_SUPPORTED
;
666 TRACE( "(%p)\n", ld
);
669 ret
= ldap_unbind_ext( ld
, NULL
, NULL
);
671 ret
= WLDAP32_LDAP_PARAM_ERROR
;
677 /***********************************************************************
678 * ldap_unbind_s (WLDAP32.@)
680 * Close LDAP connection and free resources (synchronous operation).
683 * ld [I] Pointer to an LDAP context.
686 * Success: LDAP_SUCCESS
687 * Failure: An LDAP error code.
689 ULONG CDECL
WLDAP32_ldap_unbind_s( WLDAP32_LDAP
*ld
)
691 ULONG ret
= LDAP_NOT_SUPPORTED
;
694 TRACE( "(%p)\n", ld
);
697 ret
= ldap_unbind_ext_s( ld
, NULL
, NULL
);
699 ret
= WLDAP32_LDAP_PARAM_ERROR
;