1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-26 10:04:02 +03:00

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)
This commit is contained in:
Stefan Metzmacher 2007-01-05 21:27:24 +00:00 committed by Gerald (Jerry) Carter
parent a95d58ae8f
commit 46908530bc
3 changed files with 153 additions and 12 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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;
}