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;
51 TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_a(dn), cred, method );
60 credW = strAtoW( cred );
61 if (!credW) goto exit;
64 ret = ldap_bindW( ld, dnW, credW, method );
74 ULONG ldap_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
76 ULONG ret = LDAP_NOT_SUPPORTED;
78 char *dnU = NULL, *credU = NULL;
81 TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_w(dn), cred, method );
90 credU = strWtoU( cred );
91 if (!credU) goto exit;
94 ret = ldap_bind( ld, dnU, credU, method );
104 ULONG ldap_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR cred, ULONG method )
106 ULONG ret = LDAP_NOT_SUPPORTED;
108 WCHAR *dnW = NULL, *credW = NULL;
109 ret = LDAP_NO_MEMORY;
111 TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_a(dn), cred, method );
113 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
120 credW = strAtoW( cred );
121 if (!credW) goto exit;
124 ret = ldap_bind_sW( ld, dnW, credW, method );
134 ULONG ldap_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
136 ULONG ret = LDAP_NOT_SUPPORTED;
138 char *dnU = NULL, *credU = NULL;
139 ret = LDAP_NO_MEMORY;
141 TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_w(dn), cred, method );
143 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
150 credU = strWtoU( cred );
151 if (!credU) goto exit;
154 ret = ldap_bind_s( ld, dnU, credU, method );
164 ULONG ldap_sasl_bindA( WLDAP32_LDAP *ld, const PCHAR dn,
165 const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
166 PLDAPControlA *clientctrls, int *message )
168 ULONG ret = LDAP_NOT_SUPPORTED;
170 WCHAR *dnW, *mechanismW = NULL;
171 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
172 ret = LDAP_NO_MEMORY;
174 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
175 debugstr_a(mechanism), cred, serverctrls, clientctrls, message );
177 if (!ld || !dn || !mechanism || !cred || !message)
178 return WLDAP32_LDAP_PARAM_ERROR;
183 mechanismW = strAtoW( mechanism );
184 if (!mechanismW) goto exit;
187 serverctrlsW = controlarrayAtoW( serverctrls );
188 if (!serverctrlsW) goto exit;
191 clientctrlsW = controlarrayAtoW( clientctrls );
192 if (!clientctrlsW) goto exit;
195 ret = ldap_sasl_bindW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, message );
199 strfreeW( mechanismW );
200 controlarrayfreeW( serverctrlsW );
201 controlarrayfreeW( clientctrlsW );
207 ULONG ldap_sasl_bindW( WLDAP32_LDAP *ld, const PWCHAR dn,
208 const PWCHAR mechanism, const BERVAL *cred, PLDAPControlW *serverctrls,
209 PLDAPControlW *clientctrls, int *message )
211 ULONG ret = LDAP_NOT_SUPPORTED;
213 char *dnU, *mechanismU = NULL;
214 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
215 ret = LDAP_NO_MEMORY;
217 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
218 debugstr_w(mechanism), cred, serverctrls, clientctrls, message );
220 if (!ld || !dn || !mechanism || !cred || !message)
221 return WLDAP32_LDAP_PARAM_ERROR;
226 mechanismU = strWtoU( mechanism );
227 if (!mechanismU) goto exit;
230 serverctrlsU = controlarrayWtoU( serverctrls );
231 if (!serverctrlsU) goto exit;
234 clientctrlsU = controlarrayWtoU( clientctrls );
235 if (!clientctrlsU) goto exit;
238 ret = ldap_sasl_bind( ld, dnU, mechanismU, (struct berval *)cred,
239 serverctrlsU, clientctrlsU, message );
243 strfreeU( mechanismU );
244 controlarrayfreeU( serverctrlsU );
245 controlarrayfreeU( clientctrlsU );
251 ULONG ldap_sasl_bind_sA( WLDAP32_LDAP *ld, const PCHAR dn,
252 const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
253 PLDAPControlA *clientctrls, PBERVAL *serverdata )
255 ULONG ret = LDAP_NOT_SUPPORTED;
257 WCHAR *dnW, *mechanismW = NULL;
258 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
259 ret = LDAP_NO_MEMORY;
261 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
262 debugstr_a(mechanism), cred, serverctrls, clientctrls, serverdata );
264 if (!ld || !dn || !mechanism || !cred || !serverdata)
265 return WLDAP32_LDAP_PARAM_ERROR;
270 mechanismW = strAtoW( mechanism );
271 if (!mechanismW) goto exit;
274 serverctrlsW = controlarrayAtoW( serverctrls );
275 if (!serverctrlsW) goto exit;
278 clientctrlsW = controlarrayAtoW( clientctrls );
279 if (!clientctrlsW) goto exit;
282 ret = ldap_sasl_bind_sW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, serverdata );
286 strfreeW( mechanismW );
287 controlarrayfreeW( serverctrlsW );
288 controlarrayfreeW( clientctrlsW );
294 ULONG ldap_sasl_bind_sW( WLDAP32_LDAP *ld, const PWCHAR dn,
295 const PWCHAR mechanism, const BERVAL *cred, PLDAPControlW *serverctrls,
296 PLDAPControlW *clientctrls, PBERVAL *serverdata )
298 ULONG ret = LDAP_NOT_SUPPORTED;
300 char *dnU, *mechanismU = NULL;
301 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
302 ret = LDAP_NO_MEMORY;
304 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
305 debugstr_w(mechanism), cred, serverctrls, clientctrls, serverdata );
307 if (!ld || !dn || !mechanism || !cred || !serverdata)
308 return WLDAP32_LDAP_PARAM_ERROR;
313 mechanismU = strWtoU( mechanism );
314 if (!mechanismU) goto exit;
317 serverctrlsU = controlarrayWtoU( serverctrls );
318 if (!serverctrlsU) goto exit;
321 clientctrlsU = controlarrayWtoU( clientctrls );
322 if (!clientctrlsU) goto exit;
325 ret = ldap_sasl_bind_s( ld, dnU, mechanismU, (struct berval *)cred,
326 serverctrlsU, clientctrlsU, (struct berval **)serverdata );
330 strfreeU( mechanismU );
331 controlarrayfreeU( serverctrlsU );
332 controlarrayfreeU( clientctrlsU );
338 ULONG ldap_simple_bindA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
340 ULONG ret = LDAP_NOT_SUPPORTED;
342 WCHAR *dnW = NULL, *passwdW = NULL;
343 ret = LDAP_NO_MEMORY;
345 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
347 if (!ld) return ~0UL;
354 passwdW = strAtoW( passwd );
355 if (!passwdW) goto exit;
358 ret = ldap_simple_bindW( ld, dnW, passwdW );
368 ULONG ldap_simple_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
370 ULONG ret = LDAP_NOT_SUPPORTED;
372 char *dnU = NULL, *passwdU = NULL;
373 ret = LDAP_NO_MEMORY;
375 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), passwd );
377 if (!ld) return ~0UL;
384 passwdU = strWtoU( passwd );
385 if (!passwdU) goto exit;
388 ret = ldap_simple_bind( ld, dnU, passwdU );
398 ULONG ldap_simple_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
400 ULONG ret = LDAP_NOT_SUPPORTED;
402 WCHAR *dnW = NULL, *passwdW = NULL;
403 ret = LDAP_NO_MEMORY;
405 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
407 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
414 passwdW = strAtoW( passwd );
415 if (!passwdW) goto exit;
418 ret = ldap_simple_bind_sW( ld, dnW, passwdW );
428 ULONG ldap_simple_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
430 ULONG ret = LDAP_NOT_SUPPORTED;
432 char *dnU = NULL, *passwdU = NULL;
433 ret = LDAP_NO_MEMORY;
435 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), passwd );
437 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
444 passwdU = strWtoU( passwd );
445 if (!passwdU) goto exit;
448 ret = ldap_simple_bind_s( ld, dnU, passwdU );
458 ULONG WLDAP32_ldap_unbind( WLDAP32_LDAP *ld )
460 ULONG ret = LDAP_NOT_SUPPORTED;
463 TRACE( "(%p)\n", ld );
466 ret = ldap_unbind( ld );
468 ret = WLDAP32_LDAP_PARAM_ERROR;
474 ULONG WLDAP32_ldap_unbind_s( WLDAP32_LDAP *ld )
476 ULONG ret = LDAP_NOT_SUPPORTED;
479 TRACE( "(%p)\n", ld );
482 ret = ldap_unbind_s( ld );
484 ret = WLDAP32_LDAP_PARAM_ERROR;