retrocl_create.c 9.9 KB

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