ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

compare.c
Go to the documentation of this file.
00001 /*
00002  * WLDAP32 - LDAP support for Wine
00003  *
00004  * Copyright 2005 Hans Leidekker
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "config.h"
00022 
00023 #include "wine/port.h"
00024 #include "wine/debug.h"
00025 
00026 #include <stdarg.h>
00027 
00028 #include "windef.h"
00029 #include "winbase.h"
00030 #include "winnls.h"
00031 
00032 #ifdef HAVE_LDAP_H
00033 #include <ldap.h>
00034 #endif
00035 
00036 #include "winldap_private.h"
00037 #include "wldap32.h"
00038 
00039 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
00040 
00041 /***********************************************************************
00042  *      ldap_compareA     (WLDAP32.@)
00043  *
00044  * See ldap_compareW.
00045  */
00046 ULONG CDECL ldap_compareA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value )
00047 {
00048     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00049 #ifdef HAVE_LDAP
00050     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
00051 
00052     ret = ~0u;
00053 
00054     TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(attr),
00055            debugstr_a(value) );
00056 
00057     if (!ld || !attr) return ~0u;
00058 
00059     if (dn) {
00060         dnW = strAtoW( dn );
00061         if (!dnW) goto exit;
00062     }
00063 
00064     attrW = strAtoW( attr );
00065     if (!attrW) goto exit;
00066 
00067     if (value) {
00068         valueW = strAtoW( value );
00069         if (!valueW) goto exit;
00070     }
00071 
00072     ret = ldap_compareW( ld, dnW, attrW, valueW );
00073 
00074 exit:
00075     strfreeW( dnW );
00076     strfreeW( attrW );
00077     strfreeW( valueW );
00078 
00079 #endif
00080     return ret;
00081 }
00082 
00083 /***********************************************************************
00084  *      ldap_compareW     (WLDAP32.@)
00085  *
00086  * Check if an attribute has a certain value (asynchronous operation).
00087  *
00088  * PARAMS
00089  *  ld      [I] Pointer to an LDAP context.
00090  *  dn      [I] DN of entry to compare value for.
00091  *  attr    [I] Attribute to compare value for.
00092  *  value   [I] Value to compare.
00093  *
00094  * RETURNS
00095  *  Success: Message ID of the compare operation.
00096  *  Failure: An LDAP error code.
00097  */
00098 ULONG CDECL ldap_compareW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value )
00099 {
00100     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00101 #ifdef HAVE_LDAP
00102     char *dnU = NULL, *attrU = NULL, *valueU = NULL;
00103     struct berval val = { 0, NULL };
00104     int msg;
00105 
00106     ret = ~0u;
00107 
00108     TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(attr),
00109            debugstr_w(value) );
00110 
00111     if (!ld || !attr) return ~0u;
00112 
00113     if (dn) {
00114         dnU = strWtoU( dn );
00115         if (!dnU) goto exit;
00116     }
00117 
00118     attrU = strWtoU( attr );
00119     if (!attrU) goto exit;
00120 
00121     if (value) {
00122         valueU = strWtoU( value );
00123         if (!valueU) goto exit;
00124 
00125         val.bv_len = strlen( valueU );
00126         val.bv_val = valueU;
00127     }
00128 
00129     ret = ldap_compare_ext( ld, dn ? dnU : "", attrU, &val, NULL, NULL, &msg );
00130 
00131     if (ret == LDAP_SUCCESS)
00132         ret = msg;
00133     else
00134         ret = ~0u;
00135 
00136 exit:
00137     strfreeU( dnU );
00138     strfreeU( attrU );
00139     strfreeU( valueU );
00140 
00141 #endif
00142     return ret;
00143 }
00144 
00145 /***********************************************************************
00146  *      ldap_compare_extA     (WLDAP32.@)
00147  *
00148  * See ldap_compare_extW.
00149  */
00150 ULONG CDECL ldap_compare_extA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value,
00151     struct WLDAP32_berval *data, PLDAPControlA *serverctrls, PLDAPControlA *clientctrls,
00152     ULONG *message )
00153 {
00154     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00155 #ifdef HAVE_LDAP
00156     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
00157     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
00158 
00159     ret = WLDAP32_LDAP_NO_MEMORY;
00160 
00161     TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
00162            debugstr_a(attr), debugstr_a(value), data, serverctrls,
00163            clientctrls, message );
00164 
00165     if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
00166 
00167     if (dn) {
00168         dnW = strAtoW( dn );
00169         if (!dnW) goto exit;
00170     }
00171     if (attr) {
00172         attrW = strAtoW( attr );
00173         if (!attrW) goto exit;
00174     }
00175     if (value) {
00176         valueW = strAtoW( value );
00177         if (!valueW) goto exit;
00178     }
00179     if (serverctrls) {
00180         serverctrlsW = controlarrayAtoW( serverctrls );
00181         if (!serverctrlsW) goto exit;
00182     }
00183     if (clientctrls) {
00184         clientctrlsW = controlarrayAtoW( clientctrls );
00185         if (!clientctrlsW) goto exit;
00186     }
00187 
00188     ret = ldap_compare_extW( ld, dnW, attrW, valueW, data,
00189                              serverctrlsW, clientctrlsW, message );
00190 
00191 exit:
00192     strfreeW( dnW );
00193     strfreeW( attrW );
00194     strfreeW( valueW );
00195     controlarrayfreeW( serverctrlsW );
00196     controlarrayfreeW( clientctrlsW );
00197 
00198 #endif
00199     return ret;
00200 }
00201 
00202 /***********************************************************************
00203  *      ldap_compare_extW     (WLDAP32.@)
00204  *
00205  * Check if an attribute has a certain value (asynchronous operation).
00206  *
00207  * PARAMS
00208  *  ld          [I] Pointer to an LDAP context.
00209  *  dn          [I] DN of entry to compare value for.
00210  *  attr        [I] Attribute to compare value for.
00211  *  value       [I] string encoded value to compare.
00212  *  data        [I] berval encoded value to compare.
00213  *  serverctrls [I] Array of LDAP server controls.
00214  *  clientctrls [I] Array of LDAP client controls.
00215  *  message     [O] Message ID of the compare operation.
00216  *
00217  * RETURNS
00218  *  Success: LDAP_SUCCESS
00219  *  Failure: An LDAP error code.
00220  *
00221  * NOTES
00222  *  Set value to compare strings or data to compare binary values. If
00223  *  both are non-NULL, data will be used. The serverctrls and clientctrls
00224  *  parameters are optional and should be set to NULL if not used.
00225  */
00226 ULONG CDECL ldap_compare_extW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value,
00227     struct WLDAP32_berval *data, PLDAPControlW *serverctrls, PLDAPControlW *clientctrls,
00228     ULONG *message )
00229 {
00230     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00231 #ifdef HAVE_LDAP
00232     char *dnU = NULL, *attrU = NULL, *valueU = NULL;
00233     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
00234     struct berval val = { 0, NULL };
00235 
00236     ret = WLDAP32_LDAP_NO_MEMORY;
00237 
00238     TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
00239            debugstr_w(attr), debugstr_w(value), data, serverctrls,
00240            clientctrls, message );
00241 
00242     if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
00243     if (!attr) return WLDAP32_LDAP_NO_MEMORY;
00244 
00245     if (dn) {
00246         dnU = strWtoU( dn );
00247         if (!dnU) goto exit;
00248     }
00249 
00250     attrU = strWtoU( attr );
00251     if (!attrU) goto exit;
00252 
00253     if (!data) {
00254         if (value) {
00255             valueU = strWtoU( value );
00256             if (!valueU) goto exit;
00257 
00258             val.bv_len = strlen( valueU );
00259             val.bv_val = valueU;
00260         }
00261     }
00262     if (serverctrls) {
00263         serverctrlsU = controlarrayWtoU( serverctrls );
00264         if (!serverctrlsU) goto exit;
00265     }
00266     if (clientctrls) {
00267         clientctrlsU = controlarrayWtoU( clientctrls );
00268         if (!clientctrlsU) goto exit;
00269     }
00270 
00271     ret = map_error( ldap_compare_ext( ld, dn ? dnU : "", attrU, data ? (struct berval *)data : &val,
00272                                        serverctrlsU, clientctrlsU, (int *)message ));
00273 
00274 exit:
00275     strfreeU( dnU );
00276     strfreeU( attrU );
00277     strfreeU( valueU );
00278     controlarrayfreeU( serverctrlsU );
00279     controlarrayfreeU( clientctrlsU );
00280 
00281 #endif
00282     return ret;
00283 }
00284 
00285 /***********************************************************************
00286  *      ldap_compare_ext_sA     (WLDAP32.@)
00287  *
00288  * See ldap_compare_ext_sW.
00289  */
00290 ULONG CDECL ldap_compare_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value,
00291     struct WLDAP32_berval *data, PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
00292 {
00293     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00294 #ifdef HAVE_LDAP
00295     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
00296     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
00297 
00298     ret = WLDAP32_LDAP_NO_MEMORY;
00299 
00300     TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld, debugstr_a(dn),
00301            debugstr_a(attr), debugstr_a(value), data, serverctrls,
00302            clientctrls );
00303 
00304     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
00305 
00306     if (dn) {
00307         dnW = strAtoW( dn );
00308         if (!dnW) goto exit;
00309     }
00310     if (attr) {
00311         attrW = strAtoW( attr );
00312         if (!attrW) goto exit;
00313     }
00314     if (value) {
00315         valueW = strAtoW( value );
00316         if (!valueW) goto exit;
00317     }
00318     if (serverctrls) {
00319         serverctrlsW = controlarrayAtoW( serverctrls );
00320         if (!serverctrlsW) goto exit;
00321     }
00322     if (clientctrls) {
00323         clientctrlsW = controlarrayAtoW( clientctrls );
00324         if (!clientctrlsW) goto exit;
00325     }
00326 
00327     ret = ldap_compare_ext_sW( ld, dnW, attrW, valueW, data, serverctrlsW,
00328                                clientctrlsW );
00329 
00330 exit:
00331     strfreeW( dnW );
00332     strfreeW( attrW );
00333     strfreeW( valueW );
00334     controlarrayfreeW( serverctrlsW );
00335     controlarrayfreeW( clientctrlsW );
00336 
00337 #endif
00338     return ret;
00339 }
00340 
00341 /***********************************************************************
00342  *      ldap_compare_ext_sW     (WLDAP32.@)
00343  *
00344  * Check if an attribute has a certain value (synchronous operation).
00345  *
00346  * PARAMS
00347  *  ld          [I] Pointer to an LDAP context.
00348  *  dn          [I] DN of entry to compare value for.
00349  *  attr        [I] Attribute to compare value for.
00350  *  value       [I] string encoded value to compare.
00351  *  data        [I] berval encoded value to compare.
00352  *  serverctrls [I] Array of LDAP server controls.
00353  *  clientctrls [I] Array of LDAP client controls.
00354  *
00355  * RETURNS
00356  *  Success: LDAP_SUCCESS
00357  *  Failure: An LDAP error code.
00358  *
00359  * NOTES
00360  *  Set value to compare strings or data to compare binary values. If
00361  *  both are non-NULL, data will be used. The serverctrls and clientctrls
00362  *  parameters are optional and should be set to NULL if not used.
00363  */
00364 ULONG CDECL ldap_compare_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value,
00365     struct WLDAP32_berval *data, PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
00366 {
00367     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00368 #ifdef HAVE_LDAP
00369     char *dnU = NULL, *attrU = NULL, *valueU = NULL;
00370     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
00371     struct berval val = { 0, NULL };
00372 
00373     ret = WLDAP32_LDAP_NO_MEMORY;
00374 
00375     TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld, debugstr_w(dn),
00376            debugstr_w(attr), debugstr_w(value), data, serverctrls,
00377            clientctrls );
00378 
00379     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
00380 
00381     if (dn) {
00382         dnU = strWtoU( dn );
00383         if (!dnU) goto exit;
00384     }
00385     if (attr) {
00386         attrU = strWtoU( attr );
00387         if (!attrU) goto exit;
00388     }
00389     if (!data) {
00390         if (value) {
00391             valueU = strWtoU( value );
00392             if (!valueU) goto exit;
00393 
00394             val.bv_len = strlen( valueU );
00395             val.bv_val = valueU;
00396         }
00397     }
00398     if (serverctrls) {
00399         serverctrlsU = controlarrayWtoU( serverctrls );
00400         if (!serverctrlsU) goto exit;
00401     }
00402     if (clientctrls) {
00403         clientctrlsU = controlarrayWtoU( clientctrls );
00404         if (!clientctrlsU) goto exit;
00405     }
00406 
00407     ret = map_error( ldap_compare_ext_s( ld, dn ? dnU : "", attr ? attrU : "",
00408                                          data ? (struct berval *)data : &val,
00409                                          serverctrlsU, clientctrlsU ));
00410 
00411 exit:
00412     strfreeU( dnU );
00413     strfreeU( attrU );
00414     strfreeU( valueU );
00415     controlarrayfreeU( serverctrlsU );
00416     controlarrayfreeU( clientctrlsU );
00417 
00418 #endif
00419     return ret;
00420 }
00421 
00422 /***********************************************************************
00423  *      ldap_compare_sA     (WLDAP32.@)
00424  *
00425  * See ldap_compare_sW.
00426  */
00427 ULONG CDECL ldap_compare_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value )
00428 {
00429     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00430 #ifdef HAVE_LDAP
00431     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
00432 
00433     ret = WLDAP32_LDAP_NO_MEMORY;
00434 
00435     TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(attr),
00436            debugstr_a(value) );
00437 
00438     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
00439 
00440     if (dn) {
00441         dnW = strAtoW( dn );
00442         if (!dnW) goto exit;
00443     }
00444     if (attr) {
00445         attrW = strAtoW( attr );
00446         if (!attrW) goto exit;
00447     }
00448     if (value) {
00449         valueW = strAtoW( value );
00450         if (!valueW) goto exit;
00451     }
00452 
00453     ret = ldap_compare_sW( ld, dnW, attrW, valueW );
00454 
00455 exit:
00456     strfreeW( dnW );
00457     strfreeW( attrW );
00458     strfreeW( valueW );
00459 
00460 #endif
00461     return ret;
00462 }
00463 
00464 /***********************************************************************
00465  *      ldap_compare_sW     (WLDAP32.@)
00466  *
00467  * Check if an attribute has a certain value (synchronous operation).
00468  *
00469  * PARAMS
00470  *  ld      [I] Pointer to an LDAP context.
00471  *  dn      [I] DN of entry to compare value for.
00472  *  attr    [I] Attribute to compare value for.
00473  *  value   [I] Value to compare.
00474  *
00475  * RETURNS
00476  *  Success: LDAP_SUCCESS
00477  *  Failure: An LDAP error code.
00478  */
00479 ULONG CDECL ldap_compare_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value )
00480 {
00481     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00482 #ifdef HAVE_LDAP
00483     char *dnU = NULL, *attrU = NULL, *valueU = NULL;
00484     struct berval val = { 0, NULL };
00485 
00486     ret = WLDAP32_LDAP_NO_MEMORY;
00487 
00488     TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(attr),
00489            debugstr_w(value) );
00490 
00491     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
00492 
00493     if (dn) {
00494         dnU = strWtoU( dn );
00495         if (!dnU) goto exit;
00496     }
00497     if (attr) {
00498         attrU = strWtoU( attr );
00499         if (!attrU) goto exit;
00500     }
00501     if (value) {
00502         valueU = strWtoU( value );
00503         if (!valueU) goto exit;
00504 
00505         val.bv_len = strlen( valueU );
00506         val.bv_val = valueU;
00507     }
00508 
00509     ret = map_error( ldap_compare_ext_s( ld, dn ? dnU : "", attr ? attrU : "", &val, NULL, NULL ));
00510 
00511 exit:
00512     strfreeU( dnU );
00513     strfreeU( attrU );
00514     strfreeU( valueU );
00515 
00516 #endif
00517     return ret;
00518 }

Generated on Sun May 27 2012 04:27:04 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.