mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
r11474: - enable ldb transactions from ejs
- speed up provisioning a bit using a ldb transaction (also means you
can't end up with a ldb being half done)
(This used to be commit 91dfe304cf
)
This commit is contained in:
parent
66d3ee9ccb
commit
c845ab1e60
@ -396,6 +396,84 @@ static int ejs_ldbClose(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
start a ldb transaction
|
||||
usage:
|
||||
ok = ldb.transaction_start();
|
||||
*/
|
||||
static int ejs_ldbTransactionStart(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
{
|
||||
struct ldb_context *ldb;
|
||||
int ret;
|
||||
|
||||
if (argc != 0) {
|
||||
ejsSetErrorMsg(eid, "ldb.transaction_start invalid arguments");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ldb = ejs_get_ldb_context(eid);
|
||||
if (ldb == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ldb_transaction_start(ldb);
|
||||
|
||||
mpr_Return(eid, mprCreateBoolVar(ret == 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
cancel a ldb transaction
|
||||
usage:
|
||||
ok = ldb.transaction_cancel();
|
||||
*/
|
||||
static int ejs_ldbTransactionCancel(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
{
|
||||
struct ldb_context *ldb;
|
||||
int ret;
|
||||
|
||||
if (argc != 0) {
|
||||
ejsSetErrorMsg(eid, "ldb.transaction_cancel invalid arguments");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ldb = ejs_get_ldb_context(eid);
|
||||
if (ldb == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ldb_transaction_cancel(ldb);
|
||||
|
||||
mpr_Return(eid, mprCreateBoolVar(ret == 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
commit a ldb transaction
|
||||
usage:
|
||||
ok = ldb.transaction_commit();
|
||||
*/
|
||||
static int ejs_ldbTransactionCommit(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
{
|
||||
struct ldb_context *ldb;
|
||||
int ret;
|
||||
|
||||
if (argc != 0) {
|
||||
ejsSetErrorMsg(eid, "ldb.transaction_commit invalid arguments");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ldb = ejs_get_ldb_context(eid);
|
||||
if (ldb == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ldb_transaction_commit(ldb);
|
||||
|
||||
mpr_Return(eid, mprCreateBoolVar(ret == 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
initialise ldb ejs subsystem
|
||||
*/
|
||||
@ -413,6 +491,9 @@ static int ejs_ldb_init(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
mprSetCFunction(ldb, "encode", ejs_base64encode);
|
||||
mprSetCFunction(ldb, "decode", ejs_base64decode);
|
||||
mprSetCFunction(ldb, "close", ejs_ldbClose);
|
||||
mprSetCFunction(ldb, "transaction_start", ejs_ldbTransactionStart);
|
||||
mprSetCFunction(ldb, "transaction_cancel", ejs_ldbTransactionCancel);
|
||||
mprSetCFunction(ldb, "transaction_commit", ejs_ldbTransactionCommit);
|
||||
mprSetVar(ldb, "SCOPE_BASE", mprCreateNumberVar(LDB_SCOPE_BASE));
|
||||
mprSetVar(ldb, "SCOPE_ONE", mprCreateNumberVar(LDB_SCOPE_ONELEVEL));
|
||||
mprSetVar(ldb, "SCOPE_SUBTREE", mprCreateNumberVar(LDB_SCOPE_SUBTREE));
|
||||
|
@ -128,9 +128,12 @@ function hostname()
|
||||
function ldb_delete(ldb)
|
||||
{
|
||||
println("Deleting " + ldb.filename);
|
||||
sys.unlink(ldb.filename);
|
||||
var lp = loadparm_init();
|
||||
sys.unlink(sprintf("%s/%s", lp.get("private dir"), ldb.filename));
|
||||
ldb.transaction_cancel();
|
||||
ldb.close();
|
||||
var ok = ldb.connect(ldb.filename);
|
||||
ldb.transaction_start();
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
@ -148,7 +151,7 @@ function ldb_erase(ldb)
|
||||
ldb.del("@MODULES");
|
||||
|
||||
/* and the rest */
|
||||
var res = ldb.search("(|(objectclass=*)(dn=*))", attrs);
|
||||
var res = ldb.search("(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", attrs);
|
||||
var i;
|
||||
if (typeof(res) == "undefined") {
|
||||
ldb_delete(ldb);
|
||||
@ -157,12 +160,13 @@ function ldb_erase(ldb)
|
||||
for (i=0;i<res.length;i++) {
|
||||
ldb.del(res[i].dn);
|
||||
}
|
||||
res = ldb.search("(|(objectclass=*)(dn=*))", attrs);
|
||||
var res = ldb.search("(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", attrs);
|
||||
if (res.length != 0) {
|
||||
ldb_delete(ldb);
|
||||
return;
|
||||
}
|
||||
assert(res.length == 0);
|
||||
ldb_delete(ldb);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -194,12 +198,15 @@ function setup_ldb(ldif, dbname, subobj)
|
||||
var connect_ok = ldb.connect(dbname);
|
||||
assert(connect_ok);
|
||||
|
||||
ldb.transaction_start();
|
||||
|
||||
if (erase) {
|
||||
ldb_erase(ldb);
|
||||
}
|
||||
|
||||
var add_ok = ldb.add(data);
|
||||
assert(add_ok);
|
||||
ldb.transaction_commit();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -279,6 +286,8 @@ function provision(subobj, message, blank, paths)
|
||||
setup_ldb("hklm.ldif", paths.hklm, subobj);
|
||||
message("Setting up sam.ldb attributes\n");
|
||||
setup_ldb("provision_init.ldif", paths.samdb, subobj);
|
||||
// message("Setting up sam.ldb objectclasses\n");
|
||||
// setup_ldb("schema_classes.ldif", paths.samdb, subobj, NULL, false);
|
||||
message("Setting up sam.ldb templates\n");
|
||||
setup_ldb("provision_templates.ldif", paths.samdb, subobj, NULL, false);
|
||||
message("Setting up sam.ldb data\n");
|
||||
@ -394,6 +403,8 @@ function newuser(username, unixname, password, message)
|
||||
var ok = ldb.connect(samdb);
|
||||
assert(ok);
|
||||
|
||||
ldb.transaction_start();
|
||||
|
||||
/* find the DNs for the domain and the domain users group */
|
||||
var domain_dn = searchone(ldb, "objectClass=domainDNS", "dn");
|
||||
assert(domain_dn != undefined);
|
||||
@ -451,7 +462,11 @@ member: %s
|
||||
/*
|
||||
modify the userAccountControl to remove the disabled bit
|
||||
*/
|
||||
return enable_account(ldb, user_dn);
|
||||
ok = enable_account(ldb, user_dn);
|
||||
if (ok) {
|
||||
ldb.transaction_commit();
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
// Check whether a name is valid as a NetBIOS name.
|
||||
|
Loading…
Reference in New Issue
Block a user