From ff64a6716092db5d0ac13658bb7e400da90e0dd9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 14 Feb 2008 23:28:31 +0100 Subject: Split provision from C code out of becomedc. (This used to be commit ed2b72ac76ec069fec799b3fd805cca59fc28de4) --- source4/torture/config.mk | 2 +- source4/torture/libnet/libnet_BecomeDC.c | 298 +--------------------------- source4/torture/util_provision.c | 322 +++++++++++++++++++++++++++++++ 3 files changed, 326 insertions(+), 296 deletions(-) create mode 100644 source4/torture/util_provision.c (limited to 'source4') diff --git a/source4/torture/config.mk b/source4/torture/config.mk index 0c5e641b4b..648c62f98e 100644 --- a/source4/torture/config.mk +++ b/source4/torture/config.mk @@ -14,7 +14,7 @@ PUBLIC_DEPENDENCIES = \ LIBTALLOC [SUBSYSTEM::TORTURE_UTIL] -OBJ_FILES = util_smb.o +OBJ_FILES = util_smb.o util_provision.o PRIVATE_DEPENDENCIES = LIBCLI_RAW PUBLIC_PROTO_HEADER = util.h PUBLIC_DEPENDENCIES = POPT_CREDENTIALS diff --git a/source4/torture/libnet/libnet_BecomeDC.c b/source4/torture/libnet/libnet_BecomeDC.c index 0dd06bda4c..46d9ba769e 100644 --- a/source4/torture/libnet/libnet_BecomeDC.c +++ b/source4/torture/libnet/libnet_BecomeDC.c @@ -36,6 +36,8 @@ #include "system/time.h" #include "auth/auth.h" #include "lib/ldb_wrap.h" +#include "param/param.h" +#include "torture/util.h" struct test_become_dc_state { struct libnet_context *ctx; @@ -90,297 +92,6 @@ static NTSTATUS test_become_dc_check_options(void *private_data, return NT_STATUS_OK; } -#include "lib/appweb/ejs/ejs.h" -#include "lib/appweb/ejs/ejsInternal.h" -#include "scripting/ejs/smbcalls.h" - -static EjsId eid; -static int ejs_error; - -static void test_ejs_exception(const char *reason) -{ - Ejs *ep = ejsPtr(eid); - ejsSetErrorMsg(eid, "%s", reason); - fprintf(stderr, "%s", ep->error); - ejs_error = 127; -} - -static int test_run_ejs(char *script) -{ - EjsHandle handle = 0; - MprVar result; - char *emsg; - TALLOC_CTX *mem_ctx = talloc_new(NULL); - struct MprVar *return_var; - - mprSetCtx(mem_ctx); - - if (ejsOpen(NULL, NULL, NULL) != 0) { - d_printf("ejsOpen(): unable to initialise EJS subsystem\n"); - ejs_error = 127; - goto failed; - } - - smb_setup_ejs_functions(test_ejs_exception); - - if ((eid = ejsOpenEngine(handle, 0)) == (EjsId)-1) { - d_printf("smbscript: ejsOpenEngine(): unable to initialise an EJS engine\n"); - ejs_error = 127; - goto failed; - } - - mprSetVar(ejsGetGlobalObject(eid), "ARGV", mprList("ARGV", NULL)); - - /* run the script */ - if (ejsEvalScript(eid, script, &result, &emsg) == -1) { - d_printf("smbscript: ejsEvalScript(): %s\n", emsg); - if (ejs_error == 0) ejs_error = 127; - goto failed; - } - - return_var = ejsGetReturnValue(eid); - ejs_error = mprVarToNumber(return_var); - -failed: - ejsClose(); - talloc_free(mem_ctx); - return ejs_error; -} - -static NTSTATUS test_become_dc_prepare_db_ejs(void *private_data, - const struct libnet_BecomeDC_PrepareDB *p) -{ - struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); - char *ejs; - int ret; - bool ok; - - DEBUG(0,("Provision for Become-DC test using EJS\n")); - - DEBUG(0,("New Server[%s] in Site[%s]\n", - p->dest_dsa->dns_name, p->dest_dsa->site_name)); - - DEBUG(0,("DSA Instance [%s]\n" - "\tobjectGUID[%s]\n" - "\tinvocationId[%s]\n", - p->dest_dsa->ntds_dn_str, - GUID_string(s, &p->dest_dsa->ntds_guid), - GUID_string(s, &p->dest_dsa->invocation_id))); - - DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" - "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", - lp_private_dir(s->tctx->lp_ctx), - s->path.samdb_ldb, - s->path.secrets_ldb, - s->path.secrets_keytab)); - - DEBUG(0,("Schema Partition[%s => %s]\n", - p->forest->schema_dn_str, s->path.schemadn_ldb)); - - DEBUG(0,("Config Partition[%s => %s]\n", - p->forest->config_dn_str, s->path.configdn_ldb)); - - DEBUG(0,("Domain Partition[%s => %s]\n", - p->domain->dn_str, s->path.domaindn_ldb)); - - ejs = talloc_asprintf(s, - "libinclude(\"base.js\");\n" - "libinclude(\"provision.js\");\n" - "\n" - "function message() { print(vsprintf(arguments)); }\n" - "\n" - "var subobj = provision_guess();\n" - "subobj.ROOTDN = \"%s\";\n" - "subobj.DOMAINDN = \"%s\";\n" - "subobj.DOMAINDN_LDB = \"%s\";\n" - "subobj.CONFIGDN = \"%s\";\n" - "subobj.CONFIGDN_LDB = \"%s\";\n" - "subobj.SCHEMADN = \"%s\";\n" - "subobj.SCHEMADN_LDB = \"%s\";\n" - "subobj.HOSTNAME = \"%s\";\n" - "subobj.REALM = \"%s\";\n" - "subobj.DOMAIN = \"%s\";\n" - "subobj.DEFAULTSITE = \"%s\";\n" - "\n" - "subobj.KRBTGTPASS = \"_NOT_USED_\";\n" - "subobj.MACHINEPASS = \"%s\";\n" - "subobj.ADMINPASS = \"_NOT_USED_\";\n" - "\n" - "var paths = provision_default_paths(subobj);\n" - "paths.samdb = \"%s\";\n" - "paths.secrets = \"%s\";\n" - "paths.templates = \"%s\";\n" - "paths.keytab = \"%s\";\n" - "paths.dns_keytab = \"%s\";\n" - "\n" - "var system_session = system_session();\n" - "\n" - "var ok = provision_become_dc(subobj, message, true, paths, system_session);\n" - "assert(ok);\n" - "\n" - "return 0;\n", - p->forest->root_dn_str, /* subobj.ROOTDN */ - p->domain->dn_str, /* subobj.DOMAINDN */ - s->path.domaindn_ldb, /* subobj.DOMAINDN_LDB */ - p->forest->config_dn_str, /* subobj.CONFIGDN */ - s->path.configdn_ldb, /* subobj.CONFIGDN_LDB */ - p->forest->schema_dn_str, /* subobj.SCHEMADN */ - s->path.schemadn_ldb, /* subobj.SCHEMADN_LDB */ - p->dest_dsa->netbios_name, /* subobj.HOSTNAME */ - torture_join_dom_dns_name(s->tj),/* subobj.REALM */ - torture_join_dom_netbios_name(s->tj),/* subobj.DOMAIN */ - p->dest_dsa->site_name, /* subobj.DEFAULTSITE */ - cli_credentials_get_password(s->machine_account),/* subobj.MACHINEPASS */ - s->path.samdb_ldb, /* paths.samdb */ - s->path.templates_ldb, /* paths.templates */ - s->path.secrets_ldb, /* paths.secrets */ - s->path.secrets_keytab, /* paths.keytab */ - s->path.dns_keytab); /* paths.dns_keytab */ - NT_STATUS_HAVE_NO_MEMORY(ejs); - - ret = test_run_ejs(ejs); - if (ret != 0) { - DEBUG(0,("Failed to run ejs script: %d:\n%s", - ret, ejs)); - talloc_free(ejs); - return NT_STATUS_FOOBAR; - } - talloc_free(ejs); - - talloc_free(s->ldb); - - DEBUG(0,("Open the SAM LDB with system credentials: %s\n", - s->path.samdb_ldb)); - - s->ldb = ldb_wrap_connect(s, s->tctx->lp_ctx, s->path.samdb_ldb, - system_session(s, s->tctx->lp_ctx), - NULL, 0, NULL); - if (!s->ldb) { - DEBUG(0,("Failed to open '%s'\n", - s->path.samdb_ldb)); - return NT_STATUS_INTERNAL_DB_ERROR; - } - - ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id); - if (!ok) { - DEBUG(0,("Failed to set cached ntds invocationId\n")); - return NT_STATUS_FOOBAR; - } - ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid); - if (!ok) { - DEBUG(0,("Failed to set cached ntds objectGUID\n")); - return NT_STATUS_FOOBAR; - } - - return NT_STATUS_OK; -} - -#include "param/param.h" -#include -#include "scripting/python/modules.h" - -static NTSTATUS test_become_dc_prepare_db_py(void *private_data, - const struct libnet_BecomeDC_PrepareDB *p) -{ - struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); - bool ok; - PyObject *provision_fn, *result, *parameters; - - DEBUG(0,("Provision for Become-DC test using PYTHON\n")); - - py_load_samba_modules(); - Py_Initialize(); - - py_update_path("bin"); /* FIXME: Can't assume this always runs in source/... */ - - provision_fn = PyImport_Import(PyString_FromString("samba.provision.provision")); - - if (provision_fn == NULL) { - DEBUG(0, ("Unable to import provision Python module.\n")); - return NT_STATUS_UNSUCCESSFUL; - } - - DEBUG(0,("New Server[%s] in Site[%s]\n", - p->dest_dsa->dns_name, p->dest_dsa->site_name)); - - DEBUG(0,("DSA Instance [%s]\n" - "\tobjectGUID[%s]\n" - "\tinvocationId[%s]\n", - p->dest_dsa->ntds_dn_str, - GUID_string(s, &p->dest_dsa->ntds_guid), - GUID_string(s, &p->dest_dsa->invocation_id))); - - DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" - "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", - lp_private_dir(s->tctx->lp_ctx), - s->path.samdb_ldb, - s->path.secrets_ldb, - s->path.secrets_keytab)); - - DEBUG(0,("Schema Partition[%s => %s]\n", - p->forest->schema_dn_str, s->path.schemadn_ldb)); - - DEBUG(0,("Config Partition[%s => %s]\n", - p->forest->config_dn_str, s->path.configdn_ldb)); - - DEBUG(0,("Domain Partition[%s => %s]\n", - p->domain->dn_str, s->path.domaindn_ldb)); - - parameters = PyDict_New(); - - PyDict_SetItemString(parameters, "rootdn", PyString_FromString(p->forest->root_dn_str)); - PyDict_SetItemString(parameters, "domaindn", PyString_FromString(p->domain->dn_str)); - PyDict_SetItemString(parameters, "domaindn_ldb", PyString_FromString(s->path.domaindn_ldb)); - PyDict_SetItemString(parameters, "configdn", PyString_FromString(p->forest->config_dn_str)); - PyDict_SetItemString(parameters, "configdn_ldb", PyString_FromString(s->path.configdn_ldb)); - PyDict_SetItemString(parameters, "schema_dn_str", PyString_FromString(p->forest->schema_dn_str)); - PyDict_SetItemString(parameters, "schemadn_ldb", PyString_FromString(s->path.schemadn_ldb)); - PyDict_SetItemString(parameters, "netbios_name", PyString_FromString(p->dest_dsa->netbios_name)); - PyDict_SetItemString(parameters, "dnsname", PyString_FromString(p->dest_dsa->dns_name)); - PyDict_SetItemString(parameters, "defaultsite", PyString_FromString(p->dest_dsa->site_name)); - PyDict_SetItemString(parameters, "machinepass", PyString_FromString(cli_credentials_get_password(s->machine_account))); - PyDict_SetItemString(parameters, "samdb", PyString_FromString(s->path.samdb_ldb)); - PyDict_SetItemString(parameters, "secrets_ldb", PyString_FromString(s->path.secrets_ldb)); - PyDict_SetItemString(parameters, "secrets_keytab", PyString_FromString(s->path.secrets_keytab)); - - result = PyEval_CallObjectWithKeywords(provision_fn, NULL, parameters); - - Py_DECREF(parameters); - - if (result == NULL) { - PyErr_Print(); - PyErr_Clear(); - return NT_STATUS_UNSUCCESSFUL; - } - - talloc_free(s->ldb); - - DEBUG(0,("Open the SAM LDB with system credentials: %s\n", - s->path.samdb_ldb)); - - s->ldb = ldb_wrap_connect(s, s->tctx->lp_ctx, s->path.samdb_ldb, - system_session(s, s->tctx->lp_ctx), - NULL, 0, NULL); - if (!s->ldb) { - DEBUG(0,("Failed to open '%s'\n", - s->path.samdb_ldb)); - return NT_STATUS_INTERNAL_DB_ERROR; - } - - ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id); - if (!ok) { - DEBUG(0,("Failed to set cached ntds invocationId\n")); - return NT_STATUS_FOOBAR; - } - ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid); - if (!ok) { - DEBUG(0,("Failed to set cached ntds objectGUID\n")); - return NT_STATUS_FOOBAR; - } - - return NT_STATUS_OK; -} - static NTSTATUS test_apply_schema(struct test_become_dc_state *s, const struct libnet_BecomeDC_StoreChunk *c) { @@ -876,10 +587,7 @@ bool torture_net_become_dc(struct torture_context *torture) b.in.callbacks.private_data = s; b.in.callbacks.check_options = test_become_dc_check_options; - b.in.callbacks.prepare_db = test_become_dc_prepare_db_py; - if (getenv("PROVISION_EJS")) { - b.in.callbacks.prepare_db = test_become_dc_prepare_db_ejs; - } + b.in.callbacks.prepare_db = test_become_dc_prepare_db; b.in.callbacks.schema_chunk = test_become_dc_schema_chunk; b.in.callbacks.config_chunk = test_become_dc_store_chunk; b.in.callbacks.domain_chunk = test_become_dc_store_chunk; diff --git a/source4/torture/util_provision.c b/source4/torture/util_provision.c new file mode 100644 index 0000000000..3bea5f19a5 --- /dev/null +++ b/source4/torture/util_provision.c @@ -0,0 +1,322 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2008 + + 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 . +*/ + +#include "includes.h" +#include "lib/appweb/ejs/ejs.h" +#include "lib/appweb/ejs/ejsInternal.h" +#include "scripting/ejs/smbcalls.h" + +static EjsId eid; +static int ejs_error; + +static void test_ejs_exception(const char *reason) +{ + Ejs *ep = ejsPtr(eid); + ejsSetErrorMsg(eid, "%s", reason); + fprintf(stderr, "%s", ep->error); + ejs_error = 127; +} + +static int test_run_ejs(char *script) +{ + EjsHandle handle = 0; + MprVar result; + char *emsg; + TALLOC_CTX *mem_ctx = talloc_new(NULL); + struct MprVar *return_var; + + mprSetCtx(mem_ctx); + + if (ejsOpen(NULL, NULL, NULL) != 0) { + d_printf("ejsOpen(): unable to initialise EJS subsystem\n"); + ejs_error = 127; + goto failed; + } + + smb_setup_ejs_functions(test_ejs_exception); + + if ((eid = ejsOpenEngine(handle, 0)) == (EjsId)-1) { + d_printf("smbscript: ejsOpenEngine(): unable to initialise an EJS engine\n"); + ejs_error = 127; + goto failed; + } + + mprSetVar(ejsGetGlobalObject(eid), "ARGV", mprList("ARGV", NULL)); + + /* run the script */ + if (ejsEvalScript(eid, script, &result, &emsg) == -1) { + d_printf("smbscript: ejsEvalScript(): %s\n", emsg); + if (ejs_error == 0) ejs_error = 127; + goto failed; + } + + return_var = ejsGetReturnValue(eid); + ejs_error = mprVarToNumber(return_var); + +failed: + ejsClose(); + talloc_free(mem_ctx); + return ejs_error; +} + +static NTSTATUS test_become_dc_prepare_db_ejs(void *private_data, + const struct libnet_BecomeDC_PrepareDB *p) +{ + struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); + char *ejs; + int ret; + bool ok; + + DEBUG(0,("Provision for Become-DC test using EJS\n")); + + DEBUG(0,("New Server[%s] in Site[%s]\n", + p->dest_dsa->dns_name, p->dest_dsa->site_name)); + + DEBUG(0,("DSA Instance [%s]\n" + "\tobjectGUID[%s]\n" + "\tinvocationId[%s]\n", + p->dest_dsa->ntds_dn_str, + GUID_string(s, &p->dest_dsa->ntds_guid), + GUID_string(s, &p->dest_dsa->invocation_id))); + + DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" + "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", + lp_private_dir(s->tctx->lp_ctx), + s->path.samdb_ldb, + s->path.secrets_ldb, + s->path.secrets_keytab)); + + DEBUG(0,("Schema Partition[%s => %s]\n", + p->forest->schema_dn_str, s->path.schemadn_ldb)); + + DEBUG(0,("Config Partition[%s => %s]\n", + p->forest->config_dn_str, s->path.configdn_ldb)); + + DEBUG(0,("Domain Partition[%s => %s]\n", + p->domain->dn_str, s->path.domaindn_ldb)); + + ejs = talloc_asprintf(s, + "libinclude(\"base.js\");\n" + "libinclude(\"provision.js\");\n" + "\n" + "function message() { print(vsprintf(arguments)); }\n" + "\n" + "var subobj = provision_guess();\n" + "subobj.ROOTDN = \"%s\";\n" + "subobj.DOMAINDN = \"%s\";\n" + "subobj.DOMAINDN_LDB = \"%s\";\n" + "subobj.CONFIGDN = \"%s\";\n" + "subobj.CONFIGDN_LDB = \"%s\";\n" + "subobj.SCHEMADN = \"%s\";\n" + "subobj.SCHEMADN_LDB = \"%s\";\n" + "subobj.HOSTNAME = \"%s\";\n" + "subobj.REALM = \"%s\";\n" + "subobj.DOMAIN = \"%s\";\n" + "subobj.DEFAULTSITE = \"%s\";\n" + "\n" + "subobj.KRBTGTPASS = \"_NOT_USED_\";\n" + "subobj.MACHINEPASS = \"%s\";\n" + "subobj.ADMINPASS = \"_NOT_USED_\";\n" + "\n" + "var paths = provision_default_paths(subobj);\n" + "paths.samdb = \"%s\";\n" + "paths.secrets = \"%s\";\n" + "paths.templates = \"%s\";\n" + "paths.keytab = \"%s\";\n" + "paths.dns_keytab = \"%s\";\n" + "\n" + "var system_session = system_session();\n" + "\n" + "var ok = provision_become_dc(subobj, message, true, paths, system_session);\n" + "assert(ok);\n" + "\n" + "return 0;\n", + p->forest->root_dn_str, /* subobj.ROOTDN */ + p->domain->dn_str, /* subobj.DOMAINDN */ + s->path.domaindn_ldb, /* subobj.DOMAINDN_LDB */ + p->forest->config_dn_str, /* subobj.CONFIGDN */ + s->path.configdn_ldb, /* subobj.CONFIGDN_LDB */ + p->forest->schema_dn_str, /* subobj.SCHEMADN */ + s->path.schemadn_ldb, /* subobj.SCHEMADN_LDB */ + p->dest_dsa->netbios_name, /* subobj.HOSTNAME */ + torture_join_dom_dns_name(s->tj),/* subobj.REALM */ + torture_join_dom_netbios_name(s->tj),/* subobj.DOMAIN */ + p->dest_dsa->site_name, /* subobj.DEFAULTSITE */ + cli_credentials_get_password(s->machine_account),/* subobj.MACHINEPASS */ + s->path.samdb_ldb, /* paths.samdb */ + s->path.templates_ldb, /* paths.templates */ + s->path.secrets_ldb, /* paths.secrets */ + s->path.secrets_keytab, /* paths.keytab */ + s->path.dns_keytab); /* paths.dns_keytab */ + NT_STATUS_HAVE_NO_MEMORY(ejs); + + ret = test_run_ejs(ejs); + if (ret != 0) { + DEBUG(0,("Failed to run ejs script: %d:\n%s", + ret, ejs)); + talloc_free(ejs); + return NT_STATUS_FOOBAR; + } + talloc_free(ejs); + + talloc_free(s->ldb); + + DEBUG(0,("Open the SAM LDB with system credentials: %s\n", + s->path.samdb_ldb)); + + s->ldb = ldb_wrap_connect(s, s->tctx->lp_ctx, s->path.samdb_ldb, + system_session(s, s->tctx->lp_ctx), + NULL, 0, NULL); + if (!s->ldb) { + DEBUG(0,("Failed to open '%s'\n", + s->path.samdb_ldb)); + return NT_STATUS_INTERNAL_DB_ERROR; + } + + ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id); + if (!ok) { + DEBUG(0,("Failed to set cached ntds invocationId\n")); + return NT_STATUS_FOOBAR; + } + ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid); + if (!ok) { + DEBUG(0,("Failed to set cached ntds objectGUID\n")); + return NT_STATUS_FOOBAR; + } + + return NT_STATUS_OK; +} + +#include "param/param.h" +#include +#include "scripting/python/modules.h" + +static NTSTATUS test_become_dc_prepare_db_py(void *private_data, + const struct libnet_BecomeDC_PrepareDB *p) +{ + struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); + bool ok; + PyObject *provision_fn, *result, *parameters; + + DEBUG(0,("Provision for Become-DC test using PYTHON\n")); + + py_load_samba_modules(); + Py_Initialize(); + + py_update_path("bin"); /* FIXME: Can't assume this always runs in source/... */ + + provision_fn = PyImport_Import(PyString_FromString("samba.provision.provision")); + + if (provision_fn == NULL) { + DEBUG(0, ("Unable to import provision Python module.\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + DEBUG(0,("New Server[%s] in Site[%s]\n", + p->dest_dsa->dns_name, p->dest_dsa->site_name)); + + DEBUG(0,("DSA Instance [%s]\n" + "\tobjectGUID[%s]\n" + "\tinvocationId[%s]\n", + p->dest_dsa->ntds_dn_str, + GUID_string(s, &p->dest_dsa->ntds_guid), + GUID_string(s, &p->dest_dsa->invocation_id))); + + DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" + "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", + lp_private_dir(s->tctx->lp_ctx), + s->path.samdb_ldb, + s->path.secrets_ldb, + s->path.secrets_keytab)); + + DEBUG(0,("Schema Partition[%s => %s]\n", + p->forest->schema_dn_str, s->path.schemadn_ldb)); + + DEBUG(0,("Config Partition[%s => %s]\n", + p->forest->config_dn_str, s->path.configdn_ldb)); + + DEBUG(0,("Domain Partition[%s => %s]\n", + p->domain->dn_str, s->path.domaindn_ldb)); + + parameters = PyDict_New(); + + PyDict_SetItemString(parameters, "rootdn", PyString_FromString(p->forest->root_dn_str)); + PyDict_SetItemString(parameters, "domaindn", PyString_FromString(p->domain->dn_str)); + PyDict_SetItemString(parameters, "domaindn_ldb", PyString_FromString(s->path.domaindn_ldb)); + PyDict_SetItemString(parameters, "configdn", PyString_FromString(p->forest->config_dn_str)); + PyDict_SetItemString(parameters, "configdn_ldb", PyString_FromString(s->path.configdn_ldb)); + PyDict_SetItemString(parameters, "schema_dn_str", PyString_FromString(p->forest->schema_dn_str)); + PyDict_SetItemString(parameters, "schemadn_ldb", PyString_FromString(s->path.schemadn_ldb)); + PyDict_SetItemString(parameters, "netbios_name", PyString_FromString(p->dest_dsa->netbios_name)); + PyDict_SetItemString(parameters, "dnsname", PyString_FromString(p->dest_dsa->dns_name)); + PyDict_SetItemString(parameters, "defaultsite", PyString_FromString(p->dest_dsa->site_name)); + PyDict_SetItemString(parameters, "machinepass", PyString_FromString(cli_credentials_get_password(s->machine_account))); + PyDict_SetItemString(parameters, "samdb", PyString_FromString(s->path.samdb_ldb)); + PyDict_SetItemString(parameters, "secrets_ldb", PyString_FromString(s->path.secrets_ldb)); + PyDict_SetItemString(parameters, "secrets_keytab", PyString_FromString(s->path.secrets_keytab)); + + result = PyEval_CallObjectWithKeywords(provision_fn, NULL, parameters); + + Py_DECREF(parameters); + + if (result == NULL) { + PyErr_Print(); + PyErr_Clear(); + return NT_STATUS_UNSUCCESSFUL; + } + + talloc_free(s->ldb); + + DEBUG(0,("Open the SAM LDB with system credentials: %s\n", + s->path.samdb_ldb)); + + s->ldb = ldb_wrap_connect(s, s->tctx->lp_ctx, s->path.samdb_ldb, + system_session(s, s->tctx->lp_ctx), + NULL, 0, NULL); + if (!s->ldb) { + DEBUG(0,("Failed to open '%s'\n", + s->path.samdb_ldb)); + return NT_STATUS_INTERNAL_DB_ERROR; + } + + ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id); + if (!ok) { + DEBUG(0,("Failed to set cached ntds invocationId\n")); + return NT_STATUS_FOOBAR; + } + ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid); + if (!ok) { + DEBUG(0,("Failed to set cached ntds objectGUID\n")); + return NT_STATUS_FOOBAR; + } + + return NT_STATUS_OK; +} + +NTSTATUS test_become_dc_prepare_db(void *private_data, + const struct libnet_BecomeDC_PrepareDB *p) +{ + if (getenv("PROVISION_EJS")) { + test_become_dc_prepare_db_ejs(private_data, p); + } else { + test_become_dc_prepare_db_py(private_data, p); + } +} + + -- cgit From 18a011d8a822476c3acfe37653ad19c31b904ff0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Feb 2008 00:23:56 +0100 Subject: Avoid using private libnet test structure inside util_provision. (This used to be commit 1a1f8a5e6b193f25f4838a3e7964cdf0590f4eb2) --- source4/torture/libnet/libnet_BecomeDC.c | 16 +++- source4/torture/util_provision.c | 134 ++++++++++++++++++------------- 2 files changed, 95 insertions(+), 55 deletions(-) (limited to 'source4') diff --git a/source4/torture/libnet/libnet_BecomeDC.c b/source4/torture/libnet/libnet_BecomeDC.c index 46d9ba769e..34ae53eb22 100644 --- a/source4/torture/libnet/libnet_BecomeDC.c +++ b/source4/torture/libnet/libnet_BecomeDC.c @@ -34,8 +34,8 @@ #include "librpc/gen_ndr/ndr_drsblobs.h" #include "librpc/gen_ndr/ndr_misc.h" #include "system/time.h" -#include "auth/auth.h" #include "lib/ldb_wrap.h" +#include "auth/auth.h" #include "param/param.h" #include "torture/util.h" @@ -68,6 +68,20 @@ struct test_become_dc_state { } path; }; +static NTSTATUS test_become_dc_prepare_db(void *private_data, + const struct libnet_BecomeDC_PrepareDB *p) +{ + struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); + return provision_bare(s, s->tctx->lp_ctx, p->dest_dsa->dns_name, + p->dest_dsa->site_name, p->forest->root_dn_str, + p->domain->dn_str, p->forest->config_dn_str, + p->forest->schema_dn_str, + &p->dest_dsa->invocation_id, + p->dest_dsa->netbios_name, + torture_join_dom_dns_name(s->tj), + torture_join_dom_netbios_name(s->tj)); +} + static NTSTATUS test_become_dc_check_options(void *private_data, const struct libnet_BecomeDC_CheckOptions *o) { diff --git a/source4/torture/util_provision.c b/source4/torture/util_provision.c index 3bea5f19a5..418137cbeb 100644 --- a/source4/torture/util_provision.c +++ b/source4/torture/util_provision.c @@ -18,9 +18,11 @@ */ #include "includes.h" +#include "dsdb/samdb/samdb.h" #include "lib/appweb/ejs/ejs.h" #include "lib/appweb/ejs/ejsInternal.h" #include "scripting/ejs/smbcalls.h" +#include "auth/auth.h" static EjsId eid; static int ejs_error; @@ -75,43 +77,52 @@ failed: return ejs_error; } -static NTSTATUS test_become_dc_prepare_db_ejs(void *private_data, - const struct libnet_BecomeDC_PrepareDB *p) +static NTSTATUS provision_bare_ejs(TALLOC_CTX *mem_ctx, + struct loadparm_context *lp_ctx, + const char *dns_name, + const char *site_name, + const char *root_dn_str, + const char *domain_dn_str, + const char *config_dn_str, + const char *schema_dn_str, + const struct GUID *invocation_id, + const char *netbios_name, + const char *realm, + const char *domain) { - struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); char *ejs; int ret; bool ok; + struct ldb_context *ldb; DEBUG(0,("Provision for Become-DC test using EJS\n")); - DEBUG(0,("New Server[%s] in Site[%s]\n", - p->dest_dsa->dns_name, p->dest_dsa->site_name)); + DEBUG(0,("New Server[%s] in Site[%s]\n", dns_name, site_name)); DEBUG(0,("DSA Instance [%s]\n" "\tobjectGUID[%s]\n" "\tinvocationId[%s]\n", p->dest_dsa->ntds_dn_str, - GUID_string(s, &p->dest_dsa->ntds_guid), - GUID_string(s, &p->dest_dsa->invocation_id))); + GUID_string(mem_ctx, &p->dest_dsa->ntds_guid), + GUID_string(mem_ctx, invocation_id))); DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", - lp_private_dir(s->tctx->lp_ctx), + lp_private_dir(lp_ctx), s->path.samdb_ldb, s->path.secrets_ldb, s->path.secrets_keytab)); DEBUG(0,("Schema Partition[%s => %s]\n", - p->forest->schema_dn_str, s->path.schemadn_ldb)); + schema_dn_str, s->path.schemadn_ldb)); DEBUG(0,("Config Partition[%s => %s]\n", - p->forest->config_dn_str, s->path.configdn_ldb)); + config_dn_str, s->path.configdn_ldb)); DEBUG(0,("Domain Partition[%s => %s]\n", - p->domain->dn_str, s->path.domaindn_ldb)); + domain_dn_str, s->path.domaindn_ldb)); - ejs = talloc_asprintf(s, + ejs = talloc_asprintf(mem_ctx, "libinclude(\"base.js\");\n" "libinclude(\"provision.js\");\n" "\n" @@ -147,17 +158,17 @@ static NTSTATUS test_become_dc_prepare_db_ejs(void *private_data, "assert(ok);\n" "\n" "return 0;\n", - p->forest->root_dn_str, /* subobj.ROOTDN */ - p->domain->dn_str, /* subobj.DOMAINDN */ + root_dn_str, /* subobj.ROOTDN */ + domain_dn_str, /* subobj.DOMAINDN */ s->path.domaindn_ldb, /* subobj.DOMAINDN_LDB */ - p->forest->config_dn_str, /* subobj.CONFIGDN */ + config_dn_str, /* subobj.CONFIGDN */ s->path.configdn_ldb, /* subobj.CONFIGDN_LDB */ - p->forest->schema_dn_str, /* subobj.SCHEMADN */ + schema_dn_str, /* subobj.SCHEMADN */ s->path.schemadn_ldb, /* subobj.SCHEMADN_LDB */ - p->dest_dsa->netbios_name, /* subobj.HOSTNAME */ - torture_join_dom_dns_name(s->tj),/* subobj.REALM */ - torture_join_dom_netbios_name(s->tj),/* subobj.DOMAIN */ - p->dest_dsa->site_name, /* subobj.DEFAULTSITE */ + netbios_name, /* subobj.HOSTNAME */ + realm,/* subobj.REALM */ + domain,/* subobj.DOMAIN */ + site_name, /* subobj.DEFAULTSITE */ cli_credentials_get_password(s->machine_account),/* subobj.MACHINEPASS */ s->path.samdb_ldb, /* paths.samdb */ s->path.templates_ldb, /* paths.templates */ @@ -175,26 +186,26 @@ static NTSTATUS test_become_dc_prepare_db_ejs(void *private_data, } talloc_free(ejs); - talloc_free(s->ldb); + talloc_free(ldb); DEBUG(0,("Open the SAM LDB with system credentials: %s\n", s->path.samdb_ldb)); - s->ldb = ldb_wrap_connect(s, s->tctx->lp_ctx, s->path.samdb_ldb, - system_session(s, s->tctx->lp_ctx), + ldb = ldb_wrap_connect(mem_ctx, lp_ctx, s->path.samdb_ldb, + system_session(mem_ctx, lp_ctx), NULL, 0, NULL); - if (!s->ldb) { + if (!ldb) { DEBUG(0,("Failed to open '%s'\n", s->path.samdb_ldb)); return NT_STATUS_INTERNAL_DB_ERROR; } - ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id); + ok = samdb_set_ntds_invocation_id(ldb, invocation_id); if (!ok) { DEBUG(0,("Failed to set cached ntds invocationId\n")); return NT_STATUS_FOOBAR; } - ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid); + ok = samdb_set_ntds_objectGUID(ldb, &p->dest_dsa->ntds_guid); if (!ok) { DEBUG(0,("Failed to set cached ntds objectGUID\n")); return NT_STATUS_FOOBAR; @@ -207,10 +218,17 @@ static NTSTATUS test_become_dc_prepare_db_ejs(void *private_data, #include #include "scripting/python/modules.h" -static NTSTATUS test_become_dc_prepare_db_py(void *private_data, - const struct libnet_BecomeDC_PrepareDB *p) +static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, + struct loadparm_context *lp_ctx, + const char *dns_name, + const char *site_name, + const char *root_dn_str, + const char *domain_dn_str, + const char *config_dn_str, + const char *schema_dn_str, + const struct GUID *invocation_id, + const char *domain) { - struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); bool ok; PyObject *provision_fn, *result, *parameters; @@ -228,44 +246,43 @@ static NTSTATUS test_become_dc_prepare_db_py(void *private_data, return NT_STATUS_UNSUCCESSFUL; } - DEBUG(0,("New Server[%s] in Site[%s]\n", - p->dest_dsa->dns_name, p->dest_dsa->site_name)); + DEBUG(0,("New Server[%s] in Site[%s]\n", dns_name, site_name)); DEBUG(0,("DSA Instance [%s]\n" "\tobjectGUID[%s]\n" "\tinvocationId[%s]\n", p->dest_dsa->ntds_dn_str, - GUID_string(s, &p->dest_dsa->ntds_guid), - GUID_string(s, &p->dest_dsa->invocation_id))); + GUID_string(mem_ctx, &p->dest_dsa->ntds_guid), + GUID_string(mem_ctx, invocation_id))); DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", - lp_private_dir(s->tctx->lp_ctx), + lp_private_dir(lp_ctx), s->path.samdb_ldb, s->path.secrets_ldb, s->path.secrets_keytab)); DEBUG(0,("Schema Partition[%s => %s]\n", - p->forest->schema_dn_str, s->path.schemadn_ldb)); + schema_dn_str, s->path.schemadn_ldb)); DEBUG(0,("Config Partition[%s => %s]\n", - p->forest->config_dn_str, s->path.configdn_ldb)); + config_dn_str, s->path.configdn_ldb)); DEBUG(0,("Domain Partition[%s => %s]\n", - p->domain->dn_str, s->path.domaindn_ldb)); + domain_dn_str, s->path.domaindn_ldb)); parameters = PyDict_New(); - PyDict_SetItemString(parameters, "rootdn", PyString_FromString(p->forest->root_dn_str)); - PyDict_SetItemString(parameters, "domaindn", PyString_FromString(p->domain->dn_str)); + PyDict_SetItemString(parameters, "rootdn", PyString_FromString(root_dn_str)); + PyDict_SetItemString(parameters, "domaindn", PyString_FromString(domain_dn_str)); PyDict_SetItemString(parameters, "domaindn_ldb", PyString_FromString(s->path.domaindn_ldb)); - PyDict_SetItemString(parameters, "configdn", PyString_FromString(p->forest->config_dn_str)); + PyDict_SetItemString(parameters, "configdn", PyString_FromString(config_dn_str)); PyDict_SetItemString(parameters, "configdn_ldb", PyString_FromString(s->path.configdn_ldb)); - PyDict_SetItemString(parameters, "schema_dn_str", PyString_FromString(p->forest->schema_dn_str)); + PyDict_SetItemString(parameters, "schema_dn_str", PyString_FromString(schema_dn_str)); PyDict_SetItemString(parameters, "schemadn_ldb", PyString_FromString(s->path.schemadn_ldb)); - PyDict_SetItemString(parameters, "netbios_name", PyString_FromString(p->dest_dsa->netbios_name)); - PyDict_SetItemString(parameters, "dnsname", PyString_FromString(p->dest_dsa->dns_name)); - PyDict_SetItemString(parameters, "defaultsite", PyString_FromString(p->dest_dsa->site_name)); + PyDict_SetItemString(parameters, "netbios_name", PyString_FromString(netbios_name)); + PyDict_SetItemString(parameters, "dnsname", PyString_FromString(dns_name)); + PyDict_SetItemString(parameters, "defaultsite", PyString_FromString(site_name)); PyDict_SetItemString(parameters, "machinepass", PyString_FromString(cli_credentials_get_password(s->machine_account))); PyDict_SetItemString(parameters, "samdb", PyString_FromString(s->path.samdb_ldb)); PyDict_SetItemString(parameters, "secrets_ldb", PyString_FromString(s->path.secrets_ldb)); @@ -281,26 +298,26 @@ static NTSTATUS test_become_dc_prepare_db_py(void *private_data, return NT_STATUS_UNSUCCESSFUL; } - talloc_free(s->ldb); + talloc_free(ldb); DEBUG(0,("Open the SAM LDB with system credentials: %s\n", s->path.samdb_ldb)); - s->ldb = ldb_wrap_connect(s, s->tctx->lp_ctx, s->path.samdb_ldb, - system_session(s, s->tctx->lp_ctx), + ldb = ldb_wrap_connect(s, lp_ctx, s->path.samdb_ldb, + system_session(s, lp_ctx), NULL, 0, NULL); - if (!s->ldb) { + if (!ldb) { DEBUG(0,("Failed to open '%s'\n", s->path.samdb_ldb)); return NT_STATUS_INTERNAL_DB_ERROR; } - ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id); + ok = samdb_set_ntds_invocation_id(ldb, invocation_id); if (!ok) { DEBUG(0,("Failed to set cached ntds invocationId\n")); return NT_STATUS_FOOBAR; } - ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid); + ok = samdb_set_ntds_objectGUID(ldb, &p->dest_dsa->ntds_guid); if (!ok) { DEBUG(0,("Failed to set cached ntds objectGUID\n")); return NT_STATUS_FOOBAR; @@ -309,13 +326,22 @@ static NTSTATUS test_become_dc_prepare_db_py(void *private_data, return NT_STATUS_OK; } -NTSTATUS test_become_dc_prepare_db(void *private_data, - const struct libnet_BecomeDC_PrepareDB *p) +NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, + const char *dns_name, const char *site_name, + const char *root_dn_str, const char *domain_dn_str, + const char *config_dn_str, const char *schema_dn_str, + const struct GUID *invocation_id, + const char *netbios_name, const char *realm, + const char *domain) { if (getenv("PROVISION_EJS")) { - test_become_dc_prepare_db_ejs(private_data, p); + provision_bare_ejs(mem_ctx, lp_ctx, dns_name, site_name, root_dn_str, + domain_dn_str, config_dn_str, schema_dn_str, + invocation_id, netbios_name, realm, domain); } else { - test_become_dc_prepare_db_py(private_data, p); + provision_bare_py(mem_ctx, lp_ctx, dns_name, site_name, root_dn_str, + domain_dn_str, config_dn_str, schema_dn_str, + invocation_id, netbios_name, realm, domain); } } -- cgit From 1f5cec6f405f8f4446d39a0b520cc3bae1f17ad6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Feb 2008 00:35:17 +0100 Subject: Move Python dependencies. (This used to be commit f6c5b787cc031ddf858d7b16f455692a98a19b9e) --- source4/torture/config.mk | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4') diff --git a/source4/torture/config.mk b/source4/torture/config.mk index 648c62f98e..f94d8db929 100644 --- a/source4/torture/config.mk +++ b/source4/torture/config.mk @@ -15,7 +15,7 @@ PUBLIC_DEPENDENCIES = \ [SUBSYSTEM::TORTURE_UTIL] OBJ_FILES = util_smb.o util_provision.o -PRIVATE_DEPENDENCIES = LIBCLI_RAW +PRIVATE_DEPENDENCIES = LIBCLI_RAW LIBPYTHON PUBLIC_PROTO_HEADER = util.h PUBLIC_DEPENDENCIES = POPT_CREDENTIALS @@ -297,8 +297,7 @@ PRIVATE_DEPENDENCIES = \ LIBSAMBA-NET \ smbcalls \ POPT_CREDENTIALS \ - torture_rpc \ - LIBPYTHON + torture_rpc # End SUBSYSTEM TORTURE_NET ################################# -- cgit From 3d6da3b162561b756a002c54f94a6739cfbb08fe Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Feb 2008 01:16:12 +0100 Subject: Finish migration of provision code. (This used to be commit 53c5924195844dac4dfe99e5c9b0c8911394497a) --- source4/torture/config.mk | 3 +- source4/torture/libnet/libnet_BecomeDC.c | 8 +- source4/torture/util_provision.c | 149 ++++++++++++++++++++----------- 3 files changed, 103 insertions(+), 57 deletions(-) (limited to 'source4') diff --git a/source4/torture/config.mk b/source4/torture/config.mk index f94d8db929..bcb3233ce4 100644 --- a/source4/torture/config.mk +++ b/source4/torture/config.mk @@ -15,7 +15,7 @@ PUBLIC_DEPENDENCIES = \ [SUBSYSTEM::TORTURE_UTIL] OBJ_FILES = util_smb.o util_provision.o -PRIVATE_DEPENDENCIES = LIBCLI_RAW LIBPYTHON +PRIVATE_DEPENDENCIES = LIBCLI_RAW LIBPYTHON smbcalls PUBLIC_PROTO_HEADER = util.h PUBLIC_DEPENDENCIES = POPT_CREDENTIALS @@ -295,7 +295,6 @@ OBJ_FILES = \ libnet/libnet_BecomeDC.o PRIVATE_DEPENDENCIES = \ LIBSAMBA-NET \ - smbcalls \ POPT_CREDENTIALS \ torture_rpc # End SUBSYSTEM TORTURE_NET diff --git a/source4/torture/libnet/libnet_BecomeDC.c b/source4/torture/libnet/libnet_BecomeDC.c index 34ae53eb22..83d7426dfb 100644 --- a/source4/torture/libnet/libnet_BecomeDC.c +++ b/source4/torture/libnet/libnet_BecomeDC.c @@ -79,7 +79,13 @@ static NTSTATUS test_become_dc_prepare_db(void *private_data, &p->dest_dsa->invocation_id, p->dest_dsa->netbios_name, torture_join_dom_dns_name(s->tj), - torture_join_dom_netbios_name(s->tj)); + torture_join_dom_netbios_name(s->tj), + &p->dest_dsa->ntds_guid, + p->dest_dsa->ntds_dn_str, + cli_credentials_get_password(s->machine_account), + s->path.samdb_ldb, s->path.secrets_ldb, + s->path.secrets_keytab, s->path.schemadn_ldb, + s->path.configdn_ldb, s->path.domaindn_ldb); } static NTSTATUS test_become_dc_check_options(void *private_data, diff --git a/source4/torture/util_provision.c b/source4/torture/util_provision.c index 418137cbeb..bc4f3d2b28 100644 --- a/source4/torture/util_provision.c +++ b/source4/torture/util_provision.c @@ -23,6 +23,7 @@ #include "lib/appweb/ejs/ejsInternal.h" #include "scripting/ejs/smbcalls.h" #include "auth/auth.h" +#include "lib/ldb_wrap.h" static EjsId eid; static int ejs_error; @@ -88,7 +89,18 @@ static NTSTATUS provision_bare_ejs(TALLOC_CTX *mem_ctx, const struct GUID *invocation_id, const char *netbios_name, const char *realm, - const char *domain) + const char *domain, + const struct GUID *ntds_guid, + const char *ntds_dn_str, + const char *machine_password, + const char *samdb_ldb, + const char *secrets_ldb, + const char *secrets_keytab, + const char *schemadn_ldb, + const char *configdn_ldb, + const char *domaindn_ldb, + const char *templates_ldb, + const char *dns_keytab) { char *ejs; int ret; @@ -102,25 +114,25 @@ static NTSTATUS provision_bare_ejs(TALLOC_CTX *mem_ctx, DEBUG(0,("DSA Instance [%s]\n" "\tobjectGUID[%s]\n" "\tinvocationId[%s]\n", - p->dest_dsa->ntds_dn_str, - GUID_string(mem_ctx, &p->dest_dsa->ntds_guid), + ntds_dn_str, + GUID_string(mem_ctx, ntds_guid), GUID_string(mem_ctx, invocation_id))); DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", lp_private_dir(lp_ctx), - s->path.samdb_ldb, - s->path.secrets_ldb, - s->path.secrets_keytab)); + samdb_ldb, + secrets_ldb, + secrets_keytab)); DEBUG(0,("Schema Partition[%s => %s]\n", - schema_dn_str, s->path.schemadn_ldb)); + schema_dn_str, schemadn_ldb)); DEBUG(0,("Config Partition[%s => %s]\n", - config_dn_str, s->path.configdn_ldb)); + config_dn_str, configdn_ldb)); DEBUG(0,("Domain Partition[%s => %s]\n", - domain_dn_str, s->path.domaindn_ldb)); + domain_dn_str, domaindn_ldb)); ejs = talloc_asprintf(mem_ctx, "libinclude(\"base.js\");\n" @@ -160,21 +172,21 @@ static NTSTATUS provision_bare_ejs(TALLOC_CTX *mem_ctx, "return 0;\n", root_dn_str, /* subobj.ROOTDN */ domain_dn_str, /* subobj.DOMAINDN */ - s->path.domaindn_ldb, /* subobj.DOMAINDN_LDB */ + domaindn_ldb, /* subobj.DOMAINDN_LDB */ config_dn_str, /* subobj.CONFIGDN */ - s->path.configdn_ldb, /* subobj.CONFIGDN_LDB */ + configdn_ldb, /* subobj.CONFIGDN_LDB */ schema_dn_str, /* subobj.SCHEMADN */ - s->path.schemadn_ldb, /* subobj.SCHEMADN_LDB */ + schemadn_ldb, /* subobj.SCHEMADN_LDB */ netbios_name, /* subobj.HOSTNAME */ realm,/* subobj.REALM */ domain,/* subobj.DOMAIN */ site_name, /* subobj.DEFAULTSITE */ - cli_credentials_get_password(s->machine_account),/* subobj.MACHINEPASS */ - s->path.samdb_ldb, /* paths.samdb */ - s->path.templates_ldb, /* paths.templates */ - s->path.secrets_ldb, /* paths.secrets */ - s->path.secrets_keytab, /* paths.keytab */ - s->path.dns_keytab); /* paths.dns_keytab */ + machine_password,/* subobj.MACHINEPASS */ + samdb_ldb, /* paths.samdb */ + templates_ldb, /* paths.templates */ + secrets_ldb, /* paths.secrets */ + secrets_keytab, /* paths.keytab */ + dns_keytab); /* paths.dns_keytab */ NT_STATUS_HAVE_NO_MEMORY(ejs); ret = test_run_ejs(ejs); @@ -186,17 +198,15 @@ static NTSTATUS provision_bare_ejs(TALLOC_CTX *mem_ctx, } talloc_free(ejs); - talloc_free(ldb); - DEBUG(0,("Open the SAM LDB with system credentials: %s\n", - s->path.samdb_ldb)); + samdb_ldb)); - ldb = ldb_wrap_connect(mem_ctx, lp_ctx, s->path.samdb_ldb, + ldb = ldb_wrap_connect(mem_ctx, lp_ctx, samdb_ldb, system_session(mem_ctx, lp_ctx), NULL, 0, NULL); if (!ldb) { DEBUG(0,("Failed to open '%s'\n", - s->path.samdb_ldb)); + samdb_ldb)); return NT_STATUS_INTERNAL_DB_ERROR; } @@ -205,7 +215,7 @@ static NTSTATUS provision_bare_ejs(TALLOC_CTX *mem_ctx, DEBUG(0,("Failed to set cached ntds invocationId\n")); return NT_STATUS_FOOBAR; } - ok = samdb_set_ntds_objectGUID(ldb, &p->dest_dsa->ntds_guid); + ok = samdb_set_ntds_objectGUID(ldb, ntds_guid); if (!ok) { DEBUG(0,("Failed to set cached ntds objectGUID\n")); return NT_STATUS_FOOBAR; @@ -227,10 +237,23 @@ static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, const char *config_dn_str, const char *schema_dn_str, const struct GUID *invocation_id, - const char *domain) + const char *netbios_name, const char *realm, + const char *domain, + const struct GUID *ntds_guid, + const char *ntds_dn_str, + const char *machine_password, + const char *samdb_ldb, + const char *secrets_ldb, + const char *secrets_keytab, + const char *schemadn_ldb, + const char *configdn_ldb, + const char *domaindn_ldb, + const char *templates_ldb, + const char *dns_keytab) { bool ok; PyObject *provision_fn, *result, *parameters; + struct ldb_context *ldb; DEBUG(0,("Provision for Become-DC test using PYTHON\n")); @@ -251,42 +274,42 @@ static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, DEBUG(0,("DSA Instance [%s]\n" "\tobjectGUID[%s]\n" "\tinvocationId[%s]\n", - p->dest_dsa->ntds_dn_str, - GUID_string(mem_ctx, &p->dest_dsa->ntds_guid), + ntds_dn_str, + GUID_string(mem_ctx, ntds_guid), GUID_string(mem_ctx, invocation_id))); DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", lp_private_dir(lp_ctx), - s->path.samdb_ldb, - s->path.secrets_ldb, - s->path.secrets_keytab)); + samdb_ldb, + secrets_ldb, + secrets_keytab)); DEBUG(0,("Schema Partition[%s => %s]\n", - schema_dn_str, s->path.schemadn_ldb)); + schema_dn_str, schemadn_ldb)); DEBUG(0,("Config Partition[%s => %s]\n", - config_dn_str, s->path.configdn_ldb)); + config_dn_str, configdn_ldb)); DEBUG(0,("Domain Partition[%s => %s]\n", - domain_dn_str, s->path.domaindn_ldb)); + domain_dn_str, domaindn_ldb)); parameters = PyDict_New(); PyDict_SetItemString(parameters, "rootdn", PyString_FromString(root_dn_str)); PyDict_SetItemString(parameters, "domaindn", PyString_FromString(domain_dn_str)); - PyDict_SetItemString(parameters, "domaindn_ldb", PyString_FromString(s->path.domaindn_ldb)); + PyDict_SetItemString(parameters, "domaindn_ldb", PyString_FromString(domaindn_ldb)); PyDict_SetItemString(parameters, "configdn", PyString_FromString(config_dn_str)); - PyDict_SetItemString(parameters, "configdn_ldb", PyString_FromString(s->path.configdn_ldb)); + PyDict_SetItemString(parameters, "configdn_ldb", PyString_FromString(configdn_ldb)); PyDict_SetItemString(parameters, "schema_dn_str", PyString_FromString(schema_dn_str)); - PyDict_SetItemString(parameters, "schemadn_ldb", PyString_FromString(s->path.schemadn_ldb)); + PyDict_SetItemString(parameters, "schemadn_ldb", PyString_FromString(schemadn_ldb)); PyDict_SetItemString(parameters, "netbios_name", PyString_FromString(netbios_name)); PyDict_SetItemString(parameters, "dnsname", PyString_FromString(dns_name)); PyDict_SetItemString(parameters, "defaultsite", PyString_FromString(site_name)); - PyDict_SetItemString(parameters, "machinepass", PyString_FromString(cli_credentials_get_password(s->machine_account))); - PyDict_SetItemString(parameters, "samdb", PyString_FromString(s->path.samdb_ldb)); - PyDict_SetItemString(parameters, "secrets_ldb", PyString_FromString(s->path.secrets_ldb)); - PyDict_SetItemString(parameters, "secrets_keytab", PyString_FromString(s->path.secrets_keytab)); + PyDict_SetItemString(parameters, "machinepass", PyString_FromString(machine_password)); + PyDict_SetItemString(parameters, "samdb", PyString_FromString(samdb_ldb)); + PyDict_SetItemString(parameters, "secrets_ldb", PyString_FromString(secrets_ldb)); + PyDict_SetItemString(parameters, "secrets_keytab", PyString_FromString(secrets_keytab)); result = PyEval_CallObjectWithKeywords(provision_fn, NULL, parameters); @@ -298,17 +321,15 @@ static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, return NT_STATUS_UNSUCCESSFUL; } - talloc_free(ldb); - DEBUG(0,("Open the SAM LDB with system credentials: %s\n", - s->path.samdb_ldb)); + samdb_ldb)); - ldb = ldb_wrap_connect(s, lp_ctx, s->path.samdb_ldb, - system_session(s, lp_ctx), + ldb = ldb_wrap_connect(mem_ctx, lp_ctx, samdb_ldb, + system_session(mem_ctx, lp_ctx), NULL, 0, NULL); if (!ldb) { DEBUG(0,("Failed to open '%s'\n", - s->path.samdb_ldb)); + samdb_ldb)); return NT_STATUS_INTERNAL_DB_ERROR; } @@ -317,7 +338,7 @@ static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, DEBUG(0,("Failed to set cached ntds invocationId\n")); return NT_STATUS_FOOBAR; } - ok = samdb_set_ntds_objectGUID(ldb, &p->dest_dsa->ntds_guid); + ok = samdb_set_ntds_objectGUID(ldb, ntds_guid); if (!ok) { DEBUG(0,("Failed to set cached ntds objectGUID\n")); return NT_STATUS_FOOBAR; @@ -332,16 +353,36 @@ NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, const char *config_dn_str, const char *schema_dn_str, const struct GUID *invocation_id, const char *netbios_name, const char *realm, - const char *domain) + const char *domain, const struct GUID *ntds_guid, + const char *ntds_dn_str, + const char *machine_password, + const char *samdb_ldb, + const char *secrets_ldb, + const char *secrets_keytab, + const char *schemadn_ldb, + const char *configdn_ldb, + const char *domaindn_ldb, + const char *templates_ldb, + const char *dns_keytab) { if (getenv("PROVISION_EJS")) { - provision_bare_ejs(mem_ctx, lp_ctx, dns_name, site_name, root_dn_str, - domain_dn_str, config_dn_str, schema_dn_str, - invocation_id, netbios_name, realm, domain); + return provision_bare_ejs(mem_ctx, lp_ctx, dns_name, site_name, + root_dn_str, domain_dn_str, config_dn_str, + schema_dn_str, invocation_id, netbios_name, + realm, domain, ntds_guid, ntds_dn_str, + machine_password, samdb_ldb, secrets_ldb, + secrets_keytab, schemadn_ldb, configdn_ldb, + domaindn_ldb, templates_ldb, + dns_keytab); } else { - provision_bare_py(mem_ctx, lp_ctx, dns_name, site_name, root_dn_str, - domain_dn_str, config_dn_str, schema_dn_str, - invocation_id, netbios_name, realm, domain); + return provision_bare_py(mem_ctx, lp_ctx, dns_name, site_name, + root_dn_str, domain_dn_str, config_dn_str, + schema_dn_str, invocation_id, netbios_name, + realm, domain, ntds_guid, ntds_dn_str, + machine_password, samdb_ldb, secrets_ldb, + secrets_keytab, schemadn_ldb, configdn_ldb, + domaindn_ldb, templates_ldb, + dns_keytab); } } -- cgit From d499dfd9388f39d0b45ba586169bd3c4b7138dd7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Feb 2008 01:37:57 +0100 Subject: Add test for provision_bare() code. (This used to be commit 0f3a1dbb5355bf5181d9a100af35be8a7f292be6) --- source4/torture/local/torture.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source4') diff --git a/source4/torture/local/torture.c b/source4/torture/local/torture.c index b57361bc8d..7d12c467df 100644 --- a/source4/torture/local/torture.c +++ b/source4/torture/local/torture.c @@ -39,12 +39,33 @@ static bool test_tempdir(struct torture_context *tctx) return true; } +static bool test_provision(struct torture_context *tctx) +{ + NTSTATUS status; + + status = provision_bare(tctx, tctx->lp_ctx, + "example.com", "SOME-SITE-NAME", + "DC=EXAMPLE,DC=COM", + "DC=EXAMPLE,DC=COM", + NULL, NULL, NULL, + "FOO", "EXAMPLE.COM", + "EXAMPLE", NULL, + NULL, "geheim", + NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL); + + torture_assert_ntstatus_ok(tctx, status, "provision"); + + return true; +} + struct torture_suite *torture_local_torture(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "TORTURE"); torture_suite_add_simple_test(suite, "tempdir", test_tempdir); + torture_suite_add_simple_test(suite, "provision", test_provision); return suite; } -- cgit From b5f329602b3cd044cabb9ea0945724a307139eb9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Feb 2008 02:12:37 +0100 Subject: Add ability to not specify certain provision options(), fix some other options. (This used to be commit fe8bfda22d8e1fdbece4209b7489419074565efd) --- source4/torture/util_provision.c | 66 ++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 19 deletions(-) (limited to 'source4') diff --git a/source4/torture/util_provision.c b/source4/torture/util_provision.c index bc4f3d2b28..5873b9f485 100644 --- a/source4/torture/util_provision.c +++ b/source4/torture/util_provision.c @@ -252,22 +252,36 @@ static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, const char *dns_keytab) { bool ok; - PyObject *provision_fn, *result, *parameters; + PyObject *provision_mod, *provision_dict, *provision_fn, *result, *parameters; struct ldb_context *ldb; DEBUG(0,("Provision for Become-DC test using PYTHON\n")); py_load_samba_modules(); Py_Initialize(); + py_update_path("bin"); /* FIXME: Can't assume this is always the case */ - py_update_path("bin"); /* FIXME: Can't assume this always runs in source/... */ + provision_mod = PyImport_Import(PyString_FromString("samba.provision")); - provision_fn = PyImport_Import(PyString_FromString("samba.provision.provision")); - - if (provision_fn == NULL) { + if (provision_mod == NULL) { + PyErr_Print(); DEBUG(0, ("Unable to import provision Python module.\n")); return NT_STATUS_UNSUCCESSFUL; } + + provision_dict = PyModule_GetDict(provision_mod); + + if (provision_dict == NULL) { + DEBUG(0, ("Unable to get dictionary for provision module\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + provision_fn = PyDict_GetItemString(provision_dict, "provision"); + if (provision_fn == NULL) { + PyErr_Print(); + DEBUG(0, ("Unable to get provision function\n")); + return NT_STATUS_UNSUCCESSFUL; + } DEBUG(0,("New Server[%s] in Site[%s]\n", dns_name, site_name)); @@ -275,8 +289,8 @@ static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, "\tobjectGUID[%s]\n" "\tinvocationId[%s]\n", ntds_dn_str, - GUID_string(mem_ctx, ntds_guid), - GUID_string(mem_ctx, invocation_id))); + ntds_guid == NULL?"None":GUID_string(mem_ctx, ntds_guid), + invocation_id == NULL?"None":GUID_string(mem_ctx, invocation_id))); DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", @@ -297,19 +311,33 @@ static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, parameters = PyDict_New(); PyDict_SetItemString(parameters, "rootdn", PyString_FromString(root_dn_str)); - PyDict_SetItemString(parameters, "domaindn", PyString_FromString(domain_dn_str)); - PyDict_SetItemString(parameters, "domaindn_ldb", PyString_FromString(domaindn_ldb)); - PyDict_SetItemString(parameters, "configdn", PyString_FromString(config_dn_str)); - PyDict_SetItemString(parameters, "configdn_ldb", PyString_FromString(configdn_ldb)); - PyDict_SetItemString(parameters, "schema_dn_str", PyString_FromString(schema_dn_str)); - PyDict_SetItemString(parameters, "schemadn_ldb", PyString_FromString(schemadn_ldb)); - PyDict_SetItemString(parameters, "netbios_name", PyString_FromString(netbios_name)); - PyDict_SetItemString(parameters, "dnsname", PyString_FromString(dns_name)); - PyDict_SetItemString(parameters, "defaultsite", PyString_FromString(site_name)); + if (domaindn_ldb != NULL) + PyDict_SetItemString(parameters, "domaindn_ldb", + PyString_FromString(domaindn_ldb)); + if (config_dn_str != NULL) + PyDict_SetItemString(parameters, "configdn", + PyString_FromString(config_dn_str)); + if (configdn_ldb != NULL) + PyDict_SetItemString(parameters, "configdn_ldb", + PyString_FromString(configdn_ldb)); + if (schema_dn_str != NULL) + PyDict_SetItemString(parameters, "schema_dn_str", + PyString_FromString(schema_dn_str)); + if (schemadn_ldb != NULL) + PyDict_SetItemString(parameters, "schemadn_ldb", + PyString_FromString(schemadn_ldb)); + PyDict_SetItemString(parameters, "hostname", PyString_FromString(netbios_name)); + PyDict_SetItemString(parameters, "sitename", PyString_FromString(site_name)); PyDict_SetItemString(parameters, "machinepass", PyString_FromString(machine_password)); - PyDict_SetItemString(parameters, "samdb", PyString_FromString(samdb_ldb)); - PyDict_SetItemString(parameters, "secrets_ldb", PyString_FromString(secrets_ldb)); - PyDict_SetItemString(parameters, "secrets_keytab", PyString_FromString(secrets_keytab)); + if (samdb_ldb != NULL) + PyDict_SetItemString(parameters, "samdb", + PyString_FromString(samdb_ldb)); + if (secrets_ldb != NULL) + PyDict_SetItemString(parameters, "secrets_ldb", + PyString_FromString(secrets_ldb)); + if (secrets_keytab != NULL) + PyDict_SetItemString(parameters, "secrets_keytab", + PyString_FromString(secrets_keytab)); result = PyEval_CallObjectWithKeywords(provision_fn, NULL, parameters); -- cgit From de3d54e0559ee5ae9aa6810a3eaf4f237dbc5ae5 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 14 Feb 2008 16:08:50 +0100 Subject: lsa.idl: don't use ascstr_noterm anymore metze (This used to be commit b994f899b42d294c0418bdc82660a2f7510667d6) --- source4/librpc/idl/lsa.idl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4') diff --git a/source4/librpc/idl/lsa.idl b/source4/librpc/idl/lsa.idl index 8d26ec0aad..c2b7b5b58a 100644 --- a/source4/librpc/idl/lsa.idl +++ b/source4/librpc/idl/lsa.idl @@ -33,9 +33,9 @@ import "security.idl"; } lsa_Strings; typedef [public] struct { - [value(strlen_m(string))] uint16 length; - [value(strlen_m(string))] uint16 size; - ascstr_noterm *string; + [value(strlen(string))] uint16 length; + [value(strlen(string))] uint16 size; + [charset(DOS),size_is(size),length_is(length)] uint8 *string; } lsa_AsciiString; /******************/ -- cgit From 9d9d54430aed677ae33e51fda5da7b4306c734f1 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 15 Feb 2008 14:56:07 +0100 Subject: lsa.idl: add lsa_AsciiStringLarge metze (This used to be commit 646c597b79cb01474ed8139e4e790206bd84632c) --- source4/librpc/idl/lsa.idl | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source4') diff --git a/source4/librpc/idl/lsa.idl b/source4/librpc/idl/lsa.idl index c2b7b5b58a..bc5ccaa78a 100644 --- a/source4/librpc/idl/lsa.idl +++ b/source4/librpc/idl/lsa.idl @@ -38,6 +38,12 @@ import "security.idl"; [charset(DOS),size_is(size),length_is(length)] uint8 *string; } lsa_AsciiString; + typedef [public] struct { + [value(strlen(string))] uint16 length; + [value(strlen(string)+1)] uint16 size; + [charset(DOS),size_is(size),length_is(length)] uint8 *string; + } lsa_AsciiStringLarge; + /******************/ /* Function: 0x00 */ NTSTATUS lsa_Close ( -- cgit From 85fe22a85fe7e8db7d2f6e2fdd6f02836f116b8e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Feb 2008 15:14:55 +0100 Subject: Use struct for provision parameters since there are so many of them. (This used to be commit 4b9d5bc57ca4ee14c142ea720dce5e4ee97f8c16) --- source4/scripting/python/samba/provision.py | 40 ++--- source4/torture/libnet/libnet_BecomeDC.c | 39 +++-- source4/torture/local/torture.c | 36 +++-- source4/torture/util_provision.c | 222 ++++++++++------------------ source4/torture/util_provision.h | 51 +++++++ 5 files changed, 202 insertions(+), 186 deletions(-) create mode 100644 source4/torture/util_provision.h (limited to 'source4') diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 97021fceb2..d30eaf3d7f 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -271,7 +271,7 @@ def setup_name_mappings(ldb, sid, domaindn, root, nobody, nogroup, users, def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, credentials, configdn, schemadn, domaindn, hostname, netbiosname, dnsdomain, realm, - rootdn, serverrole, ldap_backend=None, + rootdn, serverrole, sitename, ldap_backend=None, ldap_backend_type=None, erase=False): """Setup the partitions for the SAM database. @@ -378,7 +378,8 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, message("Setting up sam.ldb rootDSE") setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname, - dnsdomain, realm, rootdn, configdn, netbiosname) + dnsdomain, realm, rootdn, configdn, netbiosname, + sitename) if erase: message("Erasing data from partitions") @@ -472,7 +473,8 @@ def setup_registry(path, setup_path, session_info, credentials, lp): def setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname, - dnsdomain, realm, rootdn, configdn, netbiosname): + dnsdomain, realm, rootdn, configdn, netbiosname, + sitename): """Setup the SamDB rootdse. :param samdb: Sam Database handle @@ -482,7 +484,7 @@ def setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname, "SCHEMADN": schemadn, "NETBIOSNAME": netbiosname, "DNSDOMAIN": dnsdomain, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "REALM": realm, "DNSNAME": "%s.%s" % (hostname, dnsdomain), "DOMAINDN": domaindn, @@ -495,7 +497,7 @@ def setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname, def setup_self_join(samdb, configdn, schemadn, domaindn, netbiosname, hostname, dnsdomain, machinepass, dnspass, realm, domainname, domainsid, invocationid, setup_path, - policyguid, hostguid=None): + policyguid, sitename, hostguid=None): """Join a host to its own domain.""" if hostguid is not None: hostguid_add = "objectGUID: %s" % hostguid @@ -508,7 +510,7 @@ def setup_self_join(samdb, configdn, schemadn, domaindn, "DOMAINDN": domaindn, "INVOCATIONID": invocationid, "NETBIOSNAME": netbiosname, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "DNSNAME": "%s.%s" % (hostname, dnsdomain), "MACHINEPASS_B64": b64encode(machinepass), "DNSPASS_B64": b64encode(dnspass), @@ -529,7 +531,8 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, domainsid, aci, domainguid, policyguid, domainname, fill, adminpass, krbtgtpass, machinepass, hostguid, invocationid, dnspass, - serverrole, ldap_backend=None, ldap_backend_type=None): + serverrole, sitename, ldap_backend=None, + ldap_backend_type=None): """Setup a complete SAM Database. :note: This will wipe the main SAM database file! @@ -544,7 +547,8 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, hostname=hostname, netbiosname=netbiosname, dnsdomain=dnsdomain, realm=realm, rootdn=rootdn, ldap_backend=ldap_backend, serverrole=serverrole, - ldap_backend_type=ldap_backend_type, erase=erase) + ldap_backend_type=ldap_backend_type, erase=erase, + sitename=sitename) samdb = SamDB(path, session_info=session_info, credentials=credentials, lp=lp) @@ -562,7 +566,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, if lp.get("server role") == "domain controller": samdb.set_invocation_id(invocationid) - load_schema(setup_path, samdb, schemadn, netbiosname, configdn) + load_schema(setup_path, samdb, schemadn, netbiosname, configdn, sitename) samdb.transaction_start() @@ -584,7 +588,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, "DOMAINSID": str(domainsid), "SCHEMADN": schemadn, "NETBIOSNAME": netbiosname, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "CONFIGDN": configdn, "POLICYGUID": policyguid, "DOMAINDN": domaindn, @@ -614,7 +618,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, setup_path("provision_schema_basedn_modify.ldif"), { "SCHEMADN": schemadn, "NETBIOSNAME": netbiosname, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "CONFIGDN": configdn, }) @@ -629,7 +633,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, setup_add_ldif(samdb, setup_path("provision_configuration.ldif"), { "CONFIGDN": configdn, "NETBIOSNAME": netbiosname, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "DNSDOMAIN": dnsdomain, "DOMAIN": domainname, "SCHEMADN": schemadn, @@ -656,7 +660,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, setup_add_ldif(samdb, setup_path("provision.ldif"), { "DOMAINDN": domaindn, "NETBIOSNAME": netbiosname, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "CONFIGDN": configdn, }) @@ -679,7 +683,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, machinepass=machinepass, domainname=domainname, domainsid=domainsid, policyguid=policyguid, hostname=hostname, hostguid=hostguid, - setup_path=setup_path) + setup_path=setup_path, sitename=sitename) #We want to setup the index last, as adds are faster unindexed message("Setting up sam.ldb index") @@ -702,7 +706,7 @@ def provision(lp, setup_dir, message, paths, session_info, policyguid=None, invocationid=None, machinepass=None, dnspass=None, root=None, nobody=None, nogroup=None, users=None, wheel=None, backup=None, aci=None, serverrole=None, erase=False, - ldap_backend=None, ldap_backend_type=None): + ldap_backend=None, ldap_backend_type=None, sitename=DEFAULTSITE): """Provision samba4 :note: caution, this wipes all existing data! @@ -851,7 +855,7 @@ def provision(lp, setup_dir, message, paths, session_info, hostguid=hostguid, invocationid=invocationid, machinepass=machinepass, dnspass=dnspass, serverrole=serverrole, ldap_backend=ldap_backend, - ldap_backend_type=ldap_backend_type) + ldap_backend_type=ldap_backend_type, sitename=sitename) if lp.get("server role") == "domain controller": policy_path = os.path.join(paths.sysvol, dnsdomain, "Policies", @@ -945,7 +949,7 @@ def create_zone_file(path, setup_path, samdb, dnsdomain, domaindn, }) -def load_schema(setup_path, samdb, schemadn, netbiosname, configdn): +def load_schema(setup_path, samdb, schemadn, netbiosname, configdn, sitename): """Load schema for the SamDB. :param samdb: Load a schema into a SamDB. @@ -962,7 +966,7 @@ def load_schema(setup_path, samdb, schemadn, netbiosname, configdn): "SCHEMADN": schemadn, "NETBIOSNAME": netbiosname, "CONFIGDN": configdn, - "DEFAULTSITE": DEFAULTSITE + "DEFAULTSITE":sitename }) samdb.attach_schema_from_ldif(head_data, schema_data) diff --git a/source4/torture/libnet/libnet_BecomeDC.c b/source4/torture/libnet/libnet_BecomeDC.c index 83d7426dfb..13e1aec6d0 100644 --- a/source4/torture/libnet/libnet_BecomeDC.c +++ b/source4/torture/libnet/libnet_BecomeDC.c @@ -37,7 +37,7 @@ #include "lib/ldb_wrap.h" #include "auth/auth.h" #include "param/param.h" -#include "torture/util.h" +#include "torture/util_provision.h" struct test_become_dc_state { struct libnet_context *ctx; @@ -72,20 +72,29 @@ static NTSTATUS test_become_dc_prepare_db(void *private_data, const struct libnet_BecomeDC_PrepareDB *p) { struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); - return provision_bare(s, s->tctx->lp_ctx, p->dest_dsa->dns_name, - p->dest_dsa->site_name, p->forest->root_dn_str, - p->domain->dn_str, p->forest->config_dn_str, - p->forest->schema_dn_str, - &p->dest_dsa->invocation_id, - p->dest_dsa->netbios_name, - torture_join_dom_dns_name(s->tj), - torture_join_dom_netbios_name(s->tj), - &p->dest_dsa->ntds_guid, - p->dest_dsa->ntds_dn_str, - cli_credentials_get_password(s->machine_account), - s->path.samdb_ldb, s->path.secrets_ldb, - s->path.secrets_keytab, s->path.schemadn_ldb, - s->path.configdn_ldb, s->path.domaindn_ldb); + struct provision_settings settings; + + settings.dns_name = p->dest_dsa->dns_name; + settings.site_name = p->dest_dsa->site_name; + settings.root_dn_str = p->forest->root_dn_str; + settings.domain_dn_str = p->domain->dn_str; + settings.config_dn_str = p->forest->config_dn_str; + settings.schema_dn_str = p->forest->schema_dn_str; + settings.invocation_id = &p->dest_dsa->invocation_id; + settings.netbios_name = p->dest_dsa->netbios_name; + settings.realm = torture_join_dom_dns_name(s->tj); + settings.domain = torture_join_dom_netbios_name(s->tj); + settings.ntds_guid = &p->dest_dsa->ntds_guid; + settings.ntds_dn_str = p->dest_dsa->ntds_dn_str; + settings.machine_password = cli_credentials_get_password(s->machine_account); + settings.samdb_ldb = s->path.samdb_ldb; + settings.secrets_ldb = s->path.secrets_ldb; + settings.secrets_keytab = s->path.secrets_keytab; + settings.schemadn_ldb = s->path.schemadn_ldb; + settings.configdn_ldb = s->path.configdn_ldb; + settings.domaindn_ldb = s->path.domaindn_ldb; + + return provision_bare(s, s->tctx->lp_ctx, &settings); } static NTSTATUS test_become_dc_check_options(void *private_data, diff --git a/source4/torture/local/torture.c b/source4/torture/local/torture.c index 7d12c467df..0c9931be03 100644 --- a/source4/torture/local/torture.c +++ b/source4/torture/local/torture.c @@ -24,7 +24,7 @@ #include "system/wait.h" #include "lib/events/events.h" #include "libcli/raw/libcliraw.h" -#include "torture/util.h" +#include "torture/util_provision.h" static bool test_tempdir(struct torture_context *tctx) { @@ -42,18 +42,32 @@ static bool test_tempdir(struct torture_context *tctx) static bool test_provision(struct torture_context *tctx) { NTSTATUS status; + struct provision_settings settings; - status = provision_bare(tctx, tctx->lp_ctx, - "example.com", "SOME-SITE-NAME", - "DC=EXAMPLE,DC=COM", - "DC=EXAMPLE,DC=COM", - NULL, NULL, NULL, - "FOO", "EXAMPLE.COM", - "EXAMPLE", NULL, - NULL, "geheim", - NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL); + settings.dns_name = "example.com"; + settings.site_name = "SOME-SITE-NAME"; + settings.root_dn_str = "DC=EXAMPLE,DC=COM"; + settings.domain_dn_str = "DC=EXAMPLE,DC=COM"; + settings.config_dn_str = NULL; + settings.schema_dn_str = NULL; + settings.invocation_id = NULL; + settings.netbios_name = "FOO"; + settings.realm = "EXAMPLE.COM"; + settings.domain = "EXAMPLE"; + settings.ntds_guid = NULL; + settings.ntds_dn_str = NULL; + settings.machine_password = "geheim"; + settings.samdb_ldb = NULL; + settings.secrets_ldb = NULL; + settings.secrets_keytab = NULL; + settings.schemadn_ldb = NULL; + settings.configdn_ldb = NULL; + settings.domaindn_ldb = NULL; + settings.templates_ldb = NULL; + settings.dns_keytab = NULL; + status = provision_bare(tctx, tctx->lp_ctx, &settings); + torture_assert_ntstatus_ok(tctx, status, "provision"); return true; diff --git a/source4/torture/util_provision.c b/source4/torture/util_provision.c index 5873b9f485..a5c564b05c 100644 --- a/source4/torture/util_provision.c +++ b/source4/torture/util_provision.c @@ -24,6 +24,7 @@ #include "scripting/ejs/smbcalls.h" #include "auth/auth.h" #include "lib/ldb_wrap.h" +#include "torture/util_provision.h" static EjsId eid; static int ejs_error; @@ -80,27 +81,7 @@ failed: static NTSTATUS provision_bare_ejs(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, - const char *dns_name, - const char *site_name, - const char *root_dn_str, - const char *domain_dn_str, - const char *config_dn_str, - const char *schema_dn_str, - const struct GUID *invocation_id, - const char *netbios_name, - const char *realm, - const char *domain, - const struct GUID *ntds_guid, - const char *ntds_dn_str, - const char *machine_password, - const char *samdb_ldb, - const char *secrets_ldb, - const char *secrets_keytab, - const char *schemadn_ldb, - const char *configdn_ldb, - const char *domaindn_ldb, - const char *templates_ldb, - const char *dns_keytab) + struct provision_settings *settings) { char *ejs; int ret; @@ -109,30 +90,31 @@ static NTSTATUS provision_bare_ejs(TALLOC_CTX *mem_ctx, DEBUG(0,("Provision for Become-DC test using EJS\n")); - DEBUG(0,("New Server[%s] in Site[%s]\n", dns_name, site_name)); + DEBUG(0,("New Server[%s] in Site[%s]\n", settings->dns_name, + settings->site_name)); DEBUG(0,("DSA Instance [%s]\n" "\tobjectGUID[%s]\n" "\tinvocationId[%s]\n", - ntds_dn_str, - GUID_string(mem_ctx, ntds_guid), - GUID_string(mem_ctx, invocation_id))); + settings->ntds_dn_str, + GUID_string(mem_ctx, settings->ntds_guid), + GUID_string(mem_ctx, settings->invocation_id))); DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", lp_private_dir(lp_ctx), - samdb_ldb, - secrets_ldb, - secrets_keytab)); + settings->samdb_ldb, + settings->secrets_ldb, + settings->secrets_keytab)); DEBUG(0,("Schema Partition[%s => %s]\n", - schema_dn_str, schemadn_ldb)); + settings->schema_dn_str, settings->schemadn_ldb)); DEBUG(0,("Config Partition[%s => %s]\n", - config_dn_str, configdn_ldb)); + settings->config_dn_str, settings->configdn_ldb)); DEBUG(0,("Domain Partition[%s => %s]\n", - domain_dn_str, domaindn_ldb)); + settings->domain_dn_str, settings->domaindn_ldb)); ejs = talloc_asprintf(mem_ctx, "libinclude(\"base.js\");\n" @@ -170,23 +152,23 @@ static NTSTATUS provision_bare_ejs(TALLOC_CTX *mem_ctx, "assert(ok);\n" "\n" "return 0;\n", - root_dn_str, /* subobj.ROOTDN */ - domain_dn_str, /* subobj.DOMAINDN */ - domaindn_ldb, /* subobj.DOMAINDN_LDB */ - config_dn_str, /* subobj.CONFIGDN */ - configdn_ldb, /* subobj.CONFIGDN_LDB */ - schema_dn_str, /* subobj.SCHEMADN */ - schemadn_ldb, /* subobj.SCHEMADN_LDB */ - netbios_name, /* subobj.HOSTNAME */ - realm,/* subobj.REALM */ - domain,/* subobj.DOMAIN */ - site_name, /* subobj.DEFAULTSITE */ - machine_password,/* subobj.MACHINEPASS */ - samdb_ldb, /* paths.samdb */ - templates_ldb, /* paths.templates */ - secrets_ldb, /* paths.secrets */ - secrets_keytab, /* paths.keytab */ - dns_keytab); /* paths.dns_keytab */ + settings->root_dn_str, /* subobj.ROOTDN */ + settings->domain_dn_str, /* subobj.DOMAINDN */ + settings->domaindn_ldb, /* subobj.DOMAINDN_LDB */ + settings->config_dn_str, /* subobj.CONFIGDN */ + settings->configdn_ldb, /* subobj.CONFIGDN_LDB */ + settings->schema_dn_str, /* subobj.SCHEMADN */ + settings->schemadn_ldb, /* subobj.SCHEMADN_LDB */ + settings->netbios_name, /* subobj.HOSTNAME */ + settings->realm,/* subobj.REALM */ + settings->domain,/* subobj.DOMAIN */ + settings->site_name, /* subobj.DEFAULTSITE */ + settings->machine_password,/* subobj.MACHINEPASS */ + settings->samdb_ldb, /* paths.samdb */ + settings->templates_ldb, /* paths.templates */ + settings->secrets_ldb, /* paths.secrets */ + settings->secrets_keytab, /* paths.keytab */ + settings->dns_keytab); /* paths.dns_keytab */ NT_STATUS_HAVE_NO_MEMORY(ejs); ret = test_run_ejs(ejs); @@ -199,23 +181,23 @@ static NTSTATUS provision_bare_ejs(TALLOC_CTX *mem_ctx, talloc_free(ejs); DEBUG(0,("Open the SAM LDB with system credentials: %s\n", - samdb_ldb)); + settings->samdb_ldb)); - ldb = ldb_wrap_connect(mem_ctx, lp_ctx, samdb_ldb, + ldb = ldb_wrap_connect(mem_ctx, lp_ctx, settings->samdb_ldb, system_session(mem_ctx, lp_ctx), NULL, 0, NULL); if (!ldb) { DEBUG(0,("Failed to open '%s'\n", - samdb_ldb)); + settings->samdb_ldb)); return NT_STATUS_INTERNAL_DB_ERROR; } - ok = samdb_set_ntds_invocation_id(ldb, invocation_id); + ok = samdb_set_ntds_invocation_id(ldb, settings->invocation_id); if (!ok) { DEBUG(0,("Failed to set cached ntds invocationId\n")); return NT_STATUS_FOOBAR; } - ok = samdb_set_ntds_objectGUID(ldb, ntds_guid); + ok = samdb_set_ntds_objectGUID(ldb, settings->ntds_guid); if (!ok) { DEBUG(0,("Failed to set cached ntds objectGUID\n")); return NT_STATUS_FOOBAR; @@ -230,32 +212,13 @@ static NTSTATUS provision_bare_ejs(TALLOC_CTX *mem_ctx, static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, - const char *dns_name, - const char *site_name, - const char *root_dn_str, - const char *domain_dn_str, - const char *config_dn_str, - const char *schema_dn_str, - const struct GUID *invocation_id, - const char *netbios_name, const char *realm, - const char *domain, - const struct GUID *ntds_guid, - const char *ntds_dn_str, - const char *machine_password, - const char *samdb_ldb, - const char *secrets_ldb, - const char *secrets_keytab, - const char *schemadn_ldb, - const char *configdn_ldb, - const char *domaindn_ldb, - const char *templates_ldb, - const char *dns_keytab) + struct provision_settings *settings) { bool ok; PyObject *provision_mod, *provision_dict, *provision_fn, *result, *parameters; struct ldb_context *ldb; - DEBUG(0,("Provision for Become-DC test using PYTHON\n")); + DEBUG(0,("Provision for Become-DC test using python\n")); py_load_samba_modules(); Py_Initialize(); @@ -283,61 +246,66 @@ static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, return NT_STATUS_UNSUCCESSFUL; } - DEBUG(0,("New Server[%s] in Site[%s]\n", dns_name, site_name)); + DEBUG(0,("New Server[%s] in Site[%s]\n", settings->dns_name, + settings->site_name)); DEBUG(0,("DSA Instance [%s]\n" "\tobjectGUID[%s]\n" "\tinvocationId[%s]\n", - ntds_dn_str, - ntds_guid == NULL?"None":GUID_string(mem_ctx, ntds_guid), - invocation_id == NULL?"None":GUID_string(mem_ctx, invocation_id))); + settings->ntds_dn_str, + settings->ntds_guid == NULL?"None":GUID_string(mem_ctx, settings->ntds_guid), + settings->invocation_id == NULL?"None":GUID_string(mem_ctx, settings->invocation_id))); DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", lp_private_dir(lp_ctx), - samdb_ldb, - secrets_ldb, - secrets_keytab)); + settings->samdb_ldb, + settings->secrets_ldb, + settings->secrets_keytab)); DEBUG(0,("Schema Partition[%s => %s]\n", - schema_dn_str, schemadn_ldb)); + settings->schema_dn_str, settings->schemadn_ldb)); DEBUG(0,("Config Partition[%s => %s]\n", - config_dn_str, configdn_ldb)); + settings->config_dn_str, settings->configdn_ldb)); DEBUG(0,("Domain Partition[%s => %s]\n", - domain_dn_str, domaindn_ldb)); + settings->domain_dn_str, settings->domaindn_ldb)); parameters = PyDict_New(); - PyDict_SetItemString(parameters, "rootdn", PyString_FromString(root_dn_str)); - if (domaindn_ldb != NULL) + PyDict_SetItemString(parameters, "rootdn", + PyString_FromString(settings->root_dn_str)); + if (settings->domaindn_ldb != NULL) PyDict_SetItemString(parameters, "domaindn_ldb", - PyString_FromString(domaindn_ldb)); - if (config_dn_str != NULL) + PyString_FromString(settings->domaindn_ldb)); + if (settings->config_dn_str != NULL) PyDict_SetItemString(parameters, "configdn", - PyString_FromString(config_dn_str)); - if (configdn_ldb != NULL) + PyString_FromString(settings->config_dn_str)); + if (settings->configdn_ldb != NULL) PyDict_SetItemString(parameters, "configdn_ldb", - PyString_FromString(configdn_ldb)); - if (schema_dn_str != NULL) + PyString_FromString(settings->configdn_ldb)); + if (settings->schema_dn_str != NULL) PyDict_SetItemString(parameters, "schema_dn_str", - PyString_FromString(schema_dn_str)); - if (schemadn_ldb != NULL) + PyString_FromString(settings->schema_dn_str)); + if (settings->schemadn_ldb != NULL) PyDict_SetItemString(parameters, "schemadn_ldb", - PyString_FromString(schemadn_ldb)); - PyDict_SetItemString(parameters, "hostname", PyString_FromString(netbios_name)); - PyDict_SetItemString(parameters, "sitename", PyString_FromString(site_name)); - PyDict_SetItemString(parameters, "machinepass", PyString_FromString(machine_password)); - if (samdb_ldb != NULL) + PyString_FromString(settings->schemadn_ldb)); + PyDict_SetItemString(parameters, "hostname", + PyString_FromString(settings->netbios_name)); + PyDict_SetItemString(parameters, "sitename", + PyString_FromString(settings->site_name)); + PyDict_SetItemString(parameters, "machinepass", + PyString_FromString(settings->machine_password)); + if (settings->samdb_ldb != NULL) PyDict_SetItemString(parameters, "samdb", - PyString_FromString(samdb_ldb)); - if (secrets_ldb != NULL) + PyString_FromString(settings->samdb_ldb)); + if (settings->secrets_ldb != NULL) PyDict_SetItemString(parameters, "secrets_ldb", - PyString_FromString(secrets_ldb)); - if (secrets_keytab != NULL) + PyString_FromString(settings->secrets_ldb)); + if (settings->secrets_keytab != NULL) PyDict_SetItemString(parameters, "secrets_keytab", - PyString_FromString(secrets_keytab)); + PyString_FromString(settings->secrets_keytab)); result = PyEval_CallObjectWithKeywords(provision_fn, NULL, parameters); @@ -350,23 +318,22 @@ static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, } DEBUG(0,("Open the SAM LDB with system credentials: %s\n", - samdb_ldb)); + settings->samdb_ldb)); - ldb = ldb_wrap_connect(mem_ctx, lp_ctx, samdb_ldb, + ldb = ldb_wrap_connect(mem_ctx, lp_ctx, settings->samdb_ldb, system_session(mem_ctx, lp_ctx), NULL, 0, NULL); if (!ldb) { - DEBUG(0,("Failed to open '%s'\n", - samdb_ldb)); + DEBUG(0,("Failed to open '%s'\n", settings->samdb_ldb)); return NT_STATUS_INTERNAL_DB_ERROR; } - ok = samdb_set_ntds_invocation_id(ldb, invocation_id); + ok = samdb_set_ntds_invocation_id(ldb, settings->invocation_id); if (!ok) { DEBUG(0,("Failed to set cached ntds invocationId\n")); return NT_STATUS_FOOBAR; } - ok = samdb_set_ntds_objectGUID(ldb, ntds_guid); + ok = samdb_set_ntds_objectGUID(ldb, settings->ntds_guid); if (!ok) { DEBUG(0,("Failed to set cached ntds objectGUID\n")); return NT_STATUS_FOOBAR; @@ -376,41 +343,12 @@ static NTSTATUS provision_bare_py(TALLOC_CTX *mem_ctx, } NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, - const char *dns_name, const char *site_name, - const char *root_dn_str, const char *domain_dn_str, - const char *config_dn_str, const char *schema_dn_str, - const struct GUID *invocation_id, - const char *netbios_name, const char *realm, - const char *domain, const struct GUID *ntds_guid, - const char *ntds_dn_str, - const char *machine_password, - const char *samdb_ldb, - const char *secrets_ldb, - const char *secrets_keytab, - const char *schemadn_ldb, - const char *configdn_ldb, - const char *domaindn_ldb, - const char *templates_ldb, - const char *dns_keytab) + struct provision_settings *settings) { if (getenv("PROVISION_EJS")) { - return provision_bare_ejs(mem_ctx, lp_ctx, dns_name, site_name, - root_dn_str, domain_dn_str, config_dn_str, - schema_dn_str, invocation_id, netbios_name, - realm, domain, ntds_guid, ntds_dn_str, - machine_password, samdb_ldb, secrets_ldb, - secrets_keytab, schemadn_ldb, configdn_ldb, - domaindn_ldb, templates_ldb, - dns_keytab); + return provision_bare_ejs(mem_ctx, lp_ctx, settings); } else { - return provision_bare_py(mem_ctx, lp_ctx, dns_name, site_name, - root_dn_str, domain_dn_str, config_dn_str, - schema_dn_str, invocation_id, netbios_name, - realm, domain, ntds_guid, ntds_dn_str, - machine_password, samdb_ldb, secrets_ldb, - secrets_keytab, schemadn_ldb, configdn_ldb, - domaindn_ldb, templates_ldb, - dns_keytab); + return provision_bare_py(mem_ctx, lp_ctx, settings); } } diff --git a/source4/torture/util_provision.h b/source4/torture/util_provision.h new file mode 100644 index 0000000000..28467080b1 --- /dev/null +++ b/source4/torture/util_provision.h @@ -0,0 +1,51 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2008 + + 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 . +*/ + +#ifndef _TORTURE_PROVISION_H_ +#define _TORTURE_PROVISION_H_ + +struct provision_settings { + const char *dns_name; + const char *site_name; + const char *root_dn_str; + const char *domain_dn_str; + const char *config_dn_str; + const char *schema_dn_str; + const struct GUID *invocation_id; + const char *netbios_name; + const char *realm; + const char *domain; + const struct GUID *ntds_guid; + const char *ntds_dn_str; + const char *machine_password; + const char *samdb_ldb; + const char *secrets_ldb; + const char *secrets_keytab; + const char *schemadn_ldb; + const char *configdn_ldb; + const char *domaindn_ldb; + const char *templates_ldb; + const char *dns_keytab; +}; + +NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, + struct provision_settings *settings); + + +#endif /* _TORTURE_PROVISION_H_ */ -- cgit From 6c4acbbf9ee0f92ed614d872686426897dbe26bc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Feb 2008 15:22:01 +0100 Subject: Mark the provision_bare() test as known failing for now. (This used to be commit bb473a8d11ce0ab8d5c9f0b339861b552fc2b262) --- source4/samba4-knownfail | 1 + 1 file changed, 1 insertion(+) (limited to 'source4') diff --git a/source4/samba4-knownfail b/source4/samba4-knownfail index ab03145354..376d627764 100644 --- a/source4/samba4-knownfail +++ b/source4/samba4-knownfail @@ -36,3 +36,4 @@ BASE-CHARSET.*.Testing partial surrogate RAP.*netservergetinfo kinit with pkinit # fails with: salt type 3 not supported samba4.blackbox.provision.py.reprovision # Fails with entry already exists +LOCAL-TORTURE.provision -- cgit From 56e75ed20cd71651f2c0fdc399389e2cd6471f3f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Feb 2008 15:53:06 +0100 Subject: Reconcile header files for torture utility functions. (This used to be commit 1269758e95686cc155284d5d56080e1be11bbd75) --- source4/torture/config.mk | 1 - source4/torture/libnet/libnet_BecomeDC.c | 2 +- source4/torture/local/torture.c | 2 +- source4/torture/util.h | 120 +++++++++++++++++++++++++++++++ source4/torture/util_provision.c | 2 +- source4/torture/util_provision.h | 51 ------------- 6 files changed, 123 insertions(+), 55 deletions(-) create mode 100644 source4/torture/util.h delete mode 100644 source4/torture/util_provision.h (limited to 'source4') diff --git a/source4/torture/config.mk b/source4/torture/config.mk index 5a3e3d0658..7ab4658dc1 100644 --- a/source4/torture/config.mk +++ b/source4/torture/config.mk @@ -16,7 +16,6 @@ PUBLIC_DEPENDENCIES = \ [SUBSYSTEM::TORTURE_UTIL] OBJ_FILES = util_smb.o util_provision.o PRIVATE_DEPENDENCIES = LIBCLI_RAW LIBPYTHON smbcalls -PUBLIC_PROTO_HEADER = util.h PUBLIC_DEPENDENCIES = POPT_CREDENTIALS ################################# diff --git a/source4/torture/libnet/libnet_BecomeDC.c b/source4/torture/libnet/libnet_BecomeDC.c index 13e1aec6d0..9566f5ee29 100644 --- a/source4/torture/libnet/libnet_BecomeDC.c +++ b/source4/torture/libnet/libnet_BecomeDC.c @@ -37,7 +37,7 @@ #include "lib/ldb_wrap.h" #include "auth/auth.h" #include "param/param.h" -#include "torture/util_provision.h" +#include "torture/util.h" struct test_become_dc_state { struct libnet_context *ctx; diff --git a/source4/torture/local/torture.c b/source4/torture/local/torture.c index 0c9931be03..3273015347 100644 --- a/source4/torture/local/torture.c +++ b/source4/torture/local/torture.c @@ -24,7 +24,7 @@ #include "system/wait.h" #include "lib/events/events.h" #include "libcli/raw/libcliraw.h" -#include "torture/util_provision.h" +#include "torture/util.h" static bool test_tempdir(struct torture_context *tctx) { diff --git a/source4/torture/util.h b/source4/torture/util.h new file mode 100644 index 0000000000..c5219a5aaa --- /dev/null +++ b/source4/torture/util.h @@ -0,0 +1,120 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2008 + + 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 . +*/ + +#ifndef _TORTURE_PROVISION_H_ +#define _TORTURE_PROVISION_H_ + +struct provision_settings { + const char *dns_name; + const char *site_name; + const char *root_dn_str; + const char *domain_dn_str; + const char *config_dn_str; + const char *schema_dn_str; + const struct GUID *invocation_id; + const char *netbios_name; + const char *realm; + const char *domain; + const struct GUID *ntds_guid; + const char *ntds_dn_str; + const char *machine_password; + const char *samdb_ldb; + const char *secrets_ldb; + const char *secrets_keytab; + const char *schemadn_ldb; + const char *configdn_ldb; + const char *domaindn_ldb; + const char *templates_ldb; + const char *dns_keytab; +}; + +NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, + struct provision_settings *settings); + + +/** + setup a directory ready for a test +*/ +_PUBLIC_ bool torture_setup_dir(struct smbcli_state *cli, const char *dname); +NTSTATUS create_directory_handle(struct smbcli_tree *tree, const char *dname, int *fnum); + +/** + sometimes we need a fairly complex file to work with, so we can test + all possible attributes. +*/ +_PUBLIC_ int create_complex_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, const char *fname); +int create_complex_dir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, const char *dname); +void *shm_setup(int size); + +/** + check that a wire string matches the flags specified + not 100% accurate, but close enough for testing +*/ +bool wire_bad_flags(struct smb_wire_string *str, int flags, + struct smbcli_transport *transport); +void dump_all_info(TALLOC_CTX *mem_ctx, union smb_fileinfo *finfo); +void torture_all_info(struct smbcli_tree *tree, const char *fname); +bool torture_set_file_attribute(struct smbcli_tree *tree, const char *fname, uint16_t attrib); +NTSTATUS torture_set_sparse(struct smbcli_tree *tree, int fnum); +NTSTATUS torture_check_ea(struct smbcli_state *cli, + const char *fname, const char *eaname, const char *value); +_PUBLIC_ bool torture_open_connection_share(TALLOC_CTX *mem_ctx, + struct smbcli_state **c, + struct torture_context *tctx, + const char *hostname, + const char *sharename, + struct event_context *ev); +_PUBLIC_ bool torture_get_conn_index(int conn_index, + TALLOC_CTX *mem_ctx, + struct torture_context *tctx, + char **host, char **share); +_PUBLIC_ bool torture_open_connection_ev(struct smbcli_state **c, + int conn_index, + struct torture_context *tctx, + struct event_context *ev); +_PUBLIC_ bool torture_open_connection(struct smbcli_state **c, struct torture_context *tctx, int conn_index); +_PUBLIC_ bool torture_close_connection(struct smbcli_state *c); +_PUBLIC_ bool check_error(const char *location, struct smbcli_state *c, + uint8_t eclass, uint32_t ecode, NTSTATUS nterr); +double torture_create_procs(struct torture_context *tctx, + bool (*fn)(struct torture_context *, struct smbcli_state *, int), bool *result); +_PUBLIC_ struct torture_test *torture_suite_add_smb_multi_test( + struct torture_suite *suite, + const char *name, + bool (*run) (struct torture_context *, + struct smbcli_state *, + int i)); +_PUBLIC_ struct torture_test *torture_suite_add_2smb_test( + struct torture_suite *suite, + const char *name, + bool (*run) (struct torture_context *, + struct smbcli_state *, + struct smbcli_state *)); +_PUBLIC_ struct torture_test *torture_suite_add_1smb_test( + struct torture_suite *suite, + const char *name, + bool (*run) (struct torture_context *, struct smbcli_state *)); +NTSTATUS torture_second_tcon(TALLOC_CTX *mem_ctx, + struct smbcli_session *session, + const char *sharename, + struct smbcli_tree **res); + + + +#endif /* _TORTURE_PROVISION_H_ */ diff --git a/source4/torture/util_provision.c b/source4/torture/util_provision.c index a5c564b05c..2a1e9256f5 100644 --- a/source4/torture/util_provision.c +++ b/source4/torture/util_provision.c @@ -24,7 +24,7 @@ #include "scripting/ejs/smbcalls.h" #include "auth/auth.h" #include "lib/ldb_wrap.h" -#include "torture/util_provision.h" +#include "torture/util.h" static EjsId eid; static int ejs_error; diff --git a/source4/torture/util_provision.h b/source4/torture/util_provision.h deleted file mode 100644 index 28467080b1..0000000000 --- a/source4/torture/util_provision.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Jelmer Vernooij 2008 - - 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 . -*/ - -#ifndef _TORTURE_PROVISION_H_ -#define _TORTURE_PROVISION_H_ - -struct provision_settings { - const char *dns_name; - const char *site_name; - const char *root_dn_str; - const char *domain_dn_str; - const char *config_dn_str; - const char *schema_dn_str; - const struct GUID *invocation_id; - const char *netbios_name; - const char *realm; - const char *domain; - const struct GUID *ntds_guid; - const char *ntds_dn_str; - const char *machine_password; - const char *samdb_ldb; - const char *secrets_ldb; - const char *secrets_keytab; - const char *schemadn_ldb; - const char *configdn_ldb; - const char *domaindn_ldb; - const char *templates_ldb; - const char *dns_keytab; -}; - -NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, - struct provision_settings *settings); - - -#endif /* _TORTURE_PROVISION_H_ */ -- cgit From 57e910668d70a266ddf3a1296625fec17661a882 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Feb 2008 16:06:57 +0100 Subject: Unconditionally run the python tests. (This used to be commit 0ab4428fce9f2b970dfbced3b5dfea7ec688760a) --- source4/selftest/samba4_tests.sh | 56 +++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'source4') diff --git a/source4/selftest/samba4_tests.sh b/source4/selftest/samba4_tests.sh index 79c5c3e994..60da70cc8f 100755 --- a/source4/selftest/samba4_tests.sh +++ b/source4/selftest/samba4_tests.sh @@ -306,33 +306,29 @@ then plantest "NSS-TEST using winbind" member $VALGRIND $samba4bindir/nsstest $samba4bindir/shared/libnss_winbind.so fi -# if python is available, run the python tests: -if test -f $samba4bindir/smbpython -then - PYTHON=bin/smbpython - SUBUNITRUN="$PYTHON ./scripting/bin/subunitrun" - plantest "ldb.python" none PYTHONPATH="$PYTHONPATH:lib/ldb/tests/python/" $SUBUNITRUN api - plantest "credentials.python" none PYTHONPATH="$PYTHONPATH:auth/credentials/tests" $SUBUNITRUN bindings - plantest "registry.python" none PYTHONPATH="$PYTHONPATH:lib/registry/tests/" $SUBUNITRUN bindings - plantest "tdb.python" none PYTHONPATH="$PYTHONPATH:lib/tdb/python/tests" $SUBUNITRUN simple - plantest "auth.python" none PYTHONPATH="$PYTHONPATH:auth/tests/" $SUBUNITRUN bindings - plantest "security.python" none PYTHONPATH="$PYTHONPATH:libcli/security/tests" $SUBUNITRUN bindings - plantest "param.python" none PYTHONPATH="$PYTHONPATH:param/tests" $SUBUNITRUN bindings - plantest "upgrade.python" none $SUBUNITRUN samba.tests.upgrade - plantest "samba.python" none $SUBUNITRUN samba.tests - plantest "provision.python" none $SUBUNITRUN samba.tests.provision - plantest "samba3.python" none $SUBUNITRUN samba.tests.samba3 - plantest "samr.python" dc $SUBUNITRUN samba.tests.dcerpc.sam - plantest "samdb.python" dc $SUBUNITRUN samba.tests.samdb - plantest "events.python" none PYTHONPATH="$PYTHONPATH:lib/events" $SUBUNITRUN tests - plantest "samba3sam.python" none PYTHONPATH="$PYTHONPATH:dsdb/samdb/ldb_modules/tests" $SUBUNITRUN samba3sam - plantest "rpcecho.python" dc $SUBUNITRUN samba.tests.dcerpc.rpcecho - plantest "winreg.python" dc $SUBUNITRUN samba.tests.dcerpc.registry - plantest "ldap.python" dc $PYTHON $samba4srcdir/lib/ldb/tests/python/ldap.py $CONFIGURATION \$SERVER -U\$USERNAME%\$PASSWORD -W \$DOMAIN - plantest "blackbox.samba3dump" none $PYTHON scripting/bin/samba3dump $samba4srcdir/../testdata/samba3 - rm -rf $PREFIX/upgrade - plantest "blackbox.upgrade" none $PYTHON setup/upgrade.py $CONFIGURATION --targetdir=$PREFIX/upgrade ../testdata/samba3 ../testdata/samba3/smb.conf - rm -rf $PREFIX/provision - mkdir $PREFIX/provision - plantest "blackbox.provision.py" none PYTHON="$PYTHON" $samba4srcdir/setup/tests/blackbox_provision.sh "$PREFIX/provision" "$CONFIGURATION" -fi +PYTHON=bin/smbpython +SUBUNITRUN="$PYTHON ./scripting/bin/subunitrun" +plantest "ldb.python" none PYTHONPATH="$PYTHONPATH:lib/ldb/tests/python/" $SUBUNITRUN api +plantest "credentials.python" none PYTHONPATH="$PYTHONPATH:auth/credentials/tests" $SUBUNITRUN bindings +plantest "registry.python" none PYTHONPATH="$PYTHONPATH:lib/registry/tests/" $SUBUNITRUN bindings +plantest "tdb.python" none PYTHONPATH="$PYTHONPATH:lib/tdb/python/tests" $SUBUNITRUN simple +plantest "auth.python" none PYTHONPATH="$PYTHONPATH:auth/tests/" $SUBUNITRUN bindings +plantest "security.python" none PYTHONPATH="$PYTHONPATH:libcli/security/tests" $SUBUNITRUN bindings +plantest "param.python" none PYTHONPATH="$PYTHONPATH:param/tests" $SUBUNITRUN bindings +plantest "upgrade.python" none $SUBUNITRUN samba.tests.upgrade +plantest "samba.python" none $SUBUNITRUN samba.tests +plantest "provision.python" none $SUBUNITRUN samba.tests.provision +plantest "samba3.python" none $SUBUNITRUN samba.tests.samba3 +plantest "samr.python" dc $SUBUNITRUN samba.tests.dcerpc.sam +plantest "samdb.python" dc $SUBUNITRUN samba.tests.samdb +plantest "events.python" none PYTHONPATH="$PYTHONPATH:lib/events" $SUBUNITRUN tests +plantest "samba3sam.python" none PYTHONPATH="$PYTHONPATH:dsdb/samdb/ldb_modules/tests" $SUBUNITRUN samba3sam +plantest "rpcecho.python" dc $SUBUNITRUN samba.tests.dcerpc.rpcecho +plantest "winreg.python" dc $SUBUNITRUN samba.tests.dcerpc.registry +plantest "ldap.python" dc $PYTHON $samba4srcdir/lib/ldb/tests/python/ldap.py $CONFIGURATION \$SERVER -U\$USERNAME%\$PASSWORD -W \$DOMAIN +plantest "blackbox.samba3dump" none $PYTHON scripting/bin/samba3dump $samba4srcdir/../testdata/samba3 +rm -rf $PREFIX/upgrade +plantest "blackbox.upgrade" none $PYTHON setup/upgrade.py $CONFIGURATION --targetdir=$PREFIX/upgrade ../testdata/samba3 ../testdata/samba3/smb.conf +rm -rf $PREFIX/provision +mkdir $PREFIX/provision +plantest "blackbox.provision.py" none PYTHON="$PYTHON" $samba4srcdir/setup/tests/blackbox_provision.sh "$PREFIX/provision" "$CONFIGURATION" -- cgit