repl5.h 27 KB

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