slapi-private.h 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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. /* slapi-private.h - external header file for some special plugins */
  13. #ifndef _SLAPISTATE
  14. #define _SLAPISTATE
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <time.h> /* for time_t */
  19. #include "nspr.h"
  20. #include "slapi-plugin.h"
  21. /*
  22. * XXXmcs: we can stop including slapi-plugin-compat4.h once we stop using
  23. * deprecated functions internally.
  24. */
  25. #include "slapi-plugin-compat4.h"
  26. /*
  27. * server shutdown status
  28. */
  29. #define SLAPI_SHUTDOWN_SIGNAL 1
  30. #define SLAPI_SHUTDOWN_DISKFULL 2
  31. #define SLAPI_SHUTDOWN_EXIT 3
  32. /* filter */
  33. #define SLAPI_FILTER_LDAPSUBENTRY 1
  34. #define SLAPI_FILTER_TOMBSTONE 2
  35. #define SLAPI_FILTER_RUV 4
  36. #define SLAPI_ENTRY_LDAPSUBENTRY 2
  37. #define SLAPI_FILTER_NORMALIZED_TYPE 8
  38. #define SLAPI_FILTER_NORMALIZED_VALUE 16
  39. /*
  40. Optimized filter path. For example the following code was lifted from int.c (syntaxes plugin):
  41. if(ftype == LDAP_FILTER_EQUALITY_FAST) {
  42. tmp=(char *)slapi_ch_calloc(1,(sizeof(Slapi_Value)+sizeof(struct berval)+len+1));
  43. tmpval=(Slapi_Value *)tmp;
  44. tmpbv=(struct berval *)(tmp + sizeof(Slapi_Value));
  45. tmpbv->bv_val=(char *)tmp + sizeof(Slapi_Value) + (sizeof(struct berval));
  46. tmpbv->bv_len=len;
  47. tmpval->bvp=tmpbv;
  48. b = (unsigned char *)&num;
  49. memcpy(tmpbv->bv_val,b,len);
  50. (*ivals)=(Slapi_Value **)tmpval;
  51. }
  52. The following diagram helps explain the strategy.
  53. +---------------------------------------------------------------+
  54. | Single contiguous allocated block |
  55. +------------------------+------------------------+-------------+
  56. | Slapi_Value | struct berval | octetstring |
  57. +----------------+-------+------------------------+-------------+
  58. | struct berval* | ... | ... | char *bv_val | <value> |
  59. | v | | | v | |
  60. +-------+--------+-------+---------+------+-------+-------------+
  61. | ^ | ^
  62. |_________________| |________|
  63. The goal is to malloc one large chunk of memory up front and then manipulate the pointers to point
  64. into this chunk. We then can free the whole block at once by calling a single slapi_ch_free (see filterindex.c).
  65. */
  66. #define LDAP_FILTER_EQUALITY_FAST 0xaaL
  67. /*
  68. * Slapi_Mods and Slapi_Mod base structures.
  69. * Ideally, these would be moved to modutil.c and the structures would be
  70. * completely opaque to users of the slapi_mods_...() API. But today some
  71. * plugins such as replication use these directly for efficiency reasons.
  72. */
  73. typedef struct slapi_mods
  74. {
  75. LDAPMod **mods;
  76. int num_elements;
  77. int num_mods;
  78. int iterator;
  79. int free_mods; /* flag to indicate that the mods were dynamically allocated and needs to be freed */
  80. }slapi_mods;
  81. typedef struct slapi_mod
  82. {
  83. LDAPMod *mod;
  84. int num_elements;
  85. int num_values;
  86. int iterator;
  87. int free_mod; /* flag to inidicate that the mod was dynamically allocated and needs to be freed */
  88. }slapi_mod;
  89. void slapi_ch_free_ref(void *ptr);
  90. /*
  91. * file I/O
  92. */
  93. PRInt32 slapi_read_buffer( PRFileDesc *fd, void *buf, PRInt32 amount );
  94. PRInt32 slapi_write_buffer( PRFileDesc *fd, void *buf, PRInt32 amount );
  95. /* rename a file, overwriting the destfilename if it exists */
  96. int slapi_destructive_rename( const char *srcfilename,
  97. const char *destfilename );
  98. /* make a copy of a file */
  99. int slapi_copy( const char *srcfilename, const char *destfile );
  100. /* CSN */
  101. typedef struct csn CSN;
  102. typedef unsigned char CSNType;
  103. typedef struct csnset_node CSNSet;
  104. #define _CSN_TSTAMP_STRSIZE 8
  105. #define _CSN_SEQNUM_STRSIZE 4
  106. #define _CSN_REPLID_STRSIZE 4
  107. #define _CSN_SUBSEQNUM_STRSIZE 4
  108. #define _CSN_VALIDCSN_STRLEN (_CSN_TSTAMP_STRSIZE + _CSN_SEQNUM_STRSIZE + \
  109. _CSN_REPLID_STRSIZE + _CSN_SUBSEQNUM_STRSIZE)
  110. #define CSN_STRSIZE (_CSN_VALIDCSN_STRLEN + 1)
  111. #define CSN_TYPE_UNKNOWN 0x00
  112. #define CSN_TYPE_NONE 0x01
  113. #define CSN_TYPE_ATTRIBUTE_DELETED 0x03
  114. #define CSN_TYPE_VALUE_UPDATED 0x04
  115. #define CSN_TYPE_VALUE_DELETED 0x05
  116. #define CSN_TYPE_VALUE_DISTINGUISHED 0x06
  117. #define VALUE_NOTFOUND 1
  118. #define VALUE_PRESENT 2
  119. #define VALUE_DELETED 3
  120. #define ATTRIBUTE_NOTFOUND 1
  121. #define ATTRIBUTE_PRESENT 2
  122. #define ATTRIBUTE_DELETED 3
  123. /*
  124. * csn.c
  125. */
  126. typedef PRUint16 ReplicaId;
  127. /* max 2 byte unsigned int value */
  128. #define MAX_REPLICA_ID 65535
  129. /* we will use this value for the replica ID of read only replicas */
  130. #define READ_ONLY_REPLICA_ID MAX_REPLICA_ID
  131. CSN *csn_new();
  132. CSN *csn_new_by_string(const char *s);
  133. void csn_init_by_csn(CSN *csn1,const CSN *csn2);
  134. void csn_init_by_string(CSN *csn, const char *s);
  135. void csn_init(CSN *csn);
  136. CSN *csn_dup(const CSN *csn);
  137. void csn_free(CSN **csn);
  138. void csn_set_replicaid(CSN *csn, ReplicaId rid);
  139. void csn_set_time(CSN *csn, time_t csntime);
  140. void csn_set_seqnum(CSN *csn, PRUint16 seqnum);
  141. ReplicaId csn_get_replicaid(const CSN *csn);
  142. time_t csn_get_time(const CSN *csn);
  143. PRUint16 csn_get_seqnum(const CSN *csn);
  144. PRUint16 csn_get_subseqnum(const CSN *csn);
  145. char *csn_as_string(const CSN *csn, PRBool replicaIdOrder, char *ss); /* WARNING: ss must be CSN_STRSIZE bytes, or NULL. */
  146. int csn_compare(const CSN *csn1, const CSN *csn2);
  147. int csn_compare_ext(const CSN *csn1, const CSN *csn2, unsigned int flags);
  148. #define CSN_COMPARE_SKIP_SUBSEQ 0x1
  149. time_t csn_time_difference(const CSN *csn1, const CSN *csn2);
  150. size_t csn_string_size();
  151. char *csn_as_attr_option_string(CSNType t,const CSN *csn,char *ss);
  152. const CSN *csn_max(const CSN *csn1,const CSN *csn2);
  153. /* this function allows to expand a csn into a set of csns.
  154. The sequence is derived by adding a sequence number to the base csn
  155. passed to it. This is useful when a single client operation needs to be
  156. expanded into multiple operations. For instance, subtree move operation
  157. is split into a sequence of adds and deletes with each add and delete assigned
  158. a csn from the set.*/
  159. int csn_increment_subsequence (CSN *csn);
  160. /*
  161. * csnset.c
  162. */
  163. void csnset_add_csn(CSNSet **csnset, CSNType t, const CSN *csn);
  164. void csnset_insert_csn(CSNSet **csnset, CSNType t, const CSN *csn);
  165. void csnset_update_csn(CSNSet **csnset, CSNType t, const CSN *csn);
  166. void csnset_free(CSNSet **csnset);
  167. const CSN *csnset_get_csn_of_type(const CSNSet *csnset, CSNType t);
  168. void csnset_purge(CSNSet **csnset, const CSN *csnUpTo);
  169. size_t csnset_string_size(CSNSet *csnset);
  170. size_t csnset_size(CSNSet *csnset);
  171. CSNSet *csnset_dup(const CSNSet *csnset);
  172. void csnset_as_string(const CSNSet *csnset,char *s);
  173. void csnset_remove_csn(CSNSet **csnset, CSNType t);
  174. const CSN *csnset_get_last_csn(const CSNSet *csnset);
  175. int csnset_contains(const CSNSet *csnset, const CSN *csn);
  176. const CSN *csnset_get_previous_csn(const CSNSet *csnset, const CSN *csn);
  177. void* csnset_get_first_csn (const CSNSet *csnset, CSN **csn, CSNType *t);
  178. void* csnset_get_next_csn (const CSNSet *csnset, void *cookie, CSN **csn, CSNType *t);
  179. /*
  180. * csngen.c
  181. */
  182. /* error codes returned from CSN generation routines */
  183. enum {
  184. CSN_SUCCESS = 0,
  185. CSN_MEMORY_ERROR, /* memory allocation failed */
  186. CSN_LIMIT_EXCEEDED, /* timestamp is way out of sync */
  187. CSN_INVALID_PARAMETER, /* invalid function argument */
  188. CSN_INVALID_FORMAT, /* invalid state format */
  189. CSN_LDAP_ERROR, /* LDAP operation failed */
  190. CSN_NSPR_ERROR /* NSPR API failure */
  191. };
  192. typedef struct csngen CSNGen;
  193. /* allocates new csn generator */
  194. CSNGen *csngen_new (ReplicaId rid, Slapi_Attr *state);
  195. /* frees csn generator data structure */
  196. void csngen_free (CSNGen **gen);
  197. /* generates new csn. If notify is non-zero, the generator calls
  198. "generate" functions registered through csngen_register_callbacks call */
  199. int csngen_new_csn (CSNGen *gen, CSN **csn, PRBool notify);
  200. /* this function should be called for csns generated with non-zero notify
  201. that were unused because the corresponding operation was aborted.
  202. The function calls "abort" functions registered through
  203. csngen_register_callbacks call */
  204. void csngen_abort_csn (CSNGen *gen, const CSN *csn);
  205. /* this function should be called when a remote CSN for the same part of
  206. the dit becomes known to the server (for instance, as part of RUV during
  207. replication session. In response, the generator would adjust its notion
  208. of time so that it does not generate smaller csns */
  209. int csngen_adjust_time (CSNGen *gen, const CSN* csn);
  210. /* returns PR_TRUE if the csn was generated by this generator and
  211. PR_FALSE otherwise. */
  212. void csngen_rewrite_rid(CSNGen *gen, ReplicaId rid);
  213. PRBool csngen_is_local_csn(const CSNGen *gen, const CSN *csn);
  214. /* returns current state of the generator so that it can be saved in the DIT */
  215. int csngen_get_state (const CSNGen *gen, Slapi_Mod *state);
  216. typedef void (*GenCSNFn)(const CSN *newCsn, void *cbData);
  217. typedef void (*AbortCSNFn)(const CSN *delCsn, void *cbData);
  218. /* registers callbacks to be called when csn is created or aborted */
  219. void* csngen_register_callbacks(CSNGen *gen, GenCSNFn genFn, void *genArg,
  220. AbortCSNFn abortFn, void *abortArg);
  221. /* unregisters callbacks registered via call to csngenRegisterCallbacks */
  222. void csngen_unregister_callbacks(CSNGen *gen, void *cookie);
  223. /* this functions is periodically called from daemon.c to
  224. update time used by all generators */
  225. void csngen_update_time ();
  226. /* debugging function */
  227. void csngen_dump_state (const CSNGen *gen);
  228. /* this function tests csn generator */
  229. void csngen_test ();
  230. /*
  231. * State storage management routines
  232. *
  233. *
  234. */
  235. /*
  236. * attr_value_find_wsi looks for a particular value (rather, the berval
  237. * part of the slapi_value v) and returns it in "value". The function
  238. * returns VALUE_PRESENT, VALUE_DELETED, or VALUE_NOTFOUND.
  239. */
  240. int attr_value_find_wsi(Slapi_Attr *a, const struct berval *bval, Slapi_Value **value);
  241. /*
  242. * entry_attr_find_wsi takes an entry and a type and looks for the
  243. * attribute. If the attribute is found on the list of existing attributes,
  244. * it is returned in "a" and the function returns ATTRIBUTE_PRESENT. If the attribute is
  245. * found on the deleted list, "a" is set and the function returns ATTRIBUTE_DELETED.
  246. * If the attribute is not found on either list, the function returns ATTRIBUTE_NOTFOUND.
  247. */
  248. int entry_attr_find_wsi(Slapi_Entry *e, const char *type, Slapi_Attr **a);
  249. /*
  250. * entry_add_present_attribute_wsi adds an attribute to the entry.
  251. */
  252. int entry_add_present_attribute_wsi(Slapi_Entry *e, Slapi_Attr *a);
  253. /*
  254. * entry_add_deleted_attribute_wsi adds a deleted attribute to the entry.
  255. */
  256. int entry_add_deleted_attribute_wsi(Slapi_Entry *e, Slapi_Attr *a);
  257. /*
  258. * entry_apply_mods_wsi is similar to entry_apply_mods. It also
  259. * handles the state storage information. "csn" is the CSN associated with
  260. * this modify operation.
  261. */
  262. int entry_apply_mods_wsi(Slapi_Entry *e, Slapi_Mods *smods, const CSN *csn, int urp);
  263. int entry_first_deleted_attribute( const Slapi_Entry *e, Slapi_Attr **a);
  264. int entry_next_deleted_attribute( const Slapi_Entry *e, Slapi_Attr **a);
  265. /* entry.c */
  266. int entry_apply_mods( Slapi_Entry *e, LDAPMod **mods );
  267. int is_type_protected(const char *type);
  268. int entry_apply_mods_ignore_error( Slapi_Entry *e, LDAPMod **mods, int ignore_error );
  269. int slapi_entries_diff(Slapi_Entry **old_entries, Slapi_Entry **new_entries, int testall, const char *logging_prestr, const int force_update, void *plg_id);
  270. void set_attr_to_protected_list(char *attr, int flag);
  271. /* entrywsi.c */
  272. CSN* entry_assign_operation_csn ( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *parententry );
  273. const CSN *entry_get_maxcsn ( const Slapi_Entry *entry );
  274. void entry_set_maxcsn ( Slapi_Entry *entry, const CSN *csn );
  275. const CSN *entry_get_dncsn(const Slapi_Entry *entry);
  276. const CSNSet *entry_get_dncsnset(const Slapi_Entry *entry);
  277. int entry_add_dncsn(Slapi_Entry *entry, const CSN *csn);
  278. int entry_set_csn(Slapi_Entry *entry, const CSN *csn);
  279. void entry_purge_state_information(Slapi_Entry *entry, const CSN *csnUpto);
  280. void entry_add_rdn_csn(Slapi_Entry *e, const CSN *csn);
  281. /* this adds a csn to the entry's e_dncsnset but makes sure the set is in increasing csn order */
  282. #define ENTRY_DNCSN_INCREASING 0x1 /* for flags below */
  283. int entry_add_dncsn_ext(Slapi_Entry *entry, const CSN *csn, PRUint32 flags);
  284. const CSN *entry_get_deletion_csn(Slapi_Entry *entry);
  285. /* attr.c */
  286. Slapi_Attr *slapi_attr_init_locking_optional(Slapi_Attr *a, const char *type, PRBool use_lock);
  287. Slapi_Attr *slapi_attr_init_nosyntax(Slapi_Attr *a, const char *type);
  288. int slapi_attr_init_syntax(Slapi_Attr *a);
  289. int attr_set_csn( Slapi_Attr *a, const CSN *csn);
  290. int attr_set_deletion_csn( Slapi_Attr *a, const CSN *csn);
  291. const CSN *attr_get_deletion_csn(const Slapi_Attr *a);
  292. int attr_first_deleted_value( Slapi_Attr *a, Slapi_Value **v );
  293. int attr_next_deleted_value( Slapi_Attr *a, int hint, Slapi_Value **v);
  294. void attr_purge_state_information(Slapi_Entry *entry, Slapi_Attr *attr, const CSN *csnUpto);
  295. Slapi_Value **attr_get_present_values(const Slapi_Attr *a);
  296. int attr_add_deleted_value(Slapi_Attr *a, const Slapi_Value *v);
  297. /* value.c */
  298. Slapi_Value *value_new(const struct berval *bval, CSNType t, const CSN *csn);
  299. Slapi_Value *value_init(Slapi_Value *v, const struct berval *bval, CSNType t, const CSN *csn);
  300. void value_done(Slapi_Value *v);
  301. Slapi_Value *value_update_csn( Slapi_Value *value, CSNType t, const CSN *csn);
  302. Slapi_Value *value_add_csn( Slapi_Value *value, CSNType t, const CSN *csn);
  303. const CSN *value_get_csn( const Slapi_Value *value, CSNType t );
  304. const CSNSet *value_get_csnset ( const Slapi_Value *value);
  305. Slapi_Value *value_remove_csn( Slapi_Value *value, CSNType t);
  306. int value_contains_csn( const Slapi_Value *value, CSN *csn);
  307. int value_dn_normalize_value(Slapi_Value *value);
  308. /* dn.c */
  309. /* this functions should only be used for dns allocated on the stack */
  310. Slapi_DN *slapi_sdn_init(Slapi_DN *sdn);
  311. Slapi_DN *slapi_sdn_init_dn_byref(Slapi_DN *sdn,const char *dn);
  312. Slapi_DN *slapi_sdn_init_dn_byval(Slapi_DN *sdn,const char *dn);
  313. Slapi_DN *slapi_sdn_init_dn_passin(Slapi_DN *sdn,const char *dn);
  314. Slapi_DN *slapi_sdn_init_ndn_byref(Slapi_DN *sdn,const char *dn);
  315. Slapi_DN *slapi_sdn_init_ndn_byval(Slapi_DN *sdn,const char *dn);
  316. Slapi_DN *slapi_sdn_init_normdn_byref(Slapi_DN *sdn, const char *dn);
  317. Slapi_DN *slapi_sdn_init_normdn_byval(Slapi_DN *sdn, const char *dn);
  318. Slapi_DN *slapi_sdn_init_normdn_ndn_passin(Slapi_DN *sdn, const char *dn);
  319. Slapi_DN *slapi_sdn_init_normdn_passin(Slapi_DN *sdn, const char *dn);
  320. char *slapi_dn_normalize_original( char *dn );
  321. char *slapi_dn_normalize_case_original( char *dn );
  322. void ndn_cache_init();
  323. void ndn_cache_destroy();
  324. int ndn_cache_started();
  325. void ndn_cache_get_stats(PRUint64 *hits, PRUint64 *tries, size_t *size, size_t *max_size, long *count);
  326. #define NDN_DEFAULT_SIZE 20971520 /* 20mb - size of normalized dn cache */
  327. /* filter.c */
  328. int filter_flag_is_set(const Slapi_Filter *f,unsigned char flag);
  329. char *slapi_filter_to_string(const Slapi_Filter *f, char *buffer, size_t bufsize);
  330. char *slapi_filter_to_string_internal( const struct slapi_filter *f, char *buf, size_t *bufsize );
  331. /* operation.c */
  332. #define OP_FLAG_PS 0x000001
  333. #define OP_FLAG_PS_CHANGESONLY 0x000002
  334. #define OP_FLAG_GET_EFFECTIVE_RIGHTS 0x000004
  335. #define OP_FLAG_REPLICATED 0x000008 /* A Replicated Operation */
  336. #define OP_FLAG_REPL_FIXUP 0x000010 /* A Fixup Operation,
  337. * generated as a consequence
  338. * of a Replicated Operation.
  339. */
  340. #define OP_FLAG_INTERNAL SLAPI_OP_FLAG_INTERNAL /* 0x000020 */
  341. #define OP_FLAG_ACTION_LOG_ACCESS 0x000040
  342. #define OP_FLAG_ACTION_LOG_AUDIT 0x000080
  343. #define OP_FLAG_ACTION_SCHEMA_CHECK 0x000100
  344. #define OP_FLAG_ACTION_LOG_CHANGES 0x000200
  345. #define OP_FLAG_ACTION_INVOKE_FOR_REPLOP 0x000400
  346. #define OP_FLAG_NEVER_CHAIN SLAPI_OP_FLAG_NEVER_CHAIN /* 0x000800 */
  347. #define OP_FLAG_TOMBSTONE_ENTRY SLAPI_OP_FLAG_TOMBSTONE_ENTRY /* 0x001000 */
  348. #define OP_FLAG_RESURECT_ENTRY 0x002000
  349. #define OP_FLAG_LEGACY_REPLICATION_DN 0x004000 /* Operation done by legacy
  350. * replication DN
  351. */
  352. #define OP_FLAG_ACTION_NOLOG 0x008000 /* Do not log the entry in
  353. * audit log or change log
  354. */
  355. #define OP_FLAG_SKIP_MODIFIED_ATTRS 0x010000 /* Do not update the
  356. * modifiersname,
  357. * modifiedtimestamp, etc.
  358. * attributes
  359. */
  360. #define OP_FLAG_REPL_RUV 0x020000 /* Flag to tell to the backend
  361. * that the entry to be added/
  362. * modified is RUV. This info
  363. * is used to skip VLV op.
  364. * (see #329951)
  365. */
  366. #define OP_FLAG_PAGED_RESULTS 0x040000 /* simple paged results */
  367. #define OP_FLAG_SERVER_SIDE_SORTING 0x080000 /* server side sorting */
  368. #define OP_FLAG_REVERSE_CANDIDATE_ORDER 0x100000 /* reverse the search candidate list */
  369. #define OP_FLAG_NEVER_CACHE 0x200000 /* never keep the entry in cache */
  370. #define OP_FLAG_TOMBSTONE_FIXUP 0x400000 /* operation is tombstone fixup op */
  371. #define OP_FLAG_BULK_IMPORT 0x800000 /* operation is bulk import */
  372. /* reverse search states */
  373. #define REV_STARTED 1
  374. #define LAST_REV_ENTRY 2
  375. CSN *operation_get_csn(Slapi_Operation *op);
  376. void operation_set_csn(Slapi_Operation *op,CSN *csn);
  377. void operation_set_flag(Slapi_Operation *op,int flag);
  378. void operation_clear_flag(Slapi_Operation *op,int flag);
  379. int operation_is_flag_set(Slapi_Operation *op,int flag);
  380. unsigned long operation_get_type(Slapi_Operation *op);
  381. LDAPMod **copy_mods(LDAPMod **orig_mods);
  382. /*
  383. * From ldap.h
  384. * #define LDAP_MOD_ADD 0x00
  385. * #define LDAP_MOD_DELETE 0x01
  386. * #define LDAP_MOD_REPLACE 0x02
  387. * #define LDAP_MOD_INCREMENT 0x03 -- Openldap extension
  388. * #define LDAP_MOD_BVALUES 0x80
  389. */
  390. #define LDAP_MOD_IGNORE 0x100
  391. /* dl.c */
  392. typedef struct datalist DataList;
  393. typedef int (*CMPFN) (const void *el1, const void *el2);
  394. typedef void (*FREEFN) (void **);
  395. DataList* dl_new ();
  396. void dl_free (DataList **dl);
  397. void dl_init (DataList *dl, int init_alloc);
  398. void dl_cleanup (DataList *dl, FREEFN freefn);
  399. void dl_add (DataList *dl, void *element);
  400. void dl_add_index(DataList *dl, void *element, int index);
  401. void *dl_replace(const DataList *dl, const void *elementOld, void *elementNew, CMPFN cmpfn, FREEFN freefn);
  402. void *dl_get_first (const DataList *dl, int *cookie);
  403. void *dl_get_next (const DataList *dl, int *cookie);
  404. void *dl_get_prev (const DataList *dl, int *cookie);
  405. void *dl_get (const DataList *dl, const void *element, CMPFN cmpfn);
  406. void *dl_delete (DataList *dl, const void *element, CMPFN cmpfn, FREEFN freefn);
  407. int dl_get_count (const DataList *dl);
  408. struct ava {
  409. char *ava_type;
  410. struct berval ava_value; /* JCM SLAPI_VALUE! */
  411. void *ava_private; /* data private to syntax handler */
  412. };
  413. typedef enum{
  414. FILTER_TYPE_SUBSTRING,
  415. FILTER_TYPE_AVA,
  416. FILTER_TYPE_PRES
  417. }filter_type_t;
  418. /*
  419. * vattr entry routines.
  420. * vattrcache private (for the moment)
  421. */
  422. #define SLAPI_ENTRY_VATTR_NOT_RESOLVED -1
  423. #define SLAPI_ENTRY_VATTR_RESOLVED_ABSENT -2
  424. #define SLAPI_ENTRY_VATTR_RESOLVED_EXISTS 0
  425. int slapi_entry_vattrcache_merge_sv(Slapi_Entry *e, const char *type, Slapi_ValueSet *vals, int buffer_flags);
  426. int slapi_entry_vattrcache_find_values_and_type_ex( const Slapi_Entry *e,
  427. const char *type,
  428. Slapi_ValueSet ***results,
  429. char ***actual_type_name);
  430. SLAPI_DEPRECATED int
  431. slapi_entry_vattrcache_find_values_and_type( const Slapi_Entry *e,
  432. const char *type,
  433. Slapi_ValueSet **results,
  434. char **actual_type_name);
  435. int slapi_entry_vattrcache_findAndTest(const Slapi_Entry *e, const char *type,
  436. Slapi_Filter *f,
  437. filter_type_t filter_type,
  438. int *rc);
  439. int slapi_vattrcache_iscacheable( const char * type );
  440. void slapi_vattrcache_cache_all();
  441. void slapi_vattrcache_cache_none();
  442. int vattr_test_filter( Slapi_PBlock *pb,
  443. /* Entry we're interested in */ Slapi_Entry *e,
  444. Slapi_Filter *f,
  445. filter_type_t filter_type,
  446. char *type);
  447. /* filter routines */
  448. int test_substring_filter( Slapi_PBlock *pb, Slapi_Entry *e,
  449. struct slapi_filter *f,
  450. int verify_access,int only_check_access, int *access_check_done);
  451. int test_ava_filter( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Attr *a,
  452. struct ava *ava, int ftype, int verify_access,
  453. int only_check_access, int *access_check_done);
  454. int test_presence_filter( Slapi_PBlock *pb, Slapi_Entry *e, char *type,
  455. int verify_access, int only_check_access, int *access_check_done);
  456. /* this structure allows to address entry by dn or uniqueid */
  457. typedef struct entry_address
  458. {
  459. char *udn; /* unnormalized dn */
  460. char *uniqueid;
  461. Slapi_DN *sdn;
  462. } entry_address;
  463. /*
  464. * LDAP Operation input parameters.
  465. */
  466. typedef struct slapi_operation_parameters
  467. {
  468. unsigned long operation_type; /* SLAPI_OPERATION_ADD, SLAPI_OPERATION_MODIFY ... */
  469. entry_address target_address; /* address of target entry */
  470. CSN *csn; /* The Change Sequence Number assigned to this operation. */
  471. LDAPControl **request_controls;/* array v3 LDAPMessage controls */
  472. union
  473. {
  474. struct add_parameters
  475. {
  476. struct slapi_entry *target_entry;
  477. char *parentuniqueid;
  478. } p_add;
  479. struct bind_parameters
  480. {
  481. ber_tag_t bind_method;
  482. struct berval *bind_creds;
  483. char *bind_saslmechanism; /* v3 sasl mechanism name */
  484. struct berval *bind_ret_saslcreds; /* v3 serverSaslCreds */
  485. } p_bind;
  486. struct compare_parameters
  487. {
  488. struct ava compare_ava;
  489. } p_compare;
  490. struct modify_parameters
  491. {
  492. LDAPMod **modify_mods;
  493. } p_modify;
  494. struct modrdn_parameters
  495. {
  496. char *modrdn_newrdn;
  497. int modrdn_deloldrdn;
  498. entry_address modrdn_newsuperior_address; /* address of the superior entry */
  499. LDAPMod **modrdn_mods; /* modifiers name and timestamp */
  500. } p_modrdn;
  501. struct search_parameters
  502. {
  503. int search_scope;
  504. int search_deref;
  505. int search_sizelimit;
  506. int search_timelimit;
  507. struct slapi_filter *search_filter;
  508. char *search_strfilter;
  509. char **search_attrs;
  510. int search_attrsonly;
  511. int search_is_and;
  512. char **search_gerattrs;
  513. } p_search;
  514. struct abandon_parameters
  515. {
  516. int abandon_targetmsgid;
  517. } p_abandon;
  518. struct extended_parameters
  519. {
  520. char *exop_oid;
  521. struct berval *exop_value;
  522. } p_extended;
  523. } p;
  524. } slapi_operation_parameters;
  525. struct slapi_operation_parameters *operation_parameters_new();
  526. struct slapi_operation_parameters *operation_parameters_dup(struct slapi_operation_parameters *sop);
  527. void operation_parameters_done(struct slapi_operation_parameters *sop);
  528. void operation_parameters_free(struct slapi_operation_parameters **sop);
  529. /*
  530. * errormap.c
  531. */
  532. char *slapd_pr_strerror( const PRErrorCode prerrno );
  533. const char *slapd_system_strerror( const int syserrno );
  534. const char *slapd_versatile_strerror( const PRErrorCode prerrno );
  535. /*
  536. * localhost.c
  537. */
  538. char* get_localhost_DNS();
  539. /* Return the fully-qualified DNS name of this machine.
  540. The caller should _not_ free this pointer. */
  541. char* get_localhost_DN();
  542. /*
  543. * Reference-counted objects
  544. */
  545. typedef void (*FNFree) (void **);
  546. typedef struct object Object;
  547. Object *object_new(void *user_data, FNFree destructor);
  548. void object_acquire(Object *o);
  549. void object_release(Object *o);
  550. void *object_get_data(Object *o);
  551. /* Sets of reference-counted objects */
  552. #define OBJSET_SUCCESS 0
  553. #define OBJSET_ALREADY_EXISTS 1
  554. #define OBJSET_NO_SUCH_OBJECT 2
  555. typedef int (*CMPFn) (Object *set, const void *name);
  556. typedef struct objset Objset;
  557. Objset *objset_new(FNFree objset_destructor);
  558. void objset_delete(Objset **set);
  559. int objset_add_obj(Objset *set, Object *object);
  560. Object *objset_find(Objset *set, CMPFn compare_fn, const void *name);
  561. int objset_remove_obj(Objset *set, Object *object);
  562. Object *objset_first_obj(Objset *set);
  563. Object *objset_next_obj(Objset *set, Object *previous);
  564. int objset_is_empty(Objset *set);
  565. int objset_size(Objset *set);
  566. /* backend management */
  567. typedef struct index_config
  568. {
  569. char *attr_name; /* attr name: dn, cn, etc. */
  570. char *index_type; /* space terminated list of indexes;
  571. possible types: "eq" "sub" "pres" "approx" */
  572. int system; /* marks this index as system */
  573. }IndexConfig;
  574. void be_set_sizelimit(Slapi_Backend * be, int sizelimit);
  575. void be_set_pagedsizelimit(Slapi_Backend * be, int sizelimit);
  576. void be_set_timelimit(Slapi_Backend * be, int timelimit);
  577. int be_isdeleted( const Slapi_Backend *be );
  578. /* used by mapping tree to delay sending of result code when several
  579. * backend are parsed
  580. */
  581. void slapi_set_ldap_result( Slapi_PBlock *pb, int err, char *matched,
  582. char *text, int nentries, struct berval **urls );
  583. void slapi_send_ldap_result_from_pb( Slapi_PBlock *pb);
  584. /* mapping tree utility functions */
  585. typedef struct mt_node mapping_tree_node;
  586. mapping_tree_node *slapi_get_mapping_tree_node_by_dn(const Slapi_DN *dn);
  587. char* slapi_get_mapping_tree_node_configdn(const Slapi_DN *root);
  588. Slapi_DN* slapi_get_mapping_tree_node_configsdn(const Slapi_DN *root);
  589. const Slapi_DN* slapi_get_mapping_tree_node_root(const mapping_tree_node *node);
  590. const char* slapi_get_mapping_tree_config_root ();
  591. Slapi_Backend *slapi_mapping_tree_find_backend_for_sdn(Slapi_DN *sdn);
  592. /* possible flags to check for */
  593. #define SLAPI_MTN_LOCAL 0x1
  594. #define SLAPI_MTN_PRIVATE 0x2
  595. #define SLAPI_MTN_READONLY 0x4
  596. PRBool slapi_mapping_tree_node_is_set (const mapping_tree_node *node,
  597. PRUint32 flag);
  598. Slapi_DN* slapi_mtn_get_dn(mapping_tree_node *node);
  599. int slapi_mapping_tree_select_and_check(Slapi_PBlock *pb,char *newdn,
  600. Slapi_Backend **be, Slapi_Entry **referral, char *errorbuf, size_t ebuflen);
  601. int slapi_mapping_tree_select_all(Slapi_PBlock *pb, Slapi_Backend **be_list,
  602. Slapi_Entry **referral_list, char *errorbuf, size_t ebuflen);
  603. void slapi_mapping_tree_free_all(Slapi_Backend **be_list,
  604. Slapi_Entry **referral_list);
  605. /* Mapping Tree */
  606. int slapi_mapping_tree_select(Slapi_PBlock *pb, Slapi_Backend **be, Slapi_Entry **referral, char *error_string, size_t ebuflen);
  607. char ** slapi_mtn_get_referral(const Slapi_DN *sdn);
  608. int slapi_mtn_set_referral(const Slapi_DN *sdn, char ** referral);
  609. int slapi_mtn_set_state(const Slapi_DN *sdn, char *state);
  610. char * slapi_mtn_get_state(const Slapi_DN *sdn);
  611. void slapi_mtn_be_set_readonly(Slapi_Backend *be, int readonly);
  612. void slapi_mtn_be_stopping(Slapi_Backend *be);
  613. void slapi_mtn_be_started(Slapi_Backend *be);
  614. void slapi_mtn_be_disable(Slapi_Backend *be);
  615. void slapi_mtn_be_enable(Slapi_Backend *be);
  616. const char *slapi_mtn_get_backend_name(const Slapi_DN *sdn);
  617. void slapi_be_stopping (Slapi_Backend *be);
  618. void slapi_be_free (Slapi_Backend **be);
  619. void slapi_be_Rlock (Slapi_Backend *be);
  620. void slapi_be_Wlock (Slapi_Backend *be);
  621. void slapi_be_Unlock (Slapi_Backend *be);
  622. /* components */
  623. struct slapi_componentid {
  624. char * sci_magic;
  625. const struct slapdplugin * sci_plugin;
  626. char * sci_component_name;
  627. };
  628. struct slapi_componentid *
  629. generate_componentid ( struct slapdplugin * pp , char * name );
  630. void release_componentid ( struct slapi_componentid * id );
  631. struct slapi_componentid * plugin_get_default_component_id();
  632. /* interface for component mgmt */
  633. /* Well-known components DNs */
  634. /* Should be documented somehow for the chaining backend */
  635. #define COMPONENT_BASE_DN "cn=components,cn=config"
  636. #define COMPONENT_ROLES "cn=roles,"COMPONENT_BASE_DN
  637. #define COMPONENT_RESLIMIT "cn=resource limits,"COMPONENT_BASE_DN
  638. #define COMPONENT_PWPOLICY "cn=password policy,"COMPONENT_BASE_DN
  639. #define COMPONENT_CERT_AUTH "cn=certificate-based authentication,"COMPONENT_BASE_DN
  640. #define COMPONENT_SASL "cn=sasl,"COMPONENT_BASE_DN
  641. /* Component names for logging */
  642. #define SLAPI_COMPONENT_NAME_NSPR "Netscape Portable Runtime"
  643. #define SLAPI_COMPONENT_NAME_LDAPSDK "LDAP sdk"
  644. /* loads the policies related to the replication of the schema */
  645. int slapi_schema_load_repl_policies();
  646. void slapi_schema_get_repl_entries(char **repl_schema_top, char ** repl_schema_supplier, char **repl_schema_consumer, char **default_supplier_policy, char **default_consumer_policy);
  647. /* return the list of attr defined in the schema matching the attr flags */
  648. char ** slapi_schema_list_attribute_names(unsigned long flag);
  649. /* return the list of attributes belonging to the objectclass */
  650. char ** slapi_schema_list_objectclass_attributes(const char *ocname_or_oid,
  651. PRUint32 flags);
  652. char * slapi_schema_get_superior_name(const char *ocname_or_oid);
  653. CSN *dup_global_schema_csn();
  654. /* misc function for the chaining backend */
  655. #define CHAIN_ROOT_UPDATE_REJECT 0
  656. #define CHAIN_ROOT_UPDATE_LOCAL 1
  657. #define CHAIN_ROOT_UPDATE_REFERRAL 2
  658. char * slapi_get_rootdn(); /* return the directory manager dn in use */
  659. /* plugin interface to bulk import */
  660. /* This function initiates bulk import. The pblock must contain
  661. SLAPI_LDIF2DB_GENERATE_UNIQUEID -- currently always set to TIME_BASED
  662. SLAPI_CONNECTION -- connection over which bulk import is coming
  663. SLAPI_BACKEND -- the backend being imported
  664. or
  665. SLAPI_TARGET_DN that contains root of the imported area.
  666. The function returns LDAP_SUCCESS or LDAP error code
  667. */
  668. int slapi_start_bulk_import (Slapi_PBlock *pb);
  669. /* This function adds an entry to the bulk import. The pblock must contain
  670. SLAPI_CONNECTION -- connection over which bulk import is coming
  671. SLAPI_BACKEND -- optional backend pointer; if missing computed based on entry dn
  672. The function returns LDAP_SUCCESS or LDAP error code
  673. */
  674. int slapi_import_entry (Slapi_PBlock *pb, Slapi_Entry *e);
  675. /* This function stops bulk import. The pblock must contain
  676. SLAPI_CONNECTION -- connection over which bulk import is coming
  677. SLAPI_BACKEND -- the backend being imported
  678. or
  679. SLAPI_TARGET_DN that contains root of the imported area.
  680. The function returns LDAP_SUCCESS or LDAP error code
  681. */
  682. int slapi_stop_bulk_import (Slapi_PBlock *pb);
  683. /* allows plugins to close inbound connection */
  684. void slapi_disconnect_server(Slapi_Connection *conn);
  685. /* functions to look up instance names by suffixes (backend_manager.c) */
  686. int slapi_lookup_instance_name_by_suffixes(char **included,
  687. char **excluded, char ***instances);
  688. int slapi_lookup_instance_name_by_suffix(char *suffix,
  689. char ***suffixes, char ***instances, int isexact);
  690. /* begin and end the task subsystem */
  691. void task_init(void);
  692. void task_shutdown(void);
  693. void task_cleanup(void);
  694. /* for reversible encyrption */
  695. #define SLAPI_MB_CREDENTIALS "nsmultiplexorcredentials"
  696. #define SLAPI_REP_CREDENTIALS "nsds5ReplicaCredentials"
  697. int pw_rever_encode(Slapi_Value **vals, char * attr_name);
  698. int pw_rever_decode(char *cipher, char **plain, const char * attr_name);
  699. /* config routines */
  700. int slapi_config_get_readonly();
  701. int slapi_config_get_unhashed_pw_switch();
  702. /*
  703. * charray.c
  704. */
  705. void charray_add( char ***a, char *s );
  706. void charray_merge( char ***a, char **s, int copy_strs );
  707. void charray_merge_nodup( char ***a, char **s, int copy_strs );
  708. void charray_free( char **array );
  709. int charray_inlist( char **a, char *s );
  710. int charray_utf8_inlist( char **a, char *s );
  711. char ** charray_dup( char **a );
  712. int charray_remove(char **a, const char *s, int freeit);
  713. char ** cool_charray_dup( char **a );
  714. void cool_charray_free( char **array );
  715. void charray_subtract( char **a, char **b, char ***c );
  716. int charray_get_index(char **array, char *s);
  717. int charray_normdn_add(char ***chararray, char *dn, char *errstr);
  718. /******************************************************************************
  719. * value array routines.
  720. *
  721. * It is unclear if these should ever be public, but today they are used by
  722. * some plugins. They would need to be renamed to have a slapi_ prefix at
  723. * the very least before we make them public.
  724. */
  725. void valuearray_add_value(Slapi_Value ***vals, const Slapi_Value *addval);
  726. void valuearray_add_valuearray( Slapi_Value ***vals, Slapi_Value **addvals, PRUint32 flags );
  727. void valuearray_add_valuearray_fast( Slapi_Value ***vals, Slapi_Value **addvals, int nvals, int naddvals, int *maxvals, int exact, int passin );
  728. Slapi_Value * valueset_find_sorted (const Slapi_Attr *a, const Slapi_ValueSet *vs, const Slapi_Value *v, int *index);
  729. int valueset_insert_value_to_sorted(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *vi, int dupcheck);
  730. void valueset_array_to_sorted (const Slapi_Attr *a, Slapi_ValueSet *vs);
  731. /* NOTE: if the flags include SLAPI_VALUE_FLAG_PASSIN and SLAPI_VALUE_FLAG_DUPCHECK
  732. * THE CALLER MUST PROVIDE THE dup_index PARAMETER in order to know where in addval
  733. * the un-copied values start e.g. to free them for cleanup
  734. * see valueset_replace_valuearray_ext() for an example
  735. */
  736. int slapi_valueset_add_attr_valuearray_ext(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **addval, int nvals, unsigned long flags, int *dup_index);
  737. int valuearray_find(const Slapi_Attr *a, Slapi_Value **va, const Slapi_Value *v);
  738. int valuearray_dn_normalize_value(Slapi_Value **vals);
  739. /*
  740. * proxyauth.c
  741. */
  742. int proxyauth_get_dn( Slapi_PBlock *pb, char **proxydnp, char **errtextp );
  743. /******************************************************************************
  744. * Database plugin interface.
  745. *
  746. * Prior to the 5.0 release, this was a public interface that lived in
  747. * slapi-plugin.h, so it is still a good idea to avoid making changes to it
  748. * that are not backwards compatible.
  749. */
  750. /* plugin type */
  751. #define SLAPI_PLUGIN_DATABASE 1
  752. /* database plugin functions */
  753. #define SLAPI_PLUGIN_DB_BIND_FN 200
  754. #define SLAPI_PLUGIN_DB_UNBIND_FN 201
  755. #define SLAPI_PLUGIN_DB_SEARCH_FN 202
  756. #define SLAPI_PLUGIN_DB_COMPARE_FN 203
  757. #define SLAPI_PLUGIN_DB_MODIFY_FN 204
  758. #define SLAPI_PLUGIN_DB_MODRDN_FN 205
  759. #define SLAPI_PLUGIN_DB_ADD_FN 206
  760. #define SLAPI_PLUGIN_DB_DELETE_FN 207
  761. #define SLAPI_PLUGIN_DB_ABANDON_FN 208
  762. #define SLAPI_PLUGIN_DB_CONFIG_FN 209
  763. #define SLAPI_PLUGIN_DB_FLUSH_FN 211
  764. #define SLAPI_PLUGIN_DB_SEQ_FN 213
  765. #define SLAPI_PLUGIN_DB_ENTRY_FN 214
  766. #define SLAPI_PLUGIN_DB_REFERRAL_FN 215
  767. #define SLAPI_PLUGIN_DB_RESULT_FN 216
  768. #define SLAPI_PLUGIN_DB_LDIF2DB_FN 217
  769. #define SLAPI_PLUGIN_DB_DB2LDIF_FN 218
  770. #define SLAPI_PLUGIN_DB_BEGIN_FN 219
  771. #define SLAPI_PLUGIN_DB_COMMIT_FN 220
  772. #define SLAPI_PLUGIN_DB_ABORT_FN 221
  773. #define SLAPI_PLUGIN_DB_ARCHIVE2DB_FN 222
  774. #define SLAPI_PLUGIN_DB_DB2ARCHIVE_FN 223
  775. #define SLAPI_PLUGIN_DB_NEXT_SEARCH_ENTRY_FN 224
  776. #define SLAPI_PLUGIN_DB_FREE_RESULT_SET_FN 225
  777. #define SLAPI_PLUGIN_DB_SIZE_FN 226
  778. #define SLAPI_PLUGIN_DB_TEST_FN 227
  779. #define SLAPI_PLUGIN_DB_DB2INDEX_FN 228
  780. #define SLAPI_PLUGIN_DB_NEXT_SEARCH_ENTRY_EXT_FN 229
  781. #define SLAPI_PLUGIN_DB_ENTRY_RELEASE_FN 230
  782. #define SLAPI_PLUGIN_DB_INIT_INSTANCE_FN 231
  783. #define SLAPI_PLUGIN_DB_WIRE_IMPORT_FN 234
  784. #define SLAPI_PLUGIN_DB_UPGRADEDB_FN 235
  785. #define SLAPI_PLUGIN_DB_DBVERIFY_FN 236
  786. #define SLAPI_PLUGIN_DB_ADD_SCHEMA_FN 237
  787. #define SLAPI_PLUGIN_DB_SEARCH_RESULTS_RELEASE_FN 238
  788. #define SLAPI_PLUGIN_DB_PREV_SEARCH_RESULTS_FN 239
  789. #define SLAPI_PLUGIN_DB_UPGRADEDNFORMAT_FN 240
  790. /* database plugin-specific parameters */
  791. #define SLAPI_PLUGIN_DB_NO_ACL 250
  792. #define SLAPI_PLUGIN_DB_RMDB_FN 280
  793. #define SLAPI_PLUGIN_DB_GET_INFO_FN 290
  794. #define SLAPI_PLUGIN_DB_SET_INFO_FN 291
  795. #define SLAPI_PLUGIN_DB_CTRL_INFO_FN 292
  796. /**** End of database plugin interface. **************************************/
  797. /******************************************************************************
  798. * Interface to the UniqueID generator (uniqueid.c)
  799. *
  800. * This could be made public someday, although it is a large interface and
  801. * not all of the elements follow the SLAPI_ naming convention.
  802. */
  803. /* error codes */
  804. #define UID_UPDATE_SHUTDOWN -1 /* update state information only during server shutdown */
  805. #define UID_UPDATE_INTERVAL 600000 /* 10 minutes */
  806. enum {UID_SUCCESS, /* operation was successfull */
  807. UID_ERROR_BASE=10,/* start of the error codes */
  808. UID_BADDATA, /* invalid parameter passed to a function */
  809. UID_MEMORY_ERROR, /* memory allocation failed */
  810. UID_SYSTEM_ERROR, /* I/O failed (currently, further details
  811. can be obtained using PR_GetError */
  812. UID_TIME_ERROR, /* UUID can't be generated because system
  813. time has not been update */
  814. UID_ERROR_END /* end of the error codes */
  815. };
  816. /* Function: slapi_uniqueIDNew
  817. Description: allocates new id
  818. Parameters: none
  819. Return: pointer to the newly allocated id if successful
  820. NULL if the system is out of memory
  821. */
  822. Slapi_UniqueID* slapi_uniqueIDNew( void );
  823. /* Function: slapi_uniqueIDDestroy
  824. Description: destroys UniqueID object and sets its pointer to NULL
  825. Parameters: uId - id to destroy
  826. Return: none
  827. */
  828. void slapi_uniqueIDDestroy(Slapi_UniqueID **uId);
  829. /* Function: slapi_uniqueIDCompare
  830. Description: this function compares two ids (byte by byte).
  831. Parameters: uId1, uId2 - ids to compare
  832. Return: -1 if uId1 < uId2
  833. 0 if uId2 == uId2
  834. 1 if uId2 > uId2
  835. UID_BADDATA if invalid pointer passed to the function
  836. */
  837. int slapi_uniqueIDCompare(const Slapi_UniqueID *uId1, const Slapi_UniqueID *uId2);
  838. int slapi_uniqueIDCompareString(const char *uuid1, const char *uuid2);
  839. /* Function: slapi_uniqueIDFormat
  840. Description: this function converts entryId to its string representation.
  841. The id format is HH-HHHHHHHH-HHHHHHHH-HHHHHHHH-HHHHHHHH
  842. where H is a hex digit.
  843. Parameters: uId - unique id
  844. buff - buffer in which id is returned;
  845. Return: UID_SUCCESS - function was successfull
  846. UID_BADDATA - invalid parameter passed to the function
  847. */
  848. int slapi_uniqueIDFormat(const Slapi_UniqueID *uId, char **buff);
  849. /* Function: slapi_uniqueIDScan
  850. Description: this function converts a string buffer into uniqueID.
  851. Currently, it only supports
  852. HH-HHHHHHHH-HHHHHHHH-HHHHHHHH-HHHHHHHH data format.
  853. Parameters: uId - unique id to be returned
  854. buff - buffer with uniqueID.
  855. Return: UID_SUCCESS - function was successfull
  856. UID_BADDATA - null parameter(s) or bad format
  857. */
  858. int slapi_uniqueIDScan(Slapi_UniqueID *uId, const char *buff);
  859. /* Function: slapi_uniqueIDIsUUID
  860. Description: tests if given entry id is of UUID type
  861. Parameters: uId - unique id to test
  862. Return UID_SUCCESS - function was successfull
  863. UID_BADDATA - invalid data passed to the function
  864. */
  865. int slapi_uniqueIDIsUUID(const Slapi_UniqueID *uId);
  866. /* Name: slapi_uniqueIDSize
  867. Description: returns size of the string version of uniqueID in bytes
  868. Parameters: none
  869. Return: size of the string version of uniqueID in bytes
  870. */
  871. int slapi_uniqueIDSize( void );
  872. /* Name: slapi_uniqueIDRdnSize
  873. Description: returns size of SLAPI_ATTR_UNIQUEID=slapi_uniqueIDSize()
  874. Parameters: none
  875. Return: size of the string version of "SLAPI_ATTR_UNIQUEID=uniqueID" in bytes
  876. */
  877. int slapi_uniqueIDRdnSize( void );
  878. /* Name: slapi_uniqueIDDup
  879. Description: duplicates an UniqueID object
  880. Parameters: uId - id to duplicate
  881. Return: duplicate of the Id
  882. */
  883. Slapi_UniqueID* slapi_uniqueIDDup(Slapi_UniqueID *uId);
  884. /*
  885. * interface to UniqueID generator - uniqueidgen.c
  886. */
  887. /* Function: slapi_uniqueIDGenerate
  888. Description: this function generates uniqueid in a singlethreaded
  889. environment.
  890. Parameters: uId - buffer to receive the ID.
  891. Return: UID_SUCCESS if function succeeds;
  892. UID_BADDATA if invalid pointer passed to the function;
  893. UID_SYSTEM_ERROR update to persistent storage failed.
  894. */
  895. int slapi_uniqueIDGenerate(Slapi_UniqueID *uId);
  896. /* Function: slapi_uniqueIDGenerateString
  897. Description: this function generates uniqueid an returns it as a string
  898. in a singlethreaded environment. This function returns the
  899. data in the format generated by slapi_uniqueIDFormat.
  900. Parameters: uId - buffer to receive the ID. Caller is responsible for
  901. freeing uId buffer.
  902. Return: UID_SUCCESS if function succeeds;
  903. UID_BADDATA if invalid pointer passed to the function;
  904. UID_MEMORY_ERROR if malloc fails;
  905. UID_SYSTEM_ERROR update to persistent storage failed.
  906. */
  907. int slapi_uniqueIDGenerateString(char **uId);
  908. /* Function: slapi_uniqueIDGenerateMT
  909. Description: this function generates entry id in a multithreaded
  910. environment. Used in conjunction with
  911. uniqueIDUpdateState function.
  912. Parameters: uId - structure in which new id will be returned.
  913. Return: UID_SUCCESS if function succeeds;
  914. UID_BADDATA if invalid pointer passed to the function;
  915. UID_TIME_ERROR uniqueIDUpdateState must be called
  916. before the id can be generated.
  917. */
  918. int slapi_uniqueIDGenerateMT(Slapi_UniqueID *uId);
  919. /* Function: slapi_uniqueIDGenerateMTString
  920. Description: this function generates uniqueid and returns it as a
  921. string in a multithreaded environment. Used in conjunction
  922. with uniqueIDUpdateState function.
  923. Parameters: uId - buffer in which new id will be returned. Caller is
  924. responsible for freeing uId buffer.
  925. Return: UID_SUCCESS if function succeeds;
  926. UID_BADDATA if invalid pointer passed to the function;
  927. UID_MEMORY_ERROR if malloc fails;
  928. UID_TIME_ERROR uniqueIDUpdateState must be called
  929. before the id can be generated.
  930. */
  931. int slapi_uniqueIDGenerateMTString(char **uId);
  932. /* Function: slapi_uniqueIDGenerateFromName
  933. Description: this function generates an id from a name. See uuid
  934. draft for more details. This function can be used in
  935. both a singlethreaded and a multithreaded environments.
  936. Parameters: uId - generated id
  937. uIDBase - uid used for generation to distinguish among
  938. different name spaces
  939. name - buffer containing name from which to generate the id
  940. namelen - length of the name buffer
  941. Return: UID_SUCCESS if function succeeds
  942. UID_BADDATA if invalid argument is passed to the
  943. function.
  944. */
  945. int slapi_uniqueIDGenerateFromName(Slapi_UniqueID *uId,
  946. const Slapi_UniqueID *uIdBase,
  947. const void *name, int namelen);
  948. /* Function: slapi_uniqueIDGenerateFromName
  949. Description: this function generates an id from a name and returns
  950. it in the string format. See uuid draft for more
  951. details. This function can be used in both a
  952. singlethreaded and a multithreaded environments.
  953. Parameters: uId - generated id in string form
  954. uIDBase - uid used for generation to distinguish among
  955. different name spaces in string form. NULL means to use
  956. empty id as the base.
  957. name - buffer containing name from which to generate the id
  958. namelen - length of the name buffer
  959. Return: UID_SUCCESS if function succeeds
  960. UID_BADDATA if invalid argument is passed to the
  961. function.
  962. */
  963. int slapi_uniqueIDGenerateFromNameString(char **uId,
  964. const char *uIdBase,
  965. const void *name, int namelen);
  966. /**** End of UniqueID generator interface. ***********************************/
  967. /*****************************************************************************
  968. * JCMREPL - Added for the replication plugin.
  969. */
  970. void schema_expand_objectclasses_nolock( Slapi_Entry *e );
  971. #define DSE_SCHEMA_NO_LOAD 0x0001 /* schema won't get loaded */
  972. #define DSE_SCHEMA_NO_CHECK 0x0002 /* schema won't be checked */
  973. #define DSE_SCHEMA_NO_BACKEND 0x0004 /* don't add as backend */
  974. #define DSE_SCHEMA_NO_GLOCK 0x0010 /* don't lock global resources */
  975. #define DSE_SCHEMA_LOCKED 0x0020 /* already locked with
  976. * reload_schemafile_lock;
  977. * no further lock needed */
  978. #define DSE_SCHEMA_USER_DEFINED_ONLY 0x0100 /* refresh user defined schema */
  979. #define DSE_SCHEMA_USE_PRIV_SCHEMA 0x0200 /* Use a provided private schema */
  980. /* */
  981. #define OC_CONSUMER "consumer"
  982. #define OC_SUPPLIER "supplier"
  983. #define SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY 0
  984. #define SLAPI_RTN_BIT_FETCH_PARENT_ENTRY 1
  985. #define SLAPI_RTN_BIT_FETCH_NEWPARENT_ENTRY 2
  986. #define SLAPI_RTN_BIT_FETCH_TARGET_ENTRY 3
  987. #define SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY 4
  988. /* Attribute use to mark entries that had a replication conflict on the DN */
  989. #define ATTR_NSDS5_REPLCONFLICT "nsds5ReplConflict"
  990. /* Time */
  991. #include <time.h> /* difftime, localtime_r, mktime */
  992. /* Duplicated: time_t read_localTime (struct berval* from); */
  993. time_t time_plus_sec(time_t l, long r);
  994. char* format_localTime(time_t from);
  995. time_t read_localTime(struct berval* from);
  996. time_t parse_localTime(char* from);
  997. void write_localTime(time_t from, struct berval* into);
  998. time_t current_time( void );
  999. char* format_genTime(time_t from);
  1000. void write_genTime(time_t from, struct berval* into);
  1001. time_t read_genTime(struct berval* from);
  1002. time_t parse_genTime(char* from);
  1003. long parse_duration(char *value);
  1004. char *gen_duration(long duration);
  1005. /* Client SSL code */
  1006. int slapd_security_library_is_initialized( void );
  1007. int slapd_nss_is_initialized( void );
  1008. char* slapd_get_tmp_dir( void );
  1009. /* util.c */
  1010. #include <stdio.h> /* GGOODREPL - For BUFSIZ, below, gak */
  1011. const char* escape_string (const char* str, char buf[BUFSIZ]);
  1012. const char* escape_string_with_punctuation(const char* str, char buf[BUFSIZ]);
  1013. const char* escape_string_for_filename(const char* str, char buf[BUFSIZ]);
  1014. void strcpy_unescape_value( char *d, const char *s );
  1015. char *slapi_berval_get_string_copy(const struct berval *bval);
  1016. /* lenstr stuff */
  1017. typedef struct _lenstr {
  1018. char *ls_buf;
  1019. size_t ls_len;
  1020. size_t ls_maxlen;
  1021. } lenstr;
  1022. #define LS_INCRSIZE 256
  1023. void addlenstr( lenstr *l, const char *str );
  1024. void lenstr_free( lenstr ** );
  1025. lenstr *lenstr_new(void);
  1026. /* config DN */
  1027. char *get_config_DN(void);
  1028. /* Data Version */
  1029. const char *get_server_dataversion( void );
  1030. /* Configuration Parameters */
  1031. int config_get_port( void );
  1032. int config_get_secureport( void );
  1033. /* Local host information */
  1034. char* get_localhost_DN( void );
  1035. char* get_localhost_DNS( void );
  1036. /* GGOODREPL get_data_source definition should move into repl DLL */
  1037. struct berval **get_data_source(Slapi_PBlock *pb, const Slapi_DN *sdn, int orc, void *cf_refs);
  1038. /* JCMREPL - IFP and CFP should be defined centrally */
  1039. #ifndef _IFP
  1040. #define _IFP
  1041. typedef int (*IFP)();
  1042. #endif
  1043. #ifndef _CFP
  1044. #define _CFP
  1045. typedef char*(*CFP)();
  1046. #endif
  1047. void bervalarray_add_berval_fast(struct berval ***vals, const struct berval *addval, int nvals, int *maxvals);
  1048. /* this is the root configuration entry beneath which all plugin
  1049. configuration entries will be found */
  1050. #define PLUGIN_BASE_DN "cn=plugins,cn=config"
  1051. #define SLAPI_PLUGIN_DEFAULT_CONFIG "cn=plugin default config,cn=config"
  1052. /***** End of items added for the replication plugin. ***********************/
  1053. /* macro to specify the behavior of upgradedb & upgradednformat */
  1054. #define SLAPI_UPGRADEDB_FORCE 0x1 /* reindex all (no check w/ idl switch) */
  1055. #define SLAPI_UPGRADEDB_SKIPINIT 0x2 /* call upgradedb as part of other op */
  1056. #define SLAPI_UPGRADEDB_DN2RDN 0x4 /* modify id2entry from dn format to rdn;
  1057. generate entryrdn index */
  1058. #define SLAPI_UPGRADEDNFORMAT 0x8 /* specify this op is upgradednformat */
  1059. #define SLAPI_DRYRUN 0x10 /* dryrun mode for upgradednformat */
  1060. #define SLAPI_UPGRADEDNFORMAT_V1 0x20 /* taking care multipe spaces */
  1061. /*
  1062. * Macro to set port to the 'port' field of a NSPR PRNetAddr union.
  1063. ** INPUTS:
  1064. ** PRNetAddr *myaddr A network address.
  1065. ** PRUint16 myport port to set to the 'port' field of 'addr'.
  1066. ** RETURN: none
  1067. *
  1068. * Note: Copy from ldappr-int.h in
  1069. * ldapcsdk:mozilla/directory/c-sdk/ldap/libraries/libprldap
  1070. * Introduced to avoid calling PR_SetNetAddr w/ PR_IpAddrNull just to set port.
  1071. * Once NSPR starts providing better function/macro to do the same job,
  1072. * this macro should be replaced with it. (newer than NSPR v4.6.2)
  1073. */
  1074. #define PRLDAP_SET_PORT(myaddr,myport) \
  1075. ((myaddr)->raw.family == PR_AF_INET6 ? ((myaddr)->ipv6.port = PR_htons(myport)) : ((myaddr)->inet.port = PR_htons(myport)))
  1076. /* plugin.c */
  1077. int plugin_enabled(const char *plugin_name, void *identity);
  1078. /**
  1079. * For "database" plugins that need to call preoperation backend & backend txn plugins.
  1080. * This function should be called right before the operation is performed.
  1081. *
  1082. * \param Slapi_PBLock object
  1083. * \param int operation
  1084. *
  1085. * Operations:
  1086. * SLAPI_PLUGIN_ADD_OP
  1087. * SLAPI_PLUGIN_MOD_OP
  1088. * SLAPI_PLUGIN_MODRDN_OP
  1089. * SLAPI_PLUGIN_DEL_OP
  1090. *
  1091. * \return zero on success, non-zero for failure
  1092. */
  1093. int slapi_plugin_call_preop_be_plugins(Slapi_PBlock *pb, int operation);
  1094. /**
  1095. * For "database" plugins that need to call postoperation backend & backend txn plugins.
  1096. * This function should be called right after the operation is performed.
  1097. *
  1098. * \param Slapi_PBLock object
  1099. * \param int operation
  1100. *
  1101. * Operations:
  1102. * SLAPI_PLUGIN_ADD_OP
  1103. * SLAPI_PLUGIN_MOD_OP
  1104. * SLAPI_PLUGIN_MODRDN_OP
  1105. * SLAPI_PLUGIN_DEL_OP
  1106. *
  1107. * \return zero on success, non-zero for failure
  1108. */
  1109. int slapi_plugin_call_postop_be_plugins(Slapi_PBlock *pb, int operation);
  1110. /* protect_db.c */
  1111. /* is_slapd_running()
  1112. * returns 1 if slapd is running, 0 if not, -1 on error
  1113. */
  1114. int is_slapd_running();
  1115. /* schema.c */
  1116. void schema_destroy_dse_lock();
  1117. /* attrsyntax.c */
  1118. int slapi_add_internal_attr_syntax( const char *name, const char *oid, const char *syntax, const char *mr_equality, unsigned long extraflags );
  1119. /* pw.c */
  1120. void pw_exp_init ( void );
  1121. int pw_copy_entry_ext(Slapi_Entry *src_e, Slapi_Entry *dest_e);
  1122. int pw_get_ext_size(Slapi_Entry *e, size_t *size);
  1123. /* op_shared.c */
  1124. void modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods);
  1125. /* add.c */
  1126. void add_internal_modifiersname(Slapi_PBlock *pb, Slapi_Entry *e);
  1127. /* ldaputil.c */
  1128. char *ldaputil_get_saslpath();
  1129. int slapi_client_uses_non_nss(LDAP *ld);
  1130. int slapi_client_uses_openssl(LDAP *ld);
  1131. /* ssl.c */
  1132. /*
  1133. * If non NULL buf and positive bufsize is given,
  1134. * the memory is used to store the version string.
  1135. * Otherwise, the memory for the string is allocated.
  1136. * The latter case, caller is responsible to free it.
  1137. */
  1138. /* vnum is supposed to be in one of the following:
  1139. * nss3/sslproto.h
  1140. * #define SSL_LIBRARY_VERSION_2 0x0002
  1141. * #define SSL_LIBRARY_VERSION_3_0 0x0300
  1142. * #define SSL_LIBRARY_VERSION_TLS_1_0 0x0301
  1143. * #define SSL_LIBRARY_VERSION_TLS_1_1 0x0302
  1144. * #define SSL_LIBRARY_VERSION_TLS_1_2 0x0303
  1145. * #define SSL_LIBRARY_VERSION_TLS_1_3 0x0304
  1146. * ...
  1147. */
  1148. char *slapi_getSSLVersion_str(PRUint16 vnum, char *buf, size_t bufsize);
  1149. /*
  1150. * time.c
  1151. *
  1152. * Return Value:
  1153. * Success: duration in seconds
  1154. * Failure: -1
  1155. */
  1156. time_t slapi_parse_duration(const char *value);
  1157. long long slapi_parse_duration_longlong(const char *value);
  1158. int slapi_is_duration_valid(const char *value);
  1159. /**
  1160. * Populate the pointers with the system memory information.
  1161. * At this time, Linux is the only "reliable" system for returning these values
  1162. *
  1163. * \param pagesize Will return the system page size in bytes.
  1164. * \param pages The total number of memory pages on the system. May include swap pages depending on OS.
  1165. * \param procpages Number of memory pages our current process is consuming. May not be accurate on all platforms as this could be the VMSize rather than the actual number of consumed pages.
  1166. * \param availpages Number of available pages of memory on the system. Not all operating systems set this correctly.
  1167. *
  1168. * \return 0 on success, non-zero on failure to determine memory sizings.
  1169. */
  1170. int util_info_sys_pages(size_t *pagesize, size_t *pages, size_t *procpages, size_t *availpages);
  1171. /**
  1172. * Determine if the requested cachesize will exceed the system memory limits causing an out of memory condition
  1173. *
  1174. * \param cachesize. The requested allocation. If this value is greater than the memory available, this value will be REDUCED to be valid.
  1175. *
  1176. * \return 0 if the size is "sane". 1 if the value will cause OOM and has been REDUCED
  1177. */
  1178. int util_is_cachesize_sane(size_t *cachesize);
  1179. /**
  1180. * Write an error message to the given error buffer.
  1181. *
  1182. * \param errorbuf. The buffer that the error message is written into. If NULL, nothing happens. It could be a static array or allocated memory. If it is allocated memory, the next param len should be given.
  1183. * \param len. The length of errorbuf. If 0 is given, sizeof(errorbuf) is used.
  1184. * \param fmt. The format of the error message.
  1185. */
  1186. void slapi_create_errormsg(char *errorbuf, size_t len, const char *fmt, ...);
  1187. #ifdef __cplusplus
  1188. }
  1189. #endif
  1190. #endif