4 Copyright (C) Andrew Tridgell 2004
5 Copyright (C) Stefan Metzmacher 2004
6 Copyright (C) Simo Sorce 2004-2005
8 ** NOTE! The following LGPL license applies to the ldb
9 ** library. This does NOT imply that all of Samba is released
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/>.
29 * Component: ldb private header
31 * Description: defines internal ldb structures used by the subsystem and modules
33 * Author: Andrew Tridgell
34 * Author: Stefan Metzmacher
37 #ifndef _LDB_PRIVATE_H_
38 #define _LDB_PRIVATE_H_ 1
41 #include "system/filesys.h"
42 #include "system/time.h"
44 #include "ldb_module.h"
48 struct ldb_module_ops;
50 struct ldb_backend_ops;
52 #define LDB_HANDLE_FLAG_DONE_CALLED 1
53 /* call is from an untrusted source - eg. over ldap:// */
54 #define LDB_HANDLE_FLAG_UNTRUSTED 2
59 struct ldb_context *ldb;
61 /* flags dedicated to be set by application using ldb */
62 uint32_t custom_flags;
65 /* Private event context (if not NULL) */
66 struct tevent_context *event_context;
68 /* used for debugging */
69 struct ldb_request *parent;
73 /* basic module structure */
75 struct ldb_module *prev, *next;
76 struct ldb_context *ldb;
78 const struct ldb_module_ops *ops;
82 schema related information needed for matching rules
85 void *attribute_handler_override_private;
86 ldb_attribute_handler_override_fn_t attribute_handler_override;
88 /* attribute handling table */
89 unsigned num_attributes;
90 struct ldb_schema_attribute *attributes;
92 unsigned num_dn_extended_syntax;
93 struct ldb_dn_extended_syntax *dn_extended_syntax;
96 * If set, the attribute_handler_override has the details of
97 * what attributes have an index
99 bool index_handler_override;
100 bool one_level_indexes;
104 every ldb connection is started by establishing a ldb_context
107 /* the operations provided by the backend */
108 struct ldb_module *modules;
110 /* debugging operations */
111 struct ldb_debug_ops debug_ops;
113 /* extended matching rules */
114 struct ldb_extended_match_entry {
115 const struct ldb_extended_match_rule *rule;
116 struct ldb_extended_match_entry *prev, *next;
117 } *extended_match_rules;
119 /* custom utf8 functions */
120 struct ldb_utf8_fns utf8_fns;
122 /* backend specific opaque parameters */
124 struct ldb_opaque *next;
129 struct ldb_schema schema;
133 int transaction_active;
139 unsigned int create_perms;
141 struct tevent_context *ev_ctx;
144 * If the backend holds locks, we must not use a global event
145 * context, so this flag will be set and ldb_handle_new() will
146 * build a new event context
148 bool require_private_event_context;
150 bool prepare_commit_done;
154 struct poptOption *popt_options;
157 /* The following definitions come from lib/ldb/common/ldb.c */
159 extern const struct ldb_module_ops ldb_objectclass_module_ops;
160 extern const struct ldb_module_ops ldb_paged_results_module_ops;
161 extern const struct ldb_module_ops ldb_rdn_name_module_ops;
162 extern const struct ldb_module_ops ldb_schema_module_ops;
163 extern const struct ldb_module_ops ldb_asq_module_ops;
164 extern const struct ldb_module_ops ldb_server_sort_module_ops;
165 extern const struct ldb_module_ops ldb_ldap_module_ops;
166 extern const struct ldb_module_ops ldb_ildap_module_ops;
167 extern const struct ldb_module_ops ldb_paged_searches_module_ops;
168 extern const struct ldb_module_ops ldb_tdb_module_ops;
169 extern const struct ldb_module_ops ldb_skel_module_ops;
170 extern const struct ldb_module_ops ldb_subtree_rename_module_ops;
171 extern const struct ldb_module_ops ldb_subtree_delete_module_ops;
172 extern const struct ldb_module_ops ldb_sqlite3_module_ops;
173 extern const struct ldb_module_ops ldb_wins_ldb_module_ops;
174 extern const struct ldb_module_ops ldb_ranged_results_module_ops;
176 extern const struct ldb_backend_ops ldb_tdb_backend_ops;
177 extern const struct ldb_backend_ops ldb_sqlite3_backend_ops;
178 extern const struct ldb_backend_ops ldb_ldap_backend_ops;
179 extern const struct ldb_backend_ops ldb_ldapi_backend_ops;
180 extern const struct ldb_backend_ops ldb_ldaps_backend_ops;
182 int ldb_setup_wellknown_attributes(struct ldb_context *ldb);
184 remove attributes with a specified flag (eg LDB_ATTR_FLAG_FROM_DB) for this ldb context
186 This is to permit correct reloads
188 void ldb_schema_attribute_remove_flagged(struct ldb_context *ldb, unsigned int flag);
189 int ldb_schema_attribute_fill_with_syntax(struct ldb_context *ldb,
191 const char *attribute,
193 const struct ldb_schema_syntax *syntax,
194 struct ldb_schema_attribute *a);
196 const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname);
197 void ldb_subclass_remove(struct ldb_context *ldb, const char *classname);
198 int ldb_subclass_add(struct ldb_context *ldb, const char *classname, const char *subclass);
200 /* The following definitions come from lib/ldb/common/ldb_utf8.c */
201 char *ldb_casefold_default(void *context, TALLOC_CTX *mem_ctx, const char *s, size_t n);
203 void ldb_dump_results(struct ldb_context *ldb, struct ldb_result *result, FILE *f);
206 /* The following definitions come from lib/ldb/common/ldb_modules.c */
208 const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string);
209 int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
211 struct ldb_val ldb_binary_decode(TALLOC_CTX *mem_ctx, const char *str);
214 /* The following definitions come from lib/ldb/common/ldb_options.c */
216 const char *ldb_options_find(struct ldb_context *ldb, const char *options[],
217 const char *option_name);
219 /* The following definitions come from lib/ldb/common/ldb_ldif.c */
221 struct ldif_read_file_state {
226 struct ldb_ldif *ldb_ldif_read_file_state(struct ldb_context *ldb,
227 struct ldif_read_file_state *state);
229 char *ldb_ldif_write_redacted_trace_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
230 const struct ldb_ldif *ldif);
233 * Get the LDB context in use on an LDB DN.
235 * This is helpful to the python LDB code, which may use as part of
236 * adding base and child components to an existing DN.
238 struct ldb_context *ldb_dn_get_ldb_context(struct ldb_dn *dn);
240 #define LDB_MSG_FIND_COMMON_REMOVE_DUPLICATES 1
243 Determine whether any values in an element are also in another element,
244 and optionally fix that.
246 \param ldb an ldb context
247 \param mem_ctx a talloc context
249 \param other_el another element
250 \param options flags controlling the function behaviour
252 Without the LDB_MSG_FIND_COMMON_REMOVE_DUPLICATES flag, return
253 LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS if the elements share values, and
254 LDB_SUCCESS if they don't. That is, determine whether there is an
255 intersection without changing anything.
257 With the LDB_MSG_FIND_COMMON_REMOVE_DUPLICATES flag, any values in common
258 are removed from the first element and LDB_SUCCESS is returned.
260 LDB_ERR_OPERATIONS_ERROR indicates an allocation failure or an unknown option.
261 LDB_ERR_INAPPROPRIATE_MATCHING means the elements differ in name.
264 int ldb_msg_find_common_values(struct ldb_context *ldb,
266 struct ldb_message_element *el,
267 struct ldb_message_element *other_el,
271 Detect whether an element contains duplicate values
273 \param ldb a currently unused ldb_context struct
274 \param mem_ctx a talloc context
275 \param el the element to search
276 \param duplicate will point to a duplicate value if there are duplicates,
278 \param options is a flags field. All values are reserved.
280 \return an ldb error code. LDB_ERR_OPERATIONS_ERROR indicates an allocation
281 failure or an unknown option flag. Otherwise LDB_SUCCESS.
283 \note This search is case sensitive
285 int ldb_msg_find_duplicate_val(struct ldb_context *ldb,
287 const struct ldb_message_element *el,
288 struct ldb_val **duplicate,