shell32: Add printers CLSID to test, clean up a bit.
[wine/testsucceed.git] / dlls / wldap32 / compare.c
blob1ab36b7c75c8aa899338a57c002f43e56e1a957d
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 #endif
36 #include "winldap_private.h"
37 #include "wldap32.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
41 /***********************************************************************
42 * ldap_compareA (WLDAP32.@)
44 * See ldap_compareW.
46 ULONG CDECL ldap_compareA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value )
48 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
49 #ifdef HAVE_LDAP
50 WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
52 ret = ~0u;
54 TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(attr),
55 debugstr_a(value) );
57 if (!ld || !attr) return ~0u;
59 if (dn) {
60 dnW = strAtoW( dn );
61 if (!dnW) goto exit;
64 attrW = strAtoW( attr );
65 if (!attrW) goto exit;
67 if (value) {
68 valueW = strAtoW( value );
69 if (!valueW) goto exit;
72 ret = ldap_compareW( ld, dnW, attrW, valueW );
74 exit:
75 strfreeW( dnW );
76 strfreeW( attrW );
77 strfreeW( valueW );
79 #endif
80 return ret;
83 /***********************************************************************
84 * ldap_compareW (WLDAP32.@)
86 * Check if an attribute has a certain value (asynchronous operation).
88 * PARAMS
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.
94 * RETURNS
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;
101 #ifdef HAVE_LDAP
102 char *dnU = NULL, *attrU = NULL, *valueU = NULL;
103 struct berval val = { 0, NULL };
104 int msg;
106 ret = ~0u;
108 TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(attr),
109 debugstr_w(value) );
111 if (!ld || !attr) return ~0u;
113 if (dn) {
114 dnU = strWtoU( dn );
115 if (!dnU) goto exit;
118 attrU = strWtoU( attr );
119 if (!attrU) goto exit;
121 if (value) {
122 valueU = strWtoU( value );
123 if (!valueU) goto exit;
125 val.bv_len = strlen( valueU );
126 val.bv_val = valueU;
129 ret = ldap_compare_ext( ld, dn ? dnU : "", attrU, &val, NULL, NULL, &msg );
131 if (ret == LDAP_SUCCESS)
132 ret = msg;
133 else
134 ret = ~0u;
136 exit:
137 strfreeU( dnU );
138 strfreeU( attrU );
139 strfreeU( valueU );
141 #endif
142 return ret;
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,
152 ULONG *message )
154 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
155 #ifdef HAVE_LDAP
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;
167 if (dn) {
168 dnW = strAtoW( dn );
169 if (!dnW) goto exit;
171 if (attr) {
172 attrW = strAtoW( attr );
173 if (!attrW) goto exit;
175 if (value) {
176 valueW = strAtoW( value );
177 if (!valueW) goto exit;
179 if (serverctrls) {
180 serverctrlsW = controlarrayAtoW( serverctrls );
181 if (!serverctrlsW) goto exit;
183 if (clientctrls) {
184 clientctrlsW = controlarrayAtoW( clientctrls );
185 if (!clientctrlsW) goto exit;
188 ret = ldap_compare_extW( ld, dnW, attrW, valueW, data,
189 serverctrlsW, clientctrlsW, message );
191 exit:
192 strfreeW( dnW );
193 strfreeW( attrW );
194 strfreeW( valueW );
195 controlarrayfreeW( serverctrlsW );
196 controlarrayfreeW( clientctrlsW );
198 #endif
199 return ret;
202 /***********************************************************************
203 * ldap_compare_extW (WLDAP32.@)
205 * Check if an attribute has a certain value (asynchronous operation).
207 * PARAMS
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.
217 * RETURNS
218 * Success: LDAP_SUCCESS
219 * Failure: An LDAP error code.
221 * NOTES
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,
228 ULONG *message )
230 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
231 #ifdef HAVE_LDAP
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;
245 if (dn) {
246 dnU = strWtoU( dn );
247 if (!dnU) goto exit;
250 attrU = strWtoU( attr );
251 if (!attrU) goto exit;
253 if (!data) {
254 if (value) {
255 valueU = strWtoU( value );
256 if (!valueU) goto exit;
258 val.bv_len = strlen( valueU );
259 val.bv_val = valueU;
262 if (serverctrls) {
263 serverctrlsU = controlarrayWtoU( serverctrls );
264 if (!serverctrlsU) goto exit;
266 if (clientctrls) {
267 clientctrlsU = controlarrayWtoU( clientctrls );
268 if (!clientctrlsU) goto exit;
271 ret = map_error( ldap_compare_ext( ld, dn ? dnU : "", attrU, data ? (struct berval *)data : &val,
272 serverctrlsU, clientctrlsU, (int *)message ));
274 exit:
275 strfreeU( dnU );
276 strfreeU( attrU );
277 strfreeU( valueU );
278 controlarrayfreeU( serverctrlsU );
279 controlarrayfreeU( clientctrlsU );
281 #endif
282 return ret;
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;
294 #ifdef HAVE_LDAP
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,
302 clientctrls );
304 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
306 if (dn) {
307 dnW = strAtoW( dn );
308 if (!dnW) goto exit;
310 if (attr) {
311 attrW = strAtoW( attr );
312 if (!attrW) goto exit;
314 if (value) {
315 valueW = strAtoW( value );
316 if (!valueW) goto exit;
318 if (serverctrls) {
319 serverctrlsW = controlarrayAtoW( serverctrls );
320 if (!serverctrlsW) goto exit;
322 if (clientctrls) {
323 clientctrlsW = controlarrayAtoW( clientctrls );
324 if (!clientctrlsW) goto exit;
327 ret = ldap_compare_ext_sW( ld, dnW, attrW, valueW, data, serverctrlsW,
328 clientctrlsW );
330 exit:
331 strfreeW( dnW );
332 strfreeW( attrW );
333 strfreeW( valueW );
334 controlarrayfreeW( serverctrlsW );
335 controlarrayfreeW( clientctrlsW );
337 #endif
338 return ret;
341 /***********************************************************************
342 * ldap_compare_ext_sW (WLDAP32.@)
344 * Check if an attribute has a certain value (synchronous operation).
346 * PARAMS
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.
355 * RETURNS
356 * Success: LDAP_SUCCESS
357 * Failure: An LDAP error code.
359 * NOTES
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;
368 #ifdef HAVE_LDAP
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,
377 clientctrls );
379 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
381 if (dn) {
382 dnU = strWtoU( dn );
383 if (!dnU) goto exit;
385 if (attr) {
386 attrU = strWtoU( attr );
387 if (!attrU) goto exit;
389 if (!data) {
390 if (value) {
391 valueU = strWtoU( value );
392 if (!valueU) goto exit;
394 val.bv_len = strlen( valueU );
395 val.bv_val = valueU;
398 if (serverctrls) {
399 serverctrlsU = controlarrayWtoU( serverctrls );
400 if (!serverctrlsU) goto exit;
402 if (clientctrls) {
403 clientctrlsU = controlarrayWtoU( clientctrls );
404 if (!clientctrlsU) goto exit;
407 ret = map_error( ldap_compare_ext_s( ld, dn ? dnU : "", attr ? attrU : "",
408 data ? (struct berval *)data : &val,
409 serverctrlsU, clientctrlsU ));
411 exit:
412 strfreeU( dnU );
413 strfreeU( attrU );
414 strfreeU( valueU );
415 controlarrayfreeU( serverctrlsU );
416 controlarrayfreeU( clientctrlsU );
418 #endif
419 return ret;
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;
430 #ifdef HAVE_LDAP
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),
436 debugstr_a(value) );
438 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
440 if (dn) {
441 dnW = strAtoW( dn );
442 if (!dnW) goto exit;
444 if (attr) {
445 attrW = strAtoW( attr );
446 if (!attrW) goto exit;
448 if (value) {
449 valueW = strAtoW( value );
450 if (!valueW) goto exit;
453 ret = ldap_compare_sW( ld, dnW, attrW, valueW );
455 exit:
456 strfreeW( dnW );
457 strfreeW( attrW );
458 strfreeW( valueW );
460 #endif
461 return ret;
464 /***********************************************************************
465 * ldap_compare_sW (WLDAP32.@)
467 * Check if an attribute has a certain value (synchronous operation).
469 * PARAMS
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.
475 * RETURNS
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;
482 #ifdef HAVE_LDAP
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),
489 debugstr_w(value) );
491 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
493 if (dn) {
494 dnU = strWtoU( dn );
495 if (!dnU) goto exit;
497 if (attr) {
498 attrU = strWtoU( attr );
499 if (!attrU) goto exit;
501 if (value) {
502 valueU = strWtoU( value );
503 if (!valueU) goto exit;
505 val.bv_len = strlen( valueU );
506 val.bv_val = valueU;
509 ret = map_error( ldap_compare_ext_s( ld, dn ? dnU : "", attr ? attrU : "", &val, NULL, NULL ));
511 exit:
512 strfreeU( dnU );
513 strfreeU( attrU );
514 strfreeU( valueU );
516 #endif
517 return ret;