slapi-private.h 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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. /* entrywsi.c */
  300. CSN* entry_assign_operation_csn ( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *parententry );
  301. const CSN *entry_get_maxcsn ( const Slapi_Entry *entry );
  302. void entry_set_maxcsn ( Slapi_Entry *entry, const CSN *csn );
  303. const CSN *entry_get_dncsn(const Slapi_Entry *entry);
  304. const CSNSet *entry_get_dncsnset(const Slapi_Entry *entry);
  305. int entry_add_dncsn(Slapi_Entry *entry, const CSN *csn);
  306. int entry_set_csn(Slapi_Entry *entry, const CSN *csn);
  307. void entry_purge_state_information(Slapi_Entry *entry, const CSN *csnUpto);
  308. void entry_add_rdn_csn(Slapi_Entry *e, const CSN *csn);
  309. /* this adds a csn to the entry's e_dncsnset but makes sure the set is in increasing csn order */
  310. #define ENTRY_DNCSN_INCREASING 0x1 /* for flags below */
  311. int entry_add_dncsn_ext(Slapi_Entry *entry, const CSN *csn, PRUint32 flags);
  312. /* attr.c */
  313. Slapi_Attr *slapi_attr_init_locking_optional(Slapi_Attr *a, const char *type, PRBool use_lock);
  314. Slapi_Attr *slapi_attr_init_nosyntax(Slapi_Attr *a, const char *type);
  315. int slapi_attr_init_syntax(Slapi_Attr *a);
  316. int attr_set_csn( Slapi_Attr *a, const CSN *csn);
  317. int attr_set_deletion_csn( Slapi_Attr *a, const CSN *csn);
  318. const CSN *attr_get_deletion_csn(const Slapi_Attr *a);
  319. int attr_first_deleted_value( Slapi_Attr *a, Slapi_Value **v );
  320. int attr_next_deleted_value( Slapi_Attr *a, int hint, Slapi_Value **v);
  321. void attr_purge_state_information(Slapi_Entry *entry, Slapi_Attr *attr, const CSN *csnUpto);
  322. Slapi_Value **attr_get_present_values(const Slapi_Attr *a);
  323. int attr_add_deleted_value(Slapi_Attr *a, const Slapi_Value *v);
  324. /* value.c */
  325. Slapi_Value *value_new(const struct berval *bval, CSNType t, const CSN *csn);
  326. Slapi_Value *value_init(Slapi_Value *v, const struct berval *bval, CSNType t, const CSN *csn);
  327. void value_done(Slapi_Value *v);
  328. Slapi_Value *value_update_csn( Slapi_Value *value, CSNType t, const CSN *csn);
  329. Slapi_Value *value_add_csn( Slapi_Value *value, CSNType t, const CSN *csn);
  330. const CSN *value_get_csn( const Slapi_Value *value, CSNType t );
  331. const CSNSet *value_get_csnset ( const Slapi_Value *value);
  332. Slapi_Value *value_remove_csn( Slapi_Value *value, CSNType t);
  333. int value_contains_csn( const Slapi_Value *value, CSN *csn);
  334. int value_dn_normalize_value(Slapi_Value *value);
  335. /* dn.c */
  336. /* this functions should only be used for dns allocated on the stack */
  337. Slapi_DN *slapi_sdn_init(Slapi_DN *sdn);
  338. Slapi_DN *slapi_sdn_init_dn_byref(Slapi_DN *sdn,const char *dn);
  339. Slapi_DN *slapi_sdn_init_dn_byval(Slapi_DN *sdn,const char *dn);
  340. Slapi_DN *slapi_sdn_init_dn_passin(Slapi_DN *sdn,const char *dn);
  341. Slapi_DN *slapi_sdn_init_ndn_byref(Slapi_DN *sdn,const char *dn);
  342. Slapi_DN *slapi_sdn_init_ndn_byval(Slapi_DN *sdn,const char *dn);
  343. Slapi_DN *slapi_sdn_init_normdn_byref(Slapi_DN *sdn, const char *dn);
  344. Slapi_DN *slapi_sdn_init_normdn_byval(Slapi_DN *sdn, const char *dn);
  345. Slapi_DN *slapi_sdn_init_normdn_ndn_passin(Slapi_DN *sdn, const char *dn);
  346. Slapi_DN *slapi_sdn_init_normdn_passin(Slapi_DN *sdn, const char *dn);
  347. char *slapi_dn_normalize_original( char *dn );
  348. char *slapi_dn_normalize_case_original( char *dn );
  349. void ndn_cache_init();
  350. void ndn_cache_get_stats(PRUint64 *hits, PRUint64 *tries, size_t *size, size_t *max_size, long *count);
  351. #define NDN_DEFAULT_SIZE 20971520 /* 20mb - size of normalized dn cache */
  352. /* filter.c */
  353. int filter_flag_is_set(const Slapi_Filter *f,unsigned char flag);
  354. char *slapi_filter_to_string(const Slapi_Filter *f, char *buffer, size_t bufsize);
  355. char *slapi_filter_to_string_internal( const struct slapi_filter *f, char *buf, size_t *bufsize );
  356. /* operation.c */
  357. #define OP_FLAG_PS 0x00001
  358. #define OP_FLAG_PS_CHANGESONLY 0x00002
  359. #define OP_FLAG_GET_EFFECTIVE_RIGHTS 0x00004
  360. #define OP_FLAG_REPLICATED 0x00008 /* A Replicated Operation */
  361. #define OP_FLAG_REPL_FIXUP 0x00010 /* A Fixup Operation,
  362. * generated as a consequence
  363. * of a Replicated Operation.
  364. */
  365. #define OP_FLAG_INTERNAL SLAPI_OP_FLAG_INTERNAL /* 0x00020 */
  366. #define OP_FLAG_ACTION_LOG_ACCESS 0x00040
  367. #define OP_FLAG_ACTION_LOG_AUDIT 0x00080
  368. #define OP_FLAG_ACTION_SCHEMA_CHECK 0x00100
  369. #define OP_FLAG_ACTION_LOG_CHANGES 0x00200
  370. #define OP_FLAG_ACTION_INVOKE_FOR_REPLOP 0x00400
  371. #define OP_FLAG_NEVER_CHAIN SLAPI_OP_FLAG_NEVER_CHAIN /* 0x0800 */
  372. #define OP_FLAG_TOMBSTONE_ENTRY 0x01000
  373. #define OP_FLAG_RESURECT_ENTRY 0x02000
  374. #define OP_FLAG_LEGACY_REPLICATION_DN 0x04000 /* Operation done by legacy
  375. * replication DN
  376. */
  377. #define OP_FLAG_ACTION_NOLOG 0x08000 /* Do not log the entry in
  378. * audit log or change log
  379. */
  380. #define OP_FLAG_SKIP_MODIFIED_ATTRS 0x10000 /* Do not update the
  381. * modifiersname,
  382. * modifiedtimestamp, etc.
  383. * attributes
  384. */
  385. #define OP_FLAG_REPL_RUV 0x20000 /* Flag to tell to the backend
  386. * that the entry to be added/
  387. * modified is RUV. This info
  388. * is used to skip VLV op.
  389. * (see #329951)
  390. */
  391. #define OP_FLAG_PAGED_RESULTS 0x40000 /* simple paged results */
  392. #define OP_FLAG_SERVER_SIDE_SORTING 0x80000 /* server side sorting */
  393. CSN *operation_get_csn(Slapi_Operation *op);
  394. void operation_set_csn(Slapi_Operation *op,CSN *csn);
  395. void operation_set_flag(Slapi_Operation *op,int flag);
  396. void operation_clear_flag(Slapi_Operation *op,int flag);
  397. int operation_is_flag_set(Slapi_Operation *op,int flag);
  398. unsigned long operation_get_type(Slapi_Operation *op);
  399. LDAPMod **copy_mods(LDAPMod **orig_mods);
  400. /*
  401. * From ldap.h
  402. * #define LDAP_MOD_ADD 0x00
  403. * #define LDAP_MOD_DELETE 0x01
  404. * #define LDAP_MOD_REPLACE 0x02
  405. * #define LDAP_MOD_INCREMENT 0x03 -- Openldap extension
  406. * #define LDAP_MOD_BVALUES 0x80
  407. */
  408. #define LDAP_MOD_IGNORE 0x100
  409. /* dl.c */
  410. typedef struct datalist DataList;
  411. typedef int (*CMPFN) (const void *el1, const void *el2);
  412. typedef void (*FREEFN) (void **);
  413. DataList* dl_new ();
  414. void dl_free (DataList **dl);
  415. void dl_init (DataList *dl, int init_alloc);
  416. void dl_cleanup (DataList *dl, FREEFN freefn);
  417. void dl_add (DataList *dl, void *element);
  418. void dl_add_index(DataList *dl, void *element, int index);
  419. void *dl_replace(const DataList *dl, const void *elementOld, void *elementNew, CMPFN cmpfn, FREEFN freefn);
  420. void *dl_get_first (const DataList *dl, int *cookie);
  421. void *dl_get_next (const DataList *dl, int *cookie);
  422. void *dl_get_prev (const DataList *dl, int *cookie);
  423. void *dl_get (const DataList *dl, const void *element, CMPFN cmpfn);
  424. void *dl_delete (DataList *dl, const void *element, CMPFN cmpfn, FREEFN freefn);
  425. int dl_get_count (const DataList *dl);
  426. struct ava {
  427. char *ava_type;
  428. struct berval ava_value; /* JCM SLAPI_VALUE! */
  429. void *ava_private; /* data private to syntax handler */
  430. };
  431. typedef enum{
  432. FILTER_TYPE_SUBSTRING,
  433. FILTER_TYPE_AVA,
  434. FILTER_TYPE_PRES
  435. }filter_type_t;
  436. /*
  437. * vattr entry routines.
  438. * vattrcache private (for the moment)
  439. */
  440. #define SLAPI_ENTRY_VATTR_NOT_RESOLVED -1
  441. #define SLAPI_ENTRY_VATTR_RESOLVED_ABSENT -2
  442. #define SLAPI_ENTRY_VATTR_RESOLVED_EXISTS 0
  443. int slapi_entry_vattrcache_merge_sv(Slapi_Entry *e, const char *type, Slapi_ValueSet *vals, int buffer_flags);
  444. int slapi_entry_vattrcache_find_values_and_type_ex( const Slapi_Entry *e,
  445. const char *type,
  446. Slapi_ValueSet ***results,
  447. char ***actual_type_name);
  448. SLAPI_DEPRECATED int
  449. slapi_entry_vattrcache_find_values_and_type( const Slapi_Entry *e,
  450. const char *type,
  451. Slapi_ValueSet **results,
  452. char **actual_type_name);
  453. int slapi_entry_vattrcache_findAndTest(const Slapi_Entry *e, const char *type,
  454. Slapi_Filter *f,
  455. filter_type_t filter_type,
  456. int *rc);
  457. int slapi_vattrcache_iscacheable( const char * type );
  458. void slapi_vattrcache_cache_all();
  459. void slapi_vattrcache_cache_none();
  460. int vattr_test_filter( Slapi_PBlock *pb,
  461. /* Entry we're interested in */ Slapi_Entry *e,
  462. Slapi_Filter *f,
  463. filter_type_t filter_type,
  464. char *type);
  465. /* filter routines */
  466. int test_substring_filter( Slapi_PBlock *pb, Slapi_Entry *e,
  467. struct slapi_filter *f,
  468. int verify_access,int only_check_access, int *access_check_done);
  469. int test_ava_filter( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Attr *a,
  470. struct ava *ava, int ftype, int verify_access,
  471. int only_check_access, int *access_check_done);
  472. int test_presence_filter( Slapi_PBlock *pb, Slapi_Entry *e, char *type,
  473. int verify_access, int only_check_access, int *access_check_done);
  474. /* this structure allows to address entry by dn or uniqueid */
  475. typedef struct entry_address
  476. {
  477. char *udn; /* unnormalized dn */
  478. char *uniqueid;
  479. Slapi_DN *sdn;
  480. } entry_address;
  481. /*
  482. * LDAP Operation input parameters.
  483. */
  484. typedef struct slapi_operation_parameters
  485. {
  486. unsigned long operation_type; /* SLAPI_OPERATION_ADD, SLAPI_OPERATION_MODIFY ... */
  487. entry_address target_address; /* address of target entry */
  488. CSN *csn; /* The Change Sequence Number assigned to this operation. */
  489. LDAPControl **request_controls;/* array v3 LDAPMessage controls */
  490. union
  491. {
  492. struct add_parameters
  493. {
  494. struct slapi_entry *target_entry;
  495. char *parentuniqueid;
  496. } p_add;
  497. struct bind_parameters
  498. {
  499. int bind_method;
  500. struct berval *bind_creds;
  501. char *bind_saslmechanism; /* v3 sasl mechanism name */
  502. struct berval *bind_ret_saslcreds; /* v3 serverSaslCreds */
  503. } p_bind;
  504. struct compare_parameters
  505. {
  506. struct ava compare_ava;
  507. } p_compare;
  508. struct modify_parameters
  509. {
  510. LDAPMod **modify_mods;
  511. } p_modify;
  512. struct modrdn_parameters
  513. {
  514. char *modrdn_newrdn;
  515. int modrdn_deloldrdn;
  516. entry_address modrdn_newsuperior_address; /* address of the superior entry */
  517. LDAPMod **modrdn_mods; /* modifiers name and timestamp */
  518. } p_modrdn;
  519. struct search_parameters
  520. {
  521. int search_scope;
  522. int search_deref;
  523. int search_sizelimit;
  524. int search_timelimit;
  525. struct slapi_filter *search_filter;
  526. char *search_strfilter;
  527. char **search_attrs;
  528. int search_attrsonly;
  529. int search_is_and;
  530. char **search_gerattrs;
  531. } p_search;
  532. struct abandon_parameters
  533. {
  534. int abandon_targetmsgid;
  535. } p_abandon;
  536. struct extended_parameters
  537. {
  538. char *exop_oid;
  539. struct berval *exop_value;
  540. } p_extended;
  541. } p;
  542. } slapi_operation_parameters;
  543. struct slapi_operation_parameters *operation_parameters_new();
  544. struct slapi_operation_parameters *operation_parameters_dup(struct slapi_operation_parameters *sop);
  545. void operation_parameters_done(struct slapi_operation_parameters *sop);
  546. void operation_parameters_free(struct slapi_operation_parameters **sop);
  547. /*
  548. * errormap.c
  549. */
  550. char *slapd_pr_strerror( const PRErrorCode prerrno );
  551. const char *slapd_system_strerror( const int syserrno );
  552. const char *slapd_versatile_strerror( const PRErrorCode prerrno );
  553. /*
  554. * localhost.c
  555. */
  556. char* get_localhost_DNS();
  557. /* Return the fully-qualified DNS name of this machine.
  558. The caller should _not_ free this pointer. */
  559. char* get_localhost_DN();
  560. /*
  561. * Reference-counted objects
  562. */
  563. typedef void (*FNFree) (void **);
  564. typedef struct object Object;
  565. Object *object_new(void *user_data, FNFree destructor);
  566. void object_acquire(Object *o);
  567. void object_release(Object *o);
  568. void *object_get_data(Object *o);
  569. /* Sets of reference-counted objects */
  570. #define OBJSET_SUCCESS 0
  571. #define OBJSET_ALREADY_EXISTS 1
  572. #define OBJSET_NO_SUCH_OBJECT 2
  573. typedef int (*CMPFn) (Object *set, const void *name);
  574. typedef struct objset Objset;
  575. Objset *objset_new(FNFree objset_destructor);
  576. void objset_delete(Objset **set);
  577. int objset_add_obj(Objset *set, Object *object);
  578. Object *objset_find(Objset *set, CMPFn compare_fn, const void *name);
  579. int objset_remove_obj(Objset *set, Object *object);
  580. Object *objset_first_obj(Objset *set);
  581. Object *objset_next_obj(Objset *set, Object *previous);
  582. int objset_is_empty(Objset *set);
  583. int objset_size(Objset *set);
  584. /* backend management */
  585. typedef struct index_config
  586. {
  587. char *attr_name; /* attr name: dn, cn, etc. */
  588. char *index_type; /* space terminated list of indexes;
  589. possible types: "eq" "sub" "pres" "approx" */
  590. int system; /* marks this index as system */
  591. }IndexConfig;
  592. void be_set_sizelimit(Slapi_Backend * be, int sizelimit);
  593. void be_set_pagedsizelimit(Slapi_Backend * be, int sizelimit);
  594. void be_set_timelimit(Slapi_Backend * be, int timelimit);
  595. int be_isdeleted( const Slapi_Backend *be );
  596. /* used by mapping tree to delay sending of result code when several
  597. * backend are parsed
  598. */
  599. void slapi_set_ldap_result( Slapi_PBlock *pb, int err, char *matched,
  600. char *text, int nentries, struct berval **urls );
  601. void slapi_send_ldap_result_from_pb( Slapi_PBlock *pb);
  602. /* mapping tree utility functions */
  603. typedef struct mt_node mapping_tree_node;
  604. mapping_tree_node *slapi_get_mapping_tree_node_by_dn(const Slapi_DN *dn);
  605. char* slapi_get_mapping_tree_node_configdn(const Slapi_DN *root);
  606. Slapi_DN* slapi_get_mapping_tree_node_configsdn(const Slapi_DN *root);
  607. const Slapi_DN* slapi_get_mapping_tree_node_root(const mapping_tree_node *node);
  608. const char* slapi_get_mapping_tree_config_root ();
  609. Slapi_Backend *slapi_mapping_tree_find_backend_for_sdn(Slapi_DN *sdn);
  610. /* possible flags to check for */
  611. #define SLAPI_MTN_LOCAL 0x1
  612. #define SLAPI_MTN_PRIVATE 0x2
  613. #define SLAPI_MTN_READONLY 0x4
  614. PRBool slapi_mapping_tree_node_is_set (const mapping_tree_node *node,
  615. PRUint32 flag);
  616. Slapi_DN* slapi_mtn_get_dn(mapping_tree_node *node);
  617. int slapi_mapping_tree_select_and_check(Slapi_PBlock *pb,char *newdn,
  618. Slapi_Backend **be, Slapi_Entry **referral, char *errorbuf);
  619. int slapi_mapping_tree_select_all(Slapi_PBlock *pb, Slapi_Backend **be_list,
  620. Slapi_Entry **referral_list, char *errorbuf);
  621. void slapi_mapping_tree_free_all(Slapi_Backend **be_list,
  622. Slapi_Entry **referral_list);
  623. /* Mapping Tree */
  624. int slapi_mapping_tree_select(Slapi_PBlock *pb, Slapi_Backend **be, Slapi_Entry **referral, char *error_string);
  625. char ** slapi_mtn_get_referral(const Slapi_DN *sdn);
  626. int slapi_mtn_set_referral(const Slapi_DN *sdn, char ** referral);
  627. int slapi_mtn_set_state(const Slapi_DN *sdn, char *state);
  628. char * slapi_mtn_get_state(const Slapi_DN *sdn);
  629. void slapi_mtn_be_set_readonly(Slapi_Backend *be, int readonly);
  630. void slapi_mtn_be_stopping(Slapi_Backend *be);
  631. void slapi_mtn_be_started(Slapi_Backend *be);
  632. void slapi_mtn_be_disable(Slapi_Backend *be);
  633. void slapi_mtn_be_enable(Slapi_Backend *be);
  634. const char *slapi_mtn_get_backend_name(const Slapi_DN *sdn);
  635. void slapi_be_stopping (Slapi_Backend *be);
  636. void slapi_be_free (Slapi_Backend **be);
  637. void slapi_be_Rlock (Slapi_Backend *be);
  638. void slapi_be_Wlock (Slapi_Backend *be);
  639. void slapi_be_Unlock (Slapi_Backend *be);
  640. /* components */
  641. struct slapi_componentid {
  642. char * sci_magic;
  643. const struct slapdplugin * sci_plugin;
  644. char * sci_component_name;
  645. };
  646. struct slapi_componentid *
  647. generate_componentid ( struct slapdplugin * pp , char * name );
  648. void release_componentid ( struct slapi_componentid * id );
  649. struct slapi_componentid * plugin_get_default_component_id();
  650. /* interface for component mgmt */
  651. /* Well-known components DNs */
  652. /* Should be documented somehow for the chaining backend */
  653. #define COMPONENT_BASE_DN "cn=components,cn=config"
  654. #define COMPONENT_ROLES "cn=roles,"COMPONENT_BASE_DN
  655. #define COMPONENT_RESLIMIT "cn=resource limits,"COMPONENT_BASE_DN
  656. #define COMPONENT_PWPOLICY "cn=password policy,"COMPONENT_BASE_DN
  657. #define COMPONENT_CERT_AUTH "cn=certificate-based authentication,"COMPONENT_BASE_DN
  658. #define COMPONENT_SASL "cn=sasl,"COMPONENT_BASE_DN
  659. /* Component names for logging */
  660. #define SLAPI_COMPONENT_NAME_NSPR "Netscape Portable Runtime"
  661. #define SLAPI_COMPONENT_NAME_LDAPSDK "LDAP sdk"
  662. /* return the list of attr defined in the schema matching the attr flags */
  663. char ** slapi_schema_list_attribute_names(unsigned long flag);
  664. /* return the list of attributes belonging to the objectclass */
  665. char ** slapi_schema_list_objectclass_attributes(const char *ocname_or_oid,
  666. PRUint32 flags);
  667. char * slapi_schema_get_superior_name(const char *ocname_or_oid);
  668. CSN *dup_global_schema_csn();
  669. /* misc function for the chaining backend */
  670. char * slapi_get_rootdn(); /* return the directory manager dn in use */
  671. /* plugin interface to bulk import */
  672. /* This function initiates bulk import. The pblock must contain
  673. SLAPI_LDIF2DB_GENERATE_UNIQUEID -- currently always set to TIME_BASED
  674. SLAPI_CONNECTION -- connection over which bulk import is coming
  675. SLAPI_BACKEND -- the backend being imported
  676. or
  677. SLAPI_TARGET_DN that contains root of the imported area.
  678. The function returns LDAP_SUCCESS or LDAP error code
  679. */
  680. int slapi_start_bulk_import (Slapi_PBlock *pb);
  681. /* This function adds an entry to the bulk import. The pblock must contain
  682. SLAPI_CONNECTION -- connection over which bulk import is coming
  683. SLAPI_BACKEND -- optional backend pointer; if missing computed based on entry dn
  684. The function returns LDAP_SUCCESS or LDAP error code
  685. */
  686. int slapi_import_entry (Slapi_PBlock *pb, Slapi_Entry *e);
  687. /* This function stops bulk import. The pblock must contain
  688. SLAPI_CONNECTION -- connection over which bulk import is coming
  689. SLAPI_BACKEND -- the backend being imported
  690. or
  691. SLAPI_TARGET_DN that contains root of the imported area.
  692. The function returns LDAP_SUCCESS or LDAP error code
  693. */
  694. int slapi_stop_bulk_import (Slapi_PBlock *pb);
  695. /* allows plugins to close inbound connection */
  696. void slapi_disconnect_server(Slapi_Connection *conn);
  697. /* functions to look up instance names by suffixes (backend_manager.c) */
  698. int slapi_lookup_instance_name_by_suffixes(char **included,
  699. char **excluded, char ***instances);
  700. int slapi_lookup_instance_name_by_suffix(char *suffix,
  701. char ***suffixes, char ***instances, int isexact);
  702. /* begin and end the task subsystem */
  703. void task_init(void);
  704. void task_shutdown(void);
  705. void task_cleanup(void);
  706. /* for reversible encyrption */
  707. #define SLAPI_MB_CREDENTIALS "nsmultiplexorcredentials"
  708. #define SLAPI_REP_CREDENTIALS "nsds5ReplicaCredentials"
  709. int pw_rever_encode(Slapi_Value **vals, char * attr_name);
  710. int pw_rever_decode(char *cipher, char **plain, const char * attr_name);
  711. /* config routines */
  712. int slapi_config_get_readonly();
  713. int slapi_config_get_unhashed_pw_switch();
  714. /*
  715. * charray.c
  716. */
  717. void charray_add( char ***a, char *s );
  718. void charray_merge( char ***a, char **s, int copy_strs );
  719. void charray_merge_nodup( char ***a, char **s, int copy_strs );
  720. void charray_free( char **array );
  721. int charray_inlist( char **a, char *s );
  722. int charray_utf8_inlist( char **a, char *s );
  723. char ** charray_dup( char **a );
  724. int charray_remove(char **a, const char *s, int freeit);
  725. char ** cool_charray_dup( char **a );
  726. void cool_charray_free( char **array );
  727. void charray_subtract( char **a, char **b, char ***c );
  728. int charray_get_index(char **array, char *s);
  729. int charray_normdn_add(char ***chararray, char *dn, char *errstr);
  730. /******************************************************************************
  731. * value array routines.
  732. *
  733. * It is unclear if these should ever be public, but today they are used by
  734. * some plugins. They would need to be renamed to have a slapi_ prefix at
  735. * the very least before we make them public.
  736. */
  737. void valuearray_add_value(Slapi_Value ***vals, const Slapi_Value *addval);
  738. void valuearray_add_valuearray( Slapi_Value ***vals, Slapi_Value **addvals, PRUint32 flags );
  739. void valuearray_add_valuearray_fast( Slapi_Value ***vals, Slapi_Value **addvals, int nvals, int naddvals, int *maxvals, int exact, int passin );
  740. Slapi_Value * valueset_find_sorted (const Slapi_Attr *a, const Slapi_ValueSet *vs, const Slapi_Value *v, int *index);
  741. int valueset_insert_value_to_sorted(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *vi, int dupcheck);
  742. void valueset_array_to_sorted (const Slapi_Attr *a, Slapi_ValueSet *vs);
  743. 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);
  744. int valuearray_find(const Slapi_Attr *a, Slapi_Value **va, const Slapi_Value *v);
  745. int valuearray_dn_normalize_value(Slapi_Value **vals);
  746. /*
  747. * proxyauth.c
  748. */
  749. int proxyauth_get_dn( Slapi_PBlock *pb, char **proxydnp, char **errtextp );
  750. /******************************************************************************
  751. * Database plugin interface.
  752. *
  753. * Prior to the 5.0 release, this was a public interface that lived in
  754. * slapi-plugin.h, so it is still a good idea to avoid making changes to it
  755. * that are not backwards compatible.
  756. */
  757. /* plugin type */
  758. #define SLAPI_PLUGIN_DATABASE 1
  759. /* database plugin functions */
  760. #define SLAPI_PLUGIN_DB_BIND_FN 200
  761. #define SLAPI_PLUGIN_DB_UNBIND_FN 201
  762. #define SLAPI_PLUGIN_DB_SEARCH_FN 202
  763. #define SLAPI_PLUGIN_DB_COMPARE_FN 203
  764. #define SLAPI_PLUGIN_DB_MODIFY_FN 204
  765. #define SLAPI_PLUGIN_DB_MODRDN_FN 205
  766. #define SLAPI_PLUGIN_DB_ADD_FN 206
  767. #define SLAPI_PLUGIN_DB_DELETE_FN 207
  768. #define SLAPI_PLUGIN_DB_ABANDON_FN 208
  769. #define SLAPI_PLUGIN_DB_CONFIG_FN 209
  770. #define SLAPI_PLUGIN_DB_FLUSH_FN 211
  771. #define SLAPI_PLUGIN_DB_SEQ_FN 213
  772. #define SLAPI_PLUGIN_DB_ENTRY_FN 214
  773. #define SLAPI_PLUGIN_DB_REFERRAL_FN 215
  774. #define SLAPI_PLUGIN_DB_RESULT_FN 216
  775. #define SLAPI_PLUGIN_DB_LDIF2DB_FN 217
  776. #define SLAPI_PLUGIN_DB_DB2LDIF_FN 218
  777. #define SLAPI_PLUGIN_DB_BEGIN_FN 219
  778. #define SLAPI_PLUGIN_DB_COMMIT_FN 220
  779. #define SLAPI_PLUGIN_DB_ABORT_FN 221
  780. #define SLAPI_PLUGIN_DB_ARCHIVE2DB_FN 222
  781. #define SLAPI_PLUGIN_DB_DB2ARCHIVE_FN 223
  782. #define SLAPI_PLUGIN_DB_NEXT_SEARCH_ENTRY_FN 224
  783. #define SLAPI_PLUGIN_DB_FREE_RESULT_SET_FN 225
  784. #define SLAPI_PLUGIN_DB_SIZE_FN 226
  785. #define SLAPI_PLUGIN_DB_TEST_FN 227
  786. #define SLAPI_PLUGIN_DB_DB2INDEX_FN 228
  787. #define SLAPI_PLUGIN_DB_NEXT_SEARCH_ENTRY_EXT_FN 229
  788. #define SLAPI_PLUGIN_DB_ENTRY_RELEASE_FN 230
  789. #define SLAPI_PLUGIN_DB_INIT_INSTANCE_FN 231
  790. #define SLAPI_PLUGIN_DB_WIRE_IMPORT_FN 234
  791. #define SLAPI_PLUGIN_DB_UPGRADEDB_FN 235
  792. #define SLAPI_PLUGIN_DB_DBVERIFY_FN 236
  793. #define SLAPI_PLUGIN_DB_ADD_SCHEMA_FN 237
  794. #define SLAPI_PLUGIN_DB_SEARCH_RESULTS_RELEASE_FN 238
  795. #define SLAPI_PLUGIN_DB_PREV_SEARCH_RESULTS_FN 239
  796. #define SLAPI_PLUGIN_DB_UPGRADEDNFORMAT_FN 240
  797. /* database plugin-specific parameters */
  798. #define SLAPI_PLUGIN_DB_NO_ACL 250
  799. #define SLAPI_PLUGIN_DB_RMDB_FN 280
  800. #define SLAPI_PLUGIN_DB_GET_INFO_FN 290
  801. #define SLAPI_PLUGIN_DB_SET_INFO_FN 291
  802. #define SLAPI_PLUGIN_DB_CTRL_INFO_FN 292
  803. /**** End of database plugin interface. **************************************/
  804. /******************************************************************************
  805. * Interface to the UniqueID generator (uniqueid.c)
  806. *
  807. * This could be made public someday, although it is a large interface and
  808. * not all of the elements follow the SLAPI_ naming convention.
  809. */
  810. /* error codes */
  811. #define UID_UPDATE_SHUTDOWN -1 /* update state information only during server shutdown */
  812. #define UID_UPDATE_INTERVAL 600000 /* 10 minutes */
  813. enum {UID_SUCCESS, /* operation was successfull */
  814. UID_ERROR_BASE=10,/* start of the error codes */
  815. UID_BADDATA, /* invalid parameter passed to a function */
  816. UID_MEMORY_ERROR, /* memory allocation failed */
  817. UID_SYSTEM_ERROR, /* I/O failed (currently, further details
  818. can be obtained using PR_GetError */
  819. UID_TIME_ERROR, /* UUID can't be generated because system
  820. time has not been update */
  821. UID_ERROR_END /* end of the error codes */
  822. };
  823. /* Function: slapi_uniqueIDNew
  824. Description: allocates new id
  825. Paramters: none
  826. Return: pointer to the newly allocated id if successful
  827. NULL if the system is out of memory
  828. */
  829. Slapi_UniqueID* slapi_uniqueIDNew( void );
  830. /* Function: slapi_uniqueIDDestroy
  831. Description: destroys UniqueID object and sets its pointer to NULL
  832. Parameters: uId - id to destroy
  833. Return: none
  834. */
  835. void slapi_uniqueIDDestroy(Slapi_UniqueID **uId);
  836. /* Function: slapi_uniqueIDCompare
  837. Description: this function compares two ids (byte by byte).
  838. Parameters: uId1, uId2 - ids to compare
  839. Return: -1 if uId1 < uId2
  840. 0 if uId2 == uId2
  841. 1 if uId2 > uId2
  842. UID_BADDATA if invalid pointer passed to the function
  843. */
  844. int slapi_uniqueIDCompare(const Slapi_UniqueID *uId1, const Slapi_UniqueID *uId2);
  845. int slapi_uniqueIDCompareString(const char *uuid1, const char *uuid2);
  846. /* Function: slapi_uniqueIDFormat
  847. Description: this function converts entryId to its string representation.
  848. The id format is HH-HHHHHHHH-HHHHHHHH-HHHHHHHH-HHHHHHHH
  849. where H is a hex digit.
  850. Parameters: uId - unique id
  851. buff - buffer in which id is returned;
  852. Return: UID_SUCCESS - function was successfull
  853. UID_BADDATA - invalid parameter passed to the function
  854. */
  855. int slapi_uniqueIDFormat(const Slapi_UniqueID *uId, char **buff);
  856. /* Function: slapi_uniqueIDScan
  857. Description: this function converts a string buffer into uniqueID.
  858. Currently, it only supports
  859. HH-HHHHHHHH-HHHHHHHH-HHHHHHHH-HHHHHHHH data format.
  860. Parameters: uId - unique id to be returned
  861. buff - buffer with uniqueID.
  862. Return: UID_SUCCESS - function was successfull
  863. UID_BADDATA - null parameter(s) or bad format
  864. */
  865. int slapi_uniqueIDScan(Slapi_UniqueID *uId, const char *buff);
  866. /* Function: slapi_uniqueIDIsUUID
  867. Description: tests if given entry id is of UUID type
  868. Parameters: uId - unique id to test
  869. Return UID_SUCCESS - function was successfull
  870. UID_BADDATA - invalid data passed to the function
  871. */
  872. int slapi_uniqueIDIsUUID(const Slapi_UniqueID *uId);
  873. /* Name: slapi_uniqueIDSize
  874. Description: returns size of the string version of uniqueID in bytes
  875. Parameters: none
  876. Return: size of the string version of uniqueID in bytes
  877. */
  878. int slapi_uniqueIDSize( void );
  879. /* Name: slapi_uniqueIDDup
  880. Description: duplicates an UniqueID object
  881. Parameters: uId - id to duplicate
  882. Return: duplicate of the Id
  883. */
  884. Slapi_UniqueID* slapi_uniqueIDDup(Slapi_UniqueID *uId);
  885. /*
  886. * interface to UniqueID generator - uniqueidgen.c
  887. */
  888. /* Function: slapi_uniqueIDGenerate
  889. Description: this function generates uniqueid in a singlethreaded
  890. environment.
  891. Parameters: uId - buffer to receive the ID.
  892. Return: UID_SUCCESS if function succeeds;
  893. UID_BADDATA if invalid pointer passed to the function;
  894. UID_SYSTEM_ERROR update to persistent storage failed.
  895. */
  896. int slapi_uniqueIDGenerate(Slapi_UniqueID *uId);
  897. /* Function: slapi_uniqueIDGenerateString
  898. Description: this function generates uniqueid an returns it as a string
  899. in a singlethreaded environment. This function returns the
  900. data in the format generated by slapi_uniqueIDFormat.
  901. Parameters: uId - buffer to receive the ID. Caller is responsible for
  902. freeing uId buffer.
  903. Return: UID_SUCCESS if function succeeds;
  904. UID_BADDATA if invalid pointer passed to the function;
  905. UID_MEMORY_ERROR if malloc fails;
  906. UID_SYSTEM_ERROR update to persistent storage failed.
  907. */
  908. int slapi_uniqueIDGenerateString(char **uId);
  909. /* Function: slapi_uniqueIDGenerateMT
  910. Description: this function generates entry id in a multithreaded
  911. environment. Used in conjunction with
  912. uniqueIDUpdateState function.
  913. Parameters: uId - structure in which new id will be returned.
  914. Return: UID_SUCCESS if function succeeds;
  915. UID_BADDATA if invalid pointer passed to the function;
  916. UID_TIME_ERROR uniqueIDUpdateState must be called
  917. before the id can be generated.
  918. */
  919. int slapi_uniqueIDGenerateMT(Slapi_UniqueID *uId);
  920. /* Function: slapi_uniqueIDGenerateMTString
  921. Description: this function generates uniqueid and returns it as a
  922. string in a multithreaded environment. Used in conjunction
  923. with uniqueIDUpdateState function.
  924. Parameters: uId - buffer in which new id will be returned. Caller is
  925. responsible for freeing uId buffer.
  926. Return: UID_SUCCESS if function succeeds;
  927. UID_BADDATA if invalid pointer passed to the function;
  928. UID_MEMORY_ERROR if malloc fails;
  929. UID_TIME_ERROR uniqueIDUpdateState must be called
  930. before the id can be generated.
  931. */
  932. int slapi_uniqueIDGenerateMTString(char **uId);
  933. /* Function: slapi_uniqueIDGenerateFromName
  934. Description: this function generates an id from a name. See uuid
  935. draft for more details. This function can be used in
  936. both a singlethreaded and a multithreaded environments.
  937. Parameters: uId - generated id
  938. uIDBase - uid used for generation to distinguish among
  939. different name spaces
  940. name - buffer containing name from which to generate the id
  941. namelen - length of the name buffer
  942. Return: UID_SUCCESS if function succeeds
  943. UID_BADDATA if invalid argument is passed to the
  944. function.
  945. */
  946. int slapi_uniqueIDGenerateFromName(Slapi_UniqueID *uId,
  947. const Slapi_UniqueID *uIdBase,
  948. const void *name, int namelen);
  949. /* Function: slapi_uniqueIDGenerateFromName
  950. Description: this function generates an id from a name and returns
  951. it in the string format. See uuid draft for more
  952. details. This function can be used in both a
  953. singlethreaded and a multithreaded environments.
  954. Parameters: uId - generated id in string form
  955. uIDBase - uid used for generation to distinguish among
  956. different name spaces in string form. NULL means to use
  957. empty id as the base.
  958. name - buffer containing name from which to generate the id
  959. namelen - length of the name buffer
  960. Return: UID_SUCCESS if function succeeds
  961. UID_BADDATA if invalid argument is passed to the
  962. function.
  963. */
  964. int slapi_uniqueIDGenerateFromNameString(char **uId,
  965. const char *uIdBase,
  966. const void *name, int namelen);
  967. /**** End of UniqueID generator interface. ***********************************/
  968. /*****************************************************************************
  969. * JCMREPL - Added for the replication plugin.
  970. */
  971. void schema_expand_objectclasses_nolock( Slapi_Entry *e );
  972. #define DSE_SCHEMA_NO_LOAD 0x0001 /* schema won't get loaded */
  973. #define DSE_SCHEMA_NO_CHECK 0x0002 /* schema won't be checked */
  974. #define DSE_SCHEMA_NO_BACKEND 0x0004 /* don't add as backend */
  975. #define DSE_SCHEMA_NO_GLOCK 0x0010 /* don't lock global resources */
  976. #define DSE_SCHEMA_LOCKED 0x0020 /* already locked with
  977. * reload_schemafile_lock;
  978. * no further lock needed */
  979. #define DSE_SCHEMA_USER_DEFINED_ONLY 0x0100 /* refresh user defined schema */
  980. #define SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY 0
  981. #define SLAPI_RTN_BIT_FETCH_PARENT_ENTRY 1
  982. #define SLAPI_RTN_BIT_FETCH_NEWPARENT_ENTRY 2
  983. #define SLAPI_RTN_BIT_FETCH_TARGET_ENTRY 3
  984. #define SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY 4
  985. /* Attribute use to mark entries that had a replication conflict on the DN */
  986. #define ATTR_NSDS5_REPLCONFLICT "nsds5ReplConflict"
  987. /* Time */
  988. #include <time.h> /* difftime, localtime_r, mktime */
  989. /* Duplicated: time_t read_localTime (struct berval* from); */
  990. time_t time_plus_sec(time_t l, long r);
  991. char* format_localTime(time_t from);
  992. time_t read_localTime(struct berval* from);
  993. time_t parse_localTime(char* from);
  994. void write_localTime(time_t from, struct berval* into);
  995. time_t current_time( void );
  996. char* format_genTime(time_t from);
  997. void write_genTime(time_t from, struct berval* into);
  998. time_t read_genTime(struct berval* from);
  999. time_t parse_genTime(char* from);
  1000. long parse_duration(char *value);
  1001. char *gen_duration(long duration);
  1002. /* Client SSL code */
  1003. int slapd_security_library_is_initialized( void );
  1004. int slapd_nss_is_initialized( void );
  1005. char* slapd_get_tmp_dir( void );
  1006. /* util.c */
  1007. #include <stdio.h> /* GGOODREPL - For BUFSIZ, below, gak */
  1008. const char* escape_string (const char* str, char buf[BUFSIZ]);
  1009. const char* escape_string_with_punctuation(const char* str, char buf[BUFSIZ]);
  1010. void strcpy_unescape_value( char *d, const char *s );
  1011. char *slapi_berval_get_string_copy(const struct berval *bval);
  1012. /* lenstr stuff */
  1013. typedef struct _lenstr {
  1014. char *ls_buf;
  1015. size_t ls_len;
  1016. size_t ls_maxlen;
  1017. } lenstr;
  1018. #define LS_INCRSIZE 256
  1019. void addlenstr( lenstr *l, const char *str );
  1020. void lenstr_free( lenstr ** );
  1021. lenstr *lenstr_new(void);
  1022. /* config DN */
  1023. char *get_config_DN(void);
  1024. /* Data Version */
  1025. const char *get_server_dataversion( void );
  1026. /* Configuration Parameters */
  1027. int config_get_port( void );
  1028. int config_get_secureport( void );
  1029. /* Local host information */
  1030. char* get_localhost_DN( void );
  1031. char* get_localhost_DNS( void );
  1032. /* GGOODREPL get_data_source definition should move into repl DLL */
  1033. struct berval **get_data_source(Slapi_PBlock *pb, const Slapi_DN *sdn, int orc, void *cf_refs);
  1034. /* JCMREPL - IFP and CFP should be defined centrally */
  1035. #ifndef _IFP
  1036. #define _IFP
  1037. typedef int (*IFP)();
  1038. #endif
  1039. #ifndef _CFP
  1040. #define _CFP
  1041. typedef char*(*CFP)();
  1042. #endif
  1043. void bervalarray_add_berval_fast(struct berval ***vals, const struct berval *addval, int nvals, int *maxvals);
  1044. /* this is the root configuration entry beneath which all plugin
  1045. configuration entries will be found */
  1046. #define PLUGIN_BASE_DN "cn=plugins,cn=config"
  1047. #define SLAPI_PLUGIN_DEFAULT_CONFIG "cn=plugin default config,cn=config"
  1048. /***** End of items added for the replication plugin. ***********************/
  1049. void DS_Sleep(PRIntervalTime ticks);
  1050. /* macro to specify the behavior of upgradedb & upgradednformat */
  1051. #define SLAPI_UPGRADEDB_FORCE 0x1 /* reindex all (no check w/ idl switch) */
  1052. #define SLAPI_UPGRADEDB_SKIPINIT 0x2 /* call upgradedb as part of other op */
  1053. #define SLAPI_UPGRADEDB_DN2RDN 0x4 /* modify id2entry from dn format to rdn;
  1054. generate entryrdn index */
  1055. #define SLAPI_UPGRADEDNFORMAT 0x8 /* specify this op is upgradednformat */
  1056. #define SLAPI_DRYRUN 0x10 /* dryrun mode for upgradednformat */
  1057. #define SLAPI_UPGRADEDNFORMAT_V1 0x20 /* taking care multipe spaces */
  1058. /*
  1059. * Macro to set port to the 'port' field of a NSPR PRNetAddr union.
  1060. ** INPUTS:
  1061. ** PRNetAddr *myaddr A network address.
  1062. ** PRUint16 myport port to set to the 'port' field of 'addr'.
  1063. ** RETURN: none
  1064. *
  1065. * Note: Copy from ldappr-int.h in
  1066. * ldapcsdk:mozilla/directory/c-sdk/ldap/libraries/libprldap
  1067. * Introduced to avoid calling PR_SetNetAddr w/ PR_IpAddrNull just to set port.
  1068. * Once NSPR starts providing better function/macro to do the same job,
  1069. * this macro should be replaced with it. (newer than NSPR v4.6.2)
  1070. */
  1071. #define PRLDAP_SET_PORT(myaddr,myport) \
  1072. ((myaddr)->raw.family == PR_AF_INET6 ? ((myaddr)->ipv6.port = PR_htons(myport)) : ((myaddr)->inet.port = PR_htons(myport)))
  1073. /* plugin.c */
  1074. int plugin_enabled(const char *plugin_name, void *identity);
  1075. /* protect_db.c */
  1076. /* is_slapd_running()
  1077. * returns 1 if slapd is running, 0 if not, -1 on error
  1078. */
  1079. int is_slapd_running();
  1080. /* attrsyntax.c */
  1081. int slapi_add_internal_attr_syntax( const char *name, const char *oid, const char *syntax, const char *mr_equality, unsigned long extraflags );
  1082. /* pw.c */
  1083. void pw_exp_init ( void );
  1084. int pw_copy_entry_ext(Slapi_Entry *src_e, Slapi_Entry *dest_e);
  1085. /* op_shared.c */
  1086. void modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods);
  1087. /* add.c */
  1088. void add_internal_modifiersname(Slapi_PBlock *pb, Slapi_Entry *e);
  1089. #ifdef __cplusplus
  1090. }
  1091. #endif
  1092. #endif