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

parse.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_parse_extended_resultA     (WLDAP32.@)
00043  *
00044  * See ldap_parse_extended_resultW.
00045  */
00046 ULONG CDECL ldap_parse_extended_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
00047     PCHAR *oid, struct WLDAP32_berval **data, BOOLEAN free )
00048 {
00049     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00050 #ifdef HAVE_LDAP
00051     WCHAR *oidW = NULL;
00052 
00053     TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
00054 
00055     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
00056     if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
00057 
00058     ret = ldap_parse_extended_resultW( ld, result, &oidW, data, free );
00059 
00060     if (oid) {
00061         *oid = strWtoA( oidW );
00062         if (!*oid) ret = WLDAP32_LDAP_NO_MEMORY;
00063         ldap_memfreeW( oidW );
00064     }
00065 
00066 #endif
00067     return ret;
00068 }
00069 
00070 /***********************************************************************
00071  *      ldap_parse_extended_resultW     (WLDAP32.@)
00072  *
00073  * Parse the result of an extended operation. 
00074  *
00075  * PARAMS
00076  *  ld      [I] Pointer to an LDAP context.
00077  *  result  [I] Result message from an extended operation.
00078  *  oid     [O] OID of the extended operation.
00079  *  data    [O] Result data.
00080  *  free    [I] Free the result message?
00081  *
00082  * RETURNS
00083  *  Success: LDAP_SUCCESS
00084  *  Failure: An LDAP error code.
00085  *
00086  * NOTES
00087  *  Free the OID and result data with ldap_memfree. Pass a nonzero
00088  *  value for 'free' or call ldap_msgfree to free the result message.
00089  */
00090 ULONG CDECL ldap_parse_extended_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
00091     PWCHAR *oid, struct WLDAP32_berval **data, BOOLEAN free )
00092 {
00093     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00094 #ifdef HAVE_LDAP
00095     char *oidU = NULL;
00096 
00097     TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
00098 
00099     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
00100     if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
00101 
00102     ret = map_error( ldap_parse_extended_result( ld, result, &oidU, (struct berval **)data, free ) );
00103 
00104     if (oid) {
00105         *oid = strUtoW( oidU );
00106         if (!*oid) ret = WLDAP32_LDAP_NO_MEMORY;
00107         ldap_memfree( oidU );
00108     }
00109 
00110 #endif
00111     return ret;
00112 }
00113 
00114 /***********************************************************************
00115  *      ldap_parse_referenceA     (WLDAP32.@)
00116  *
00117  * See ldap_parse_referenceW.
00118  */
00119 ULONG CDECL ldap_parse_referenceA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message,
00120     PCHAR **referrals )
00121 {
00122     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00123 #ifdef HAVE_LDAP
00124     WCHAR **referralsW = NULL;
00125 
00126     TRACE( "(%p, %p, %p)\n", ld, message, referrals );
00127 
00128     if (!ld) return ~0u;
00129 
00130     ret = ldap_parse_referenceW( ld, message, &referralsW );
00131 
00132     *referrals = strarrayWtoA( referralsW );
00133     ldap_value_freeW( referralsW );
00134 
00135 #endif 
00136     return ret;
00137 }
00138 
00139 /***********************************************************************
00140  *      ldap_parse_referenceW     (WLDAP32.@)
00141  *
00142  * Return any referrals from a result message.
00143  *
00144  * PARAMS
00145  *  ld         [I] Pointer to an LDAP context.
00146  *  result     [I] Result message.
00147  *  referrals  [O] Array of referral URLs.
00148  *
00149  * RETURNS
00150  *  Success: LDAP_SUCCESS
00151  *  Failure: An LDAP error code.
00152  *
00153  * NOTES
00154  *  Free the referrals with ldap_value_free.
00155  */
00156 ULONG CDECL ldap_parse_referenceW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message,
00157     PWCHAR **referrals )
00158 {
00159     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00160 #ifdef HAVE_LDAP_PARSE_REFERENCE
00161     char **referralsU = NULL;
00162 
00163     TRACE( "(%p, %p, %p)\n", ld, message, referrals );
00164 
00165     if (!ld) return ~0u;
00166     
00167     ret = map_error( ldap_parse_reference( ld, message, &referralsU, NULL, 0 ));
00168 
00169     *referrals = strarrayUtoW( referralsU );
00170     ldap_memfree( referralsU );
00171 
00172 #endif
00173     return ret;
00174 }
00175 
00176 /***********************************************************************
00177  *      ldap_parse_resultA     (WLDAP32.@)
00178  *
00179  * See ldap_parse_resultW.
00180  */
00181 ULONG CDECL ldap_parse_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
00182     ULONG *retcode, PCHAR *matched, PCHAR *error, PCHAR **referrals,
00183     PLDAPControlA **serverctrls, BOOLEAN free )
00184 {
00185     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00186 #ifdef HAVE_LDAP
00187     WCHAR *matchedW = NULL, *errorW = NULL, **referralsW = NULL;
00188     LDAPControlW **serverctrlsW = NULL;
00189 
00190     TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode,
00191            matched, error, referrals, serverctrls, free );
00192 
00193     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
00194 
00195     ret = ldap_parse_resultW( ld, result, retcode, &matchedW, &errorW,
00196                               &referralsW, &serverctrlsW, free );
00197 
00198     if (matched) *matched = strWtoA( matchedW );
00199     if (error) *error = strWtoA( errorW );
00200 
00201     if (referrals) *referrals = strarrayWtoA( referralsW );
00202     if (serverctrls) *serverctrls = controlarrayWtoA( serverctrlsW );
00203 
00204     ldap_memfreeW( matchedW );
00205     ldap_memfreeW( errorW );
00206     ldap_value_freeW( referralsW );
00207     ldap_controls_freeW( serverctrlsW );
00208 
00209 #endif
00210     return ret;
00211 }
00212 
00213 /***********************************************************************
00214  *      ldap_parse_resultW     (WLDAP32.@)
00215  *
00216  * Parse a result message. 
00217  *
00218  * PARAMS
00219  *  ld           [I] Pointer to an LDAP context.
00220  *  result       [I] Result message.
00221  *  retcode      [O] Return code for the server operation.
00222  *  matched      [O] DNs matched in the operation.
00223  *  error        [O] Error message for the operation.
00224  *  referrals    [O] Referrals found in the result message.
00225  *  serverctrls  [O] Controls used in the operation.
00226  *  free         [I] Free the result message?
00227  *
00228  * RETURNS
00229  *  Success: LDAP_SUCCESS
00230  *  Failure: An LDAP error code.
00231  *
00232  * NOTES
00233  *  Free the DNs and error message with ldap_memfree. Free
00234  *  the referrals with ldap_value_free and the controls with
00235  *  ldap_controls_free. Pass a nonzero value for 'free' or call
00236  *  ldap_msgfree to free the result message.
00237  */
00238 ULONG CDECL ldap_parse_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
00239     ULONG *retcode, PWCHAR *matched, PWCHAR *error, PWCHAR **referrals,
00240     PLDAPControlW **serverctrls, BOOLEAN free )
00241 {
00242     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00243 #ifdef HAVE_LDAP
00244     char *matchedU = NULL, *errorU = NULL, **referralsU = NULL;
00245     LDAPControl **serverctrlsU = NULL;
00246 
00247     TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode,
00248            matched, error, referrals, serverctrls, free );
00249 
00250     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
00251 
00252     ret = map_error( ldap_parse_result( ld, result, (int *)retcode, &matchedU, &errorU,
00253                                         &referralsU, &serverctrlsU, free ));
00254 
00255     if (matched) *matched = strUtoW( matchedU );
00256     if (error) *error = strUtoW( errorU );
00257 
00258     if (referrals) *referrals = strarrayUtoW( referralsU );
00259     if (serverctrls) *serverctrls = controlarrayUtoW( serverctrlsU );
00260 
00261     ldap_memfree( matchedU );
00262     ldap_memfree( errorU );
00263     strarrayfreeU( referralsU );
00264     ldap_controls_free( serverctrlsU );
00265 
00266 #endif
00267     return ret;
00268 }
00269 
00270 /***********************************************************************
00271  *      ldap_parse_sort_controlA     (WLDAP32.@)
00272  *
00273  * See ldap_parse_sort_controlW.
00274  */
00275 ULONG CDECL ldap_parse_sort_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
00276     ULONG *result, PCHAR *attr )
00277 {
00278     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00279 #ifdef HAVE_LDAP
00280     WCHAR *attrW = NULL;
00281     LDAPControlW **controlW = NULL;
00282 
00283     TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
00284 
00285     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
00286     if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
00287 
00288     controlW = controlarrayAtoW( control );
00289     if (!controlW) return WLDAP32_LDAP_NO_MEMORY;
00290 
00291     ret = ldap_parse_sort_controlW( ld, controlW, result, &attrW );
00292 
00293     *attr = strWtoA( attrW );
00294     controlarrayfreeW( controlW );
00295 
00296 #endif
00297     return ret;
00298 }
00299 
00300 /***********************************************************************
00301  *      ldap_parse_sort_controlW     (WLDAP32.@)
00302  *
00303  * Parse a sort control.
00304  *
00305  * PARAMS
00306  *  ld       [I] Pointer to an LDAP context.
00307  *  control  [I] Control obtained from a result message.
00308  *  result   [O] Result code.
00309  *  attr     [O] Failing attribute.
00310  *
00311  * RETURNS
00312  *  Success: LDAP_SUCCESS
00313  *  Failure: An LDAP error code.
00314  *
00315  * NOTES
00316  *  If the function fails, free the failing attribute with ldap_memfree.
00317  */
00318 ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
00319     ULONG *result, PWCHAR *attr )
00320 {
00321     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
00322 #ifdef HAVE_LDAP
00323     char *attrU = NULL;
00324     LDAPControl **controlU = NULL;
00325 #ifdef HAVE_LDAP_PARSE_SORT_CONTROL
00326     unsigned long res;
00327 #elif defined(HAVE_LDAP_PARSE_SORTRESPONSE_CONTROL)
00328     ber_int_t res;
00329     LDAPControl *sortcontrol = NULL;
00330     unsigned int i;
00331 #endif
00332 
00333     TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
00334 
00335     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
00336     if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
00337 
00338     controlU = controlarrayWtoU( control );
00339     if (!controlU) return WLDAP32_LDAP_NO_MEMORY;
00340 
00341 #ifdef HAVE_LDAP_PARSE_SORT_CONTROL
00342     if (!(ret = ldap_parse_sort_control( ld, controlU, &res, &attrU )))
00343     {
00344         *result = res;
00345         *attr = strUtoW( attrU );
00346     }
00347 #elif defined(HAVE_LDAP_PARSE_SORTRESPONSE_CONTROL)
00348     for (i = 0; controlU[i]; i++)
00349     {
00350         if (!strcmp( LDAP_SERVER_RESP_SORT_OID, controlU[i]->ldctl_oid ))
00351             sortcontrol = controlU[i];
00352     }
00353     if (!sortcontrol)
00354     {
00355         controlarrayfreeU( controlU );
00356         return WLDAP32_LDAP_CONTROL_NOT_FOUND;
00357     }
00358     if (!(ret = ldap_parse_sortresponse_control( ld, sortcontrol, &res, &attrU )))
00359     {
00360         *result = res;
00361         *attr = strUtoW( attrU );
00362     }
00363 #endif
00364     controlarrayfreeU( controlU );
00365 
00366 #endif
00367     return map_error( ret );
00368 }
00369 
00370 /***********************************************************************
00371  *      ldap_parse_vlv_controlA     (WLDAP32.@)
00372  *
00373  * See ldap_parse_vlv_controlW.
00374  */
00375 INT CDECL ldap_parse_vlv_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
00376     PULONG targetpos, PULONG listcount,
00377     struct WLDAP32_berval **context, PINT errcode )
00378 {
00379     int ret = WLDAP32_LDAP_NOT_SUPPORTED;
00380 #ifdef HAVE_LDAP
00381     LDAPControlW **controlW = NULL;
00382 
00383     TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos,
00384            listcount, context, errcode );
00385 
00386     if (!ld) return ~0u;
00387 
00388     if (control) {
00389         controlW = controlarrayAtoW( control );
00390         if (!controlW) return WLDAP32_LDAP_NO_MEMORY;
00391     }
00392 
00393     ret = ldap_parse_vlv_controlW( ld, controlW, targetpos, listcount,
00394                                    context, errcode );
00395 
00396     controlarrayfreeW( controlW );
00397 
00398 #endif
00399     return ret;
00400 }
00401 
00402 /***********************************************************************
00403  *      ldap_parse_vlv_controlW     (WLDAP32.@)
00404  *
00405  * Parse a virtual list view control.
00406  *
00407  * PARAMS
00408  *  ld         [I] Pointer to an LDAP context.
00409  *  control    [I] Controls obtained from a result message.
00410  *  targetpos  [O] Position of the target in the result list.
00411  *  listcount  [O] Estimate of the number of results in the list.
00412  *  context    [O] Server side context.
00413  *  errcode    [O] Error code from the listview operation.
00414  *
00415  * RETURNS
00416  *  Success: LDAP_SUCCESS
00417  *  Failure: An LDAP error code.
00418  *
00419  * NOTES
00420  *  Free the server context with ber_bvfree.
00421  */
00422 INT CDECL ldap_parse_vlv_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
00423     PULONG targetpos, PULONG listcount,
00424     struct WLDAP32_berval **context, PINT errcode )
00425 {
00426     int ret = WLDAP32_LDAP_NOT_SUPPORTED;
00427 #ifdef HAVE_LDAP
00428     LDAPControl **controlU = NULL;
00429 #ifdef HAVE_LDAP_PARSE_VLV_CONTROL
00430     unsigned long pos, count;
00431 #elif defined(HAVE_LDAP_PARSE_VLVRESPONSE_CONTROL)
00432     ber_int_t pos, count;
00433     LDAPControl *vlvcontrol = NULL;
00434     unsigned int i;
00435 #endif
00436 
00437     TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos,
00438            listcount, context, errcode );
00439 
00440     if (!ld || !control) return ~0u;
00441 
00442     controlU = controlarrayWtoU( control );
00443     if (!controlU) return WLDAP32_LDAP_NO_MEMORY;
00444 
00445 #ifdef HAVE_LDAP_PARSE_VLV_CONTROL
00446     if (!(ret = ldap_parse_vlv_control( ld, controlU, &pos, &count,
00447                                         context, errcode )))
00448     {
00449         *targetpos = pos;
00450         *listcount = count;
00451     }
00452 #elif defined(HAVE_LDAP_PARSE_VLVRESPONSE_CONTROL)
00453     for (i = 0; controlU[i]; i++)
00454     {
00455         if (!strcmp( LDAP_CONTROL_VLVRESPONSE, controlU[i]->ldctl_oid ))
00456             vlvcontrol = controlU[i];
00457     }
00458     if (!vlvcontrol)
00459     {
00460         controlarrayfreeU( controlU );
00461         return WLDAP32_LDAP_CONTROL_NOT_FOUND;
00462     }
00463     if (!(ret = ldap_parse_vlvresponse_control( ld, vlvcontrol, &pos, &count,
00464                                                 (struct berval **)context, errcode )))
00465     {
00466         *targetpos = pos;
00467         *listcount = count;
00468     }
00469 #endif
00470     controlarrayfreeU( controlU );
00471 
00472 #endif
00473     return map_error( ret );
00474 }

Generated on Fri May 25 2012 04:17:20 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.