retrocl_create.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright 2001 Sun Microsystems, Inc.
  3. * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
  4. * All rights reserved.
  5. * END COPYRIGHT BLOCK **/
  6. #include "retrocl.h"
  7. /*
  8. The changelog is created by
  9. - changing the node in the dse tree which represents the changelog plugin
  10. to enabled on,
  11. - shutting down the server,
  12. - starting the server.
  13. */
  14. /******************************/
  15. /*
  16. * Function: retrocl_create_be
  17. *
  18. * Returns: LDAP_
  19. *
  20. * Arguments: location in file system to put changelog, or NULL for default
  21. *
  22. * Description:
  23. * add an entry of class nsBackendInstance below cn=ldbm,cn=plugins,cn=config
  24. *
  25. */
  26. static int retrocl_create_be(const char *bedir)
  27. {
  28. Slapi_PBlock *pb = NULL;
  29. Slapi_Entry *e;
  30. struct berval *vals[2];
  31. struct berval val;
  32. int rc;
  33. vals[0] = &val;
  34. vals[1] = NULL;
  35. e = slapi_entry_alloc();
  36. slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_LDBM_DN));
  37. /* Set the objectclass attribute */
  38. val.bv_val = "top";
  39. val.bv_len = 3;
  40. slapi_entry_add_values( e, "objectclass", vals );
  41. /* Set the objectclass attribute */
  42. val.bv_val = "extensibleObject";
  43. val.bv_len = strlen(val.bv_val);
  44. slapi_entry_add_values( e, "objectclass", vals );
  45. /* Set the objectclass attribute */
  46. val.bv_val = "nsBackendInstance";
  47. val.bv_len = strlen(val.bv_val);
  48. slapi_entry_add_values( e, "objectclass", vals );
  49. val.bv_val = "changelog";
  50. val.bv_len = strlen(val.bv_val);
  51. slapi_entry_add_values( e, "cn", vals );
  52. val.bv_val = RETROCL_BE_CACHESIZE;
  53. val.bv_len = strlen(val.bv_val);
  54. slapi_entry_add_values( e, "nsslapd-cachesize", vals );
  55. val.bv_val = RETROCL_CHANGELOG_DN;
  56. val.bv_len = strlen(val.bv_val);
  57. slapi_entry_add_values( e, "nsslapd-suffix", vals );
  58. val.bv_val = RETROCL_BE_CACHEMEMSIZE;
  59. val.bv_len = strlen(val.bv_val);
  60. slapi_entry_add_values( e, "nsslapd-cachememsize", vals );
  61. val.bv_val = "off";
  62. val.bv_len = strlen(val.bv_val);
  63. slapi_entry_add_values( e, "nsslapd-readonly", vals );
  64. if (bedir) {
  65. val.bv_val = (char *)bedir; /* cast const */
  66. val.bv_len = strlen(val.bv_val);
  67. slapi_entry_add_values( e, "nsslapd-directory", vals );
  68. }
  69. pb = slapi_pblock_new ();
  70. slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
  71. g_plg_identity[PLUGIN_RETROCL],
  72. 0 /* actions */ );
  73. slapi_add_internal_pb (pb);
  74. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  75. slapi_pblock_destroy(pb);
  76. if (rc == 0) {
  77. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  78. "created changelog database node\n");
  79. } else if (rc == LDAP_ALREADY_EXISTS) {
  80. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  81. "changelog database node already existed\n");
  82. } else {
  83. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "Changelog LDBM backend could not be created (%d)\n", rc);
  84. return rc;
  85. }
  86. /* we need the changenumber indexed */
  87. e = slapi_entry_alloc();
  88. slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_INDEX_DN));
  89. /* Set the objectclass attribute */
  90. val.bv_val = "top";
  91. val.bv_len = 3;
  92. slapi_entry_add_values( e, "objectclass", vals );
  93. /* Set the objectclass attribute */
  94. val.bv_val = "nsIndex";
  95. val.bv_len = strlen(val.bv_val);
  96. slapi_entry_add_values( e, "objectclass", vals );
  97. val.bv_val = "changenumber";
  98. val.bv_len = strlen(val.bv_val);
  99. slapi_entry_add_values( e, "cn", vals );
  100. val.bv_val = "false";
  101. val.bv_len = strlen(val.bv_val);
  102. slapi_entry_add_values( e, "nssystemindex", vals );
  103. val.bv_val = "eq";
  104. val.bv_len = strlen(val.bv_val);
  105. slapi_entry_add_values( e, "nsindextype", vals );
  106. pb = slapi_pblock_new ();
  107. slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
  108. g_plg_identity[PLUGIN_RETROCL],
  109. 0 /* actions */ );
  110. slapi_add_internal_pb (pb);
  111. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  112. slapi_pblock_destroy(pb);
  113. if (rc == 0) {
  114. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  115. "created changenumber index node\n");
  116. } else if (rc == LDAP_ALREADY_EXISTS) {
  117. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  118. "changelog index node already existed\n");
  119. } else {
  120. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "Changelog LDBM backend changenumber index could not be created (%d)\n", rc);
  121. return rc;
  122. }
  123. return rc;
  124. }
  125. /*
  126. * Function: retrocl_create_config
  127. *
  128. * Returns: LDAP_
  129. *
  130. * Arguments: none
  131. *
  132. * Description:
  133. * This function is called if there was no mapping tree node or backend for
  134. * cn=changelog.
  135. */
  136. int retrocl_create_config(void)
  137. {
  138. Slapi_PBlock *pb = NULL;
  139. Slapi_Entry *e;
  140. struct berval *vals[2];
  141. struct berval val;
  142. int rc;
  143. vals[0] = &val;
  144. vals[1] = NULL;
  145. /* Assume the mapping tree node is missing. It doesn't hurt to
  146. * attempt to add it if it already exists. You will see a warning
  147. * in the errors file when the referenced backend does not exist.
  148. */
  149. e = slapi_entry_alloc();
  150. slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_MAPPINGTREE_DN));
  151. /* Set the objectclass attribute */
  152. val.bv_val = "top";
  153. val.bv_len = 3;
  154. slapi_entry_add_values( e, "objectclass", vals );
  155. /* Set the objectclass attribute */
  156. val.bv_val = "extensibleObject";
  157. val.bv_len = strlen(val.bv_val);
  158. slapi_entry_add_values( e, "objectclass", vals );
  159. /* Set the objectclass attribute */
  160. val.bv_val = "nsMappingTree";
  161. val.bv_len = strlen(val.bv_val);
  162. slapi_entry_add_values( e, "objectclass", vals );
  163. val.bv_val = "backend";
  164. val.bv_len = strlen(val.bv_val);
  165. slapi_entry_add_values( e, "nsslapd-state", vals );
  166. val.bv_val = RETROCL_CHANGELOG_DN;
  167. val.bv_len = strlen(val.bv_val);
  168. slapi_entry_add_values( e, "cn", vals );
  169. val.bv_val = "changelog";
  170. val.bv_len = strlen(val.bv_val);
  171. slapi_entry_add_values( e, "nsslapd-backend", vals );
  172. pb = slapi_pblock_new ();
  173. slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
  174. g_plg_identity[PLUGIN_RETROCL],
  175. 0 /* actions */ );
  176. slapi_add_internal_pb (pb);
  177. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  178. slapi_pblock_destroy(pb);
  179. if (rc == 0) {
  180. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  181. "created changelog mapping tree node\n");
  182. } else if (rc == LDAP_ALREADY_EXISTS) {
  183. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  184. "changelog mapping tree node already existed\n");
  185. } else {
  186. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "cn=\"cn=changelog\",cn=mapping tree,cn=config could not be created (%d)\n", rc);
  187. return rc;
  188. }
  189. retrocl_be_changelog = slapi_be_select_by_instance_name("changelog");
  190. if (retrocl_be_changelog == NULL) {
  191. /* This is not the nsslapd-changelogdir from cn=changelog4,cn=config */
  192. char *bedir;
  193. bedir = retrocl_get_config_str(CONFIG_CHANGELOG_DIRECTORY_ATTRIBUTE);
  194. if (bedir == NULL) {
  195. /* none specified */
  196. }
  197. rc = retrocl_create_be(bedir);
  198. slapi_ch_free ((void **)&bedir);
  199. if (rc != LDAP_SUCCESS && rc != LDAP_ALREADY_EXISTS) {
  200. return rc;
  201. }
  202. retrocl_be_changelog = slapi_be_select_by_instance_name("changelog");
  203. }
  204. return LDAP_SUCCESS;
  205. }
  206. /******************************/
  207. /* Function: retrocl_create_cle
  208. *
  209. * Arguments: none
  210. * Returns: nothing
  211. * Description: Attempts to create the cn=changelog entry which might already
  212. * exist.
  213. */
  214. void retrocl_create_cle (void)
  215. {
  216. Slapi_PBlock *pb = NULL;
  217. Slapi_Entry *e;
  218. int rc;
  219. struct berval *vals[2];
  220. struct berval val;
  221. vals[0] = &val;
  222. vals[1] = NULL;
  223. e = slapi_entry_alloc();
  224. slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_CHANGELOG_DN));
  225. /* Set the objectclass attribute */
  226. val.bv_val = "top";
  227. val.bv_len = strlen(val.bv_val);
  228. slapi_entry_add_values( e, "objectclass", vals );
  229. /* Set the objectclass attribute */
  230. val.bv_val = "nsContainer";
  231. val.bv_len = strlen(val.bv_val);
  232. slapi_entry_add_values( e, "objectclass", vals );
  233. /* Set the objectclass attribute */
  234. val.bv_val = "changelog";
  235. val.bv_len = strlen(val.bv_val);
  236. slapi_entry_add_values( e, "cn", vals );
  237. val.bv_val = RETROCL_ACL;
  238. val.bv_len = strlen(val.bv_val);
  239. slapi_entry_add_values( e, "aci", vals );
  240. pb = slapi_pblock_new ();
  241. slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
  242. g_plg_identity[PLUGIN_RETROCL],
  243. 0 /* actions */ );
  244. slapi_add_internal_pb (pb);
  245. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  246. slapi_pblock_destroy(pb);
  247. if (rc == 0) {
  248. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  249. "created cn=changelog\n");
  250. } else if (rc == LDAP_ALREADY_EXISTS) {
  251. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  252. "cn=changelog already existed\n");
  253. } else {
  254. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "cn=changelog could not be created (%d)\n", rc);
  255. }
  256. }