msi: Load the folder property if available and requested.
[wine/multimedia.git] / dlls / wldap32 / compare.c
blob83b0c9fdce08ba39737cfcf208aa7d7bd52c0ea8
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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_NOT_SUPPORTED 0x5c
36 #endif
38 #include "winldap_private.h"
39 #include "wldap32.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
43 /***********************************************************************
44 * ldap_compareA (WLDAP32.@)
46 * See ldap_compareW.
48 ULONG CDECL ldap_compareA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value )
50 ULONG ret = LDAP_NOT_SUPPORTED;
51 #ifdef HAVE_LDAP
52 WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
54 ret = ~0UL;
56 TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(attr),
57 debugstr_a(value) );
59 if (!ld || !attr) return ~0UL;
61 if (dn) {
62 dnW = strAtoW( dn );
63 if (!dnW) goto exit;
66 attrW = strAtoW( attr );
67 if (!attrW) goto exit;
69 if (value) {
70 valueW = strAtoW( value );
71 if (!valueW) goto exit;
74 ret = ldap_compareW( ld, dnW, attrW, valueW );
76 exit:
77 strfreeW( dnW );
78 strfreeW( attrW );
79 strfreeW( valueW );
81 #endif
82 return ret;
85 /***********************************************************************
86 * ldap_compareW (WLDAP32.@)
88 * Check if an attribute has a certain value (asynchronous operation).
90 * PARAMS
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.
96 * RETURNS
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;
103 #ifdef HAVE_LDAP
104 char *dnU = NULL, *attrU = NULL, *valueU = NULL;
105 struct berval val = { 0, NULL };
106 int msg;
108 ret = ~0UL;
110 TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(attr),
111 debugstr_w(value) );
113 if (!ld || !attr) return ~0UL;
115 if (dn) {
116 dnU = strWtoU( dn );
117 if (!dnU) goto exit;
120 attrU = strWtoU( attr );
121 if (!attrU) goto exit;
123 if (value) {
124 valueU = strWtoU( value );
125 if (!valueU) goto exit;
127 val.bv_len = strlen( valueU );
128 val.bv_val = valueU;
131 ret = ldap_compare_ext( ld, dn ? dnU : "", attrU, &val, NULL, NULL, &msg );
133 if (ret == LDAP_SUCCESS)
134 ret = msg;
135 else
136 ret = ~0UL;
138 exit:
139 strfreeU( dnU );
140 strfreeU( attrU );
141 strfreeU( valueU );
143 #endif
144 return ret;
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,
154 ULONG *message )
156 ULONG ret = LDAP_NOT_SUPPORTED;
157 #ifdef HAVE_LDAP
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;
169 if (dn) {
170 dnW = strAtoW( dn );
171 if (!dnW) goto exit;
173 if (attr) {
174 attrW = strAtoW( attr );
175 if (!attrW) goto exit;
177 if (value) {
178 valueW = strAtoW( value );
179 if (!valueW) goto exit;
181 if (serverctrls) {
182 serverctrlsW = controlarrayAtoW( serverctrls );
183 if (!serverctrlsW) goto exit;
185 if (clientctrls) {
186 clientctrlsW = controlarrayAtoW( clientctrls );
187 if (!clientctrlsW) goto exit;
190 ret = ldap_compare_extW( ld, dnW, attrW, valueW, data,
191 serverctrlsW, clientctrlsW, message );
193 exit:
194 strfreeW( dnW );
195 strfreeW( attrW );
196 strfreeW( valueW );
197 controlarrayfreeW( serverctrlsW );
198 controlarrayfreeW( clientctrlsW );
200 #endif
201 return ret;
204 /***********************************************************************
205 * ldap_compare_extW (WLDAP32.@)
207 * Check if an attribute has a certain value (asynchronous operation).
209 * PARAMS
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.
219 * RETURNS
220 * Success: LDAP_SUCCESS
221 * Failure: An LDAP error code.
223 * NOTES
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,
230 ULONG *message )
232 ULONG ret = LDAP_NOT_SUPPORTED;
233 #ifdef HAVE_LDAP
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;
247 if (dn) {
248 dnU = strWtoU( dn );
249 if (!dnU) goto exit;
252 attrU = strWtoU( attr );
253 if (!attrU) goto exit;
255 if (!data) {
256 if (value) {
257 valueU = strWtoU( value );
258 if (!valueU) goto exit;
260 val.bv_len = strlen( valueU );
261 val.bv_val = valueU;
264 if (serverctrls) {
265 serverctrlsU = controlarrayWtoU( serverctrls );
266 if (!serverctrlsU) goto exit;
268 if (clientctrls) {
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 );
276 exit:
277 strfreeU( dnU );
278 strfreeU( attrU );
279 strfreeU( valueU );
280 controlarrayfreeU( serverctrlsU );
281 controlarrayfreeU( clientctrlsU );
283 #endif
284 return ret;
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;
296 #ifdef HAVE_LDAP
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,
304 clientctrls );
306 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
308 if (dn) {
309 dnW = strAtoW( dn );
310 if (!dnW) goto exit;
312 if (attr) {
313 attrW = strAtoW( attr );
314 if (!attrW) goto exit;
316 if (value) {
317 valueW = strAtoW( value );
318 if (!valueW) goto exit;
320 if (serverctrls) {
321 serverctrlsW = controlarrayAtoW( serverctrls );
322 if (!serverctrlsW) goto exit;
324 if (clientctrls) {
325 clientctrlsW = controlarrayAtoW( clientctrls );
326 if (!clientctrlsW) goto exit;
329 ret = ldap_compare_ext_sW( ld, dnW, attrW, valueW, data, serverctrlsW,
330 clientctrlsW );
332 exit:
333 strfreeW( dnW );
334 strfreeW( attrW );
335 strfreeW( valueW );
336 controlarrayfreeW( serverctrlsW );
337 controlarrayfreeW( clientctrlsW );
339 #endif
340 return ret;
343 /***********************************************************************
344 * ldap_compare_ext_sW (WLDAP32.@)
346 * Check if an attribute has a certain value (synchronous operation).
348 * PARAMS
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.
357 * RETURNS
358 * Success: LDAP_SUCCESS
359 * Failure: An LDAP error code.
361 * NOTES
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;
370 #ifdef HAVE_LDAP
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,
379 clientctrls );
381 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
383 if (dn) {
384 dnU = strWtoU( dn );
385 if (!dnU) goto exit;
387 if (attr) {
388 attrU = strWtoU( attr );
389 if (!attrU) goto exit;
391 if (!data) {
392 if (value) {
393 valueU = strWtoU( value );
394 if (!valueU) goto exit;
396 val.bv_len = strlen( valueU );
397 val.bv_val = valueU;
400 if (serverctrls) {
401 serverctrlsU = controlarrayWtoU( serverctrls );
402 if (!serverctrlsU) goto exit;
404 if (clientctrls) {
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 );
413 exit:
414 strfreeU( dnU );
415 strfreeU( attrU );
416 strfreeU( valueU );
417 controlarrayfreeU( serverctrlsU );
418 controlarrayfreeU( clientctrlsU );
420 #endif
421 return ret;
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;
432 #ifdef HAVE_LDAP
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),
438 debugstr_a(value) );
440 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
442 if (dn) {
443 dnW = strAtoW( dn );
444 if (!dnW) goto exit;
446 if (attr) {
447 attrW = strAtoW( attr );
448 if (!attrW) goto exit;
450 if (value) {
451 valueW = strAtoW( value );
452 if (!valueW) goto exit;
455 ret = ldap_compare_sW( ld, dnW, attrW, valueW );
457 exit:
458 strfreeW( dnW );
459 strfreeW( attrW );
460 strfreeW( valueW );
462 #endif
463 return ret;
466 /***********************************************************************
467 * ldap_compare_sW (WLDAP32.@)
469 * Check if an attribute has a certain value (synchronous operation).
471 * PARAMS
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.
477 * RETURNS
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;
484 #ifdef HAVE_LDAP
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),
491 debugstr_w(value) );
493 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
495 if (dn) {
496 dnU = strWtoU( dn );
497 if (!dnU) goto exit;
499 if (attr) {
500 attrU = strWtoU( attr );
501 if (!attrU) goto exit;
503 if (value) {
504 valueU = strWtoU( value );
505 if (!valueU) goto exit;
507 val.bv_len = strlen( valueU );
508 val.bv_val = valueU;
511 ret = ldap_compare_ext_s( ld, dn ? dnU : "", attr ? attrU : "", &val, NULL, NULL );
513 exit:
514 strfreeU( dnU );
515 strfreeU( attrU );
516 strfreeU( valueU );
518 #endif
519 return ret;