repl.h 14 KB

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