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