init.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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
  37. load_server_libs(const char *dir)
  38. {
  39. int rv = LDAPU_SUCCESS;
  40. PRDir *ds;
  41. int suffix_len = strlen(DLL_SUFFIX);
  42. if ((ds = PR_OpenDir(dir)) != NULL) {
  43. PRDirEntry *d;
  44. /* Dir exists */
  45. while ((d = PR_ReadDir(ds, PR_SKIP_BOTH))) {
  46. PRLibrary *lib = 0;
  47. const char *libname = d->name;
  48. int len = strlen(libname);
  49. int is_lib;
  50. is_lib = (len > suffix_len && !strcmp(libname + len - suffix_len, 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)
  56. rv = LDAPU_ERR_UNABLE_TO_LOAD_PLUGIN;
  57. }
  58. }
  59. } else {
  60. /* It's ok if dir doesn't exists */
  61. }
  62. return rv;
  63. }
  64. NSAPI_PUBLIC int
  65. ldaputil_init(const char *config_file,
  66. const char *dllname,
  67. const char *serv_root,
  68. const char *serv_type,
  69. const char *serv_id)
  70. {
  71. int rv = LDAPU_SUCCESS;
  72. static int initialized = 0;
  73. /* If already initialized, cleanup the old structures */
  74. if (initialized)
  75. ldaputil_exit();
  76. if (config_file && *config_file) {
  77. char dir[1024];
  78. LDAPUCertMapListInfo_t *certmap_list;
  79. LDAPUCertMapInfo_t *certmap_default;
  80. if (serv_root && *serv_root) {
  81. /* Load common libraries */
  82. PR_snprintf(dir, sizeof(dir), "%s%clib%c%s", serv_root, FILE_PATHSEP,
  83. FILE_PATHSEP, "common");
  84. rv = load_server_libs(dir);
  85. if (rv != LDAPU_SUCCESS)
  86. return rv;
  87. if (serv_type && *serv_type) {
  88. /* Load server type specific libraries */
  89. sprintf(dir, "%s%clib%c%s", serv_root, FILE_PATHSEP,
  90. FILE_PATHSEP, serv_type);
  91. rv = load_server_libs(dir);
  92. if (rv != LDAPU_SUCCESS)
  93. return rv;
  94. if (serv_id && *serv_id) {
  95. /* Load server instance specific libraries */
  96. sprintf(dir, "%s%clib%c%s", serv_root, FILE_PATHSEP,
  97. FILE_PATHSEP, serv_id);
  98. rv = load_server_libs(dir);
  99. if (rv != LDAPU_SUCCESS)
  100. return rv;
  101. }
  102. }
  103. }
  104. rv = ldapu_certmap_init(config_file, dllname, &certmap_list,
  105. &certmap_default);
  106. }
  107. initialized = 1;
  108. if (rv != LDAPU_SUCCESS)
  109. return rv;
  110. return rv;
  111. }