retrocl_create.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. #include "retrocl.h"
  42. /*
  43. The changelog is created by
  44. - changing the node in the dse tree which represents the changelog plugin
  45. to enabled on,
  46. - shutting down the server,
  47. - starting the server.
  48. */
  49. /******************************/
  50. /*
  51. * Function: retrocl_create_be
  52. *
  53. * Returns: LDAP_
  54. *
  55. * Arguments: location in file system to put changelog, or NULL for default
  56. *
  57. * Description:
  58. * add an entry of class nsBackendInstance below cn=ldbm,cn=plugins,cn=config
  59. *
  60. */
  61. static int retrocl_create_be(const char *bedir)
  62. {
  63. Slapi_PBlock *pb = NULL;
  64. Slapi_Entry *e;
  65. struct berval *vals[2];
  66. struct berval val;
  67. int rc;
  68. vals[0] = &val;
  69. vals[1] = NULL;
  70. e = slapi_entry_alloc();
  71. slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_LDBM_DN));
  72. /* Set the objectclass attribute */
  73. val.bv_val = "top";
  74. val.bv_len = 3;
  75. slapi_entry_add_values( e, "objectclass", vals );
  76. /* Set the objectclass attribute */
  77. val.bv_val = "extensibleObject";
  78. val.bv_len = strlen(val.bv_val);
  79. slapi_entry_add_values( e, "objectclass", vals );
  80. /* Set the objectclass attribute */
  81. val.bv_val = "nsBackendInstance";
  82. val.bv_len = strlen(val.bv_val);
  83. slapi_entry_add_values( e, "objectclass", vals );
  84. val.bv_val = "changelog";
  85. val.bv_len = strlen(val.bv_val);
  86. slapi_entry_add_values( e, "cn", vals );
  87. val.bv_val = RETROCL_BE_CACHESIZE;
  88. val.bv_len = strlen(val.bv_val);
  89. slapi_entry_add_values( e, "nsslapd-cachesize", vals );
  90. val.bv_val = RETROCL_CHANGELOG_DN;
  91. val.bv_len = strlen(val.bv_val);
  92. slapi_entry_add_values( e, "nsslapd-suffix", vals );
  93. val.bv_val = RETROCL_BE_CACHEMEMSIZE;
  94. val.bv_len = strlen(val.bv_val);
  95. slapi_entry_add_values( e, "nsslapd-cachememsize", vals );
  96. val.bv_val = "off";
  97. val.bv_len = strlen(val.bv_val);
  98. slapi_entry_add_values( e, "nsslapd-readonly", vals );
  99. if (bedir) {
  100. val.bv_val = (char *)bedir; /* cast const */
  101. val.bv_len = strlen(val.bv_val);
  102. slapi_entry_add_values( e, "nsslapd-directory", vals );
  103. }
  104. pb = slapi_pblock_new ();
  105. slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
  106. g_plg_identity[PLUGIN_RETROCL],
  107. 0 /* actions */ );
  108. slapi_add_internal_pb (pb);
  109. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  110. slapi_pblock_destroy(pb);
  111. if (rc == 0) {
  112. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  113. "created changelog database node\n");
  114. } else if (rc == LDAP_ALREADY_EXISTS) {
  115. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  116. "changelog database node already existed\n");
  117. } else {
  118. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "Changelog LDBM backend could not be created (%d)\n", rc);
  119. return rc;
  120. }
  121. /* we need the changenumber indexed */
  122. e = slapi_entry_alloc();
  123. slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_INDEX_DN));
  124. /* Set the objectclass attribute */
  125. val.bv_val = "top";
  126. val.bv_len = 3;
  127. slapi_entry_add_values( e, "objectclass", vals );
  128. /* Set the objectclass attribute */
  129. val.bv_val = "nsIndex";
  130. val.bv_len = strlen(val.bv_val);
  131. slapi_entry_add_values( e, "objectclass", vals );
  132. val.bv_val = "changenumber";
  133. val.bv_len = strlen(val.bv_val);
  134. slapi_entry_add_values( e, "cn", vals );
  135. val.bv_val = "false";
  136. val.bv_len = strlen(val.bv_val);
  137. slapi_entry_add_values( e, "nssystemindex", vals );
  138. val.bv_val = "eq";
  139. val.bv_len = strlen(val.bv_val);
  140. slapi_entry_add_values( e, "nsindextype", vals );
  141. val.bv_val = "integerOrderingMatch";
  142. val.bv_len = strlen(val.bv_val);
  143. slapi_entry_add_values( e, "nsMatchingRule", vals );
  144. pb = slapi_pblock_new ();
  145. slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
  146. g_plg_identity[PLUGIN_RETROCL],
  147. 0 /* actions */ );
  148. slapi_add_internal_pb (pb);
  149. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  150. slapi_pblock_destroy(pb);
  151. if (rc == 0) {
  152. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  153. "created changenumber index node\n");
  154. } else if (rc == LDAP_ALREADY_EXISTS) {
  155. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  156. "changelog index node already existed\n");
  157. } else {
  158. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "Changelog LDBM backend changenumber index could not be created (%d)\n", rc);
  159. return rc;
  160. }
  161. return rc;
  162. }
  163. /*
  164. * Function: retrocl_create_config
  165. *
  166. * Returns: LDAP_
  167. *
  168. * Arguments: none
  169. *
  170. * Description:
  171. * This function is called if there was no mapping tree node or backend for
  172. * cn=changelog.
  173. */
  174. int retrocl_create_config(void)
  175. {
  176. Slapi_PBlock *pb = NULL;
  177. Slapi_Entry *e;
  178. struct berval *vals[2];
  179. struct berval val;
  180. int rc;
  181. vals[0] = &val;
  182. vals[1] = NULL;
  183. /* Assume the mapping tree node is missing. It doesn't hurt to
  184. * attempt to add it if it already exists. You will see a warning
  185. * in the errors file when the referenced backend does not exist.
  186. */
  187. e = slapi_entry_alloc();
  188. slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_MAPPINGTREE_DN));
  189. /* Set the objectclass attribute */
  190. val.bv_val = "top";
  191. val.bv_len = 3;
  192. slapi_entry_add_values( e, "objectclass", vals );
  193. /* Set the objectclass attribute */
  194. val.bv_val = "extensibleObject";
  195. val.bv_len = strlen(val.bv_val);
  196. slapi_entry_add_values( e, "objectclass", vals );
  197. /* Set the objectclass attribute */
  198. val.bv_val = "nsMappingTree";
  199. val.bv_len = strlen(val.bv_val);
  200. slapi_entry_add_values( e, "objectclass", vals );
  201. val.bv_val = "backend";
  202. val.bv_len = strlen(val.bv_val);
  203. slapi_entry_add_values( e, "nsslapd-state", vals );
  204. val.bv_val = RETROCL_CHANGELOG_DN;
  205. val.bv_len = strlen(val.bv_val);
  206. slapi_entry_add_values( e, "cn", vals );
  207. val.bv_val = "changelog";
  208. val.bv_len = strlen(val.bv_val);
  209. slapi_entry_add_values( e, "nsslapd-backend", vals );
  210. pb = slapi_pblock_new ();
  211. slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
  212. g_plg_identity[PLUGIN_RETROCL],
  213. 0 /* actions */ );
  214. slapi_add_internal_pb (pb);
  215. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  216. slapi_pblock_destroy(pb);
  217. if (rc == 0) {
  218. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  219. "created changelog mapping tree node\n");
  220. } else if (rc == LDAP_ALREADY_EXISTS) {
  221. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  222. "changelog mapping tree node already existed\n");
  223. } else {
  224. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "cn=\"cn=changelog\",cn=mapping tree,cn=config could not be created (%d)\n", rc);
  225. return rc;
  226. }
  227. retrocl_be_changelog = slapi_be_select_by_instance_name("changelog");
  228. if (retrocl_be_changelog == NULL) {
  229. /* This is not the nsslapd-changelogdir from cn=changelog4,cn=config */
  230. char *bedir;
  231. bedir = retrocl_get_config_str(CONFIG_CHANGELOG_DIRECTORY_ATTRIBUTE);
  232. if (bedir == NULL) {
  233. /* none specified */
  234. }
  235. rc = retrocl_create_be(bedir);
  236. slapi_ch_free ((void **)&bedir);
  237. if (rc != LDAP_SUCCESS && rc != LDAP_ALREADY_EXISTS) {
  238. return rc;
  239. }
  240. retrocl_be_changelog = slapi_be_select_by_instance_name("changelog");
  241. }
  242. return LDAP_SUCCESS;
  243. }
  244. /******************************/
  245. /* Function: retrocl_create_cle
  246. *
  247. * Arguments: none
  248. * Returns: nothing
  249. * Description: Attempts to create the cn=changelog entry which might already
  250. * exist.
  251. */
  252. void retrocl_create_cle (void)
  253. {
  254. Slapi_PBlock *pb = NULL;
  255. Slapi_Entry *e;
  256. int rc;
  257. struct berval *vals[2];
  258. struct berval val;
  259. vals[0] = &val;
  260. vals[1] = NULL;
  261. e = slapi_entry_alloc();
  262. slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_CHANGELOG_DN));
  263. /* Set the objectclass attribute */
  264. val.bv_val = "top";
  265. val.bv_len = strlen(val.bv_val);
  266. slapi_entry_add_values( e, "objectclass", vals );
  267. /* Set the objectclass attribute */
  268. val.bv_val = "nsContainer";
  269. val.bv_len = strlen(val.bv_val);
  270. slapi_entry_add_values( e, "objectclass", vals );
  271. /* Set the objectclass attribute */
  272. val.bv_val = "changelog";
  273. val.bv_len = strlen(val.bv_val);
  274. slapi_entry_add_values( e, "cn", vals );
  275. val.bv_val = RETROCL_ACL;
  276. val.bv_len = strlen(val.bv_val);
  277. slapi_entry_add_values( e, "aci", vals );
  278. pb = slapi_pblock_new ();
  279. slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
  280. g_plg_identity[PLUGIN_RETROCL],
  281. 0 /* actions */ );
  282. slapi_add_internal_pb (pb);
  283. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  284. slapi_pblock_destroy(pb);
  285. if (rc == 0) {
  286. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  287. "created cn=changelog\n");
  288. } else if (rc == LDAP_ALREADY_EXISTS) {
  289. slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  290. "cn=changelog already existed\n");
  291. } else {
  292. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "cn=changelog could not be created (%d)\n", rc);
  293. }
  294. }