slapi-private.h 48 KB

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