s4:dsdb Split 'set per-partition metadata' into it's own function
[ira/wip.git] / source4 / dsdb / samdb / ldb_modules / partition_init.c
1 /* 
2    Partitions ldb module
3
4    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006
5    Copyright (C) Stefan Metzmacher <metze@samba.org> 2007
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 /*
22  *  Name: ldb
23  *
24  *  Component: ldb partitions module
25  *
26  *  Description: Implement LDAP partitions
27  *
28  *  Author: Andrew Bartlett
29  *  Author: Stefan Metzmacher
30  */
31
32 #include "dsdb/samdb/ldb_modules/partition.h"
33 static int partition_sort_compare(const void *v1, const void *v2)
34 {
35         const struct dsdb_partition *p1;
36         const struct dsdb_partition *p2;
37
38         p1 = *((struct dsdb_partition * const*)v1);
39         p2 = *((struct dsdb_partition * const*)v2);
40
41         return ldb_dn_compare(p1->ctrl->dn, p2->ctrl->dn);
42 }
43
44 /* Load the list of DNs that we must replicate to all partitions */
45 static int partition_load_replicate_dns(struct ldb_context *ldb, struct partition_private_data *data, struct ldb_message *msg) 
46 {
47         struct ldb_message_element *replicate_attributes = ldb_msg_find_element(msg, "replicateEntries");
48
49         talloc_free(data->replicate);
50         if (!replicate_attributes) {
51                 data->replicate = NULL;
52         } else {
53                 int i;
54                 data->replicate = talloc_array(data, struct ldb_dn *, replicate_attributes->num_values + 1);
55                 if (!data->replicate) {
56                         return LDB_ERR_OPERATIONS_ERROR;
57                 }
58
59                 for (i=0; i < replicate_attributes->num_values; i++) {
60                         data->replicate[i] = ldb_dn_from_ldb_val(data->replicate, ldb, &replicate_attributes->values[i]);
61                         if (!ldb_dn_validate(data->replicate[i])) {
62                                 ldb_asprintf_errstring(ldb,
63                                                         "partition_init: "
64                                                         "invalid DN in partition replicate record: %s", 
65                                                         replicate_attributes->values[i].data);
66                                 return LDB_ERR_CONSTRAINT_VIOLATION;
67                         }
68                 }
69                 data->replicate[i] = NULL;
70         }
71         return LDB_SUCCESS;
72 }
73
74 /* Load the list of modules for the partitions */
75 static int partition_load_modules(struct ldb_context *ldb, 
76                                   struct partition_private_data *data, struct ldb_message *msg) 
77 {
78         int i;
79         struct ldb_message_element *modules_attributes = ldb_msg_find_element(msg, "modules");
80         talloc_free(data->modules);
81         if (!modules_attributes) {
82                 return LDB_SUCCESS;
83         }
84         
85         data->modules = talloc_array(data, struct partition_module *, modules_attributes->num_values + 1);
86         if (!data->modules) {
87                 ldb_oom(ldb);
88                 return LDB_ERR_OPERATIONS_ERROR;
89         }
90         
91         for (i=0; i < modules_attributes->num_values; i++) {
92                 char *base;
93                 char *p;
94
95                 data->modules[i] = talloc(data->modules, struct partition_module);
96                 if (!data->modules[i]) {
97                         ldb_oom(ldb);
98                         return LDB_ERR_OPERATIONS_ERROR;
99                 }
100
101                 base = talloc_strdup(data->partitions, (char *)modules_attributes->values[i].data);
102                 p = strchr(base, ':');
103                 if (!p) {
104                         ldb_asprintf_errstring(ldb, 
105                                                "partition_load_modules: "
106                                                "invalid form for partition module record (missing ':'): %s", base);
107                         return LDB_ERR_CONSTRAINT_VIOLATION;
108                 }
109                 p[0] = '\0';
110                 p++;
111                 data->modules[i]->modules = ldb_modules_list_from_string(ldb, data->modules[i],
112                                                                          p);
113                 
114                 if (strcmp(base, "*") == 0) {
115                         data->modules[i]->dn = NULL;
116                 } else {
117                         data->modules[i]->dn = ldb_dn_new(data->modules[i], ldb, base);
118                         if (!data->modules[i]->dn || !ldb_dn_validate(data->modules[i]->dn)) {
119                                 return LDB_ERR_OPERATIONS_ERROR;
120                         }
121                 }
122         }
123         return LDB_SUCCESS;
124 }
125
126 static int partition_reload_metadata(struct ldb_module *module, struct partition_private_data *data, TALLOC_CTX *mem_ctx, struct ldb_message **_msg) 
127 {
128         int ret;
129         struct ldb_message *msg;
130         struct ldb_result *res;
131         struct ldb_context *ldb = ldb_module_get_ctx(module);
132         const char *attrs[] = { "partition", "replicateEntries", "modules", NULL };
133         /* perform search for @PARTITION, looking for module, replicateEntries and ldapBackend */
134         ret = dsdb_module_search_dn(module, mem_ctx, &res, 
135                                     ldb_dn_new(mem_ctx, ldb, DSDB_PARTITION_DN),
136                                     attrs);
137         if (ret != LDB_SUCCESS) {
138                 return ret;
139         }
140
141         msg = res->msgs[0];
142
143         ret = partition_load_replicate_dns(ldb, data, msg);
144         if (ret != LDB_SUCCESS) {
145                 return ret;
146         }
147
148         ret = partition_load_modules(ldb, data, msg);                   
149         if (ret != LDB_SUCCESS) {
150                 return ret;
151         }
152
153         data->ldapBackend = talloc_steal(data, ldb_msg_find_attr_as_string(msg, "ldapBackend", NULL));
154         if (_msg) {
155                 *_msg = msg;
156         } else {
157                 talloc_free(msg);
158         }
159         return LDB_SUCCESS;
160 }
161
162 static const char **find_modules_for_dn(struct partition_private_data *data, struct ldb_dn *dn) 
163 {
164         int i;
165         struct partition_module *default_mod = NULL;
166         for (i=0; data->modules && data->modules[i]; i++) {
167                 if (!data->modules[i]->dn) {
168                         default_mod = data->modules[i];
169                 } else if (ldb_dn_compare(dn, data->modules[i]->dn) == 0) {
170                         return data->modules[i]->modules;
171                 }
172         }
173         if (default_mod) {
174                 return default_mod->modules;
175         } else {
176                 return NULL;
177         }
178 }
179
180 static int new_partition_from_dn(struct ldb_context *ldb, struct partition_private_data *data, 
181                                  TALLOC_CTX *mem_ctx, 
182                                  struct ldb_dn *dn, const char *casefold_dn,
183                                  struct dsdb_partition **partition) {
184         const char *backend_name;
185         const char *full_backend;
186         struct dsdb_control_current_partition *ctrl;
187         struct ldb_module *module;
188         const char **modules;
189         int ret;
190
191         (*partition) = talloc(mem_ctx, struct dsdb_partition);
192         if (!*partition) {
193                 return LDB_ERR_OPERATIONS_ERROR;
194         }
195
196         (*partition)->ctrl = ctrl = talloc((*partition), struct dsdb_control_current_partition);
197         if (!ctrl) {
198                 talloc_free(*partition);
199                 ldb_oom(ldb);
200                 return LDB_ERR_OPERATIONS_ERROR;
201         }
202
203         /* See if an LDAP backend has been specified */
204         if (data->ldapBackend) {
205                 backend_name = data->ldapBackend;
206         } else {
207
208                 /* the backend LDB is the DN (base64 encoded if not 'plain') followed by .ldb */
209                 const char *p;
210                 char *base64_dn = NULL;
211                 for (p = casefold_dn; *p; p++) {
212                         /* We have such a strict check because I don't want shell metacharacters in the file name, nor ../ */
213                         if (!(isalnum(*p) || *p == ' ' || *p == '=' || *p == ',')) {
214                                 break;
215                         }
216                 }
217                 if (*p) {
218                         casefold_dn = base64_dn = ldb_base64_encode(data, casefold_dn, strlen(casefold_dn));
219                 }
220                 
221                 backend_name = talloc_asprintf(data, "%s.ldb", casefold_dn); 
222                 if (base64_dn) {
223                         talloc_free(base64_dn);
224                 }
225         }
226
227         ctrl->version = DSDB_CONTROL_CURRENT_PARTITION_VERSION;
228         ctrl->dn = talloc_steal(ctrl, dn);
229         
230         full_backend = samdb_relative_path(ldb, 
231                                            *partition, 
232                                            backend_name);
233         if (!full_backend) {
234                 ldb_asprintf_errstring(ldb_module_get_ctx(module), 
235                                        "partition_init: unable to determine an relative path for partition: %s", backend_name);
236                 talloc_free(*partition);
237                 return LDB_ERR_OPERATIONS_ERROR;                
238         }
239
240         ret = ldb_connect_backend(ldb, full_backend, NULL, &module);
241         if (ret != LDB_SUCCESS) {
242                 return ret;
243         }
244
245         modules = find_modules_for_dn(data, dn);
246
247         ret = ldb_load_modules_list(ldb, modules, module, &(*partition)->module);
248         if (ret != LDB_SUCCESS) {
249                 ldb_asprintf_errstring(ldb, 
250                                        "partition_init: "
251                                        "loading backend for %s failed: %s", 
252                                        ldb_dn_get_linearized(dn), ldb_errstring(ldb));
253                 talloc_free(*partition);
254                 return ret;
255         }
256         ret = ldb_init_module_chain(ldb, (*partition)->module);
257         if (ret != LDB_SUCCESS) {
258                 ldb_asprintf_errstring(ldb,
259                                        "partition_init: "
260                                        "initialising backend for %s failed: %s", 
261                                        ldb_dn_get_linearized(dn), ldb_errstring(ldb));
262                 talloc_free(*partition);
263                 return ret;
264         }
265
266         talloc_steal((*partition), (*partition)->module);
267
268         return ret;
269 }
270
271 /* Copy the metadata (@OPTIONS etc) for the new partition into the partition */
272
273 static int new_partition_set_replicated_metadata(struct ldb_context *ldb, 
274                                                  struct ldb_module *module, struct ldb_request *last_req, 
275                                                  struct partition_private_data *data, 
276                                                  struct dsdb_partition *partition)
277 {
278         int i, ret;
279         /* for each replicate, copy from main partition.  If we get an error, we report it up the chain */
280         for (i=0; data->replicate && data->replicate[i]; i++) {
281                 struct ldb_result *replicate_res;
282                 struct ldb_request *add_req;
283                 ret = dsdb_module_search_dn(module, last_req, &replicate_res, 
284                                             data->replicate[i],
285                                             NULL);
286                 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
287                         continue;
288                 }
289                 if (ret != LDB_SUCCESS) {
290                         ldb_asprintf_errstring(ldb,
291                                                "Failed to search for %s from " DSDB_PARTITION_DN 
292                                                " replicateEntries for new partition at %s: %s", 
293                                                ldb_dn_get_linearized(data->replicate[i]), 
294                                                ldb_dn_get_linearized(partition->ctrl->dn), 
295                                                ldb_errstring(ldb));
296                         return ret;
297                 }
298
299                 /* Build add request */
300                 ret = ldb_build_add_req(&add_req, ldb, replicate_res, 
301                                         replicate_res->msgs[0], NULL, NULL, 
302                                         ldb_op_default_callback, last_req);
303                 last_req = add_req;
304                 if (ret != LDB_SUCCESS) {
305                         /* return directly, this is a very unlikely error */
306                         return ret;
307                 }
308                 /* do request */
309                 ret = ldb_next_request(partition->module, add_req);
310                 /* wait */
311                 if (ret == LDB_SUCCESS) {
312                         ret = ldb_wait(add_req->handle, LDB_WAIT_ALL);
313                 }
314                 
315                 switch (ret) {
316                 case LDB_SUCCESS:
317                         break;
318
319                 case LDB_ERR_ENTRY_ALREADY_EXISTS:
320                         /* Handle this case specially - if the
321                          * metadata already exists, replace it */
322                 {
323                         struct ldb_request *del_req;
324                         
325                         /* Don't leave a confusing string in the ldb_errstring() */
326                         ldb_reset_err_string(ldb);
327                         /* Build del request */
328                         ret = ldb_build_del_req(&del_req, ldb, replicate_res, replicate_res->msgs[0]->dn, NULL, NULL, 
329                                                 ldb_op_default_callback, last_req);
330                         last_req = del_req;
331                         if (ret != LDB_SUCCESS) {
332                                 /* return directly, this is a very unlikely error */
333                                 return ret;
334                         }
335                         /* do request */
336                         ret = ldb_next_request(partition->module, del_req);
337                         
338                         /* wait */
339                         if (ret == LDB_SUCCESS) {
340                                 ret = ldb_wait(del_req->handle, LDB_WAIT_ALL);
341                         }
342                         if (ret != LDB_SUCCESS) {
343                                 ldb_asprintf_errstring(ldb,
344                                                        "Failed to delete  (for re-add) %s from " DSDB_PARTITION_DN 
345                                                        " replicateEntries in new partition at %s: %s", 
346                                                        ldb_dn_get_linearized(data->replicate[i]), 
347                                                        ldb_dn_get_linearized(partition->ctrl->dn), 
348                                                        ldb_errstring(ldb));
349                                 return ret;
350                         }
351                         
352                         /* Build add request */
353                         ret = ldb_build_add_req(&add_req, ldb, replicate_res, replicate_res->msgs[0], NULL, NULL, 
354                                                 ldb_op_default_callback, last_req);
355                         last_req = add_req;
356                         if (ret != LDB_SUCCESS) {
357                                 /* return directly, this is a very unlikely error */
358                                 return ret;
359                         }
360                         
361                         /* do the add again */
362                         ret = ldb_next_request(partition->module, add_req);
363                         
364                         /* wait */
365                         if (ret == LDB_SUCCESS) {
366                                 ret = ldb_wait(add_req->handle, LDB_WAIT_ALL);
367                         }
368
369                         if (ret != LDB_SUCCESS) {
370                                 ldb_asprintf_errstring(ldb,
371                                                        "Failed to add (after delete) %s from " DSDB_PARTITION_DN 
372                                                        " replicateEntries to new partition at %s: %s", 
373                                                        ldb_dn_get_linearized(data->replicate[i]), 
374                                                        ldb_dn_get_linearized(partition->ctrl->dn), 
375                                                        ldb_errstring(ldb));
376                                 return ret;
377                         }
378                         break;
379                 }
380                 default: 
381                 {
382                         ldb_asprintf_errstring(ldb,
383                                                "Failed to add %s from " DSDB_PARTITION_DN 
384                                                " replicateEntries to new partition at %s: %s", 
385                                                ldb_dn_get_linearized(data->replicate[i]), 
386                                                ldb_dn_get_linearized(partition->ctrl->dn), 
387                                                ldb_errstring(ldb));
388                         return ret;
389                 }
390                 }
391
392                 /* And around again, for the next thing we must merge */
393         }
394         return LDB_SUCCESS;
395 }
396
397 static int partition_register(struct ldb_context *ldb, struct dsdb_control_current_partition *ctrl, TALLOC_CTX *mem_ctx) 
398 {
399         struct ldb_request *req;
400         int ret;
401
402         req = talloc_zero(mem_ctx, struct ldb_request);
403         if (req == NULL) {
404                 ldb_oom(ldb);
405                 return LDB_ERR_OPERATIONS_ERROR;
406         }
407                 
408         req->operation = LDB_REQ_REGISTER_PARTITION;
409         req->op.reg_partition.dn = ctrl->dn;
410         req->callback = ldb_op_default_callback;
411
412         ldb_set_timeout(ldb, req, 0);
413         
414         req->handle = ldb_handle_new(req, ldb);
415         if (req->handle == NULL) {
416                 return LDB_ERR_OPERATIONS_ERROR;
417         }
418         
419         ret = ldb_request(ldb, req);
420         if (ret == LDB_SUCCESS) {
421                 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
422         }
423         if (ret != LDB_SUCCESS) {
424                 ldb_debug(ldb, LDB_DEBUG_ERROR, "partition: Unable to register partition with rootdse!\n");
425                 talloc_free(mem_ctx);
426                 return LDB_ERR_OTHER;
427         }
428         talloc_free(req);
429
430         return LDB_SUCCESS;
431 }
432
433 int partition_create(struct ldb_module *module, struct ldb_request *req)
434 {
435         int i, ret;
436         struct ldb_context *ldb = ldb_module_get_ctx(module);
437         struct ldb_request *mod_req, *last_req = req;
438         struct ldb_message *mod_msg;
439         struct partition_private_data *data;
440         struct dsdb_partition *partition = NULL;
441         const char *casefold_dn;
442         bool new_partition = false;
443
444         /* Check if this is already a partition */
445
446         struct dsdb_create_partition_exop *ex_op = talloc_get_type(req->op.extended.data, struct dsdb_create_partition_exop);
447         struct ldb_dn *dn = ex_op->new_dn;
448
449         data = talloc_get_type(module->private_data, struct partition_private_data);
450         if (!data) {
451                 return LDB_ERR_OPERATIONS_ERROR;
452         }
453         
454         if (!data) {
455                 /* We are not going to create a partition before we are even set up */
456                 return LDB_ERR_UNWILLING_TO_PERFORM;
457         }
458
459         ret = partition_reload_metadata(module, data, req, NULL);
460         if (ret != LDB_SUCCESS) {
461                 return ret;
462         }
463                 
464         for (i=0; data->partitions && data->partitions[i]; i++) {
465                 if (ldb_dn_compare(data->partitions[i]->ctrl->dn, dn) == 0) {
466                         partition = data->partitions[i];
467                 }
468         }
469
470         if (!partition) {
471                 new_partition = true;
472                 mod_msg = ldb_msg_new(req);
473                 if (!mod_msg) {
474                         ldb_oom(ldb);
475                         return LDB_ERR_OPERATIONS_ERROR;
476                 }
477                 
478                 mod_msg->dn = ldb_dn_new(mod_msg, ldb, DSDB_PARTITION_DN);
479                 ret = ldb_msg_add_empty(mod_msg, DSDB_PARTITION_ATTR, LDB_FLAG_MOD_ADD, NULL);
480                 if (ret != LDB_SUCCESS) {
481                         return ret;
482                 }
483                 
484                 casefold_dn = ldb_dn_get_casefold(dn);
485                 
486                 ret = ldb_msg_add_string(mod_msg, DSDB_PARTITION_ATTR, casefold_dn);
487                 if (ret != LDB_SUCCESS) {
488                         return ret;
489                 }
490                 
491                 /* Perform modify on @PARTITION record */
492                 ret = ldb_build_mod_req(&mod_req, ldb, req, mod_msg, NULL, NULL, 
493                                         ldb_op_default_callback, req);
494                 
495                 if (ret != LDB_SUCCESS) {
496                         return ret;
497                 }
498                 
499                 last_req = mod_req;
500
501                 ret = ldb_next_request(module, mod_req);
502                 if (ret == LDB_SUCCESS) {
503                         ret = ldb_wait(mod_req->handle, LDB_WAIT_ALL);
504                 }
505                 
506                 if (ret != LDB_SUCCESS) {
507                         return ret;
508                 }
509                 
510                 /* Make a partition structure for this new partition, so we can copy in the template structure */ 
511                 ret = new_partition_from_dn(ldb, data, req, ldb_dn_copy(req, dn), casefold_dn, &partition);
512                 if (ret != LDB_SUCCESS) {
513                         return ret;
514                 }
515                 
516                 /* Start a transaction on the DB (as it won't be in one being brand new) */
517                 {
518                         struct ldb_module *next = partition->module;
519                         PARTITION_FIND_OP(next, start_transaction);
520                         
521                         ret = next->ops->start_transaction(next);
522                         if (ret != LDB_SUCCESS) {
523                                 return ret;
524                         }
525                 }
526         }
527         
528         ret = new_partition_set_replicated_metadata(ldb, module, last_req, data, partition);
529         if (ret != LDB_SUCCESS) {
530                 return ret;
531         }
532         
533         if (new_partition) {
534                 /* Count the partitions */
535                 for (i=0; data->partitions && data->partitions[i]; i++) { /* noop */};
536                 
537                 /* Add partition to list of partitions */
538                 data->partitions = talloc_realloc(data, data->partitions, struct dsdb_partition *, i + 2);
539                 if (!data->partitions) {
540                         ldb_oom(ldb);
541                         return LDB_ERR_OPERATIONS_ERROR;
542                 }
543                 data->partitions[i] = talloc_steal(data->partitions, partition);
544                 data->partitions[i+1] = NULL;
545                 
546                 /* Sort again (should use binary insert) */
547                 qsort(data->partitions, i+1,
548                       sizeof(*data->partitions), partition_sort_compare);
549                 
550                 ret = partition_register(ldb, partition->ctrl, req);
551                 if (ret != LDB_SUCCESS) {
552                         return ret;
553                 }
554         }
555
556         /* send request done */
557         return ldb_module_done(req, NULL, NULL, LDB_SUCCESS);
558 }
559
560
561 int partition_init(struct ldb_module *module)
562 {
563         int ret, i;
564         TALLOC_CTX *mem_ctx = talloc_new(module);
565         struct ldb_context *ldb = ldb_module_get_ctx(module);
566         struct ldb_message *msg;
567         struct ldb_message_element *partition_attributes;
568
569         struct partition_private_data *data;
570
571         if (!mem_ctx) {
572                 return LDB_ERR_OPERATIONS_ERROR;
573         }
574
575         data = talloc_zero(mem_ctx, struct partition_private_data);
576         if (data == NULL) {
577                 return LDB_ERR_OPERATIONS_ERROR;
578         }
579
580         ret = partition_reload_metadata(module, data, mem_ctx, &msg);
581         if (ret != LDB_SUCCESS) {
582                 return ret;
583         }
584
585         partition_attributes = ldb_msg_find_element(msg, "partition");
586         if (!partition_attributes) {
587                 data->partitions = NULL;
588         } else {
589                 data->partitions = talloc_array(data, struct dsdb_partition *, partition_attributes->num_values + 1);
590                 if (!data->partitions) {
591                         ldb_oom(ldb_module_get_ctx(module));
592                         talloc_free(mem_ctx);
593                         return LDB_ERR_OPERATIONS_ERROR;
594                 }
595         }
596         for (i=0; partition_attributes && i < partition_attributes->num_values; i++) {
597                 struct ldb_dn *dn = ldb_dn_from_ldb_val(mem_ctx, ldb, &partition_attributes->values[i]);
598                 if (!dn) {
599                         ldb_asprintf_errstring(ldb_module_get_ctx(module), 
600                                                "partition_init: invalid DN in partition record: %s", (const char *)partition_attributes->values[i].data);
601                         talloc_free(mem_ctx);
602                         return LDB_ERR_CONSTRAINT_VIOLATION;
603                 }
604         
605                 /* We call ldb_dn_get_linearized() because the DN in
606                  * partition_attributes is already casefolded
607                  * correctly.  We don't want to mess that up as the
608                  * schema isn't loaded yet */
609                 ret = new_partition_from_dn(ldb, data, data->partitions, dn, 
610                                             ldb_dn_get_linearized(dn),
611                                             &data->partitions[i]);
612                 if (ret != LDB_SUCCESS) {
613                         talloc_free(mem_ctx);
614                         return ret;
615                 }
616         }
617
618         if (data->partitions) {
619                 data->partitions[i] = NULL;
620
621                 /* sort these into order, most to least specific */
622                 qsort(data->partitions, partition_attributes->num_values,
623                       sizeof(*data->partitions), partition_sort_compare);
624         }
625
626         for (i=0; data->partitions && data->partitions[i]; i++) {
627                 ret = partition_register(ldb, data->partitions[i]->ctrl, mem_ctx);
628                 if (ret != LDB_SUCCESS) {
629                         return ret;
630                 }
631         }
632
633         ret = ldb_mod_register_control(module, LDB_CONTROL_DOMAIN_SCOPE_OID);
634         if (ret != LDB_SUCCESS) {
635                 ldb_debug(ldb_module_get_ctx(module), LDB_DEBUG_ERROR,
636                         "partition: Unable to register control with rootdse!\n");
637                 return LDB_ERR_OPERATIONS_ERROR;
638         }
639
640         ret = ldb_mod_register_control(module, LDB_CONTROL_SEARCH_OPTIONS_OID);
641         if (ret != LDB_SUCCESS) {
642                 ldb_debug(ldb_module_get_ctx(module), LDB_DEBUG_ERROR,
643                         "partition: Unable to register control with rootdse!\n");
644                 return LDB_ERR_OPERATIONS_ERROR;
645         }
646
647         module->private_data = talloc_steal(module, data);
648
649         talloc_free(mem_ctx);
650         return ldb_next_init(module);
651 }