Added Japanese resources.
[wine/multimedia.git] / dlls / wldap32 / bind.c
blob833cbdcd373e0db2da1862fec2920e15b3e2cbd8
1 /*
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
21 #include "config.h"
23 #include "wine/port.h"
24 #include "wine/debug.h"
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #else
35 #define LDAP_SUCCESS 0x00
36 #define LDAP_NOT_SUPPORTED 0x5c
37 #endif
39 #include "winldap_private.h"
40 #include "wldap32.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;
47 #ifdef HAVE_LDAP
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 );
54 if (!ld) return ~0UL;
56 if (dn) {
57 dnW = strAtoW( dn );
58 if (!dnW) goto exit;
60 if (cred) {
61 credW = strAtoW( cred );
62 if (!credW) goto exit;
65 ret = ldap_bindW( ld, dnW, credW, method );
67 exit:
68 strfreeW( dnW );
69 strfreeW( credW );
71 #endif
72 return ret;
75 ULONG ldap_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
77 ULONG ret = LDAP_NOT_SUPPORTED;
78 #ifdef HAVE_LDAP
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 );
85 if (!ld) return ~0UL;
87 if (dn) {
88 dnU = strWtoU( dn );
89 if (!dnU) goto exit;
91 if (cred) {
92 credU = strWtoU( cred );
93 if (!credU) goto exit;
96 ret = ldap_bind( ld, dnU, credU, method );
98 exit:
99 strfreeU( dnU );
100 strfreeU( credU );
102 #endif
103 return ret;
106 ULONG ldap_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR cred, ULONG method )
108 ULONG ret = LDAP_NOT_SUPPORTED;
109 #ifdef HAVE_LDAP
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;
118 if (dn) {
119 dnW = strAtoW( dn );
120 if (!dnW) goto exit;
122 if (cred) {
123 credW = strAtoW( cred );
124 if (!credW) goto exit;
127 ret = ldap_bind_sW( ld, dnW, credW, method );
129 exit:
130 strfreeW( dnW );
131 strfreeW( credW );
133 #endif
134 return ret;
137 ULONG ldap_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
139 ULONG ret = LDAP_NOT_SUPPORTED;
140 #ifdef HAVE_LDAP
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;
149 if (dn) {
150 dnU = strWtoU( dn );
151 if (!dnU) goto exit;
153 if (cred) {
154 credU = strWtoU( cred );
155 if (!credU) goto exit;
158 ret = ldap_bind_s( ld, dnU, credU, method );
160 exit:
161 strfreeU( dnU );
162 strfreeU( credU );
164 #endif
165 return ret;
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;
173 #ifdef HAVE_LDAP
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;
185 dnW = strAtoW( dn );
186 if (!dnW) goto exit;
188 mechanismW = strAtoW( mechanism );
189 if (!mechanismW) goto exit;
191 if (serverctrls) {
192 serverctrlsW = controlarrayAtoW( serverctrls );
193 if (!serverctrlsW) goto exit;
195 if (clientctrls) {
196 clientctrlsW = controlarrayAtoW( clientctrls );
197 if (!clientctrlsW) goto exit;
200 ret = ldap_sasl_bindW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, message );
202 exit:
203 strfreeW( dnW );
204 strfreeW( mechanismW );
205 controlarrayfreeW( serverctrlsW );
206 controlarrayfreeW( clientctrlsW );
208 #endif
209 return ret;
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;
217 #ifdef HAVE_LDAP
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;
229 dnU = strWtoU( dn );
230 if (!dnU) goto exit;
232 mechanismU = strWtoU( mechanism );
233 if (!mechanismU) goto exit;
235 if (serverctrls) {
236 serverctrlsU = controlarrayWtoU( serverctrls );
237 if (!serverctrlsU) goto exit;
239 if (clientctrls) {
240 clientctrlsU = controlarrayWtoU( clientctrls );
241 if (!clientctrlsU) goto exit;
244 ret = ldap_sasl_bind( ld, dnU, mechanismU, (struct berval *)cred,
245 serverctrlsU, clientctrlsU, message );
247 exit:
248 strfreeU( dnU );
249 strfreeU( mechanismU );
250 controlarrayfreeU( serverctrlsU );
251 controlarrayfreeU( clientctrlsU );
253 #endif
254 return ret;
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;
262 #ifdef HAVE_LDAP
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;
274 dnW = strAtoW( dn );
275 if (!dnW) goto exit;
277 mechanismW = strAtoW( mechanism );
278 if (!mechanismW) goto exit;
280 if (serverctrls) {
281 serverctrlsW = controlarrayAtoW( serverctrls );
282 if (!serverctrlsW) goto exit;
284 if (clientctrls) {
285 clientctrlsW = controlarrayAtoW( clientctrls );
286 if (!clientctrlsW) goto exit;
289 ret = ldap_sasl_bind_sW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, serverdata );
291 exit:
292 strfreeW( dnW );
293 strfreeW( mechanismW );
294 controlarrayfreeW( serverctrlsW );
295 controlarrayfreeW( clientctrlsW );
297 #endif
298 return ret;
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;
306 #ifdef HAVE_LDAP
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;
318 dnU = strWtoU( dn );
319 if (!dnU) goto exit;
321 mechanismU = strWtoU( mechanism );
322 if (!mechanismU) goto exit;
324 if (serverctrls) {
325 serverctrlsU = controlarrayWtoU( serverctrls );
326 if (!serverctrlsU) goto exit;
328 if (clientctrls) {
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 );
336 exit:
337 strfreeU( dnU );
338 strfreeU( mechanismU );
339 controlarrayfreeU( serverctrlsU );
340 controlarrayfreeU( clientctrlsU );
342 #endif
343 return ret;
346 ULONG ldap_simple_bindA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
348 ULONG ret = LDAP_NOT_SUPPORTED;
349 #ifdef HAVE_LDAP
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;
358 if (dn) {
359 dnW = strAtoW( dn );
360 if (!dnW) goto exit;
362 if (passwd) {
363 passwdW = strAtoW( passwd );
364 if (!passwdW) goto exit;
367 ret = ldap_simple_bindW( ld, dnW, passwdW );
369 exit:
370 strfreeW( dnW );
371 strfreeW( passwdW );
373 #endif
374 return ret;
377 ULONG ldap_simple_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
379 ULONG ret = LDAP_NOT_SUPPORTED;
380 #ifdef HAVE_LDAP
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;
389 if (dn) {
390 dnU = strWtoU( dn );
391 if (!dnU) goto exit;
393 if (passwd) {
394 passwdU = strWtoU( passwd );
395 if (!passwdU) goto exit;
398 ret = ldap_simple_bind( ld, dnU, passwdU );
400 exit:
401 strfreeU( dnU );
402 strfreeU( passwdU );
404 #endif
405 return ret;
408 ULONG ldap_simple_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR passwd )
410 ULONG ret = LDAP_NOT_SUPPORTED;
411 #ifdef HAVE_LDAP
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;
420 if (dn) {
421 dnW = strAtoW( dn );
422 if (!dnW) goto exit;
424 if (passwd) {
425 passwdW = strAtoW( passwd );
426 if (!passwdW) goto exit;
429 ret = ldap_simple_bind_sW( ld, dnW, passwdW );
431 exit:
432 strfreeW( dnW );
433 strfreeW( passwdW );
435 #endif
436 return ret;
439 ULONG ldap_simple_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR passwd )
441 ULONG ret = LDAP_NOT_SUPPORTED;
442 #ifdef HAVE_LDAP
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;
451 if (dn) {
452 dnU = strWtoU( dn );
453 if (!dnU) goto exit;
455 if (passwd) {
456 passwdU = strWtoU( passwd );
457 if (!passwdU) goto exit;
460 ret = ldap_simple_bind_s( ld, dnU, passwdU );
462 exit:
463 strfreeU( dnU );
464 strfreeU( passwdU );
466 #endif
467 return ret;
470 ULONG WLDAP32_ldap_unbind( WLDAP32_LDAP *ld )
472 ULONG ret = LDAP_NOT_SUPPORTED;
473 #ifdef HAVE_LDAP
475 TRACE( "(%p)\n", ld );
477 if (ld)
478 ret = ldap_unbind( ld );
479 else
480 ret = WLDAP32_LDAP_PARAM_ERROR;
482 #endif
483 return ret;
486 ULONG WLDAP32_ldap_unbind_s( WLDAP32_LDAP *ld )
488 ULONG ret = LDAP_NOT_SUPPORTED;
489 #ifdef HAVE_LDAP
491 TRACE( "(%p)\n", ld );
493 if (ld)
494 ret = ldap_unbind_s( ld );
495 else
496 ret = WLDAP32_LDAP_PARAM_ERROR;
498 #endif
499 return ret;