1
0

cl5_config.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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. /* cl5_config.c - functions to process changelog configuration
  42. */
  43. #include <string.h>
  44. #include <prio.h>
  45. #include "repl5.h"
  46. #include "cl5.h"
  47. #include "cl5_clcache.h" /* To configure the Changelog Cache */
  48. #include "intrinsics.h" /* JCMREPL - Is this bad? */
  49. #ifdef TEST_CL5
  50. #include "cl5_test.h"
  51. #endif
  52. #include "nspr.h"
  53. #include "plstr.h"
  54. #define CONFIG_BASE "cn=changelog5,cn=config" /*"cn=changelog,cn=supplier,cn=replication5.0,cn=replication,cn=config"*/
  55. #define CONFIG_FILTER "(objectclass=*)"
  56. static Slapi_RWLock *s_configLock; /* guarantees that only on thread at a time
  57. modifies changelog configuration */
  58. /* Forward Declartions */
  59. static int changelog5_config_add (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  60. static int changelog5_config_modify (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  61. static int changelog5_config_delete (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  62. static int dont_allow_that(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode, char *returntext, void *arg);
  63. static void changelog5_extract_config(Slapi_Entry* entry, changelog5Config *config);
  64. static changelog5Config * changelog5_dup_config(changelog5Config *config);
  65. static void replace_bslash (char *dir);
  66. static int notify_replica (Replica *r, void *arg);
  67. static int _is_absolutepath (char *dir);
  68. int changelog5_config_init()
  69. {
  70. /* The FE DSE *must* be initialised before we get here */
  71. /* create the configuration lock, if not yet created. */
  72. if (!s_configLock)
  73. {
  74. s_configLock = slapi_new_rwlock();
  75. }
  76. if (s_configLock == NULL)
  77. {
  78. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  79. "changelog5_config_init: failed to create configurationlock; "
  80. "NSPR error - %d\n",PR_GetError ());
  81. return 1;
  82. }
  83. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_BASE,
  84. CONFIG_FILTER, changelog5_config_add, NULL);
  85. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_BASE,
  86. CONFIG_FILTER, changelog5_config_modify, NULL);
  87. slapi_config_register_callback(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_BASE,
  88. CONFIG_FILTER, dont_allow_that, NULL);
  89. slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_BASE,
  90. CONFIG_FILTER, changelog5_config_delete, NULL);
  91. return 0;
  92. }
  93. void changelog5_config_cleanup()
  94. {
  95. slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_BASE,
  96. CONFIG_FILTER, changelog5_config_add);
  97. slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_BASE,
  98. CONFIG_FILTER, changelog5_config_modify);
  99. slapi_config_remove_callback(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_BASE,
  100. CONFIG_FILTER, dont_allow_that);
  101. slapi_config_remove_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_BASE,
  102. CONFIG_FILTER, changelog5_config_delete);
  103. if (s_configLock)
  104. {
  105. slapi_destroy_rwlock (s_configLock);
  106. s_configLock = NULL;
  107. }
  108. }
  109. int changelog5_read_config (changelog5Config *config)
  110. {
  111. int rc = LDAP_SUCCESS;
  112. Slapi_PBlock *pb;
  113. pb = slapi_pblock_new ();
  114. slapi_search_internal_set_pb (pb, CONFIG_BASE, LDAP_SCOPE_BASE,
  115. CONFIG_FILTER, NULL, 0, NULL, NULL,
  116. repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION), 0);
  117. slapi_search_internal_pb (pb);
  118. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
  119. if ( LDAP_SUCCESS == rc )
  120. {
  121. Slapi_Entry **entries = NULL;
  122. slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries );
  123. if ( NULL != entries && NULL != entries[0])
  124. {
  125. /* Extract the config info from the changelog entry */
  126. changelog5_extract_config(entries[0], config);
  127. }
  128. else
  129. {
  130. memset (config, 0, sizeof (*config));
  131. rc = LDAP_SUCCESS;
  132. }
  133. }
  134. else
  135. {
  136. memset (config, 0, sizeof (*config));
  137. rc = LDAP_SUCCESS;
  138. }
  139. slapi_free_search_results_internal(pb);
  140. slapi_pblock_destroy(pb);
  141. return rc;
  142. }
  143. void changelog5_config_done (changelog5Config *config)
  144. {
  145. if (config) {
  146. /* slapi_ch_free_string accepts NULL pointer */
  147. slapi_ch_free_string (&config->maxAge);
  148. slapi_ch_free_string (&config->dir);
  149. }
  150. }
  151. void changelog5_config_free (changelog5Config **config)
  152. {
  153. changelog5_config_done(*config);
  154. slapi_ch_free((void **)config);
  155. }
  156. static int
  157. changelog5_config_add (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter,
  158. int *returncode, char *returntext, void *arg)
  159. {
  160. int rc;
  161. changelog5Config config;
  162. *returncode = LDAP_SUCCESS;
  163. slapi_rwlock_wrlock (s_configLock);
  164. /* we already have a configured changelog - don't need to do anything
  165. since add operation will fail */
  166. if (cl5GetState () == CL5_STATE_OPEN)
  167. {
  168. *returncode = 1;
  169. if (returntext)
  170. {
  171. strcpy (returntext, "attempt to add changelog when it already exists");
  172. }
  173. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  174. "changelog5_config_add: changelog already exist; "
  175. "request ignored\n");
  176. goto done;
  177. }
  178. changelog5_extract_config(e, &config);
  179. if (config.dir == NULL)
  180. {
  181. *returncode = 1;
  182. if (returntext)
  183. {
  184. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "NULL changelog directory");
  185. }
  186. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  187. "changelog5_config_add: NULL changelog directory\n");
  188. goto done;
  189. }
  190. if (!cl5DbDirIsEmpty(config.dir))
  191. {
  192. *returncode = 1;
  193. if (returntext)
  194. {
  195. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  196. "The changelog directory [%s] already exists and is not empty. "
  197. "Please choose a directory that does not exist or is empty.\n",
  198. config.dir);
  199. }
  200. goto done;
  201. }
  202. /* start the changelog */
  203. rc = cl5Open (config.dir, &config.dbconfig);
  204. if (rc != CL5_SUCCESS)
  205. {
  206. *returncode = 1;
  207. if (returntext)
  208. {
  209. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "failed to start changelog; error - %d", rc);
  210. }
  211. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  212. "changelog5_config_add: failed to start changelog\n");
  213. goto done;
  214. }
  215. /* set trimming parameters */
  216. rc = cl5ConfigTrimming (config.maxEntries, config.maxAge, config.compactInterval);
  217. if (rc != CL5_SUCCESS)
  218. {
  219. *returncode = 1;
  220. if (returntext)
  221. {
  222. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "failed to configure changelog trimming; error - %d", rc);
  223. }
  224. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  225. "changelog5_config_add: failed to configure changelog trimming\n");
  226. goto done;
  227. }
  228. /* notify all the replicas that the changelog is configured
  229. so that the can log dummy changes if necessary. */
  230. replica_enumerate_replicas (notify_replica, NULL);
  231. #ifdef TEST_CL5
  232. testChangelog (TEST_ITERATION);
  233. #endif
  234. done:;
  235. slapi_rwlock_unlock (s_configLock);
  236. changelog5_config_done (&config);
  237. if (*returncode == LDAP_SUCCESS)
  238. {
  239. if (returntext)
  240. {
  241. returntext[0] = '\0';
  242. }
  243. return SLAPI_DSE_CALLBACK_OK;
  244. }
  245. return SLAPI_DSE_CALLBACK_ERROR;
  246. }
  247. static int
  248. changelog5_config_modify (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  249. int *returncode, char *returntext, void *arg)
  250. {
  251. int rc= 0;
  252. LDAPMod **mods;
  253. int i;
  254. changelog5Config config;
  255. changelog5Config * originalConfig = NULL;
  256. char *currentDir = NULL;
  257. *returncode = LDAP_SUCCESS;
  258. /* changelog must be open before its parameters can be modified */
  259. if (cl5GetState() != CL5_STATE_OPEN)
  260. {
  261. if (returntext)
  262. {
  263. strcpy (returntext, "changelog is not configured");
  264. }
  265. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  266. "changelog5_config_modify: changelog is not configured\n");
  267. return SLAPI_DSE_CALLBACK_ERROR;
  268. }
  269. slapi_rwlock_wrlock (s_configLock);
  270. /* changelog must be open before its parameters can be modified */
  271. if (cl5GetState() != CL5_STATE_OPEN)
  272. {
  273. *returncode = 1;
  274. if (returntext)
  275. {
  276. strcpy (returntext, "changelog is not configured");
  277. }
  278. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  279. "changelog5_config_modify: changelog is not configured\n");
  280. goto done;
  281. }
  282. /*
  283. * Extract all the original configuration: This is needed to ensure that the configuration
  284. * is trully reloaded. This was not needed before 091401 because the changelog configuration
  285. * was always hardcoded (NULL was being passed to cl5Open). Now we need to ensure we pass to
  286. * cl5Open the proper configuration...
  287. */
  288. changelog5_extract_config(e, &config);
  289. originalConfig = changelog5_dup_config(&config);
  290. /* Reset all the attributes that have been potentially modified by the current MODIFY operation */
  291. slapi_ch_free_string(&config.dir);
  292. config.dir = NULL;
  293. config.maxEntries = CL5_NUM_IGNORE;
  294. config.compactInterval = CL5_NUM_IGNORE;
  295. slapi_ch_free_string(&config.maxAge);
  296. config.maxAge = slapi_ch_strdup(CL5_STR_IGNORE);
  297. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  298. for (i = 0; mods[i] != NULL; i++)
  299. {
  300. if (mods[i]->mod_op & LDAP_MOD_DELETE)
  301. {
  302. /* We don't support deleting changelog attributes */
  303. }
  304. else
  305. {
  306. int j;
  307. for (j = 0; ((mods[i]->mod_values[j]) && (LDAP_SUCCESS == rc)); j++)
  308. {
  309. char *config_attr, *config_attr_value;
  310. config_attr = (char *) mods[i]->mod_type;
  311. config_attr_value = (char *) mods[i]->mod_bvalues[j]->bv_val;
  312. #define ATTR_MODIFIERSNAME "modifiersname"
  313. #define ATTR_MODIFYTIMESTAMP "modifytimestamp"
  314. if ( strcasecmp ( config_attr, ATTR_MODIFIERSNAME ) == 0 ) {
  315. continue;
  316. }
  317. if ( strcasecmp ( config_attr, ATTR_MODIFYTIMESTAMP ) == 0 ) {
  318. continue;
  319. }
  320. /* replace existing value */
  321. if ( strcasecmp (config_attr, CONFIG_CHANGELOG_DIR_ATTRIBUTE ) == 0 )
  322. {
  323. if (config_attr_value && config_attr_value[0] != '\0')
  324. {
  325. slapi_ch_free_string(&config.dir);
  326. config.dir = slapi_ch_strdup(config_attr_value);
  327. replace_bslash (config.dir);
  328. }
  329. else
  330. {
  331. *returncode = 1;
  332. if (returntext)
  333. {
  334. strcpy (returntext, "null changelog directory");
  335. }
  336. goto done;
  337. }
  338. }
  339. else if ( strcasecmp ( config_attr, CONFIG_CHANGELOG_MAXENTRIES_ATTRIBUTE ) == 0 )
  340. {
  341. if (config_attr_value && config_attr_value[0] != '\0')
  342. {
  343. config.maxEntries = atoi (config_attr_value);
  344. }
  345. else
  346. {
  347. config.maxEntries = 0;
  348. }
  349. }
  350. else if ( strcasecmp ( config_attr, CONFIG_CHANGELOG_MAXAGE_ATTRIBUTE ) == 0 )
  351. {
  352. slapi_ch_free_string(&config.maxAge);
  353. config.maxAge = slapi_ch_strdup(config_attr_value);
  354. }
  355. else if ( strcasecmp ( config_attr, CONFIG_CHANGELOG_COMPACTDB_ATTRIBUTE ) == 0 )
  356. {
  357. if (config_attr_value && config_attr_value[0] != '\0')
  358. {
  359. config.compactInterval = atoi (config_attr_value);
  360. }
  361. else
  362. {
  363. config.compactInterval = 0;
  364. }
  365. }
  366. else if ( strcasecmp ( config_attr, CONFIG_CHANGELOG_SYMMETRIC_KEY ) == 0 )
  367. {
  368. slapi_ch_free_string(&config.symmetricKey);
  369. config.symmetricKey = slapi_ch_strdup(config_attr_value);
  370. /* Storing the encryption symmetric key */
  371. /* no need to change any changelog configuration */
  372. goto done;
  373. }
  374. else
  375. {
  376. *returncode = LDAP_UNWILLING_TO_PERFORM;
  377. if (returntext)
  378. {
  379. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  380. "Unwilling to apply %s mods while the server is running", config_attr);
  381. }
  382. goto done;
  383. }
  384. }
  385. }
  386. }
  387. /* Undo the reset above for all the modifiable attributes that were not modified
  388. * except config.dir */
  389. if (config.maxEntries == CL5_NUM_IGNORE)
  390. config.maxEntries = originalConfig->maxEntries;
  391. if (config.compactInterval == CL5_NUM_IGNORE)
  392. config.compactInterval = originalConfig->compactInterval;
  393. if (strcmp (config.maxAge, CL5_STR_IGNORE) == 0) {
  394. slapi_ch_free_string(&config.maxAge);
  395. if (originalConfig->maxAge)
  396. config.maxAge = slapi_ch_strdup(originalConfig->maxAge);
  397. }
  398. /* attempt to change chagelog dir */
  399. if (config.dir)
  400. {
  401. currentDir = cl5GetDir ();
  402. if (currentDir == NULL)
  403. {
  404. /* something is wrong: we should never be here */
  405. *returncode = 1;
  406. if (returntext)
  407. {
  408. strcpy (returntext, "internal failure");
  409. }
  410. goto done;
  411. }
  412. #ifdef _WIN32
  413. if (strcasecmp (currentDir, config.dir) != 0)
  414. #else /* On Unix, path are case sensitive */
  415. if (strcmp (currentDir, config.dir) != 0)
  416. #endif
  417. {
  418. if (!cl5DbDirIsEmpty(config.dir))
  419. {
  420. *returncode = 1;
  421. if (returntext)
  422. {
  423. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  424. "The changelog directory [%s] already exists and is not empty. "
  425. "Please choose a directory that does not exist or is empty.\n",
  426. config.dir);
  427. }
  428. goto done;
  429. }
  430. if (!_is_absolutepath(config.dir) || (CL5_SUCCESS != cl5CreateDirIfNeeded(config.dir)))
  431. {
  432. *returncode = 1;
  433. if (returntext)
  434. {
  435. PL_strncpyz (returntext, "invalid changelog directory or insufficient access", SLAPI_DSE_RETURNTEXT_SIZE);
  436. }
  437. goto done;
  438. }
  439. /* changelog directory changed - need to remove the
  440. previous changelog and create new one */
  441. slapi_log_error(SLAPI_LOG_PLUGIN, repl_plugin_name_cl,
  442. "changelog5_config_modify: changelog directory changed; "
  443. "old dir - %s, new dir - %s; recreating changelog.\n",
  444. currentDir, config.dir);
  445. rc = cl5Close ();
  446. if (rc != CL5_SUCCESS)
  447. {
  448. *returncode = 1;
  449. if (returntext)
  450. {
  451. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "failed to close changelog; error - %d", rc);
  452. }
  453. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  454. "changelog5_config_modify: failed to close changelog\n");
  455. goto done;
  456. } else {
  457. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name_cl,
  458. "changelog5_config_modify: closed the changelog\n");
  459. }
  460. rc = cl5Delete (currentDir);
  461. if (rc != CL5_SUCCESS)
  462. {
  463. *returncode = 1;
  464. if (returntext)
  465. {
  466. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "failed to remove changelog; error - %d", rc);
  467. }
  468. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  469. "changelog5_config_modify: failed to remove changelog\n");
  470. goto done;
  471. } else {
  472. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name_cl,
  473. "changelog5_config_modify: deleted the changelog at %s\n", currentDir);
  474. }
  475. rc = cl5Open (config.dir, &config.dbconfig);
  476. if (rc != CL5_SUCCESS)
  477. {
  478. *returncode = 1;
  479. if (returntext)
  480. {
  481. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "failed to restart changelog; error - %d", rc);
  482. }
  483. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  484. "changelog5_config_modify: failed to restart changelog\n");
  485. /* before finishing, let's try to do some error recovery */
  486. if (CL5_SUCCESS != cl5Open(currentDir, &config.dbconfig))
  487. {
  488. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  489. "changelog5_config_modify: failed to restore previous changelog\n");
  490. }
  491. goto done;
  492. } else {
  493. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name_cl,
  494. "changelog5_config_modify: opened the changelog at %s\n", config.dir);
  495. }
  496. }
  497. }
  498. /* one of the changelog parameters is modified */
  499. if (config.maxEntries != CL5_NUM_IGNORE ||
  500. strcmp (config.maxAge, CL5_STR_IGNORE) != 0)
  501. {
  502. rc = cl5ConfigTrimming (config.maxEntries, config.maxAge, config.compactInterval);
  503. if (rc != CL5_SUCCESS)
  504. {
  505. *returncode = 1;
  506. if (returntext)
  507. {
  508. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "failed to configure changelog trimming; error - %d", rc);
  509. }
  510. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  511. "changelog5_config_modify: failed to configure changelog trimming\n");
  512. goto done;
  513. }
  514. }
  515. done:;
  516. slapi_rwlock_unlock (s_configLock);
  517. changelog5_config_done (&config);
  518. changelog5_config_free (&originalConfig);
  519. /* slapi_ch_free accepts NULL pointer */
  520. slapi_ch_free ((void**)&currentDir);
  521. if (*returncode == LDAP_SUCCESS)
  522. {
  523. if (returntext)
  524. {
  525. returntext[0] = '\0';
  526. }
  527. return SLAPI_DSE_CALLBACK_OK;
  528. }
  529. return SLAPI_DSE_CALLBACK_ERROR;
  530. }
  531. static int
  532. changelog5_config_delete (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter,
  533. int *returncode, char *returntext, void *arg)
  534. {
  535. int rc;
  536. char *currentDir = NULL;
  537. *returncode = LDAP_SUCCESS;
  538. /* changelog must be open before it can be deleted */
  539. if (cl5GetState () != CL5_STATE_OPEN)
  540. {
  541. *returncode = 1;
  542. if (returntext)
  543. {
  544. PL_strncpyz(returntext, "changelog is not configured", SLAPI_DSE_RETURNTEXT_SIZE);
  545. }
  546. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  547. "changelog5_config_delete: chagelog is not configured\n");
  548. return SLAPI_DSE_CALLBACK_ERROR;
  549. }
  550. slapi_rwlock_wrlock (s_configLock);
  551. /* changelog must be open before it can be deleted */
  552. if (cl5GetState () != CL5_STATE_OPEN)
  553. {
  554. *returncode = 1;
  555. if (returntext)
  556. {
  557. PL_strncpyz(returntext, "changelog is not configured", SLAPI_DSE_RETURNTEXT_SIZE);
  558. }
  559. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  560. "changelog5_config_delete: chagelog is not configured\n");
  561. goto done;
  562. }
  563. currentDir = cl5GetDir ();
  564. if (currentDir == NULL)
  565. {
  566. /* something is wrong: we should never be here */
  567. *returncode = 1;
  568. if (returntext)
  569. {
  570. PL_strncpyz (returntext, "internal failure", SLAPI_DSE_RETURNTEXT_SIZE);
  571. }
  572. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  573. "changelog5_config_delete: NULL directory\n");
  574. goto done;
  575. }
  576. /* this call will block until all threads using changelog
  577. release changelog by calling cl5RemoveThread () */
  578. rc = cl5Close ();
  579. if (rc != CL5_SUCCESS)
  580. {
  581. *returncode = 1;
  582. if (returntext)
  583. {
  584. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "failed to close changelog; error - %d", rc);
  585. }
  586. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  587. "changelog5_config_delete: failed to close changelog\n");
  588. goto done;
  589. }
  590. rc = cl5Delete (currentDir);
  591. if (rc != CL5_SUCCESS)
  592. {
  593. *returncode = 1;
  594. if (returntext)
  595. {
  596. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "failed to remove changelog; error - %d", rc);
  597. }
  598. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl,
  599. "changelog5_config_delete: failed to remove changelog\n");
  600. goto done;
  601. }
  602. done:;
  603. slapi_rwlock_unlock (s_configLock);
  604. /* slapi_ch_free accepts NULL pointer */
  605. slapi_ch_free ((void**)&currentDir);
  606. if (*returncode == LDAP_SUCCESS)
  607. {
  608. if (returntext)
  609. {
  610. returntext[0] = '\0';
  611. }
  612. return SLAPI_DSE_CALLBACK_OK;
  613. }
  614. return SLAPI_DSE_CALLBACK_ERROR;
  615. }
  616. static int dont_allow_that(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  617. int *returncode, char *returntext, void *arg)
  618. {
  619. *returncode = LDAP_UNWILLING_TO_PERFORM;
  620. return SLAPI_DSE_CALLBACK_ERROR;
  621. }
  622. static changelog5Config * changelog5_dup_config(changelog5Config *config)
  623. {
  624. changelog5Config *dup = (changelog5Config *) slapi_ch_calloc(1, sizeof(changelog5Config));
  625. if (config->dir)
  626. dup->dir = slapi_ch_strdup(config->dir);
  627. if (config->maxAge)
  628. dup->maxAge = slapi_ch_strdup(config->maxAge);
  629. dup->maxEntries = config->maxEntries;
  630. dup->compactInterval = config->compactInterval;
  631. dup->dbconfig.pageSize = config->dbconfig.pageSize;
  632. dup->dbconfig.fileMode = config->dbconfig.fileMode;
  633. dup->dbconfig.maxConcurrentWrites = config->dbconfig.maxConcurrentWrites;
  634. return dup;
  635. }
  636. /*
  637. * Given the changelog configuration entry, extract the configuration directives.
  638. */
  639. static void changelog5_extract_config(Slapi_Entry* entry, changelog5Config *config)
  640. {
  641. char *arg;
  642. memset (config, 0, sizeof (*config));
  643. config->dir = slapi_entry_attr_get_charptr(entry,CONFIG_CHANGELOG_DIR_ATTRIBUTE);
  644. replace_bslash (config->dir);
  645. arg= slapi_entry_attr_get_charptr(entry,CONFIG_CHANGELOG_MAXENTRIES_ATTRIBUTE);
  646. if (arg)
  647. {
  648. config->maxEntries = atoi (arg);
  649. slapi_ch_free_string(&arg);
  650. }
  651. arg= slapi_entry_attr_get_charptr(entry,CONFIG_CHANGELOG_COMPACTDB_ATTRIBUTE);
  652. if (arg)
  653. {
  654. config->compactInterval = atoi (arg);
  655. slapi_ch_free_string(&arg);
  656. }
  657. else
  658. {
  659. config->compactInterval = CHANGELOGDB_COMPACT_INTERVAL;
  660. }
  661. config->maxAge = slapi_entry_attr_get_charptr(entry,CONFIG_CHANGELOG_MAXAGE_ATTRIBUTE);
  662. /*
  663. * Read the Changelog Internal Configuration Parameters for the Changelog DB
  664. */
  665. arg= slapi_entry_attr_get_charptr(entry, CONFIG_CHANGELOG_MAX_CONCURRENT_WRITES);
  666. if (arg)
  667. {
  668. config->dbconfig.maxConcurrentWrites = atoi (arg);
  669. slapi_ch_free_string(&arg);
  670. }
  671. if ( config->dbconfig.maxConcurrentWrites <= 0 )
  672. {
  673. config->dbconfig.maxConcurrentWrites = CL5_DEFAULT_CONFIG_MAX_CONCURRENT_WRITES;
  674. }
  675. /*
  676. * changelog encryption
  677. */
  678. arg = slapi_entry_attr_get_charptr(entry,
  679. CONFIG_CHANGELOG_ENCRYPTION_ALGORITHM);
  680. if (arg)
  681. {
  682. config->dbconfig.encryptionAlgorithm = slapi_ch_strdup(arg);
  683. slapi_ch_free_string(&arg);
  684. }
  685. else
  686. {
  687. config->dbconfig.encryptionAlgorithm = NULL; /* no encryption */
  688. }
  689. /*
  690. * symmetric key
  691. */
  692. arg = slapi_entry_attr_get_charptr(entry, CONFIG_CHANGELOG_SYMMETRIC_KEY);
  693. if (arg)
  694. {
  695. config->dbconfig.symmetricKey = slapi_ch_strdup(arg);
  696. slapi_ch_free_string(&arg);
  697. }
  698. else
  699. {
  700. config->dbconfig.symmetricKey = NULL; /* no symmetric key */
  701. }
  702. }
  703. static void replace_bslash (char *dir)
  704. {
  705. char *bslash;
  706. if (dir == NULL)
  707. return;
  708. bslash = strchr (dir, '\\');
  709. while (bslash)
  710. {
  711. *bslash = '/';
  712. bslash = strchr (bslash, '\\');
  713. }
  714. }
  715. static int notify_replica (Replica *r, void *arg)
  716. {
  717. return replica_log_ruv_elements (r);
  718. }
  719. static int _is_absolutepath (char * dir)
  720. {
  721. if (dir[0] == '/')
  722. return 1;
  723. #if defined(_WIN32)
  724. if (dir[2] == '/' && dir[1] == ':')
  725. return 1;
  726. #endif
  727. return 0;
  728. }