summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-01-05 21:27:24 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:37:03 -0500
commit46908530bc39e0ba3742650639b35a6d0c32852b (patch)
tree10579634d026d9c04ccb5bcc434e4654812eb260 /source4
parenta95d58ae8f45089e74099f707450a73432792ed9 (diff)
downloadsamba-46908530bc39e0ba3742650639b35a6d0c32852b.tar.gz
samba-46908530bc39e0ba3742650639b35a6d0c32852b.tar.bz2
samba-46908530bc39e0ba3742650639b35a6d0c32852b.zip
r20572: - prepare a test_samdb.ldb in the NET-API-BECOME-DC torture test
- we call a ejs script from the torture test for this task so that we can use the provision template ldif's. metze (This used to be commit e84b0c7d4004df312ae58ed76dd708a2c3c37986)
Diffstat (limited to 'source4')
-rw-r--r--source4/scripting/libjs/provision.js59
-rw-r--r--source4/torture/config.mk1
-rw-r--r--source4/torture/libnet/libnet_BecomeDC.c105
3 files changed, 153 insertions, 12 deletions
diff --git a/source4/scripting/libjs/provision.js b/source4/scripting/libjs/provision.js
index 772505f569..1ef569c908 100644
--- a/source4/scripting/libjs/provision.js
+++ b/source4/scripting/libjs/provision.js
@@ -431,6 +431,50 @@ function setup_name_mappings(info, ldb)
return true;
}
+function provision_fix_subobj(subobj, message)
+{
+ subobj.REALM = strupper(subobj.REALM);
+ subobj.HOSTNAME = strlower(subobj.HOSTNAME);
+ subobj.DOMAIN = strupper(subobj.DOMAIN);
+ assert(valid_netbios_name(subobj.DOMAIN));
+ subobj.NETBIOSNAME = strupper(subobj.HOSTNAME);
+ assert(valid_netbios_name(subobj.NETBIOSNAME));
+ var rdns = split(",", subobj.DOMAINDN);
+ subobj.RDN_DC = substr(rdns[0], strlen("DC="));
+
+ return true;
+}
+
+function provision_become_dc(subobj, message, paths, session_info)
+{
+ var lp = loadparm_init();
+ var sys = sys_init();
+ var info = new Object();
+
+ var ok = provision_fix_subobj(subobj, message);
+ assert(ok);
+
+ info.subobj = subobj;
+ info.message = message;
+ info.session_info = session_info;
+
+ /* Also wipes the database */
+ message("Setting up " + paths.samdb + " partitions\n");
+ setup_ldb("provision_partitions.ldif", info, paths.samdb);
+
+ var samdb = open_ldb(info, paths.samdb, false);
+
+ message("Setting up " + paths.samdb + " attributes\n");
+ setup_add_ldif("provision_init.ldif", info, samdb, false);
+
+ message("Setting up " + paths.samdb + " rootDSE\n");
+ setup_add_ldif("provision_rootdse_add.ldif", info, samdb, false);
+
+ ok = samdb.transaction_commit();
+ assert(ok);
+
+ return true;
+}
/*
provision samba4 - caution, this wipes all existing data!
@@ -441,18 +485,9 @@ function provision(subobj, message, blank, paths, session_info, credentials, lda
var sys = sys_init();
var info = new Object();
- /*
- some options need to be upper/lower case
- */
- subobj.REALM = strupper(subobj.REALM);
- subobj.HOSTNAME = strlower(subobj.HOSTNAME);
- subobj.DOMAIN = strupper(subobj.DOMAIN);
- assert(valid_netbios_name(subobj.DOMAIN));
- subobj.NETBIOSNAME = strupper(subobj.HOSTNAME);
- assert(valid_netbios_name(subobj.NETBIOSNAME));
- var rdns = split(",", subobj.DOMAINDN);
- subobj.RDN_DC = substr(rdns[0], strlen("DC="));
-
+ var ok = provision_fix_subobj(subobj, message);
+ assert(ok);
+
if (subobj.DOMAINGUID != undefined) {
subobj.DOMAINGUID_MOD = sprintf("replace: objectGUID\nobjectGUID: %s\n-", subobj.DOMAINGUID);
} else {
diff --git a/source4/torture/config.mk b/source4/torture/config.mk
index cc05709377..de71747a9d 100644
--- a/source4/torture/config.mk
+++ b/source4/torture/config.mk
@@ -260,6 +260,7 @@ OBJ_FILES = \
libnet/libnet_BecomeDC.o
PUBLIC_DEPENDENCIES = \
LIBSAMBA-NET \
+ smbcalls \
POPT_CREDENTIALS
PRIVATE_DEPENDENCIES = torture_rpc
# End SUBSYSTEM TORTURE_NET
diff --git a/source4/torture/libnet/libnet_BecomeDC.c b/source4/torture/libnet/libnet_BecomeDC.c
index 2f8707892f..2fcec59fc8 100644
--- a/source4/torture/libnet/libnet_BecomeDC.c
+++ b/source4/torture/libnet/libnet_BecomeDC.c
@@ -36,6 +36,63 @@
#include "librpc/gen_ndr/ndr_misc.h"
#include "system/time.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;
+}
+
#define TORTURE_NETBIOS_NAME "smbtorturedc"
struct test_become_dc_state {
@@ -77,6 +134,8 @@ 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);
+ char *ejs;
+ int ret;
DEBUG(0,("New Server[%s] in Site[%s]\n",
p->dest_dsa->dns_name, p->dest_dsa->site_name));
@@ -97,6 +156,52 @@ static NTSTATUS test_become_dc_prepare_db(void *private_data,
DEBUG(0,("Domain Partition[%s]\n",
p->domain->dn_str));
+ 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 = \"test_domain.ldb\";\n"
+ "subobj.CONFIGDN = \"%s\";\n"
+ "subobj.CONFIGDN_LDB = \"test_config.ldb\";\n"
+ "subobj.SCHEMADN = \"%s\";\n"
+ "subobj.SCHEMADN_LDB = \"test_schema.ldb\";\n"
+ "subobj.HOSTNAME = \"%s\";\n"
+ "subobj.DNSNAME = \"%s\";\n"
+ "subobj.DEFAULTSITE = \"%s\";\n"
+ "\n"
+ "var paths = provision_default_paths(subobj);\n"
+ "paths.samdb = \"test_samdb.ldb\";\n"
+ "\n"
+ "var system_session = system_session();\n"
+ "\n"
+ "var ok = provision_become_dc(subobj, message, paths, system_session);\n"
+ "assert(ok);\n"
+ "\n"
+ "return 0;\n",
+ p->forest->root_dn_str,
+ p->domain->dn_str,
+ p->forest->config_dn_str,
+ p->forest->schema_dn_str,
+ p->dest_dsa->netbios_name,
+ p->dest_dsa->dns_name,
+ p->dest_dsa->site_name);
+ 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);
+
return NT_STATUS_OK;
}