ldb: Allow to register extended match rules
[obnox/samba/samba-obnox.git] / 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 #include "replace.h"
41 #include "system/filesys.h"
42 #include "system/time.h"
43 #include "ldb.h"
44 #include "ldb_module.h"
45
46 struct ldb_context;
47
48 struct ldb_module_ops;
49
50 struct ldb_backend_ops;
51
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
55
56 struct ldb_handle {
57         int status;
58         enum ldb_state state;
59         struct ldb_context *ldb;
60         unsigned flags;
61         /* flags dedicated to be set by application using ldb */
62         uint32_t custom_flags;
63         unsigned nesting;
64
65         /* used for debugging */
66         struct ldb_request *parent;
67         const char *location;
68 };
69
70 /* basic module structure */
71 struct ldb_module {
72         struct ldb_module *prev, *next;
73         struct ldb_context *ldb;
74         void *private_data;
75         const struct ldb_module_ops *ops;
76 };
77
78 /*
79   schema related information needed for matching rules
80 */
81 struct ldb_schema {
82         void *attribute_handler_override_private;
83         ldb_attribute_handler_override_fn_t attribute_handler_override;
84         
85         /* attribute handling table */
86         unsigned num_attributes;
87         struct ldb_schema_attribute *attributes;
88
89         unsigned num_dn_extended_syntax;
90         struct ldb_dn_extended_syntax *dn_extended_syntax;
91 };
92
93 /*
94   every ldb connection is started by establishing a ldb_context
95 */
96 struct ldb_context {
97         /* the operations provided by the backend */
98         struct ldb_module *modules;
99
100         /* debugging operations */
101         struct ldb_debug_ops debug_ops;
102
103         /* extended matching rules */
104         struct ldb_extended_match_entry {
105                 const struct ldb_extended_match_rule *rule;
106                 struct ldb_extended_match_entry *prev, *next;
107         } *extended_match_rules;
108
109         /* custom utf8 functions */
110         struct ldb_utf8_fns utf8_fns;
111
112         /* backend specific opaque parameters */
113         struct ldb_opaque {
114                 struct ldb_opaque *next;
115                 const char *name;
116                 void *value;
117         } *opaque;
118
119         struct ldb_schema schema;
120
121         char *err_string;
122
123         int transaction_active;
124
125         int default_timeout;
126
127         unsigned int flags;
128
129         unsigned int create_perms;
130
131         struct tevent_context *ev_ctx;
132
133         bool prepare_commit_done;
134
135         char *partial_debug;
136
137         struct poptOption *popt_options;
138 };
139
140 /* The following definitions come from lib/ldb/common/ldb.c  */
141
142 extern const struct ldb_module_ops ldb_objectclass_module_ops;
143 extern const struct ldb_module_ops ldb_paged_results_module_ops;
144 extern const struct ldb_module_ops ldb_rdn_name_module_ops;
145 extern const struct ldb_module_ops ldb_schema_module_ops;
146 extern const struct ldb_module_ops ldb_asq_module_ops;
147 extern const struct ldb_module_ops ldb_server_sort_module_ops;
148 extern const struct ldb_module_ops ldb_ldap_module_ops;
149 extern const struct ldb_module_ops ldb_ildap_module_ops;
150 extern const struct ldb_module_ops ldb_paged_searches_module_ops;
151 extern const struct ldb_module_ops ldb_tdb_module_ops;
152 extern const struct ldb_module_ops ldb_skel_module_ops;
153 extern const struct ldb_module_ops ldb_subtree_rename_module_ops;
154 extern const struct ldb_module_ops ldb_subtree_delete_module_ops;
155 extern const struct ldb_module_ops ldb_sqlite3_module_ops;
156 extern const struct ldb_module_ops ldb_wins_ldb_module_ops;
157 extern const struct ldb_module_ops ldb_ranged_results_module_ops;
158
159 extern const struct ldb_backend_ops ldb_tdb_backend_ops;
160 extern const struct ldb_backend_ops ldb_sqlite3_backend_ops;
161 extern const struct ldb_backend_ops ldb_ldap_backend_ops;
162 extern const struct ldb_backend_ops ldb_ldapi_backend_ops;
163 extern const struct ldb_backend_ops ldb_ldaps_backend_ops;
164
165 int ldb_setup_wellknown_attributes(struct ldb_context *ldb);
166
167 const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname);
168 void ldb_subclass_remove(struct ldb_context *ldb, const char *classname);
169 int ldb_subclass_add(struct ldb_context *ldb, const char *classname, const char *subclass);
170
171 /* The following definitions come from lib/ldb/common/ldb_utf8.c */
172 char *ldb_casefold_default(void *context, TALLOC_CTX *mem_ctx, const char *s, size_t n);
173
174 void ldb_dump_results(struct ldb_context *ldb, struct ldb_result *result, FILE *f);
175
176
177 /* The following definitions come from lib/ldb/common/ldb_modules.c  */
178
179 const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string);
180 int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
181
182 struct ldb_val ldb_binary_decode(TALLOC_CTX *mem_ctx, const char *str);
183
184
185 /* The following definitions come from lib/ldb/common/ldb_options.c  */
186
187 const char *ldb_options_find(struct ldb_context *ldb, const char *options[],
188                              const char *option_name);
189
190 /* The following definitions come from lib/ldb/common/ldb_ldif.c  */
191
192 struct ldif_read_file_state {
193         FILE *f;
194         size_t line_no;
195 };
196
197 struct ldb_ldif *ldb_ldif_read_file_state(struct ldb_context *ldb, 
198                                           struct ldif_read_file_state *state);
199
200 char *ldb_ldif_write_redacted_trace_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, 
201                                            const struct ldb_ldif *ldif);
202
203 /*
204  * these pack/unpack functions are exposed in the library for use by
205  * ldb tools like ldbdump, but are not part of the public API
206  */
207 int ldb_pack_data(struct ldb_context *ldb,
208                   const struct ldb_message *message,
209                   struct ldb_val *data);
210 int ldb_unpack_data(struct ldb_context *ldb,
211                     const struct ldb_val *data,
212                     struct ldb_message *message);
213
214 #endif