Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into 4-0-abartlet
[kai/samba.git] / source4 / lib / ldb / include / ldb_private.h
1 /* 
2    ldb database library
3
4    Copyright (C) Andrew Tridgell    2004
5    Copyright (C) Stefan Metzmacher  2004
6    Copyright (C) Simo Sorce         2004-2005
7
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
11    
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.
16
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.
21
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/>.
24 */
25
26 /*
27  *  Name: ldb
28  *
29  *  Component: ldb private header
30  *
31  *  Description: defines internal ldb structures used by the subsystem and modules
32  *
33  *  Author: Andrew Tridgell
34  *  Author: Stefan Metzmacher
35  */
36
37 #ifndef _LDB_PRIVATE_H_
38 #define _LDB_PRIVATE_H_ 1
39
40 struct ldb_context;
41
42 struct ldb_module_ops;
43
44 struct ldb_backend_ops;
45
46 /* basic module structure */
47 struct ldb_module {
48         struct ldb_module *prev, *next;
49         struct ldb_context *ldb;
50         void *private_data;
51         const struct ldb_module_ops *ops;
52 };
53
54 /* 
55    these function pointers define the operations that a ldb module must perform
56    they correspond exactly to the ldb_*() interface 
57 */
58 struct ldb_module_ops {
59         const char *name;
60         int (*init_context) (struct ldb_module *);
61         int (*search)(struct ldb_module *, struct ldb_request *); /* search */
62         int (*add)(struct ldb_module *, struct ldb_request *); /* add */
63         int (*modify)(struct ldb_module *, struct ldb_request *); /* modify */
64         int (*del)(struct ldb_module *, struct ldb_request *); /* delete */
65         int (*rename)(struct ldb_module *, struct ldb_request *); /* rename */
66         int (*request)(struct ldb_module *, struct ldb_request *); /* match any other operation */
67         int (*extended)(struct ldb_module *, struct ldb_request *); /* extended operations */
68         int (*start_transaction)(struct ldb_module *);
69         int (*end_transaction)(struct ldb_module *);
70         int (*del_transaction)(struct ldb_module *);
71         int (*wait)(struct ldb_handle *, enum ldb_wait_type);
72         int (*sequence_number)(struct ldb_module *, struct ldb_request *);
73 };
74
75
76 typedef int (*ldb_connect_fn) (struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[],
77                                struct ldb_module **module);
78
79
80 struct ldb_backend_ops {
81         const char *name;
82         ldb_connect_fn connect_fn;
83 };
84
85 const char *ldb_default_modules_dir(void);
86
87 /*
88   schema related information needed for matching rules
89 */
90 struct ldb_schema {
91         /* attribute handling table */
92         unsigned num_attributes;
93         struct ldb_schema_attribute *attributes;
94 };
95
96 /*
97   every ldb connection is started by establishing a ldb_context
98 */
99 struct ldb_context {
100         /* the operations provided by the backend */
101         struct ldb_module *modules;
102
103         /* debugging operations */
104         struct ldb_debug_ops debug_ops;
105
106         /* custom utf8 functions */
107         struct ldb_utf8_fns utf8_fns;
108
109         /* backend specific opaque parameters */
110         struct ldb_opaque {
111                 struct ldb_opaque *next;
112                 const char *name;
113                 void *value;
114         } *opaque;
115
116         struct ldb_schema schema;
117
118         char *err_string;
119
120         int transaction_active;
121
122         int default_timeout;
123
124         unsigned int flags;
125
126         unsigned int create_perms;
127
128         char *modules_dir;
129
130         struct event_context *ev_ctx;
131 };
132
133 #ifndef ARRAY_SIZE
134 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
135 #endif
136
137 /*
138   simplify out of memory handling
139 */
140 #define ldb_oom(ldb) ldb_debug_set(ldb, LDB_DEBUG_FATAL, "ldb out of memory at %s:%d\n", __FILE__, __LINE__)
141
142 /* The following definitions come from lib/ldb/common/ldb.c  */
143
144 int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *options[],
145                         struct ldb_module **backend_module);
146 void ldb_set_default_dns(struct ldb_context *ldb);
147
148 /* The following definitions come from lib/ldb/common/ldb_modules.c  */
149
150 const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string);
151 int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, struct ldb_module *backend, struct ldb_module **out);
152 int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
153 int ldb_init_module_chain(struct ldb_context *ldb, struct ldb_module *module);
154 int ldb_next_request(struct ldb_module *module, struct ldb_request *request);
155 int ldb_next_start_trans(struct ldb_module *module);
156 int ldb_next_end_trans(struct ldb_module *module);
157 int ldb_next_del_trans(struct ldb_module *module);
158 int ldb_next_init(struct ldb_module *module);
159
160 void ldb_set_errstring(struct ldb_context *ldb, const char *err_string);
161 void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
162 void ldb_reset_err_string(struct ldb_context *ldb);
163
164 int ldb_register_module(const struct ldb_module_ops *);
165 int ldb_register_backend(const char *url_prefix, ldb_connect_fn);
166 void *ldb_dso_load_symbol(struct ldb_context *ldb, const char *name,
167                             const char *symbol);
168
169 /* The following definitions come from lib/ldb/common/ldb_debug.c  */
170 void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
171 void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, 
172                    const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
173
174 /* The following definitions come from lib/ldb/common/ldb_ldif.c  */
175 int ldb_should_b64_encode(const struct ldb_val *val);
176
177 extern const struct ldb_module_ops ldb_objectclass_module_ops;
178 extern const struct ldb_module_ops ldb_operational_module_ops;
179 extern const struct ldb_module_ops ldb_paged_results_module_ops;
180 extern const struct ldb_module_ops ldb_rdn_name_module_ops;
181 extern const struct ldb_module_ops ldb_schema_module_ops;
182 extern const struct ldb_module_ops ldb_asq_module_ops;
183 extern const struct ldb_module_ops ldb_server_sort_module_ops;
184 extern const struct ldb_module_ops ldb_ldap_module_ops;
185 extern const struct ldb_module_ops ldb_ildap_module_ops;
186 extern const struct ldb_module_ops ldb_paged_searches_module_ops;
187 extern const struct ldb_module_ops ldb_tdb_module_ops;
188 extern const struct ldb_module_ops ldb_skel_module_ops;
189 extern const struct ldb_module_ops ldb_subtree_rename_module_ops;
190 extern const struct ldb_module_ops ldb_subtree_delete_module_ops;
191 extern const struct ldb_module_ops ldb_sqlite3_module_ops;
192 extern const struct ldb_module_ops ldb_wins_ldb_module_ops;
193 extern const struct ldb_module_ops ldb_ranged_results_module_ops;
194
195 extern const struct ldb_backend_ops ldb_tdb_backend_ops;
196 extern const struct ldb_backend_ops ldb_sqlite3_backend_ops;
197 extern const struct ldb_backend_ops ldb_ldap_backend_ops;
198 extern const struct ldb_backend_ops ldb_ldapi_backend_ops;
199 extern const struct ldb_backend_ops ldb_ldaps_backend_ops;
200
201 int ldb_match_msg(struct ldb_context *ldb,
202                   const struct ldb_message *msg,
203                   const struct ldb_parse_tree *tree,
204                   struct ldb_dn *base,
205                   enum ldb_scope scope);
206
207 const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb,
208                                                             const char *syntax);
209
210 /* The following definitions come from lib/ldb/common/ldb_attributes.c  */
211
212 int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb,
213                                          const char *name,
214                                          unsigned flags,
215                                          const struct ldb_schema_syntax *syntax);
216 int ldb_schema_attribute_add(struct ldb_context *ldb, 
217                              const char *name,
218                              unsigned flags,
219                              const char *syntax);
220 void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name);
221 int ldb_setup_wellknown_attributes(struct ldb_context *ldb);
222
223 const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname);
224 void ldb_subclass_remove(struct ldb_context *ldb, const char *classname);
225 int ldb_subclass_add(struct ldb_context *ldb, const char *classname, const char *subclass);
226
227 int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx,
228                      const struct ldb_val *in, struct ldb_val *out);
229 int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx,
230                           const struct ldb_val *v1, const struct ldb_val *v2);
231
232 /* The following definitions come from lib/ldb/common/ldb_controls.c  */
233 struct ldb_control *get_control_from_list(struct ldb_control **controls, const char *oid);
234 int save_controls(struct ldb_control *exclude, struct ldb_request *req, struct ldb_control ***saver);
235 int check_critical_controls(struct ldb_control **controls);
236
237 /* The following definitions come from lib/ldb/common/ldb_utf8.c */
238 char *ldb_casefold_default(void *context, void *mem_ctx, const char *s);
239
240 void ldb_msg_remove_element(struct ldb_message *msg, struct ldb_message_element *el);
241
242 /**
243   Obtain current/next database sequence number
244 */
245 int ldb_sequence_number(struct ldb_context *ldb, enum ldb_sequence_type type, uint64_t *seq_num);
246
247 #define LDB_SEQ_GLOBAL_SEQUENCE    0x01
248 #define LDB_SEQ_TIMESTAMP_SEQUENCE 0x02
249
250
251 #endif