retrocl_create.c 11 KB

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