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"
36 #include "winldap_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
41 /***********************************************************************
42 * ldap_bindA (WLDAP32.@)
46 ULONG CDECL
ldap_bindA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR cred
, ULONG method
)
48 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
50 WCHAR
*dnW
= NULL
, *credW
= NULL
;
52 ret
= WLDAP32_LDAP_NO_MEMORY
;
54 TRACE( "(%p, %s, %p, 0x%08x)\n", ld
, debugstr_a(dn
), cred
, method
);
63 credW
= strAtoW( cred
);
64 if (!credW
) goto exit
;
67 ret
= ldap_bindW( ld
, dnW
, credW
, method
);
77 /***********************************************************************
78 * ldap_bindW (WLDAP32.@)
80 * Authenticate with an LDAP server (asynchronous operation).
83 * ld [I] Pointer to an LDAP context.
84 * dn [I] DN of entry to bind as.
85 * cred [I] Credentials (e.g. password string).
86 * method [I] Authentication method.
89 * Success: Message ID of the bind operation.
90 * Failure: An LDAP error code.
93 * Only LDAP_AUTH_SIMPLE is supported (just like native).
95 ULONG CDECL
ldap_bindW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR cred
, ULONG method
)
97 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
99 char *dnU
= NULL
, *credU
= NULL
;
100 struct berval pwd
= { 0, NULL
};
103 ret
= WLDAP32_LDAP_NO_MEMORY
;
105 TRACE( "(%p, %s, %p, 0x%08x)\n", ld
, debugstr_w(dn
), cred
, method
);
107 if (!ld
) return ~0UL;
108 if (method
!= LDAP_AUTH_SIMPLE
) return WLDAP32_LDAP_PARAM_ERROR
;
115 credU
= strWtoU( cred
);
116 if (!credU
) goto exit
;
118 pwd
.bv_len
= strlen( credU
);
122 ret
= ldap_sasl_bind( ld
, dnU
, LDAP_SASL_SIMPLE
, &pwd
, NULL
, NULL
, &msg
);
124 if (ret
== LDAP_SUCCESS
)
137 /***********************************************************************
138 * ldap_bind_sA (WLDAP32.@)
142 ULONG CDECL
ldap_bind_sA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR cred
, ULONG method
)
144 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
146 WCHAR
*dnW
= NULL
, *credW
= NULL
;
148 ret
= WLDAP32_LDAP_NO_MEMORY
;
150 TRACE( "(%p, %s, %p, 0x%08x)\n", ld
, debugstr_a(dn
), cred
, method
);
152 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
159 credW
= strAtoW( cred
);
160 if (!credW
) goto exit
;
163 ret
= ldap_bind_sW( ld
, dnW
, credW
, method
);
173 /***********************************************************************
174 * ldap_bind_sW (WLDAP32.@)
176 * Authenticate with an LDAP server (synchronous operation).
179 * ld [I] Pointer to an LDAP context.
180 * dn [I] DN of entry to bind as.
181 * cred [I] Credentials (e.g. password string).
182 * method [I] Authentication method.
185 * Success: LDAP_SUCCESS
186 * Failure: An LDAP error code.
188 ULONG CDECL
ldap_bind_sW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR cred
, ULONG method
)
190 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
192 char *dnU
= NULL
, *credU
= NULL
;
193 struct berval pwd
= { 0, NULL
};
195 ret
= WLDAP32_LDAP_NO_MEMORY
;
197 TRACE( "(%p, %s, %p, 0x%08x)\n", ld
, debugstr_w(dn
), cred
, method
);
199 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
200 if (method
!= LDAP_AUTH_SIMPLE
) return WLDAP32_LDAP_PARAM_ERROR
;
207 credU
= strWtoU( cred
);
208 if (!credU
) goto exit
;
210 pwd
.bv_len
= strlen( credU
);
214 ret
= ldap_sasl_bind_s( ld
, dnU
, LDAP_SASL_SIMPLE
, &pwd
, NULL
, NULL
, NULL
);
224 /***********************************************************************
225 * ldap_sasl_bindA (WLDAP32.@)
227 * See ldap_sasl_bindW.
229 ULONG CDECL
ldap_sasl_bindA( WLDAP32_LDAP
*ld
, const PCHAR dn
,
230 const PCHAR mechanism
, const BERVAL
*cred
, PLDAPControlA
*serverctrls
,
231 PLDAPControlA
*clientctrls
, int *message
)
233 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
235 WCHAR
*dnW
, *mechanismW
= NULL
;
236 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
238 ret
= WLDAP32_LDAP_NO_MEMORY
;
240 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_a(dn
),
241 debugstr_a(mechanism
), cred
, serverctrls
, clientctrls
, message
);
243 if (!ld
|| !dn
|| !mechanism
|| !cred
|| !message
)
244 return WLDAP32_LDAP_PARAM_ERROR
;
249 mechanismW
= strAtoW( mechanism
);
250 if (!mechanismW
) goto exit
;
253 serverctrlsW
= controlarrayAtoW( serverctrls
);
254 if (!serverctrlsW
) goto exit
;
257 clientctrlsW
= controlarrayAtoW( clientctrls
);
258 if (!clientctrlsW
) goto exit
;
261 ret
= ldap_sasl_bindW( ld
, dnW
, mechanismW
, cred
, serverctrlsW
, clientctrlsW
, message
);
265 strfreeW( mechanismW
);
266 controlarrayfreeW( serverctrlsW
);
267 controlarrayfreeW( clientctrlsW
);
273 /***********************************************************************
274 * ldap_sasl_bindW (WLDAP32.@)
276 * Authenticate with an LDAP server using SASL (asynchronous operation).
279 * ld [I] Pointer to an LDAP context.
280 * dn [I] DN of entry to bind as.
281 * mechanism [I] Authentication method.
282 * cred [I] Credentials.
283 * serverctrls [I] Array of LDAP server controls.
284 * clientctrls [I] Array of LDAP client controls.
285 * message [O] Message ID of the bind operation.
288 * Success: LDAP_SUCCESS
289 * Failure: An LDAP error code.
292 * The serverctrls and clientctrls parameters are optional and should
293 * be set to NULL if not used.
295 ULONG CDECL
ldap_sasl_bindW( WLDAP32_LDAP
*ld
, const PWCHAR dn
,
296 const PWCHAR mechanism
, const BERVAL
*cred
, PLDAPControlW
*serverctrls
,
297 PLDAPControlW
*clientctrls
, int *message
)
299 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
301 char *dnU
, *mechanismU
= NULL
;
302 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
305 ret
= WLDAP32_LDAP_NO_MEMORY
;
307 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_w(dn
),
308 debugstr_w(mechanism
), cred
, serverctrls
, clientctrls
, message
);
310 if (!ld
|| !dn
|| !mechanism
|| !cred
|| !message
)
311 return WLDAP32_LDAP_PARAM_ERROR
;
316 mechanismU
= strWtoU( mechanism
);
317 if (!mechanismU
) goto exit
;
320 serverctrlsU
= controlarrayWtoU( serverctrls
);
321 if (!serverctrlsU
) goto exit
;
324 clientctrlsU
= controlarrayWtoU( clientctrls
);
325 if (!clientctrlsU
) goto exit
;
328 credU
.bv_len
= cred
->bv_len
;
329 credU
.bv_val
= cred
->bv_val
;
331 ret
= ldap_sasl_bind( ld
, dnU
, mechanismU
, &credU
,
332 serverctrlsU
, clientctrlsU
, message
);
336 strfreeU( mechanismU
);
337 controlarrayfreeU( serverctrlsU
);
338 controlarrayfreeU( clientctrlsU
);
344 /***********************************************************************
345 * ldap_sasl_bind_sA (WLDAP32.@)
347 * See ldap_sasl_bind_sW.
349 ULONG CDECL
ldap_sasl_bind_sA( WLDAP32_LDAP
*ld
, const PCHAR dn
,
350 const PCHAR mechanism
, const BERVAL
*cred
, PLDAPControlA
*serverctrls
,
351 PLDAPControlA
*clientctrls
, PBERVAL
*serverdata
)
353 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
355 WCHAR
*dnW
, *mechanismW
= NULL
;
356 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
358 ret
= WLDAP32_LDAP_NO_MEMORY
;
360 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_a(dn
),
361 debugstr_a(mechanism
), cred
, serverctrls
, clientctrls
, serverdata
);
363 if (!ld
|| !dn
|| !mechanism
|| !cred
|| !serverdata
)
364 return WLDAP32_LDAP_PARAM_ERROR
;
369 mechanismW
= strAtoW( mechanism
);
370 if (!mechanismW
) goto exit
;
373 serverctrlsW
= controlarrayAtoW( serverctrls
);
374 if (!serverctrlsW
) goto exit
;
377 clientctrlsW
= controlarrayAtoW( clientctrls
);
378 if (!clientctrlsW
) goto exit
;
381 ret
= ldap_sasl_bind_sW( ld
, dnW
, mechanismW
, cred
, serverctrlsW
, clientctrlsW
, serverdata
);
385 strfreeW( mechanismW
);
386 controlarrayfreeW( serverctrlsW
);
387 controlarrayfreeW( clientctrlsW
);
393 /***********************************************************************
394 * ldap_sasl_bind_sW (WLDAP32.@)
396 * Authenticate with an LDAP server using SASL (synchronous operation).
399 * ld [I] Pointer to an LDAP context.
400 * dn [I] DN of entry to bind as.
401 * mechanism [I] Authentication method.
402 * cred [I] Credentials.
403 * serverctrls [I] Array of LDAP server controls.
404 * clientctrls [I] Array of LDAP client controls.
405 * serverdata [O] Authentication response from the server.
408 * Success: LDAP_SUCCESS
409 * Failure: An LDAP error code.
412 * The serverctrls and clientctrls parameters are optional and should
413 * be set to NULL if not used.
415 ULONG CDECL
ldap_sasl_bind_sW( WLDAP32_LDAP
*ld
, const PWCHAR dn
,
416 const PWCHAR mechanism
, const BERVAL
*cred
, PLDAPControlW
*serverctrls
,
417 PLDAPControlW
*clientctrls
, PBERVAL
*serverdata
)
419 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
421 char *dnU
, *mechanismU
= NULL
;
422 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
425 ret
= WLDAP32_LDAP_NO_MEMORY
;
427 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_w(dn
),
428 debugstr_w(mechanism
), cred
, serverctrls
, clientctrls
, serverdata
);
430 if (!ld
|| !dn
|| !mechanism
|| !cred
|| !serverdata
)
431 return WLDAP32_LDAP_PARAM_ERROR
;
436 mechanismU
= strWtoU( mechanism
);
437 if (!mechanismU
) goto exit
;
440 serverctrlsU
= controlarrayWtoU( serverctrls
);
441 if (!serverctrlsU
) goto exit
;
444 clientctrlsU
= controlarrayWtoU( clientctrls
);
445 if (!clientctrlsU
) goto exit
;
448 credU
.bv_len
= cred
->bv_len
;
449 credU
.bv_val
= cred
->bv_val
;
451 ret
= ldap_sasl_bind_s( ld
, dnU
, mechanismU
, &credU
,
452 serverctrlsU
, clientctrlsU
, (struct berval
**)serverdata
);
456 strfreeU( mechanismU
);
457 controlarrayfreeU( serverctrlsU
);
458 controlarrayfreeU( clientctrlsU
);
464 /***********************************************************************
465 * ldap_simple_bindA (WLDAP32.@)
467 * See ldap_simple_bindW.
469 ULONG CDECL
ldap_simple_bindA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR passwd
)
471 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
473 WCHAR
*dnW
= NULL
, *passwdW
= NULL
;
475 ret
= WLDAP32_LDAP_NO_MEMORY
;
477 TRACE( "(%p, %s, %p)\n", ld
, debugstr_a(dn
), passwd
);
479 if (!ld
) return ~0UL;
486 passwdW
= strAtoW( passwd
);
487 if (!passwdW
) goto exit
;
490 ret
= ldap_simple_bindW( ld
, dnW
, passwdW
);
500 /***********************************************************************
501 * ldap_simple_bindW (WLDAP32.@)
503 * Authenticate with an LDAP server (asynchronous operation).
506 * ld [I] Pointer to an LDAP context.
507 * dn [I] DN of entry to bind as.
508 * passwd [I] Password string.
511 * Success: Message ID of the bind operation.
512 * Failure: An LDAP error code.
515 * Set dn and passwd to NULL to bind as an anonymous user.
517 ULONG CDECL
ldap_simple_bindW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR passwd
)
519 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
521 char *dnU
= NULL
, *passwdU
= NULL
;
522 struct berval pwd
= { 0, NULL
};
525 ret
= WLDAP32_LDAP_NO_MEMORY
;
527 TRACE( "(%p, %s, %p)\n", ld
, debugstr_w(dn
), passwd
);
529 if (!ld
) return ~0UL;
536 passwdU
= strWtoU( passwd
);
537 if (!passwdU
) goto exit
;
539 pwd
.bv_len
= strlen( passwdU
);
540 pwd
.bv_val
= passwdU
;
543 ret
= ldap_sasl_bind( ld
, dnU
, LDAP_SASL_SIMPLE
, &pwd
, NULL
, NULL
, &msg
);
545 if (ret
== LDAP_SUCCESS
)
558 /***********************************************************************
559 * ldap_simple_bind_sA (WLDAP32.@)
561 * See ldap_simple_bind_sW.
563 ULONG CDECL
ldap_simple_bind_sA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR passwd
)
565 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
567 WCHAR
*dnW
= NULL
, *passwdW
= NULL
;
569 ret
= WLDAP32_LDAP_NO_MEMORY
;
571 TRACE( "(%p, %s, %p)\n", ld
, debugstr_a(dn
), passwd
);
573 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
580 passwdW
= strAtoW( passwd
);
581 if (!passwdW
) goto exit
;
584 ret
= ldap_simple_bind_sW( ld
, dnW
, passwdW
);
594 /***********************************************************************
595 * ldap_simple_bind_sW (WLDAP32.@)
597 * Authenticate with an LDAP server (synchronous operation).
600 * ld [I] Pointer to an LDAP context.
601 * dn [I] DN of entry to bind as.
602 * passwd [I] Password string.
605 * Success: LDAP_SUCCESS
606 * Failure: An LDAP error code.
609 * Set dn and passwd to NULL to bind as an anonymous user.
611 ULONG CDECL
ldap_simple_bind_sW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR passwd
)
613 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
615 char *dnU
= NULL
, *passwdU
= NULL
;
616 struct berval pwd
= { 0, NULL
};
618 ret
= WLDAP32_LDAP_NO_MEMORY
;
620 TRACE( "(%p, %s, %p)\n", ld
, debugstr_w(dn
), passwd
);
622 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
629 passwdU
= strWtoU( passwd
);
630 if (!passwdU
) goto exit
;
632 pwd
.bv_len
= strlen( passwdU
);
633 pwd
.bv_val
= passwdU
;
636 ret
= ldap_sasl_bind_s( ld
, dnU
, LDAP_SASL_SIMPLE
, &pwd
, NULL
, NULL
, NULL
);
646 /***********************************************************************
647 * ldap_unbind (WLDAP32.@)
649 * Close LDAP connection and free resources (asynchronous operation).
652 * ld [I] Pointer to an LDAP context.
655 * Success: LDAP_SUCCESS
656 * Failure: An LDAP error code.
658 ULONG CDECL
WLDAP32_ldap_unbind( WLDAP32_LDAP
*ld
)
660 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
663 TRACE( "(%p)\n", ld
);
666 ret
= ldap_unbind_ext( ld
, NULL
, NULL
);
668 ret
= WLDAP32_LDAP_PARAM_ERROR
;
674 /***********************************************************************
675 * ldap_unbind_s (WLDAP32.@)
677 * Close LDAP connection and free resources (synchronous operation).
680 * ld [I] Pointer to an LDAP context.
683 * Success: LDAP_SUCCESS
684 * Failure: An LDAP error code.
686 ULONG CDECL
WLDAP32_ldap_unbind_s( WLDAP32_LDAP
*ld
)
688 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
691 TRACE( "(%p)\n", ld
);
694 ret
= ldap_unbind_ext_s( ld
, NULL
, NULL
);
696 ret
= WLDAP32_LDAP_PARAM_ERROR
;