cf4017ef148b0c9e086607b3fb3d084e966b858d
[metze/samba/wip.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 struct ldb_handle {
47         int status;
48         enum ldb_state state;
49         struct ldb_context *ldb;
50 };
51
52 /* basic module structure */
53 struct ldb_module {
54         struct ldb_module *prev, *next;
55         struct ldb_context *ldb;
56         void *private_data;
57         const struct ldb_module_ops *ops;
58 };
59
60 /*
61    these function pointers define the operations that a ldb module can intercept
62 */
63 struct ldb_module_ops {
64         const char *name;
65         int (*init_context) (struct ldb_module *);
66         int (*search)(struct ldb_module *, struct ldb_request *); /* search */
67         int (*add)(struct ldb_module *, struct ldb_request *); /* add */
68         int (*modify)(struct ldb_module *, struct ldb_request *); /* modify */
69         int (*del)(struct ldb_module *, struct ldb_request *); /* delete */
70         int (*rename)(struct ldb_module *, struct ldb_request *); /* rename */
71         int (*request)(struct ldb_module *, struct ldb_request *); /* match any other operation */
72         int (*extended)(struct ldb_module *, struct ldb_request *); /* extended operations */
73         int (*start_transaction)(struct ldb_module *);
74         int (*end_transaction)(struct ldb_module *);
75         int (*del_transaction)(struct ldb_module *);
76         int (*sequence_number)(struct ldb_module *, struct ldb_request *);
77     void *private_data;
78 };
79
80 /*
81   schema related information needed for matching rules
82 */
83 struct ldb_schema {
84         /* attribute handling table */
85         unsigned num_attributes;
86         struct ldb_schema_attribute *attributes;
87
88         unsigned num_dn_extended_syntax;
89         struct ldb_dn_extended_syntax *dn_extended_syntax;
90 };
91
92 /*
93   every ldb connection is started by establishing a ldb_context
94 */
95 struct ldb_context {
96         /* the operations provided by the backend */
97         struct ldb_module *modules;
98
99         /* debugging operations */
100         struct ldb_debug_ops debug_ops;
101
102         /* custom utf8 functions */
103         struct ldb_utf8_fns utf8_fns;
104
105         /* backend specific opaque parameters */
106         struct ldb_opaque {
107                 struct ldb_opaque *next;
108                 const char *name;
109                 void *value;
110         } *opaque;
111
112         struct ldb_schema schema;
113
114         char *err_string;
115
116         int transaction_active;
117
118         int default_timeout;
119
120         unsigned int flags;
121
122         unsigned int create_perms;
123
124         char *modules_dir;
125
126         struct tevent_context *ev_ctx;
127 };
128
129 #ifndef ARRAY_SIZE
130 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
131 #endif
132
133 /*
134   simplify out of memory handling
135 */
136 #define ldb_oom(ldb) ldb_debug_set(ldb, LDB_DEBUG_FATAL, "ldb out of memory at %s:%d\n", __FILE__, __LINE__)
137
138 /* The following definitions come from lib/ldb/common/ldb.c  */
139
140 int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *options[],
141                         struct ldb_module **backend_module);
142 void ldb_set_default_dns(struct ldb_context *ldb);
143
144 /* The following definitions come from lib/ldb/common/ldb_debug.c  */
145 void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
146 void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, 
147                    const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
148
149 /* The following definitions come from lib/ldb/common/ldb_ldif.c  */
150 int ldb_should_b64_encode(const struct ldb_val *val);
151
152 extern const struct ldb_module_ops ldb_objectclass_module_ops;
153 extern const struct ldb_module_ops ldb_operational_module_ops;
154 extern const struct ldb_module_ops ldb_paged_results_module_ops;
155 extern const struct ldb_module_ops ldb_rdn_name_module_ops;
156 extern const struct ldb_module_ops ldb_schema_module_ops;
157 extern const struct ldb_module_ops ldb_asq_module_ops;
158 extern const struct ldb_module_ops ldb_server_sort_module_ops;
159 extern const struct ldb_module_ops ldb_ldap_module_ops;
160 extern const struct ldb_module_ops ldb_ildap_module_ops;
161 extern const struct ldb_module_ops ldb_paged_searches_module_ops;
162 extern const struct ldb_module_ops ldb_tdb_module_ops;
163 extern const struct ldb_module_ops ldb_skel_module_ops;
164 extern const struct ldb_module_ops ldb_subtree_rename_module_ops;
165 extern const struct ldb_module_ops ldb_subtree_delete_module_ops;
166 extern const struct ldb_module_ops ldb_sqlite3_module_ops;
167 extern const struct ldb_module_ops ldb_wins_ldb_module_ops;
168 extern const struct ldb_module_ops ldb_ranged_results_module_ops;
169
170 extern const struct ldb_backend_ops ldb_tdb_backend_ops;
171 extern const struct ldb_backend_ops ldb_sqlite3_backend_ops;
172 extern const struct ldb_backend_ops ldb_ldap_backend_ops;
173 extern const struct ldb_backend_ops ldb_ldapi_backend_ops;
174 extern const struct ldb_backend_ops ldb_ldaps_backend_ops;
175
176 int ldb_match_msg(struct ldb_context *ldb,
177                   const struct ldb_message *msg,
178                   const struct ldb_parse_tree *tree,
179                   struct ldb_dn *base,
180                   enum ldb_scope scope);
181
182 const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb,
183                                                             const char *syntax);
184
185 /* The following definitions come from lib/ldb/common/ldb_attributes.c  */
186
187 int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb,
188                                          const char *name,
189                                          unsigned flags,
190                                          const struct ldb_schema_syntax *syntax);
191 int ldb_schema_attribute_add(struct ldb_context *ldb, 
192                              const char *name,
193                              unsigned flags,
194                              const char *syntax);
195 void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name);
196 int ldb_setup_wellknown_attributes(struct ldb_context *ldb);
197
198 const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname);
199 void ldb_subclass_remove(struct ldb_context *ldb, const char *classname);
200 int ldb_subclass_add(struct ldb_context *ldb, const char *classname, const char *subclass);
201
202 int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx,
203                      const struct ldb_val *in, struct ldb_val *out);
204 int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx,
205                           const struct ldb_val *v1, const struct ldb_val *v2);
206
207 /* The following definitions come from lib/ldb/common/ldb_controls.c  */
208 struct ldb_control *get_control_from_list(struct ldb_control **controls, const char *oid);
209 int save_controls(struct ldb_control *exclude, struct ldb_request *req, struct ldb_control ***saver);
210 int check_critical_controls(struct ldb_control **controls);
211
212 /* The following definitions come from lib/ldb/common/ldb_utf8.c */
213 char *ldb_casefold_default(void *context, void *mem_ctx, const char *s, size_t n);
214
215 void ldb_msg_remove_element(struct ldb_message *msg, struct ldb_message_element *el);
216
217 int ldb_msg_element_compare_name(struct ldb_message_element *el1, 
218                                  struct ldb_message_element *el2);
219 void ldb_dump_results(struct ldb_context *ldb, struct ldb_result *result, FILE *f);
220
221 /**
222   Obtain current/next database sequence number
223 */
224 int ldb_sequence_number(struct ldb_context *ldb, enum ldb_sequence_type type, uint64_t *seq_num);
225
226 #define LDB_SEQ_GLOBAL_SEQUENCE    0x01
227 #define LDB_SEQ_TIMESTAMP_SEQUENCE 0x02
228
229
230 /* MODULES specific headers -- SSS */
231
232 /* The following definitions come from lib/ldb/common/ldb_modules.c  */
233
234 const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string);
235 int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, struct ldb_module *backend, struct ldb_module **out);
236 int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
237 int ldb_init_module_chain(struct ldb_context *ldb, struct ldb_module *module);
238 int ldb_next_request(struct ldb_module *module, struct ldb_request *request);
239 int ldb_next_start_trans(struct ldb_module *module);
240 int ldb_next_end_trans(struct ldb_module *module);
241 int ldb_next_del_trans(struct ldb_module *module);
242 int ldb_next_init(struct ldb_module *module);
243
244 void ldb_set_errstring(struct ldb_context *ldb, const char *err_string);
245 void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
246 void ldb_reset_err_string(struct ldb_context *ldb);
247
248 const char *ldb_default_modules_dir(void);
249
250 int ldb_register_module(const struct ldb_module_ops *);
251
252 typedef int (*ldb_connect_fn)(struct ldb_context *ldb, const char *url,
253                               unsigned int flags, const char *options[],
254                               struct ldb_module **module);
255
256 struct ldb_backend_ops {
257         const char *name;
258         ldb_connect_fn connect_fn;
259 };
260
261 const char *ldb_default_modules_dir(void);
262
263 int ldb_register_backend(const char *url_prefix, ldb_connect_fn);
264
265 struct ldb_handle *ldb_handle_new(TALLOC_CTX *mem_ctx, struct ldb_context *ldb);
266
267 int ldb_module_send_entry(struct ldb_request *req,
268                           struct ldb_message *msg,
269                           struct ldb_control **ctrls);
270
271 int ldb_module_send_referral(struct ldb_request *req,
272                                            char *ref);
273
274 int ldb_module_done(struct ldb_request *req,
275                     struct ldb_control **ctrls,
276                     struct ldb_extended *response,
277                     int error);
278
279 int ldb_mod_register_control(struct ldb_module *module, const char *oid);
280
281
282 struct ldb_val ldb_binary_decode(void *mem_ctx, const char *str);
283
284 #endif