• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • KDE Home
  • Contact Us
 

KLDAP Library

wce-ldap-help.h
00001 /*
00002  * winceldap - LDAP helper functions for Windows CE
00003  * Copyright 2010 Andre Heinecke
00004  *
00005  * Derived from:
00006  *
00007  * WLDAP32 - LDAP support for Wine
00008  *
00009  * Copyright 2005 Hans Leidekker
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Lesser General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2.1 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this library; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00024  */
00025 #ifndef WCE_LDAP_HELP_H
00026 #define WCE_LDAP_HELP_H
00027 ULONG map_error( int );
00028 
00029 /* A set of helper functions to convert LDAP data structures
00030  * to and from ansi (A), wide character (W) and utf8 (U) encodings.
00031  */
00032 
00033 static inline char *strdupU( const char *src )
00034 {
00035     char *dst;
00036 
00037     if (!src) return NULL;
00038     dst = ( char * )malloc( (strlen( src ) + 1) * sizeof(char) );
00039     if (dst)
00040         strcpy( dst, src );
00041     return dst;
00042 }
00043 
00044 static inline LPWSTR strAtoW( LPCSTR str )
00045 {
00046     LPWSTR ret = NULL;
00047     if (str)
00048     {
00049         DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
00050         if ((ret = ( WCHAR* )malloc( len * sizeof(WCHAR) )))
00051             MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
00052     }
00053     return ret;
00054 }
00055 
00056 static inline LPSTR strWtoA( LPCWSTR str )
00057 {
00058     LPSTR ret = NULL;
00059     if (str)
00060     {
00061         DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
00062         if ((ret = ( char* )malloc( len )))
00063             WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
00064     }
00065     return ret;
00066 }
00067 
00068 static inline char *strWtoU( LPCWSTR str )
00069 {
00070     LPSTR ret = NULL;
00071     if (str)
00072     {
00073         DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
00074         if ((ret = ( char * )malloc( len )))
00075             WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
00076     }
00077     return ret;
00078 }
00079 
00080 static inline LPWSTR strUtoW( char *str )
00081 {
00082     LPWSTR ret = NULL;
00083     if (str)
00084     {
00085         DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
00086         if ((ret = ( WCHAR* )malloc( len * sizeof(WCHAR) )))
00087             MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
00088     }
00089     return ret;
00090 }
00091 
00092 static inline DWORD strarraylenA( LPSTR *strarray )
00093 {
00094     LPSTR *p = strarray;
00095     while (*p) p++;
00096     return p - strarray;
00097 }
00098 
00099 static inline DWORD strarraylenW( LPWSTR *strarray )
00100 {
00101     LPWSTR *p = strarray;
00102     while (*p) p++;
00103     return p - strarray;
00104 }
00105 
00106 static inline DWORD strarraylenU( char **strarray )
00107 {
00108     char **p = strarray;
00109     while (*p) p++;
00110     return p - strarray;
00111 }
00112 
00113 static inline LPWSTR *strarrayAtoW( LPSTR *strarray )
00114 {
00115     LPWSTR *strarrayW = NULL;
00116     DWORD size;
00117 
00118     if (strarray)
00119     {
00120         size  = sizeof(WCHAR*) * (strarraylenA( strarray ) + 1);
00121         strarrayW = ( WCHAR** )malloc( size );
00122 
00123         if (strarrayW)
00124         {
00125             LPSTR *p = strarray;
00126             LPWSTR *q = strarrayW;
00127 
00128             while (*p) *q++ = strAtoW( *p++ );
00129             *q = NULL;
00130         }
00131     }
00132     return strarrayW;
00133 }
00134 
00135 static inline LPSTR *strarrayWtoA( LPWSTR *strarray )
00136 {
00137     LPSTR *strarrayA = NULL;
00138     DWORD size;
00139 
00140     if (strarray)
00141     {
00142         size = sizeof(LPSTR) * (strarraylenW( strarray ) + 1);
00143         strarrayA = ( char** )malloc( size );
00144 
00145         if (strarrayA)
00146         {
00147             LPWSTR *p = strarray;
00148             LPSTR *q = strarrayA;
00149 
00150             while (*p) *q++ = strWtoA( *p++ );
00151             *q = NULL;
00152         }
00153     }
00154     return strarrayA;
00155 }
00156 
00157 static inline char **strarrayWtoU( LPWSTR *strarray )
00158 {
00159     char **strarrayU = NULL;
00160     DWORD size;
00161 
00162     if (strarray)
00163     {
00164         size = sizeof(char*) * (strarraylenW( strarray ) + 1);
00165         strarrayU = ( char** )malloc( size );
00166 
00167         if (strarrayU)
00168         {
00169             LPWSTR *p = strarray;
00170             char **q = strarrayU;
00171 
00172             while (*p) *q++ = strWtoU( *p++ );
00173             *q = NULL;
00174         }
00175     }
00176     return strarrayU;
00177 }
00178 
00179 static inline LPWSTR *strarrayUtoW( char **strarray )
00180 {
00181     LPWSTR *strarrayW = NULL;
00182     DWORD size;
00183 
00184     if (strarray)
00185     {
00186         size = sizeof(WCHAR*) * (strarraylenU( strarray ) + 1);
00187         strarrayW = ( WCHAR ** )malloc( size );
00188 
00189         if (strarrayW)
00190         {
00191             char **p = strarray;
00192             LPWSTR *q = strarrayW;
00193 
00194             while (*p) *q++ = strUtoW( *p++ );
00195             *q = NULL;
00196         }
00197     }
00198     return strarrayW;
00199 }
00200 
00201 static inline void strarrayfreeA( LPSTR *strarray )
00202 {
00203     if (strarray)
00204     {
00205         LPSTR *p = strarray;
00206         while (*p) free( *p++ );
00207         free( strarray );
00208     }
00209 }
00210 
00211 static inline void strarrayfreeW( LPWSTR *strarray )
00212 {
00213     if (strarray)
00214     {
00215         LPWSTR *p = strarray;
00216         while (*p) free( *p++ );
00217         free( strarray );
00218     }
00219 }
00220 
00221 static inline void strarrayfreeU( char **strarray )
00222 {
00223     if (strarray)
00224     {
00225         char **p = strarray;
00226         while (*p) free( *p++ );
00227         free( strarray );
00228     }
00229 }
00230 
00231 static inline struct berval *bvdup( struct berval *bv )
00232 {
00233     struct berval *berval;
00234     DWORD size = sizeof(struct berval) + bv->bv_len;
00235 
00236     berval = ( struct berval * )malloc( size );
00237     if (berval)
00238     {
00239         char *val = (char *)berval + sizeof(struct berval);
00240 
00241         berval->bv_len = bv->bv_len;
00242         berval->bv_val = val;
00243         memcpy( val, bv->bv_val, bv->bv_len );
00244     }
00245     return berval;
00246 }
00247 
00248 static inline DWORD bvarraylen( struct berval **bv )
00249 {
00250     struct berval **p = bv;
00251     while (*p) p++;
00252     return p - bv;
00253 }
00254 
00255 static inline struct berval **bvarraydup( struct berval **bv )
00256 {
00257     struct berval **berval = NULL;
00258     DWORD size;
00259 
00260     if (bv)
00261     {
00262         size = sizeof(struct berval *) * (bvarraylen( bv ) + 1);
00263         berval = ( struct berval ** )malloc( size );
00264 
00265         if (berval)
00266         {
00267             struct berval **p = bv;
00268             struct berval **q = berval;
00269 
00270             while (*p) *q++ = bvdup( *p++ );
00271             *q = NULL;
00272         }
00273     }
00274     return berval;
00275 }
00276 
00277 static inline void bvarrayfree( struct berval **bv )
00278 {
00279     struct berval **p = bv;
00280     while (*p) free( *p++ );
00281     free( bv );
00282 }
00283 
00284 static inline LDAPModW *modAtoW( LDAPModA *mod )
00285 {
00286     LDAPModW *modW;
00287 
00288     modW = ( LDAPModW *)malloc( sizeof(LDAPModW) );
00289     if (modW)
00290     {
00291         modW->mod_op = mod->mod_op;
00292         modW->mod_type = strAtoW( mod->mod_type );
00293 
00294         if (mod->mod_op & LDAP_MOD_BVALUES)
00295             modW->mod_vals.modv_bvals = bvarraydup( mod->mod_vals.modv_bvals );
00296         else
00297             modW->mod_vals.modv_strvals = strarrayAtoW( mod->mod_vals.modv_strvals );
00298     }
00299     return modW;
00300 }
00301 
00302 static inline LDAPMod *modWtoU( LDAPModW *mod )
00303 {
00304     LDAPMod *modU;
00305 
00306     modU = ( LDAPMod * )malloc( sizeof(LDAPMod) );
00307     if (modU)
00308     {
00309         modU->mod_op = mod->mod_op;
00310         modU->mod_type = strWtoU( mod->mod_type );
00311 
00312         if (mod->mod_op & LDAP_MOD_BVALUES)
00313             modU->mod_vals.modv_bvals = bvarraydup( mod->mod_vals.modv_bvals );
00314         else
00315             modU->mod_vals.modv_strvals = strarrayWtoU( mod->mod_vals.modv_strvals );
00316     }
00317     return modU;
00318 }
00319 
00320 static inline void modfreeW( LDAPModW *mod )
00321 {
00322     if (mod->mod_op & LDAP_MOD_BVALUES)
00323         bvarrayfree( mod->mod_vals.modv_bvals );
00324     else
00325         strarrayfreeW( mod->mod_vals.modv_strvals );
00326     free( mod );
00327 }
00328 
00329 static inline void modfreeU( LDAPMod *mod )
00330 {
00331     if (mod->mod_op & LDAP_MOD_BVALUES)
00332         bvarrayfree( mod->mod_vals.modv_bvals );
00333     else
00334         strarrayfreeU( mod->mod_vals.modv_strvals );
00335     free( mod );
00336 }
00337 
00338 static inline DWORD modarraylenA( LDAPModA **modarray )
00339 {
00340     LDAPModA **p = modarray;
00341     while (*p) p++;
00342     return p - modarray;
00343 }
00344 
00345 static inline DWORD modarraylenW( LDAPModW **modarray )
00346 {
00347     LDAPModW **p = modarray;
00348     while (*p) p++;
00349     return p - modarray;
00350 }
00351 
00352 static inline LDAPModW **modarrayAtoW( LDAPModA **modarray )
00353 {
00354     LDAPModW **modarrayW = NULL;
00355     DWORD size;
00356 
00357     if (modarray)
00358     {
00359         size = sizeof(LDAPModW*) * (modarraylenA( modarray ) + 1);
00360         modarrayW = ( LDAPModW**)malloc( size );
00361 
00362         if (modarrayW)
00363         {
00364             LDAPModA **p = modarray;
00365             LDAPModW **q = modarrayW;
00366 
00367             while (*p) *q++ = modAtoW( *p++ );
00368             *q = NULL;
00369         }
00370     }
00371     return modarrayW;
00372 }
00373 
00374 static inline LDAPMod **modarrayWtoU( LDAPModW **modarray )
00375 {
00376     LDAPMod **modarrayU = NULL;
00377     DWORD size;
00378 
00379     if (modarray)
00380     {
00381         size = sizeof(LDAPMod*) * (modarraylenW( modarray ) + 1);
00382         modarrayU = ( LDAPMod** )malloc( size );
00383 
00384         if (modarrayU)
00385         {
00386             LDAPModW **p = modarray;
00387             LDAPMod **q = modarrayU;
00388 
00389             while (*p) *q++ = modWtoU( *p++ );
00390             *q = NULL;
00391         }
00392     }
00393     return modarrayU;
00394 }
00395 
00396 static inline void modarrayfreeW( LDAPModW **modarray )
00397 {
00398     if (modarray)
00399     {
00400         LDAPModW **p = modarray;
00401         while (*p) modfreeW( *p++ );
00402         free( modarray );
00403     }
00404 }
00405 
00406 static inline void modarrayfreeU( LDAPMod **modarray )
00407 {
00408     if (modarray)
00409     {
00410         LDAPMod **p = modarray;
00411         while (*p) modfreeU( *p++ );
00412         free( modarray );
00413     }
00414 }
00415 
00416 static inline LDAPControlW *controlAtoW( LDAPControlA *control )
00417 {
00418     LDAPControlW *controlW;
00419     DWORD len = control->ldctl_value.bv_len;
00420     char *val = NULL;
00421 
00422     if (control->ldctl_value.bv_val)
00423     {
00424         val = ( char* )malloc( len );
00425         if (!val) return NULL;
00426         memcpy( val, control->ldctl_value.bv_val, len );
00427     }
00428 
00429     controlW = ( LDAPControlW* )malloc( sizeof(LDAPControlW) );
00430     if (!controlW)
00431     {
00432         free( val );
00433         return NULL;
00434     }
00435 
00436     controlW->ldctl_oid = strAtoW( control->ldctl_oid );
00437     controlW->ldctl_value.bv_len = len; 
00438     controlW->ldctl_value.bv_val = val; 
00439     controlW->ldctl_iscritical = control->ldctl_iscritical;
00440 
00441     return controlW;
00442 }
00443 
00444 static inline LDAPControlA *controlWtoA( LDAPControlW *control )
00445 {
00446     LDAPControlA *controlA;
00447     DWORD len = control->ldctl_value.bv_len;
00448     char *val = NULL;
00449 
00450     if (control->ldctl_value.bv_val)
00451     {
00452         val = ( char* )malloc( len );
00453         if (!val) return NULL;
00454         memcpy( val, control->ldctl_value.bv_val, len );
00455     }
00456 
00457     controlA = ( LDAPControlA* )malloc( sizeof(LDAPControlA) );
00458     if (!controlA)
00459     {
00460         free( val );
00461         return NULL;
00462     }
00463 
00464     controlA->ldctl_oid = strWtoA( control->ldctl_oid );
00465     controlA->ldctl_value.bv_len = len; 
00466     controlA->ldctl_value.bv_val = val;
00467     controlA->ldctl_iscritical = control->ldctl_iscritical;
00468 
00469     return controlA;
00470 }
00471 
00472 static inline LDAPControl *controlWtoU( LDAPControlW *control )
00473 {
00474     LDAPControl *controlU;
00475     DWORD len = control->ldctl_value.bv_len;
00476     char *val = NULL;
00477 
00478     if (control->ldctl_value.bv_val)
00479     {
00480         val = ( char * )malloc( len );
00481         if (!val) return NULL;
00482         memcpy( val, control->ldctl_value.bv_val, len );
00483     }
00484 
00485     controlU = ( LDAPControl* )malloc( sizeof(LDAPControl) );
00486     if (!controlU)
00487     {
00488         free( val );
00489         return NULL;
00490     }
00491 
00492     controlU->ldctl_oid = strWtoU( control->ldctl_oid );
00493     controlU->ldctl_value.bv_len = len; 
00494     controlU->ldctl_value.bv_val = val; 
00495     controlU->ldctl_iscritical = control->ldctl_iscritical;
00496 
00497     return controlU;
00498 }
00499 
00500 static inline LDAPControlW *controlUtoW( LDAPControl *control )
00501 {
00502     LDAPControlW *controlW;
00503     DWORD len = control->ldctl_value.bv_len;
00504     char *val = NULL;
00505 
00506     if (control->ldctl_value.bv_val)
00507     {
00508         val = ( char* )malloc( len );
00509         if (!val) return NULL;
00510         memcpy( val, control->ldctl_value.bv_val, len );
00511     }
00512 
00513     controlW = ( LDAPControlW* )malloc( sizeof(LDAPControlW) );
00514     if (!controlW)
00515     {
00516         free( val );
00517         return NULL;
00518     }
00519 
00520     controlW->ldctl_oid = strUtoW( control->ldctl_oid );
00521     controlW->ldctl_value.bv_len = len; 
00522     controlW->ldctl_value.bv_val = val; 
00523     controlW->ldctl_iscritical = control->ldctl_iscritical;
00524  
00525     return controlW;
00526 }
00527 
00528 static inline void controlfreeA( LDAPControlA *control )
00529 {
00530     if (control)
00531     {
00532         free( control->ldctl_oid );
00533         free( control->ldctl_value.bv_val );
00534         free( control );
00535     }
00536 }
00537 
00538 static inline void controlfreeW( LDAPControlW *control )
00539 {
00540     if (control)
00541     {
00542         free( control->ldctl_oid );
00543         free( control->ldctl_value.bv_val );
00544         free( control );
00545     }
00546 }
00547 
00548 static inline void controlfreeU( LDAPControl *control )
00549 {
00550     if (control)
00551     {
00552         free( control->ldctl_oid );
00553         free( control->ldctl_value.bv_val );
00554         free( control );
00555     }
00556 }
00557 
00558 static inline DWORD controlarraylenA( LDAPControlA **controlarray )
00559 {
00560     LDAPControlA **p = controlarray;
00561     while (*p) p++;
00562     return p - controlarray;
00563 }
00564 
00565 static inline DWORD controlarraylenW( LDAPControlW **controlarray )
00566 {
00567     LDAPControlW **p = controlarray;
00568     while (*p) p++;
00569     return p - controlarray;
00570 }
00571 
00572 static inline DWORD controlarraylenU( LDAPControl **controlarray )
00573 {
00574     LDAPControl **p = controlarray;
00575     while (*p) p++;
00576     return p - controlarray;
00577 }
00578 
00579 static inline LDAPControlW **controlarrayAtoW( LDAPControlA **controlarray )
00580 {
00581     LDAPControlW **controlarrayW = NULL;
00582     DWORD size;
00583 
00584     if (controlarray)
00585     {
00586         size = sizeof(LDAPControlW*) * (controlarraylenA( controlarray ) + 1);
00587         controlarrayW = ( LDAPControlW ** )malloc( size );
00588 
00589         if (controlarrayW)
00590         {
00591             LDAPControlA **p = controlarray;
00592             LDAPControlW **q = controlarrayW;
00593 
00594             while (*p) *q++ = controlAtoW( *p++ );
00595             *q = NULL;
00596         }
00597     }
00598     return controlarrayW;
00599 }
00600 
00601 static inline LDAPControlA **controlarrayWtoA( LDAPControlW **controlarray )
00602 {
00603     LDAPControlA **controlarrayA = NULL;
00604     DWORD size;
00605 
00606     if (controlarray)
00607     {
00608         size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
00609         controlarrayA = ( LDAPControlA** )malloc( size );
00610 
00611         if (controlarrayA)
00612         {
00613             LDAPControlW **p = controlarray;
00614             LDAPControlA **q = controlarrayA;
00615 
00616             while (*p) *q++ = controlWtoA( *p++ );
00617             *q = NULL;
00618         }
00619     }
00620     return controlarrayA;
00621 }
00622 
00623 static inline LDAPControl **controlarrayWtoU( LDAPControlW **controlarray )
00624 {
00625     LDAPControl **controlarrayU = NULL;
00626     DWORD size;
00627 
00628     if (controlarray)
00629     {
00630         size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
00631         controlarrayU = ( LDAPControl ** )malloc( size );
00632 
00633         if (controlarrayU)
00634         {
00635             LDAPControlW **p = controlarray;
00636             LDAPControl **q = controlarrayU;
00637 
00638             while (*p) *q++ = controlWtoU( *p++ );
00639             *q = NULL;
00640         }
00641     }
00642     return controlarrayU;
00643 }
00644 
00645 static inline LDAPControlW **controlarrayUtoW( LDAPControl **controlarray )
00646 {
00647     LDAPControlW **controlarrayW = NULL;
00648     DWORD size;
00649 
00650     if (controlarray)
00651     {
00652         size = sizeof(LDAPControlW*) * (controlarraylenU( controlarray ) + 1);
00653         controlarrayW = (LDAPControlW** )malloc( size );
00654 
00655         if (controlarrayW)
00656         {
00657             LDAPControl **p = controlarray;
00658             LDAPControlW **q = controlarrayW;
00659 
00660             while (*p) *q++ = controlUtoW( *p++ );
00661             *q = NULL;
00662         }
00663     }
00664     return controlarrayW;
00665 }
00666 
00667 static inline void controlarrayfreeA( LDAPControlA **controlarray )
00668 {
00669     if (controlarray)
00670     {
00671         LDAPControlA **p = controlarray;
00672         while (*p) controlfreeA( *p++ );
00673         free( controlarray );
00674     }
00675 }
00676 
00677 static inline void controlarrayfreeW( LDAPControlW **controlarray )
00678 {
00679     if (controlarray)
00680     {
00681         LDAPControlW **p = controlarray;
00682         while (*p) controlfreeW( *p++ );
00683         free( controlarray );
00684     }
00685 }
00686 
00687 static inline void controlarrayfreeU( LDAPControl **controlarray )
00688 {
00689     if (controlarray)
00690     {
00691         LDAPControl **p = controlarray;
00692         while (*p) controlfreeU( *p++ );
00693         free( controlarray );
00694     }
00695 }
00696 
00697 #ifdef _WIN32_WCE
00698 static inline ULONG my_win_ldap_compare_ext_sA( LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value,
00699     struct berval *data, PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
00700 {
00701     ULONG ret = LDAP_NOT_SUPPORTED;
00702     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
00703     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
00704 
00705     ret = LDAP_NO_MEMORY;
00706 
00707     if (!ld) return LDAP_PARAM_ERROR;
00708 
00709     if (dn) {
00710         dnW = strAtoW( dn );
00711         if (!dnW) goto exit;
00712     }
00713     if (attr) {
00714         attrW = strAtoW( attr );
00715         if (!attrW) goto exit;
00716     }
00717     if (value) {
00718         valueW = strAtoW( value );
00719         if (!valueW) goto exit;
00720     }
00721     if (serverctrls) {
00722         serverctrlsW = controlarrayAtoW( serverctrls );
00723         if (!serverctrlsW) goto exit;
00724     }
00725     if (clientctrls) {
00726         clientctrlsW = controlarrayAtoW( clientctrls );
00727         if (!clientctrlsW) goto exit;
00728     }
00729 
00730     ret = ldap_compare_ext_sW( ld, dnW, attrW, valueW, data, serverctrlsW,
00731                                clientctrlsW );
00732 
00733 exit:
00734     free( dnW );
00735     free( attrW );
00736     free( valueW );
00737     controlarrayfreeW( serverctrlsW );
00738     controlarrayfreeW( clientctrlsW );
00739 
00740     return ret;
00741 }
00742 
00743 static inline ULONG my_win_ldap_compare_extA( LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value,
00744     struct berval *data, PLDAPControlA *serverctrls, PLDAPControlA *clientctrls,
00745     ULONG *message )
00746 {
00747     ULONG ret = LDAP_NOT_SUPPORTED;
00748     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
00749     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
00750 
00751     ret = LDAP_NO_MEMORY;
00752 
00753     if (!ld || !message) return LDAP_PARAM_ERROR;
00754 
00755     if (dn) {
00756         dnW = strAtoW( dn );
00757         if (!dnW) goto exit;
00758     }
00759     if (attr) {
00760         attrW = strAtoW( attr );
00761         if (!attrW) goto exit;
00762     }
00763     if (value) {
00764         valueW = strAtoW( value );
00765         if (!valueW) goto exit;
00766     }
00767     if (serverctrls) {
00768         serverctrlsW = controlarrayAtoW( serverctrls );
00769         if (!serverctrlsW) goto exit;
00770     }
00771     if (clientctrls) {
00772         clientctrlsW = controlarrayAtoW( clientctrls );
00773         if (!clientctrlsW) goto exit;
00774     }
00775 
00776     ret = ldap_compare_extW( ld, dnW, attrW, valueW, data,
00777                              serverctrlsW, clientctrlsW, message );
00778 
00779 exit:
00780     free( dnW );
00781     free( attrW );
00782     free( valueW );
00783     controlarrayfreeW( serverctrlsW );
00784     controlarrayfreeW( clientctrlsW );
00785 
00786     return ret;
00787 }
00788 
00789 static inline ULONG my_win_ldap_modify_ext_sA( LDAP *ld, PCHAR dn, LDAPModA *mods[],
00790     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
00791 {
00792     ULONG ret = LDAP_NOT_SUPPORTED;
00793     WCHAR *dnW = NULL;
00794     LDAPModW **modsW = NULL;
00795     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
00796 
00797     ret = LDAP_NO_MEMORY;
00798 
00799     if (!ld) return LDAP_PARAM_ERROR;
00800 
00801     if (dn) {
00802         dnW = strAtoW( dn );
00803         if (!dnW) goto exit;
00804     }
00805     if (mods) {
00806         modsW = modarrayAtoW( mods );
00807         if (!modsW) goto exit;
00808     }
00809     if (serverctrls) {
00810         serverctrlsW = controlarrayAtoW( serverctrls );
00811         if (!serverctrlsW) goto exit;
00812     }
00813     if (clientctrls) {
00814         clientctrlsW = controlarrayAtoW( clientctrls );
00815         if (!clientctrlsW) goto exit;
00816     }
00817 
00818     ret = ldap_modify_ext_sW( ld, dnW, modsW, serverctrlsW, clientctrlsW );
00819 
00820 exit:
00821     free( dnW );
00822     modarrayfreeW( modsW );
00823     controlarrayfreeW( serverctrlsW );
00824     controlarrayfreeW( clientctrlsW );
00825 
00826     return ret;
00827 }
00828 
00829 static inline ULONG my_win_ldap_add_ext_sA( LDAP *ld, PCHAR dn, LDAPModA *attrs[],
00830     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
00831 {
00832     ULONG ret = LDAP_NOT_SUPPORTED;
00833     WCHAR *dnW = NULL;
00834     LDAPModW **attrsW = NULL;
00835     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
00836 
00837     ret = LDAP_NO_MEMORY;
00838 
00839     if (!ld) return LDAP_PARAM_ERROR;
00840 
00841     if (dn) {
00842         dnW = strAtoW( dn );
00843         if (!dnW) goto exit;
00844     }
00845     if (attrs) {
00846         attrsW = modarrayAtoW( attrs );
00847         if (!attrsW) goto exit;
00848     }
00849     if (serverctrls) {
00850         serverctrlsW = controlarrayAtoW( serverctrls );
00851         if (!serverctrlsW) goto exit;
00852     }
00853     if (clientctrls) {
00854         clientctrlsW = controlarrayAtoW( clientctrls );
00855         if (!clientctrlsW) goto exit;
00856     }
00857 
00858     ret = ldap_add_ext_sW( ld, dnW, attrsW, serverctrlsW, clientctrlsW );
00859 
00860 exit:
00861     free( dnW );
00862     modarrayfreeW( attrsW );
00863     controlarrayfreeW( serverctrlsW );
00864     controlarrayfreeW( clientctrlsW );
00865 
00866     return ret;
00867 }
00868 
00869 static inline ULONG my_win_ldap_add_extA( LDAP *ld, PCHAR dn, LDAPModA *attrs[],
00870     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
00871 {
00872     ULONG ret = LDAP_NOT_SUPPORTED;
00873     WCHAR *dnW = NULL;
00874     LDAPModW **attrsW = NULL;
00875     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
00876 
00877     ret = LDAP_NO_MEMORY;
00878 
00879     if (!ld) return LDAP_PARAM_ERROR;
00880 
00881     if (dn) {
00882         dnW = strAtoW( dn );
00883         if (!dnW) goto exit;
00884     }
00885     if (attrs) {
00886         attrsW = modarrayAtoW( attrs );
00887         if (!attrsW) goto exit;
00888     }
00889     if (serverctrls) {
00890         serverctrlsW = controlarrayAtoW( serverctrls );
00891         if (!serverctrlsW) goto exit;
00892     }
00893     if (clientctrls) {
00894         clientctrlsW = controlarrayAtoW( clientctrls );
00895         if (!clientctrlsW) goto exit;
00896     }
00897 
00898     ret = ldap_add_extW( ld, dnW, attrsW, serverctrlsW, clientctrlsW, message );
00899 
00900 exit:
00901     free( dnW );
00902     modarrayfreeW( attrsW );
00903     controlarrayfreeW( serverctrlsW );
00904     controlarrayfreeW( clientctrlsW );
00905 
00906     return ret;
00907 }
00908 
00909 static void my_win_ldap_mods_freeA(LDAPMod  **mods, int freemods)
00910 {
00911     modarrayfreeU( mods );
00912     if ( freemods ) {
00913       free( mods );
00914     }
00915 }
00916 
00917 static inline ULONG my_win_ldap_parse_resultA( LDAP *ld, LDAPMessage *result,
00918     ULONG *retcode, PCHAR *matched, PCHAR *error, PCHAR **referrals,
00919     PLDAPControlA **serverctrls, BOOLEAN free )
00920 {
00921     ULONG ret = LDAP_NOT_SUPPORTED;
00922     WCHAR *matchedW = NULL, *errorW = NULL, **referralsW = NULL;
00923     LDAPControlW **serverctrlsW = NULL;
00924 
00925     if (!ld) return LDAP_PARAM_ERROR;
00926 
00927     ret = ldap_parse_resultW( ld, result, retcode, &matchedW, &errorW,
00928                               &referralsW, &serverctrlsW, free );
00929 
00930     if (matched) *matched = strWtoA( matchedW );
00931     if (error) *error = strWtoA( errorW );
00932 
00933     if (referrals) *referrals = strarrayWtoA( referralsW );
00934     if (serverctrls) *serverctrls = controlarrayWtoA( serverctrlsW );
00935 
00936     ldap_memfreeW( matchedW );
00937     ldap_memfreeW( errorW );
00938     ldap_value_freeW( referralsW );
00939     ldap_controls_freeW( serverctrlsW );
00940 
00941     return ret;
00942 }
00943 
00944 static inline ULONG my_win_ldap_controls_freeA( LDAPControlA **controls )
00945 {
00946     ULONG ret = LDAP_SUCCESS;
00947 
00948     controlarrayfreeA( controls );
00949 
00950     return ret;
00951 }
00952 
00953 static inline ULONG my_win_ldap_sasl_bind_sA( LDAP *ld, const PCHAR dn,
00954     const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
00955     PLDAPControlA *clientctrls, PBERVAL *serverdata )
00956 {
00957     ULONG ret = LDAP_NOT_SUPPORTED;
00958     WCHAR *dnW, *mechanismW = NULL;
00959     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
00960 
00961     ret = LDAP_NO_MEMORY;
00962 
00963     if (!ld || !dn || !mechanism || !cred || !serverdata)
00964         return LDAP_PARAM_ERROR;
00965 
00966     dnW = strAtoW( dn );
00967     if (!dnW) goto exit;
00968 
00969     mechanismW = strAtoW( mechanism );
00970     if (!mechanismW) goto exit;
00971 
00972     if (serverctrls) {
00973         serverctrlsW = controlarrayAtoW( serverctrls );
00974         if (!serverctrlsW) goto exit;
00975     }
00976     if (clientctrls) {
00977         clientctrlsW = controlarrayAtoW( clientctrls );
00978         if (!clientctrlsW) goto exit;
00979     }
00980 
00981     ret = ldap_sasl_bind_sW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, serverdata );
00982 
00983 exit:
00984     free( dnW );
00985     free( mechanismW );
00986     controlarrayfreeW( serverctrlsW );
00987     controlarrayfreeW( clientctrlsW );
00988 
00989     return ret;
00990 }
00991 
00992 static inline ULONG my_win_ldap_sasl_bindA( LDAP *ld, const PCHAR dn,
00993     const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
00994     PLDAPControlA *clientctrls, int *message )
00995 {
00996     ULONG ret = LDAP_NOT_SUPPORTED;
00997 
00998     WCHAR *dnW, *mechanismW = NULL;
00999     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
01000 
01001     ret = LDAP_NO_MEMORY;
01002 
01003     if (!ld || !dn || !mechanism || !cred || !message)
01004         return LDAP_PARAM_ERROR;
01005 
01006     dnW = strAtoW( dn );
01007     if (!dnW) goto exit;
01008 
01009     mechanismW = strAtoW( mechanism );
01010     if (!mechanismW) goto exit;
01011 
01012     if (serverctrls) {
01013         serverctrlsW = controlarrayAtoW( serverctrls );
01014         if (!serverctrlsW) goto exit;
01015     }
01016     if (clientctrls) {
01017         clientctrlsW = controlarrayAtoW( clientctrls );
01018         if (!clientctrlsW) goto exit;
01019     }
01020 
01021     ret = ldap_sasl_bindW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, message );
01022 
01023 exit:
01024     free( dnW );
01025     free( mechanismW );
01026     controlarrayfreeW( serverctrlsW );
01027     controlarrayfreeW( clientctrlsW );
01028 
01029     return ret;
01030 }
01031 
01032 static inline PCHAR my_win_ldap_get_dnA( LDAP *ld, LDAPMessage *entry )
01033 {
01034     PCHAR ret = NULL;
01035     PWCHAR retW;
01036 
01037     if (!ld || !entry) return NULL;
01038 
01039     retW = ldap_get_dnW( ld, entry );
01040 
01041     ret = strWtoA( retW );
01042     ldap_memfreeW( retW );
01043 
01044     return ret;
01045 }
01046 
01047 static inline ULONG my_win_ldap_parse_extended_resultA( LDAP *ld,
01048     LDAPMessage *result,
01049     PCHAR *oid, struct berval **data, BOOLEAN free )
01050 {
01051     ULONG ret = LDAP_NOT_SUPPORTED;
01052     WCHAR *oidW = NULL;
01053 
01054     if (!ld) return LDAP_PARAM_ERROR;
01055     if (!result) return LDAP_NO_RESULTS_RETURNED;
01056 
01057     ret = ldap_parse_extended_resultW( ld, result, &oidW, data, free );
01058 
01059     if (oid) {
01060         *oid = strWtoA( oidW );
01061         if (!*oid) ret = LDAP_NO_MEMORY;
01062         ldap_memfreeW( oidW );
01063     }
01064 
01065     return ret;
01066 }
01067 
01068 static inline LDAP *
01069 my_win_ldap_initA (const char *host, unsigned short port)
01070 {
01071   LDAP *ld;
01072   wchar_t *whost = NULL;
01073 
01074   if (host)
01075     {
01076       whost = strAtoW (host);
01077       if (!whost)
01078         return NULL;
01079     }
01080   ld = ldap_initW (whost, port);
01081   free (whost);
01082   return ld;
01083 }
01084 
01085 static inline ULONG
01086 my_win_ldap_simple_bind_sA (LDAP *ld, const char *user, const char *pass)
01087 {
01088   ULONG ret;
01089   wchar_t *wuser, *wpass;
01090 
01091   wuser = user? strAtoW (user) : NULL;
01092   wpass = pass? strAtoW (pass) : NULL;
01093   /* We can't easily map errnos to ldap_errno, thus we pass a NULL to
01094      the function in the hope that the server will throw an error.  */
01095   ret = ldap_simple_bind_sW (ld, wuser, wpass);
01096   free (wpass);
01097   free (wuser);
01098   return ret;
01099 }
01100 
01101 static inline ULONG my_win_ldap_search_extA( LDAP *ld, PCHAR base, ULONG scope,
01102     PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
01103     PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, int *message )
01104 {
01105     ULONG ret = LDAP_NOT_SUPPORTED;
01106     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
01107     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
01108 
01109     ret = LDAP_NO_MEMORY;
01110 
01111     if (!ld) return LDAP_PARAM_ERROR;
01112 
01113     if (base) {
01114         baseW = strAtoW( base );
01115         if (!baseW) goto exit;
01116     }
01117     if (filter)
01118     {
01119         filterW = strAtoW( filter );
01120         if (!filterW) goto exit;
01121     }
01122     if (attrs) {
01123         attrsW = strarrayAtoW( attrs );
01124         if (!attrsW) goto exit;
01125     }
01126     if (serverctrls) {
01127         serverctrlsW = controlarrayAtoW( serverctrls );
01128         if (!serverctrlsW) goto exit;
01129     }
01130     if (clientctrls) {
01131         clientctrlsW = controlarrayAtoW( clientctrls );
01132         if (!clientctrlsW) goto exit;
01133     }
01134 
01135     ret = ldap_search_extW( ld, baseW, scope, filterW, attrsW, attrsonly,
01136                             serverctrlsW, clientctrlsW, timelimit, sizelimit, ( ULONG* )message );
01137 
01138 exit:
01139     free( baseW );
01140     free( filterW );
01141     strarrayfreeW( attrsW );
01142     controlarrayfreeW( serverctrlsW );
01143     controlarrayfreeW( clientctrlsW );
01144 
01145     return ret;
01146 }
01147 
01148 static inline ULONG my_win_ldap_search_stA( LDAP *ld, const PCHAR base, ULONG scope,
01149     const PCHAR filter, PCHAR attrs[], ULONG attrsonly,
01150     struct l_timeval *timeout, LDAPMessage **res )
01151 {
01152     ULONG ret = LDAP_NOT_SUPPORTED;
01153     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
01154 
01155     ret = LDAP_NO_MEMORY;
01156 
01157     if (!ld || !res) return LDAP_PARAM_ERROR;
01158 
01159     if (base) {
01160         baseW = strAtoW( base );
01161         if (!baseW) goto exit;
01162     }
01163     if (filter) {
01164         filterW = strAtoW( filter );
01165         if (!filterW) goto exit;
01166     }
01167     if (attrs) {
01168         attrsW = strarrayAtoW( attrs );
01169         if (!attrsW) goto exit;
01170     }
01171 
01172     ret = ldap_search_stW( ld, baseW, scope, filterW, attrsW, attrsonly,
01173                            timeout, res );
01174 
01175 exit:
01176     free( baseW );
01177     free( filterW );
01178     strarrayfreeW( attrsW );
01179 
01180     return ret;
01181 }
01182 
01183 static inline char *
01184 my_win_ldap_first_attributeA (LDAP *ld, LDAPMessage *msg, BerElement **elem)
01185 {
01186   wchar_t *wattr;
01187   char *attr;
01188 
01189   wattr = ldap_first_attributeW (ld, msg, elem);
01190   if (!wattr)
01191     return NULL;
01192   attr = strWtoA (wattr);
01193   ldap_memfreeW (wattr);
01194   return attr;
01195 }
01196 
01197 
01198 static inline char *
01199 my_win_ldap_next_attributeA (LDAP *ld, LDAPMessage *msg, BerElement *elem)
01200 {
01201   wchar_t *wattr;
01202   char *attr;
01203 
01204   wattr = ldap_next_attributeW (ld, msg, elem);
01205   if (!wattr)
01206     return NULL;
01207   attr = strWtoA (wattr);
01208   ldap_memfreeW (wattr);
01209   return attr;
01210 }
01211 
01212 static inline BerValue **
01213 my_win_ldap_get_values_lenA (LDAP *ld, LDAPMessage *msg, const char *attr)
01214 {
01215   BerValue **ret;
01216   wchar_t *wattr;
01217 
01218   if (attr)
01219     {
01220       wattr = strAtoW (attr);
01221       if (!wattr)
01222         return NULL;
01223     }
01224   else
01225     wattr = NULL;
01226 
01227   ret = ldap_get_values_lenW (ld, msg, wattr);
01228   free (wattr);
01229 
01230   return ret;
01231 }
01232 #endif /*_WIN32_WCE*/
01233 #endif // WCE_LDAP_HELP_H

KLDAP Library

Skip menu "KLDAP Library"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal