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;
81 ret = WLDAP32_LDAP_NO_MEMORY;
83 TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_w(dn), cred, method );
92 credU = strWtoU( cred );
93 if (!credU) goto exit;
96 ret = ldap_bind( ld, dnU, credU, method );
106 ULONG ldap_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR cred, ULONG method )
108 ULONG ret = LDAP_NOT_SUPPORTED;
110 WCHAR *dnW = NULL, *credW = NULL;
112 ret = WLDAP32_LDAP_NO_MEMORY;
114 TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_a(dn), cred, method );
116 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
123 credW = strAtoW( cred );
124 if (!credW) goto exit;
127 ret = ldap_bind_sW( ld, dnW, credW, method );
137 ULONG ldap_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
139 ULONG ret = LDAP_NOT_SUPPORTED;
141 char *dnU = NULL, *credU = NULL;
143 ret = WLDAP32_LDAP_NO_MEMORY;
145 TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_w(dn), cred, method );
147 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
154 credU = strWtoU( cred );
155 if (!credU) goto exit;
158 ret = ldap_bind_s( ld, dnU, credU, method );
168 ULONG ldap_sasl_bindA( WLDAP32_LDAP *ld, const PCHAR dn,
169 const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
170 PLDAPControlA *clientctrls, int *message )
172 ULONG ret = LDAP_NOT_SUPPORTED;
174 WCHAR *dnW, *mechanismW = NULL;
175 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
177 ret = WLDAP32_LDAP_NO_MEMORY;
179 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
180 debugstr_a(mechanism), cred, serverctrls, clientctrls, message );
182 if (!ld || !dn || !mechanism || !cred || !message)
183 return WLDAP32_LDAP_PARAM_ERROR;
188 mechanismW = strAtoW( mechanism );
189 if (!mechanismW) goto exit;
192 serverctrlsW = controlarrayAtoW( serverctrls );
193 if (!serverctrlsW) goto exit;
196 clientctrlsW = controlarrayAtoW( clientctrls );
197 if (!clientctrlsW) goto exit;
200 ret = ldap_sasl_bindW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, message );
204 strfreeW( mechanismW );
205 controlarrayfreeW( serverctrlsW );
206 controlarrayfreeW( clientctrlsW );
212 ULONG ldap_sasl_bindW( WLDAP32_LDAP *ld, const PWCHAR dn,
213 const PWCHAR mechanism, const BERVAL *cred, PLDAPControlW *serverctrls,
214 PLDAPControlW *clientctrls, int *message )
216 ULONG ret = LDAP_NOT_SUPPORTED;
218 char *dnU, *mechanismU = NULL;
219 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
221 ret = WLDAP32_LDAP_NO_MEMORY;
223 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
224 debugstr_w(mechanism), cred, serverctrls, clientctrls, message );
226 if (!ld || !dn || !mechanism || !cred || !message)
227 return WLDAP32_LDAP_PARAM_ERROR;
232 mechanismU = strWtoU( mechanism );
233 if (!mechanismU) goto exit;
236 serverctrlsU = controlarrayWtoU( serverctrls );
237 if (!serverctrlsU) goto exit;
240 clientctrlsU = controlarrayWtoU( clientctrls );
241 if (!clientctrlsU) goto exit;
244 ret = ldap_sasl_bind( ld, dnU, mechanismU, (struct berval *)cred,
245 serverctrlsU, clientctrlsU, message );
249 strfreeU( mechanismU );
250 controlarrayfreeU( serverctrlsU );
251 controlarrayfreeU( clientctrlsU );
257 ULONG ldap_sasl_bind_sA( WLDAP32_LDAP *ld, const PCHAR dn,
258 const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
259 PLDAPControlA *clientctrls, PBERVAL *serverdata )
261 ULONG ret = LDAP_NOT_SUPPORTED;
263 WCHAR *dnW, *mechanismW = NULL;
264 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
266 ret = WLDAP32_LDAP_NO_MEMORY;
268 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
269 debugstr_a(mechanism), cred, serverctrls, clientctrls, serverdata );
271 if (!ld || !dn || !mechanism || !cred || !serverdata)
272 return WLDAP32_LDAP_PARAM_ERROR;
277 mechanismW = strAtoW( mechanism );
278 if (!mechanismW) goto exit;
281 serverctrlsW = controlarrayAtoW( serverctrls );
282 if (!serverctrlsW) goto exit;
285 clientctrlsW = controlarrayAtoW( clientctrls );
286 if (!clientctrlsW) goto exit;
289 ret = ldap_sasl_bind_sW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, serverdata );
293 strfreeW( mechanismW );
294 controlarrayfreeW( serverctrlsW );
295 controlarrayfreeW( clientctrlsW );
301 ULONG ldap_sasl_bind_sW( WLDAP32_LDAP *ld, const PWCHAR dn,
302 const PWCHAR mechanism, const BERVAL *cred, PLDAPControlW *serverctrls,
303 PLDAPControlW *clientctrls, PBERVAL *serverdata )
305 ULONG ret = LDAP_NOT_SUPPORTED;
307 char *dnU, *mechanismU = NULL;
308 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
310 ret = WLDAP32_LDAP_NO_MEMORY;
312 TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
313 debugstr_w(mechanism), cred, serverctrls, clientctrls, serverdata );
315 if (!ld || !dn || !mechanism || !cred || !serverdata)
316 return WLDAP32_LDAP_PARAM_ERROR;
321 mechanismU = strWtoU( mechanism );
322 if (!mechanismU) goto exit;
325 serverctrlsU = controlarrayWtoU( serverctrls );
326 if (!serverctrlsU) goto exit;
329 clientctrlsU = controlarrayWtoU( clientctrls );
330 if (!clientctrlsU) goto exit;
333 ret = ldap_sasl_bind_s( ld, dnU, mechanismU, (struct berval *)cred,
334 serverctrlsU, clientctrlsU, (struct berval **)serverdata );
338 strfreeU( mechanismU );
339 controlarrayfreeU( serverctrlsU );
340 controlarrayfreeU( clientctrlsU );
346 ULONG ldap_simple_bindA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
348 ULONG ret = LDAP_NOT_SUPPORTED;
350 WCHAR *dnW = NULL, *passwdW = NULL;
352 ret = WLDAP32_LDAP_NO_MEMORY;
354 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
356 if (!ld) return ~0UL;
363 passwdW = strAtoW( passwd );
364 if (!passwdW) goto exit;
367 ret = ldap_simple_bindW( ld, dnW, passwdW );
377 ULONG ldap_simple_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
379 ULONG ret = LDAP_NOT_SUPPORTED;
381 char *dnU = NULL, *passwdU = NULL;
383 ret = WLDAP32_LDAP_NO_MEMORY;
385 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), passwd );
387 if (!ld) return ~0UL;
394 passwdU = strWtoU( passwd );
395 if (!passwdU) goto exit;
398 ret = ldap_simple_bind( ld, dnU, passwdU );
408 ULONG ldap_simple_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
410 ULONG ret = LDAP_NOT_SUPPORTED;
412 WCHAR *dnW = NULL, *passwdW = NULL;
414 ret = WLDAP32_LDAP_NO_MEMORY;
416 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
418 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
425 passwdW = strAtoW( passwd );
426 if (!passwdW) goto exit;
429 ret = ldap_simple_bind_sW( ld, dnW, passwdW );
439 ULONG ldap_simple_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
441 ULONG ret = LDAP_NOT_SUPPORTED;
443 char *dnU = NULL, *passwdU = NULL;
445 ret = WLDAP32_LDAP_NO_MEMORY;
447 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), passwd );
449 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
456 passwdU = strWtoU( passwd );
457 if (!passwdU) goto exit;
460 ret = ldap_simple_bind_s( ld, dnU, passwdU );
470 ULONG WLDAP32_ldap_unbind( WLDAP32_LDAP *ld )
472 ULONG ret = LDAP_NOT_SUPPORTED;
475 TRACE( "(%p)\n", ld );
478 ret = ldap_unbind( ld );
480 ret = WLDAP32_LDAP_PARAM_ERROR;
486 ULONG WLDAP32_ldap_unbind_s( WLDAP32_LDAP *ld )
488 ULONG ret = LDAP_NOT_SUPPORTED;
491 TRACE( "(%p)\n", ld );
494 ret = ldap_unbind_s( ld );
496 ret = WLDAP32_LDAP_PARAM_ERROR;