repl5.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. * END COPYRIGHT BLOCK **/
  6. /* repl5.h - 5.0 replication header */
  7. #ifndef _REPL5_H_
  8. #define _REPL5_H_
  9. #include <limits.h>
  10. #include <time.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #ifndef _WIN32
  14. #include <sys/param.h>
  15. #endif /* _WIN32 */
  16. #include "portable.h" /* GGOODREPL - is this cheating? */
  17. #include "repl_shared.h"
  18. #include "llist.h"
  19. #include "repl5_ruv.h"
  20. #include "cl4.h"
  21. #define REPLICA_TYPE_WINDOWS 1
  22. #define REPLICA_TYPE_MULTIMASTER 0
  23. #define REPL_DIRSYNC_CONTROL_OID "1.2.840.113556.1.4.841"
  24. #define CONN_SUPPORTS_DIRSYNC 12
  25. #define CONN_DOES_NOT_SUPPORT_DIRSYNC 13
  26. /* DS 5.0 replication protocol OIDs */
  27. #define REPL_START_NSDS50_REPLICATION_REQUEST_OID "2.16.840.1.113730.3.5.3"
  28. #define REPL_END_NSDS50_REPLICATION_REQUEST_OID "2.16.840.1.113730.3.5.5"
  29. #define REPL_NSDS50_REPLICATION_ENTRY_REQUEST_OID "2.16.840.1.113730.3.5.6"
  30. #define REPL_NSDS50_REPLICATION_RESPONSE_OID "2.16.840.1.113730.3.5.4"
  31. #define REPL_NSDS50_UPDATE_INFO_CONTROL_OID "2.16.840.1.113730.3.4.13"
  32. #define REPL_NSDS50_INCREMENTAL_PROTOCOL_OID "2.16.840.1.113730.3.6.1"
  33. #define REPL_NSDS50_TOTAL_PROTOCOL_OID "2.16.840.1.113730.3.6.2"
  34. /* DS7.1 introduces pipelineing in the protocol : really not much different to the 5.0
  35. * protocol, but enough change to make it unsafe to interoperate the two. So we define
  36. * new OIDs for 7.1 here. The supplier server looks for these on the consumer and
  37. * if they're not there it falls back to the older 5.0 non-pipelined protocol */
  38. #define REPL_NSDS71_INCREMENTAL_PROTOCOL_OID "2.16.840.1.113730.3.6.4"
  39. #define REPL_NSDS71_TOTAL_PROTOCOL_OID "2.16.840.1.113730.3.6.3"
  40. /* The new protocol OIDs above do not help us with determining if a consumer
  41. * Supports them or not. That's because they're burried inside the start replication
  42. * extended operation, and are not visible in the support controls and operations list
  43. * So, we add a new extended operation for the 7.1 total protocol. This is partly because
  44. * the total protocol is slightly different (no LDAP_BUSY allowed in 7.1) and partly
  45. * because we need a handy way to spot the difference between a pre-7.1 and post-7.0
  46. * consumer at the supplier */
  47. #define REPL_NSDS71_REPLICATION_ENTRY_REQUEST_OID "2.16.840.1.113730.3.5.9"
  48. /* DS 5.0 replication protocol error codes */
  49. #define NSDS50_REPL_REPLICA_READY 0x00 /* Replica ready, go ahead */
  50. #define NSDS50_REPL_REPLICA_BUSY 0x01 /* Replica busy, try later */
  51. #define NSDS50_REPL_EXCESSIVE_CLOCK_SKEW 0x02 /* Supplier clock too far ahead */
  52. #define NSDS50_REPL_PERMISSION_DENIED 0x03 /* Bind DN not allowed to send updates */
  53. #define NSDS50_REPL_DECODING_ERROR 0x04 /* Consumer couldn't decode extended operation */
  54. #define NSDS50_REPL_UNKNOWN_UPDATE_PROTOCOL 0x05 /* Consumer doesn't understand suplier's update protocol */
  55. #define NSDS50_REPL_NO_SUCH_REPLICA 0x06 /* Consumer holds no such replica */
  56. #define NSDS50_REPL_BELOW_PURGEPOINT 0x07 /* Supplier provided a CSN below the consumer's purge point */
  57. #define NSDS50_REPL_INTERNAL_ERROR 0x08 /* Something bad happened on consumer */
  58. #define NSDS50_REPL_REPLICA_RELEASE_SUCCEEDED 0x09 /* Replica released successfully */
  59. #define NSDS50_REPL_LEGACY_CONSUMER 0x0A /* replica is a legacy consumer */
  60. #define NSDS50_REPL_REPLICAID_ERROR 0x0B /* replicaID doesn't seem to be unique */
  61. #define NSDS50_REPL_DISABLED 0x0C /* replica suffix is disabled */
  62. #define NSDS50_REPL_UPTODATE 0x0D /* replica is uptodate */
  63. #define NSDS50_REPL_REPLICA_NO_RESPONSE 0xff /* No response received */
  64. /* Protocol status */
  65. #define PROTOCOL_STATUS_UNKNOWN 701
  66. #define PROTOCOL_STATUS_INCREMENTAL_AWAITING_CHANGES 702
  67. #define PROTOCOL_STATUS_INCREMENTAL_ACQUIRING_REPLICA 703
  68. #define PROTOCOL_STATUS_INCREMENTAL_RELEASING_REPLICA 704
  69. #define PROTOCOL_STATUS_INCREMENTAL_SENDING_UPDATES 705
  70. #define PROTOCOL_STATUS_INCREMENTAL_BACKING_OFF 706
  71. #define PROTOCOL_STATUS_INCREMENTAL_NEEDS_TOTAL_UPDATE 707
  72. #define PROTOCOL_STATUS_INCREMENTAL_FATAL_ERROR 708
  73. #define PROTOCOL_STATUS_TOTAL_ACQUIRING_REPLICA 709
  74. #define PROTOCOL_STATUS_TOTAL_RELEASING_REPLICA 710
  75. #define PROTOCOL_STATUS_TOTAL_SENDING_DATA 711
  76. /* To Allow Consumer Initialisation when adding an agreement - */
  77. #define STATE_PERFORMING_TOTAL_UPDATE 501
  78. #define STATE_PERFORMING_INCREMENTAL_UPDATE 502
  79. #define MAX_NUM_OF_MASTERS 64
  80. #define REPL_SESSION_ID_SIZE 64
  81. /* Attribute names for replication agreement attributes */
  82. extern const char *type_nsds5ReplicaHost;
  83. extern const char *type_nsds5ReplicaPort;
  84. extern const char *type_nsds5TransportInfo;
  85. extern const char *type_nsds5ReplicaBindDN;
  86. extern const char *type_nsds5ReplicaCredentials;
  87. extern const char *type_nsds5ReplicaBindMethod;
  88. extern const char *type_nsds5ReplicaRoot;
  89. extern const char *type_nsds5ReplicatedAttributeList;
  90. extern const char *type_nsds5ReplicaUpdateSchedule;
  91. extern const char *type_nsds5ReplicaInitialize;
  92. extern const char *type_nsds5ReplicaTimeout;
  93. extern const char *type_nsds5ReplicaBusyWaitTime;
  94. extern const char *type_nsds5ReplicaSessionPauseTime;
  95. /* Attribute names for windows replication agreements */
  96. extern const char *type_nsds7WindowsReplicaArea;
  97. extern const char *type_nsds7DirectoryReplicaArea;
  98. extern const char *type_nsds7CreateNewUsers;
  99. /* To Allow Consumer Initialisation when adding an agreement - */
  100. extern const char *type_nsds5BeginReplicaRefresh;
  101. /* replica related attributes */
  102. extern const char *attr_replicaId;
  103. extern const char *attr_replicaRoot;
  104. extern const char *attr_replicaType;
  105. extern const char *attr_replicaBindDn;
  106. extern const char *attr_state;
  107. extern const char *attr_flags;
  108. extern const char *attr_replicaName;
  109. extern const char *attr_replicaReferral;
  110. extern const char *type_ruvElement;
  111. extern const char *type_replicaPurgeDelay;
  112. extern const char *type_replicaChangeCount;
  113. extern const char *type_replicaTombstonePurgeInterval;
  114. extern const char *type_replicaLegacyConsumer;
  115. extern const char *type_ruvElementUpdatetime;
  116. /* multimaster plugin points */
  117. int multimaster_preop_bind (Slapi_PBlock *pb);
  118. int multimaster_preop_add (Slapi_PBlock *pb);
  119. int multimaster_preop_delete (Slapi_PBlock *pb);
  120. int multimaster_preop_modify (Slapi_PBlock *pb);
  121. int multimaster_preop_modrdn (Slapi_PBlock *pb);
  122. int multimaster_preop_search (Slapi_PBlock *pb);
  123. int multimaster_preop_compare (Slapi_PBlock *pb);
  124. int multimaster_bepreop_add (Slapi_PBlock *pb);
  125. int multimaster_bepreop_delete (Slapi_PBlock *pb);
  126. int multimaster_bepreop_modify (Slapi_PBlock *pb);
  127. int multimaster_bepreop_modrdn (Slapi_PBlock *pb);
  128. int multimaster_bepostop_modrdn (Slapi_PBlock *pb);
  129. int multimaster_bepostop_delete (Slapi_PBlock *pb);
  130. int multimaster_postop_bind (Slapi_PBlock *pb);
  131. int multimaster_postop_add (Slapi_PBlock *pb);
  132. int multimaster_postop_delete (Slapi_PBlock *pb);
  133. int multimaster_postop_modify (Slapi_PBlock *pb);
  134. int multimaster_postop_modrdn (Slapi_PBlock *pb);
  135. /* In repl5_init.c */
  136. char* get_thread_private_agmtname ();
  137. void set_thread_private_agmtname (const char *agmtname);
  138. void* get_thread_private_cache ();
  139. void set_thread_private_cache (void *buf);
  140. char* get_repl_session_id (Slapi_PBlock *pb, char *id, CSN **opcsn);
  141. /* In repl_extop.c */
  142. int multimaster_extop_StartNSDS50ReplicationRequest(Slapi_PBlock *pb);
  143. int multimaster_extop_EndNSDS50ReplicationRequest(Slapi_PBlock *pb);
  144. int extop_noop(Slapi_PBlock *pb);
  145. struct berval *NSDS50StartReplicationRequest_new(const char *protocol_oid,
  146. const char *repl_root, char **extra_referrals, CSN *csn);
  147. struct berval *NSDS50EndReplicationRequest_new(char *repl_root);
  148. int decode_repl_ext_response(struct berval *data, int *response_code,
  149. struct berval ***ruv_bervals);
  150. /* In repl5_total.c */
  151. int multimaster_extop_NSDS50ReplicationEntry(Slapi_PBlock *pb);
  152. /* In repl_controls.c */
  153. int create_NSDS50ReplUpdateInfoControl(const char *uuid,
  154. const char *superior_uuid, const CSN *csn,
  155. LDAPMod **modify_mods, LDAPControl **ctrlp);
  156. void destroy_NSDS50ReplUpdateInfoControl(LDAPControl **ctrlp);
  157. int decode_NSDS50ReplUpdateInfoControl(LDAPControl **controlsp,
  158. char **uuid, char **newsuperior_uuid, CSN **csn, LDAPMod ***modrdn_mods);
  159. /* In repl5_replsupplier.c */
  160. typedef struct repl_supplier Repl_Supplier;
  161. Repl_Supplier *replsupplier_init(Slapi_Entry *e);
  162. void replsupplier_configure(Repl_Supplier *rs, Slapi_PBlock *pb);
  163. void replsupplier_start(Repl_Supplier *rs);
  164. void replsupplier_stop(Repl_Supplier *rs);
  165. void replsupplier_destroy(Repl_Supplier **rs);
  166. void replsupplier_notify(Repl_Supplier *rs, PRUint32 eventmask);
  167. PRUint32 replsupplier_get_status(Repl_Supplier *rs);
  168. /* In repl5_plugins.c */
  169. int multimaster_set_local_purl();
  170. const char *multimaster_get_local_purl();
  171. PRBool multimaster_started();
  172. /* In repl5_schedule.c */
  173. typedef struct schedule Schedule;
  174. typedef void (*window_state_change_callback)(void *arg, PRBool opened);
  175. Schedule *schedule_new(window_state_change_callback callback_fn, void *callback_arg, const char *session_id);
  176. void schedule_destroy(Schedule *s);
  177. int schedule_set(Schedule *sch, Slapi_Attr *attr);
  178. char **schedule_get(Schedule *sch);
  179. int schedule_in_window_now(Schedule *sch);
  180. PRTime schedule_next(Schedule *sch);
  181. int schedule_notify(Schedule *sch, Slapi_PBlock *pb);
  182. void schedule_set_priority_attributes(Schedule *sch, char **prio_attrs, int override_schedule);
  183. void schedule_set_startup_delay(Schedule *sch, size_t startup_delay);
  184. void schedule_set_maximum_backlog(Schedule *sch, size_t max_backlog);
  185. void schedule_notify_session(Schedule *sch, PRTime session_end_time, unsigned int flags);
  186. #define REPLICATION_SESSION_SUCCESS 0
  187. /* In repl5_bos.c */
  188. typedef struct repl_bos Repl_Bos;
  189. /* In repl5_agmt.c */
  190. typedef struct repl5agmt Repl_Agmt;
  191. #define TRANSPORT_FLAG_SSL 1
  192. #define TRANSPORT_FLAG_TLS 2
  193. #define BINDMETHOD_SIMPLE_AUTH 1
  194. #define BINDMETHOD_SSL_CLIENTAUTH 2
  195. Repl_Agmt *agmt_new_from_entry(Slapi_Entry *e);
  196. Repl_Agmt *agmt_new_from_pblock(Slapi_PBlock *pb);
  197. void agmt_delete(void **ra);
  198. const Slapi_DN *agmt_get_dn_byref(const Repl_Agmt *ra);
  199. int agmt_get_auto_initialize(const Repl_Agmt *ra);
  200. long agmt_get_timeout(const Repl_Agmt *ra);
  201. long agmt_get_busywaittime(const Repl_Agmt *ra);
  202. long agmt_get_pausetime(const Repl_Agmt *ra);
  203. int agmt_start(Repl_Agmt *ra);
  204. int windows_agmt_start(Repl_Agmt *ra);
  205. int agmt_stop(Repl_Agmt *ra);
  206. int agmt_replicate_now(Repl_Agmt *ra);
  207. char *agmt_get_hostname(const Repl_Agmt *ra);
  208. int agmt_get_port(const Repl_Agmt *ra);
  209. PRUint32 agmt_get_transport_flags(const Repl_Agmt *ra);
  210. char *agmt_get_binddn(const Repl_Agmt *ra);
  211. struct berval *agmt_get_credentials(const Repl_Agmt *ra);
  212. int agmt_get_bindmethod(const Repl_Agmt *ra);
  213. Slapi_DN *agmt_get_replarea(const Repl_Agmt *ra);
  214. int agmt_is_fractional(const Repl_Agmt *ra);
  215. int agmt_is_fractional_attr(const Repl_Agmt *ra, const char *attrname);
  216. int agmt_is_50_mm_protocol(const Repl_Agmt *ra);
  217. int agmt_matches_name(const Repl_Agmt *ra, const Slapi_DN *name);
  218. int agmt_replarea_matches(const Repl_Agmt *ra, const Slapi_DN *name);
  219. int agmt_schedule_in_window_now(const Repl_Agmt *ra);
  220. int agmt_set_schedule_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  221. int agmt_set_timeout_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  222. int agmt_set_busywaittime_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  223. int agmt_set_pausetime_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  224. int agmt_set_credentials_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  225. int agmt_set_binddn_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  226. int agmt_set_bind_method_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  227. int agmt_set_transportinfo_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
  228. const char *agmt_get_long_name(const Repl_Agmt *ra);
  229. int agmt_initialize_replica(const Repl_Agmt *agmt);
  230. void agmt_replica_init_done (const Repl_Agmt *agmt);
  231. void agmt_notify_change(Repl_Agmt *ra, Slapi_PBlock *pb);
  232. Object* agmt_get_consumer_ruv (Repl_Agmt *ra);
  233. ReplicaId agmt_get_consumer_rid ( Repl_Agmt *ra, void *conn );
  234. int agmt_set_consumer_ruv (Repl_Agmt *ra, RUV *ruv);
  235. void agmt_update_consumer_ruv (Repl_Agmt *ra);
  236. CSN* agmt_get_consumer_schema_csn (Repl_Agmt *ra);
  237. void agmt_set_consumer_schema_csn (Repl_Agmt *ra, CSN *csn);
  238. void agmt_set_last_update_in_progress (Repl_Agmt *ra, PRBool in_progress);
  239. void agmt_set_last_update_start (Repl_Agmt *ra, time_t start_time);
  240. void agmt_set_last_update_end (Repl_Agmt *ra, time_t end_time);
  241. void agmt_set_last_update_status (Repl_Agmt *ra, int ldaprc, int replrc, const char *msg);
  242. void agmt_set_update_in_progress (Repl_Agmt *ra, PRBool in_progress);
  243. void agmt_set_last_init_start (Repl_Agmt *ra, time_t start_time);
  244. void agmt_set_last_init_end (Repl_Agmt *ra, time_t end_time);
  245. void agmt_set_last_init_status (Repl_Agmt *ra, int ldaprc, int replrc, const char *msg);
  246. void agmt_inc_last_update_changecount (Repl_Agmt *ra, ReplicaId rid, int skipped);
  247. void agmt_get_changecount_string (Repl_Agmt *ra, char *buf, int bufsize);
  248. int agmt_set_replicated_attributes_from_entry(Repl_Agmt *ra, const Slapi_Entry *e);
  249. int agmt_set_replicated_attributes_from_attr(Repl_Agmt *ra, Slapi_Attr *sattr);
  250. char **agmt_get_fractional_attrs(const Repl_Agmt *ra);
  251. char **agmt_validate_replicated_attributes(Repl_Agmt *ra);
  252. int get_agmt_agreement_type ( Repl_Agmt *agmt);
  253. typedef struct replica Replica;
  254. /* In repl5_agmtlist.c */
  255. int agmtlist_config_init();
  256. void agmtlist_shutdown();
  257. void agmtlist_notify_all(Slapi_PBlock *pb);
  258. Object* agmtlist_get_first_agreement_for_replica (Replica *r);
  259. Object* agmtlist_get_next_agreement_for_replica (Replica *r, Object *prev);
  260. /* In repl5_backoff.c */
  261. typedef struct backoff_timer Backoff_Timer;
  262. #define BACKOFF_FIXED 1
  263. #define BACKOFF_EXPONENTIAL 2
  264. #define BACKOFF_RANDOM 3
  265. Backoff_Timer *backoff_new(int timer_type, int initial_interval, int max_interval);
  266. time_t backoff_reset(Backoff_Timer *bt, slapi_eq_fn_t callback, void *callback_data);
  267. time_t backoff_step(Backoff_Timer *bt);
  268. int backoff_expired(Backoff_Timer *bt, int margin);
  269. void backoff_delete(Backoff_Timer **btp);
  270. /* In repl5_connection.c */
  271. typedef struct repl_connection Repl_Connection;
  272. typedef enum
  273. {
  274. CONN_OPERATION_SUCCESS,
  275. CONN_OPERATION_FAILED,
  276. CONN_NOT_CONNECTED,
  277. CONN_SUPPORTS_DS5_REPL,
  278. CONN_DOES_NOT_SUPPORT_DS5_REPL,
  279. CONN_SCHEMA_UPDATED,
  280. CONN_SCHEMA_NO_UPDATE_NEEDED,
  281. CONN_LOCAL_ERROR,
  282. CONN_BUSY,
  283. CONN_SSL_NOT_ENABLED,
  284. CONN_TIMEOUT,
  285. CONN_SUPPORTS_DS71_REPL,
  286. CONN_DOES_NOT_SUPPORT_DS71_REPL,
  287. CONN_IS_READONLY,
  288. CONN_IS_NOT_READONLY
  289. } ConnResult;
  290. Repl_Connection *conn_new(Repl_Agmt *agmt);
  291. ConnResult conn_connect(Repl_Connection *conn);
  292. void conn_disconnect(Repl_Connection *conn);
  293. void conn_delete(Repl_Connection *conn);
  294. void conn_get_error(Repl_Connection *conn, int *operation, int *error);
  295. void conn_get_error_ex(Repl_Connection *conn, int *operation, int *error, char **error_string);
  296. ConnResult conn_send_add(Repl_Connection *conn, const char *dn, LDAPMod **attrs,
  297. LDAPControl *update_control, int *message_id);
  298. ConnResult conn_send_delete(Repl_Connection *conn, const char *dn,
  299. LDAPControl *update_control, int *message_id);
  300. ConnResult conn_send_modify(Repl_Connection *conn, const char *dn, LDAPMod **mods,
  301. LDAPControl *update_control, int *message_id);
  302. ConnResult conn_send_rename(Repl_Connection *conn, const char *dn,
  303. const char *newrdn, const char *newparent, int deleteoldrdn,
  304. LDAPControl *update_control, int *message_id);
  305. ConnResult conn_send_extended_operation(Repl_Connection *conn, const char *extop_oid,
  306. struct berval *payload, LDAPControl *update_control, int *message_id);
  307. const char *conn_get_status(Repl_Connection *conn);
  308. void conn_start_linger(Repl_Connection *conn);
  309. void conn_cancel_linger(Repl_Connection *conn);
  310. ConnResult conn_replica_supports_ds5_repl(Repl_Connection *conn);
  311. ConnResult conn_replica_supports_ds71_repl(Repl_Connection *conn);
  312. ConnResult conn_replica_is_readonly(Repl_Connection *conn);
  313. ConnResult conn_read_entry_attribute(Repl_Connection *conn, const char *dn, char *type,
  314. struct berval ***returned_bvals);
  315. ConnResult conn_push_schema(Repl_Connection *conn, CSN **remotecsn);
  316. void conn_set_timeout(Repl_Connection *conn, long timeout);
  317. long conn_get_timeout(Repl_Connection *conn);
  318. void conn_set_agmt_changed(Repl_Connection *conn);
  319. ConnResult conn_read_result(Repl_Connection *conn, int *message_id);
  320. ConnResult conn_read_result_ex(Repl_Connection *conn, char **retoidp, struct berval **retdatap, LDAPControl ***returned_controls, int *message_id, int noblock);
  321. /* In repl5_protocol.c */
  322. typedef struct repl_protocol Repl_Protocol;
  323. Repl_Protocol *prot_new(Repl_Agmt *agmt, int protocol_state);
  324. void prot_start(Repl_Protocol *rp);
  325. Repl_Agmt *prot_get_agreement(Repl_Protocol *rp);
  326. /* initiate total protocol */
  327. void prot_initialize_replica(Repl_Protocol *rp);
  328. /* stop protocol session in progress */
  329. void prot_stop(Repl_Protocol *rp);
  330. void prot_delete(Repl_Protocol **rpp);
  331. void prot_free(Repl_Protocol **rpp);
  332. PRBool prot_set_active_protocol (Repl_Protocol *rp, PRBool total);
  333. void prot_clear_active_protocol (Repl_Protocol *rp);
  334. Repl_Connection *prot_get_connection(Repl_Protocol *rp);
  335. void prot_resume(Repl_Protocol *rp, int wakeup_action);
  336. void prot_notify_update(Repl_Protocol *rp);
  337. void prot_notify_agmt_changed(Repl_Protocol *rp, char * agmt_name);
  338. void prot_notify_window_opened (Repl_Protocol *rp);
  339. void prot_notify_window_closed (Repl_Protocol *rp);
  340. Object *prot_get_replica_object(Repl_Protocol *rp);
  341. void prot_replicate_now(Repl_Protocol *rp);
  342. /* In repl5_replica.c */
  343. typedef enum
  344. {
  345. REPLICA_TYPE_UNKNOWN,
  346. REPLICA_TYPE_PRIMARY,
  347. REPLICA_TYPE_READONLY,
  348. REPLICA_TYPE_UPDATABLE,
  349. REPLICA_TYPE_END
  350. } ReplicaType;
  351. #define RUV_STORAGE_ENTRY_UNIQUEID "ffffffff-ffffffff-ffffffff-ffffffff"
  352. #define START_ITERATION_ENTRY_UNIQUEID "00000000-00000000-00000000-00000000"
  353. #define START_ITERATION_ENTRY_DN "cn=start iteration"
  354. typedef int (*FNEnumReplica) (Replica *r, void *arg);
  355. /* this function should be called to construct the replica object
  356. from the data already in the DIT */
  357. Replica *replica_new(const Slapi_DN *root);
  358. Replica *windows_replica_new(const Slapi_DN *root);
  359. /* this function should be called to construct the replica object
  360. during addition of the replica over LDAP */
  361. Replica *replica_new_from_entry (Slapi_Entry *e, char *errortext, PRBool is_add_operation);
  362. void replica_destroy(void **arg);
  363. PRBool replica_get_exclusive_access(Replica *r, PRBool *isInc, int connid, int opid,
  364. const char *locking_purl,
  365. char **current_purl);
  366. void replica_relinquish_exclusive_access(Replica *r, int connid, int opid);
  367. PRBool replica_get_tombstone_reap_active(const Replica *r);
  368. const Slapi_DN *replica_get_root(const Replica *r);
  369. const char *replica_get_name(const Replica *r);
  370. ReplicaId replica_get_rid (const Replica *r);
  371. void replica_set_rid (Replica *r, ReplicaId rid);
  372. PRBool replica_is_initialized (const Replica *r);
  373. Object *replica_get_ruv (const Replica *r);
  374. /* replica now owns the RUV */
  375. void replica_set_ruv (Replica *r, RUV *ruv);
  376. Object *replica_get_csngen (const Replica *r);
  377. ReplicaType replica_get_type (const Replica *r);
  378. void replica_set_type (Replica *r, ReplicaType type);
  379. PRBool replica_is_legacy_consumer (const Replica *r);
  380. void replica_set_legacy_consumer (Replica *r, PRBool legacy);
  381. char *replica_get_legacy_purl (const Replica *r);
  382. void replica_set_legacy_purl (Replica *r, const char *purl);
  383. PRBool replica_is_updatedn (const Replica *r, const Slapi_DN *sdn);
  384. void replica_set_updatedn (Replica *r, const Slapi_ValueSet *vs, int mod_op);
  385. char *replica_get_generation (const Replica *r);
  386. /* currently supported flags */
  387. #define REPLICA_LOG_CHANGES 0x1 /* enable change logging */
  388. PRBool replica_is_flag_set (const Replica *r, PRUint32 flag);
  389. void replica_set_flag (Replica *r, PRUint32 flag, PRBool clear);
  390. void replica_replace_flags (Replica *r, PRUint32 flags);
  391. void replica_dump(Replica *r);
  392. void replica_set_enabled (Replica *r, PRBool enable);
  393. Object *replica_get_replica_from_dn (const Slapi_DN *dn);
  394. void replica_update_ruv(Replica *replica, const CSN *csn, const char *replica_purl);
  395. Object *replica_get_replica_for_op (Slapi_PBlock *pb);
  396. /* the functions below manipulate replica hash */
  397. int replica_init_name_hash ();
  398. void replica_destroy_name_hash ();
  399. int replica_add_by_name (const char *name, Object *replica);
  400. int replica_delete_by_name (const char *name);
  401. Object* replica_get_by_name (const char *name);
  402. void replica_flush(Replica *r);
  403. void replica_get_referrals(const Replica *r, char ***referrals);
  404. void replica_set_referrals(Replica *r,const Slapi_ValueSet *vs);
  405. int replica_update_csngen_state (Replica *r, const RUV *ruv);
  406. CSN *replica_get_purge_csn(const Replica *r);
  407. int replica_log_ruv_elements (const Replica *r);
  408. void replica_enumerate_replicas (FNEnumReplica fn, void *arg);
  409. int replica_reload_ruv (Replica *r);
  410. int replica_check_for_data_reload (Replica *r, void *arg);
  411. /* the functions below manipulate replica dn hash */
  412. int replica_init_dn_hash ();
  413. void replica_destroy_dn_hash ();
  414. int replica_add_by_dn (const char *dn);
  415. int replica_delete_by_dn (const char *dn);
  416. int replica_is_being_configured (const char *dn);
  417. const CSN * _get_deletion_csn(Slapi_Entry *e);
  418. int legacy_consumer_init_referrals (Replica *r);
  419. void consumer5_set_mapping_tree_state_for_replica(const Replica *r, RUV *supplierRuv);
  420. Object *replica_get_for_backend (const char *be_name);
  421. void replica_set_purge_delay (Replica *r, PRUint32 purge_delay);
  422. void replica_set_tombstone_reap_interval (Replica *r, long interval);
  423. void replica_update_ruv_consumer (Replica *r, RUV *supplier_ruv);
  424. void replica_set_ruv_dirty (Replica *r);
  425. void replica_write_ruv (Replica *r);
  426. /* The functions below handles the state flag */
  427. /* Current internal state flags */
  428. /* The replica can be busy and not other flag,
  429. * it means that the protocol has ended, but the work is not done yet.
  430. * It happens on total protocol, the end protocol has been received,
  431. * and the thread waits for import to finish
  432. */
  433. #define REPLICA_IN_USE 1 /* The replica is busy */
  434. #define REPLICA_INCREMENTAL_IN_PROGRESS 2 /* Set only between start and stop inc */
  435. #define REPLICA_TOTAL_IN_PROGRESS 4 /* Set only between start and stop total */
  436. #define REPLICA_AGREEMENTS_DISABLED 8 /* Replica is offline */
  437. PRBool replica_is_state_flag_set(Replica *r, PRInt32 flag);
  438. void replica_set_state_flag (Replica *r, PRUint32 flag, PRBool clear);
  439. void replica_set_tombstone_reap_stop(Replica *r, PRBool val);
  440. void replica_enable_replication (Replica *r);
  441. void replica_disable_replication (Replica *r, Object *r_obj);
  442. int replica_start_agreement(Replica *r, Repl_Agmt *ra);
  443. int windows_replica_start_agreement(Replica *r, Repl_Agmt *ra);
  444. CSN* replica_generate_next_csn ( Slapi_PBlock *pb, const CSN *basecsn );
  445. int replica_get_attr ( Slapi_PBlock *pb, const char *type, void *value );
  446. /* mapping tree extensions manipulation */
  447. void multimaster_mtnode_extension_init ();
  448. void multimaster_mtnode_extension_destroy ();
  449. void multimaster_mtnode_construct_replicas ();
  450. void multimaster_be_state_change (void *handle, char *be_name, int old_be_state, int new_be_state);
  451. /* In repl5_replica_config.c */
  452. int replica_config_init();
  453. void replica_config_destroy ();
  454. int get_replica_type(Replica *r);
  455. /* replutil.c */
  456. LDAPControl* create_managedsait_control ();
  457. LDAPControl* create_backend_control(Slapi_DN *sdn);
  458. void repl_set_mtn_state_and_referrals(const Slapi_DN *sdn, const char *mtn_state,
  459. const RUV *ruv, char **ruv_referrals,
  460. char **other_referrals);
  461. void repl_set_repl_plugin_path(const char *path);
  462. /* repl5_updatedn_list.c */
  463. typedef void *ReplicaUpdateDNList;
  464. typedef int (*FNEnumDN)(Slapi_DN *dn, void *arg);
  465. ReplicaUpdateDNList replica_updatedn_list_new(const Slapi_Entry *entry);
  466. void replica_updatedn_list_free(ReplicaUpdateDNList list);
  467. void replica_updatedn_list_replace(ReplicaUpdateDNList list, const Slapi_ValueSet *vs);
  468. void replica_updatedn_list_delete(ReplicaUpdateDNList list, const Slapi_ValueSet *vs);
  469. void replica_updatedn_list_add(ReplicaUpdateDNList list, const Slapi_ValueSet *vs);
  470. PRBool replica_updatedn_list_ismember(ReplicaUpdateDNList list, const Slapi_DN *dn);
  471. char *replica_updatedn_list_to_string(ReplicaUpdateDNList list, const char *delimiter);
  472. void replica_updatedn_list_enumerate(ReplicaUpdateDNList list, FNEnumDN fn, void *arg);
  473. /* enabling developper traces for MMR to understand the total/inc protocol state machines */
  474. #ifdef DEV_DEBUG
  475. #define SLAPI_LOG_DEV_DEBUG SLAPI_LOG_FATAL
  476. #define dev_debug(a) slapi_log_error(SLAPI_LOG_DEV_DEBUG, "DEV_DEBUG", "%s\n", a)
  477. #else
  478. #define dev_debug(a)
  479. #endif
  480. void repl5_set_debug_timeout(const char *val);
  481. /* temp hack XXX */
  482. ReplicaId agmt_get_consumerRID(Repl_Agmt *ra);
  483. /* windows_private.c */
  484. typedef struct windowsprivate Dirsync_Private;
  485. void windows_private_delete(Dirsync_Private **dp);
  486. void* get_priv_from_agmt (const Repl_Agmt *agmt);
  487. Dirsync_Private* windows_private_new();
  488. void windows_private_set_windows_replarea (const Repl_Agmt *ra,const Slapi_DN* sdn );
  489. const Slapi_DN* windows_private_get_windows_replarea (const Repl_Agmt *ra);
  490. void windows_private_set_directory_replarea (const Repl_Agmt *ra,const Slapi_DN* sdn );
  491. const Slapi_DN* windows_private_get_directory_replarea (const Repl_Agmt *ra);
  492. LDAPControl* windows_private_dirsync_control(const Repl_Agmt *ra);
  493. ConnResult perform_search(Repl_Connection *conn);
  494. Slapi_Entry *windows_conn_get_search_result(Repl_Connection *conn );
  495. void windows_private_update_dirsync_control(const Repl_Agmt *ra,LDAPControl **controls );
  496. void windows_private_null_dirsync_control(const Repl_Agmt *ra);
  497. void windows_private_set_create_users(const Repl_Agmt *ra, PRBool value);
  498. PRBool windows_private_create_users(const Repl_Agmt *ra);
  499. #endif /* _REPL5_H_ */