8db28d262cf094fb68f11805132e0921d7fa2569
[metze/samba/wip.git] / source4 / lib / ldb / common / ldb_modules.c
1 /* 
2    ldb database library
3
4    Copyright (C) Simo Sorce  2004-2008
5
6      ** NOTE! The following LGPL license applies to the ldb
7      ** library. This does NOT imply that all of Samba is released
8      ** under the LGPL
9    
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 3 of the License, or (at your option) any later version.
14
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Lesser General Public License for more details.
19
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 */
23
24 /*
25  *  Name: ldb
26  *
27  *  Component: ldb modules core
28  *
29  *  Description: core modules routines
30  *
31  *  Author: Simo Sorce
32  */
33
34 #include "ldb_includes.h"
35
36 #if (_SAMBA_BUILD_ >= 4)
37 #include "includes.h"
38 #endif
39
40 #define LDB_MODULE_PREFIX       "modules:"
41 #define LDB_MODULE_PREFIX_LEN   8
42
43 static void *ldb_dso_load_symbol(struct ldb_context *ldb, const char *name,
44                                  const char *symbol);
45
46 void ldb_set_modules_dir(struct ldb_context *ldb, const char *path)
47 {
48         talloc_free(ldb->modules_dir);
49         ldb->modules_dir = talloc_strdup(ldb, path);
50 }
51
52 static char *ldb_modules_strdup_no_spaces(TALLOC_CTX *mem_ctx, const char *string)
53 {
54         int i, len;
55         char *trimmed;
56
57         trimmed = talloc_strdup(mem_ctx, string);
58         if (!trimmed) {
59                 return NULL;
60         }
61
62         len = strlen(trimmed);
63         for (i = 0; trimmed[i] != '\0'; i++) {
64                 switch (trimmed[i]) {
65                 case ' ':
66                 case '\t':
67                 case '\n':
68                         memmove(&trimmed[i], &trimmed[i + 1], len -i -1);
69                         break;
70                 }
71         }
72
73         return trimmed;
74 }
75
76
77 /* modules are called in inverse order on the stack.
78    Lets place them as an admin would think the right order is.
79    Modules order is important */
80 const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string)
81 {
82         char **modules = NULL;
83         const char **m;
84         char *modstr, *p;
85         int i;
86
87         /* spaces not admitted */
88         modstr = ldb_modules_strdup_no_spaces(mem_ctx, string);
89         if ( ! modstr) {
90                 ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_strdup_no_spaces()\n");
91                 return NULL;
92         }
93
94         modules = talloc_realloc(mem_ctx, modules, char *, 2);
95         if ( ! modules ) {
96                 ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_list_from_string()\n");
97                 talloc_free(modstr);
98                 return NULL;
99         }
100         talloc_steal(modules, modstr);
101
102         i = 0;
103         /* The str*r*chr walks backwards:  This is how we get the inverse order mentioned above */
104         while ((p = strrchr(modstr, ',')) != NULL) {
105                 *p = '\0';
106                 p++;
107                 modules[i] = p;
108
109                 i++;
110                 modules = talloc_realloc(mem_ctx, modules, char *, i + 2);
111                 if ( ! modules ) {
112                         ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_list_from_string()\n");
113                         return NULL;
114                 }
115
116         }
117         modules[i] = modstr;
118
119         modules[i + 1] = NULL;
120
121         m = (const char **)modules;
122
123         return m;
124 }
125
126 static struct backends_list_entry {
127         struct ldb_backend_ops *ops;
128         struct backends_list_entry *prev, *next;
129 } *ldb_backends = NULL;
130
131 static struct ops_list_entry {
132         const struct ldb_module_ops *ops;
133         struct ops_list_entry *next;    
134 } *registered_modules = NULL;
135
136 static const struct ldb_builtins {
137         const struct ldb_backend_ops *backend_ops;
138         const struct ldb_module_ops *module_ops;
139 } builtins[];
140
141 static ldb_connect_fn ldb_find_backend(const char *url)
142 {
143         struct backends_list_entry *backend;
144         int i;
145
146         for (i = 0; builtins[i].backend_ops || builtins[i].module_ops; i++) {
147                 if (builtins[i].backend_ops == NULL) continue;
148
149                 if (strncmp(builtins[i].backend_ops->name, url,
150                             strlen(builtins[i].backend_ops->name)) == 0) {
151                         return builtins[i].backend_ops->connect_fn;
152                 }
153         }
154
155         for (backend = ldb_backends; backend; backend = backend->next) {
156                 if (strncmp(backend->ops->name, url,
157                             strlen(backend->ops->name)) == 0) {
158                         return backend->ops->connect_fn;
159                 }
160         }
161
162         return NULL;
163 }
164
165 /*
166  register a new ldb backend
167 */
168 int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn)
169 {
170         struct ldb_backend_ops *backend;
171         struct backends_list_entry *entry;
172
173         backend = talloc(talloc_autofree_context(), struct ldb_backend_ops);
174         if (!backend) return LDB_ERR_OPERATIONS_ERROR;
175
176         entry = talloc(talloc_autofree_context(), struct backends_list_entry);
177         if (!entry) {
178                 talloc_free(backend);
179                 return LDB_ERR_OPERATIONS_ERROR;
180         }
181
182         if (ldb_find_backend(url_prefix)) {
183                 return LDB_SUCCESS;
184         }
185
186         /* Maybe check for duplicity here later on? */
187
188         backend->name = talloc_strdup(backend, url_prefix);
189         backend->connect_fn = connectfn;
190         entry->ops = backend;
191         DLIST_ADD(ldb_backends, entry);
192
193         return LDB_SUCCESS;
194 }
195
196 /*
197    Return the ldb module form of a database.
198    The URL can either be one of the following forms
199    ldb://path
200    ldapi://path
201
202    flags is made up of LDB_FLG_*
203
204    the options are passed uninterpreted to the backend, and are
205    backend specific.
206
207    This allows modules to get at only the backend module, for example where a
208    module may wish to direct certain requests at a particular backend.
209 */
210 int ldb_connect_backend(struct ldb_context *ldb,
211                         const char *url,
212                         const char *options[],
213                         struct ldb_module **backend_module)
214 {
215         int ret;
216         char *backend;
217         ldb_connect_fn fn;
218
219         if (strchr(url, ':') != NULL) {
220                 backend = talloc_strndup(ldb, url, strchr(url, ':')-url);
221         } else {
222                 /* Default to tdb */
223                 backend = talloc_strdup(ldb, "tdb");
224         }
225
226         fn = ldb_find_backend(backend);
227
228         if (fn == NULL) {
229                 struct ldb_backend_ops *ops;
230                 char *symbol_name = talloc_asprintf(ldb, "ldb_%s_backend_ops", backend);
231                 if (symbol_name == NULL) {
232                         return LDB_ERR_OPERATIONS_ERROR;
233                 }
234                 ops = ldb_dso_load_symbol(ldb, backend, symbol_name);
235                 if (ops != NULL) {
236                         fn = ops->connect_fn;
237                 }
238                 talloc_free(symbol_name);
239         }
240
241         talloc_free(backend);
242
243         if (fn == NULL) {
244                 ldb_debug(ldb, LDB_DEBUG_FATAL,
245                           "Unable to find backend for '%s'\n", url);
246                 return LDB_ERR_OTHER;
247         }
248
249         ret = fn(ldb, url, ldb->flags, options, backend_module);
250
251         if (ret != LDB_SUCCESS) {
252                 ldb_debug(ldb, LDB_DEBUG_ERROR,
253                           "Failed to connect to '%s'\n", url);
254                 return ret;
255         }
256         return ret;
257 }
258
259 static const struct ldb_module_ops *ldb_find_module_ops(const char *name)
260 {
261         struct ops_list_entry *e;
262         int i;
263
264         for (i = 0; builtins[i].backend_ops || builtins[i].module_ops; i++) {
265                 if (builtins[i].module_ops == NULL) continue;
266
267                 if (strcmp(builtins[i].module_ops->name, name) == 0)
268                         return builtins[i].module_ops;
269         }
270  
271         for (e = registered_modules; e; e = e->next) {
272                 if (strcmp(e->ops->name, name) == 0) 
273                         return e->ops;
274         }
275
276         return NULL;
277 }
278
279
280 int ldb_register_module(const struct ldb_module_ops *ops)
281 {
282         struct ops_list_entry *entry = talloc(talloc_autofree_context(), struct ops_list_entry);
283
284         if (ldb_find_module_ops(ops->name) != NULL)
285                 return -1;
286
287         if (entry == NULL)
288                 return -1;
289
290         entry->ops = ops;
291         entry->next = registered_modules;
292         registered_modules = entry;
293
294         return 0;
295 }
296
297 static void *ldb_dso_load_symbol(struct ldb_context *ldb, const char *name,
298                                  const char *symbol)
299 {
300         char *path;
301         void *handle;
302         void *sym;
303
304         if (ldb->modules_dir == NULL)
305                 return NULL;
306
307         path = talloc_asprintf(ldb, "%s/%s.%s", ldb->modules_dir, name, 
308                                SHLIBEXT);
309
310         ldb_debug(ldb, LDB_DEBUG_TRACE, "trying to load %s from %s\n", name, path);
311
312         handle = dlopen(path, RTLD_NOW);
313         if (handle == NULL) {
314                 ldb_debug(ldb, LDB_DEBUG_WARNING, "unable to load %s from %s: %s\n", name, path, dlerror());
315                 return NULL;
316         }
317
318         sym = (int (*)(void))dlsym(handle, symbol);
319
320         if (sym == NULL) {
321                 ldb_debug(ldb, LDB_DEBUG_ERROR, "no symbol `%s' found in %s: %s\n", symbol, path, dlerror());
322                 return NULL;
323         }
324
325         talloc_free(path);
326
327         return sym;
328 }
329
330 int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, struct ldb_module *backend, struct ldb_module **out)
331 {
332         struct ldb_module *module;
333         int i;
334         
335         module = backend;
336
337         for (i = 0; module_list[i] != NULL; i++) {
338                 struct ldb_module *current;
339                 const struct ldb_module_ops *ops;
340
341                 if (strcmp(module_list[i], "") == 0) {
342                         continue;
343                 }
344                 
345                 ops = ldb_find_module_ops(module_list[i]);
346                 if (ops == NULL) {
347                         char *symbol_name = talloc_asprintf(ldb, "ldb_%s_module_ops", 
348                                                                                                 module_list[i]);
349                         if (symbol_name == NULL) {
350                                 return LDB_ERR_OPERATIONS_ERROR;
351                         }
352                         ops = ldb_dso_load_symbol(ldb, module_list[i], symbol_name);
353                         talloc_free(symbol_name);
354                 }
355                 
356                 if (ops == NULL) {
357                         ldb_debug(ldb, LDB_DEBUG_WARNING, "WARNING: Module [%s] not found\n", 
358                                   module_list[i]);
359                         continue;
360                 }
361                 
362                 current = talloc_zero(ldb, struct ldb_module);
363                 if (current == NULL) {
364                         return LDB_ERR_OPERATIONS_ERROR;
365                 }
366                 talloc_set_name(current, "ldb_module: %s", module_list[i]);
367                 
368                 current->ldb = ldb;
369                 current->ops = ops;
370                 
371                 DLIST_ADD(module, current);
372         }
373         *out = module;
374         return LDB_SUCCESS;
375 }
376
377 int ldb_init_module_chain(struct ldb_context *ldb, struct ldb_module *module) 
378 {
379         while (module && module->ops->init_context == NULL) 
380                 module = module->next;
381
382         /* init is different in that it is not an error if modules
383          * do not require initialization */
384
385         if (module) {
386                 int ret = module->ops->init_context(module);
387                 if (ret != LDB_SUCCESS) {
388                         ldb_debug(ldb, LDB_DEBUG_FATAL, "module %s initialization failed\n", module->ops->name);
389                         return ret;
390                 }
391         }
392
393         return LDB_SUCCESS;
394 }
395
396 int ldb_load_modules(struct ldb_context *ldb, const char *options[])
397 {
398         const char **modules = NULL;
399         int i;
400         int ret;
401         TALLOC_CTX *mem_ctx = talloc_new(ldb);
402         if (!mem_ctx) {
403                 return LDB_ERR_OPERATIONS_ERROR;
404         }
405
406         /* find out which modules we are requested to activate */
407
408         /* check if we have a custom module list passd as ldb option */
409         if (options) {
410                 for (i = 0; options[i] != NULL; i++) {
411                         if (strncmp(options[i], LDB_MODULE_PREFIX, LDB_MODULE_PREFIX_LEN) == 0) {
412                                 modules = ldb_modules_list_from_string(ldb, mem_ctx, &options[i][LDB_MODULE_PREFIX_LEN]);
413                         }
414                 }
415         }
416
417         /* if not overloaded by options and the backend is not ldap try to load the modules list from ldb */
418         if ((modules == NULL) && (strcmp("ldap", ldb->modules->ops->name) != 0)) { 
419                 const char * const attrs[] = { "@LIST" , NULL};
420                 struct ldb_result *res = NULL;
421                 struct ldb_dn *mods_dn;
422
423                 mods_dn = ldb_dn_new(mem_ctx, ldb, "@MODULES");
424                 if (mods_dn == NULL) {
425                         talloc_free(mem_ctx);
426                         return -1;
427                 }
428
429                 ret = ldb_search(ldb, mods_dn, &res, mods_dn, LDB_SCOPE_BASE, attrs, "@LIST=*");
430                 
431                 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
432                         ldb_debug(ldb, LDB_DEBUG_TRACE, "no modules required by the db");
433                 } else if (ret != LDB_SUCCESS) {
434                         ldb_debug(ldb, LDB_DEBUG_FATAL, "ldb error (%s) occurred searching for modules, bailing out\n", ldb_errstring(ldb));
435                         talloc_free(mem_ctx);
436                         return ret;
437                 } else {
438                         const char *module_list;
439                         if (res->count == 0) {
440                                 ldb_debug(ldb, LDB_DEBUG_TRACE, "no modules required by the db");
441                         } else if (res->count > 1) {
442                                 ldb_debug(ldb, LDB_DEBUG_FATAL, "Too many records found (%d), bailing out\n", res->count);
443                                 talloc_free(mem_ctx);
444                                 return -1;
445                         } else {
446                                 module_list = ldb_msg_find_attr_as_string(res->msgs[0], "@LIST", NULL);
447                                 if (!module_list) {
448                                         ldb_debug(ldb, LDB_DEBUG_TRACE, "no modules required by the db");
449                                 }
450                                 modules = ldb_modules_list_from_string(ldb, mem_ctx,
451                                                                module_list);
452                         }
453                 }
454
455                 talloc_free(mods_dn);
456         }
457
458         if (modules != NULL) {
459                 ret = ldb_load_modules_list(ldb, modules, ldb->modules, &ldb->modules);
460                 if (ret != LDB_SUCCESS) {
461                         talloc_free(mem_ctx);
462                         return ret;
463                 }
464         } else {
465                 ldb_debug(ldb, LDB_DEBUG_TRACE, "No modules specified for this database");
466         }
467
468         ret = ldb_init_module_chain(ldb, ldb->modules);
469         talloc_free(mem_ctx);
470         return ret;
471 }
472
473 /*
474   by using this we allow ldb modules to only implement the functions they care about,
475   which makes writing a module simpler, and makes it more likely to keep working
476   when ldb is extended
477 */
478 #define FIND_OP(module, op) do { \
479         struct ldb_context *ldb = module->ldb; \
480         module = module->next; \
481         while (module && module->ops->op == NULL) module = module->next; \
482         if (module == NULL) { \
483                 ldb_asprintf_errstring(ldb, "Unable to find backend operation for " #op ); \
484                 return LDB_ERR_OPERATIONS_ERROR;        \
485         }                                               \
486 } while (0)
487
488
489 /*
490    helper functions to call the next module in chain
491 */
492
493 int ldb_next_request(struct ldb_module *module, struct ldb_request *request)
494 {
495         int ret;
496
497         if (request->callback == NULL) {
498                 ldb_set_errstring(module->ldb, "Requests MUST define callbacks");
499                 return LDB_ERR_UNWILLING_TO_PERFORM;
500         }
501
502         switch (request->operation) {
503         case LDB_SEARCH:
504                 FIND_OP(module, search);
505                 ret = module->ops->search(module, request);
506                 break;
507         case LDB_ADD:
508                 FIND_OP(module, add);
509                 ret = module->ops->add(module, request);
510                 break;
511         case LDB_MODIFY:
512                 FIND_OP(module, modify);
513                 ret = module->ops->modify(module, request);
514                 break;
515         case LDB_DELETE:
516                 FIND_OP(module, del);
517                 ret = module->ops->del(module, request);
518                 break;
519         case LDB_RENAME:
520                 FIND_OP(module, rename);
521                 ret = module->ops->rename(module, request);
522                 break;
523         case LDB_EXTENDED:
524                 FIND_OP(module, extended);
525                 ret = module->ops->extended(module, request);
526                 break;
527         default:
528                 FIND_OP(module, request);
529                 ret = module->ops->request(module, request);
530                 break;
531         }
532         if (ret == LDB_SUCCESS) {
533                 return ret;
534         }
535         if (!ldb_errstring(module->ldb)) {
536                 /* Set a default error string, to place the blame somewhere */
537                 ldb_asprintf_errstring(module->ldb, "error in module %s: %s (%d)", module->ops->name, ldb_strerror(ret), ret);
538         }
539         return ret;
540 }
541
542 int ldb_next_init(struct ldb_module *module)
543 {
544         module = module->next;
545
546         return ldb_init_module_chain(module->ldb, module);
547 }
548
549 int ldb_next_start_trans(struct ldb_module *module)
550 {
551         FIND_OP(module, start_transaction);
552         return module->ops->start_transaction(module);
553 }
554
555 int ldb_next_end_trans(struct ldb_module *module)
556 {
557         FIND_OP(module, end_transaction);
558         return module->ops->end_transaction(module);
559 }
560
561 int ldb_next_del_trans(struct ldb_module *module)
562 {
563         FIND_OP(module, del_transaction);
564         return module->ops->del_transaction(module);
565 }
566
567 struct ldb_handle *ldb_handle_new(TALLOC_CTX *mem_ctx, struct ldb_context *ldb)
568 {
569         struct ldb_handle *h;
570
571         h = talloc_zero(mem_ctx, struct ldb_handle);
572         if (h == NULL) {
573                 ldb_set_errstring(ldb, "Out of Memory");
574                 return NULL;
575         }
576
577         h->status = LDB_SUCCESS;
578         h->state = LDB_ASYNC_INIT;
579         h->ldb = ldb;
580
581         return h;
582 }
583
584 /* calls the request callback to send an entry
585  *
586  * params:
587  *      req: the original request passed to your module
588  *      msg: reply message (must be a talloc pointer, and it will be stolen
589  *           on the ldb_reply that is sent to the callback)
590  *      ctrls: controls to send in the reply  (must be a talloc pointer, and it will be stolen
591  *           on the ldb_reply that is sent to the callback)
592  */
593
594 int ldb_module_send_entry(struct ldb_request *req,
595                           struct ldb_message *msg,
596                           struct ldb_control **ctrls)
597 {
598         struct ldb_reply *ares;
599
600         ares = talloc_zero(req, struct ldb_reply);
601         if (!ares) {
602                 ldb_oom(req->handle->ldb);
603                 req->callback(req, NULL);
604                 return LDB_ERR_OPERATIONS_ERROR;
605         }
606         ares->type = LDB_REPLY_ENTRY;
607         ares->message = talloc_steal(ares, msg);
608         ares->controls = talloc_steal(ares, ctrls);
609         ares->error = LDB_SUCCESS;
610
611         return req->callback(req, ares);
612 }
613
614 /* calls the request callback to send an referrals
615  *
616  * params:
617  *      req: the original request passed to your module
618  *      ref: referral string (must be a talloc pointeri, steal)
619  */
620
621 int ldb_module_send_referral(struct ldb_request *req,
622                                            char *ref)
623 {
624         struct ldb_reply *ares;
625
626         ares = talloc_zero(req, struct ldb_reply);
627         if (!ares) {
628                 ldb_oom(req->handle->ldb);
629                 req->callback(req, NULL);
630                 return LDB_ERR_OPERATIONS_ERROR;
631         }
632         ares->type = LDB_REPLY_REFERRAL;
633         ares->referral = talloc_steal(ares, ref);
634         ares->error = LDB_SUCCESS;
635
636         return req->callback(req, ares);
637 }
638
639 /* calls the original request callback
640  *
641  * params:
642  *      req:   the original request passed to your module
643  *      ctrls: controls to send in the reply (must be a talloc pointer, steal)
644  *      response: results for extended request (steal)
645  *      error: LDB_SUCCESS for a succesful return
646  *             any other ldb error otherwise
647  */
648 int ldb_module_done(struct ldb_request *req,
649                     struct ldb_control **ctrls,
650                     struct ldb_extended *response,
651                     int error)
652 {
653         struct ldb_reply *ares;
654
655         ares = talloc_zero(req, struct ldb_reply);
656         if (!ares) {
657                 ldb_oom(req->handle->ldb);
658                 req->callback(req, NULL);
659                 return LDB_ERR_OPERATIONS_ERROR;
660         }
661         ares->type = LDB_REPLY_DONE;
662         ares->controls = talloc_steal(ares, ctrls);
663         ares->response = talloc_steal(ares, response);
664         ares->error = error;
665
666         req->callback(req, ares);
667         return error;
668 }
669
670 /* to be used *only* in modules init functions.
671  * this function i synchronous and will register
672  * the requested OID in the rootdse module if present
673  * otherwise it will return an error */
674 int ldb_mod_register_control(struct ldb_module *module, const char *oid)
675 {
676         struct ldb_request *req;
677         int ret;
678
679         req = talloc_zero(module, struct ldb_request);
680         if (req == NULL) {
681                 return LDB_ERR_OPERATIONS_ERROR;
682         }
683
684         req->operation = LDB_REQ_REGISTER_CONTROL;
685         req->op.reg_control.oid = oid;
686         req->callback = ldb_op_default_callback;
687
688         ldb_set_timeout(module->ldb, req, 0);
689
690         req->handle = ldb_handle_new(req, module->ldb);
691         if (req->handle == NULL) {
692                 return LDB_ERR_OPERATIONS_ERROR;
693         }
694
695         ret = ldb_request(module->ldb, req);
696         if (ret == LDB_SUCCESS) {
697                 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
698         }
699         talloc_free(req);
700
701         return ret;
702 }
703
704 #ifndef STATIC_LIBLDB_MODULES
705
706 #ifdef HAVE_LDB_LDAP
707 #define LDAP_BACKEND LDB_BACKEND(ldap), LDB_BACKEND(ldapi), LDB_BACKEND(ldaps),
708 #else
709 #define LDAP_BACKEND
710 #endif
711
712 #ifdef HAVE_LDB_SQLITE3
713 #define SQLITE3_BACKEND LDB_BACKEND(sqlite3),
714 #else
715 #define SQLITE3_BACKEND
716 #endif
717
718 #define STATIC_LIBLDB_MODULES \
719         LDB_BACKEND(tdb),       \
720         LDAP_BACKEND    \
721         SQLITE3_BACKEND \
722         LDB_MODULE(operational),        \
723         LDB_MODULE(rdn_name),   \
724         LDB_MODULE(paged_results),      \
725         LDB_MODULE(server_sort),                \
726         LDB_MODULE(asq), \
727         NULL
728 #endif
729
730 /*
731  * this is a bit hacked, as STATIC_LIBLDB_MODULES contains ','
732  * between the elements and we want to autogenerate the
733  * extern struct declarations, so we do some hacks and let the
734  * ',' appear in an unused function prototype.
735  */
736 #undef NULL
737 #define NULL LDB_MODULE(NULL),
738
739 #define LDB_BACKEND(name) \
740         int); \
741         extern const struct ldb_backend_ops ldb_ ## name ## _backend_ops;\
742         extern void ldb_noop ## name (int
743 #define LDB_MODULE(name) \
744         int); \
745         extern const struct ldb_module_ops ldb_ ## name ## _module_ops;\
746         extern void ldb_noop ## name (int
747
748 extern void ldb_start_noop(int,
749 STATIC_LIBLDB_MODULES
750 int);
751
752 #undef NULL
753 #define NULL { \
754         .backend_ops = (void *)0, \
755         .module_ops = (void *)0 \
756 }
757
758 #undef LDB_BACKEND
759 #define LDB_BACKEND(name) { \
760         .backend_ops = &ldb_ ## name ## _backend_ops, \
761         .module_ops = (void *)0 \
762 }
763 #undef LDB_MODULE
764 #define LDB_MODULE(name) { \
765         .backend_ops = (void *)0, \
766         .module_ops = &ldb_ ## name ## _module_ops \
767 }
768
769 static const struct ldb_builtins builtins[] = {
770         STATIC_LIBLDB_MODULES
771 };