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_compareA (WLDAP32.@)
46 ULONG CDECL
ldap_compareA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
)
48 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
50 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
54 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_a(dn
), debugstr_a(attr
),
57 if (!ld
|| !attr
) return ~0UL;
64 attrW
= strAtoW( attr
);
65 if (!attrW
) goto exit
;
68 valueW
= strAtoW( value
);
69 if (!valueW
) goto exit
;
72 ret
= ldap_compareW( ld
, dnW
, attrW
, valueW
);
83 /***********************************************************************
84 * ldap_compareW (WLDAP32.@)
86 * Check if an attribute has a certain value (asynchronous operation).
89 * ld [I] Pointer to an LDAP context.
90 * dn [I] DN of entry to compare value for.
91 * attr [I] Attribute to compare value for.
92 * value [I] Value to compare.
95 * Success: Message ID of the compare operation.
96 * Failure: An LDAP error code.
98 ULONG CDECL
ldap_compareW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
)
100 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
102 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
103 struct berval val
= { 0, NULL
};
108 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_w(dn
), debugstr_w(attr
),
111 if (!ld
|| !attr
) return ~0UL;
118 attrU
= strWtoU( attr
);
119 if (!attrU
) goto exit
;
122 valueU
= strWtoU( value
);
123 if (!valueU
) goto exit
;
125 val
.bv_len
= strlen( valueU
);
129 ret
= ldap_compare_ext( ld
, dn
? dnU
: "", attrU
, &val
, NULL
, NULL
, &msg
);
131 if (ret
== LDAP_SUCCESS
)
145 /***********************************************************************
146 * ldap_compare_extA (WLDAP32.@)
148 * See ldap_compare_extW.
150 ULONG CDECL
ldap_compare_extA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
,
151 struct WLDAP32_berval
*data
, PLDAPControlA
*serverctrls
, PLDAPControlA
*clientctrls
,
154 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
156 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
157 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
159 ret
= WLDAP32_LDAP_NO_MEMORY
;
161 TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_a(dn
),
162 debugstr_a(attr
), debugstr_a(value
), data
, serverctrls
,
163 clientctrls
, message
);
165 if (!ld
|| !message
) return WLDAP32_LDAP_PARAM_ERROR
;
172 attrW
= strAtoW( attr
);
173 if (!attrW
) goto exit
;
176 valueW
= strAtoW( value
);
177 if (!valueW
) goto exit
;
180 serverctrlsW
= controlarrayAtoW( serverctrls
);
181 if (!serverctrlsW
) goto exit
;
184 clientctrlsW
= controlarrayAtoW( clientctrls
);
185 if (!clientctrlsW
) goto exit
;
188 ret
= ldap_compare_extW( ld
, dnW
, attrW
, valueW
, data
,
189 serverctrlsW
, clientctrlsW
, message
);
195 controlarrayfreeW( serverctrlsW
);
196 controlarrayfreeW( clientctrlsW
);
202 /***********************************************************************
203 * ldap_compare_extW (WLDAP32.@)
205 * Check if an attribute has a certain value (asynchronous operation).
208 * ld [I] Pointer to an LDAP context.
209 * dn [I] DN of entry to compare value for.
210 * attr [I] Attribute to compare value for.
211 * value [I] string encoded value to compare.
212 * data [I] berval encoded value to compare.
213 * serverctrls [I] Array of LDAP server controls.
214 * clientctrls [I] Array of LDAP client controls.
215 * message [O] Message ID of the compare operation.
218 * Success: LDAP_SUCCESS
219 * Failure: An LDAP error code.
222 * Set value to compare strings or data to compare binary values. If
223 * both are non-NULL, data will be used. The serverctrls and clientctrls
224 * parameters are optional and should be set to NULL if not used.
226 ULONG CDECL
ldap_compare_extW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
,
227 struct WLDAP32_berval
*data
, PLDAPControlW
*serverctrls
, PLDAPControlW
*clientctrls
,
230 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
232 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
233 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
234 struct berval val
= { 0, NULL
};
236 ret
= WLDAP32_LDAP_NO_MEMORY
;
238 TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_w(dn
),
239 debugstr_w(attr
), debugstr_w(value
), data
, serverctrls
,
240 clientctrls
, message
);
242 if (!ld
|| !message
) return WLDAP32_LDAP_PARAM_ERROR
;
243 if (!attr
) return WLDAP32_LDAP_NO_MEMORY
;
250 attrU
= strWtoU( attr
);
251 if (!attrU
) goto exit
;
255 valueU
= strWtoU( value
);
256 if (!valueU
) goto exit
;
258 val
.bv_len
= strlen( valueU
);
263 serverctrlsU
= controlarrayWtoU( serverctrls
);
264 if (!serverctrlsU
) goto exit
;
267 clientctrlsU
= controlarrayWtoU( clientctrls
);
268 if (!clientctrlsU
) goto exit
;
271 ret
= ldap_compare_ext( ld
, dn
? dnU
: "", attrU
, data
? (struct berval
*)data
: &val
,
272 serverctrlsU
, clientctrlsU
, (int *)message
);
278 controlarrayfreeU( serverctrlsU
);
279 controlarrayfreeU( clientctrlsU
);
285 /***********************************************************************
286 * ldap_compare_ext_sA (WLDAP32.@)
288 * See ldap_compare_ext_sW.
290 ULONG CDECL
ldap_compare_ext_sA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
,
291 struct WLDAP32_berval
*data
, PLDAPControlA
*serverctrls
, PLDAPControlA
*clientctrls
)
293 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
295 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
296 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
298 ret
= WLDAP32_LDAP_NO_MEMORY
;
300 TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld
, debugstr_a(dn
),
301 debugstr_a(attr
), debugstr_a(value
), data
, serverctrls
,
304 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
311 attrW
= strAtoW( attr
);
312 if (!attrW
) goto exit
;
315 valueW
= strAtoW( value
);
316 if (!valueW
) goto exit
;
319 serverctrlsW
= controlarrayAtoW( serverctrls
);
320 if (!serverctrlsW
) goto exit
;
323 clientctrlsW
= controlarrayAtoW( clientctrls
);
324 if (!clientctrlsW
) goto exit
;
327 ret
= ldap_compare_ext_sW( ld
, dnW
, attrW
, valueW
, data
, serverctrlsW
,
334 controlarrayfreeW( serverctrlsW
);
335 controlarrayfreeW( clientctrlsW
);
341 /***********************************************************************
342 * ldap_compare_ext_sW (WLDAP32.@)
344 * Check if an attribute has a certain value (synchronous operation).
347 * ld [I] Pointer to an LDAP context.
348 * dn [I] DN of entry to compare value for.
349 * attr [I] Attribute to compare value for.
350 * value [I] string encoded value to compare.
351 * data [I] berval encoded value to compare.
352 * serverctrls [I] Array of LDAP server controls.
353 * clientctrls [I] Array of LDAP client controls.
356 * Success: LDAP_SUCCESS
357 * Failure: An LDAP error code.
360 * Set value to compare strings or data to compare binary values. If
361 * both are non-NULL, data will be used. The serverctrls and clientctrls
362 * parameters are optional and should be set to NULL if not used.
364 ULONG CDECL
ldap_compare_ext_sW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
,
365 struct WLDAP32_berval
*data
, PLDAPControlW
*serverctrls
, PLDAPControlW
*clientctrls
)
367 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
369 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
370 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
371 struct berval val
= { 0, NULL
};
373 ret
= WLDAP32_LDAP_NO_MEMORY
;
375 TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld
, debugstr_w(dn
),
376 debugstr_w(attr
), debugstr_w(value
), data
, serverctrls
,
379 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
386 attrU
= strWtoU( attr
);
387 if (!attrU
) goto exit
;
391 valueU
= strWtoU( value
);
392 if (!valueU
) goto exit
;
394 val
.bv_len
= strlen( valueU
);
399 serverctrlsU
= controlarrayWtoU( serverctrls
);
400 if (!serverctrlsU
) goto exit
;
403 clientctrlsU
= controlarrayWtoU( clientctrls
);
404 if (!clientctrlsU
) goto exit
;
407 ret
= ldap_compare_ext_s( ld
, dn
? dnU
: "", attr
? attrU
: "",
408 data
? (struct berval
*)data
: &val
,
409 serverctrlsU
, clientctrlsU
);
415 controlarrayfreeU( serverctrlsU
);
416 controlarrayfreeU( clientctrlsU
);
422 /***********************************************************************
423 * ldap_compare_sA (WLDAP32.@)
425 * See ldap_compare_sW.
427 ULONG CDECL
ldap_compare_sA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
)
429 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
431 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
433 ret
= WLDAP32_LDAP_NO_MEMORY
;
435 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_a(dn
), debugstr_a(attr
),
438 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
445 attrW
= strAtoW( attr
);
446 if (!attrW
) goto exit
;
449 valueW
= strAtoW( value
);
450 if (!valueW
) goto exit
;
453 ret
= ldap_compare_sW( ld
, dnW
, attrW
, valueW
);
464 /***********************************************************************
465 * ldap_compare_sW (WLDAP32.@)
467 * Check if an attribute has a certain value (synchronous operation).
470 * ld [I] Pointer to an LDAP context.
471 * dn [I] DN of entry to compare value for.
472 * attr [I] Attribute to compare value for.
473 * value [I] Value to compare.
476 * Success: LDAP_SUCCESS
477 * Failure: An LDAP error code.
479 ULONG CDECL
ldap_compare_sW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
)
481 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
483 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
484 struct berval val
= { 0, NULL
};
486 ret
= WLDAP32_LDAP_NO_MEMORY
;
488 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_w(dn
), debugstr_w(attr
),
491 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
498 attrU
= strWtoU( attr
);
499 if (!attrU
) goto exit
;
502 valueU
= strWtoU( value
);
503 if (!valueU
) goto exit
;
505 val
.bv_len
= strlen( valueU
);
509 ret
= ldap_compare_ext_s( ld
, dn
? dnU
: "", attr
? attrU
: "", &val
, NULL
, NULL
);