repl.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. #ifndef _REPL_H_
  13. #define _REPL_H_
  14. /* Required to get portable printf/scanf format macros */
  15. #ifdef HAVE_INTTYPES_H
  16. #include <inttypes.h>
  17. /* NSPR uses the print macros a bit differently than ANSI C. We
  18. * need to use ll for a 64-bit integer, even when a long is 64-bit.
  19. */
  20. #undef PRIu64
  21. #define PRIu64 "llu"
  22. #undef PRI64
  23. #define PRI64 "ll"
  24. #else
  25. #error Need to define portable format macros such as PRIu64
  26. #endif /* HAVE_INTTYPES_H */
  27. #include <limits.h>
  28. #include <time.h>
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <sys/param.h>
  32. #include "portable.h" /* GGOODREPL - is this cheating? */
  33. #include "ldaplog.h"
  34. #include "repl_shared.h"
  35. #include "cl4.h"
  36. typedef struct schedule_item
  37. {
  38. unsigned long sch_start; /* seconds after midnight */
  39. unsigned long sch_length; /* sec */
  40. unsigned int sch_weekdays; /* bit mask; LSB = Sunday */
  41. struct schedule_item* sch_next;
  42. } schedule_item;
  43. /* XXXggood - copied from slap.h - bad */
  44. /* XXXrichm - copied to match definition in slap.h - 20060406 */
  45. #ifndef NO_TIME
  46. #define NO_TIME (time_t)0 /* cannot be -1, NT's localtime( -1 ) returns NULL */
  47. #endif
  48. /*
  49. * A status message contains a time, the textual message,
  50. * and a count of the number of times the message occured.
  51. */
  52. typedef struct _status_message {
  53. time_t sm_time;
  54. char *sm_message;
  55. int sm_occurances;
  56. } status_message;
  57. /*
  58. * A status_message_list is a circular array of status messages.
  59. * Old messages roll off the end and are discarded.
  60. */
  61. typedef struct _status_message_list {
  62. int sml_size; /* number of slots in array */
  63. int sml_tail; /* next slot to be written */
  64. status_message *sml_messages; /* array of messages */
  65. } sm_list;
  66. #define NUM_REPL_MESSAGES 20 /* max # of messages to save */
  67. /* Selective attribute Inclusion states. ORDERING IS SIGNIFICANT */
  68. #define IMPLICITLY_INCLUDED 1
  69. #define IMPLICITLY_EXCLUDED 2
  70. #define EXPLICITLY_EXCLUDED 3
  71. #define EXPLICITLY_INCLUDED 4
  72. #if defined(__JCMREPL_FILTER__)
  73. /*
  74. * Structure used to implement selective attribute filtering.
  75. * sa_filter nodes are arranged in a linked list.
  76. */
  77. typedef struct _sa_filter {
  78. Slapi_Filter *sa_filter; /* Filter to apply */
  79. int sa_isexclude; /* non-zero if list is exclude list */
  80. char **sa_attrlist; /* array - attrs to replicate */
  81. struct _sa_filter *sa_next; /* Link to next struct */
  82. } sa_filter;
  83. #endif
  84. typedef unsigned long changeNumber;
  85. #define a2changeNumber( a ) strtoul(( a ), (char **)NULL, 10 )
  86. #define AUTH_SIMPLE 1
  87. #define AUTH_KERBEROS 2
  88. typedef struct modinfo {
  89. char *type;
  90. char *value;
  91. int len;
  92. } modinfo;
  93. /*
  94. * Representation of one change entry from the replog file.
  95. */
  96. typedef struct repl {
  97. char *time; /* time of modification */
  98. changeNumber change; /* number of this change */
  99. char *dn; /* dn of entry being modified - normalized */
  100. char *raw_dn; /* dn of entry - not normalized */
  101. int changetype; /* type of change */
  102. modinfo *mods; /* modifications to make */
  103. char *newrdn; /* new rdn for modrdn */
  104. int deleteoldrdn; /* flag for modrdn */
  105. } repl;
  106. #define BIND_OK 0
  107. #define BIND_ERR_BADLDP 1
  108. #define BIND_ERR_OPEN 2
  109. #define BIND_ERR_BAD_ATYPE 3
  110. #define BIND_ERR_SIMPLE_FAILED 4
  111. #define BIND_ERR_KERBEROS_FAILED 5
  112. #define BIND_ERR_SSL_INIT_FAILED 6
  113. #define BIND_ERR_RACE 7
  114. #define MAX_CHANGENUMBER ULONG_MAX
  115. #define REPLICATION_SUBSYSTEM "replication"
  116. #define REPL_LDAP_TIMEOUT 30L /* Wait 30 seconds for responses */
  117. /* Update the copiedFrom attribute every <n> updates */
  118. #define UPDATE_COPIEDFROM_INTERVAL 10
  119. #define REPL_ERROR_REPL_HALTED "REPLICATION HALTED"
  120. #define ATTR_NETSCAPEMDSUFFIX "netscapemdsuffix"
  121. #define CONFIG_LEGACY_REPLICATIONDN_ATTRIBUTE "nsslapd-legacy-updatedn"
  122. #define CONFIG_LEGACY_REPLICATIONPW_ATTRIBUTE "nsslapd-legacy-updatepw"
  123. #define LDAP_CONTROL_REPL_MODRDN_EXTRAMODS "2.16.840.1.113730.3.4.999"
  124. /* Operation types */
  125. #define OP_MODIFY 1
  126. #define OP_ADD 2
  127. #define OP_DELETE 3
  128. #define OP_MODDN 4
  129. #define OP_SEARCH 5
  130. #define OP_COMPARE 6
  131. /* 4.0-style housekeeping interval */
  132. #define REPLICATION_HOUSEKEEPING_INTERVAL (30 * 1000) /* 30 seconds */
  133. /* Top of tree for replication configuration information */
  134. #define REPL_CONFIG_TOP "cn=replication,cn=config"
  135. /* Functions */
  136. /* repl_rootdse.c */
  137. int repl_rootdse_init();
  138. /* In repl.c */
  139. Slapi_Entry *get_changerecord(const chglog4Info *cl4, changeNumber cnum, int *err);
  140. changeNumber replog_get_firstchangenum(const chglog4Info *cl4, int *err);
  141. changeNumber replog_get_lastchangenum(const chglog4Info *cl4, int *err);
  142. void changelog_housekeeping(time_t cur_time );
  143. /* In repl_config.c */
  144. int repl_config_init ();
  145. /* Legacy Plugin Functions */
  146. int legacy_preop_bind( Slapi_PBlock *pb );
  147. int legacy_bepreop_bind( Slapi_PBlock *pb );
  148. int legacy_postop_bind( Slapi_PBlock *pb );
  149. int legacy_preop_add( Slapi_PBlock *pb );
  150. int legacy_bepreop_add( Slapi_PBlock *pb );
  151. int legacy_postop_add( Slapi_PBlock *pb );
  152. int legacy_preop_modify( Slapi_PBlock *pb );
  153. int legacy_bepreop_modify( Slapi_PBlock *pb );
  154. int legacy_postop_modify( Slapi_PBlock *pb );
  155. int legacy_preop_modrdn( Slapi_PBlock *pb );
  156. int legacy_bepreop_modrdn( Slapi_PBlock *pb );
  157. int legacy_postop_modrdn( Slapi_PBlock *pb );
  158. int legacy_preop_delete( Slapi_PBlock *pb );
  159. int legacy_bepreop_delete( Slapi_PBlock *pb );
  160. int legacy_postop_delete( Slapi_PBlock *pb );
  161. int legacy_preop_search( Slapi_PBlock *pb );
  162. int legacy_preop_compare( Slapi_PBlock *pb );
  163. int legacy_pre_entry( Slapi_PBlock *pb );
  164. int legacy_bepostop_assignchangenum( Slapi_PBlock *pb );
  165. int replication_plugin_start( Slapi_PBlock *pb );
  166. int replication_plugin_poststart( Slapi_PBlock *pb );
  167. int replication_plugin_stop( Slapi_PBlock *pb );
  168. /* In repl.c */
  169. void replog( Slapi_PBlock *pb, int optype );
  170. void init_changelog_trimming( changeNumber max_changes, time_t max_age );
  171. /* From repl_globals.c */
  172. extern char *attr_changenumber;
  173. extern char *attr_targetdn;
  174. extern char *attr_changetype;
  175. extern char *attr_newrdn;
  176. extern char *attr_deleteoldrdn;
  177. extern char *attr_changes;
  178. extern char *attr_newsuperior;
  179. extern char *attr_changetime;
  180. extern char *attr_dataversion;
  181. extern char *attr_csn;
  182. extern char *changetype_add;
  183. extern char *changetype_delete;
  184. extern char *changetype_modify;
  185. extern char *changetype_modrdn;
  186. extern char *changetype_moddn;
  187. extern char *type_copyingFrom;
  188. extern char *type_copiedFrom;
  189. extern char *filter_copyingFrom;
  190. extern char *filter_copiedFrom;
  191. extern char *filter_objectclass;
  192. extern char *type_cn;
  193. extern char *type_objectclass;
  194. /* JCMREPL - IFP should be defined centrally */
  195. #ifndef _IFP
  196. #define _IFP
  197. typedef int (*IFP)();
  198. #endif
  199. /* In cl4.c */
  200. changeNumber ldapi_assign_changenumber(chglog4Info *cl4);
  201. changeNumber ldapi_get_last_changenumber(chglog4Info *cl4);
  202. changeNumber ldapi_get_first_changenumber(chglog4Info *cl4);
  203. void ldapi_commit_changenumber(chglog4Info *cl4, changeNumber cnum);
  204. void ldapi_set_first_changenumber(chglog4Info *cl4, changeNumber cnum);
  205. void ldapi_set_last_changenumber(chglog4Info *cl4, changeNumber cnum);
  206. void ldapi_initialize_changenumbers(chglog4Info *cl4, changeNumber first, changeNumber last);
  207. #define LDBM_TYPE "ldbm"
  208. #define CHANGELOG_LDBM_TYPE "changelog-ldbm"
  209. #define MAX_RETRY_INTERVAL 3600 /* sec = 1 hour */
  210. #define REPL_PROTOCOL_UNKNOWN 0
  211. #define REPL_PROTOCOL_40 1
  212. #define REPL_PROTOCOL_50_INCREMENTAL 2
  213. #define REPL_PROTOCOL_50_TOTALUPDATE 3
  214. /* TEL 20120529: REPL_PROTOCOL_71_TOTALUPDATE is never used in the code, and the
  215. * equivalent code checking the 7.1 OID for incremental updates assigns the
  216. * protocol version as REPL_PROTOCOL_50_INCREMENTAL. One or the other of these
  217. * is wrong, but there are many tests for REPL_PROTOCOL_50_TOTALUPDATE that would
  218. * need to be rewritten to to make use of REPL_PROTOCOL_71_TOTALUPDATE, so it
  219. * seems safer and simpler to take this definition out. */
  220. /* #define REPL_PROTOCOL_71_TOTALUPDATE 4 */
  221. /* In repl_globals.c */
  222. int decrement_repl_active_threads();
  223. int increment_repl_active_threads();
  224. /* operation extensions */
  225. /* Type of extensions that can be registered */
  226. typedef enum
  227. {
  228. REPL_SUP_EXT_OP, /* extension for Operation object, replication supplier */
  229. REPL_SUP_EXT_CONN, /* extension for Connection object, replication supplier */
  230. REPL_CON_EXT_OP, /* extension for Operation object, replication consumer */
  231. REPL_CON_EXT_CONN, /* extension for Connection object, replication consumer */
  232. REPL_CON_EXT_MTNODE,/* extension for mapping_tree_node object, replication consumer */
  233. REPL_EXT_ALL
  234. } ext_type;
  235. /* general extension functions - repl_ext.c */
  236. void repl_sup_init_ext (); /* initializes registrations - must be called first */
  237. void repl_con_init_ext (); /* initializes registrations - must be called first */
  238. int repl_sup_register_ext (ext_type type); /* registers an extension of the specified type */
  239. int repl_con_register_ext (ext_type type); /* registers an extension of the specified type */
  240. void* repl_sup_get_ext (ext_type type, void *object); /* retireves the extension from the object */
  241. void* repl_con_get_ext (ext_type type, void *object); /* retireves the extension from the object */
  242. /* Operation extension functions - supplier_operation_extension.c */
  243. /* --- supplier operation extension --- */
  244. typedef struct supplier_operation_extension
  245. {
  246. int prevent_recursive_call;
  247. struct slapi_operation_parameters *operation_parameters;
  248. char *repl_gen;
  249. } supplier_operation_extension;
  250. /* extension construct/destructor */
  251. void* supplier_operation_extension_constructor (void *object, void *parent);
  252. void supplier_operation_extension_destructor (void* ext,void *object, void *parent);
  253. /* --- consumer operation extension --- */
  254. typedef struct consumer_operation_extension
  255. {
  256. int has_cf; /* non-zero if the operation contains a copiedFrom/copyingFrom attr */
  257. void *search_referrals;
  258. } consumer_operation_extension;
  259. /* extension construct/destructor */
  260. void* consumer_operation_extension_constructor (void *object, void *parent);
  261. void consumer_operation_extension_destructor (void* ext,void *object, void *parent);
  262. /* Connection extension functions - repl_connext.c */
  263. /* --- connection extension --- */
  264. /* ONREPL - some pointers are void* because they represent 5.0 data structures
  265. not known in this header. Fix */
  266. typedef struct consumer_connection_extension
  267. {
  268. int is_legacy_replication_dn;
  269. int repl_protocol_version; /* the replication protocol version number the supplier is talking. */
  270. void *replica_acquired; /* Object* for replica */
  271. void *supplier_ruv; /* RUV* */
  272. int isreplicationsession;
  273. Slapi_Connection *connection;
  274. PRLock *lock; /* protects entire structure */
  275. int in_use_opid; /* the id of the operation actively using this, else -1 */
  276. } consumer_connection_extension;
  277. /* extension construct/destructor */
  278. void* consumer_connection_extension_constructor (void *object,void *parent);
  279. void consumer_connection_extension_destructor (void* ext,void *object,void *parent);
  280. /* extension helpers for managing exclusive access */
  281. consumer_connection_extension* consumer_connection_extension_acquire_exclusive_access(void* conn, PRUint64 connid, int opid);
  282. int consumer_connection_extension_relinquish_exclusive_access(void* conn, PRUint64 connid, int opid, PRBool force);
  283. /* mapping tree extension - stores replica object */
  284. typedef struct multimaster_mtnode_extension
  285. {
  286. Object *replica;
  287. } multimaster_mtnode_extension;
  288. void* multimaster_mtnode_extension_constructor (void *object,void *parent);
  289. void multimaster_mtnode_extension_destructor (void* ext,void *object,void *parent);
  290. /* In repl_init.c */
  291. int get_legacy_stop();
  292. /* In repl_entry.c */
  293. void repl_entry_init(int argc, char** argv);
  294. /* In repl_ops.c */
  295. int legacy_preop( Slapi_PBlock *pb, const char* caller, int operation_type);
  296. int legacy_postop( Slapi_PBlock *pb, const char* caller, int operation_type);
  297. /* In profile.c */
  298. #ifdef PROFILE
  299. #define PROFILE_POINT if (CFG_profile) profile_log(__FILE__,__LINE__) /* JCMREPL - Where is the profiling flag stored? */
  300. #else
  301. #define PROFILE_POINT ((void)0)
  302. #endif
  303. void profile_log(char *file,int line);
  304. void profile_open();
  305. void profile_close();
  306. /* in repl_controls.c */
  307. void add_repl_control_mods( Slapi_PBlock *pb, Slapi_Mods *smods );
  308. /* ... */
  309. void create_entity (char* DN, const char* oclass);
  310. void write_replog_db( int optype, char *dn, void *change, int flag, changeNumber changenum, time_t curtime, LDAPMod **modrdn_mods );
  311. int entry2reple( Slapi_Entry *e, Slapi_Entry *oe );
  312. int mods2reple( Slapi_Entry *e, LDAPMod **ldm );
  313. int modrdn2reple( Slapi_Entry *e, char *newrdn, int deloldrdn, LDAPMod **ldm );
  314. /* In legacy_consumer.c */
  315. void process_legacy_cf(Slapi_PBlock *pb);
  316. int legacy_consumer_is_replicationdn(const char *dn);
  317. int legacy_consumer_is_replicationpw(struct berval *creds);
  318. int legacy_consumer_config_init();
  319. /* function that gets called when a backend state is changed */
  320. void legacy_consumer_be_state_change (void *handle, char *be_name,
  321. int old_be_state, int new_be_state);
  322. #endif /* _REPL_H_ */