cl5_config.c 25 KB

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