repl.h 14 KB

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