cl5_config.c 25 KB

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