s3:rpc_server: Initialize array
[Samba.git] / lib / ldb / include / ldb.h
blobf2d4642375f3b2bf916d037260a767ea4ba2c5ef
1 /*
2 ldb database library
4 Copyright (C) Andrew Tridgell 2004
5 Copyright (C) Stefan Metzmacher 2004
6 Copyright (C) Simo Sorce 2005-2006
8 ** NOTE! The following LGPL license applies to the ldb
9 ** library. This does NOT imply that all of Samba is released
10 ** under the LGPL
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Lesser General Public
14 License as published by the Free Software Foundation; either
15 version 3 of the License, or (at your option) any later version.
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public
23 License along with this library; if not, see <http://www.gnu.org/licenses/>.
27 * Name: ldb
29 * Component: ldb header
31 * Description: defines for base ldb API
33 * Author: Andrew Tridgell
34 * Author: Stefan Metzmacher
37 /**
38 \file ldb.h Samba's ldb database
40 This header file provides the main API for ldb.
43 #ifndef _LDB_H_
45 /*! \cond DOXYGEN_IGNORE */
46 #define _LDB_H_ 1
47 /*! \endcond */
49 #include <stdbool.h>
50 #include <talloc.h>
51 #include <tevent.h>
52 #include <ldb_version.h>
53 #include <ldb_errors.h>
56 major restrictions as compared to normal LDAP:
58 - each record must have a unique key field
59 - the key must be representable as a NULL terminated C string and may not
60 contain a comma or braces
62 major restrictions as compared to tdb:
64 - no explicit locking calls, but we have transactions when using ldb_tdb
68 #ifndef ldb_val
69 /**
70 Result value
72 An individual lump of data in a result comes in this format. The
73 pointer will usually be to a UTF-8 string if the application is
74 sensible, but it can be to anything you like, including binary data
75 blobs of arbitrary size.
77 \note the data is null (0x00) terminated, but the length does not
78 include the terminator.
80 struct ldb_val {
81 uint8_t *data; /*!< result data */
82 size_t length; /*!< length of data */
84 #endif
86 /*! \cond DOXYGEN_IGNORE */
87 #ifndef PRINTF_ATTRIBUTE
88 #define PRINTF_ATTRIBUTE(a,b)
89 #endif
91 #ifndef _DEPRECATED_
92 #if __has_attribute(deprecated) || ( (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) )
93 #define _DEPRECATED_ __attribute__ ((deprecated))
94 #else
95 #define _DEPRECATED_
96 #endif
97 #endif
98 /*! \endcond */
100 /* opaque ldb_dn structures, see ldb_dn.c for internals */
101 struct ldb_dn_component;
102 struct ldb_dn;
105 There are a number of flags that are used with ldap_modify() in
106 ldb_message_element.flags fields. The LDB_FLAG_MOD_ADD,
107 LDB_FLAG_MOD_DELETE and LDB_FLAG_MOD_REPLACE are better thought of as
108 an enumeration, not flags, and are used in ldap_modify() calls to
109 specify whether attributes are being added, deleted or modified
110 respectively.
112 #define LDB_FLAG_MOD_MASK 0x3
115 use this to extract the mod type (enum) from the operation
117 #define LDB_FLAG_MOD_TYPE(flags) ((flags) & LDB_FLAG_MOD_MASK)
120 Value used in ldap_modify() to indicate that attributes are
121 being added.
123 \sa LDB_FLAG_MOD_MASK
125 #define LDB_FLAG_MOD_ADD 1
128 Value used in ldap_modify() to indicate that attributes are
129 being replaced.
131 \sa LDB_FLAG_MOD_MASK
133 #define LDB_FLAG_MOD_REPLACE 2
136 Value used in ldap_modify() to indicate that attributes are
137 being deleted.
139 \sa LDB_FLAG_MOD_MASK
141 #define LDB_FLAG_MOD_DELETE 3
144 Flag value used in ldb_ldif_write_trace() to enforce binary encoded
145 attribute values per attribute.
147 This is a genuine flag, being outside LDB_FLAG_MOD_MASK and also
148 outside LDB_FLAG_INTERNAL_MASK
150 #define LDB_FLAG_FORCE_NO_BASE64_LDIF 4
153 flag bits on an element usable only by the internal implementation
155 #define LDB_FLAG_INTERNAL_MASK 0xFFFFFFF0
158 OID for logic AND comparison.
160 This is the well known object ID for a logical AND comparator.
162 #define LDB_OID_COMPARATOR_AND "1.2.840.113556.1.4.803"
165 OID for logic OR comparison.
167 This is the well known object ID for a logical OR comparator.
169 #define LDB_OID_COMPARATOR_OR "1.2.840.113556.1.4.804"
172 results are given back as arrays of ldb_message_element
174 struct ldb_message_element {
175 unsigned int flags;
176 const char *name;
177 unsigned int num_values;
178 struct ldb_val *values;
183 a ldb_message represents all or part of a record. It can contain an arbitrary
184 number of elements.
186 struct ldb_message {
187 struct ldb_dn *dn;
188 unsigned int num_elements;
189 struct ldb_message_element *elements;
192 enum ldb_changetype {
193 LDB_CHANGETYPE_NONE=0,
194 LDB_CHANGETYPE_ADD,
195 LDB_CHANGETYPE_DELETE,
196 LDB_CHANGETYPE_MODIFY,
197 LDB_CHANGETYPE_MODRDN
201 LDIF record
203 This structure contains a LDIF record, as returned from ldif_read()
204 and equivalent functions.
206 struct ldb_ldif {
207 enum ldb_changetype changetype; /*!< The type of change */
208 struct ldb_message *msg; /*!< The changes */
211 enum ldb_scope {LDB_SCOPE_DEFAULT=-1,
212 LDB_SCOPE_BASE=0,
213 LDB_SCOPE_ONELEVEL=1,
214 LDB_SCOPE_SUBTREE=2};
216 struct ldb_context;
217 struct tevent_context;
219 /* debugging uses one of the following levels */
220 enum ldb_debug_level {LDB_DEBUG_FATAL, LDB_DEBUG_ERROR,
221 LDB_DEBUG_WARNING, LDB_DEBUG_TRACE};
223 /* alias for something that's not a fatal error but we really want to log */
224 #define LDB_DEBUG_ALWAYS_LOG LDB_DEBUG_FATAL
227 Flag value for database connection mode.
229 If LDB_FLG_RDONLY is used in ldb_connect, then the database will be
230 opened read-only, if possible.
232 #define LDB_FLG_RDONLY 1
235 Flag value for database connection mode.
237 If LDB_FLG_NOSYNC is used in ldb_connect, then the database will be
238 opened without synchronous operations, if possible.
240 #define LDB_FLG_NOSYNC 2
243 Flag value to specify autoreconnect mode.
245 If LDB_FLG_RECONNECT is used in ldb_connect, then the backend will
246 be opened in a way that makes it try to auto reconnect if the
247 connection is dropped (actually make sense only with ldap).
249 #define LDB_FLG_RECONNECT 4
252 Flag to tell backends not to use mmap
254 #define LDB_FLG_NOMMAP 8
257 Flag to tell ldif handlers not to force encoding of binary
258 structures in base64
260 #define LDB_FLG_SHOW_BINARY 16
263 Flags to enable ldb tracing
265 #define LDB_FLG_ENABLE_TRACING 32
268 Flags to tell LDB not to create a new database file:
270 Without this flag ldb_tdb (for example) will create a blank file
271 during an invocation of ldb_connect(), even when the caller only
272 wanted read operations, for example in ldbsearch.
274 #define LDB_FLG_DONT_CREATE_DB 64
277 * Allow DB create time flags that have meaning only to our
278 * calling application or modules. These must be in this range:
280 #define LDB_FLG_PRIVATE_MASK 0xff000000
283 structures for ldb_parse_tree handling code
285 enum ldb_parse_op { LDB_OP_AND=1, LDB_OP_OR=2, LDB_OP_NOT=3,
286 LDB_OP_EQUALITY=4, LDB_OP_SUBSTRING=5,
287 LDB_OP_GREATER=6, LDB_OP_LESS=7, LDB_OP_PRESENT=8,
288 LDB_OP_APPROX=9, LDB_OP_EXTENDED=10 };
290 struct ldb_parse_tree {
291 enum ldb_parse_op operation;
292 union {
293 struct {
294 struct ldb_parse_tree *child;
295 } isnot;
296 struct {
297 const char *attr;
298 struct ldb_val value;
299 } equality;
300 struct {
301 const char *attr;
302 int start_with_wildcard;
303 int end_with_wildcard;
304 struct ldb_val **chunks;
305 } substring;
306 struct {
307 const char *attr;
308 } present;
309 struct {
310 const char *attr;
311 struct ldb_val value;
312 } comparison;
313 struct {
314 const char *attr;
315 int dnAttributes;
316 const char *rule_id;
317 struct ldb_val value;
318 } extended;
319 struct {
320 unsigned int num_elements;
321 struct ldb_parse_tree **elements;
322 } list;
323 } u;
326 struct ldb_parse_tree *ldb_parse_tree(TALLOC_CTX *mem_ctx, const char *s);
327 char *ldb_filter_from_tree(TALLOC_CTX *mem_ctx, const struct ldb_parse_tree *tree);
330 Encode a binary blob
332 This function encodes a binary blob using the encoding rules in RFC
333 2254 (Section 4). This function also escapes any non-printable
334 characters.
336 \param mem_ctx the memory context to allocate the return string in.
337 \param val the (potentially) binary data to be encoded
339 \return the encoded data as a null terminated string
341 \sa <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>.
343 char *ldb_binary_encode(TALLOC_CTX *mem_ctx, struct ldb_val val);
346 Encode a string
348 This function encodes a string using the encoding rules in RFC 2254
349 (Section 4). This function also escapes any non-printable
350 characters.
352 \param mem_ctx the memory context to allocate the return string in.
353 \param string the string to be encoded
355 \return the encoded data as a null terminated string
357 \sa <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>.
359 char *ldb_binary_encode_string(TALLOC_CTX *mem_ctx, const char *string);
362 functions for controlling attribute handling
364 typedef int (*ldb_attr_handler_t)(struct ldb_context *, TALLOC_CTX *mem_ctx, const struct ldb_val *, struct ldb_val *);
365 typedef int (*ldb_attr_comparison_t)(struct ldb_context *, TALLOC_CTX *mem_ctx, const struct ldb_val *, const struct ldb_val *);
366 struct ldb_schema_attribute;
367 typedef int (*ldb_attr_operator_t)(struct ldb_context *, enum ldb_parse_op operation,
368 const struct ldb_schema_attribute *a,
369 const struct ldb_val *, const struct ldb_val *, bool *matched);
372 attribute handler structure
374 attr -> The attribute name
375 ldif_read_fn -> convert from ldif to binary format
376 ldif_write_fn -> convert from binary to ldif format
377 canonicalise_fn -> canonicalise a value, for use by indexing and dn construction
378 index_form_fn -> get lexicographically sorted format for index
379 comparison_fn -> compare two values
380 operator_fn -> override function for optimizing out unnecessary
381 calls to canonicalise_fn and comparison_fn
384 struct ldb_schema_syntax {
385 const char *name;
386 ldb_attr_handler_t ldif_read_fn;
387 ldb_attr_handler_t ldif_write_fn;
388 ldb_attr_handler_t canonicalise_fn;
389 ldb_attr_handler_t index_format_fn;
390 ldb_attr_comparison_t comparison_fn;
391 ldb_attr_operator_t operator_fn;
394 struct ldb_schema_attribute {
395 const char *name;
396 unsigned flags;
397 const struct ldb_schema_syntax *syntax;
400 const struct ldb_schema_attribute *ldb_schema_attribute_by_name(struct ldb_context *ldb,
401 const char *name);
403 struct ldb_dn_extended_syntax {
404 const char *name;
405 ldb_attr_handler_t read_fn;
406 ldb_attr_handler_t write_clear_fn;
407 ldb_attr_handler_t write_hex_fn;
410 const struct ldb_dn_extended_syntax *ldb_dn_extended_syntax_by_name(struct ldb_context *ldb,
411 const char *name);
414 The attribute is not returned by default
416 #define LDB_ATTR_FLAG_HIDDEN (1<<0)
418 /* the attribute handler name should be freed when released */
419 #define LDB_ATTR_FLAG_ALLOCATED (1<<1)
422 The attribute is supplied by the application and should not be removed
424 #define LDB_ATTR_FLAG_FIXED (1<<2)
427 when this is set, attempts to create two records which have the same
428 value for this attribute will return LDB_ERR_ENTRY_ALREADY_EXISTS
430 #define LDB_ATTR_FLAG_UNIQUE_INDEX (1<<3)
433 when this is set, attempts to create two attribute values for this attribute on a single DN will return LDB_ERR_CONSTRAINT_VIOLATION
435 #define LDB_ATTR_FLAG_SINGLE_VALUE (1<<4)
438 * The values should always be base64 encoded
440 #define LDB_ATTR_FLAG_FORCE_BASE64_LDIF (1<<5)
443 * The attribute was loaded from a DB, rather than via the C API
445 #define LDB_ATTR_FLAG_FROM_DB (1<<6)
448 * The attribute is indexed
450 #define LDB_ATTR_FLAG_INDEXED (1<<7)
453 LDAP attribute syntax for a DN
455 This is the well-known LDAP attribute syntax for a DN.
457 See <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>, Section 4.3.2
459 #define LDB_SYNTAX_DN "1.3.6.1.4.1.1466.115.121.1.12"
462 LDAP attribute syntax for a Directory String
464 This is the well-known LDAP attribute syntax for a Directory String.
466 \sa <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>, Section 4.3.2
468 #define LDB_SYNTAX_DIRECTORY_STRING "1.3.6.1.4.1.1466.115.121.1.15"
471 LDAP attribute syntax for an integer
473 This is the well-known LDAP attribute syntax for an integer.
475 See <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>, Section 4.3.2
477 #define LDB_SYNTAX_INTEGER "1.3.6.1.4.1.1466.115.121.1.27"
480 Custom attribute syntax for an integer whose index is lexicographically
481 ordered by attribute value in the database.
483 #define LDB_SYNTAX_ORDERED_INTEGER "LDB_SYNTAX_ORDERED_INTEGER"
486 LDAP attribute syntax for a boolean
488 This is the well-known LDAP attribute syntax for a boolean.
490 See <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>, Section 4.3.2
492 #define LDB_SYNTAX_BOOLEAN "1.3.6.1.4.1.1466.115.121.1.7"
495 LDAP attribute syntax for an octet string
497 This is the well-known LDAP attribute syntax for an octet string.
499 See <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>, Section 4.3.2
501 #define LDB_SYNTAX_OCTET_STRING "1.3.6.1.4.1.1466.115.121.1.40"
504 LDAP attribute syntax for UTC time.
506 This is the well-known LDAP attribute syntax for a UTC time.
508 See <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>, Section 4.3.2
510 #define LDB_SYNTAX_UTC_TIME "1.3.6.1.4.1.1466.115.121.1.53"
511 #define LDB_SYNTAX_GENERALIZED_TIME "1.3.6.1.4.1.1466.115.121.1.24"
513 #define LDB_SYNTAX_OBJECTCLASS "LDB_SYNTAX_OBJECTCLASS"
515 /* sorting helpers */
516 typedef int (*ldb_qsort_cmp_fn_t) (void *v1, void *v2, void *opaque);
518 /* Individual controls */
521 OID for getting and manipulating attributes from the ldb
522 without interception in the operational module.
523 It can be used to access attribute that used to be stored in the sam
524 and that are now calculated.
526 #define LDB_CONTROL_BYPASS_OPERATIONAL_OID "1.3.6.1.4.1.7165.4.3.13"
527 #define LDB_CONTROL_BYPASS_OPERATIONAL_NAME "bypassoperational"
530 OID for recalculate RDN (rdn attribute and 'name') control. This control forces
531 the rdn_name module to the recalculate the rdn and name attributes as if the
532 object was just created.
534 #define LDB_CONTROL_RECALCULATE_RDN_OID "1.3.6.1.4.1.7165.4.3.30"
537 OID for recalculate SD control. This control force the
538 dsdb code to recalculate the SD of the object as if the
539 object was just created.
542 #define LDB_CONTROL_RECALCULATE_SD_OID "1.3.6.1.4.1.7165.4.3.5"
543 #define LDB_CONTROL_RECALCULATE_SD_NAME "recalculate_sd"
546 REVEAL_INTERNALS is used to reveal internal attributes and DN
547 components which are not normally shown to the user
549 #define LDB_CONTROL_REVEAL_INTERNALS "1.3.6.1.4.1.7165.4.3.6"
550 #define LDB_CONTROL_REVEAL_INTERNALS_NAME "reveal_internals"
553 LDB_CONTROL_AS_SYSTEM is used to skip access checks on operations
554 that are performed by the system, but with a user's credentials, e.g.
555 updating prefix map
557 #define LDB_CONTROL_AS_SYSTEM_OID "1.3.6.1.4.1.7165.4.3.7"
560 LDB_CONTROL_PROVISION_OID is used to skip some constraint checks. It's is
561 mainly thought to be used for the provisioning.
563 #define LDB_CONTROL_PROVISION_OID "1.3.6.1.4.1.7165.4.3.16"
564 #define LDB_CONTROL_PROVISION_NAME "provision"
566 /* AD controls */
569 OID for the paged results control. This control is included in the
570 searchRequest and searchResultDone messages as part of the controls
571 field of the LDAPMessage, as defined in Section 4.1.12 of
572 LDAP v3.
574 \sa <a href="http://www.ietf.org/rfc/rfc2696.txt">RFC 2696</a>.
576 #define LDB_CONTROL_PAGED_RESULTS_OID "1.2.840.113556.1.4.319"
577 #define LDB_CONTROL_PAGED_RESULTS_NAME "paged_results"
580 OID for specifying the returned elements of the ntSecurityDescriptor
582 \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_sd_flags_oid.asp">Microsoft documentation of this OID</a>
584 #define LDB_CONTROL_SD_FLAGS_OID "1.2.840.113556.1.4.801"
585 #define LDB_CONTROL_SD_FLAGS_NAME "sd_flags"
588 OID for specifying an advanced scope for the search (one partition)
590 \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_domain_scope_oid.asp">Microsoft documentation of this OID</a>
592 #define LDB_CONTROL_DOMAIN_SCOPE_OID "1.2.840.113556.1.4.1339"
593 #define LDB_CONTROL_DOMAIN_SCOPE_NAME "domain_scope"
596 OID for specifying an advanced scope for a search
598 \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_search_options_oid.asp">Microsoft documentation of this OID</a>
600 #define LDB_CONTROL_SEARCH_OPTIONS_OID "1.2.840.113556.1.4.1340"
601 #define LDB_CONTROL_SEARCH_OPTIONS_NAME "search_options"
604 OID for notification
606 \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_notification_oid.asp">Microsoft documentation of this OID</a>
608 #define LDB_CONTROL_NOTIFICATION_OID "1.2.840.113556.1.4.528"
609 #define LDB_CONTROL_NOTIFICATION_NAME "notification"
612 OID for performing subtree deletes
614 \sa <a href="http://msdn.microsoft.com/en-us/library/aa366991(v=VS.85).aspx">Microsoft documentation of this OID</a>
616 #define LDB_CONTROL_TREE_DELETE_OID "1.2.840.113556.1.4.805"
617 #define LDB_CONTROL_TREE_DELETE_NAME "tree_delete"
620 OID for getting deleted objects
622 \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_show_deleted_oid.asp">Microsoft documentation of this OID</a>
624 #define LDB_CONTROL_SHOW_DELETED_OID "1.2.840.113556.1.4.417"
625 #define LDB_CONTROL_SHOW_DELETED_NAME "show_deleted"
628 OID for getting recycled objects
630 \sa <a href="http://msdn.microsoft.com/en-us/library/dd304621(PROT.13).aspx">Microsoft documentation of this OID</a>
632 #define LDB_CONTROL_SHOW_RECYCLED_OID "1.2.840.113556.1.4.2064"
633 #define LDB_CONTROL_SHOW_RECYCLED_NAME "show_recycled"
636 OID for getting deactivated linked attributes
638 \sa <a href="http://msdn.microsoft.com/en-us/library/dd302781(PROT.13).aspx">Microsoft documentation of this OID</a>
640 #define LDB_CONTROL_SHOW_DEACTIVATED_LINK_OID "1.2.840.113556.1.4.2065"
641 #define LDB_CONTROL_SHOW_DEACTIVATED_LINK_NAME "show_deactivated_link"
644 OID for extended DN
646 \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_extended_dn_oid.asp">Microsoft documentation of this OID</a>
648 #define LDB_CONTROL_EXTENDED_DN_OID "1.2.840.113556.1.4.529"
649 #define LDB_CONTROL_EXTENDED_DN_NAME "extended_dn"
652 OID for LDAP server sort result extension.
654 This control is included in the searchRequest message as part of
655 the controls field of the LDAPMessage, as defined in Section 4.1.12
656 of LDAP v3. The controlType is set to
657 "1.2.840.113556.1.4.473". The criticality MAY be either TRUE or
658 FALSE (where absent is also equivalent to FALSE) at the client's
659 option.
661 \sa <a href="http://www.ietf.org/rfc/rfc2891.txt">RFC 2891</a>.
663 #define LDB_CONTROL_SERVER_SORT_OID "1.2.840.113556.1.4.473"
664 #define LDB_CONTROL_SERVER_SORT_NAME "server_sort"
667 OID for LDAP server sort result response extension.
669 This control is included in the searchResultDone message as part of
670 the controls field of the LDAPMessage, as defined in Section 4.1.12 of
671 LDAP v3.
673 \sa <a href="http://www.ietf.org/rfc/rfc2891.txt">RFC 2891</a>.
675 #define LDB_CONTROL_SORT_RESP_OID "1.2.840.113556.1.4.474"
676 #define LDB_CONTROL_SORT_RESP_NAME "server_sort_resp"
679 OID for LDAP Attribute Scoped Query extension.
681 This control is included in SearchRequest or SearchResponse
682 messages as part of the controls field of the LDAPMessage.
684 #define LDB_CONTROL_ASQ_OID "1.2.840.113556.1.4.1504"
685 #define LDB_CONTROL_ASQ_NAME "asq"
688 OID for LDAP Directory Sync extension.
690 This control is included in SearchRequest or SearchResponse
691 messages as part of the controls field of the LDAPMessage.
693 #define LDB_CONTROL_DIRSYNC_OID "1.2.840.113556.1.4.841"
694 #define LDB_CONTROL_DIRSYNC_NAME "dirsync"
695 #define LDB_CONTROL_DIRSYNC_EX_OID "1.2.840.113556.1.4.2090"
696 #define LDB_CONTROL_DIRSYNC_EX_NAME "dirsync_ex"
700 OID for LDAP Virtual List View Request extension.
702 This control is included in SearchRequest messages
703 as part of the controls field of the LDAPMessage.
705 #define LDB_CONTROL_VLV_REQ_OID "2.16.840.1.113730.3.4.9"
706 #define LDB_CONTROL_VLV_REQ_NAME "vlv"
709 OID for LDAP Virtual List View Response extension.
711 This control is included in SearchResponse messages
712 as part of the controls field of the LDAPMessage.
714 #define LDB_CONTROL_VLV_RESP_OID "2.16.840.1.113730.3.4.10"
715 #define LDB_CONTROL_VLV_RESP_NAME "vlv_resp"
718 OID to let modifies don't give an error when adding an existing
719 attribute with the same value or deleting an nonexisting one attribute
721 \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_permissive_modify_oid.asp">Microsoft documentation of this OID</a>
723 #define LDB_CONTROL_PERMISSIVE_MODIFY_OID "1.2.840.113556.1.4.1413"
724 #define LDB_CONTROL_PERMISSIVE_MODIFY_NAME "permissive_modify"
727 OID to allow the server to be more 'fast and loose' with the data being added.
729 \sa <a href="http://msdn.microsoft.com/en-us/library/aa366982(v=VS.85).aspx">Microsoft documentation of this OID</a>
731 #define LDB_CONTROL_SERVER_LAZY_COMMIT "1.2.840.113556.1.4.619"
734 Control for RODC join -see [MS-ADTS] section 3.1.1.3.4.1.23
736 \sa <a href="">Microsoft documentation of this OID</a>
738 #define LDB_CONTROL_RODC_DCPROMO_OID "1.2.840.113556.1.4.1341"
739 #define LDB_CONTROL_RODC_DCPROMO_NAME "rodc_join"
741 /* Other standardised controls */
744 OID for the allowing client to request temporary relaxed
745 enforcement of constraints of the x.500 model.
747 Mainly used for the OpenLDAP backend.
749 \sa <a href="http://opends.dev.java.net/public/standards/draft-zeilenga-ldap-managedit.txt">draft managedit</a>.
751 #define LDB_CONTROL_RELAX_OID "1.3.6.1.4.1.4203.666.5.12"
752 #define LDB_CONTROL_RELAX_NAME "relax"
755 OID for the allowing some kind of relax check for attributes with DNs
758 \sa 3.1.1.3.4.1.16 in [MS-ADTS].pdf
760 #define LDB_CONTROL_VERIFY_NAME_OID "1.2.840.113556.1.4.1338"
761 #define LDB_CONTROL_VERIFY_NAME_NAME "verify_name"
763 /* Extended operations */
766 OID for LDAP Extended Operation SEQUENCE_NUMBER
768 This extended operation is used to retrieve the extended sequence number.
770 #define LDB_EXTENDED_SEQUENCE_NUMBER "1.3.6.1.4.1.7165.4.4.3"
773 OID for LDAP Extended Operation PASSWORD_CHANGE.
775 This Extended operation is used to allow user password changes by the user
776 itself.
778 #define LDB_EXTENDED_PASSWORD_CHANGE_OID "1.3.6.1.4.1.4203.1.11.1"
782 OID for LDAP Extended Operation FAST_BIND
784 This Extended operations is used to perform a fast bind.
786 #define LDB_EXTENDED_FAST_BIND_OID "1.2.840.113556.1.4.1781"
789 OID for LDAP Extended Operation START_TLS.
791 This Extended operation is used to start a new TLS channel on top of a clear
792 text channel.
794 #define LDB_EXTENDED_START_TLS_OID "1.3.6.1.4.1.1466.20037"
797 OID for LDAP Extended Operation DYNAMIC_REFRESH.
799 This Extended operation is used to create and maintain objects which exist
800 only a specific time, e.g. when a certain client or a certain person is
801 logged in. Data refreshes have to be periodically sent in a specific
802 interval. Otherwise the entry is going to be removed.
804 #define LDB_EXTENDED_DYNAMIC_OID "1.3.6.1.4.1.1466.101.119.1"
807 OID for RFC4532 "Who Am I" extended operation
809 #define LDB_EXTENDED_WHOAMI_OID "1.3.6.1.4.1.4203.1.11.3"
811 struct ldb_sd_flags_control {
813 * request the owner 0x00000001
814 * request the group 0x00000002
815 * request the DACL 0x00000004
816 * request the SACL 0x00000008
818 unsigned secinfo_flags;
822 * DOMAIN_SCOPE 0x00000001
823 * this limits the search to one partition,
824 * and no referrals will be returned.
825 * (Note this doesn't limit the entries by there
826 * objectSid belonging to a domain! Builtin and Foreign Sids
827 * are still returned)
829 * PHANTOM_ROOT 0x00000002
830 * this search on the whole tree on a domain controller
831 * over multiple partitions without referrals.
832 * (This is the default behavior on the Global Catalog Port)
835 #define LDB_SEARCH_OPTION_DOMAIN_SCOPE 0x00000001
836 #define LDB_SEARCH_OPTION_PHANTOM_ROOT 0x00000002
838 struct ldb_search_options_control {
839 unsigned search_options;
842 struct ldb_paged_control {
843 int size;
844 int cookie_len;
845 char *cookie;
848 struct ldb_extended_dn_control {
849 int type;
852 struct ldb_server_sort_control {
853 const char *attributeName;
854 const char *orderingRule;
855 int reverse;
858 struct ldb_sort_resp_control {
859 int result;
860 char *attr_desc;
863 struct ldb_asq_control {
864 int request;
865 char *source_attribute;
866 int src_attr_len;
867 int result;
870 struct ldb_dirsync_control {
871 int flags;
872 int max_attributes;
873 int cookie_len;
874 char *cookie;
877 struct ldb_vlv_req_control {
878 int beforeCount;
879 int afterCount;
880 int type;
881 union {
882 struct {
883 int offset;
884 int contentCount;
885 } byOffset;
886 struct {
887 int value_len;
888 char *value;
889 } gtOrEq;
890 } match;
891 int ctxid_len;
892 uint8_t *contextId;
895 struct ldb_vlv_resp_control {
896 int targetPosition;
897 int contentCount;
898 int vlv_result;
899 int ctxid_len;
900 uint8_t *contextId;
903 struct ldb_verify_name_control {
904 int flags;
905 size_t gc_len;
906 char *gc;
909 struct ldb_control {
910 const char *oid;
911 int critical;
912 void *data;
915 enum ldb_request_type {
916 LDB_SEARCH,
917 LDB_ADD,
918 LDB_MODIFY,
919 LDB_DELETE,
920 LDB_RENAME,
921 LDB_EXTENDED,
922 LDB_REQ_REGISTER_CONTROL,
923 LDB_REQ_REGISTER_PARTITION
926 enum ldb_reply_type {
927 LDB_REPLY_ENTRY,
928 LDB_REPLY_REFERRAL,
929 LDB_REPLY_DONE
932 enum ldb_wait_type {
933 LDB_WAIT_ALL,
934 LDB_WAIT_NONE
937 enum ldb_state {
938 LDB_ASYNC_INIT,
939 LDB_ASYNC_PENDING,
940 LDB_ASYNC_DONE
943 struct ldb_extended {
944 const char *oid;
945 void *data; /* NULL or a valid talloc pointer! talloc_get_type() will be used on it */
948 enum ldb_sequence_type {
949 LDB_SEQ_HIGHEST_SEQ,
950 LDB_SEQ_HIGHEST_TIMESTAMP,
951 LDB_SEQ_NEXT
954 #define LDB_SEQ_GLOBAL_SEQUENCE 0x01
955 #define LDB_SEQ_TIMESTAMP_SEQUENCE 0x02
957 struct ldb_seqnum_request {
958 enum ldb_sequence_type type;
961 struct ldb_seqnum_result {
962 uint64_t seq_num;
963 uint32_t flags;
966 struct ldb_result {
967 unsigned int count;
968 struct ldb_message **msgs;
969 struct ldb_extended *extended;
970 struct ldb_control **controls;
971 char **refs;
974 struct ldb_reply {
975 int error;
976 enum ldb_reply_type type;
977 struct ldb_message *message;
978 struct ldb_extended *response;
979 struct ldb_control **controls;
980 char *referral;
983 struct ldb_request;
984 struct ldb_handle;
986 struct ldb_search {
987 struct ldb_dn *base;
988 enum ldb_scope scope;
989 struct ldb_parse_tree *tree;
990 const char * const *attrs;
991 struct ldb_result *res;
994 struct ldb_add {
995 const struct ldb_message *message;
998 struct ldb_modify {
999 const struct ldb_message *message;
1002 struct ldb_delete {
1003 struct ldb_dn *dn;
1006 struct ldb_rename {
1007 struct ldb_dn *olddn;
1008 struct ldb_dn *newdn;
1011 struct ldb_register_control {
1012 const char *oid;
1015 struct ldb_register_partition {
1016 struct ldb_dn *dn;
1019 typedef int (*ldb_request_callback_t)(struct ldb_request *, struct ldb_reply *);
1021 struct ldb_request {
1023 enum ldb_request_type operation;
1025 union {
1026 struct ldb_search search;
1027 struct ldb_add add;
1028 struct ldb_modify mod;
1029 struct ldb_delete del;
1030 struct ldb_rename rename;
1031 struct ldb_extended extended;
1032 struct ldb_register_control reg_control;
1033 struct ldb_register_partition reg_partition;
1034 } op;
1036 struct ldb_control **controls;
1038 void *context;
1039 ldb_request_callback_t callback;
1041 int timeout;
1042 time_t starttime;
1043 struct ldb_handle *handle;
1046 int ldb_request(struct ldb_context *ldb, struct ldb_request *request);
1047 int ldb_request_done(struct ldb_request *req, int status);
1048 bool ldb_request_is_done(struct ldb_request *req);
1050 int ldb_modules_wait(struct ldb_handle *handle);
1051 int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type);
1053 int ldb_set_timeout(struct ldb_context *ldb, struct ldb_request *req, int timeout);
1054 int ldb_set_timeout_from_prev_req(struct ldb_context *ldb, struct ldb_request *oldreq, struct ldb_request *newreq);
1055 void ldb_set_create_perms(struct ldb_context *ldb, unsigned int perms);
1056 void ldb_set_modules_dir(struct ldb_context *ldb, const char *path);
1057 struct tevent_context;
1058 void ldb_set_event_context(struct ldb_context *ldb, struct tevent_context *ev);
1059 struct tevent_context * ldb_get_event_context(struct ldb_context *ldb);
1062 Initialise ldbs' global information
1064 This is required before any other LDB call
1066 \return 0 if initialisation succeeded, -1 otherwise
1068 int ldb_global_init(void);
1071 Initialise an ldb context
1073 This is required before any other LDB call.
1075 \param mem_ctx pointer to a talloc memory context. Pass NULL if there is
1076 no suitable context available.
1078 \note The LDB modules will be loaded from directory specified by the environment
1079 variable LDB_MODULES_PATH. If the variable is not specified, the compiled-in default
1080 is used.
1082 \return pointer to ldb_context that should be free'd (using talloc_free())
1083 at the end of the program.
1085 struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx);
1088 Connect to a database.
1090 This is typically called soon after ldb_init(), and is required prior to
1091 any search or database modification operations.
1093 The URL can be one of the following forms:
1094 - tdb://path
1095 - ldapi://path
1096 - ldap://host
1097 - sqlite://path
1099 \param ldb the context associated with the database (from ldb_init())
1100 \param url the URL of the database to connect to, as noted above
1101 \param flags a combination of LDB_FLG_* to modify the connection behaviour
1102 \param options backend specific options - passed uninterpreted to the backend
1104 \return result code (LDB_SUCCESS on success, or a failure code)
1106 \note It is an error to connect to a database that does not exist in readonly mode
1107 (that is, with LDB_FLG_RDONLY). However in read-write mode, the database will be
1108 created if it does not exist.
1110 int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[]);
1113 return an automatic basedn from the rootDomainNamingContext of the rootDSE
1114 This value have been set in an opaque pointer at connection time
1116 struct ldb_dn *ldb_get_root_basedn(struct ldb_context *ldb);
1119 return an automatic basedn from the configurationNamingContext of the rootDSE
1120 This value have been set in an opaque pointer at connection time
1122 struct ldb_dn *ldb_get_config_basedn(struct ldb_context *ldb);
1125 return an automatic basedn from the schemaNamingContext of the rootDSE
1126 This value have been set in an opaque pointer at connection time
1128 struct ldb_dn *ldb_get_schema_basedn(struct ldb_context *ldb);
1131 return an automatic baseDN from the defaultNamingContext of the rootDSE
1132 This value have been set in an opaque pointer at connection time
1134 struct ldb_dn *ldb_get_default_basedn(struct ldb_context *ldb);
1137 The default async search callback function
1139 \param req the request we are callback of
1140 \param ares a single reply from the async core
1142 \return result code (LDB_SUCCESS on success, or a failure code)
1144 \note this function expects req->context to always be an struct ldb_result pointer
1145 AND a talloc context, this function will steal on the context each message
1146 from the ares reply passed on by the async core so that in the end all the
1147 messages will be in the context (ldb_result) memory tree.
1148 Freeing the passed context (ldb_result tree) will free all the resources
1149 (the request need to be freed separately and the result does not depend on the
1150 request that can be freed as soon as the search request is finished)
1153 int ldb_search_default_callback(struct ldb_request *req, struct ldb_reply *ares);
1156 The default async extended operation callback function
1158 \param req the request we are callback of
1159 \param ares a single reply from the async core
1161 \return result code (LDB_SUCCESS on success, or a failure code)
1163 int ldb_op_default_callback(struct ldb_request *req, struct ldb_reply *ares);
1165 int ldb_modify_default_callback(struct ldb_request *req, struct ldb_reply *ares);
1168 Helper function to build a search request
1170 \param ret_req the request structure is returned here (talloced on mem_ctx)
1171 \param ldb the context associated with the database (from ldb_init())
1172 \param mem_ctx a talloc memory context (used as parent of ret_req)
1173 \param base the Base Distinguished Name for the query (use ldb_dn_new() for an empty one)
1174 \param scope the search scope for the query
1175 \param expression the search expression to use for this query
1176 \param attrs the search attributes for the query (pass NULL if none required)
1177 \param controls an array of controls
1178 \param context the callback function context
1179 \param callback the callback function to handle the async replies
1180 \param parent the parent request if any
1182 \return result code (LDB_SUCCESS on success, or a failure code)
1185 int ldb_build_search_req(struct ldb_request **ret_req,
1186 struct ldb_context *ldb,
1187 TALLOC_CTX *mem_ctx,
1188 struct ldb_dn *base,
1189 enum ldb_scope scope,
1190 const char *expression,
1191 const char * const *attrs,
1192 struct ldb_control **controls,
1193 void *context,
1194 ldb_request_callback_t callback,
1195 struct ldb_request *parent);
1197 int ldb_build_search_req_ex(struct ldb_request **ret_req,
1198 struct ldb_context *ldb,
1199 TALLOC_CTX *mem_ctx,
1200 struct ldb_dn *base,
1201 enum ldb_scope scope,
1202 struct ldb_parse_tree *tree,
1203 const char * const *attrs,
1204 struct ldb_control **controls,
1205 void *context,
1206 ldb_request_callback_t callback,
1207 struct ldb_request *parent);
1210 Helper function to build an add request
1212 \param ret_req the request structure is returned here (talloced on mem_ctx)
1213 \param ldb the context associated with the database (from ldb_init())
1214 \param mem_ctx a talloc memory context (used as parent of ret_req)
1215 \param message contains the entry to be added
1216 \param controls an array of controls
1217 \param context the callback function context
1218 \param callback the callback function to handle the async replies
1219 \param parent the parent request if any
1221 \return result code (LDB_SUCCESS on success, or a failure code)
1224 int ldb_build_add_req(struct ldb_request **ret_req,
1225 struct ldb_context *ldb,
1226 TALLOC_CTX *mem_ctx,
1227 const struct ldb_message *message,
1228 struct ldb_control **controls,
1229 void *context,
1230 ldb_request_callback_t callback,
1231 struct ldb_request *parent);
1234 Helper function to build a modify request
1236 \param ret_req the request structure is returned here (talloced on mem_ctx)
1237 \param ldb the context associated with the database (from ldb_init())
1238 \param mem_ctx a talloc memory context (used as parent of ret_req)
1239 \param message contains the entry to be modified
1240 \param controls an array of controls
1241 \param context the callback function context
1242 \param callback the callback function to handle the async replies
1243 \param parent the parent request if any
1245 \return result code (LDB_SUCCESS on success, or a failure code)
1248 int ldb_build_mod_req(struct ldb_request **ret_req,
1249 struct ldb_context *ldb,
1250 TALLOC_CTX *mem_ctx,
1251 const struct ldb_message *message,
1252 struct ldb_control **controls,
1253 void *context,
1254 ldb_request_callback_t callback,
1255 struct ldb_request *parent);
1258 Helper function to build a delete request
1260 \param ret_req the request structure is returned here (talloced on mem_ctx)
1261 \param ldb the context associated with the database (from ldb_init())
1262 \param mem_ctx a talloc memory context (used as parent of ret_req)
1263 \param dn the DN to be deleted
1264 \param controls an array of controls
1265 \param context the callback function context
1266 \param callback the callback function to handle the async replies
1267 \param parent the parent request if any
1269 \return result code (LDB_SUCCESS on success, or a failure code)
1272 int ldb_build_del_req(struct ldb_request **ret_req,
1273 struct ldb_context *ldb,
1274 TALLOC_CTX *mem_ctx,
1275 struct ldb_dn *dn,
1276 struct ldb_control **controls,
1277 void *context,
1278 ldb_request_callback_t callback,
1279 struct ldb_request *parent);
1282 Helper function to build a rename request
1284 \param ret_req the request structure is returned here (talloced on mem_ctx)
1285 \param ldb the context associated with the database (from ldb_init())
1286 \param mem_ctx a talloc memory context (used as parent of ret_req)
1287 \param olddn the old DN
1288 \param newdn the new DN
1289 \param controls an array of controls
1290 \param context the callback function context
1291 \param callback the callback function to handle the async replies
1292 \param parent the parent request if any
1294 \return result code (LDB_SUCCESS on success, or a failure code)
1297 int ldb_build_rename_req(struct ldb_request **ret_req,
1298 struct ldb_context *ldb,
1299 TALLOC_CTX *mem_ctx,
1300 struct ldb_dn *olddn,
1301 struct ldb_dn *newdn,
1302 struct ldb_control **controls,
1303 void *context,
1304 ldb_request_callback_t callback,
1305 struct ldb_request *parent);
1308 Add a ldb_control to a ldb_request
1310 \param req the request struct where to add the control
1311 \param oid the object identifier of the control as string
1312 \param critical whether the control should be critical or not
1313 \param data a talloc pointer to the control specific data
1315 \return result code (LDB_SUCCESS on success, or a failure code)
1317 int ldb_request_add_control(struct ldb_request *req, const char *oid, bool critical, void *data);
1320 replace a ldb_control in a ldb_request
1322 \param req the request struct where to add the control
1323 \param oid the object identifier of the control as string
1324 \param critical whether the control should be critical or not
1325 \param data a talloc pointer to the control specific data
1327 \return result code (LDB_SUCCESS on success, or a failure code)
1329 int ldb_request_replace_control(struct ldb_request *req, const char *oid, bool critical, void *data);
1332 check if a control with the specified "oid" exist and return it
1333 \param controls the array of controls
1334 \param oid the object identifier of the control as string
1336 \return the control, NULL if not found
1338 struct ldb_control *ldb_controls_get_control(struct ldb_control **controls, const char *oid);
1341 check if a control with the specified "oid" exist and return it
1342 \param req the request struct to search for the control
1343 \param oid the object identifier of the control as string
1345 \return the control, NULL if not found
1347 struct ldb_control *ldb_request_get_control(struct ldb_request *req, const char *oid);
1350 check if a control with the specified "oid" exist and return it
1351 \param rep the reply struct to search for the control
1352 \param oid the object identifier of the control as string
1354 \return the control, NULL if not found
1356 struct ldb_control *ldb_reply_get_control(struct ldb_reply *rep, const char *oid);
1359 Search the database
1361 This function searches the database, and returns
1362 records that match an LDAP-like search expression
1364 \param ldb the context associated with the database (from ldb_init())
1365 \param mem_ctx the memory context to use for the request and the results
1366 \param result the return result
1367 \param base the Base Distinguished Name for the query (use ldb_dn_new() for an empty one)
1368 \param scope the search scope for the query
1369 \param attrs the search attributes for the query (pass NULL if none required)
1370 \param exp_fmt the search expression to use for this query (printf like)
1372 \return result code (LDB_SUCCESS on success, or a failure code)
1374 \note use talloc_free() to free the ldb_result returned
1376 int ldb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
1377 struct ldb_result **result, struct ldb_dn *base,
1378 enum ldb_scope scope, const char * const *attrs,
1379 const char *exp_fmt, ...) PRINTF_ATTRIBUTE(7,8);
1382 Add a record to the database.
1384 This function adds a record to the database. This function will fail
1385 if a record with the specified class and key already exists in the
1386 database.
1388 \param ldb the context associated with the database (from
1389 ldb_init())
1390 \param message the message containing the record to add.
1392 \return result code (LDB_SUCCESS if the record was added, otherwise
1393 a failure code)
1395 int ldb_add(struct ldb_context *ldb,
1396 const struct ldb_message *message);
1399 Modify the specified attributes of a record
1401 This function modifies a record that is in the database.
1403 \param ldb the context associated with the database (from
1404 ldb_init())
1405 \param message the message containing the changes required.
1407 \return result code (LDB_SUCCESS if the record was modified as
1408 requested, otherwise a failure code)
1410 int ldb_modify(struct ldb_context *ldb,
1411 const struct ldb_message *message);
1414 Rename a record in the database
1416 This function renames a record in the database.
1418 \param ldb the context associated with the database (from
1419 ldb_init())
1420 \param olddn the DN for the record to be renamed.
1421 \param newdn the new DN
1423 \return result code (LDB_SUCCESS if the record was renamed as
1424 requested, otherwise a failure code)
1426 int ldb_rename(struct ldb_context *ldb, struct ldb_dn *olddn, struct ldb_dn *newdn);
1429 Delete a record from the database
1431 This function deletes a record from the database.
1433 \param ldb the context associated with the database (from
1434 ldb_init())
1435 \param dn the DN for the record to be deleted.
1437 \return result code (LDB_SUCCESS if the record was deleted,
1438 otherwise a failure code)
1440 int ldb_delete(struct ldb_context *ldb, struct ldb_dn *dn);
1443 The default async extended operation callback function
1445 \param req the request we are callback of
1446 \param ares a single reply from the async core
1448 \return result code (LDB_SUCCESS on success, or a failure code)
1450 \note this function expects req->context to always be an struct ldb_result pointer
1451 AND a talloc context, this function will steal on the context each message
1452 from the ares reply passed on by the async core so that in the end all the
1453 messages will be in the context (ldb_result) memory tree.
1454 Freeing the passed context (ldb_result tree) will free all the resources
1455 (the request need to be freed separately and the result does not depend on the
1456 request that can be freed as soon as the search request is finished)
1459 int ldb_extended_default_callback(struct ldb_request *req, struct ldb_reply *ares);
1463 Helper function to build a extended request
1465 \param ret_req the request structure is returned here (talloced on mem_ctx)
1466 \param ldb the context associated with the database (from ldb_init())
1467 \param mem_ctx a talloc memory context (used as parent of ret_req)
1468 \param oid the OID of the extended operation.
1469 \param data a void pointer to the extended operation specific parameters,
1470 it needs to be NULL or a valid talloc pointer! talloc_get_type() will be used on it
1471 \param controls an array of controls
1472 \param context the callback function context
1473 \param callback the callback function to handle the async replies
1474 \param parent the parent request if any
1476 \return result code (LDB_SUCCESS on success, or a failure code)
1478 int ldb_build_extended_req(struct ldb_request **ret_req,
1479 struct ldb_context *ldb,
1480 TALLOC_CTX *mem_ctx,
1481 const char *oid,
1482 void *data,/* NULL or a valid talloc pointer! talloc_get_type() will be used on it */
1483 struct ldb_control **controls,
1484 void *context,
1485 ldb_request_callback_t callback,
1486 struct ldb_request *parent);
1489 call an extended operation
1491 \param ldb the context associated with the database (from ldb_init())
1492 \param oid the OID of the extended operation.
1493 \param data a void pointer to the extended operation specific parameters,
1494 it needs to be NULL or a valid talloc pointer! talloc_get_type() will be used on it
1495 \param res the result of the extended operation
1497 \return result code (LDB_SUCCESS if the extended operation returned fine,
1498 otherwise a failure code)
1500 int ldb_extended(struct ldb_context *ldb,
1501 const char *oid,
1502 void *data,/* NULL or a valid talloc pointer! talloc_get_type() will be used on it */
1503 struct ldb_result **res);
1506 Obtain current/next database sequence number
1508 int ldb_sequence_number(struct ldb_context *ldb, enum ldb_sequence_type type, uint64_t *seq_num);
1511 start a transaction
1513 int ldb_transaction_start(struct ldb_context *ldb);
1516 first phase of two phase commit
1518 int ldb_transaction_prepare_commit(struct ldb_context *ldb);
1521 commit a transaction
1523 int ldb_transaction_commit(struct ldb_context *ldb);
1526 cancel a transaction
1528 int ldb_transaction_cancel(struct ldb_context *ldb);
1531 cancel a transaction with no error if no transaction is pending
1532 used when we fork() to clear any parent transactions
1534 int ldb_transaction_cancel_noerr(struct ldb_context *ldb);
1538 return extended error information from the last call
1540 const char *ldb_errstring(struct ldb_context *ldb);
1543 return a string explaining what a ldb error constant means
1545 const char *ldb_strerror(int ldb_err);
1548 setup the default utf8 functions
1549 FIXME: these functions do not yet handle utf8
1551 void ldb_set_utf8_default(struct ldb_context *ldb);
1554 \brief Casefold a string
1556 Note that the callback needs to be ASCII compatible. So first ASCII needs
1557 to be handled before any UTF-8. This is needed to avoid issues with dotted
1558 languages.
1560 \param ldb the ldb context
1561 \param mem_ctx the memory context to allocate the result string
1562 memory from.
1563 \param s the string that is to be folded
1564 \return a copy of the string, converted to upper case
1566 \note The default function is not yet UTF8 aware. Provide your own
1567 set of functions through ldb_set_utf8_fns()
1569 char *ldb_casefold(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *s, size_t n);
1572 Check the attribute name is valid according to rfc2251
1573 \param s the string to check
1575 \return 1 if the name is ok
1577 int ldb_valid_attr_name(const char *s);
1580 ldif manipulation functions
1584 Write an LDIF message
1586 This function writes an LDIF message using a caller supplied write
1587 function.
1589 \param ldb the ldb context (from ldb_init())
1590 \param fprintf_fn a function pointer for the write function. This must take
1591 a private data pointer, followed by a format string, and then a variable argument
1592 list.
1593 \param private_data pointer that will be provided back to the write
1594 function. This is useful for maintaining state or context.
1595 \param ldif the message to write out
1597 \return the total number of bytes written, or an error code as returned
1598 from the write function.
1600 \sa ldb_ldif_write_file for a more convenient way to write to a
1601 file stream.
1603 \sa ldb_ldif_read for the reader equivalent to this function.
1605 int ldb_ldif_write(struct ldb_context *ldb,
1606 int (*fprintf_fn)(void *, const char *, ...) PRINTF_ATTRIBUTE(2,3),
1607 void *private_data,
1608 const struct ldb_ldif *ldif);
1611 Clean up an LDIF message
1613 This function cleans up a LDIF message read using ldb_ldif_read()
1614 or related functions (such as ldb_ldif_read_string() and
1615 ldb_ldif_read_file().
1617 \param ldb the ldb context (from ldb_init())
1618 \param msg the message to clean up and free
1621 void ldb_ldif_read_free(struct ldb_context *ldb, struct ldb_ldif *msg);
1624 Read an LDIF message
1626 This function creates an LDIF message using a caller supplied read
1627 function.
1629 \param ldb the ldb context (from ldb_init())
1630 \param fgetc_fn a function pointer for the read function. This must
1631 take a private data pointer, and must return a pointer to an
1632 integer corresponding to the next byte read (or EOF if there is no
1633 more data to be read).
1634 \param private_data pointer that will be provided back to the read
1635 function. This is useful for maintaining state or context.
1637 \return the LDIF message that has been read in
1639 \note You must free the LDIF message when no longer required, using
1640 ldb_ldif_read_free().
1642 \sa ldb_ldif_read_file for a more convenient way to read from a
1643 file stream.
1645 \sa ldb_ldif_read_string for a more convenient way to read from a
1646 string (char array).
1648 \sa ldb_ldif_write for the writer equivalent to this function.
1650 struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
1651 int (*fgetc_fn)(void *), void *private_data);
1654 Read an LDIF message from a file
1656 This function reads the next LDIF message from the contents of a
1657 file stream. If you want to get all of the LDIF messages, you will
1658 need to repeatedly call this function, until it returns NULL.
1660 \param ldb the ldb context (from ldb_init())
1661 \param f the file stream to read from (typically from fdopen())
1663 \sa ldb_ldif_read_string for an equivalent function that will read
1664 from a string (char array).
1666 \sa ldb_ldif_write_file for the writer equivalent to this function.
1669 struct ldb_ldif *ldb_ldif_read_file(struct ldb_context *ldb, FILE *f);
1672 Read an LDIF message from a string
1674 This function reads the next LDIF message from the contents of a char
1675 array. If you want to get all of the LDIF messages, you will need
1676 to repeatedly call this function, until it returns NULL.
1678 \param ldb the ldb context (from ldb_init())
1679 \param s pointer to the char array to read from
1681 \sa ldb_ldif_read_file for an equivalent function that will read
1682 from a file stream.
1684 \sa ldb_ldif_write for a more general (arbitrary read function)
1685 version of this function.
1687 struct ldb_ldif *ldb_ldif_read_string(struct ldb_context *ldb, const char **s);
1690 Parse a modrdn LDIF message from a struct ldb_message
1692 \param ldb the ldb context (from ldb_init())
1693 \param ldif the preparsed LDIF chunk (from ldb_ldif_read())
1695 \param mem_ctx the memory context that's used for return values
1697 \param olddn the old dn as struct ldb_dn, if not needed pass NULL
1698 \param newrdn the new rdn as struct ldb_dn, if not needed pass NULL
1699 \param deleteoldrdn the deleteoldrdn value as bool, if not needed pass NULL
1700 \param newsuperior the newsuperior dn as struct ldb_dn, if not needed pass NULL
1701 *newsuperior can be NULL as it is optional in the LDIF
1702 \param newdn the full constructed new dn as struct ldb_dn, if not needed pass NULL
1705 int ldb_ldif_parse_modrdn(struct ldb_context *ldb,
1706 const struct ldb_ldif *ldif,
1707 TALLOC_CTX *mem_ctx,
1708 struct ldb_dn **olddn,
1709 struct ldb_dn **newrdn,
1710 bool *deleteoldrdn,
1711 struct ldb_dn **newsuperior,
1712 struct ldb_dn **newdn);
1715 Write an LDIF message to a file
1717 \param ldb the ldb context (from ldb_init())
1718 \param f the file stream to write to (typically from fdopen())
1719 \param msg the message to write out
1721 \return the total number of bytes written, or a negative error code
1723 \sa ldb_ldif_read_file for the reader equivalent to this function.
1725 int ldb_ldif_write_file(struct ldb_context *ldb, FILE *f, const struct ldb_ldif *msg);
1728 Write an LDIF message to a string
1730 \param ldb the ldb context (from ldb_init())
1731 \param mem_ctx the talloc context on which to attach the string)
1732 \param msg the message to write out
1734 \return the string containing the LDIF, or NULL on error
1736 \sa ldb_ldif_read_string for the reader equivalent to this function.
1738 char * ldb_ldif_write_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
1739 const struct ldb_ldif *msg);
1743 Write an LDB message to a string
1745 \param ldb the ldb context (from ldb_init())
1746 \param mem_ctx the talloc context on which to attach the string)
1747 \param changetype LDB_CHANGETYPE_ADD or LDB_CHANGETYPE_MODIFY
1748 \param msg the message to write out
1750 \return the string containing the LDIF, or NULL on error
1752 \sa ldb_ldif_message_redacted_string for a safer version of this
1753 function
1755 char *ldb_ldif_message_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
1756 enum ldb_changetype changetype,
1757 const struct ldb_message *msg);
1760 Write an LDB message to a string
1762 \param ldb the ldb context (from ldb_init())
1763 \param mem_ctx the talloc context on which to attach the string)
1764 \param changetype LDB_CHANGETYPE_ADD or LDB_CHANGETYPE_MODIFY
1765 \param msg the message to write out
1767 \return the string containing the LDIF, or NULL on error, but
1768 with secret attributes redacted
1770 \note The secret attributes are specified in a
1771 'const char * const *' within the LDB_SECRET_ATTRIBUTE_LIST
1772 opaque set on the ldb
1774 \sa ldb_ldif_message_string for an exact representation of the
1775 message as LDIF
1777 char *ldb_ldif_message_redacted_string(struct ldb_context *ldb,
1778 TALLOC_CTX *mem_ctx,
1779 enum ldb_changetype changetype,
1780 const struct ldb_message *msg);
1784 Base64 encode a buffer
1786 \param mem_ctx the memory context that the result is allocated
1787 from.
1788 \param buf pointer to the array that is to be encoded
1789 \param len the number of elements in the array to be encoded
1791 \return pointer to an array containing the encoded data
1793 \note The caller is responsible for freeing the result
1795 char *ldb_base64_encode(TALLOC_CTX *mem_ctx, const char *buf, int len);
1798 Base64 decode a buffer
1800 This function decodes a base64 encoded string in place.
1802 \param s the string to decode.
1804 \return the length of the returned (decoded) string.
1806 \note the string is null terminated, but the null terminator is not
1807 included in the length.
1809 int ldb_base64_decode(char *s);
1811 /* The following definitions come from lib/ldb/common/ldb_dn.c */
1814 Get the linear form of a DN (without any extended components)
1816 \param dn The DN to linearize
1819 const char *ldb_dn_get_linearized(struct ldb_dn *dn);
1822 Allocate a copy of the linear form of a DN (without any extended components) onto the supplied memory context
1824 \param dn The DN to linearize
1825 \param mem_ctx TALLOC context to return result on
1828 char *ldb_dn_alloc_linearized(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);
1831 Get the linear form of a DN (with any extended components)
1833 \param mem_ctx TALLOC context to return result on
1834 \param dn The DN to linearize
1835 \param mode Style of extended DN to return (0 is HEX representation of binary form, 1 is a string form)
1837 char *ldb_dn_get_extended_linearized(TALLOC_CTX *mem_ctx, struct ldb_dn *dn, int mode);
1838 const struct ldb_val *ldb_dn_get_extended_component(struct ldb_dn *dn, const char *name);
1839 int ldb_dn_set_extended_component(struct ldb_dn *dn, const char *name, const struct ldb_val *val);
1840 void ldb_dn_extended_filter(struct ldb_dn *dn, const char * const *accept_list);
1841 void ldb_dn_remove_extended_components(struct ldb_dn *dn);
1842 bool ldb_dn_has_extended(struct ldb_dn *dn);
1844 int ldb_dn_extended_add_syntax(struct ldb_context *ldb,
1845 unsigned flags,
1846 const struct ldb_dn_extended_syntax *syntax);
1849 Allocate a new DN from a string
1851 \param mem_ctx TALLOC context to return resulting ldb_dn structure on
1852 \param dn The new DN
1854 \note The DN will not be parsed at this time. Use ldb_dn_validate to tell if the DN is syntactically correct
1857 struct ldb_dn *ldb_dn_new(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, const char *dn);
1859 Allocate a new DN from a printf style format string and arguments
1861 \param mem_ctx TALLOC context to return resulting ldb_dn structure on
1862 \param new_fmt The new DN as a format string (plus arguments)
1864 \note The DN will not be parsed at this time. Use ldb_dn_validate to tell if the DN is syntactically correct
1867 struct ldb_dn *ldb_dn_new_fmt(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, const char *new_fmt, ...) PRINTF_ATTRIBUTE(3,4);
1869 Allocate a new DN from a struct ldb_val (useful to avoid buffer overrun)
1871 \param mem_ctx TALLOC context to return resulting ldb_dn structure on
1872 \param dn The new DN
1874 \note The DN will not be parsed at this time. Use ldb_dn_validate to tell if the DN is syntactically correct
1877 struct ldb_dn *ldb_dn_from_ldb_val(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, const struct ldb_val *strdn);
1880 Determine if this DN is syntactically valid
1882 \param dn The DN to validate
1885 bool ldb_dn_validate(struct ldb_dn *dn);
1887 char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value);
1888 const char *ldb_dn_get_casefold(struct ldb_dn *dn);
1889 char *ldb_dn_alloc_casefold(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);
1891 int ldb_dn_compare_base(struct ldb_dn *base, struct ldb_dn *dn);
1892 int ldb_dn_compare(struct ldb_dn *edn0, struct ldb_dn *edn1);
1894 bool ldb_dn_add_base(struct ldb_dn *dn, struct ldb_dn *base);
1895 bool ldb_dn_add_base_fmt(struct ldb_dn *dn, const char *base_fmt, ...) PRINTF_ATTRIBUTE(2,3);
1896 bool ldb_dn_add_child(struct ldb_dn *dn, struct ldb_dn *child);
1897 bool ldb_dn_add_child_fmt(struct ldb_dn *dn, const char *child_fmt, ...) PRINTF_ATTRIBUTE(2,3);
1898 bool ldb_dn_remove_base_components(struct ldb_dn *dn, unsigned int num);
1899 bool ldb_dn_remove_child_components(struct ldb_dn *dn, unsigned int num);
1900 bool ldb_dn_add_child_val(struct ldb_dn *dn,
1901 const char *rdn,
1902 struct ldb_val value);
1904 struct ldb_dn *ldb_dn_copy(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);
1905 struct ldb_dn *ldb_dn_copy_with_ldb_context(TALLOC_CTX *mem_ctx,
1906 struct ldb_dn *dn,
1907 struct ldb_context *ldb);
1908 struct ldb_dn *ldb_dn_get_parent(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);
1909 char *ldb_dn_canonical_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);
1910 char *ldb_dn_canonical_ex_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);
1911 int ldb_dn_get_comp_num(struct ldb_dn *dn);
1912 int ldb_dn_get_extended_comp_num(struct ldb_dn *dn);
1913 const char *ldb_dn_get_component_name(struct ldb_dn *dn, unsigned int num);
1914 const struct ldb_val *ldb_dn_get_component_val(struct ldb_dn *dn, unsigned int num);
1915 const char *ldb_dn_get_rdn_name(struct ldb_dn *dn);
1916 const struct ldb_val *ldb_dn_get_rdn_val(struct ldb_dn *dn);
1917 int ldb_dn_set_component(struct ldb_dn *dn, int num, const char *name, const struct ldb_val val);
1919 bool ldb_dn_is_valid(struct ldb_dn *dn);
1920 bool ldb_dn_is_special(struct ldb_dn *dn);
1921 bool ldb_dn_check_special(struct ldb_dn *dn, const char *check);
1922 bool ldb_dn_is_null(struct ldb_dn *dn);
1923 int ldb_dn_update_components(struct ldb_dn *dn, const struct ldb_dn *ref_dn);
1927 Compare two attributes
1929 This function compares to attribute names. Note that this is a
1930 case-insensitive comparison.
1932 \param a the first attribute name to compare
1933 \param b the second attribute name to compare
1935 \return 0 if the attribute names are the same, or only differ in
1936 case; non-zero if there are any differences
1938 attribute names are restricted by rfc2251 so using
1939 strcasecmp and toupper here is ok.
1940 return 0 for match
1942 #undef strcasecmp
1943 #define ldb_attr_cmp(a, b) strcasecmp(a, b)
1944 char *ldb_attr_casefold(TALLOC_CTX *mem_ctx, const char *s);
1945 int ldb_attr_dn(const char *attr);
1948 Create an empty message
1950 \param mem_ctx the memory context to create in. You can pass NULL
1951 to get the top level context, however the ldb context (from
1952 ldb_init()) may be a better choice
1954 struct ldb_message *ldb_msg_new(TALLOC_CTX *mem_ctx);
1957 Find an element within an message
1959 struct ldb_message_element *ldb_msg_find_element(const struct ldb_message *msg,
1960 const char *attr_name);
1963 Compare two ldb_val values
1965 \param v1 first ldb_val structure to be tested
1966 \param v2 second ldb_val structure to be tested
1968 \return 1 for a match, 0 if there is any difference
1970 int ldb_val_equal_exact(const struct ldb_val *v1, const struct ldb_val *v2);
1973 find a value within an ldb_message_element
1975 \param el the element to search
1976 \param val the value to search for
1978 \note This search is case sensitive
1980 struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el,
1981 struct ldb_val *val);
1984 add a new empty element to a ldb_message
1986 int ldb_msg_add_empty(struct ldb_message *msg,
1987 const char *attr_name,
1988 int flags,
1989 struct ldb_message_element **return_el);
1992 add a value to a message element
1994 int ldb_msg_element_add_value(TALLOC_CTX *mem_ctx,
1995 struct ldb_message_element *el,
1996 const struct ldb_val *val);
1998 add a element to a ldb_message
2000 int ldb_msg_add(struct ldb_message *msg,
2001 const struct ldb_message_element *el,
2002 int flags);
2003 int ldb_msg_add_value(struct ldb_message *msg,
2004 const char *attr_name,
2005 const struct ldb_val *val,
2006 struct ldb_message_element **return_el);
2007 int ldb_msg_add_steal_value(struct ldb_message *msg,
2008 const char *attr_name,
2009 struct ldb_val *val);
2010 int ldb_msg_add_steal_string(struct ldb_message *msg,
2011 const char *attr_name, char *str);
2012 int ldb_msg_add_string_flags(struct ldb_message *msg,
2013 const char *attr_name, const char *str,
2014 int flags);
2015 int ldb_msg_add_string(struct ldb_message *msg,
2016 const char *attr_name, const char *str);
2017 int ldb_msg_add_linearized_dn(struct ldb_message *msg, const char *attr_name,
2018 struct ldb_dn *dn);
2019 int ldb_msg_add_fmt(struct ldb_message *msg,
2020 const char *attr_name, const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
2022 append a element to a ldb_message
2024 int ldb_msg_append_value(struct ldb_message *msg,
2025 const char *attr_name,
2026 const struct ldb_val *val,
2027 int flags);
2028 int ldb_msg_append_steal_value(struct ldb_message *msg,
2029 const char *attr_name,
2030 struct ldb_val *val,
2031 int flags);
2032 int ldb_msg_append_steal_string(struct ldb_message *msg,
2033 const char *attr_name, char *str,
2034 int flags);
2035 int ldb_msg_append_string(struct ldb_message *msg,
2036 const char *attr_name, const char *str,
2037 int flags);
2038 int ldb_msg_append_linearized_dn(struct ldb_message *msg, const char *attr_name,
2039 struct ldb_dn *dn, int flags);
2040 int ldb_msg_append_fmt(struct ldb_message *msg, int flags,
2041 const char *attr_name, const char *fmt, ...) PRINTF_ATTRIBUTE(4,5);
2044 compare two message elements - return 0 on match
2046 int ldb_msg_element_compare(struct ldb_message_element *el1,
2047 struct ldb_message_element *el2);
2048 int ldb_msg_element_compare_name(struct ldb_message_element *el1,
2049 struct ldb_message_element *el2);
2052 Find elements in a message.
2054 This function finds elements and converts to a specific type, with
2055 a given default value if not found. Assumes that elements are
2056 single valued.
2058 const struct ldb_val *ldb_msg_find_ldb_val(const struct ldb_message *msg, const char *attr_name);
2059 int ldb_msg_find_attr_as_int(const struct ldb_message *msg,
2060 const char *attr_name,
2061 int default_value);
2062 unsigned int ldb_msg_find_attr_as_uint(const struct ldb_message *msg,
2063 const char *attr_name,
2064 unsigned int default_value);
2065 int64_t ldb_msg_find_attr_as_int64(const struct ldb_message *msg,
2066 const char *attr_name,
2067 int64_t default_value);
2068 uint64_t ldb_msg_find_attr_as_uint64(const struct ldb_message *msg,
2069 const char *attr_name,
2070 uint64_t default_value);
2071 double ldb_msg_find_attr_as_double(const struct ldb_message *msg,
2072 const char *attr_name,
2073 double default_value);
2074 int ldb_msg_find_attr_as_bool(const struct ldb_message *msg,
2075 const char *attr_name,
2076 int default_value);
2077 const char *ldb_msg_find_attr_as_string(const struct ldb_message *msg,
2078 const char *attr_name,
2079 const char *default_value);
2081 struct ldb_dn *ldb_msg_find_attr_as_dn(struct ldb_context *ldb,
2082 TALLOC_CTX *mem_ctx,
2083 const struct ldb_message *msg,
2084 const char *attr_name);
2086 void ldb_msg_sort_elements(struct ldb_message *msg);
2088 struct ldb_message *ldb_msg_copy_shallow(TALLOC_CTX *mem_ctx,
2089 const struct ldb_message *msg);
2090 struct ldb_message *ldb_msg_copy(TALLOC_CTX *mem_ctx,
2091 const struct ldb_message *msg);
2094 * ldb_msg_canonicalize() is now deprecated
2095 * Please use ldb_msg_normalize() instead
2097 * NOTE: Returned ldb_message object is allocated
2098 * into *ldb's context. Callers are recommended
2099 * to steal the returned object into a TALLOC_CTX
2100 * with short lifetime.
2102 struct ldb_message *ldb_msg_canonicalize(struct ldb_context *ldb,
2103 const struct ldb_message *msg) _DEPRECATED_;
2105 int ldb_msg_normalize(struct ldb_context *ldb,
2106 TALLOC_CTX *mem_ctx,
2107 const struct ldb_message *msg,
2108 struct ldb_message **_msg_out);
2112 * ldb_msg_diff() is now deprecated
2113 * Please use ldb_msg_difference() instead
2115 * NOTE: Returned ldb_message object is allocated
2116 * into *ldb's context. Callers are recommended
2117 * to steal the returned object into a TALLOC_CTX
2118 * with short lifetime.
2120 struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
2121 struct ldb_message *msg1,
2122 struct ldb_message *msg2) _DEPRECATED_;
2125 * return a ldb_message representing the differences between msg1 and msg2.
2126 * If you then use this in a ldb_modify() call,
2127 * it can be used to save edits to a message
2129 * Result message is constructed as follows:
2130 * - LDB_FLAG_MOD_ADD - elements found only in msg2
2131 * - LDB_FLAG_MOD_REPLACE - elements in msg2 that have
2132 * different value in msg1
2133 * Value for msg2 element is used
2134 * - LDB_FLAG_MOD_DELETE - elements found only in msg2
2136 * @return LDB_SUCCESS or LDB_ERR_OPERATIONS_ERROR
2138 int ldb_msg_difference(struct ldb_context *ldb,
2139 TALLOC_CTX *mem_ctx,
2140 struct ldb_message *msg1,
2141 struct ldb_message *msg2,
2142 struct ldb_message **_msg_out);
2145 Tries to find a certain string attribute in a message
2147 \param msg the message to check
2148 \param name attribute name
2149 \param value attribute value
2151 \return 1 on match and 0 otherwise.
2153 int ldb_msg_check_string_attribute(const struct ldb_message *msg,
2154 const char *name,
2155 const char *value);
2158 Integrity check an ldb_message
2160 This function performs basic sanity / integrity checks on an
2161 ldb_message.
2163 \param ldb context in which to perform the checks
2164 \param msg the message to check
2166 \return LDB_SUCCESS if the message is OK, or a non-zero error code
2167 (one of LDB_ERR_INVALID_DN_SYNTAX, LDB_ERR_ENTRY_ALREADY_EXISTS or
2168 LDB_ERR_INVALID_ATTRIBUTE_SYNTAX) if there is a problem with a
2169 message.
2171 int ldb_msg_sanity_check(struct ldb_context *ldb,
2172 const struct ldb_message *msg);
2175 Duplicate an ldb_val structure
2177 This function copies an ldb value structure.
2179 \param mem_ctx the memory context that the duplicated value will be
2180 allocated from
2181 \param v the ldb_val to be duplicated.
2183 \return the duplicated ldb_val structure.
2185 struct ldb_val ldb_val_dup(TALLOC_CTX *mem_ctx, const struct ldb_val *v);
2188 this allows the user to set a debug function for error reporting
2190 int ldb_set_debug(struct ldb_context *ldb,
2191 void (*debug)(void *context, enum ldb_debug_level level,
2192 const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0),
2193 void *context);
2196 * This allows the user to set custom utf8 functions.
2198 * Be aware that casefold in some locales will break ldb expectations. In
2199 * particular, if 'i' is uppercased to 'İ' (a capital I with a dot, used in
2200 * some languages), the string '<guid=' will not equal '<GUID='.
2202 * The default functions casefold ASCII only, and those used by Samba use a
2203 * version of the NTFS UCS-2 upcase table which is dotted-i safe.
2205 * The context argument will be passed to the casefold() and casecmp()
2206 * functions as the first argument. It is unused in the default and Samba
2207 * implementations, but could for example be used to hold a libICU context.
2209 * The second argument for the casefold function is a TALLOC context.
2211 void ldb_set_utf8_functions(struct ldb_context *ldb,
2212 void *context,
2213 char *(*casefold)(void *, void *, const char *, size_t n),
2214 int (*casecmp)(void *ctx, const struct ldb_val *v1,
2215 const struct ldb_val *v2));
2218 * This legacy function is for setting a custom utf8 casefold function. It
2219 * cannot set a comparison function, which makes it very difficult for a
2220 * comparison to be both efficient and correct.
2222 * Use ldb_set_utf8_functions() instead!
2224 void ldb_set_utf8_fns(struct ldb_context *ldb,
2225 void *context,
2226 char *(*casefold)(void *, void *, const char *, size_t n)) _DEPRECATED_;
2229 this sets up debug to print messages on stderr
2231 int ldb_set_debug_stderr(struct ldb_context *ldb);
2233 /* control backend specific opaque values */
2234 int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value);
2235 void *ldb_get_opaque(struct ldb_context *ldb, const char *name);
2237 const char **ldb_attr_list_copy(TALLOC_CTX *mem_ctx, const char * const *attrs);
2238 const char **ldb_attr_list_copy_add(TALLOC_CTX *mem_ctx, const char * const *attrs, const char *new_attr);
2239 int ldb_attr_in_list(const char * const *attrs, const char *attr);
2241 int ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace);
2242 int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace);
2243 void ldb_msg_remove_attr(struct ldb_message *msg, const char *attr);
2244 void ldb_msg_remove_element(struct ldb_message *msg, struct ldb_message_element *el);
2247 void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree,
2248 const char *attr,
2249 const char *replace);
2252 shallow copy a tree - copying only the elements array so that the caller
2253 can safely add new elements without changing the message
2255 struct ldb_parse_tree *ldb_parse_tree_copy_shallow(TALLOC_CTX *mem_ctx,
2256 const struct ldb_parse_tree *ot);
2259 Convert a time structure to a string
2261 This function converts a time_t structure to an LDAP formatted
2262 GeneralizedTime string.
2264 \param mem_ctx the memory context to allocate the return string in
2265 \param t the time structure to convert
2267 \return the formatted string, or NULL if the time structure could
2268 not be converted
2270 char *ldb_timestring(TALLOC_CTX *mem_ctx, time_t t);
2273 Convert a string to a time structure
2275 This function converts an LDAP formatted GeneralizedTime string
2276 to a time_t structure.
2278 \param s the string to convert
2280 \return the time structure, or 0 if the string cannot be converted
2282 time_t ldb_string_to_time(const char *s);
2285 convert a LDAP GeneralizedTime string in ldb_val format to a
2286 time_t.
2288 int ldb_val_to_time(const struct ldb_val *v, time_t *t);
2291 Convert a time structure to a string
2293 This function converts a time_t structure to an LDAP formatted
2294 UTCTime string.
2296 \param mem_ctx the memory context to allocate the return string in
2297 \param t the time structure to convert
2299 \return the formatted string, or NULL if the time structure could
2300 not be converted
2302 char *ldb_timestring_utc(TALLOC_CTX *mem_ctx, time_t t);
2305 Convert a string to a time structure
2307 This function converts an LDAP formatted UTCTime string
2308 to a time_t structure.
2310 \param s the string to convert
2312 \return the time structure, or 0 if the string cannot be converted
2314 time_t ldb_string_utc_to_time(const char *s);
2317 void ldb_qsort (void *const pbase, size_t total_elems, size_t size, void *opaque, ldb_qsort_cmp_fn_t cmp);
2319 #ifndef discard_const
2320 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
2321 #endif
2324 a wrapper around ldb_qsort() that ensures the comparison function is
2325 type safe. This will produce a compilation warning if the types
2326 don't match
2328 #define LDB_TYPESAFE_QSORT(base, numel, opaque, comparison) \
2329 do { \
2330 if (numel > 1) { \
2331 ldb_qsort(base, numel, sizeof((base)[0]), discard_const(opaque), (ldb_qsort_cmp_fn_t)comparison); \
2332 if (0) { \
2333 comparison(&((base)[0]), &((base)[1]), opaque); \
2336 } while (0)
2338 /* allow ldb to also call TYPESAFE_QSORT() */
2339 #ifndef TYPESAFE_QSORT
2340 #define TYPESAFE_QSORT(base, numel, comparison) \
2341 do { \
2342 if (numel > 1) { \
2343 qsort(base, numel, sizeof((base)[0]), (int (*)(const void *, const void *))comparison); \
2344 if (0) { \
2345 comparison(&((base)[0]), &((base)[1])); \
2348 } while (0)
2349 #endif
2351 #ifndef NUMERIC_CMP
2353 * NUMERIC_CMP is a safe replacement for `a - b` in comparison
2354 * functions. It will work on integers, pointers, and floats.
2356 * Rather than
2358 * return a - b;
2360 * use
2362 * return NUMERIC_CMP(a, b);
2364 #define NUMERIC_CMP(a, b) (((a) > (b)) - ((a) < (b)))
2365 #endif
2370 Convert a control into its string representation.
2372 \param mem_ctx TALLOC context to return result on, and to allocate error_string on
2373 \param control A struct ldb_control to convert
2375 \return string representation of the control
2377 char* ldb_control_to_string(TALLOC_CTX *mem_ctx, const struct ldb_control *control);
2379 Convert a string representing a control into a ldb_control structure
2381 \param ldb LDB context
2382 \param mem_ctx TALLOC context to return result on, and to allocate error_string on
2383 \param control_strings A string-formatted control
2385 \return a ldb_control element
2387 struct ldb_control *ldb_parse_control_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *control_strings);
2389 Convert an array of string representation of a control into an array of ldb_control structures
2391 \param ldb LDB context
2392 \param mem_ctx TALLOC context to return result on, and to allocate error_string on
2393 \param control_strings Array of string-formatted controls
2395 \return array of ldb_control elements
2397 struct ldb_control **ldb_parse_control_strings(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char **control_strings);
2400 return the ldb flags
2402 unsigned int ldb_get_flags(struct ldb_context *ldb);
2404 /* set the ldb flags */
2405 void ldb_set_flags(struct ldb_context *ldb, unsigned flags);
2408 struct ldb_dn *ldb_dn_binary_from_ldb_val(TALLOC_CTX *mem_ctx,
2409 struct ldb_context *ldb,
2410 const struct ldb_val *strdn);
2412 int ldb_dn_get_binary(struct ldb_dn *dn, struct ldb_val *val);
2413 int ldb_dn_set_binary(struct ldb_dn *dn, struct ldb_val *val);
2415 /* debugging functions for ldb requests */
2416 void ldb_req_set_location(struct ldb_request *req, const char *location);
2417 const char *ldb_req_location(struct ldb_request *req);
2419 /* set the location marker on a request handle - used for debugging */
2420 #define LDB_REQ_SET_LOCATION(req) ldb_req_set_location(req, __location__)
2423 minimise a DN. The caller must pass in a validated DN.
2425 If the DN has an extended component then only the first extended
2426 component is kept, the DN string is stripped.
2428 The existing dn is modified
2430 bool ldb_dn_minimise(struct ldb_dn *dn);
2433 compare a ldb_val to a string
2435 int ldb_val_string_cmp(const struct ldb_val *v, const char *str);
2437 #endif