repl5_agmtlist.c 18 KB

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