slapi-private.h 46 KB

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