Merge branch 'v4-0-trivial' into v4-0-gmake3
[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 /* basic module structure */
45 struct ldb_module {
46         struct ldb_module *prev, *next;
47         struct ldb_context *ldb;
48         void *private_data;
49         const struct ldb_module_ops *ops;
50 };
51
52 /* 
53    these function pointers define the operations that a ldb module must perform
54    they correspond exactly to the ldb_*() interface 
55 */
56 struct ldb_module_ops {
57         const char *name;
58         int (*init_context) (struct ldb_module *);
59         int (*search)(struct ldb_module *, struct ldb_request *); /* search */
60         int (*add)(struct ldb_module *, struct ldb_request *); /* add */
61         int (*modify)(struct ldb_module *, struct ldb_request *); /* modify */
62         int (*del)(struct ldb_module *, struct ldb_request *); /* delete */
63         int (*rename)(struct ldb_module *, struct ldb_request *); /* rename */
64         int (*request)(struct ldb_module *, struct ldb_request *); /* match any other operation */
65         int (*extended)(struct ldb_module *, struct ldb_request *); /* extended operations */
66         int (*start_transaction)(struct ldb_module *);
67         int (*end_transaction)(struct ldb_module *);
68         int (*del_transaction)(struct ldb_module *);
69         int (*wait)(struct ldb_handle *, enum ldb_wait_type);
70         int (*sequence_number)(struct ldb_module *, struct ldb_request *);
71 };
72
73 typedef int (*ldb_connect_fn) (struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[],
74                                struct ldb_module **module);
75
76 const char *ldb_default_modules_dir(void);
77
78 /*
79   schema related information needed for matching rules
80 */
81 struct ldb_schema {
82         /* attribute handling table */
83         unsigned num_attributes;
84         struct ldb_schema_attribute *attributes;
85
86         /* objectclass information */
87         unsigned num_classes;
88         struct ldb_subclass {
89                 char *name;
90                 char **subclasses;
91         } *classes;
92 };
93
94 /*
95   every ldb connection is started by establishing a ldb_context
96 */
97 struct ldb_context {
98         /* the operations provided by the backend */
99         struct ldb_module *modules;
100
101         /* debugging operations */
102         struct ldb_debug_ops debug_ops;
103
104         /* custom utf8 functions */
105         struct ldb_utf8_fns utf8_fns;
106
107         /* backend specific opaque parameters */
108         struct ldb_opaque {
109                 struct ldb_opaque *next;
110                 const char *name;
111                 void *value;
112         } *opaque;
113
114         struct ldb_schema schema;
115
116         char *err_string;
117
118         int transaction_active;
119
120         int default_timeout;
121
122         unsigned int flags;
123
124         unsigned int create_perms;
125
126         char *modules_dir;
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_modules.c  */
145
146 const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string);
147 int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, struct ldb_module *backend, struct ldb_module **out);
148 int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
149 int ldb_init_module_chain(struct ldb_context *ldb, struct ldb_module *module);
150 int ldb_next_request(struct ldb_module *module, struct ldb_request *request);
151 int ldb_next_start_trans(struct ldb_module *module);
152 int ldb_next_end_trans(struct ldb_module *module);
153 int ldb_next_del_trans(struct ldb_module *module);
154 int ldb_next_init(struct ldb_module *module);
155
156 void ldb_set_errstring(struct ldb_context *ldb, const char *err_string);
157 void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
158 void ldb_reset_err_string(struct ldb_context *ldb);
159
160 int ldb_register_module(const struct ldb_module_ops *);
161 int ldb_register_backend(const char *url_prefix, ldb_connect_fn);
162 void *ldb_dso_load_symbol(struct ldb_context *ldb, const char *name,
163                             const char *symbol);
164
165 /* The following definitions come from lib/ldb/common/ldb_debug.c  */
166 void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
167 void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, 
168                    const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
169
170 /* The following definitions come from lib/ldb/common/ldb_ldif.c  */
171 int ldb_should_b64_encode(const struct ldb_val *val);
172
173 int ldb_objectclass_init(void);
174 int ldb_operational_init(void);
175 int ldb_paged_results_init(void);
176 int ldb_paged_searches_init(void);
177 int ldb_rdn_name_init(void);
178 int ldb_schema_init(void);
179 int ldb_asq_init(void);
180 int ldb_sort_init(void);
181 int ldb_ldap_init(void);
182 int ldb_ildap_init(void);
183 int ldb_tdb_init(void);
184 int ldb_skel_init(void);
185 int ldb_sqlite3_init(void);
186
187 int ldb_match_msg(struct ldb_context *ldb,
188                   const struct ldb_message *msg,
189                   const struct ldb_parse_tree *tree,
190                   struct ldb_dn *base,
191                   enum ldb_scope scope);
192
193 const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb,
194                                                             const char *syntax);
195
196 /* The following definitions come from lib/ldb/common/ldb_attributes.c  */
197
198 int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb,
199                                          const char *name,
200                                          unsigned flags,
201                                          const struct ldb_schema_syntax *syntax);
202 int ldb_schema_attribute_add(struct ldb_context *ldb, 
203                              const char *name,
204                              unsigned flags,
205                              const char *syntax);
206 void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name);
207 int ldb_setup_wellknown_attributes(struct ldb_context *ldb);
208
209 const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname);
210 void ldb_subclass_remove(struct ldb_context *ldb, const char *classname);
211 int ldb_subclass_add(struct ldb_context *ldb, const char *classname, const char *subclass);
212
213 int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx,
214                      const struct ldb_val *in, struct ldb_val *out);
215 int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx,
216                           const struct ldb_val *v1, const struct ldb_val *v2);
217
218 /* The following definitions come from lib/ldb/common/ldb_controls.c  */
219 struct ldb_control *get_control_from_list(struct ldb_control **controls, const char *oid);
220 int save_controls(struct ldb_control *exclude, struct ldb_request *req, struct ldb_control ***saver);
221 int check_critical_controls(struct ldb_control **controls);
222
223 /* The following definitions come from lib/ldb/common/ldb_utf8.c */
224 char *ldb_casefold_default(void *context, void *mem_ctx, const char *s);
225
226 void ldb_msg_remove_element(struct ldb_message *msg, struct ldb_message_element *el);
227
228 /**
229   Obtain current/next database sequence number
230 */
231 int ldb_sequence_number(struct ldb_context *ldb, enum ldb_sequence_type type, uint64_t *seq_num);
232
233 #define LDB_SEQ_GLOBAL_SEQUENCE    0x01
234 #define LDB_SEQ_TIMESTAMP_SEQUENCE 0x02
235
236
237 #endif