• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KLDAP Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kldap
wce-ldap-help.h
1 //krazy:excludeall=style,copyright to maintain the original look of the derived code.
2 /*
3  * winceldap - LDAP helper functions for Windows CE
4  * Copyright 2010 Andre Heinecke <aheinecke@intevation.de>
5  *
6  * Derived from:
7  *
8  * WLDAP32 - LDAP support for Wine
9  *
10  * Copyright 2005 Hans Leidekker
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 #ifndef WCE_LDAP_HELP_H
27 #define WCE_LDAP_HELP_H
28 ULONG map_error( int );
29 
30 /* A set of helper functions to convert LDAP data structures
31  * to and from ansi (A), wide character (W) and utf8 (U) encodings.
32  */
33 
34 static inline char *strdupU( const char *src )
35 {
36  char *dst;
37 
38  if (!src) return NULL;
39  dst = ( char * )malloc( (strlen( src ) + 1) * sizeof(char) );
40  if (dst)
41  strcpy( dst, src );
42  return dst;
43 }
44 
45 static inline LPWSTR strAtoW( LPCSTR str )
46 {
47  LPWSTR ret = NULL;
48  if (str)
49  {
50  DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
51  if ((ret = ( WCHAR* )malloc( len * sizeof(WCHAR) )))
52  MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
53  }
54  return ret;
55 }
56 
57 static inline LPSTR strWtoA( LPCWSTR str )
58 {
59  LPSTR ret = NULL;
60  if (str)
61  {
62  DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
63  if ((ret = ( char* )malloc( len )))
64  WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
65  }
66  return ret;
67 }
68 
69 static inline char *strWtoU( LPCWSTR str )
70 {
71  LPSTR ret = NULL;
72  if (str)
73  {
74  DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
75  if ((ret = ( char * )malloc( len )))
76  WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
77  }
78  return ret;
79 }
80 
81 static inline LPWSTR strUtoW( char *str )
82 {
83  LPWSTR ret = NULL;
84  if (str)
85  {
86  DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
87  if ((ret = ( WCHAR* )malloc( len * sizeof(WCHAR) )))
88  MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
89  }
90  return ret;
91 }
92 
93 static inline DWORD strarraylenA( LPSTR *strarray )
94 {
95  LPSTR *p = strarray;
96  while (*p) p++;
97  return p - strarray;
98 }
99 
100 static inline DWORD strarraylenW( LPWSTR *strarray )
101 {
102  LPWSTR *p = strarray;
103  while (*p) p++;
104  return p - strarray;
105 }
106 
107 static inline DWORD strarraylenU( char **strarray )
108 {
109  char **p = strarray;
110  while (*p) p++;
111  return p - strarray;
112 }
113 
114 static inline LPWSTR *strarrayAtoW( LPSTR *strarray )
115 {
116  LPWSTR *strarrayW = NULL;
117  DWORD size;
118 
119  if (strarray)
120  {
121  size = sizeof(WCHAR*) * (strarraylenA( strarray ) + 1);
122  strarrayW = ( WCHAR** )malloc( size );
123 
124  if (strarrayW)
125  {
126  LPSTR *p = strarray;
127  LPWSTR *q = strarrayW;
128 
129  while (*p) *q++ = strAtoW( *p++ );
130  *q = NULL;
131  }
132  }
133  return strarrayW;
134 }
135 
136 static inline LPSTR *strarrayWtoA( LPWSTR *strarray )
137 {
138  LPSTR *strarrayA = NULL;
139  DWORD size;
140 
141  if (strarray)
142  {
143  size = sizeof(LPSTR) * (strarraylenW( strarray ) + 1);
144  strarrayA = ( char** )malloc( size );
145 
146  if (strarrayA)
147  {
148  LPWSTR *p = strarray;
149  LPSTR *q = strarrayA;
150 
151  while (*p) *q++ = strWtoA( *p++ );
152  *q = NULL;
153  }
154  }
155  return strarrayA;
156 }
157 
158 static inline char **strarrayWtoU( LPWSTR *strarray )
159 {
160  char **strarrayU = NULL;
161  DWORD size;
162 
163  if (strarray)
164  {
165  size = sizeof(char*) * (strarraylenW( strarray ) + 1);
166  strarrayU = ( char** )malloc( size );
167 
168  if (strarrayU)
169  {
170  LPWSTR *p = strarray;
171  char **q = strarrayU;
172 
173  while (*p) *q++ = strWtoU( *p++ );
174  *q = NULL;
175  }
176  }
177  return strarrayU;
178 }
179 
180 static inline LPWSTR *strarrayUtoW( char **strarray )
181 {
182  LPWSTR *strarrayW = NULL;
183  DWORD size;
184 
185  if (strarray)
186  {
187  size = sizeof(WCHAR*) * (strarraylenU( strarray ) + 1);
188  strarrayW = ( WCHAR ** )malloc( size );
189 
190  if (strarrayW)
191  {
192  char **p = strarray;
193  LPWSTR *q = strarrayW;
194 
195  while (*p) *q++ = strUtoW( *p++ );
196  *q = NULL;
197  }
198  }
199  return strarrayW;
200 }
201 
202 static inline void strarrayfreeA( LPSTR *strarray )
203 {
204  if (strarray)
205  {
206  LPSTR *p = strarray;
207  while (*p) free( *p++ );
208  free( strarray );
209  }
210 }
211 
212 static inline void strarrayfreeW( LPWSTR *strarray )
213 {
214  if (strarray)
215  {
216  LPWSTR *p = strarray;
217  while (*p) free( *p++ );
218  free( strarray );
219  }
220 }
221 
222 static inline void strarrayfreeU( char **strarray )
223 {
224  if (strarray)
225  {
226  char **p = strarray;
227  while (*p) free( *p++ );
228  free( strarray );
229  }
230 }
231 
232 static inline struct berval *bvdup( struct berval *bv )
233 {
234  struct berval *berval;
235  DWORD size = sizeof(struct berval) + bv->bv_len;
236 
237  berval = ( struct berval * )malloc( size );
238  if (berval)
239  {
240  char *val = (char *)berval + sizeof(struct berval);
241 
242  berval->bv_len = bv->bv_len;
243  berval->bv_val = val;
244  memcpy( val, bv->bv_val, bv->bv_len );
245  }
246  return berval;
247 }
248 
249 static inline DWORD bvarraylen( struct berval **bv )
250 {
251  struct berval **p = bv;
252  while (*p) p++;
253  return p - bv;
254 }
255 
256 static inline struct berval **bvarraydup( struct berval **bv )
257 {
258  struct berval **berval = NULL;
259  DWORD size;
260 
261  if (bv)
262  {
263  size = sizeof(struct berval *) * (bvarraylen( bv ) + 1);
264  berval = ( struct berval ** )malloc( size );
265 
266  if (berval)
267  {
268  struct berval **p = bv;
269  struct berval **q = berval;
270 
271  while (*p) *q++ = bvdup( *p++ );
272  *q = NULL;
273  }
274  }
275  return berval;
276 }
277 
278 static inline void bvarrayfree( struct berval **bv )
279 {
280  struct berval **p = bv;
281  while (*p) free( *p++ );
282  free( bv );
283 }
284 
285 static inline LDAPModW *modAtoW( LDAPModA *mod )
286 {
287  LDAPModW *modW;
288 
289  modW = ( LDAPModW *)malloc( sizeof(LDAPModW) );
290  if (modW)
291  {
292  modW->mod_op = mod->mod_op;
293  modW->mod_type = strAtoW( mod->mod_type );
294 
295  if (mod->mod_op & LDAP_MOD_BVALUES)
296  modW->mod_vals.modv_bvals = bvarraydup( mod->mod_vals.modv_bvals );
297  else
298  modW->mod_vals.modv_strvals = strarrayAtoW( mod->mod_vals.modv_strvals );
299  }
300  return modW;
301 }
302 
303 static inline LDAPMod *modWtoU( LDAPModW *mod )
304 {
305  LDAPMod *modU;
306 
307  modU = ( LDAPMod * )malloc( sizeof(LDAPMod) );
308  if (modU)
309  {
310  modU->mod_op = mod->mod_op;
311  modU->mod_type = strWtoU( mod->mod_type );
312 
313  if (mod->mod_op & LDAP_MOD_BVALUES)
314  modU->mod_vals.modv_bvals = bvarraydup( mod->mod_vals.modv_bvals );
315  else
316  modU->mod_vals.modv_strvals = strarrayWtoU( mod->mod_vals.modv_strvals );
317  }
318  return modU;
319 }
320 
321 static inline void modfreeW( LDAPModW *mod )
322 {
323  if (mod->mod_op & LDAP_MOD_BVALUES)
324  bvarrayfree( mod->mod_vals.modv_bvals );
325  else
326  strarrayfreeW( mod->mod_vals.modv_strvals );
327  free( mod );
328 }
329 
330 static inline void modfreeU( LDAPMod *mod )
331 {
332  if (mod->mod_op & LDAP_MOD_BVALUES)
333  bvarrayfree( mod->mod_vals.modv_bvals );
334  else
335  strarrayfreeU( mod->mod_vals.modv_strvals );
336  free( mod );
337 }
338 
339 static inline DWORD modarraylenA( LDAPModA **modarray )
340 {
341  LDAPModA **p = modarray;
342  while (*p) p++;
343  return p - modarray;
344 }
345 
346 static inline DWORD modarraylenW( LDAPModW **modarray )
347 {
348  LDAPModW **p = modarray;
349  while (*p) p++;
350  return p - modarray;
351 }
352 
353 static inline LDAPModW **modarrayAtoW( LDAPModA **modarray )
354 {
355  LDAPModW **modarrayW = NULL;
356  DWORD size;
357 
358  if (modarray)
359  {
360  size = sizeof(LDAPModW*) * (modarraylenA( modarray ) + 1);
361  modarrayW = ( LDAPModW**)malloc( size );
362 
363  if (modarrayW)
364  {
365  LDAPModA **p = modarray;
366  LDAPModW **q = modarrayW;
367 
368  while (*p) *q++ = modAtoW( *p++ );
369  *q = NULL;
370  }
371  }
372  return modarrayW;
373 }
374 
375 static inline LDAPMod **modarrayWtoU( LDAPModW **modarray )
376 {
377  LDAPMod **modarrayU = NULL;
378  DWORD size;
379 
380  if (modarray)
381  {
382  size = sizeof(LDAPMod*) * (modarraylenW( modarray ) + 1);
383  modarrayU = ( LDAPMod** )malloc( size );
384 
385  if (modarrayU)
386  {
387  LDAPModW **p = modarray;
388  LDAPMod **q = modarrayU;
389 
390  while (*p) *q++ = modWtoU( *p++ );
391  *q = NULL;
392  }
393  }
394  return modarrayU;
395 }
396 
397 static inline void modarrayfreeW( LDAPModW **modarray )
398 {
399  if (modarray)
400  {
401  LDAPModW **p = modarray;
402  while (*p) modfreeW( *p++ );
403  free( modarray );
404  }
405 }
406 
407 static inline void modarrayfreeU( LDAPMod **modarray )
408 {
409  if (modarray)
410  {
411  LDAPMod **p = modarray;
412  while (*p) modfreeU( *p++ );
413  free( modarray );
414  }
415 }
416 
417 static inline LDAPControlW *controlAtoW( LDAPControlA *control )
418 {
419  LDAPControlW *controlW;
420  DWORD len = control->ldctl_value.bv_len;
421  char *val = NULL;
422 
423  if (control->ldctl_value.bv_val)
424  {
425  val = ( char* )malloc( len );
426  if (!val) return NULL;
427  memcpy( val, control->ldctl_value.bv_val, len );
428  }
429 
430  controlW = ( LDAPControlW* )malloc( sizeof(LDAPControlW) );
431  if (!controlW)
432  {
433  free( val );
434  return NULL;
435  }
436 
437  controlW->ldctl_oid = strAtoW( control->ldctl_oid );
438  controlW->ldctl_value.bv_len = len;
439  controlW->ldctl_value.bv_val = val;
440  controlW->ldctl_iscritical = control->ldctl_iscritical;
441 
442  return controlW;
443 }
444 
445 static inline LDAPControlA *controlWtoA( LDAPControlW *control )
446 {
447  LDAPControlA *controlA;
448  DWORD len = control->ldctl_value.bv_len;
449  char *val = NULL;
450 
451  if (control->ldctl_value.bv_val)
452  {
453  val = ( char* )malloc( len );
454  if (!val) return NULL;
455  memcpy( val, control->ldctl_value.bv_val, len );
456  }
457 
458  controlA = ( LDAPControlA* )malloc( sizeof(LDAPControlA) );
459  if (!controlA)
460  {
461  free( val );
462  return NULL;
463  }
464 
465  controlA->ldctl_oid = strWtoA( control->ldctl_oid );
466  controlA->ldctl_value.bv_len = len;
467  controlA->ldctl_value.bv_val = val;
468  controlA->ldctl_iscritical = control->ldctl_iscritical;
469 
470  return controlA;
471 }
472 
473 static inline LDAPControl *controlWtoU( LDAPControlW *control )
474 {
475  LDAPControl *controlU;
476  DWORD len = control->ldctl_value.bv_len;
477  char *val = NULL;
478 
479  if (control->ldctl_value.bv_val)
480  {
481  val = ( char * )malloc( len );
482  if (!val) return NULL;
483  memcpy( val, control->ldctl_value.bv_val, len );
484  }
485 
486  controlU = ( LDAPControl* )malloc( sizeof(LDAPControl) );
487  if (!controlU)
488  {
489  free( val );
490  return NULL;
491  }
492 
493  controlU->ldctl_oid = strWtoU( control->ldctl_oid );
494  controlU->ldctl_value.bv_len = len;
495  controlU->ldctl_value.bv_val = val;
496  controlU->ldctl_iscritical = control->ldctl_iscritical;
497 
498  return controlU;
499 }
500 
501 static inline LDAPControlW *controlUtoW( LDAPControl *control )
502 {
503  LDAPControlW *controlW;
504  DWORD len = control->ldctl_value.bv_len;
505  char *val = NULL;
506 
507  if (control->ldctl_value.bv_val)
508  {
509  val = ( char* )malloc( len );
510  if (!val) return NULL;
511  memcpy( val, control->ldctl_value.bv_val, len );
512  }
513 
514  controlW = ( LDAPControlW* )malloc( sizeof(LDAPControlW) );
515  if (!controlW)
516  {
517  free( val );
518  return NULL;
519  }
520 
521  controlW->ldctl_oid = strUtoW( control->ldctl_oid );
522  controlW->ldctl_value.bv_len = len;
523  controlW->ldctl_value.bv_val = val;
524  controlW->ldctl_iscritical = control->ldctl_iscritical;
525 
526  return controlW;
527 }
528 
529 static inline void controlfreeA( LDAPControlA *control )
530 {
531  if (control)
532  {
533  free( control->ldctl_oid );
534  free( control->ldctl_value.bv_val );
535  free( control );
536  }
537 }
538 
539 static inline void controlfreeW( LDAPControlW *control )
540 {
541  if (control)
542  {
543  free( control->ldctl_oid );
544  free( control->ldctl_value.bv_val );
545  free( control );
546  }
547 }
548 
549 static inline void controlfreeU( LDAPControl *control )
550 {
551  if (control)
552  {
553  free( control->ldctl_oid );
554  free( control->ldctl_value.bv_val );
555  free( control );
556  }
557 }
558 
559 static inline DWORD controlarraylenA( LDAPControlA **controlarray )
560 {
561  LDAPControlA **p = controlarray;
562  while (*p) p++;
563  return p - controlarray;
564 }
565 
566 static inline DWORD controlarraylenW( LDAPControlW **controlarray )
567 {
568  LDAPControlW **p = controlarray;
569  while (*p) p++;
570  return p - controlarray;
571 }
572 
573 static inline DWORD controlarraylenU( LDAPControl **controlarray )
574 {
575  LDAPControl **p = controlarray;
576  while (*p) p++;
577  return p - controlarray;
578 }
579 
580 static inline LDAPControlW **controlarrayAtoW( LDAPControlA **controlarray )
581 {
582  LDAPControlW **controlarrayW = NULL;
583  DWORD size;
584 
585  if (controlarray)
586  {
587  size = sizeof(LDAPControlW*) * (controlarraylenA( controlarray ) + 1);
588  controlarrayW = ( LDAPControlW ** )malloc( size );
589 
590  if (controlarrayW)
591  {
592  LDAPControlA **p = controlarray;
593  LDAPControlW **q = controlarrayW;
594 
595  while (*p) *q++ = controlAtoW( *p++ );
596  *q = NULL;
597  }
598  }
599  return controlarrayW;
600 }
601 
602 static inline LDAPControlA **controlarrayWtoA( LDAPControlW **controlarray )
603 {
604  LDAPControlA **controlarrayA = NULL;
605  DWORD size;
606 
607  if (controlarray)
608  {
609  size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
610  controlarrayA = ( LDAPControlA** )malloc( size );
611 
612  if (controlarrayA)
613  {
614  LDAPControlW **p = controlarray;
615  LDAPControlA **q = controlarrayA;
616 
617  while (*p) *q++ = controlWtoA( *p++ );
618  *q = NULL;
619  }
620  }
621  return controlarrayA;
622 }
623 
624 static inline LDAPControl **controlarrayWtoU( LDAPControlW **controlarray )
625 {
626  LDAPControl **controlarrayU = NULL;
627  DWORD size;
628 
629  if (controlarray)
630  {
631  size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
632  controlarrayU = ( LDAPControl ** )malloc( size );
633 
634  if (controlarrayU)
635  {
636  LDAPControlW **p = controlarray;
637  LDAPControl **q = controlarrayU;
638 
639  while (*p) *q++ = controlWtoU( *p++ );
640  *q = NULL;
641  }
642  }
643  return controlarrayU;
644 }
645 
646 static inline LDAPControlW **controlarrayUtoW( LDAPControl **controlarray )
647 {
648  LDAPControlW **controlarrayW = NULL;
649  DWORD size;
650 
651  if (controlarray)
652  {
653  size = sizeof(LDAPControlW*) * (controlarraylenU( controlarray ) + 1);
654  controlarrayW = (LDAPControlW** )malloc( size );
655 
656  if (controlarrayW)
657  {
658  LDAPControl **p = controlarray;
659  LDAPControlW **q = controlarrayW;
660 
661  while (*p) *q++ = controlUtoW( *p++ );
662  *q = NULL;
663  }
664  }
665  return controlarrayW;
666 }
667 
668 static inline void controlarrayfreeA( LDAPControlA **controlarray )
669 {
670  if (controlarray)
671  {
672  LDAPControlA **p = controlarray;
673  while (*p) controlfreeA( *p++ );
674  free( controlarray );
675  }
676 }
677 
678 static inline void controlarrayfreeW( LDAPControlW **controlarray )
679 {
680  if (controlarray)
681  {
682  LDAPControlW **p = controlarray;
683  while (*p) controlfreeW( *p++ );
684  free( controlarray );
685  }
686 }
687 
688 static inline void controlarrayfreeU( LDAPControl **controlarray )
689 {
690  if (controlarray)
691  {
692  LDAPControl **p = controlarray;
693  while (*p) controlfreeU( *p++ );
694  free( controlarray );
695  }
696 }
697 
698 #ifdef _WIN32_WCE //krazy:exclude=cpp allow as this is a non-Qt source file
699 static inline ULONG my_win_ldap_compare_ext_sA( LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value,
700  struct berval *data, PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
701 {
702  ULONG ret = LDAP_NOT_SUPPORTED;
703  WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
704  LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
705 
706  ret = LDAP_NO_MEMORY;
707 
708  if (!ld) return LDAP_PARAM_ERROR;
709 
710  if (dn) {
711  dnW = strAtoW( dn );
712  if (!dnW) goto exit;
713  }
714  if (attr) {
715  attrW = strAtoW( attr );
716  if (!attrW) goto exit;
717  }
718  if (value) {
719  valueW = strAtoW( value );
720  if (!valueW) goto exit;
721  }
722  if (serverctrls) {
723  serverctrlsW = controlarrayAtoW( serverctrls );
724  if (!serverctrlsW) goto exit;
725  }
726  if (clientctrls) {
727  clientctrlsW = controlarrayAtoW( clientctrls );
728  if (!clientctrlsW) goto exit;
729  }
730 
731  ret = ldap_compare_ext_sW( ld, dnW, attrW, valueW, data, serverctrlsW,
732  clientctrlsW );
733 
734 exit:
735  free( dnW );
736  free( attrW );
737  free( valueW );
738  controlarrayfreeW( serverctrlsW );
739  controlarrayfreeW( clientctrlsW );
740 
741  return ret;
742 }
743 
744 static inline ULONG my_win_ldap_compare_extA( LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value,
745  struct berval *data, PLDAPControlA *serverctrls, PLDAPControlA *clientctrls,
746  ULONG *message )
747 {
748  ULONG ret = LDAP_NOT_SUPPORTED;
749  WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
750  LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
751 
752  ret = LDAP_NO_MEMORY;
753 
754  if (!ld || !message) return LDAP_PARAM_ERROR;
755 
756  if (dn) {
757  dnW = strAtoW( dn );
758  if (!dnW) goto exit;
759  }
760  if (attr) {
761  attrW = strAtoW( attr );
762  if (!attrW) goto exit;
763  }
764  if (value) {
765  valueW = strAtoW( value );
766  if (!valueW) goto exit;
767  }
768  if (serverctrls) {
769  serverctrlsW = controlarrayAtoW( serverctrls );
770  if (!serverctrlsW) goto exit;
771  }
772  if (clientctrls) {
773  clientctrlsW = controlarrayAtoW( clientctrls );
774  if (!clientctrlsW) goto exit;
775  }
776 
777  ret = ldap_compare_extW( ld, dnW, attrW, valueW, data,
778  serverctrlsW, clientctrlsW, message );
779 
780 exit:
781  free( dnW );
782  free( attrW );
783  free( valueW );
784  controlarrayfreeW( serverctrlsW );
785  controlarrayfreeW( clientctrlsW );
786 
787  return ret;
788 }
789 
790 static inline ULONG my_win_ldap_modify_ext_sA( LDAP *ld, PCHAR dn, LDAPModA *mods[],
791  PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
792 {
793  ULONG ret = LDAP_NOT_SUPPORTED;
794  WCHAR *dnW = NULL;
795  LDAPModW **modsW = NULL;
796  LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
797 
798  ret = LDAP_NO_MEMORY;
799 
800  if (!ld) return LDAP_PARAM_ERROR;
801 
802  if (dn) {
803  dnW = strAtoW( dn );
804  if (!dnW) goto exit;
805  }
806  if (mods) {
807  modsW = modarrayAtoW( mods );
808  if (!modsW) goto exit;
809  }
810  if (serverctrls) {
811  serverctrlsW = controlarrayAtoW( serverctrls );
812  if (!serverctrlsW) goto exit;
813  }
814  if (clientctrls) {
815  clientctrlsW = controlarrayAtoW( clientctrls );
816  if (!clientctrlsW) goto exit;
817  }
818 
819  ret = ldap_modify_ext_sW( ld, dnW, modsW, serverctrlsW, clientctrlsW );
820 
821 exit:
822  free( dnW );
823  modarrayfreeW( modsW );
824  controlarrayfreeW( serverctrlsW );
825  controlarrayfreeW( clientctrlsW );
826 
827  return ret;
828 }
829 
830 static inline ULONG my_win_ldap_add_ext_sA( LDAP *ld, PCHAR dn, LDAPModA *attrs[],
831  PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
832 {
833  ULONG ret = LDAP_NOT_SUPPORTED;
834  WCHAR *dnW = NULL;
835  LDAPModW **attrsW = NULL;
836  LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
837 
838  ret = LDAP_NO_MEMORY;
839 
840  if (!ld) return LDAP_PARAM_ERROR;
841 
842  if (dn) {
843  dnW = strAtoW( dn );
844  if (!dnW) goto exit;
845  }
846  if (attrs) {
847  attrsW = modarrayAtoW( attrs );
848  if (!attrsW) goto exit;
849  }
850  if (serverctrls) {
851  serverctrlsW = controlarrayAtoW( serverctrls );
852  if (!serverctrlsW) goto exit;
853  }
854  if (clientctrls) {
855  clientctrlsW = controlarrayAtoW( clientctrls );
856  if (!clientctrlsW) goto exit;
857  }
858 
859  ret = ldap_add_ext_sW( ld, dnW, attrsW, serverctrlsW, clientctrlsW );
860 
861 exit:
862  free( dnW );
863  modarrayfreeW( attrsW );
864  controlarrayfreeW( serverctrlsW );
865  controlarrayfreeW( clientctrlsW );
866 
867  return ret;
868 }
869 
870 static inline ULONG my_win_ldap_add_extA( LDAP *ld, PCHAR dn, LDAPModA *attrs[],
871  PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
872 {
873  ULONG ret = LDAP_NOT_SUPPORTED;
874  WCHAR *dnW = NULL;
875  LDAPModW **attrsW = NULL;
876  LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
877 
878  ret = LDAP_NO_MEMORY;
879 
880  if (!ld) return LDAP_PARAM_ERROR;
881 
882  if (dn) {
883  dnW = strAtoW( dn );
884  if (!dnW) goto exit;
885  }
886  if (attrs) {
887  attrsW = modarrayAtoW( attrs );
888  if (!attrsW) goto exit;
889  }
890  if (serverctrls) {
891  serverctrlsW = controlarrayAtoW( serverctrls );
892  if (!serverctrlsW) goto exit;
893  }
894  if (clientctrls) {
895  clientctrlsW = controlarrayAtoW( clientctrls );
896  if (!clientctrlsW) goto exit;
897  }
898 
899  ret = ldap_add_extW( ld, dnW, attrsW, serverctrlsW, clientctrlsW, message );
900 
901 exit:
902  free( dnW );
903  modarrayfreeW( attrsW );
904  controlarrayfreeW( serverctrlsW );
905  controlarrayfreeW( clientctrlsW );
906 
907  return ret;
908 }
909 
910 static void my_win_ldap_mods_freeA(LDAPMod **mods, int freemods)
911 {
912  modarrayfreeU( mods );
913  if ( freemods ) {
914  free( mods );
915  }
916 }
917 
918 static inline ULONG my_win_ldap_parse_resultA( LDAP *ld, LDAPMessage *result,
919  ULONG *retcode, PCHAR *matched, PCHAR *error, PCHAR **referrals,
920  PLDAPControlA **serverctrls, BOOLEAN free )
921 {
922  ULONG ret = LDAP_NOT_SUPPORTED;
923  WCHAR *matchedW = NULL, *errorW = NULL, **referralsW = NULL;
924  LDAPControlW **serverctrlsW = NULL;
925 
926  if (!ld) return LDAP_PARAM_ERROR;
927 
928  ret = ldap_parse_resultW( ld, result, retcode, &matchedW, &errorW,
929  &referralsW, &serverctrlsW, free );
930 
931  if (matched) *matched = strWtoA( matchedW );
932  if (error) *error = strWtoA( errorW );
933 
934  if (referrals) *referrals = strarrayWtoA( referralsW );
935  if (serverctrls) *serverctrls = controlarrayWtoA( serverctrlsW );
936 
937  ldap_memfreeW( matchedW );
938  ldap_memfreeW( errorW );
939  ldap_value_freeW( referralsW );
940  ldap_controls_freeW( serverctrlsW );
941 
942  return ret;
943 }
944 
945 static inline ULONG my_win_ldap_controls_freeA( LDAPControlA **controls )
946 {
947  ULONG ret = LDAP_SUCCESS;
948 
949  controlarrayfreeA( controls );
950 
951  return ret;
952 }
953 
954 static inline ULONG my_win_ldap_sasl_bind_sA( LDAP *ld, const PCHAR dn,
955  const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
956  PLDAPControlA *clientctrls, PBERVAL *serverdata )
957 {
958  ULONG ret = LDAP_NOT_SUPPORTED;
959  WCHAR *dnW, *mechanismW = NULL;
960  LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
961 
962  ret = LDAP_NO_MEMORY;
963 
964  if (!ld || !dn || !mechanism || !cred || !serverdata)
965  return LDAP_PARAM_ERROR;
966 
967  dnW = strAtoW( dn );
968  if (!dnW) goto exit;
969 
970  mechanismW = strAtoW( mechanism );
971  if (!mechanismW) goto exit;
972 
973  if (serverctrls) {
974  serverctrlsW = controlarrayAtoW( serverctrls );
975  if (!serverctrlsW) goto exit;
976  }
977  if (clientctrls) {
978  clientctrlsW = controlarrayAtoW( clientctrls );
979  if (!clientctrlsW) goto exit;
980  }
981 
982  ret = ldap_sasl_bind_sW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, serverdata );
983 
984 exit:
985  free( dnW );
986  free( mechanismW );
987  controlarrayfreeW( serverctrlsW );
988  controlarrayfreeW( clientctrlsW );
989 
990  return ret;
991 }
992 
993 static inline ULONG my_win_ldap_sasl_bindA( LDAP *ld, const PCHAR dn,
994  const PCHAR mechanism, const BERVAL *cred, PLDAPControlA *serverctrls,
995  PLDAPControlA *clientctrls, int *message )
996 {
997  ULONG ret = LDAP_NOT_SUPPORTED;
998 
999  WCHAR *dnW, *mechanismW = NULL;
1000  LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
1001 
1002  ret = LDAP_NO_MEMORY;
1003 
1004  if (!ld || !dn || !mechanism || !cred || !message)
1005  return LDAP_PARAM_ERROR;
1006 
1007  dnW = strAtoW( dn );
1008  if (!dnW) goto exit;
1009 
1010  mechanismW = strAtoW( mechanism );
1011  if (!mechanismW) goto exit;
1012 
1013  if (serverctrls) {
1014  serverctrlsW = controlarrayAtoW( serverctrls );
1015  if (!serverctrlsW) goto exit;
1016  }
1017  if (clientctrls) {
1018  clientctrlsW = controlarrayAtoW( clientctrls );
1019  if (!clientctrlsW) goto exit;
1020  }
1021 
1022  ret = ldap_sasl_bindW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, message );
1023 
1024 exit:
1025  free( dnW );
1026  free( mechanismW );
1027  controlarrayfreeW( serverctrlsW );
1028  controlarrayfreeW( clientctrlsW );
1029 
1030  return ret;
1031 }
1032 
1033 static inline PCHAR my_win_ldap_get_dnA( LDAP *ld, LDAPMessage *entry )
1034 {
1035  PCHAR ret = NULL;
1036  PWCHAR retW;
1037 
1038  if (!ld || !entry) return NULL;
1039 
1040  retW = ldap_get_dnW( ld, entry );
1041 
1042  ret = strWtoA( retW );
1043  ldap_memfreeW( retW );
1044 
1045  return ret;
1046 }
1047 
1048 static inline ULONG my_win_ldap_parse_extended_resultA( LDAP *ld,
1049  LDAPMessage *result,
1050  PCHAR *oid, struct berval **data, BOOLEAN free )
1051 {
1052  ULONG ret = LDAP_NOT_SUPPORTED;
1053  WCHAR *oidW = NULL;
1054 
1055  if (!ld) return LDAP_PARAM_ERROR;
1056  if (!result) return LDAP_NO_RESULTS_RETURNED;
1057 
1058  ret = ldap_parse_extended_resultW( ld, result, &oidW, data, free );
1059 
1060  if (oid) {
1061  *oid = strWtoA( oidW );
1062  if (!*oid) ret = LDAP_NO_MEMORY;
1063  ldap_memfreeW( oidW );
1064  }
1065 
1066  return ret;
1067 }
1068 
1069 static inline LDAP *
1070 my_win_ldap_initA (const char *host, unsigned short port)
1071 {
1072  LDAP *ld;
1073  wchar_t *whost = NULL;
1074 
1075  if (host)
1076  {
1077  whost = strAtoW (host);
1078  if (!whost)
1079  return NULL;
1080  }
1081  ld = ldap_initW (whost, port);
1082  free (whost);
1083  return ld;
1084 }
1085 
1086 static inline ULONG
1087 my_win_ldap_simple_bind_sA (LDAP *ld, const char *user, const char *pass)
1088 {
1089  ULONG ret;
1090  wchar_t *wuser, *wpass;
1091 
1092  wuser = user? strAtoW (user) : NULL;
1093  wpass = pass? strAtoW (pass) : NULL;
1094  /* We can't easily map errnos to ldap_errno, thus we pass a NULL to
1095  the function in the hope that the server will throw an error. */
1096  ret = ldap_simple_bind_sW (ld, wuser, wpass);
1097  free (wpass);
1098  free (wuser);
1099  return ret;
1100 }
1101 
1102 static inline ULONG my_win_ldap_search_extA( LDAP *ld, PCHAR base, ULONG scope,
1103  PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
1104  PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, int *message )
1105 {
1106  ULONG ret = LDAP_NOT_SUPPORTED;
1107  WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
1108  LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
1109 
1110  ret = LDAP_NO_MEMORY;
1111 
1112  if (!ld) return LDAP_PARAM_ERROR;
1113 
1114  if (base) {
1115  baseW = strAtoW( base );
1116  if (!baseW) goto exit;
1117  }
1118  if (filter)
1119  {
1120  filterW = strAtoW( filter );
1121  if (!filterW) goto exit;
1122  }
1123  if (attrs) {
1124  attrsW = strarrayAtoW( attrs );
1125  if (!attrsW) goto exit;
1126  }
1127  if (serverctrls) {
1128  serverctrlsW = controlarrayAtoW( serverctrls );
1129  if (!serverctrlsW) goto exit;
1130  }
1131  if (clientctrls) {
1132  clientctrlsW = controlarrayAtoW( clientctrls );
1133  if (!clientctrlsW) goto exit;
1134  }
1135 
1136  ret = ldap_search_extW( ld, baseW, scope, filterW, attrsW, attrsonly,
1137  serverctrlsW, clientctrlsW, timelimit, sizelimit, ( ULONG* )message );
1138 
1139 exit:
1140  free( baseW );
1141  free( filterW );
1142  strarrayfreeW( attrsW );
1143  controlarrayfreeW( serverctrlsW );
1144  controlarrayfreeW( clientctrlsW );
1145 
1146  return ret;
1147 }
1148 
1149 static inline ULONG my_win_ldap_search_stA( LDAP *ld, const PCHAR base, ULONG scope,
1150  const PCHAR filter, PCHAR attrs[], ULONG attrsonly,
1151  struct l_timeval *timeout, LDAPMessage **res )
1152 {
1153  ULONG ret = LDAP_NOT_SUPPORTED;
1154  WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
1155 
1156  ret = LDAP_NO_MEMORY;
1157 
1158  if (!ld || !res) return LDAP_PARAM_ERROR;
1159 
1160  if (base) {
1161  baseW = strAtoW( base );
1162  if (!baseW) goto exit;
1163  }
1164  if (filter) {
1165  filterW = strAtoW( filter );
1166  if (!filterW) goto exit;
1167  }
1168  if (attrs) {
1169  attrsW = strarrayAtoW( attrs );
1170  if (!attrsW) goto exit;
1171  }
1172 
1173  ret = ldap_search_stW( ld, baseW, scope, filterW, attrsW, attrsonly,
1174  timeout, res );
1175 
1176 exit:
1177  free( baseW );
1178  free( filterW );
1179  strarrayfreeW( attrsW );
1180 
1181  return ret;
1182 }
1183 
1184 static inline char *
1185 my_win_ldap_first_attributeA (LDAP *ld, LDAPMessage *msg, BerElement **elem)
1186 {
1187  wchar_t *wattr;
1188  char *attr;
1189 
1190  wattr = ldap_first_attributeW (ld, msg, elem);
1191  if (!wattr)
1192  return NULL;
1193  attr = strWtoA (wattr);
1194  ldap_memfreeW (wattr);
1195  return attr;
1196 }
1197 
1198 
1199 static inline char *
1200 my_win_ldap_next_attributeA (LDAP *ld, LDAPMessage *msg, BerElement *elem)
1201 {
1202  wchar_t *wattr;
1203  char *attr;
1204 
1205  wattr = ldap_next_attributeW (ld, msg, elem);
1206  if (!wattr)
1207  return NULL;
1208  attr = strWtoA (wattr);
1209  ldap_memfreeW (wattr);
1210  return attr;
1211 }
1212 
1213 static inline BerValue **
1214 my_win_ldap_get_values_lenA (LDAP *ld, LDAPMessage *msg, const char *attr)
1215 {
1216  BerValue **ret;
1217  wchar_t *wattr;
1218 
1219  if (attr)
1220  {
1221  wattr = strAtoW (attr);
1222  if (!wattr)
1223  return NULL;
1224  }
1225  else
1226  wattr = NULL;
1227 
1228  ret = ldap_get_values_lenW (ld, msg, wattr);
1229  free (wattr);
1230 
1231  return ret;
1232 }
1233 #endif /*_WIN32_WCE*/
1234 #endif // WCE_LDAP_HELP_H
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KLDAP Library

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

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal