init.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include <string.h>
  13. #include <prlink.h>
  14. #include <prio.h>
  15. #include <prprf.h>
  16. /*#include "base/file.h"*/
  17. #include "ldaputil/certmap.h"
  18. /*#include "ldaputil/ldapdb.h"*/
  19. #include "ldaputil/ldaputil.h"
  20. #include "ldaputil/cert.h"
  21. #include "ldaputil/errors.h"
  22. #include "ldaputil/init.h"
  23. #include "slapi-plugin.h"
  24. #ifndef FILE_PATHSEP
  25. #define FILE_PATHSEP '/'
  26. #endif
  27. #ifdef HPUX
  28. #ifdef __ia64
  29. #define DLL_SUFFIX ".so"
  30. #else
  31. #define DLL_SUFFIX ".sl"
  32. #endif
  33. #else
  34. #define DLL_SUFFIX ".so"
  35. #endif
  36. static int load_server_libs (const char *dir)
  37. {
  38. int rv = LDAPU_SUCCESS;
  39. PRDir* ds;
  40. int suffix_len = strlen(DLL_SUFFIX);
  41. if ((ds = PR_OpenDir(dir)) != NULL) {
  42. PRDirEntry *d;
  43. /* Dir exists */
  44. while( (d = PR_ReadDir(ds, PR_SKIP_BOTH)) ) {
  45. PRLibrary *lib = 0;
  46. const char *libname = d->name;
  47. int len = strlen(libname);
  48. int is_lib;
  49. is_lib = (len > suffix_len && !strcmp(libname+len-suffix_len,
  50. DLL_SUFFIX));
  51. if(is_lib) {
  52. char path[1024];
  53. PR_snprintf(path, sizeof(path), "%s%c%s", dir, FILE_PATHSEP, libname);
  54. lib = PR_LoadLibrary(path);
  55. if (!lib) rv = LDAPU_ERR_UNABLE_TO_LOAD_PLUGIN;
  56. }
  57. }
  58. }
  59. else {
  60. /* It's ok if dir doesn't exists */
  61. }
  62. return rv;
  63. }
  64. NSAPI_PUBLIC int ldaputil_init (const char *config_file,
  65. const char *dllname,
  66. const char *serv_root,
  67. const char *serv_type,
  68. const char *serv_id)
  69. {
  70. int rv = LDAPU_SUCCESS;
  71. static int initialized = 0;
  72. /* If already initialized, cleanup the old structures */
  73. if (initialized) ldaputil_exit();
  74. if (config_file && *config_file) {
  75. char dir[1024];
  76. LDAPUCertMapListInfo_t *certmap_list;
  77. LDAPUCertMapInfo_t *certmap_default;
  78. if (serv_root && *serv_root) {
  79. /* Load common libraries */
  80. PR_snprintf(dir, sizeof(dir), "%s%clib%c%s", serv_root, FILE_PATHSEP,
  81. FILE_PATHSEP, "common");
  82. rv = load_server_libs(dir);
  83. if (rv != LDAPU_SUCCESS) return rv;
  84. if (serv_type && *serv_type) {
  85. /* Load server type specific libraries */
  86. sprintf(dir, "%s%clib%c%s", serv_root, FILE_PATHSEP,
  87. FILE_PATHSEP, serv_type);
  88. rv = load_server_libs(dir);
  89. if (rv != LDAPU_SUCCESS) return rv;
  90. if (serv_id && *serv_id) {
  91. /* Load server instance specific libraries */
  92. sprintf(dir, "%s%clib%c%s", serv_root, FILE_PATHSEP,
  93. FILE_PATHSEP, serv_id);
  94. rv = load_server_libs(dir);
  95. if (rv != LDAPU_SUCCESS) return rv;
  96. }
  97. }
  98. }
  99. rv = ldapu_certmap_init (config_file, dllname, &certmap_list,
  100. &certmap_default);
  101. }
  102. initialized = 1;
  103. if (rv != LDAPU_SUCCESS) return rv;
  104. return rv;
  105. }