repl5.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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) 2010 Red Hat, Inc.
  36. * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
  37. * All rights reserved.
  38. * END COPYRIGHT BLOCK **/
  39. #ifdef HAVE_CONFIG_H
  40. # include <config.h>
  41. #endif
  42. /* repl5.h - 5.0 replication header */
  43. #ifndef _REPL5_H_
  44. #define _REPL5_H_
  45. #include <limits.h>
  46. #include <time.h>
  47. #include <stdio.h>
  48. #include <string.h>
  49. #ifndef _WIN32
  50. #include <sys/param.h>
  51. #endif /* _WIN32 */
  52. #include "portable.h" /* GGOODREPL - is this cheating? */
  53. #include "repl_shared.h"
  54. #include "llist.h"
  55. #include "repl5_ruv.h"
  56. #include "cl4.h"
  57. #define REPLICA_TYPE_WINDOWS 1
  58. #define REPLICA_TYPE_MULTIMASTER 0
  59. #define REPL_DIRSYNC_CONTROL_OID "1.2.840.113556.1.4.841"
  60. #define REPL_RETURN_DELETED_OBJS_CONTROL_OID "1.2.840.113556.1.4.417"
  61. #define REPL_WIN2K3_AD_OID "1.2.840.113556.1.4.1670"
  62. /* DS 5.0 replication protocol OIDs */
  63. #define REPL_START_NSDS50_REPLICATION_REQUEST_OID "2.16.840.1.113730.3.5.3"
  64. #define REPL_END_NSDS50_REPLICATION_REQUEST_OID "2.16.840.1.113730.3.5.5"
  65. #define REPL_NSDS50_REPLICATION_ENTRY_REQUEST_OID "2.16.840.1.113730.3.5.6"
  66. #define REPL_NSDS50_REPLICATION_RESPONSE_OID "2.16.840.1.113730.3.5.4"
  67. #define REPL_NSDS50_UPDATE_INFO_CONTROL_OID "2.16.840.1.113730.3.4.13"
  68. #define REPL_NSDS50_INCREMENTAL_PROTOCOL_OID "2.16.840.1.113730.3.6.1"
  69. #define REPL_NSDS50_TOTAL_PROTOCOL_OID "2.16.840.1.113730.3.6.2"
  70. /* DS7.1 introduces pipelineing in the protocol : really not much different to the 5.0
  71. * protocol, but enough change to make it unsafe to interoperate the two. So we define
  72. * new OIDs for 7.1 here. The supplier server looks for these on the consumer and
  73. * if they're not there it falls back to the older 5.0 non-pipelined protocol */
  74. #define REPL_NSDS71_INCREMENTAL_PROTOCOL_OID "2.16.840.1.113730.3.6.4"
  75. #define REPL_NSDS71_TOTAL_PROTOCOL_OID "2.16.840.1.113730.3.6.3"
  76. /* The new protocol OIDs above do not help us with determining if a consumer
  77. * Supports them or not. That's because they're burried inside the start replication
  78. * extended operation, and are not visible in the support controls and operations list
  79. * So, we add a new extended operation for the 7.1 total protocol. This is partly because
  80. * the total protocol is slightly different (no LDAP_BUSY allowed in 7.1) and partly
  81. * because we need a handy way to spot the difference between a pre-7.1 and post-7.0
  82. * consumer at the supplier */
  83. #define REPL_NSDS71_REPLICATION_ENTRY_REQUEST_OID "2.16.840.1.113730.3.5.9"
  84. /* DS9.0 introduces replication session callbacks that can send/receive
  85. * arbitrary data when starting a replication session. This requires a
  86. * new set of start and response extops. */
  87. #define REPL_START_NSDS90_REPLICATION_REQUEST_OID "2.16.840.1.113730.3.5.12"
  88. #define REPL_NSDS90_REPLICATION_RESPONSE_OID "2.16.840.1.113730.3.5.13"
  89. /* cleanallruv extended ops */
  90. #define REPL_CLEANRUV_OID "2.16.840.1.113730.3.6.5"
  91. #define REPL_ABORT_CLEANRUV_OID "2.16.840.1.113730.3.6.6"
  92. #define CLEANRUV_NOTIFIED 0
  93. #define CLEANRUV_RELEASED 1
  94. /* DS 5.0 replication protocol error codes */
  95. #define NSDS50_REPL_REPLICA_READY 0x00 /* Replica ready, go ahead */
  96. #define NSDS50_REPL_REPLICA_BUSY 0x01 /* Replica busy, try later */
  97. #define NSDS50_REPL_EXCESSIVE_CLOCK_SKEW 0x02 /* Supplier clock too far ahead */
  98. #define NSDS50_REPL_PERMISSION_DENIED 0x03 /* Bind DN not allowed to send updates */
  99. #define NSDS50_REPL_DECODING_ERROR 0x04 /* Consumer couldn't decode extended operation */
  100. #define NSDS50_REPL_UNKNOWN_UPDATE_PROTOCOL 0x05 /* Consumer doesn't understand suplier's update protocol */
  101. #define NSDS50_REPL_NO_SUCH_REPLICA 0x06 /* Consumer holds no such replica */
  102. #define NSDS50_REPL_BELOW_PURGEPOINT 0x07 /* Supplier provided a CSN below the consumer's purge point */
  103. #define NSDS50_REPL_INTERNAL_ERROR 0x08 /* Something bad happened on consumer */
  104. #define NSDS50_REPL_REPLICA_RELEASE_SUCCEEDED 0x09 /* Replica released successfully */
  105. #define NSDS50_REPL_LEGACY_CONSUMER 0x0A /* replica is a legacy consumer */
  106. #define NSDS50_REPL_REPLICAID_ERROR 0x0B /* replicaID doesn't seem to be unique */
  107. #define NSDS50_REPL_DISABLED 0x0C /* replica suffix is disabled */
  108. #define NSDS50_REPL_UPTODATE 0x0D /* replica is uptodate */
  109. #define NSDS50_REPL_BACKOFF 0x0E /* replica wants master to go into backoff mode */
  110. #define NSDS50_REPL_REPLICA_NO_RESPONSE 0xff /* No response received */
  111. /* Protocol status */
  112. #define PROTOCOL_STATUS_UNKNOWN 701
  113. #define PROTOCOL_STATUS_INCREMENTAL_AWAITING_CHANGES 702
  114. #define PROTOCOL_STATUS_INCREMENTAL_ACQUIRING_REPLICA 703
  115. #define PROTOCOL_STATUS_INCREMENTAL_RELEASING_REPLICA 704
  116. #define PROTOCOL_STATUS_INCREMENTAL_SENDING_UPDATES 705
  117. #define PROTOCOL_STATUS_INCREMENTAL_BACKING_OFF 706
  118. #define PROTOCOL_STATUS_INCREMENTAL_NEEDS_TOTAL_UPDATE 707
  119. #define PROTOCOL_STATUS_INCREMENTAL_FATAL_ERROR 708
  120. #define PROTOCOL_STATUS_TOTAL_ACQUIRING_REPLICA 709
  121. #define PROTOCOL_STATUS_TOTAL_RELEASING_REPLICA 710
  122. #define PROTOCOL_STATUS_TOTAL_SENDING_DATA 711
  123. /* To Allow Consumer Initialisation when adding an agreement - */
  124. #define STATE_PERFORMING_TOTAL_UPDATE 501
  125. #define STATE_PERFORMING_INCREMENTAL_UPDATE 502
  126. #define MAX_NUM_OF_MASTERS 64
  127. #define REPL_SESSION_ID_SIZE 64
  128. #define REPL_GET_DN(addrp) slapi_sdn_get_dn((addrp)->sdn)
  129. #define REPL_GET_DN_LEN(addrp) slapi_sdn_get_ndn_len((addrp)->sdn)
  130. /* Attribute names for replication agreement attributes */
  131. extern const char *type_nsds5ReplicaHost;
  132. extern const char *type_nsds5ReplicaPort;
  133. extern const char *type_nsds5TransportInfo;
  134. extern const char *type_nsds5ReplicaBindDN;
  135. extern const char *type_nsds5ReplicaCredentials;
  136. extern const char *type_nsds5ReplicaBindMethod;
  137. extern const char *type_nsds5ReplicaRoot;
  138. extern const char *type_nsds5ReplicatedAttributeList;
  139. extern const char *type_nsds5ReplicatedAttributeListTotal;
  140. extern const char *type_nsds5ReplicaUpdateSchedule;
  141. extern const char *type_nsds5ReplicaInitialize;
  142. extern const char *type_nsds5ReplicaTimeout;
  143. extern const char *type_nsds5ReplicaBusyWaitTime;
  144. extern const char *type_nsds5ReplicaSessionPauseTime;
  145. extern const char *type_nsds5ReplicaEnabled;
  146. extern const char *type_nsds5ReplicaStripAttrs;
  147. extern const char *type_nsds5ReplicaCleanRUVnotified;
  148. /* Attribute names for windows replication agreements */
  149. extern const char *type_nsds7WindowsReplicaArea;
  150. extern const char *type_nsds7DirectoryReplicaArea;
  151. extern const char *type_nsds7CreateNewUsers;
  152. extern const char *type_nsds7CreateNewGroups;
  153. extern const char *type_nsds7DirsyncCookie;
  154. extern const char *type_nsds7WindowsDomain;
  155. extern const char *type_winSyncInterval;
  156. extern const char *type_oneWaySync;
  157. extern const char *type_winsyncMoveAction;
  158. /* To Allow Consumer Initialisation when adding an agreement - */
  159. extern const char *type_nsds5BeginReplicaRefresh;
  160. /* replica related attributes */
  161. extern const char *attr_replicaId;
  162. extern const char *attr_replicaRoot;
  163. extern const char *attr_replicaType;
  164. extern const char *attr_replicaBindDn;
  165. extern const char *attr_state;
  166. extern const char *attr_flags;
  167. extern const char *attr_replicaName;
  168. extern const char *attr_replicaReferral;
  169. extern const char *type_ruvElement;
  170. extern const char *type_replicaPurgeDelay;
  171. extern const char *type_replicaChangeCount;
  172. extern const char *type_replicaTombstonePurgeInterval;
  173. extern const char *type_replicaLegacyConsumer;
  174. extern const char *type_replicaCleanRUV;
  175. extern const char *type_replicaAbortCleanRUV;
  176. extern const char *type_ruvElementUpdatetime;
  177. /* multimaster plugin points */
  178. int multimaster_preop_bind (Slapi_PBlock *pb);
  179. int multimaster_preop_add (Slapi_PBlock *pb);
  180. int multimaster_preop_delete (Slapi_PBlock *pb);
  181. int multimaster_preop_modify (Slapi_PBlock *pb);
  182. int multimaster_preop_modrdn (Slapi_PBlock *pb);
  183. int multimaster_preop_search (Slapi_PBlock *pb);
  184. int multimaster_preop_compare (Slapi_PBlock *pb);
  185. int multimaster_bepreop_add (Slapi_PBlock *pb);
  186. int multimaster_bepreop_delete (Slapi_PBlock *pb);
  187. int multimaster_bepreop_modify (Slapi_PBlock *pb);
  188. int replica_ruv_smods_for_op (Slapi_PBlock *pb, char **uniqueid,
  189. Slapi_Mods **smods);
  190. int multimaster_bepreop_modrdn (Slapi_PBlock *pb);
  191. int multimaster_bepostop_modrdn (Slapi_PBlock *pb);
  192. int multimaster_bepostop_delete (Slapi_PBlock *pb);
  193. int multimaster_postop_bind (Slapi_PBlock *pb);
  194. int multimaster_postop_add (Slapi_PBlock *pb);
  195. int multimaster_postop_delete (Slapi_PBlock *pb);
  196. int multimaster_postop_modify (Slapi_PBlock *pb);
  197. int multimaster_postop_modrdn (Slapi_PBlock *pb);
  198. int multimaster_betxnpostop_modrdn (Slapi_PBlock *pb);
  199. int multimaster_betxnpostop_delete (Slapi_PBlock *pb);
  200. int multimaster_betxnpostop_add (Slapi_PBlock *pb);
  201. int multimaster_betxnpostop_modify (Slapi_PBlock *pb);
  202. /* In repl5_init.c */
  203. char* get_thread_private_agmtname ();
  204. void set_thread_private_agmtname (const char *agmtname);
  205. void* get_thread_private_cache ();
  206. void set_thread_private_cache (void *buf);
  207. char* get_repl_session_id (Slapi_PBlock *pb, char *id, CSN **opcsn);
  208. /* In repl_extop.c */
  209. int multimaster_extop_StartNSDS50ReplicationRequest(Slapi_PBlock *pb);
  210. int multimaster_extop_EndNSDS50ReplicationRequest(Slapi_PBlock *pb);
  211. int multimaster_extop_cleanruv(Slapi_PBlock *pb);
  212. int multimaster_extop_abort_cleanruv(Slapi_PBlock *pb);
  213. int extop_noop(Slapi_PBlock *pb);
  214. struct berval *NSDS50StartReplicationRequest_new(const char *protocol_oid,
  215. const char *repl_root, char **extra_referrals, CSN *csn);
  216. struct berval *NSDS50EndReplicationRequest_new(char *repl_root);
  217. int decode_repl_ext_response(struct berval *bvdata, int *response_code,
  218. struct berval ***ruv_bervals, char **data_guid, struct berval **data);
  219. struct berval *NSDS90StartReplicationRequest_new(const char *protocol_oid,
  220. const char *repl_root, char **extra_referrals, CSN *csn,
  221. const char *data_guid, const struct berval *data);
  222. /* In repl5_total.c */
  223. int multimaster_extop_NSDS50ReplicationEntry(Slapi_PBlock *pb);
  224. /* In repl_controls.c */
  225. int create_NSDS50ReplUpdateInfoControl(const char *uuid,
  226. const char *superior_uuid, const CSN *csn,
  227. LDAPMod **modify_mods, LDAPControl **ctrlp);
  228. void destroy_NSDS50ReplUpdateInfoControl(LDAPControl **ctrlp);
  229. int decode_NSDS50ReplUpdateInfoControl(LDAPControl **controlsp,
  230. char **uuid, char **newsuperior_uuid, CSN **csn, LDAPMod ***modrdn_mods);
  231. /* In repl5_replsupplier.c */
  232. typedef struct repl_supplier Repl_Supplier;
  233. Repl_Supplier *replsupplier_init(Slapi_Entry *e);
  234. void replsupplier_configure(Repl_Supplier *rs, Slapi_PBlock *pb);
  235. void replsupplier_start(Repl_Supplier *rs);
  236. void replsupplier_stop(Repl_Supplier *rs);
  237. void replsupplier_destroy(Repl_Supplier **rs);
  238. void replsupplier_notify(Repl_Supplier *rs, PRUint32 eventmask);
  239. PRUint32 replsupplier_get_status(Repl_Supplier *rs);
  240. /* In repl5_plugins.c */
  241. int multimaster_set_local_purl();
  242. const char *multimaster_get_local_purl();
  243. PRBool multimaster_started();
  244. /* In repl5_schedule.c */
  245. typedef struct schedule Schedule;
  246. typedef void (*window_state_change_callback)(void *arg, PRBool opened);
  247. Schedule *schedule_new(window_state_change_callback callback_fn, void *callback_arg, const char *session_id);
  248. void schedule_destroy(Schedule *s);
  249. int schedule_set(Schedule *sch, Slapi_Attr *attr);
  250. char **schedule_get(Schedule *sch);
  251. int schedule_in_window_now(Schedule *sch);
  252. PRTime schedule_next(Schedule *sch);
  253. int schedule_notify(Schedule *sch, Slapi_PBlock *pb);
  254. void schedule_set_priority_attributes(Schedule *sch, char **prio_attrs, int override_schedule);
  255. void schedule_set_startup_delay(Schedule *sch, size_t startup_delay);
  256. void schedule_set_maximum_backlog(Schedule *sch, size_t max_backlog);
  257. void schedule_notify_session(Schedule *sch, PRTime session_end_time, unsigned int flags);
  258. #define REPLICATION_SESSION_SUCCESS 0
  259. /* In repl5_bos.c */
  260. typedef struct repl_bos Repl_Bos;
  261. /* In repl5_agmt.c */
  262. typedef struct repl5agmt Repl_Agmt;
  263. #define TRANSPORT_FLAG_SSL 1
  264. #define TRANSPORT_FLAG_TLS 2
  265. #define BINDMETHOD_SIMPLE_AUTH 1
  266. #define BINDMETHOD_SSL_CLIENTAUTH 2
  267. #define BINDMETHOD_SASL_GSSAPI 3
  268. #define BINDMETHOD_SASL_DIGEST_MD5 4
  269. Repl_Agmt *agmt_new_from_entry(Slapi_Entry *e);
  270. Repl_Agmt *agmt_new_from_pblock(Slapi_PBlock *pb);
  271. void agmt_delete(void **ra);
  272. const Slapi_DN *agmt_get_dn_byref(const Repl_Agmt *ra);
  273. int agmt_get_auto_initialize(const Repl_Agmt *ra);
  274. long agmt_get_timeout(const Repl_Agmt *ra);
  275. long agmt_get_busywaittime(const Repl_Agmt *ra);
  276. long agmt_get_pausetime(const Repl_Agmt *ra);
  277. int agmt_start(Repl_Agmt *ra);
  278. int windows_agmt_start(Repl_Agmt *ra);
  279. int agmt_stop(Repl_Agmt *ra);
  280. int agmt_replicate_now(Repl_Agmt *ra);
  281. char *agmt_get_hostname(const Repl_Agmt *ra);
  282. int agmt_get_port(const Repl_Agmt *ra);
  283. PRUint32 agmt_get_transport_flags(const Repl_Agmt *ra);
  284. char *agmt_get_binddn(const Repl_Agmt *ra);
  285. struct berval *agmt_get_credentials(const Repl_Agmt *ra);
  286. int agmt_get_bindmethod(const Repl_Agmt *ra);
  287. Slapi_DN *agmt_get_replarea(const Repl_Agmt *ra);
  288. int agmt_is_fractional(const Repl_Agmt *ra);
  289. int agmt_is_fractional_attr(const Repl_Agmt *ra, const char *attrname);
  290. int agmt_is_fractional_attr_total(const Repl_Agmt *ra, const char *attrname);
  291. int agmt_is_50_mm_protocol(const Repl_Agmt *ra);
  292. int agmt_matches_name(const Repl_Agmt *ra, const Slapi_DN *name);
  293. int agmt_replarea_matches(const Repl_Agmt *ra, const Slapi_DN *name);
  294. int agmt_schedule_in_window_now(const Repl_Agmt *ra);
  295. int agmt_set_schedule_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  296. int agmt_set_timeout_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  297. int agmt_set_busywaittime_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  298. int agmt_set_pausetime_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  299. int agmt_set_credentials_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  300. int agmt_set_binddn_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  301. int agmt_set_bind_method_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  302. int agmt_set_transportinfo_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  303. int agmt_set_port_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  304. const char *agmt_get_long_name(const Repl_Agmt *ra);
  305. int agmt_initialize_replica(const Repl_Agmt *agmt);
  306. void agmt_replica_init_done (const Repl_Agmt *agmt);
  307. void agmt_notify_change(Repl_Agmt *ra, Slapi_PBlock *pb);
  308. Object* agmt_get_consumer_ruv (Repl_Agmt *ra);
  309. ReplicaId agmt_get_consumer_rid ( Repl_Agmt *ra, void *conn );
  310. int agmt_set_consumer_ruv (Repl_Agmt *ra, RUV *ruv);
  311. void agmt_update_consumer_ruv (Repl_Agmt *ra);
  312. CSN* agmt_get_consumer_schema_csn (Repl_Agmt *ra);
  313. void agmt_set_consumer_schema_csn (Repl_Agmt *ra, CSN *csn);
  314. void agmt_set_last_update_in_progress (Repl_Agmt *ra, PRBool in_progress);
  315. void agmt_set_last_update_start (Repl_Agmt *ra, time_t start_time);
  316. void agmt_set_last_update_end (Repl_Agmt *ra, time_t end_time);
  317. void agmt_set_last_update_status (Repl_Agmt *ra, int ldaprc, int replrc, const char *msg);
  318. void agmt_set_update_in_progress (Repl_Agmt *ra, PRBool in_progress);
  319. PRBool agmt_get_update_in_progress (const Repl_Agmt *ra);
  320. void agmt_set_last_init_start (Repl_Agmt *ra, time_t start_time);
  321. void agmt_set_last_init_end (Repl_Agmt *ra, time_t end_time);
  322. void agmt_set_last_init_status (Repl_Agmt *ra, int ldaprc, int replrc, const char *msg);
  323. void agmt_inc_last_update_changecount (Repl_Agmt *ra, ReplicaId rid, int skipped);
  324. void agmt_get_changecount_string (Repl_Agmt *ra, char *buf, int bufsize);
  325. int agmt_set_replicated_attributes_from_entry(Repl_Agmt *ra, const Slapi_Entry *e);
  326. int agmt_set_replicated_attributes_total_from_entry(Repl_Agmt *ra, const Slapi_Entry *e);
  327. int agmt_set_replicated_attributes_from_attr(Repl_Agmt *ra, Slapi_Attr *sattr);
  328. int agmt_set_replicated_attributes_total_from_attr(Repl_Agmt *ra, Slapi_Attr *sattr);
  329. char **agmt_get_fractional_attrs(const Repl_Agmt *ra);
  330. char **agmt_get_fractional_attrs_total(const Repl_Agmt *ra);
  331. char **agmt_validate_replicated_attributes(Repl_Agmt *ra, int total);
  332. void* agmt_get_priv (const Repl_Agmt *agmt);
  333. void agmt_set_priv (Repl_Agmt *agmt, void* priv);
  334. int get_agmt_agreement_type ( Repl_Agmt *agmt);
  335. void* agmt_get_connection( Repl_Agmt *ra);
  336. int agmt_has_protocol(Repl_Agmt *agmt);
  337. PRBool agmt_is_enabled(Repl_Agmt *ra);
  338. int agmt_set_enabled_from_entry(Repl_Agmt *ra, Slapi_Entry *e, char *returntext);
  339. char **agmt_get_attrs_to_strip(Repl_Agmt *ra);
  340. int agmt_set_attrs_to_strip(Repl_Agmt *ra, Slapi_Entry *e);
  341. void agmt_set_cleanruv_notified_from_entry(Repl_Agmt *ra, Slapi_Entry *e);
  342. int agmt_set_cleanruv_data(Repl_Agmt *ra, ReplicaId rid, int op);
  343. int agmt_is_cleanruv_notified(Repl_Agmt *ra, ReplicaId rid);
  344. int agmt_set_timeout(Repl_Agmt *ra, long timeout);
  345. void agmt_update_done(Repl_Agmt *ra, int is_total);
  346. typedef struct replica Replica;
  347. /* In repl5_agmtlist.c */
  348. int agmtlist_config_init();
  349. void agmtlist_shutdown();
  350. void agmtlist_notify_all(Slapi_PBlock *pb);
  351. Object* agmtlist_get_first_agreement_for_replica (Replica *r);
  352. Object* agmtlist_get_next_agreement_for_replica (Replica *r, Object *prev);
  353. /* In repl5_backoff.c */
  354. typedef struct backoff_timer Backoff_Timer;
  355. #define BACKOFF_FIXED 1
  356. #define BACKOFF_EXPONENTIAL 2
  357. #define BACKOFF_RANDOM 3
  358. Backoff_Timer *backoff_new(int timer_type, int initial_interval, int max_interval);
  359. time_t backoff_reset(Backoff_Timer *bt, slapi_eq_fn_t callback, void *callback_data);
  360. time_t backoff_step(Backoff_Timer *bt);
  361. int backoff_expired(Backoff_Timer *bt, int margin);
  362. void backoff_delete(Backoff_Timer **btp);
  363. /* In repl5_connection.c */
  364. typedef struct repl_connection Repl_Connection;
  365. typedef enum
  366. {
  367. CONN_OPERATION_SUCCESS,
  368. CONN_OPERATION_FAILED,
  369. CONN_NOT_CONNECTED,
  370. CONN_SUPPORTS_DS5_REPL,
  371. CONN_DOES_NOT_SUPPORT_DS5_REPL,
  372. CONN_SCHEMA_UPDATED,
  373. CONN_SCHEMA_NO_UPDATE_NEEDED,
  374. CONN_LOCAL_ERROR,
  375. CONN_BUSY,
  376. CONN_SSL_NOT_ENABLED,
  377. CONN_TIMEOUT,
  378. CONN_SUPPORTS_DS71_REPL,
  379. CONN_DOES_NOT_SUPPORT_DS71_REPL,
  380. CONN_IS_READONLY,
  381. CONN_IS_NOT_READONLY,
  382. CONN_SUPPORTS_DIRSYNC,
  383. CONN_DOES_NOT_SUPPORT_DIRSYNC,
  384. CONN_IS_WIN2K3,
  385. CONN_NOT_WIN2K3,
  386. CONN_SUPPORTS_DS90_REPL,
  387. CONN_DOES_NOT_SUPPORT_DS90_REPL
  388. } ConnResult;
  389. Repl_Connection *conn_new(Repl_Agmt *agmt);
  390. ConnResult conn_connect(Repl_Connection *conn);
  391. void conn_disconnect(Repl_Connection *conn);
  392. void conn_delete(Repl_Connection *conn);
  393. void conn_get_error(Repl_Connection *conn, int *operation, int *error);
  394. void conn_get_error_ex(Repl_Connection *conn, int *operation, int *error, char **error_string);
  395. ConnResult conn_send_add(Repl_Connection *conn, const char *dn, LDAPMod **attrs,
  396. LDAPControl *update_control, int *message_id);
  397. ConnResult conn_send_delete(Repl_Connection *conn, const char *dn,
  398. LDAPControl *update_control, int *message_id);
  399. ConnResult conn_send_modify(Repl_Connection *conn, const char *dn, LDAPMod **mods,
  400. LDAPControl *update_control, int *message_id);
  401. ConnResult conn_send_rename(Repl_Connection *conn, const char *dn,
  402. const char *newrdn, const char *newparent, int deleteoldrdn,
  403. LDAPControl *update_control, int *message_id);
  404. ConnResult conn_send_extended_operation(Repl_Connection *conn, const char *extop_oid,
  405. struct berval *payload, LDAPControl *update_control, int *message_id);
  406. const char *conn_get_status(Repl_Connection *conn);
  407. void conn_start_linger(Repl_Connection *conn);
  408. void conn_cancel_linger(Repl_Connection *conn);
  409. ConnResult conn_replica_supports_ds5_repl(Repl_Connection *conn);
  410. ConnResult conn_replica_supports_ds71_repl(Repl_Connection *conn);
  411. ConnResult conn_replica_supports_ds90_repl(Repl_Connection *conn);
  412. ConnResult conn_replica_is_readonly(Repl_Connection *conn);
  413. ConnResult conn_read_entry_attribute(Repl_Connection *conn, const char *dn, char *type,
  414. struct berval ***returned_bvals);
  415. ConnResult conn_push_schema(Repl_Connection *conn, CSN **remotecsn);
  416. void conn_set_timeout(Repl_Connection *conn, long timeout);
  417. long conn_get_timeout(Repl_Connection *conn);
  418. void conn_set_agmt_changed(Repl_Connection *conn);
  419. ConnResult conn_read_result(Repl_Connection *conn, int *message_id);
  420. ConnResult conn_read_result_ex(Repl_Connection *conn, char **retoidp, struct berval **retdatap, LDAPControl ***returned_controls, int send_msgid, int *resp_msgid, int noblock);
  421. LDAP * conn_get_ldap(Repl_Connection *conn);
  422. void conn_lock(Repl_Connection *conn);
  423. void conn_unlock(Repl_Connection *conn);
  424. void conn_delete_internal_ext(Repl_Connection *conn);
  425. /* In repl5_protocol.c */
  426. typedef struct repl_protocol Repl_Protocol;
  427. Repl_Protocol *prot_new(Repl_Agmt *agmt, int protocol_state);
  428. void prot_start(Repl_Protocol *rp);
  429. Repl_Agmt *prot_get_agreement(Repl_Protocol *rp);
  430. /* initiate total protocol */
  431. void prot_initialize_replica(Repl_Protocol *rp);
  432. /* stop protocol session in progress */
  433. void prot_stop(Repl_Protocol *rp);
  434. void prot_delete(Repl_Protocol **rpp);
  435. void prot_free(Repl_Protocol **rpp);
  436. PRBool prot_set_active_protocol (Repl_Protocol *rp, PRBool total);
  437. void prot_clear_active_protocol (Repl_Protocol *rp);
  438. Repl_Connection *prot_get_connection(Repl_Protocol *rp);
  439. void prot_resume(Repl_Protocol *rp, int wakeup_action);
  440. void prot_notify_update(Repl_Protocol *rp);
  441. void prot_notify_agmt_changed(Repl_Protocol *rp, char * agmt_name);
  442. void prot_notify_window_opened (Repl_Protocol *rp);
  443. void prot_notify_window_closed (Repl_Protocol *rp);
  444. Object *prot_get_replica_object(Repl_Protocol *rp);
  445. void prot_replicate_now(Repl_Protocol *rp);
  446. /* In repl5_replica.c */
  447. typedef enum
  448. {
  449. REPLICA_TYPE_UNKNOWN,
  450. REPLICA_TYPE_PRIMARY,
  451. REPLICA_TYPE_READONLY,
  452. REPLICA_TYPE_UPDATABLE,
  453. REPLICA_TYPE_END
  454. } ReplicaType;
  455. #define RUV_STORAGE_ENTRY_UNIQUEID "ffffffff-ffffffff-ffffffff-ffffffff"
  456. #define START_ITERATION_ENTRY_UNIQUEID "00000000-00000000-00000000-00000000"
  457. #define START_ITERATION_ENTRY_DN "cn=start iteration"
  458. typedef int (*FNEnumReplica) (Replica *r, void *arg);
  459. /* this function should be called to construct the replica object
  460. from the data already in the DIT */
  461. Replica *replica_new(const Slapi_DN *root);
  462. Replica *windows_replica_new(const Slapi_DN *root);
  463. /* this function should be called to construct the replica object
  464. during addition of the replica over LDAP */
  465. Replica *replica_new_from_entry (Slapi_Entry *e, char *errortext, PRBool is_add_operation);
  466. void replica_destroy(void **arg);
  467. PRBool replica_get_exclusive_access(Replica *r, PRBool *isInc, PRUint64 connid, int opid,
  468. const char *locking_purl,
  469. char **current_purl);
  470. void replica_relinquish_exclusive_access(Replica *r, PRUint64 connid, int opid);
  471. PRBool replica_get_tombstone_reap_active(const Replica *r);
  472. const Slapi_DN *replica_get_root(const Replica *r);
  473. const char *replica_get_name(const Replica *r);
  474. ReplicaId replica_get_rid (const Replica *r);
  475. void replica_set_rid (Replica *r, ReplicaId rid);
  476. PRBool replica_is_initialized (const Replica *r);
  477. Object *replica_get_ruv (const Replica *r);
  478. /* replica now owns the RUV */
  479. void replica_set_ruv (Replica *r, RUV *ruv);
  480. Object *replica_get_csngen (const Replica *r);
  481. ReplicaType replica_get_type (const Replica *r);
  482. void replica_set_type (Replica *r, ReplicaType type);
  483. PRBool replica_is_legacy_consumer (const Replica *r);
  484. void replica_set_legacy_consumer (Replica *r, PRBool legacy);
  485. char *replica_get_legacy_purl (const Replica *r);
  486. void replica_set_legacy_purl (Replica *r, const char *purl);
  487. PRBool replica_is_updatedn (const Replica *r, const Slapi_DN *sdn);
  488. void replica_set_updatedn (Replica *r, const Slapi_ValueSet *vs, int mod_op);
  489. char *replica_get_generation (const Replica *r);
  490. /* currently supported flags */
  491. #define REPLICA_LOG_CHANGES 0x1 /* enable change logging */
  492. PRBool replica_is_flag_set (const Replica *r, PRUint32 flag);
  493. void replica_set_flag (Replica *r, PRUint32 flag, PRBool clear);
  494. void replica_replace_flags (Replica *r, PRUint32 flags);
  495. void replica_dump(Replica *r);
  496. void replica_set_enabled (Replica *r, PRBool enable);
  497. Object *replica_get_replica_from_dn (const Slapi_DN *dn);
  498. void replica_update_ruv(Replica *replica, const CSN *csn, const char *replica_purl);
  499. Object *replica_get_replica_for_op (Slapi_PBlock *pb);
  500. /* the functions below manipulate replica hash */
  501. int replica_init_name_hash ();
  502. void replica_destroy_name_hash ();
  503. int replica_add_by_name (const char *name, Object *replica);
  504. int replica_delete_by_name (const char *name);
  505. Object* replica_get_by_name (const char *name);
  506. void replica_flush(Replica *r);
  507. void replica_get_referrals(const Replica *r, char ***referrals);
  508. void replica_set_referrals(Replica *r,const Slapi_ValueSet *vs);
  509. int replica_update_csngen_state (Replica *r, const RUV *ruv);
  510. int replica_update_csngen_state_ext (Replica *r, const RUV *ruv, const CSN *extracsn);
  511. CSN *replica_get_purge_csn(const Replica *r);
  512. int replica_log_ruv_elements (const Replica *r);
  513. void replica_enumerate_replicas (FNEnumReplica fn, void *arg);
  514. int replica_reload_ruv (Replica *r);
  515. int replica_check_for_data_reload (Replica *r, void *arg);
  516. /* the functions below manipulate replica dn hash */
  517. int replica_init_dn_hash ();
  518. void replica_destroy_dn_hash ();
  519. int replica_add_by_dn (const char *dn);
  520. int replica_delete_by_dn (const char *dn);
  521. int replica_is_being_configured (const char *dn);
  522. const CSN * _get_deletion_csn(Slapi_Entry *e);
  523. int legacy_consumer_init_referrals (Replica *r);
  524. void consumer5_set_mapping_tree_state_for_replica(const Replica *r, RUV *supplierRuv);
  525. Object *replica_get_for_backend (const char *be_name);
  526. void replica_set_purge_delay (Replica *r, PRUint32 purge_delay);
  527. void replica_set_tombstone_reap_interval (Replica *r, long interval);
  528. void replica_update_ruv_consumer (Replica *r, RUV *supplier_ruv);
  529. void replica_set_ruv_dirty (Replica *r);
  530. void replica_write_ruv (Replica *r);
  531. char *replica_get_dn(Replica *r);
  532. void replica_check_for_tasks(Replica*r, Slapi_Entry *e);
  533. /* The functions below handles the state flag */
  534. /* Current internal state flags */
  535. /* The replica can be busy and not other flag,
  536. * it means that the protocol has ended, but the work is not done yet.
  537. * It happens on total protocol, the end protocol has been received,
  538. * and the thread waits for import to finish
  539. */
  540. #define REPLICA_IN_USE 1 /* The replica is busy */
  541. #define REPLICA_INCREMENTAL_IN_PROGRESS 2 /* Set only between start and stop inc */
  542. #define REPLICA_TOTAL_IN_PROGRESS 4 /* Set only between start and stop total */
  543. #define REPLICA_AGREEMENTS_DISABLED 8 /* Replica is offline */
  544. #define REPLICA_TOTAL_EXCL_SEND 16 /* The server is either sending or receiving
  545. the total update. Introducing it if SEND
  546. is active, RECV should back off. And
  547. vice versa. But SEND can coexist. */
  548. #define REPLICA_TOTAL_EXCL_RECV 32 /* ditto */
  549. PRBool replica_is_state_flag_set(Replica *r, PRInt32 flag);
  550. void replica_set_state_flag (Replica *r, PRUint32 flag, PRBool clear);
  551. void replica_set_tombstone_reap_stop(Replica *r, PRBool val);
  552. void replica_enable_replication (Replica *r);
  553. void replica_disable_replication (Replica *r, Object *r_obj);
  554. int replica_start_agreement(Replica *r, Repl_Agmt *ra);
  555. int windows_replica_start_agreement(Replica *r, Repl_Agmt *ra);
  556. CSN* replica_generate_next_csn ( Slapi_PBlock *pb, const CSN *basecsn );
  557. int replica_get_attr ( Slapi_PBlock *pb, const char *type, void *value );
  558. /* mapping tree extensions manipulation */
  559. void multimaster_mtnode_extension_init ();
  560. void multimaster_mtnode_extension_destroy ();
  561. void multimaster_mtnode_construct_replicas ();
  562. void multimaster_be_state_change (void *handle, char *be_name, int old_be_state, int new_be_state);
  563. /* In repl5_replica_config.c */
  564. int replica_config_init();
  565. void replica_config_destroy ();
  566. int get_replica_type(Replica *r);
  567. int replica_execute_cleanruv_task_ext(Object *r, ReplicaId rid);
  568. void add_cleaned_rid(ReplicaId rid, Replica *r, char *maxcsn);
  569. int is_cleaned_rid(ReplicaId rid);
  570. int replica_cleanall_ruv_abort(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *eAfter,
  571. int *returncode, char *returntext, void *arg);
  572. void replica_cleanallruv_thread_ext(void *arg);
  573. void stop_ruv_cleaning();
  574. int task_aborted();
  575. void replica_abort_task_thread(void *arg);
  576. void delete_cleaned_rid(Replica *r, ReplicaId rid, CSN *maxcsn);
  577. int process_repl_agmts(Replica *replica, int *agmt_info, char *oid, Slapi_Task *task, struct berval *payload, int op);
  578. int decode_cleanruv_payload(struct berval *extop_value, char **payload);
  579. struct berval *create_ruv_payload(char *value);
  580. void replica_add_cleanruv_data(Replica *r, char *val);
  581. void replica_remove_cleanruv_data(Replica *r, char *val);
  582. CSN *replica_get_cleanruv_maxcsn(Replica *r, ReplicaId rid);
  583. void ruv_get_cleaned_rids(RUV *ruv, ReplicaId *rids);
  584. void add_aborted_rid(ReplicaId rid, Replica *r, char *repl_root);
  585. int is_task_aborted(ReplicaId rid);
  586. void delete_aborted_rid(Replica *replica, ReplicaId rid, char *repl_root);
  587. void set_cleaned_rid(ReplicaId rid);
  588. void cleanruv_log(Slapi_Task *task, char *task_type, char *fmt, ...);
  589. #define CLEANRIDSIZ 4 /* maximum number for concurrent CLEANALLRUV tasks */
  590. typedef struct _cleanruv_data
  591. {
  592. Object *repl_obj;
  593. Replica *replica;
  594. ReplicaId rid;
  595. Slapi_Task *task;
  596. struct berval *payload;
  597. CSN *maxcsn;
  598. char *repl_root;
  599. Slapi_DN *sdn;
  600. } cleanruv_data;
  601. /* replutil.c */
  602. LDAPControl* create_managedsait_control ();
  603. LDAPControl* create_backend_control(Slapi_DN *sdn);
  604. void repl_set_mtn_state_and_referrals(const Slapi_DN *sdn, const char *mtn_state,
  605. const RUV *ruv, char **ruv_referrals,
  606. char **other_referrals);
  607. void repl_set_repl_plugin_path(const char *path);
  608. /* repl5_updatedn_list.c */
  609. typedef void *ReplicaUpdateDNList;
  610. typedef int (*FNEnumDN)(Slapi_DN *dn, void *arg);
  611. ReplicaUpdateDNList replica_updatedn_list_new(const Slapi_Entry *entry);
  612. void replica_updatedn_list_free(ReplicaUpdateDNList list);
  613. void replica_updatedn_list_replace(ReplicaUpdateDNList list, const Slapi_ValueSet *vs);
  614. void replica_updatedn_list_delete(ReplicaUpdateDNList list, const Slapi_ValueSet *vs);
  615. void replica_updatedn_list_add(ReplicaUpdateDNList list, const Slapi_ValueSet *vs);
  616. PRBool replica_updatedn_list_ismember(ReplicaUpdateDNList list, const Slapi_DN *dn);
  617. char *replica_updatedn_list_to_string(ReplicaUpdateDNList list, const char *delimiter);
  618. void replica_updatedn_list_enumerate(ReplicaUpdateDNList list, FNEnumDN fn, void *arg);
  619. /* enabling developper traces for MMR to understand the total/inc protocol state machines */
  620. #ifdef DEV_DEBUG
  621. #define SLAPI_LOG_DEV_DEBUG SLAPI_LOG_FATAL
  622. #define dev_debug(a) slapi_log_error(SLAPI_LOG_DEV_DEBUG, "DEV_DEBUG", "%s\n", a)
  623. #else
  624. #define dev_debug(a)
  625. #endif
  626. void repl5_set_debug_timeout(const char *val);
  627. /* temp hack XXX */
  628. ReplicaId agmt_get_consumerRID(Repl_Agmt *ra);
  629. void windows_init_agreement_from_entry(Repl_Agmt *ra, Slapi_Entry *e);
  630. int windows_handle_modify_agreement(Repl_Agmt *ra, const char *type, Slapi_Entry *e);
  631. void windows_agreement_delete(Repl_Agmt *ra);
  632. Repl_Connection *windows_conn_new(Repl_Agmt *agmt);
  633. void windows_conn_delete(Repl_Connection *conn);
  634. void windows_update_done(Repl_Agmt *ra, int is_total);
  635. /* repl_session_plugin.c */
  636. void repl_session_plugin_init();
  637. void repl_session_plugin_call_agmt_init_cb(Repl_Agmt *ra);
  638. int repl_session_plugin_call_pre_acquire_cb(const Repl_Agmt *ra, int is_total,
  639. char **data_guid, struct berval **data);
  640. int repl_session_plugin_call_post_acquire_cb(const Repl_Agmt *ra, int is_total,
  641. const char *data_guid, const struct berval *data);
  642. int repl_session_plugin_call_recv_acquire_cb(const char *repl_area, int is_total,
  643. const char *data_guid, const struct berval *data);
  644. int repl_session_plugin_call_reply_acquire_cb(const char *repl_area, int is_total,
  645. char **data_guid, struct berval **data);
  646. void repl_session_plugin_call_destroy_agmt_cb(const Repl_Agmt *ra);
  647. #endif /* _REPL5_H_ */