slapi-private.h 52 KB

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