summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2007-02-14 21:55:29 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:48:18 -0500
commit7ca399c0755e186508a4ed9796cbbbe6f50181e9 (patch)
tree50c7ce84b894bfdd46a773c16a890401afe751c1 /source4
parentbd7df755f326e9c601439c0aa727961c4a4f4518 (diff)
downloadsamba-7ca399c0755e186508a4ed9796cbbbe6f50181e9.tar.gz
samba-7ca399c0755e186508a4ed9796cbbbe6f50181e9.tar.bz2
samba-7ca399c0755e186508a4ed9796cbbbe6f50181e9.zip
r21351: Change ldb ejs bindings return codes.
We were returning just true/false and discarding error number and string. This checking probably breaks swat, will fix it in next round as swat is what made me look into this as I had no way to get back error messages to show to the users. Simo. (This used to be commit 35886b4ae68be475b0fc8b2689ca04d766661261)
Diffstat (limited to 'source4')
-rw-r--r--source4/scripting/ejs/mprutil.c31
-rw-r--r--source4/scripting/ejs/smbcalls.h1
-rw-r--r--source4/scripting/ejs/smbcalls_ldb.c10
-rw-r--r--source4/scripting/libjs/provision.js113
-rw-r--r--source4/setup/setpassword13
5 files changed, 94 insertions, 74 deletions
diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c
index cfed69dbe0..459f198dca 100644
--- a/source4/scripting/ejs/mprutil.c
+++ b/source4/scripting/ejs/mprutil.c
@@ -223,19 +223,32 @@ failed:
/*
- turn an array of ldb_messages into a ejs object variable
+ build a MprVar result object for ldb operations with lots of funky properties
*/
-struct MprVar mprLdbArray(struct ldb_context *ldb,
- struct ldb_message **msg, int count, const char *name)
+struct MprVar mprLdbResult(struct ldb_context *ldb, int err, struct ldb_result *result)
{
- struct MprVar res;
- int i;
+ struct MprVar ret;
+ struct MprVar ary;
+
+ ret = mprObject("ldbret");
+
+ mprSetVar(&ret, "error", mprCreateIntegerVar(err));
+ mprSetVar(&ret, "errstr", mprString(ldb_errstring(ldb)));
+
+ ary = mprArray("ldb_message");
+ if (result) {
+ int i;
- res = mprArray(name);
- for (i=0;i<count;i++) {
- mprAddArray(&res, i, mprLdbMessage(ldb, msg[i]));
+ for (i = 0; i < result->count; i++) {
+ mprAddArray(&ary, i, mprLdbMessage(ldb, result->msgs[i]));
+ }
}
- return res;
+
+ mprSetVar(&ret, "msgs", ary);
+
+ /* TODO: add referrals, exteded ops, and controls */
+
+ return ret;
}
diff --git a/source4/scripting/ejs/smbcalls.h b/source4/scripting/ejs/smbcalls.h
index 9fa9100276..a525403493 100644
--- a/source4/scripting/ejs/smbcalls.h
+++ b/source4/scripting/ejs/smbcalls.h
@@ -21,6 +21,7 @@
*/
#include "lib/appweb/ejs/ejs.h"
+#include "lib/ldb/include/ldb.h"
void mpr_Return(int eid, struct MprVar);
NTSTATUS mprSetVar(struct MprVar *v, const char *name, struct MprVar val);
diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c
index 3c368bba4f..fc44862985 100644
--- a/source4/scripting/ejs/smbcalls_ldb.c
+++ b/source4/scripting/ejs/smbcalls_ldb.c
@@ -108,9 +108,9 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv)
ret = ldb_search(ldb, basedn, scope, expression, attrs, &res);
if (ret != LDB_SUCCESS) {
ejsSetErrorMsg(eid, "ldb.search failed - %s", ldb_errstring(ldb));
- mpr_Return(eid, mprCreateUndefinedVar());
+ mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
} else {
- mpr_Return(eid, mprLdbArray(ldb, res->msgs, res->count, "ldb_message"));
+ mpr_Return(eid, mprLdbResult(ldb, ret, res));
talloc_free(res);
}
talloc_free(tmp_ctx);
@@ -161,7 +161,7 @@ static int ejs_ldbAddModify(MprVarHandle eid, int argc, struct MprVar **argv,
return -1;
}
- mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
return 0;
}
@@ -197,7 +197,7 @@ static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
talloc_free(dn);
- mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
return 0;
}
@@ -234,7 +234,7 @@ static int ejs_ldbRename(MprVarHandle eid, int argc, struct MprVar **argv)
talloc_free(dn1);
talloc_free(dn2);
- mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
return 0;
}
diff --git a/source4/scripting/libjs/provision.js b/source4/scripting/libjs/provision.js
index 9f24b5e48b..b50e9b5bcf 100644
--- a/source4/scripting/libjs/provision.js
+++ b/source4/scripting/libjs/provision.js
@@ -23,7 +23,7 @@ function install_ok(session_info, credentials)
return false;
}
var res = ldb.search("(cn=Administrator)");
- if (res.length != 1) {
+ if (res.error != 0 || res.msgs.length != 1) {
return false;
}
return true;
@@ -72,7 +72,7 @@ function setup_name_mapping(info, ldb, sid, unixname)
var attrs = new Array("dn");
var res = ldb.search(sprintf("objectSid=%s", sid),
info.subobj.DOMAINDN, ldb.SCOPE_SUBTREE, attrs);
- if (res.length != 1) {
+ if (res.error != 0 || res.msgs.length != 1) {
info.message("Failed to find record for objectSid %s\n", sid);
return false;
}
@@ -82,9 +82,9 @@ changetype: modify
replace: unixName
unixName: %s
",
- res[0].dn, unixname);
+ res.msgs[0].dn, unixname);
var ok = ldb.modify(mod);
- if (!ok) {
+ if (ok.error != 0) {
info.message("name mapping for %s failed - %s\n",
sid, ldb.errstring());
return false;
@@ -172,20 +172,20 @@ function ldb_erase(ldb)
var basedn = "";
var res = ldb.search("(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs);
var i;
- if (typeof(res) == "undefined") {
+ if (res.error != 0) {
ldb_delete(ldb);
return;
}
- for (i=0;i<res.length;i++) {
+ for (i=0;i<res.msgs.length;i++) {
ldb.del(res[i].dn);
}
var res = ldb.search("(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs);
- if (res.length != 0) {
+ if (res.error != 0 || res.msgs.length != 0) {
ldb_delete(ldb);
return;
}
- assert(res.length == 0);
+ assert(res.msgs.length == 0);
}
/*
@@ -198,15 +198,15 @@ function ldb_erase_partitions(info, ldb, ldapbackend)
var j;
var res = ldb.search("(objectClass=*)", "", ldb.SCOPE_BASE, rootDSE_attrs);
- assert(typeof(res) != "undefined");
- assert(res.length == 1);
- if (typeof(res[0].namingContexts) == "undefined") {
+ assert(res.error == 0);
+ assert(res.msgs.length == 1);
+ if (typeof(res.msgs[0].namingContexts) == "undefined") {
return;
}
- for (j=0; j<res[0].namingContexts.length; j++) {
+ for (j=0; j<res.msgs[0].namingContexts.length; j++) {
var anything = "(|(objectclass=*)(dn=*))";
var attrs = new Array("dn");
- var basedn = res[0].namingContexts[j];
+ var basedn = res.msgs[0].namingContexts[j];
var k;
var previous_remaining = 1;
var current_remaining = 0;
@@ -220,23 +220,23 @@ function ldb_erase_partitions(info, ldb, ldapbackend)
/* and the rest */
var res2 = ldb.search(anything, basedn, ldb.SCOPE_SUBTREE, attrs);
var i;
- if (typeof(res2) == "undefined") {
- info.message("ldb search failed: " + ldb.errstring() + "\n");
+ if (res2.error != 0) {
+ info.message("ldb search failed: " + res.errstr + "\n");
continue;
}
previous_remaining = current_remaining;
- current_remaining = res2.length;
- for (i=0;i<res2.length;i++) {
- ldb.del(res2[i].dn);
+ current_remaining = res2.msgs.length;
+ for (i=0;i<res2.msgs.length;i++) {
+ ldb.del(res2.msgs[i].dn);
}
var res3 = ldb.search(anything, basedn, ldb.SCOPE_SUBTREE, attrs);
- if (typeof(res3) == "undefined") {
- info.message("ldb search failed: " + ldb.errstring() + "\n");
+ if (res3.error != 0) {
+ info.message("ldb search failed: " + res.errstr + "\n");
continue;
}
- if (res3.length != 0) {
- info.message("Failed to delete all records under " + basedn + ", " + res3.length + " records remaining\n");
+ if (res3.msgs.length != 0) {
+ info.message("Failed to delete all records under " + basedn + ", " + res3.msgs.length + " records remaining\n");
}
}
}
@@ -277,14 +277,14 @@ function setup_add_ldif(ldif, info, ldb, failok)
var data = sys.file_load(src);
data = substitute_var(data, info.subobj);
- var add_ok = ldb.add(data);
- if (!add_ok) {
- info.message("ldb load failed: " + ldb.errstring() + "\n");
+ var add_res = ldb.add(data);
+ if (add_res.error != 0) {
+ info.message("ldb load failed: " + add_res.errstr + "\n");
if (!failok) {
- assert(add_ok);
+ assert(add_res.error == 0);
}
}
- return add_ok;
+ return (add_res.error == 0);
}
function setup_modify_ldif(ldif, info, ldb, failok)
@@ -295,14 +295,14 @@ function setup_modify_ldif(ldif, info, ldb, failok)
var data = sys.file_load(src);
data = substitute_var(data, info.subobj);
- var mod_ok = ldb.modify(data);
- if (!mod_ok) {
- info.message("ldb load failed: " + ldb.errstring() + "\n");
+ var mod_res = ldb.modify(data);
+ if (mod_res.error != 0) {
+ info.message("ldb load failed: " + mod_res.errstr + "\n");
if (!failok) {
- assert(mod_ok);
+ assert(mod_res.error == 0);
}
}
- return mod_ok;
+ return (mod_res.error == 0);
}
@@ -339,12 +339,12 @@ function setup_ldb_modify(ldif, info, ldb)
var data = sys.file_load(src);
data = substitute_var(data, info.subobj);
- var mod_ok = ldb.modify(data);
- if (!mod_ok) {
- info.message("ldb load failed: " + ldb.errstring() + "\n");
- return mod_ok;
+ var mod_res = ldb.modify(data);
+ if (mod_res.error != 0) {
+ info.message("ldb load failed: " + mod_res.errstr + "\n");
+ return (mod_res.error == 0);
}
- return mod_ok;
+ return (mod_res.error == 0);
}
/*
@@ -400,8 +400,9 @@ function setup_name_mappings(info, ldb)
var subobj = info.subobj;
res = ldb.search("objectSid=*", subobj.DOMAINDN, ldb.SCOPE_BASE, attrs);
- assert(res.length == 1 && res[0].objectSid != undefined);
- var sid = res[0].objectSid;
+ assert(res.error == 0);
+ assert(res.msgs.length == 1 && res.msgs[0].objectSid != undefined);
+ var sid = res.msgs[0].objectSid;
/* add some foreign sids if they are not present already */
add_foreign(ldb, subobj, "S-1-5-7", "Anonymous");
@@ -687,9 +688,10 @@ function provision_dns(subobj, message, paths, session_info, credentials)
var attrs = new Array("objectGUID");
res = ldb.search("objectGUID=*", subobj.DOMAINDN, ldb.SCOPE_BASE, attrs);
- assert(res.length == 1);
- assert(res[0].objectGUID != undefined);
- subobj.DOMAINGUID = res[0].objectGUID;
+ assert(res.error == 0);
+ assert(res.msgs.length == 1);
+ assert(res.msgs[0].objectGUID != undefined);
+ subobj.DOMAINGUID = res.msgs[0].objectGUID;
subobj.HOSTGUID = searchone(ldb, subobj.DOMAINDN, "(&(objectClass=computer)(cn=" + subobj.NETBIOSNAME + "))", "objectGUID");
assert(subobj.HOSTGUID != undefined);
@@ -808,11 +810,12 @@ function searchone(ldb, basedn, expression, attribute)
{
var attrs = new Array(attribute);
res = ldb.search(expression, basedn, ldb.SCOPE_SUBTREE, attrs);
- if (res.length != 1 ||
- res[0][attribute] == undefined) {
+ if (res.error != 0 ||
+ res.msgs.length != 1 ||
+ res.msgs[0][attribute] == undefined) {
return undefined;
}
- return res[0][attribute];
+ return res.msgs[0][attribute];
}
/*
@@ -822,8 +825,9 @@ function enable_account(ldb, user_dn)
{
var attrs = new Array("userAccountControl");
var res = ldb.search(NULL, user_dn, ldb.SCOPE_ONELEVEL, attrs);
- assert(res.length == 1);
- var userAccountControl = res[0].userAccountControl;
+ assert(res.error == 0);
+ assert(res.msgs.length == 1);
+ var userAccountControl = res.msgs[0].userAccountControl;
userAccountControl = userAccountControl - 2; /* remove disabled bit */
var mod = sprintf("
dn: %s
@@ -833,7 +837,7 @@ userAccountControl: %u
",
user_dn, userAccountControl);
var ok = ldb.modify(mod);
- return ok;
+ return (ok.error == 0);
}
@@ -858,8 +862,9 @@ function newuser(username, unixname, password, message, session_info, credential
/* find the DNs for the domain and the domain users group */
var attrs = new Array("defaultNamingContext");
res = ldb.search("defaultNamingContext=*", "", ldb.SCOPE_BASE, attrs);
- assert(res.length == 1 && res[0].defaultNamingContext != undefined);
- var domain_dn = res[0].defaultNamingContext;
+ assert(res.error == 0);
+ assert(res.msgs.length == 1 && res.msgs[0].defaultNamingContext != undefined);
+ var domain_dn = res.msgs[0].defaultNamingContext;
assert(domain_dn != undefined);
var dom_users = searchone(ldb, domain_dn, "name=Domain Users", "dn");
assert(dom_users != undefined);
@@ -898,15 +903,15 @@ member: %s
*/
message("Adding user %s\n", user_dn);
ok = ldb.add(ldif);
- if (ok != true) {
- message("Failed to add %s - %s\n", user_dn, ldb.errstring());
+ if (ok.error != 0) {
+ message("Failed to add %s - %s\n", user_dn, ok.errstr);
return false;
}
message("Modifying group %s\n", dom_users);
ok = ldb.modify(modgroup);
- if (ok != true) {
- message("Failed to modify %s - %s\n", dom_users, ldb.errstring());
+ if (ok.error != 0) {
+ message("Failed to modify %s - %s\n", dom_users, ok.errstr);
return false;
}
diff --git a/source4/setup/setpassword b/source4/setup/setpassword
index c3357a3cdd..618e304077 100644
--- a/source4/setup/setpassword
+++ b/source4/setup/setpassword
@@ -78,21 +78,22 @@ if (options['newpassword'] == undefined) {
var attrs = new Array("defaultNamingContext");
var attrs2 = new Array("cn");
res = ldb.search("defaultNamingContext=*", "", ldb.SCOPE_BASE, attrs);
-assert(res.length == 1 && res[0].defaultNamingContext != undefined);
-var domain_dn = res[0].defaultNamingContext;
+assert(res.error == 0);
+assert(res.msgs.length == 1 && res.msgs[0].defaultNamingContext != undefined);
+var domain_dn = res.msgs[0].defaultNamingContext;
assert(domain_dn != undefined);
if (options['filter'] != undefined) {
var res = ldb.search(options['filter'],
domain_dn, ldb.SCOPE_SUBTREE, attrs2);
- if (res.length != 1) {
+ if (res.error != 0 || res.msgs.length != 1) {
message("Failed to find record for filter %s\n", options['filter']);
exit(1);
}
} else {
var res = ldb.search(sprintf("samAccountName=%s", options['username']),
domain_dn, ldb.SCOPE_SUBTREE, attrs2);
- if (res.length != 1) {
+ if (res.error != 0 || res.msgs.length != 1) {
message("Failed to find record for user %s\n", options['username']);
exit(1);
}
@@ -106,9 +107,9 @@ sambaPassword: %s
",
res[0].dn, options['newpassword']);
var ok = ldb.modify(mod);
-if (!ok) {
+if (ok.error != 0) {
message("set password for %s failed - %s\n",
- res[0].dn, ldb.errstring());
+ res[0].dn, ok.errstr);
ldb.transaction_cancel();
exit(1);
} else {