retrocl_create.c 12 KB

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