repl5_agmtlist.c 28 KB

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