1
0

retrocl_create.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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_FATAL, RETROCL_PLUGIN_NAME, "Changelog LDBM backend could not be created (%d)\n", rc);
  91. return rc;
  92. }
  93. /* we need the changenumber indexed */
  94. e = slapi_entry_alloc();
  95. /* RETROCL_INDEX_DN is no need to be normalized. */
  96. slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_INDEX_DN));
  97. /* Set the objectclass attribute */
  98. val.bv_val = "top";
  99. val.bv_len = 3;
  100. slapi_entry_add_values( e, "objectclass", vals );
  101. /* Set the objectclass attribute */
  102. val.bv_val = "nsIndex";
  103. val.bv_len = strlen(val.bv_val);
  104. slapi_entry_add_values( e, "objectclass", vals );
  105. val.bv_val = "changenumber";
  106. val.bv_len = strlen(val.bv_val);
  107. slapi_entry_add_values( e, "cn", vals );
  108. val.bv_val = "false";
  109. val.bv_len = strlen(val.bv_val);
  110. slapi_entry_add_values( e, "nssystemindex", vals );
  111. val.bv_val = "eq";
  112. val.bv_len = strlen(val.bv_val);
  113. slapi_entry_add_values( e, "nsindextype", vals );
  114. val.bv_val = "integerOrderingMatch";
  115. val.bv_len = strlen(val.bv_val);
  116. slapi_entry_add_values( e, "nsMatchingRule", vals );
  117. pb = slapi_pblock_new ();
  118. slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
  119. g_plg_identity[PLUGIN_RETROCL],
  120. 0 /* actions */ );
  121. slapi_add_internal_pb (pb);
  122. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  123. slapi_pblock_destroy(pb);
  124. if (rc == 0) {
  125. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  126. "created changenumber index node\n");
  127. } else if (rc == LDAP_ALREADY_EXISTS) {
  128. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  129. "changelog index node already existed\n");
  130. } else {
  131. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "Changelog LDBM backend changenumber index could not be created (%d)\n", rc);
  132. return rc;
  133. }
  134. return rc;
  135. }
  136. /*
  137. * Function: retrocl_create_config
  138. *
  139. * Returns: LDAP_
  140. *
  141. * Arguments: none
  142. *
  143. * Description:
  144. * This function is called if there was no mapping tree node or backend for
  145. * cn=changelog.
  146. */
  147. int retrocl_create_config(void)
  148. {
  149. Slapi_PBlock *pb = NULL;
  150. Slapi_Entry *e;
  151. struct berval *vals[2];
  152. struct berval val;
  153. int rc;
  154. char *mappingtree_dn = NULL;
  155. vals[0] = &val;
  156. vals[1] = NULL;
  157. /* Assume the mapping tree node is missing. It doesn't hurt to
  158. * attempt to add it if it already exists. You will see a warning
  159. * in the errors file when the referenced backend does not exist.
  160. */
  161. e = slapi_entry_alloc();
  162. /* This function converts the old DN style to the new one. */
  163. mappingtree_dn = slapi_create_dn_string("%s", RETROCL_MAPPINGTREE_DN);
  164. if (NULL == mappingtree_dn) {
  165. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  166. "retrocl_create_config: failed to normalize "
  167. "mappingtree dn %s\n", RETROCL_MAPPINGTREE_DN);
  168. return LDAP_PARAM_ERROR;
  169. }
  170. slapi_entry_set_dn(e, mappingtree_dn); /* mappingtree_dn is consumed */
  171. /* Set the objectclass attribute */
  172. val.bv_val = "top";
  173. val.bv_len = 3;
  174. slapi_entry_add_values( e, "objectclass", vals );
  175. /* Set the objectclass attribute */
  176. val.bv_val = "extensibleObject";
  177. val.bv_len = strlen(val.bv_val);
  178. slapi_entry_add_values( e, "objectclass", vals );
  179. /* Set the objectclass attribute */
  180. val.bv_val = "nsMappingTree";
  181. val.bv_len = strlen(val.bv_val);
  182. slapi_entry_add_values( e, "objectclass", vals );
  183. val.bv_val = "backend";
  184. val.bv_len = strlen(val.bv_val);
  185. slapi_entry_add_values( e, "nsslapd-state", vals );
  186. val.bv_val = RETROCL_CHANGELOG_DN;
  187. val.bv_len = strlen(val.bv_val);
  188. slapi_entry_add_values( e, "cn", vals );
  189. val.bv_val = "changelog";
  190. val.bv_len = strlen(val.bv_val);
  191. slapi_entry_add_values( e, "nsslapd-backend", vals );
  192. pb = slapi_pblock_new ();
  193. slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
  194. g_plg_identity[PLUGIN_RETROCL],
  195. 0 /* actions */ );
  196. slapi_add_internal_pb (pb);
  197. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  198. slapi_pblock_destroy(pb);
  199. if (rc == 0) {
  200. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  201. "created changelog mapping tree node\n");
  202. } else if (rc == LDAP_ALREADY_EXISTS) {
  203. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  204. "changelog mapping tree node already existed\n");
  205. } else {
  206. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "cn=\"cn=changelog\",cn=mapping tree,cn=config could not be created (%d)\n", rc);
  207. return rc;
  208. }
  209. retrocl_be_changelog = slapi_be_select_by_instance_name("changelog");
  210. if (retrocl_be_changelog == NULL) {
  211. /* This is not the nsslapd-changelogdir from cn=changelog4,cn=config */
  212. char *bedir;
  213. bedir = retrocl_get_config_str(CONFIG_CHANGELOG_DIRECTORY_ATTRIBUTE);
  214. if (bedir == NULL) {
  215. /* none specified */
  216. }
  217. rc = retrocl_create_be(bedir);
  218. slapi_ch_free ((void **)&bedir);
  219. if (rc != LDAP_SUCCESS && rc != LDAP_ALREADY_EXISTS) {
  220. return rc;
  221. }
  222. retrocl_be_changelog = slapi_be_select_by_instance_name("changelog");
  223. }
  224. return LDAP_SUCCESS;
  225. }
  226. /******************************/
  227. /* Function: retrocl_create_cle
  228. *
  229. * Arguments: none
  230. * Returns: nothing
  231. * Description: Attempts to create the cn=changelog entry which might already
  232. * exist.
  233. */
  234. void retrocl_create_cle (void)
  235. {
  236. Slapi_PBlock *pb = NULL;
  237. Slapi_Entry *e;
  238. int rc;
  239. struct berval *vals[2];
  240. struct berval val;
  241. vals[0] = &val;
  242. vals[1] = NULL;
  243. e = slapi_entry_alloc();
  244. slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_CHANGELOG_DN));
  245. /* Set the objectclass attribute */
  246. val.bv_val = "top";
  247. val.bv_len = strlen(val.bv_val);
  248. slapi_entry_add_values( e, "objectclass", vals );
  249. /* Set the objectclass attribute */
  250. val.bv_val = "nsContainer";
  251. val.bv_len = strlen(val.bv_val);
  252. slapi_entry_add_values( e, "objectclass", vals );
  253. /* Set the objectclass attribute */
  254. val.bv_val = "changelog";
  255. val.bv_len = strlen(val.bv_val);
  256. slapi_entry_add_values( e, "cn", vals );
  257. pb = slapi_pblock_new ();
  258. slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
  259. g_plg_identity[PLUGIN_RETROCL],
  260. 0 /* actions */ );
  261. slapi_add_internal_pb (pb);
  262. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  263. slapi_pblock_destroy(pb);
  264. if (rc == 0) {
  265. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  266. "created cn=changelog\n");
  267. } else if (rc == LDAP_ALREADY_EXISTS) {
  268. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  269. "cn=changelog already existed\n");
  270. } else {
  271. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "cn=changelog could not be created (%d)\n", rc);
  272. }
  273. }