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"
35 #define LDAP_NOT_SUPPORTED 0x5c
38 #include "winldap_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
43 /***********************************************************************
44 * ldap_compareA (WLDAP32.@)
48 ULONG CDECL
ldap_compareA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
)
50 ULONG ret
= LDAP_NOT_SUPPORTED
;
52 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
56 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_a(dn
), debugstr_a(attr
),
59 if (!ld
|| !attr
) return ~0UL;
66 attrW
= strAtoW( attr
);
67 if (!attrW
) goto exit
;
70 valueW
= strAtoW( value
);
71 if (!valueW
) goto exit
;
74 ret
= ldap_compareW( ld
, dnW
, attrW
, valueW
);
85 /***********************************************************************
86 * ldap_compareW (WLDAP32.@)
88 * Check if an attribute has a certain value (asynchronous operation).
91 * ld [I] Pointer to an LDAP context.
92 * dn [I] DN of entry to compare value for.
93 * attr [I] Attribute to compare value for.
94 * value [I] Value to compare.
97 * Success: Message ID of the compare operation.
98 * Failure: An LDAP error code.
100 ULONG CDECL
ldap_compareW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
)
102 ULONG ret
= LDAP_NOT_SUPPORTED
;
104 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
105 struct berval val
= { 0, NULL
};
110 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_w(dn
), debugstr_w(attr
),
113 if (!ld
|| !attr
) return ~0UL;
120 attrU
= strWtoU( attr
);
121 if (!attrU
) goto exit
;
124 valueU
= strWtoU( value
);
125 if (!valueU
) goto exit
;
127 val
.bv_len
= strlen( valueU
);
131 ret
= ldap_compare_ext( ld
, dn
? dnU
: "", attrU
, &val
, NULL
, NULL
, &msg
);
133 if (ret
== LDAP_SUCCESS
)
147 /***********************************************************************
148 * ldap_compare_extA (WLDAP32.@)
150 * See ldap_compare_extW.
152 ULONG CDECL
ldap_compare_extA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
,
153 struct WLDAP32_berval
*data
, PLDAPControlA
*serverctrls
, PLDAPControlA
*clientctrls
,
156 ULONG ret
= LDAP_NOT_SUPPORTED
;
158 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
159 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
161 ret
= WLDAP32_LDAP_NO_MEMORY
;
163 TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_a(dn
),
164 debugstr_a(attr
), debugstr_a(value
), data
, serverctrls
,
165 clientctrls
, message
);
167 if (!ld
|| !message
) return WLDAP32_LDAP_PARAM_ERROR
;
174 attrW
= strAtoW( attr
);
175 if (!attrW
) goto exit
;
178 valueW
= strAtoW( value
);
179 if (!valueW
) goto exit
;
182 serverctrlsW
= controlarrayAtoW( serverctrls
);
183 if (!serverctrlsW
) goto exit
;
186 clientctrlsW
= controlarrayAtoW( clientctrls
);
187 if (!clientctrlsW
) goto exit
;
190 ret
= ldap_compare_extW( ld
, dnW
, attrW
, valueW
, data
,
191 serverctrlsW
, clientctrlsW
, message
);
197 controlarrayfreeW( serverctrlsW
);
198 controlarrayfreeW( clientctrlsW
);
204 /***********************************************************************
205 * ldap_compare_extW (WLDAP32.@)
207 * Check if an attribute has a certain value (asynchronous operation).
210 * ld [I] Pointer to an LDAP context.
211 * dn [I] DN of entry to compare value for.
212 * attr [I] Attribute to compare value for.
213 * value [I] string encoded value to compare.
214 * data [I] berval encoded value to compare.
215 * serverctrls [I] Array of LDAP server controls.
216 * clientctrls [I] Array of LDAP client controls.
217 * message [O] Message ID of the compare operation.
220 * Success: LDAP_SUCCESS
221 * Failure: An LDAP error code.
224 * Set value to compare strings or data to compare binary values. If
225 * both are non-NULL, data will be used. The serverctrls and clientctrls
226 * parameters are optional and should be set to NULL if not used.
228 ULONG CDECL
ldap_compare_extW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
,
229 struct WLDAP32_berval
*data
, PLDAPControlW
*serverctrls
, PLDAPControlW
*clientctrls
,
232 ULONG ret
= LDAP_NOT_SUPPORTED
;
234 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
235 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
236 struct berval val
= { 0, NULL
};
238 ret
= WLDAP32_LDAP_NO_MEMORY
;
240 TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_w(dn
),
241 debugstr_w(attr
), debugstr_w(value
), data
, serverctrls
,
242 clientctrls
, message
);
244 if (!ld
|| !message
) return WLDAP32_LDAP_PARAM_ERROR
;
245 if (!attr
) return WLDAP32_LDAP_NO_MEMORY
;
252 attrU
= strWtoU( attr
);
253 if (!attrU
) goto exit
;
257 valueU
= strWtoU( value
);
258 if (!valueU
) goto exit
;
260 val
.bv_len
= strlen( valueU
);
265 serverctrlsU
= controlarrayWtoU( serverctrls
);
266 if (!serverctrlsU
) goto exit
;
269 clientctrlsU
= controlarrayWtoU( clientctrls
);
270 if (!clientctrlsU
) goto exit
;
273 ret
= ldap_compare_ext( ld
, dn
? dnU
: "", attrU
, data
? (struct berval
*)data
: &val
,
274 serverctrlsU
, clientctrlsU
, (int *)message
);
280 controlarrayfreeU( serverctrlsU
);
281 controlarrayfreeU( clientctrlsU
);
287 /***********************************************************************
288 * ldap_compare_ext_sA (WLDAP32.@)
290 * See ldap_compare_ext_sW.
292 ULONG CDECL
ldap_compare_ext_sA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
,
293 struct WLDAP32_berval
*data
, PLDAPControlA
*serverctrls
, PLDAPControlA
*clientctrls
)
295 ULONG ret
= LDAP_NOT_SUPPORTED
;
297 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
298 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
300 ret
= WLDAP32_LDAP_NO_MEMORY
;
302 TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld
, debugstr_a(dn
),
303 debugstr_a(attr
), debugstr_a(value
), data
, serverctrls
,
306 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
313 attrW
= strAtoW( attr
);
314 if (!attrW
) goto exit
;
317 valueW
= strAtoW( value
);
318 if (!valueW
) goto exit
;
321 serverctrlsW
= controlarrayAtoW( serverctrls
);
322 if (!serverctrlsW
) goto exit
;
325 clientctrlsW
= controlarrayAtoW( clientctrls
);
326 if (!clientctrlsW
) goto exit
;
329 ret
= ldap_compare_ext_sW( ld
, dnW
, attrW
, valueW
, data
, serverctrlsW
,
336 controlarrayfreeW( serverctrlsW
);
337 controlarrayfreeW( clientctrlsW
);
343 /***********************************************************************
344 * ldap_compare_ext_sW (WLDAP32.@)
346 * Check if an attribute has a certain value (synchronous operation).
349 * ld [I] Pointer to an LDAP context.
350 * dn [I] DN of entry to compare value for.
351 * attr [I] Attribute to compare value for.
352 * value [I] string encoded value to compare.
353 * data [I] berval encoded value to compare.
354 * serverctrls [I] Array of LDAP server controls.
355 * clientctrls [I] Array of LDAP client controls.
358 * Success: LDAP_SUCCESS
359 * Failure: An LDAP error code.
362 * Set value to compare strings or data to compare binary values. If
363 * both are non-NULL, data will be used. The serverctrls and clientctrls
364 * parameters are optional and should be set to NULL if not used.
366 ULONG CDECL
ldap_compare_ext_sW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
,
367 struct WLDAP32_berval
*data
, PLDAPControlW
*serverctrls
, PLDAPControlW
*clientctrls
)
369 ULONG ret
= LDAP_NOT_SUPPORTED
;
371 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
372 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
373 struct berval val
= { 0, NULL
};
375 ret
= WLDAP32_LDAP_NO_MEMORY
;
377 TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld
, debugstr_w(dn
),
378 debugstr_w(attr
), debugstr_w(value
), data
, serverctrls
,
381 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
388 attrU
= strWtoU( attr
);
389 if (!attrU
) goto exit
;
393 valueU
= strWtoU( value
);
394 if (!valueU
) goto exit
;
396 val
.bv_len
= strlen( valueU
);
401 serverctrlsU
= controlarrayWtoU( serverctrls
);
402 if (!serverctrlsU
) goto exit
;
405 clientctrlsU
= controlarrayWtoU( clientctrls
);
406 if (!clientctrlsU
) goto exit
;
409 ret
= ldap_compare_ext_s( ld
, dn
? dnU
: "", attr
? attrU
: "",
410 data
? (struct berval
*)data
: &val
,
411 serverctrlsU
, clientctrlsU
);
417 controlarrayfreeU( serverctrlsU
);
418 controlarrayfreeU( clientctrlsU
);
424 /***********************************************************************
425 * ldap_compare_sA (WLDAP32.@)
427 * See ldap_compare_sW.
429 ULONG CDECL
ldap_compare_sA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
)
431 ULONG ret
= LDAP_NOT_SUPPORTED
;
433 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
435 ret
= WLDAP32_LDAP_NO_MEMORY
;
437 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_a(dn
), debugstr_a(attr
),
440 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
447 attrW
= strAtoW( attr
);
448 if (!attrW
) goto exit
;
451 valueW
= strAtoW( value
);
452 if (!valueW
) goto exit
;
455 ret
= ldap_compare_sW( ld
, dnW
, attrW
, valueW
);
466 /***********************************************************************
467 * ldap_compare_sW (WLDAP32.@)
469 * Check if an attribute has a certain value (synchronous operation).
472 * ld [I] Pointer to an LDAP context.
473 * dn [I] DN of entry to compare value for.
474 * attr [I] Attribute to compare value for.
475 * value [I] Value to compare.
478 * Success: LDAP_SUCCESS
479 * Failure: An LDAP error code.
481 ULONG CDECL
ldap_compare_sW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
)
483 ULONG ret
= LDAP_NOT_SUPPORTED
;
485 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
486 struct berval val
= { 0, NULL
};
488 ret
= WLDAP32_LDAP_NO_MEMORY
;
490 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_w(dn
), debugstr_w(attr
),
493 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
500 attrU
= strWtoU( attr
);
501 if (!attrU
) goto exit
;
504 valueU
= strWtoU( value
);
505 if (!valueU
) goto exit
;
507 val
.bv_len
= strlen( valueU
);
511 ret
= ldap_compare_ext_s( ld
, dn
? dnU
: "", attr
? attrU
: "", &val
, NULL
, NULL
);