ptutil.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /*
  13. * ptutil.c - utility functions for Pass Through Authentication
  14. *
  15. */
  16. #include "passthru.h"
  17. /*
  18. * Convert a char * array into a struct berval * array.
  19. * Always succeeds.
  20. */
  21. struct berval **
  22. passthru_strs2bervals( char **ss )
  23. {
  24. int i;
  25. struct berval **bvs;
  26. if ( ss == NULL || ss[0] == NULL ) {
  27. return( NULL );
  28. }
  29. for ( i = 0; ss[i] != NULL; ++i ) {
  30. ;
  31. }
  32. bvs = (struct berval **)slapi_ch_calloc( i + 1, sizeof( struct berval * ));
  33. for ( i = 0; ss[i] != NULL; ++i ) {
  34. bvs[i] = (struct berval *)slapi_ch_malloc( sizeof( struct berval ));
  35. bvs[i]->bv_val = slapi_ch_strdup( ss[i] );
  36. bvs[i]->bv_len = strlen( ss[i] );
  37. }
  38. return( bvs );
  39. }
  40. /*
  41. * Convert a struct berval * array into a char * array.
  42. * Always succeeds.
  43. */
  44. char **
  45. passthru_bervals2strs( struct berval **bvs )
  46. {
  47. int i;
  48. char **strs;
  49. if ( bvs == NULL || bvs[0] == NULL ) {
  50. return( NULL );
  51. }
  52. for ( i = 0; bvs[i] != NULL; ++i ) {
  53. ;
  54. }
  55. strs = (char **)slapi_ch_calloc( i + 1, sizeof( char * ));
  56. for ( i = 0; bvs[i] != NULL; ++i ) {
  57. strs[i] = slapi_ch_strdup( bvs[i]->bv_val );
  58. }
  59. return( strs );
  60. }
  61. void
  62. passthru_free_bervals( struct berval **bvs )
  63. {
  64. int i;
  65. if ( bvs != NULL ) {
  66. for ( i = 0; bvs[ i ] != NULL; ++i ) {
  67. slapi_ch_free( (void **)&bvs[ i ] );
  68. }
  69. }
  70. slapi_ch_free( (void **)&bvs );
  71. }