repl5_agmtlist.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. /* repl5_agmtlist.c */
  7. /*
  8. Replication agreements are held in object set (objset.c).
  9. */
  10. #include "repl5.h"
  11. #define AGMT_CONFIG_BASE "cn=mapping tree, cn=config"
  12. #define CONFIG_FILTER "(objectclass=nsds5replicationagreement)"
  13. #define WINDOWS_CONFIG_FILTER "(objectclass=nsdsWindowsreplicationagreement)"
  14. #define GLOBAL_CONFIG_FILTER "(|" CONFIG_FILTER WINDOWS_CONFIG_FILTER " )"
  15. PRCallOnceType once = {0};
  16. Objset *agmt_set = NULL; /* The set of replication agreements */
  17. typedef struct agmt_wrapper {
  18. Repl_Agmt *agmt;
  19. void *handle;
  20. } agmt_wrapper;
  21. /*
  22. * Find the replication agreement whose entry DN matches the given DN.
  23. * Object is returned referenced, so be sure to release it when
  24. * finished.
  25. */
  26. Repl_Agmt *
  27. agmtlist_get_by_agmt_name(const Slapi_DN *agmt_name)
  28. {
  29. Repl_Agmt *ra;
  30. Object *ro;
  31. for (ro = objset_first_obj(agmt_set); NULL != ro;
  32. ro = objset_next_obj(agmt_set, ro))
  33. {
  34. ra = (Repl_Agmt *)object_get_data(ro);
  35. if (agmt_matches_name(ra, agmt_name))
  36. {
  37. break;
  38. }
  39. }
  40. return ra;
  41. }
  42. static int
  43. agmt_ptr_cmp(Object *ro, const void *arg)
  44. {
  45. Repl_Agmt *ra;
  46. Repl_Agmt *provided_ra = (Repl_Agmt *)arg;
  47. ra = object_get_data(ro);
  48. if (ra == provided_ra)
  49. return 0;
  50. else
  51. return 1;
  52. }
  53. static int
  54. agmt_dn_cmp(Object *ro, const void *arg)
  55. {
  56. Repl_Agmt *ra;
  57. Slapi_DN *sdn = (Slapi_DN *)arg;
  58. ra = object_get_data(ro);
  59. return(slapi_sdn_compare(sdn, agmt_get_dn_byref(ra)));
  60. }
  61. void
  62. agmtlist_release_agmt(Repl_Agmt *ra)
  63. {
  64. Object *ro;
  65. PR_ASSERT(NULL != agmt_set);
  66. PR_ASSERT(NULL != ra);
  67. ro = objset_find(agmt_set, agmt_ptr_cmp, (const void *)ra);
  68. if (NULL != ro)
  69. {
  70. /*
  71. * Release twice - once for the reference we got when finding
  72. * it, and once for the reference we got when we called
  73. * agmtlist_get_*().
  74. */
  75. object_release(ro);
  76. object_release(ro);
  77. }
  78. }
  79. /*
  80. * Note: when we add the new object, we have a reference to it. We hold
  81. * on to this reference until the agreement is deleted (or until the
  82. * server is shut down).
  83. */
  84. int
  85. add_new_agreement(Slapi_Entry *e)
  86. {
  87. int rc = 0;
  88. Repl_Agmt *ra = agmt_new_from_entry(e);
  89. Slapi_DN *replarea_sdn = NULL;
  90. Replica *replica = NULL;
  91. Object *repl_obj = NULL;
  92. Object *ro = NULL;
  93. if (ra == NULL) return 0;
  94. ro = object_new((void *)ra, agmt_delete);
  95. objset_add_obj(agmt_set, ro);
  96. object_release(ro); /* Object now owned by objset */
  97. /* get the replica for this agreement */
  98. replarea_sdn = agmt_get_replarea(ra);
  99. repl_obj = replica_get_replica_from_dn(replarea_sdn);
  100. slapi_sdn_free(&replarea_sdn);
  101. if (repl_obj) {
  102. replica = (Replica*)object_get_data (repl_obj);
  103. }
  104. rc = replica_start_agreement(replica, ra);
  105. if (repl_obj) object_release(repl_obj);
  106. return rc;
  107. }
  108. static int
  109. agmtlist_add_callback(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *entryAfter,
  110. int *returncode, char *returntext, void *arg)
  111. {
  112. int rc;
  113. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmt_add: begin\n");
  114. rc = add_new_agreement(e);
  115. if (0 != rc) {
  116. char *dn;
  117. slapi_pblock_get(pb, SLAPI_TARGET_DN, &dn);
  118. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmtlist_add_callback: "
  119. "Can't start agreement \"%s\"\n", dn);
  120. *returncode = LDAP_UNWILLING_TO_PERFORM;
  121. return SLAPI_DSE_CALLBACK_ERROR;
  122. }
  123. *returncode = LDAP_SUCCESS;
  124. return SLAPI_DSE_CALLBACK_OK;
  125. }
  126. static int
  127. agmtlist_modify_callback(Slapi_PBlock *pb, Slapi_Entry *entryBefore, Slapi_Entry *e,
  128. int *returncode, char *returntext, void *arg)
  129. {
  130. int i;
  131. char *dn;
  132. Slapi_DN *sdn = NULL;
  133. int start_initialize = 0, stop_initialize = 0, cancel_initialize = 0;
  134. int update_the_schedule = 0; /* do we need to update the repl sched? */
  135. Repl_Agmt *agmt = NULL;
  136. LDAPMod **mods;
  137. char buff [SLAPI_DSE_RETURNTEXT_SIZE];
  138. char *errortext = returntext ? returntext : buff;
  139. int rc = SLAPI_DSE_CALLBACK_OK;
  140. Slapi_Operation *op;
  141. void *identity;
  142. *returncode = LDAP_SUCCESS;
  143. /* just let internal operations originated from replication plugin to go through */
  144. slapi_pblock_get (pb, SLAPI_OPERATION, &op);
  145. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  146. if (operation_is_flag_set(op, OP_FLAG_INTERNAL) &&
  147. (identity == repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION)))
  148. {
  149. goto done;
  150. }
  151. slapi_pblock_get(pb, SLAPI_TARGET_DN, &dn);
  152. sdn= slapi_sdn_new_dn_byref(dn);
  153. agmt = agmtlist_get_by_agmt_name(sdn);
  154. if (NULL == agmt)
  155. {
  156. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmtlist_modify_callback: received "
  157. "a modification for unknown replication agreement \"%s\"\n", dn);
  158. goto done;
  159. }
  160. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  161. for (i = 0; NULL != mods && NULL != mods[i]; i++)
  162. {
  163. if (slapi_attr_types_equivalent(mods[i]->mod_type, type_nsds5ReplicaInitialize))
  164. {
  165. /* we don't allow delete attribute operations unless it was issued by
  166. the replication plugin - handled above */
  167. if (mods[i]->mod_op & LDAP_MOD_DELETE)
  168. {
  169. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  170. "deletion of %s attribute is not allowed\n", type_nsds5ReplicaInitialize);
  171. *returncode = LDAP_UNWILLING_TO_PERFORM;
  172. rc = SLAPI_DSE_CALLBACK_ERROR;
  173. break;
  174. }
  175. else
  176. {
  177. char *val;
  178. if (mods[i]->mod_bvalues && mods[i]->mod_bvalues[0])
  179. val = slapi_berval_get_string_copy (mods[i]->mod_bvalues[0]);
  180. else
  181. {
  182. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  183. "no value provided for %s attribute\n", type_nsds5ReplicaInitialize);
  184. *returncode = LDAP_UNWILLING_TO_PERFORM;
  185. rc = SLAPI_DSE_CALLBACK_ERROR;
  186. break;
  187. }
  188. /* Start replica initialization */
  189. if (val == NULL)
  190. {
  191. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "No value supplied for attr (%s)", mods[i]->mod_type);
  192. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: %s\n",
  193. errortext);
  194. *returncode = LDAP_UNWILLING_TO_PERFORM;
  195. rc = SLAPI_DSE_CALLBACK_ERROR;
  196. break;
  197. }
  198. if (strcasecmp (val, "start") == 0)
  199. {
  200. start_initialize = 1;
  201. }
  202. else if (strcasecmp (val, "stop") == 0)
  203. {
  204. stop_initialize = 1;
  205. }
  206. else if (strcasecmp (val, "cancel") == 0)
  207. {
  208. cancel_initialize = 1;
  209. }
  210. else
  211. {
  212. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "Invalid value (%s) value supplied for attr (%s)",
  213. val, mods[i]->mod_type);
  214. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: %s\n",
  215. errortext);
  216. }
  217. slapi_ch_free ((void**)&val);
  218. }
  219. }
  220. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  221. type_nsds5ReplicaUpdateSchedule))
  222. {
  223. /*
  224. * Request to update the replication schedule. Set a flag so
  225. * we know to update the schedule later.
  226. */
  227. update_the_schedule = 1;
  228. }
  229. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  230. type_nsds5ReplicaCredentials))
  231. {
  232. /* New replica credentials */
  233. if (agmt_set_credentials_from_entry(agmt, e) != 0)
  234. {
  235. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  236. "failed to update credentials for agreement %s\n",
  237. agmt_get_long_name(agmt));
  238. *returncode = LDAP_OPERATIONS_ERROR;
  239. rc = SLAPI_DSE_CALLBACK_ERROR;
  240. }
  241. }
  242. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  243. type_nsds5ReplicaTimeout))
  244. {
  245. /* New replica timeout */
  246. if (agmt_set_timeout_from_entry(agmt, e) != 0)
  247. {
  248. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  249. "failed to update timeout for agreement %s\n",
  250. agmt_get_long_name(agmt));
  251. *returncode = LDAP_OPERATIONS_ERROR;
  252. rc = SLAPI_DSE_CALLBACK_ERROR;
  253. }
  254. }
  255. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  256. type_nsds5ReplicaBusyWaitTime))
  257. {
  258. /* New replica busywaittime */
  259. if (agmt_set_busywaittime_from_entry(agmt, e) != 0)
  260. {
  261. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  262. "failed to update busy wait time for agreement %s\n",
  263. agmt_get_long_name(agmt));
  264. *returncode = LDAP_OPERATIONS_ERROR;
  265. rc = SLAPI_DSE_CALLBACK_ERROR;
  266. }
  267. }
  268. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  269. type_nsds5ReplicaSessionPauseTime))
  270. {
  271. /* New replica pausetime */
  272. if (agmt_set_pausetime_from_entry(agmt, e) != 0)
  273. {
  274. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  275. "failed to update session pause time for agreement %s\n",
  276. agmt_get_long_name(agmt));
  277. *returncode = LDAP_OPERATIONS_ERROR;
  278. rc = SLAPI_DSE_CALLBACK_ERROR;
  279. }
  280. }
  281. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  282. type_nsds5ReplicaBindDN))
  283. {
  284. /* New replica Bind DN */
  285. if (agmt_set_binddn_from_entry(agmt, e) != 0)
  286. {
  287. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  288. "failed to update bind DN for agreement %s\n",
  289. agmt_get_long_name(agmt));
  290. *returncode = LDAP_OPERATIONS_ERROR;
  291. rc = SLAPI_DSE_CALLBACK_ERROR;
  292. }
  293. }
  294. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  295. type_nsds5TransportInfo))
  296. {
  297. /* New Transport info */
  298. if (agmt_set_transportinfo_from_entry(agmt, e) != 0)
  299. {
  300. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  301. "failed to update transport info for agreement %s\n",
  302. agmt_get_long_name(agmt));
  303. *returncode = LDAP_OPERATIONS_ERROR;
  304. rc = SLAPI_DSE_CALLBACK_ERROR;
  305. }
  306. }
  307. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  308. type_nsds5ReplicaBindMethod))
  309. {
  310. /* New replica bind method */
  311. if (agmt_set_bind_method_from_entry(agmt, e) != 0)
  312. {
  313. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  314. "failed to update bind method for agreement %s\n",
  315. agmt_get_long_name(agmt));
  316. *returncode = LDAP_OPERATIONS_ERROR;
  317. rc = SLAPI_DSE_CALLBACK_ERROR;
  318. }
  319. }
  320. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  321. type_nsds5ReplicatedAttributeList))
  322. {
  323. char **denied_attrs = NULL;
  324. /* New set of excluded attributes */
  325. if (agmt_set_replicated_attributes_from_entry(agmt, e) != 0)
  326. {
  327. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  328. "failed to update replicated attributes for agreement %s\n",
  329. agmt_get_long_name(agmt));
  330. *returncode = LDAP_OPERATIONS_ERROR;
  331. rc = SLAPI_DSE_CALLBACK_ERROR;
  332. }
  333. /* Check that there are no verboten attributes in the exclude list */
  334. denied_attrs = agmt_validate_replicated_attributes(agmt);
  335. if (denied_attrs)
  336. {
  337. /* Report the error to the client */
  338. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  339. "attempt to exclude an illegal attribute in a fractional agreement\n");
  340. *returncode = LDAP_UNWILLING_TO_PERFORM;
  341. rc = SLAPI_DSE_CALLBACK_ERROR;
  342. /* Free the deny list if we got one */
  343. slapi_ch_array_free(denied_attrs);
  344. break;
  345. }
  346. }
  347. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  348. "nsds5debugreplicatimeout"))
  349. {
  350. char *val = slapi_entry_attr_get_charptr(e, "nsds5debugreplicatimeout");
  351. repl5_set_debug_timeout(val);
  352. slapi_ch_free_string(&val);
  353. }
  354. else if (strcasecmp (mods[i]->mod_type, "modifytimestamp") == 0 ||
  355. strcasecmp (mods[i]->mod_type, "modifiersname") == 0 ||
  356. strcasecmp (mods[i]->mod_type, "description") == 0)
  357. {
  358. /* ignore modifier's name and timestamp attributes and the description. */
  359. continue;
  360. }
  361. else
  362. {
  363. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  364. "modification of %s attribute is not allowed\n", mods[i]->mod_type);
  365. *returncode = LDAP_UNWILLING_TO_PERFORM;
  366. rc = SLAPI_DSE_CALLBACK_ERROR;
  367. break;
  368. }
  369. }
  370. if (stop_initialize)
  371. {
  372. agmt_stop (agmt);
  373. }
  374. else if (start_initialize)
  375. {
  376. if (agmt_initialize_replica(agmt) != 0) {
  377. /* The suffix is disabled */
  378. agmt_set_last_init_status(agmt, 0, NSDS50_REPL_DISABLED, NULL);
  379. }
  380. }
  381. else if (cancel_initialize)
  382. {
  383. agmt_replica_init_done(agmt);
  384. }
  385. if (update_the_schedule)
  386. {
  387. if (agmt_set_schedule_from_entry(agmt, e) != 0)
  388. {
  389. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  390. "failed to update replication schedule for agreement %s\n",
  391. agmt_get_long_name(agmt));
  392. *returncode = LDAP_OPERATIONS_ERROR;
  393. rc = SLAPI_DSE_CALLBACK_ERROR;
  394. }
  395. }
  396. done:
  397. if (NULL != agmt)
  398. {
  399. agmtlist_release_agmt(agmt);
  400. }
  401. if (sdn)
  402. slapi_sdn_free(&sdn);
  403. return rc;
  404. }
  405. static int
  406. agmtlist_delete_callback(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *entryAfter,
  407. int *returncode, char *returntext, void *arg)
  408. {
  409. Repl_Agmt *ra;
  410. Object *ro;
  411. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmt_delete: begin\n");
  412. ro = objset_find(agmt_set, agmt_dn_cmp, (const void *)slapi_entry_get_sdn_const(e));
  413. ra = (NULL == ro) ? NULL : (Repl_Agmt *)object_get_data(ro);
  414. if (NULL == ra)
  415. {
  416. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmtlist_delete: "
  417. "Tried to delete replication agreement \"%s\", but no such "
  418. "agreement was configured.\n", slapi_sdn_get_dn(slapi_entry_get_sdn_const(e)));
  419. }
  420. else
  421. {
  422. agmt_stop(ra);
  423. object_release(ro); /* Release ref acquired in objset_find */
  424. objset_remove_obj(agmt_set, ro); /* Releases a reference (should be final reference */
  425. }
  426. *returncode = LDAP_SUCCESS;
  427. return SLAPI_DSE_CALLBACK_OK;
  428. }
  429. static int
  430. agmtlist_rename_callback(Slapi_PBlock *pb, Slapi_Entry *entryBefore, Slapi_Entry *e,
  431. int *returncode, char *returntext, void *arg)
  432. {
  433. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmt_rename: begin\n");
  434. *returncode = LDAP_SUCCESS;
  435. return SLAPI_DSE_CALLBACK_OK;
  436. }
  437. static int
  438. handle_agmt_search(Slapi_Entry *e, void *callback_data)
  439. {
  440. int *agmtcount = (int *)callback_data;
  441. int rc;
  442. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
  443. "Found replication agreement named \"%s\".\n",
  444. slapi_sdn_get_dn(slapi_entry_get_sdn(e)));
  445. rc = add_new_agreement(e);
  446. if (0 == rc)
  447. {
  448. (*agmtcount)++;
  449. }
  450. else
  451. {
  452. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "The replication "
  453. "agreement named \"%s\" could not be correctly parsed. No "
  454. "replication will occur with this replica.\n",
  455. slapi_sdn_get_dn(slapi_entry_get_sdn(e)));
  456. }
  457. return rc;
  458. }
  459. static void
  460. agmtlist_objset_destructor(void **o)
  461. {
  462. /* XXXggood Nothing to do, I think. */
  463. }
  464. int
  465. agmtlist_config_init()
  466. {
  467. Slapi_PBlock *pb;
  468. int agmtcount = 0;
  469. agmt_set = objset_new(agmtlist_objset_destructor);
  470. /* Register callbacks so we're informed about updates */
  471. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, AGMT_CONFIG_BASE,
  472. LDAP_SCOPE_SUBTREE, CONFIG_FILTER, agmtlist_add_callback, NULL);
  473. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, AGMT_CONFIG_BASE,
  474. LDAP_SCOPE_SUBTREE, CONFIG_FILTER, agmtlist_modify_callback, NULL);
  475. slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, AGMT_CONFIG_BASE,
  476. LDAP_SCOPE_SUBTREE, CONFIG_FILTER, agmtlist_delete_callback, NULL);
  477. slapi_config_register_callback(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP, AGMT_CONFIG_BASE,
  478. LDAP_SCOPE_SUBTREE, CONFIG_FILTER, agmtlist_rename_callback, NULL);
  479. /* Search the DIT and find all the replication agreements */
  480. pb = slapi_pblock_new();
  481. slapi_search_internal_set_pb(pb, AGMT_CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  482. GLOBAL_CONFIG_FILTER, NULL /* attrs */, 0 /* attrsonly */,
  483. NULL, /* controls */ NULL /* uniqueid */,
  484. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0 /* actions */);
  485. slapi_search_internal_callback_pb(pb,
  486. (void *)&agmtcount /* callback data */,
  487. NULL /* result_callback */,
  488. handle_agmt_search /* search entry cb */,
  489. NULL /* referral callback */);
  490. slapi_pblock_destroy(pb);
  491. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_config_init: found %d replication agreements in DIT\n", agmtcount);
  492. return 0;
  493. }
  494. void
  495. agmtlist_shutdown()
  496. {
  497. Repl_Agmt *ra;
  498. Object *ro;
  499. Object *next_ro;
  500. ro = objset_first_obj(agmt_set);
  501. while (NULL != ro)
  502. {
  503. next_ro = objset_next_obj(agmt_set, ro);
  504. ra = (Repl_Agmt *)object_get_data(ro);
  505. agmt_stop(ra);
  506. agmt_update_consumer_ruv (ra);
  507. objset_remove_obj(agmt_set, ro);
  508. ro = next_ro;
  509. }
  510. objset_delete(&agmt_set);
  511. agmt_set = NULL;
  512. }
  513. /*
  514. * Notify each replication agreement about an update.
  515. */
  516. void
  517. agmtlist_notify_all(Slapi_PBlock *pb)
  518. {
  519. Repl_Agmt *ra;
  520. Object *ro;
  521. if (NULL != agmt_set)
  522. {
  523. ro = objset_first_obj(agmt_set);
  524. while (NULL != ro)
  525. {
  526. ra = (Repl_Agmt *)object_get_data(ro);
  527. agmt_notify_change(ra, pb);
  528. ro = objset_next_obj(agmt_set, ro);
  529. }
  530. }
  531. }
  532. Object* agmtlist_get_first_agreement_for_replica (Replica *r)
  533. {
  534. return agmtlist_get_next_agreement_for_replica (r, NULL) ;
  535. }
  536. Object* agmtlist_get_next_agreement_for_replica (Replica *r, Object *prev)
  537. {
  538. const Slapi_DN *replica_root;
  539. Slapi_DN *agmt_root;
  540. Object *obj;
  541. Repl_Agmt *agmt;
  542. if (r == NULL)
  543. {
  544. /* ONREPL - log error */
  545. return NULL;
  546. }
  547. replica_root = replica_get_root(r);
  548. if (prev)
  549. obj = objset_next_obj(agmt_set, prev);
  550. else
  551. obj = objset_first_obj(agmt_set);
  552. while (obj)
  553. {
  554. agmt = (Repl_Agmt*)object_get_data (obj);
  555. PR_ASSERT (agmt);
  556. agmt_root = agmt_get_replarea(agmt);
  557. PR_ASSERT (agmt_root);
  558. if (slapi_sdn_compare (replica_root, agmt_root) == 0)
  559. {
  560. slapi_sdn_free (&agmt_root);
  561. return obj;
  562. }
  563. slapi_sdn_free (&agmt_root);
  564. obj = objset_next_obj(agmt_set, obj);
  565. }
  566. return NULL;
  567. }