repl.h 13 KB

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