repl.h 15 KB

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