repl5_agmtlist.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  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. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /* repl5_agmtlist.c */
  13. /*
  14. Replication agreements are held in object set (objset.c).
  15. */
  16. #include "repl5.h"
  17. #include <plstr.h>
  18. /* normalized DN */
  19. #define AGMT_CONFIG_BASE "cn=mapping tree,cn=config"
  20. #define CONFIG_FILTER "(objectclass=nsds5replicationagreement)"
  21. #define WINDOWS_CONFIG_FILTER "(objectclass=nsdsWindowsreplicationagreement)"
  22. #define GLOBAL_CONFIG_FILTER "(|" CONFIG_FILTER WINDOWS_CONFIG_FILTER " )"
  23. PRCallOnceType once = {0};
  24. Objset *agmt_set = NULL; /* The set of replication agreements */
  25. typedef struct agmt_wrapper {
  26. Repl_Agmt *agmt;
  27. void *handle;
  28. } agmt_wrapper;
  29. /*
  30. * Find the replication agreement whose entry DN matches the given DN.
  31. * Object is returned referenced, so be sure to release it when
  32. * finished.
  33. */
  34. Repl_Agmt *
  35. agmtlist_get_by_agmt_name(const Slapi_DN *agmt_name)
  36. {
  37. Repl_Agmt *ra = NULL;
  38. Object *ro;
  39. for (ro = objset_first_obj(agmt_set); NULL != ro;
  40. ro = objset_next_obj(agmt_set, ro))
  41. {
  42. ra = (Repl_Agmt *)object_get_data(ro);
  43. if (agmt_matches_name(ra, agmt_name))
  44. {
  45. break;
  46. }
  47. }
  48. return ra;
  49. }
  50. static int
  51. agmt_ptr_cmp(Object *ro, const void *arg)
  52. {
  53. Repl_Agmt *ra;
  54. Repl_Agmt *provided_ra = (Repl_Agmt *)arg;
  55. ra = object_get_data(ro);
  56. if (ra == provided_ra)
  57. return 0;
  58. else
  59. return 1;
  60. }
  61. static int
  62. agmt_dn_cmp(Object *ro, const void *arg)
  63. {
  64. Repl_Agmt *ra;
  65. Slapi_DN *sdn = (Slapi_DN *)arg;
  66. ra = object_get_data(ro);
  67. return(slapi_sdn_compare(sdn, agmt_get_dn_byref(ra)));
  68. }
  69. void
  70. agmtlist_release_agmt(Repl_Agmt *ra)
  71. {
  72. Object *ro;
  73. PR_ASSERT(NULL != agmt_set);
  74. PR_ASSERT(NULL != ra);
  75. ro = objset_find(agmt_set, agmt_ptr_cmp, (const void *)ra);
  76. if (NULL != ro)
  77. {
  78. /*
  79. * Release twice - once for the reference we got when finding
  80. * it, and once for the reference we got when we called
  81. * agmtlist_get_*().
  82. */
  83. object_release(ro);
  84. object_release(ro);
  85. }
  86. }
  87. /*
  88. * Note: when we add the new object, we have a reference to it. We hold
  89. * on to this reference until the agreement is deleted (or until the
  90. * server is shut down).
  91. */
  92. int
  93. add_new_agreement(Slapi_Entry *e)
  94. {
  95. int rc = 0;
  96. Repl_Agmt *ra = agmt_new_from_entry(e);
  97. Slapi_DN *replarea_sdn = NULL;
  98. Replica *replica = NULL;
  99. Object *repl_obj = NULL;
  100. Object *ro = NULL;
  101. /* tell search result handler callback this entry was not sent */
  102. if (ra == NULL)
  103. return 1;
  104. ro = object_new((void *)ra, agmt_delete);
  105. objset_add_obj(agmt_set, ro);
  106. object_release(ro); /* Object now owned by objset */
  107. /* get the replica for this agreement */
  108. replarea_sdn = agmt_get_replarea(ra);
  109. repl_obj = replica_get_replica_from_dn(replarea_sdn);
  110. slapi_sdn_free(&replarea_sdn);
  111. if (repl_obj) {
  112. replica = (Replica*)object_get_data (repl_obj);
  113. }
  114. rc = replica_start_agreement(replica, ra);
  115. if (repl_obj) object_release(repl_obj);
  116. return rc;
  117. }
  118. int
  119. id_extended_agreement(Repl_Agmt *agmt, LDAPMod** mods, Slapi_Entry *e)
  120. {
  121. Slapi_Attr *sattr = NULL;
  122. char *val = NULL;
  123. int return_value = 0;
  124. int i;
  125. slapi_entry_attr_find(e, "objectclass", &sattr);
  126. if (sattr) {
  127. Slapi_Value *sval = NULL;
  128. const char *val = NULL;
  129. for (i = slapi_attr_first_value(sattr, &sval);
  130. i >= 0; i = slapi_attr_next_value(sattr, i, &sval)) {
  131. val = slapi_value_get_string(sval);
  132. if ((0 == strcasecmp(val,"top")) ||
  133. (0 == strcasecmp(val,"nsds5replicationAgreement"))) {
  134. continue;
  135. } else {
  136. /* the entry has an additional objectclass, accept mods */
  137. return 1;
  138. }
  139. }
  140. }
  141. /* This modification could remove an additional objectclass.
  142. * In the entry we check this mod has already been applied,
  143. * so check list of mods
  144. */
  145. for (i = 0; NULL != mods && NULL != mods[i]; i++) {
  146. if (strcasecmp(mods[i]->mod_type, "objectclass")) continue;
  147. if (mods[i]->mod_bvalues){
  148. int j;
  149. for (j = 0; mods[i]->mod_bvalues[j]; j++){
  150. slapi_ch_free_string(&val);
  151. val = slapi_berval_get_string_copy (mods[i]->mod_bvalues[j]);
  152. if ((0 == strcasecmp(val,"top")) ||
  153. (0 == strcasecmp(val,"nsds5replicationAgreement"))) {
  154. continue;
  155. } else {
  156. /* an additional objectclass was modified */
  157. return_value = 1;
  158. break;
  159. }
  160. }
  161. }
  162. break;
  163. }
  164. slapi_ch_free_string(&val);
  165. return return_value;
  166. }
  167. static int
  168. agmtlist_add_callback(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *entryAfter,
  169. int *returncode, char *returntext, void *arg)
  170. {
  171. int rc;
  172. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmt_add: begin\n");
  173. rc = add_new_agreement(e);
  174. if (0 != rc) {
  175. Slapi_DN *sdn = NULL;
  176. slapi_pblock_get(pb, SLAPI_TARGET_SDN, &sdn);
  177. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmtlist_add_callback: "
  178. "Can't start agreement \"%s\"\n", slapi_sdn_get_dn(sdn));
  179. *returncode = LDAP_UNWILLING_TO_PERFORM;
  180. return SLAPI_DSE_CALLBACK_ERROR;
  181. }
  182. *returncode = LDAP_SUCCESS;
  183. return SLAPI_DSE_CALLBACK_OK;
  184. }
  185. static int
  186. agmtlist_modify_callback(Slapi_PBlock *pb, Slapi_Entry *entryBefore, Slapi_Entry *e,
  187. int *returncode, char *returntext, void *arg)
  188. {
  189. int i;
  190. Slapi_DN *sdn = NULL;
  191. int start_initialize = 0, stop_initialize = 0, cancel_initialize = 0;
  192. int update_the_schedule = 0; /* do we need to update the repl sched? */
  193. Repl_Agmt *agmt = NULL;
  194. LDAPMod **mods;
  195. char buff [SLAPI_DSE_RETURNTEXT_SIZE];
  196. char *errortext = returntext ? returntext : buff;
  197. char *val = NULL;
  198. int rc = SLAPI_DSE_CALLBACK_OK;
  199. Slapi_Operation *op;
  200. void *identity;
  201. *returncode = LDAP_SUCCESS;
  202. /* just let internal operations originated from replication plugin to go through */
  203. slapi_pblock_get (pb, SLAPI_OPERATION, &op);
  204. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  205. if (operation_is_flag_set(op, OP_FLAG_INTERNAL) &&
  206. (identity == repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION)))
  207. {
  208. goto done;
  209. }
  210. slapi_pblock_get(pb, SLAPI_TARGET_SDN, &sdn);
  211. if (NULL == sdn) {
  212. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  213. "agmtlist_modify_callback: NULL target dn\n");
  214. goto done;
  215. }
  216. agmt = agmtlist_get_by_agmt_name(sdn);
  217. if (NULL == agmt)
  218. {
  219. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmtlist_modify_callback: received "
  220. "a modification for unknown replication agreement \"%s\"\n",
  221. slapi_sdn_get_dn(sdn));
  222. goto done;
  223. }
  224. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  225. for (i = 0; NULL != mods && NULL != mods[i]; i++)
  226. {
  227. slapi_ch_free_string(&val);
  228. if (mods[i]->mod_bvalues && mods[i]->mod_bvalues[0]){
  229. val = slapi_berval_get_string_copy (mods[i]->mod_bvalues[0]);
  230. }
  231. if (slapi_attr_types_equivalent(mods[i]->mod_type, type_nsds5ReplicaInitialize))
  232. {
  233. /* we don't allow delete attribute operations unless it was issued by
  234. the replication plugin - handled above */
  235. if (mods[i]->mod_op & LDAP_MOD_DELETE)
  236. {
  237. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  238. "deletion of %s attribute is not allowed\n", type_nsds5ReplicaInitialize);
  239. *returncode = LDAP_UNWILLING_TO_PERFORM;
  240. rc = SLAPI_DSE_CALLBACK_ERROR;
  241. break;
  242. }
  243. else
  244. {
  245. if(val == NULL){
  246. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  247. "no value provided for %s attribute\n", type_nsds5ReplicaInitialize);
  248. *returncode = LDAP_UNWILLING_TO_PERFORM;
  249. rc = SLAPI_DSE_CALLBACK_ERROR;
  250. break;
  251. }
  252. /* Start replica initialization */
  253. if (strcasecmp (val, "start") == 0)
  254. {
  255. start_initialize = 1;
  256. }
  257. else if (strcasecmp (val, "stop") == 0)
  258. {
  259. stop_initialize = 1;
  260. }
  261. else if (strcasecmp (val, "cancel") == 0)
  262. {
  263. cancel_initialize = 1;
  264. }
  265. else
  266. {
  267. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE,
  268. "Invalid value (%s) value supplied for attr (%s); Ignoring ...",
  269. val, mods[i]->mod_type);
  270. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: %s\n", errortext);
  271. *returncode = LDAP_UNWILLING_TO_PERFORM;
  272. rc = SLAPI_DSE_CALLBACK_ERROR;
  273. }
  274. }
  275. }
  276. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  277. type_nsds5ReplicaUpdateSchedule))
  278. {
  279. /*
  280. * Request to update the replication schedule. Set a flag so
  281. * we know to update the schedule later.
  282. */
  283. update_the_schedule = 1;
  284. }
  285. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  286. type_nsds5ReplicaCredentials))
  287. {
  288. /* New replica credentials */
  289. if (agmt_set_credentials_from_entry(agmt, e) != 0)
  290. {
  291. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  292. "failed to update credentials for agreement %s\n",
  293. agmt_get_long_name(agmt));
  294. *returncode = LDAP_OPERATIONS_ERROR;
  295. rc = SLAPI_DSE_CALLBACK_ERROR;
  296. }
  297. }
  298. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  299. type_nsds5ReplicaTimeout))
  300. {
  301. /* New replica timeout */
  302. if (agmt_set_timeout_from_entry(agmt, e) != 0)
  303. {
  304. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  305. "failed to update timeout for agreement %s\n",
  306. agmt_get_long_name(agmt));
  307. *returncode = LDAP_OPERATIONS_ERROR;
  308. rc = SLAPI_DSE_CALLBACK_ERROR;
  309. }
  310. }
  311. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  312. type_nsds5ReplicaFlowControlWindow))
  313. {
  314. /* New replica timeout */
  315. if (agmt_set_flowcontrolwindow_from_entry(agmt, e) != 0)
  316. {
  317. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  318. "failed to update the flow control window for agreement %s\n",
  319. agmt_get_long_name(agmt));
  320. *returncode = LDAP_OPERATIONS_ERROR;
  321. rc = SLAPI_DSE_CALLBACK_ERROR;
  322. }
  323. }
  324. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  325. type_nsds5ReplicaFlowControlPause))
  326. {
  327. /* New replica timeout */
  328. if (agmt_set_flowcontrolpause_from_entry(agmt, e) != 0)
  329. {
  330. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  331. "failed to update the flow control pause for agreement %s\n",
  332. agmt_get_long_name(agmt));
  333. *returncode = LDAP_OPERATIONS_ERROR;
  334. rc = SLAPI_DSE_CALLBACK_ERROR;
  335. }
  336. }
  337. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  338. type_nsds5ReplicaBusyWaitTime))
  339. {
  340. /* New replica busywaittime */
  341. if (agmt_set_busywaittime_from_entry(agmt, e) != 0)
  342. {
  343. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  344. "failed to update busy wait time for agreement %s\n",
  345. agmt_get_long_name(agmt));
  346. *returncode = LDAP_OPERATIONS_ERROR;
  347. rc = SLAPI_DSE_CALLBACK_ERROR;
  348. }
  349. }
  350. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  351. type_nsds5ReplicaSessionPauseTime))
  352. {
  353. /* New replica pausetime */
  354. if (agmt_set_pausetime_from_entry(agmt, e) != 0)
  355. {
  356. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  357. "failed to update session pause time for agreement %s\n",
  358. agmt_get_long_name(agmt));
  359. *returncode = LDAP_OPERATIONS_ERROR;
  360. rc = SLAPI_DSE_CALLBACK_ERROR;
  361. }
  362. }
  363. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  364. type_nsds5ReplicaBindDN))
  365. {
  366. /* New replica Bind DN */
  367. if (agmt_set_binddn_from_entry(agmt, e) != 0)
  368. {
  369. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  370. "failed to update bind DN for agreement %s\n",
  371. agmt_get_long_name(agmt));
  372. *returncode = LDAP_OPERATIONS_ERROR;
  373. rc = SLAPI_DSE_CALLBACK_ERROR;
  374. }
  375. }
  376. else if (slapi_attr_types_equivalent(mods[i]->mod_type, type_nsds5ReplicaHost))
  377. {
  378. /* New replica host */
  379. if (agmt_set_host_from_entry(agmt, e) != 0)
  380. {
  381. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
  382. "agmtlist_modify_callback: "
  383. "failed to update host for agreement %s\n",
  384. agmt_get_long_name(agmt));
  385. *returncode = LDAP_OPERATIONS_ERROR;
  386. rc = SLAPI_DSE_CALLBACK_ERROR;
  387. } else {
  388. /*
  389. * Changing the host invalidates the agmt maxcsn, so remove it.
  390. * The next update will add the correct maxcsn back to the agmt/local ruv.
  391. */
  392. agmt_remove_maxcsn(agmt);
  393. }
  394. }
  395. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  396. type_nsds5ReplicaPort))
  397. {
  398. /* New replica port */
  399. if (agmt_set_port_from_entry(agmt, e) != 0)
  400. {
  401. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
  402. "agmtlist_modify_callback: "
  403. "failed to update port for agreement %s\n",
  404. agmt_get_long_name(agmt));
  405. *returncode = LDAP_OPERATIONS_ERROR;
  406. rc = SLAPI_DSE_CALLBACK_ERROR;
  407. } else {
  408. /*
  409. * Changing the port invalidates the agmt maxcsn, so remove it.
  410. * The next update will add the correct maxcsn back to the agmt/local ruv.
  411. */
  412. agmt_remove_maxcsn(agmt);
  413. }
  414. }
  415. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  416. type_nsds5TransportInfo))
  417. {
  418. /* New Transport info */
  419. if (agmt_set_transportinfo_from_entry(agmt, e) != 0)
  420. {
  421. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  422. "failed to update transport info for agreement %s\n",
  423. agmt_get_long_name(agmt));
  424. *returncode = LDAP_OPERATIONS_ERROR;
  425. rc = SLAPI_DSE_CALLBACK_ERROR;
  426. }
  427. }
  428. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  429. type_nsds5ReplicaBindMethod))
  430. {
  431. if (agmt_set_bind_method_from_entry(agmt, e) != 0)
  432. {
  433. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  434. "failed to update bind method for agreement %s\n",
  435. agmt_get_long_name(agmt));
  436. *returncode = LDAP_OPERATIONS_ERROR;
  437. rc = SLAPI_DSE_CALLBACK_ERROR;
  438. }
  439. }
  440. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  441. type_nsds5ReplicatedAttributeList))
  442. {
  443. char **denied_attrs = NULL;
  444. /* New set of excluded attributes */
  445. if (agmt_set_replicated_attributes_from_entry(agmt, e) != 0)
  446. {
  447. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  448. "failed to update replicated attributes for agreement %s\n",
  449. agmt_get_long_name(agmt));
  450. *returncode = LDAP_OPERATIONS_ERROR;
  451. rc = SLAPI_DSE_CALLBACK_ERROR;
  452. }
  453. /* Check that there are no verboten attributes in the exclude list */
  454. denied_attrs = agmt_validate_replicated_attributes(agmt, 0 /* incremental */);
  455. if (denied_attrs)
  456. {
  457. /* Report the error to the client */
  458. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "attempt to exclude an illegal attribute in a fractional agreement");
  459. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  460. "attempt to exclude an illegal attribute in a fractional agreement\n");
  461. *returncode = LDAP_UNWILLING_TO_PERFORM;
  462. rc = SLAPI_DSE_CALLBACK_ERROR;
  463. /* Free the deny list if we got one */
  464. slapi_ch_array_free(denied_attrs);
  465. break;
  466. }
  467. }
  468. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  469. type_nsds5ReplicatedAttributeListTotal))
  470. {
  471. char **denied_attrs = NULL;
  472. /* New set of excluded attributes */
  473. if (agmt_set_replicated_attributes_total_from_entry(agmt, e) != 0)
  474. {
  475. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  476. "failed to update total update replicated attributes for agreement %s\n",
  477. agmt_get_long_name(agmt));
  478. *returncode = LDAP_OPERATIONS_ERROR;
  479. rc = SLAPI_DSE_CALLBACK_ERROR;
  480. }
  481. /* Check that there are no verboten attributes in the exclude list */
  482. denied_attrs = agmt_validate_replicated_attributes(agmt, 1 /* total */);
  483. if (denied_attrs)
  484. {
  485. /* Report the error to the client */
  486. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "attempt to exclude an illegal total update "
  487. "attribute in a fractional agreement");
  488. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  489. "attempt to exclude an illegal total update attribute in a fractional agreement\n");
  490. *returncode = LDAP_UNWILLING_TO_PERFORM;
  491. rc = SLAPI_DSE_CALLBACK_ERROR;
  492. /* Free the deny list if we got one */
  493. slapi_ch_array_free(denied_attrs);
  494. break;
  495. }
  496. }
  497. else if (slapi_attr_types_equivalent(mods[i]->mod_type,
  498. "nsds5debugreplicatimeout"))
  499. {
  500. char *val = slapi_entry_attr_get_charptr(e, "nsds5debugreplicatimeout");
  501. repl5_set_debug_timeout(val);
  502. slapi_ch_free_string(&val);
  503. }
  504. else if (slapi_attr_is_last_mod(mods[i]->mod_type) ||
  505. strcasecmp (mods[i]->mod_type, "description") == 0)
  506. {
  507. /* ignore modifier's name and timestamp attributes and the description. */
  508. continue;
  509. }
  510. else if (slapi_attr_types_equivalent(mods[i]->mod_type, type_nsds5ReplicaEnabled))
  511. {
  512. if(agmt_set_enabled_from_entry(agmt, e, returntext) != 0){
  513. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  514. "failed to set replica agmt state \"enabled/disabled\" for %s\n",agmt_get_long_name(agmt));
  515. *returncode = LDAP_OPERATIONS_ERROR;
  516. rc = SLAPI_DSE_CALLBACK_ERROR;
  517. }
  518. }
  519. else if (slapi_attr_types_equivalent(mods[i]->mod_type, type_nsds5ReplicaStripAttrs))
  520. {
  521. if(agmt_set_attrs_to_strip(agmt, e) != 0){
  522. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  523. "failed to set replica agmt attributes to strip for %s\n",agmt_get_long_name(agmt));
  524. *returncode = LDAP_OPERATIONS_ERROR;
  525. rc = SLAPI_DSE_CALLBACK_ERROR;
  526. }
  527. }
  528. else if (slapi_attr_types_equivalent(mods[i]->mod_type, type_replicaProtocolTimeout))
  529. {
  530. if (mods[i]->mod_op & LDAP_MOD_DELETE)
  531. {
  532. agmt_set_protocol_timeout(agmt, 0);
  533. }
  534. else
  535. {
  536. long ptimeout = 0;
  537. if (val){
  538. ptimeout = atol(val);
  539. }
  540. if(ptimeout <= 0){
  541. *returncode = LDAP_UNWILLING_TO_PERFORM;
  542. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  543. "attribute %s value (%s) is invalid, must be a number greater than zero.\n",
  544. type_replicaProtocolTimeout, val ? val : "");
  545. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "attribute %s value (%s) is invalid, "
  546. "must be a number greater than zero.\n",
  547. type_replicaProtocolTimeout, val ? val : "");
  548. rc = SLAPI_DSE_CALLBACK_ERROR;
  549. break;
  550. }
  551. agmt_set_protocol_timeout(agmt, ptimeout);
  552. }
  553. }
  554. else if (slapi_attr_types_equivalent(mods[i]->mod_type, type_nsds5WaitForAsyncResults))
  555. {
  556. if (mods[i]->mod_op & LDAP_MOD_DELETE) {
  557. (void) agmt_set_WaitForAsyncResults(agmt, NULL);
  558. } else {
  559. (void) agmt_set_WaitForAsyncResults(agmt, e);
  560. }
  561. }
  562. else if ((0 == windows_handle_modify_agreement(agmt, mods[i]->mod_type, e)) &&
  563. (0 == id_extended_agreement(agmt, mods, e)))
  564. {
  565. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  566. "modification of %s attribute is not allowed\n", mods[i]->mod_type);
  567. *returncode = LDAP_UNWILLING_TO_PERFORM;
  568. rc = SLAPI_DSE_CALLBACK_ERROR;
  569. break;
  570. }
  571. }
  572. if (stop_initialize)
  573. {
  574. agmt_stop (agmt);
  575. }
  576. else if (start_initialize)
  577. {
  578. if (agmt_initialize_replica(agmt) != 0) {
  579. /* The suffix/repl agmt is disabled */
  580. agmt_set_last_init_status(agmt, 0, NSDS50_REPL_DISABLED, 0, NULL);
  581. if(agmt_is_enabled(agmt)){
  582. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Suffix is disabled");
  583. } else {
  584. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Replication agreement is disabled");
  585. }
  586. *returncode = LDAP_UNWILLING_TO_PERFORM;
  587. rc = SLAPI_DSE_CALLBACK_ERROR;
  588. }
  589. }
  590. else if (cancel_initialize)
  591. {
  592. agmt_replica_init_done(agmt);
  593. }
  594. if (update_the_schedule)
  595. {
  596. if (agmt_set_schedule_from_entry(agmt, e) != 0)
  597. {
  598. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_modify_callback: "
  599. "failed to update replication schedule for agreement %s\n",
  600. agmt_get_long_name(agmt));
  601. *returncode = LDAP_OPERATIONS_ERROR;
  602. rc = SLAPI_DSE_CALLBACK_ERROR;
  603. }
  604. }
  605. done:
  606. if (NULL != agmt)
  607. {
  608. agmtlist_release_agmt(agmt);
  609. }
  610. slapi_ch_free_string(&val);
  611. return rc;
  612. }
  613. static int
  614. agmtlist_delete_callback(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *entryAfter,
  615. int *returncode, char *returntext, void *arg)
  616. {
  617. Repl_Agmt *ra;
  618. Object *ro;
  619. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmt_delete: begin\n");
  620. ro = objset_find(agmt_set, agmt_dn_cmp, (const void *)slapi_entry_get_sdn_const(e));
  621. ra = (NULL == ro) ? NULL : (Repl_Agmt *)object_get_data(ro);
  622. if (NULL == ra)
  623. {
  624. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmtlist_delete: "
  625. "Tried to delete replication agreement \"%s\", but no such "
  626. "agreement was configured.\n", slapi_sdn_get_dn(slapi_entry_get_sdn_const(e)));
  627. }
  628. else
  629. {
  630. agmt_remove_maxcsn(ra); /* remove the agmt maxcsn from the localruv */
  631. agmt_stop(ra);
  632. object_release(ro); /* Release ref acquired in objset_find */
  633. objset_remove_obj(agmt_set, ro); /* Releases a reference (should be final reference */
  634. }
  635. *returncode = LDAP_SUCCESS;
  636. return SLAPI_DSE_CALLBACK_OK;
  637. }
  638. static int
  639. agmtlist_rename_callback(Slapi_PBlock *pb, Slapi_Entry *entryBefore, Slapi_Entry *e,
  640. int *returncode, char *returntext, void *arg)
  641. {
  642. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmt_rename: begin\n");
  643. *returncode = LDAP_SUCCESS;
  644. return SLAPI_DSE_CALLBACK_OK;
  645. }
  646. static int
  647. handle_agmt_search(Slapi_Entry *e, void *callback_data)
  648. {
  649. int *agmtcount = (int *)callback_data;
  650. int rc;
  651. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
  652. "Found replication agreement named \"%s\".\n",
  653. slapi_sdn_get_dn(slapi_entry_get_sdn(e)));
  654. rc = add_new_agreement(e);
  655. if (0 == rc)
  656. {
  657. (*agmtcount)++;
  658. }
  659. else
  660. {
  661. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "The replication "
  662. "agreement named \"%s\" could not be correctly parsed. No "
  663. "replication will occur with this replica.\n",
  664. slapi_sdn_get_dn(slapi_entry_get_sdn(e)));
  665. }
  666. return rc;
  667. }
  668. static void
  669. agmtlist_objset_destructor(void **o)
  670. {
  671. /* XXXggood Nothing to do, I think. */
  672. }
  673. int
  674. agmtlist_config_init()
  675. {
  676. Slapi_PBlock *pb;
  677. int agmtcount = 0;
  678. agmt_set = objset_new(agmtlist_objset_destructor);
  679. /* Register callbacks so we're informed about updates */
  680. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, AGMT_CONFIG_BASE,
  681. LDAP_SCOPE_SUBTREE, GLOBAL_CONFIG_FILTER, agmtlist_add_callback, NULL);
  682. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, AGMT_CONFIG_BASE,
  683. LDAP_SCOPE_SUBTREE, GLOBAL_CONFIG_FILTER, agmtlist_modify_callback, NULL);
  684. slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, AGMT_CONFIG_BASE,
  685. LDAP_SCOPE_SUBTREE, GLOBAL_CONFIG_FILTER, agmtlist_delete_callback, NULL);
  686. slapi_config_register_callback(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP, AGMT_CONFIG_BASE,
  687. LDAP_SCOPE_SUBTREE, GLOBAL_CONFIG_FILTER, agmtlist_rename_callback, NULL);
  688. /* Search the DIT and find all the replication agreements */
  689. pb = slapi_pblock_new();
  690. slapi_search_internal_set_pb(pb, AGMT_CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  691. GLOBAL_CONFIG_FILTER, NULL /* attrs */, 0 /* attrsonly */,
  692. NULL, /* controls */ NULL /* uniqueid */,
  693. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0 /* actions */);
  694. slapi_search_internal_callback_pb(pb,
  695. (void *)&agmtcount /* callback data */,
  696. NULL /* result_callback */,
  697. handle_agmt_search /* search entry cb */,
  698. NULL /* referral callback */);
  699. slapi_pblock_destroy(pb);
  700. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "agmtlist_config_init: found %d replication agreements in DIT\n", agmtcount);
  701. return 0;
  702. }
  703. void
  704. agmtlist_shutdown()
  705. {
  706. Repl_Agmt *ra;
  707. Object *ro;
  708. Object *next_ro;
  709. ro = objset_first_obj(agmt_set);
  710. while (NULL != ro)
  711. {
  712. ra = (Repl_Agmt *)object_get_data(ro);
  713. agmt_stop(ra);
  714. agmt_update_consumer_ruv (ra);
  715. next_ro = objset_next_obj(agmt_set, ro);
  716. /* Object ro was released in objset_next_obj,
  717. * but the address ro can be still used to remove ro from objset. */
  718. objset_remove_obj(agmt_set, ro);
  719. ro = next_ro;
  720. }
  721. objset_delete(&agmt_set);
  722. agmt_set = NULL;
  723. }
  724. /*
  725. * Notify each replication agreement about an update.
  726. */
  727. void
  728. agmtlist_notify_all(Slapi_PBlock *pb)
  729. {
  730. Repl_Agmt *ra;
  731. Object *ro;
  732. if (NULL != agmt_set)
  733. {
  734. ro = objset_first_obj(agmt_set);
  735. while (NULL != ro)
  736. {
  737. ra = (Repl_Agmt *)object_get_data(ro);
  738. agmt_notify_change(ra, pb);
  739. ro = objset_next_obj(agmt_set, ro);
  740. }
  741. }
  742. }
  743. Object* agmtlist_get_first_agreement_for_replica (Replica *r)
  744. {
  745. return agmtlist_get_next_agreement_for_replica (r, NULL) ;
  746. }
  747. Object* agmtlist_get_next_agreement_for_replica (Replica *r, Object *prev)
  748. {
  749. const Slapi_DN *replica_root;
  750. Slapi_DN *agmt_root;
  751. Object *obj;
  752. Repl_Agmt *agmt;
  753. if (r == NULL)
  754. {
  755. /* ONREPL - log error */
  756. return NULL;
  757. }
  758. replica_root = replica_get_root(r);
  759. if (prev)
  760. obj = objset_next_obj(agmt_set, prev);
  761. else
  762. obj = objset_first_obj(agmt_set);
  763. while (obj)
  764. {
  765. agmt = (Repl_Agmt*)object_get_data (obj);
  766. PR_ASSERT (agmt);
  767. agmt_root = agmt_get_replarea(agmt);
  768. PR_ASSERT (agmt_root);
  769. if (slapi_sdn_compare (replica_root, agmt_root) == 0)
  770. {
  771. slapi_sdn_free (&agmt_root);
  772. return obj;
  773. }
  774. slapi_sdn_free (&agmt_root);
  775. obj = objset_next_obj(agmt_set, obj);
  776. }
  777. return NULL;
  778. }