repl5_agmtlist.c 22 KB

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