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_bindA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR cred, ULONG method )
46 ULONG ret = LDAP_NOT_SUPPORTED;
48 WCHAR *dnW = NULL, *credW = NULL;
50 ret = WLDAP32_LDAP_NO_MEMORY;
52 TRACE( "(%p, %s, %p, 0x%08lx)\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 ULONG ldap_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
77 ULONG ret = LDAP_NOT_SUPPORTED;
79 char *dnU = NULL, *credU = NULL;
80 struct berval pwd = { 0, NULL };
83 ret = WLDAP32_LDAP_NO_MEMORY;
85 TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_w(dn), cred, method );
88 if (method != LDAP_AUTH_SIMPLE) return WLDAP32_LDAP_PARAM_ERROR;
95 credU = strWtoU( cred );
96 if (!credU) goto exit;
98 pwd.bv_len = strlen( credU );
102 ret = ldap_sasl_bind( ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, &msg );
104 if (ret == LDAP_SUCCESS)
117 ULONG ldap_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR cred, ULONG method )
119 ULONG ret = LDAP_NOT_SUPPORTED;
121 WCHAR *dnW = NULL, *credW = NULL;
123 ret = WLDAP32_LDAP_NO_MEMORY;
125 TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_a(dn), cred, method );
127 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
134 credW = strAtoW( cred );
135 if (!credW) goto exit;
138 ret = ldap_bind_sW( ld, dnW, credW, method );
148 ULONG ldap_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
150 ULONG ret = LDAP_NOT_SUPPORTED;
152 char *dnU = NULL, *credU = NULL;
153 struct berval pwd = { 0, NULL };
155 ret = WLDAP32_LDAP_NO_MEMORY;
157 TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_w(dn), cred, method );
159 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
160 if (method != LDAP_AUTH_SIMPLE) return WLDAP32_LDAP_PARAM_ERROR;
167 credU = strWtoU( cred );
168 if (!credU) goto exit;
170 pwd.bv_len = strlen( credU );
174 ret = ldap_sasl_bind_s( ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, NULL );
184 ULONG ldap_sasl_bindA( WLDAP32_LDAP *ld, const PCHAR dn,
185 const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
186 PLDAPControlA *clientctrls, int *message )
188 ULONG ret = LDAP_NOT_SUPPORTED;
190 WCHAR *dnW, *mechanismW = NULL;
191 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
193 ret = WLDAP32_LDAP_NO_MEMORY;
195 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
196 debugstr_a(mechanism), cred, serverctrls, clientctrls, message );
198 if (!ld || !dn || !mechanism || !cred || !message)
199 return WLDAP32_LDAP_PARAM_ERROR;
204 mechanismW = strAtoW( mechanism );
205 if (!mechanismW) goto exit;
208 serverctrlsW = controlarrayAtoW( serverctrls );
209 if (!serverctrlsW) goto exit;
212 clientctrlsW = controlarrayAtoW( clientctrls );
213 if (!clientctrlsW) goto exit;
216 ret = ldap_sasl_bindW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, message );
220 strfreeW( mechanismW );
221 controlarrayfreeW( serverctrlsW );
222 controlarrayfreeW( clientctrlsW );
228 ULONG ldap_sasl_bindW( WLDAP32_LDAP *ld, const PWCHAR dn,
229 const PWCHAR mechanism, const BERVAL *cred, PLDAPControlW *serverctrls,
230 PLDAPControlW *clientctrls, int *message )
232 ULONG ret = LDAP_NOT_SUPPORTED;
234 char *dnU, *mechanismU = NULL;
235 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
237 ret = WLDAP32_LDAP_NO_MEMORY;
239 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
240 debugstr_w(mechanism), cred, serverctrls, clientctrls, message );
242 if (!ld || !dn || !mechanism || !cred || !message)
243 return WLDAP32_LDAP_PARAM_ERROR;
248 mechanismU = strWtoU( mechanism );
249 if (!mechanismU) goto exit;
252 serverctrlsU = controlarrayWtoU( serverctrls );
253 if (!serverctrlsU) goto exit;
256 clientctrlsU = controlarrayWtoU( clientctrls );
257 if (!clientctrlsU) goto exit;
260 ret = ldap_sasl_bind( ld, dnU, mechanismU, (struct berval *)cred,
261 serverctrlsU, clientctrlsU, message );
265 strfreeU( mechanismU );
266 controlarrayfreeU( serverctrlsU );
267 controlarrayfreeU( clientctrlsU );
273 ULONG ldap_sasl_bind_sA( WLDAP32_LDAP *ld, const PCHAR dn,
274 const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
275 PLDAPControlA *clientctrls, PBERVAL *serverdata )
277 ULONG ret = LDAP_NOT_SUPPORTED;
279 WCHAR *dnW, *mechanismW = NULL;
280 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
282 ret = WLDAP32_LDAP_NO_MEMORY;
284 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
285 debugstr_a(mechanism), cred, serverctrls, clientctrls, serverdata );
287 if (!ld || !dn || !mechanism || !cred || !serverdata)
288 return WLDAP32_LDAP_PARAM_ERROR;
293 mechanismW = strAtoW( mechanism );
294 if (!mechanismW) goto exit;
297 serverctrlsW = controlarrayAtoW( serverctrls );
298 if (!serverctrlsW) goto exit;
301 clientctrlsW = controlarrayAtoW( clientctrls );
302 if (!clientctrlsW) goto exit;
305 ret = ldap_sasl_bind_sW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, serverdata );
309 strfreeW( mechanismW );
310 controlarrayfreeW( serverctrlsW );
311 controlarrayfreeW( clientctrlsW );
317 ULONG ldap_sasl_bind_sW( WLDAP32_LDAP *ld, const PWCHAR dn,
318 const PWCHAR mechanism, const BERVAL *cred, PLDAPControlW *serverctrls,
319 PLDAPControlW *clientctrls, PBERVAL *serverdata )
321 ULONG ret = LDAP_NOT_SUPPORTED;
323 char *dnU, *mechanismU = NULL;
324 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
326 ret = WLDAP32_LDAP_NO_MEMORY;
328 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
329 debugstr_w(mechanism), cred, serverctrls, clientctrls, serverdata );
331 if (!ld || !dn || !mechanism || !cred || !serverdata)
332 return WLDAP32_LDAP_PARAM_ERROR;
337 mechanismU = strWtoU( mechanism );
338 if (!mechanismU) goto exit;
341 serverctrlsU = controlarrayWtoU( serverctrls );
342 if (!serverctrlsU) goto exit;
345 clientctrlsU = controlarrayWtoU( clientctrls );
346 if (!clientctrlsU) goto exit;
349 ret = ldap_sasl_bind_s( ld, dnU, mechanismU, (struct berval *)cred,
350 serverctrlsU, clientctrlsU, (struct berval **)serverdata );
354 strfreeU( mechanismU );
355 controlarrayfreeU( serverctrlsU );
356 controlarrayfreeU( clientctrlsU );
362 ULONG ldap_simple_bindA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
364 ULONG ret = LDAP_NOT_SUPPORTED;
366 WCHAR *dnW = NULL, *passwdW = NULL;
368 ret = WLDAP32_LDAP_NO_MEMORY;
370 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
372 if (!ld) return ~0UL;
379 passwdW = strAtoW( passwd );
380 if (!passwdW) goto exit;
383 ret = ldap_simple_bindW( ld, dnW, passwdW );
393 ULONG ldap_simple_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
395 ULONG ret = LDAP_NOT_SUPPORTED;
397 char *dnU = NULL, *passwdU = NULL;
398 struct berval pwd = { 0, NULL };
401 ret = WLDAP32_LDAP_NO_MEMORY;
403 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), passwd );
405 if (!ld) return ~0UL;
412 passwdU = strWtoU( passwd );
413 if (!passwdU) goto exit;
415 pwd.bv_len = strlen( passwdU );
416 pwd.bv_val = passwdU;
419 ret = ldap_sasl_bind( ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, &msg );
421 if (ret == LDAP_SUCCESS)
434 ULONG ldap_simple_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
436 ULONG ret = LDAP_NOT_SUPPORTED;
438 WCHAR *dnW = NULL, *passwdW = NULL;
440 ret = WLDAP32_LDAP_NO_MEMORY;
442 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
444 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
451 passwdW = strAtoW( passwd );
452 if (!passwdW) goto exit;
455 ret = ldap_simple_bind_sW( ld, dnW, passwdW );
465 ULONG ldap_simple_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
467 ULONG ret = LDAP_NOT_SUPPORTED;
469 char *dnU = NULL, *passwdU = NULL;
470 struct berval pwd = { 0, NULL };
472 ret = WLDAP32_LDAP_NO_MEMORY;
474 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), passwd );
476 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
483 passwdU = strWtoU( passwd );
484 if (!passwdU) goto exit;
486 pwd.bv_len = strlen( passwdU );
487 pwd.bv_val = passwdU;
490 ret = ldap_sasl_bind_s( ld, dnU, LDAP_SASL_SIMPLE, &pwd, NULL, NULL, NULL );
500 ULONG WLDAP32_ldap_unbind( WLDAP32_LDAP *ld )
502 ULONG ret = LDAP_NOT_SUPPORTED;
505 TRACE( "(%p)\n", ld );
508 ret = ldap_unbind_ext( ld, NULL, NULL );
510 ret = WLDAP32_LDAP_PARAM_ERROR;
516 ULONG WLDAP32_ldap_unbind_s( WLDAP32_LDAP *ld )
518 ULONG ret = LDAP_NOT_SUPPORTED;
521 TRACE( "(%p)\n", ld );
524 ret = ldap_unbind_ext_s( ld, NULL, NULL );
526 ret = WLDAP32_LDAP_PARAM_ERROR;