s4:provision Move secrets.ldb over to .c file module lists, like sam.ldb
authorAndrew Bartlett <abartlet@samba.org>
Mon, 23 Nov 2009 23:36:28 +0000 (10:36 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 23 Nov 2009 23:41:45 +0000 (10:41 +1100)
source4/dsdb/samdb/ldb_modules/config.mk
source4/dsdb/samdb/ldb_modules/samba_secrets.c [new file with mode: 0644]
source4/setup/secrets_init.ldif

index 1849c698138f3d09e31687447d6366b847172b37..3bd38606ea79307c273f73d71ec6bb44a2656fc5 100644 (file)
@@ -19,6 +19,17 @@ INIT_FUNCTION = LDB_MODULE(samba_dsdb)
 
 ldb_samba_dsdb_OBJ_FILES = $(dsdbsrcdir)/samdb/ldb_modules/samba_dsdb.o
 
+################################################
+# Start MODULE ldb_samba_secrets
+[MODULE::ldb_samba_secrets]
+SUBSYSTEM = LIBLDB
+PRIVATE_DEPENDENCIES = SAMDB LIBTALLOC LIBEVENTS LIBNDR
+INIT_FUNCTION = LDB_MODULE(samba_secrets)
+# End MODULE ldb_samba_secrets
+################################################
+
+ldb_samba_secrets_OBJ_FILES = $(dsdbsrcdir)/samdb/ldb_modules/samba_secrets.o
+
 ################################################
 # Start MODULE ldb_objectguid
 [MODULE::ldb_objectguid]
diff --git a/source4/dsdb/samdb/ldb_modules/samba_secrets.c b/source4/dsdb/samdb/ldb_modules/samba_secrets.c
new file mode 100644 (file)
index 0000000..1045bb9
--- /dev/null
@@ -0,0 +1,100 @@
+/* 
+   Samba4 module loading module (for secrets)
+
+   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+ *  Name: ldb
+ *
+ *  Component: Samba4 module loading module (for secrets.ldb)
+ *
+ *  Description: Implement a single 'module' in the secrets.ldb database
+ *
+ *  This is to avoid forcing a reprovision of the ldb databases when we change the internal structure of the code
+ *
+ *  Author: Andrew Bartlett
+ */
+
+#include "includes.h"
+#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
+#include "lib/ldb/include/ldb_module.h"
+#include "lib/ldb/include/ldb_private.h"
+
+#include "dsdb/samdb/ldb_modules/util.h"
+#include "dsdb/samdb/samdb.h"
+
+
+static int samba_secrets_init(struct ldb_module *module)
+{
+       struct ldb_context *ldb = ldb_module_get_ctx(module);
+       int ret, len, i;
+       TALLOC_CTX *tmp_ctx = talloc_new(module);
+       struct ldb_module *backend_module, *module_chain;
+       const char **reverse_module_list;
+       /*
+         Add modules to the list to activate them by default
+         beware often order is important
+         
+         The list is presented here as a set of declarations to show the
+         stack visually
+       */
+       static const char *modules_list[] = {"update_keytab",
+                                            "objectguid",
+                                            "rdn_name",
+                                            NULL };
+
+       if (!tmp_ctx) {
+               ldb_oom(ldb);
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       /* Now prepare the module chain.  Oddly, we must give it to ldb_load_modules_list in REVERSE */
+       for (len = 0; modules_list[len]; len++) { /* noop */};
+
+       reverse_module_list = talloc_array(tmp_ctx, const char *, len+1);
+       if (!reverse_module_list) {
+               talloc_free(tmp_ctx);
+               ldb_oom(ldb);
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+       for (i=0; i < len; i++) {
+               reverse_module_list[i] = modules_list[(len - 1) - i];
+       }
+       reverse_module_list[i] = NULL;
+
+       /* The backend (at least until the partitions module
+        * reconfigures things) is the next module in the currently
+        * loaded chain */
+       backend_module = module->next;
+       ret = ldb_load_modules_list(ldb, reverse_module_list, backend_module, &module_chain);
+       if (ret != LDB_SUCCESS) {
+               talloc_free(tmp_ctx);
+               return ret;
+       }
+
+       talloc_free(tmp_ctx);
+       /* Set this as the 'next' module, so that we effectivly append it to module chain */
+       module->next = module_chain;
+
+       return ldb_next_init(module);
+}
+
+const struct ldb_module_ops ldb_samba_secrets_module_ops = {
+       .name              = "samba_secrets",
+       .init_context      = samba_secrets_init,
+};
index 8a8557972d0c4d4e5ba4e989587ced53294cbd9e..3044d3ec449c4dc23864126ad706ad2fed2a47f7 100644 (file)
@@ -12,5 +12,5 @@ sAMAccountName: CASE_INSENSITIVE
 #Add modules to the list to activate them by default
 #beware often order is important
 dn: @MODULES
-@LIST: update_keytab,objectguid,rdn_name
+@LIST: samba_secrets