1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-27 14:04:05 +03:00

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)
This commit is contained in:
Simo Sorce 2007-02-14 21:55:29 +00:00 committed by Gerald (Jerry) Carter
parent bd7df755f3
commit 7ca399c075
9 changed files with 942 additions and 883 deletions

View File

@ -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 MprVar mprLdbResult(struct ldb_context *ldb, int err, struct ldb_result *result)
struct ldb_message **msg, int count, const char *name)
{ {
struct MprVar res; struct MprVar ret;
int i; struct MprVar ary;
res = mprArray(name); ret = mprObject("ldbret");
for (i=0;i<count;i++) {
mprAddArray(&res, i, mprLdbMessage(ldb, msg[i])); mprSetVar(&ret, "error", mprCreateIntegerVar(err));
mprSetVar(&ret, "errstr", mprString(ldb_errstring(ldb)));
ary = mprArray("ldb_message");
if (result) {
int 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;
} }

View File

@ -21,6 +21,7 @@
*/ */
#include "lib/appweb/ejs/ejs.h" #include "lib/appweb/ejs/ejs.h"
#include "lib/ldb/include/ldb.h"
void mpr_Return(int eid, struct MprVar); void mpr_Return(int eid, struct MprVar);
NTSTATUS mprSetVar(struct MprVar *v, const char *name, struct MprVar val); NTSTATUS mprSetVar(struct MprVar *v, const char *name, struct MprVar val);

View File

@ -108,9 +108,9 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv)
ret = ldb_search(ldb, basedn, scope, expression, attrs, &res); ret = ldb_search(ldb, basedn, scope, expression, attrs, &res);
if (ret != LDB_SUCCESS) { if (ret != LDB_SUCCESS) {
ejsSetErrorMsg(eid, "ldb.search failed - %s", ldb_errstring(ldb)); ejsSetErrorMsg(eid, "ldb.search failed - %s", ldb_errstring(ldb));
mpr_Return(eid, mprCreateUndefinedVar()); mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
} else { } else {
mpr_Return(eid, mprLdbArray(ldb, res->msgs, res->count, "ldb_message")); mpr_Return(eid, mprLdbResult(ldb, ret, res));
talloc_free(res); talloc_free(res);
} }
talloc_free(tmp_ctx); talloc_free(tmp_ctx);
@ -161,7 +161,7 @@ static int ejs_ldbAddModify(MprVarHandle eid, int argc, struct MprVar **argv,
return -1; return -1;
} }
mpr_Return(eid, mprCreateBoolVar(ret == 0)); mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
return 0; return 0;
} }
@ -197,7 +197,7 @@ static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
talloc_free(dn); talloc_free(dn);
mpr_Return(eid, mprCreateBoolVar(ret == 0)); mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
return 0; return 0;
} }
@ -234,7 +234,7 @@ static int ejs_ldbRename(MprVarHandle eid, int argc, struct MprVar **argv)
talloc_free(dn1); talloc_free(dn1);
talloc_free(dn2); talloc_free(dn2);
mpr_Return(eid, mprCreateBoolVar(ret == 0)); mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
return 0; return 0;
} }

View File

@ -23,7 +23,7 @@ function install_ok(session_info, credentials)
return false; return false;
} }
var res = ldb.search("(cn=Administrator)"); var res = ldb.search("(cn=Administrator)");
if (res.length != 1) { if (res.error != 0 || res.msgs.length != 1) {
return false; return false;
} }
return true; return true;
@ -72,7 +72,7 @@ function setup_name_mapping(info, ldb, sid, unixname)
var attrs = new Array("dn"); var attrs = new Array("dn");
var res = ldb.search(sprintf("objectSid=%s", sid), var res = ldb.search(sprintf("objectSid=%s", sid),
info.subobj.DOMAINDN, ldb.SCOPE_SUBTREE, attrs); 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); info.message("Failed to find record for objectSid %s\n", sid);
return false; return false;
} }
@ -82,9 +82,9 @@ changetype: modify
replace: unixName replace: unixName
unixName: %s unixName: %s
", ",
res[0].dn, unixname); res.msgs[0].dn, unixname);
var ok = ldb.modify(mod); var ok = ldb.modify(mod);
if (!ok) { if (ok.error != 0) {
info.message("name mapping for %s failed - %s\n", info.message("name mapping for %s failed - %s\n",
sid, ldb.errstring()); sid, ldb.errstring());
return false; return false;
@ -172,20 +172,20 @@ function ldb_erase(ldb)
var basedn = ""; var basedn = "";
var res = ldb.search("(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs); var res = ldb.search("(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs);
var i; var i;
if (typeof(res) == "undefined") { if (res.error != 0) {
ldb_delete(ldb); ldb_delete(ldb);
return; return;
} }
for (i=0;i<res.length;i++) { for (i=0;i<res.msgs.length;i++) {
ldb.del(res[i].dn); ldb.del(res[i].dn);
} }
var res = ldb.search("(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs); 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); ldb_delete(ldb);
return; return;
} }
assert(res.length == 0); assert(res.msgs.length == 0);
} }
/* /*
@ -198,15 +198,15 @@ function ldb_erase_partitions(info, ldb, ldapbackend)
var j; var j;
var res = ldb.search("(objectClass=*)", "", ldb.SCOPE_BASE, rootDSE_attrs); var res = ldb.search("(objectClass=*)", "", ldb.SCOPE_BASE, rootDSE_attrs);
assert(typeof(res) != "undefined"); assert(res.error == 0);
assert(res.length == 1); assert(res.msgs.length == 1);
if (typeof(res[0].namingContexts) == "undefined") { if (typeof(res.msgs[0].namingContexts) == "undefined") {
return; 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 anything = "(|(objectclass=*)(dn=*))";
var attrs = new Array("dn"); var attrs = new Array("dn");
var basedn = res[0].namingContexts[j]; var basedn = res.msgs[0].namingContexts[j];
var k; var k;
var previous_remaining = 1; var previous_remaining = 1;
var current_remaining = 0; var current_remaining = 0;
@ -220,23 +220,23 @@ function ldb_erase_partitions(info, ldb, ldapbackend)
/* and the rest */ /* and the rest */
var res2 = ldb.search(anything, basedn, ldb.SCOPE_SUBTREE, attrs); var res2 = ldb.search(anything, basedn, ldb.SCOPE_SUBTREE, attrs);
var i; var i;
if (typeof(res2) == "undefined") { if (res2.error != 0) {
info.message("ldb search failed: " + ldb.errstring() + "\n"); info.message("ldb search failed: " + res.errstr + "\n");
continue; continue;
} }
previous_remaining = current_remaining; previous_remaining = current_remaining;
current_remaining = res2.length; current_remaining = res2.msgs.length;
for (i=0;i<res2.length;i++) { for (i=0;i<res2.msgs.length;i++) {
ldb.del(res2[i].dn); ldb.del(res2.msgs[i].dn);
} }
var res3 = ldb.search(anything, basedn, ldb.SCOPE_SUBTREE, attrs); var res3 = ldb.search(anything, basedn, ldb.SCOPE_SUBTREE, attrs);
if (typeof(res3) == "undefined") { if (res3.error != 0) {
info.message("ldb search failed: " + ldb.errstring() + "\n"); info.message("ldb search failed: " + res.errstr + "\n");
continue; continue;
} }
if (res3.length != 0) { if (res3.msgs.length != 0) {
info.message("Failed to delete all records under " + basedn + ", " + res3.length + " records remaining\n"); 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); var data = sys.file_load(src);
data = substitute_var(data, info.subobj); data = substitute_var(data, info.subobj);
var add_ok = ldb.add(data); var add_res = ldb.add(data);
if (!add_ok) { if (add_res.error != 0) {
info.message("ldb load failed: " + ldb.errstring() + "\n"); info.message("ldb load failed: " + add_res.errstr + "\n");
if (!failok) { 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) 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); var data = sys.file_load(src);
data = substitute_var(data, info.subobj); data = substitute_var(data, info.subobj);
var mod_ok = ldb.modify(data); var mod_res = ldb.modify(data);
if (!mod_ok) { if (mod_res.error != 0) {
info.message("ldb load failed: " + ldb.errstring() + "\n"); info.message("ldb load failed: " + mod_res.errstr + "\n");
if (!failok) { 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); var data = sys.file_load(src);
data = substitute_var(data, info.subobj); data = substitute_var(data, info.subobj);
var mod_ok = ldb.modify(data); var mod_res = ldb.modify(data);
if (!mod_ok) { if (mod_res.error != 0) {
info.message("ldb load failed: " + ldb.errstring() + "\n"); info.message("ldb load failed: " + mod_res.errstr + "\n");
return mod_ok; 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; var subobj = info.subobj;
res = ldb.search("objectSid=*", subobj.DOMAINDN, ldb.SCOPE_BASE, attrs); res = ldb.search("objectSid=*", subobj.DOMAINDN, ldb.SCOPE_BASE, attrs);
assert(res.length == 1 && res[0].objectSid != undefined); assert(res.error == 0);
var sid = res[0].objectSid; 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 some foreign sids if they are not present already */
add_foreign(ldb, subobj, "S-1-5-7", "Anonymous"); 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"); var attrs = new Array("objectGUID");
res = ldb.search("objectGUID=*", subobj.DOMAINDN, ldb.SCOPE_BASE, attrs); res = ldb.search("objectGUID=*", subobj.DOMAINDN, ldb.SCOPE_BASE, attrs);
assert(res.length == 1); assert(res.error == 0);
assert(res[0].objectGUID != undefined); assert(res.msgs.length == 1);
subobj.DOMAINGUID = res[0].objectGUID; assert(res.msgs[0].objectGUID != undefined);
subobj.DOMAINGUID = res.msgs[0].objectGUID;
subobj.HOSTGUID = searchone(ldb, subobj.DOMAINDN, "(&(objectClass=computer)(cn=" + subobj.NETBIOSNAME + "))", "objectGUID"); subobj.HOSTGUID = searchone(ldb, subobj.DOMAINDN, "(&(objectClass=computer)(cn=" + subobj.NETBIOSNAME + "))", "objectGUID");
assert(subobj.HOSTGUID != undefined); assert(subobj.HOSTGUID != undefined);
@ -808,11 +810,12 @@ function searchone(ldb, basedn, expression, attribute)
{ {
var attrs = new Array(attribute); var attrs = new Array(attribute);
res = ldb.search(expression, basedn, ldb.SCOPE_SUBTREE, attrs); res = ldb.search(expression, basedn, ldb.SCOPE_SUBTREE, attrs);
if (res.length != 1 || if (res.error != 0 ||
res[0][attribute] == undefined) { res.msgs.length != 1 ||
res.msgs[0][attribute] == undefined) {
return 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 attrs = new Array("userAccountControl");
var res = ldb.search(NULL, user_dn, ldb.SCOPE_ONELEVEL, attrs); var res = ldb.search(NULL, user_dn, ldb.SCOPE_ONELEVEL, attrs);
assert(res.length == 1); assert(res.error == 0);
var userAccountControl = res[0].userAccountControl; assert(res.msgs.length == 1);
var userAccountControl = res.msgs[0].userAccountControl;
userAccountControl = userAccountControl - 2; /* remove disabled bit */ userAccountControl = userAccountControl - 2; /* remove disabled bit */
var mod = sprintf(" var mod = sprintf("
dn: %s dn: %s
@ -833,7 +837,7 @@ userAccountControl: %u
", ",
user_dn, userAccountControl); user_dn, userAccountControl);
var ok = ldb.modify(mod); 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 */ /* find the DNs for the domain and the domain users group */
var attrs = new Array("defaultNamingContext"); var attrs = new Array("defaultNamingContext");
res = ldb.search("defaultNamingContext=*", "", ldb.SCOPE_BASE, attrs); res = ldb.search("defaultNamingContext=*", "", ldb.SCOPE_BASE, attrs);
assert(res.length == 1 && res[0].defaultNamingContext != undefined); assert(res.error == 0);
var domain_dn = res[0].defaultNamingContext; assert(res.msgs.length == 1 && res.msgs[0].defaultNamingContext != undefined);
var domain_dn = res.msgs[0].defaultNamingContext;
assert(domain_dn != undefined); assert(domain_dn != undefined);
var dom_users = searchone(ldb, domain_dn, "name=Domain Users", "dn"); var dom_users = searchone(ldb, domain_dn, "name=Domain Users", "dn");
assert(dom_users != undefined); assert(dom_users != undefined);
@ -898,15 +903,15 @@ member: %s
*/ */
message("Adding user %s\n", user_dn); message("Adding user %s\n", user_dn);
ok = ldb.add(ldif); ok = ldb.add(ldif);
if (ok != true) { if (ok.error != 0) {
message("Failed to add %s - %s\n", user_dn, ldb.errstring()); message("Failed to add %s - %s\n", user_dn, ok.errstr);
return false; return false;
} }
message("Modifying group %s\n", dom_users); message("Modifying group %s\n", dom_users);
ok = ldb.modify(modgroup); ok = ldb.modify(modgroup);
if (ok != true) { if (ok.error != 0) {
message("Failed to modify %s - %s\n", dom_users, ldb.errstring()); message("Failed to modify %s - %s\n", dom_users, ok.errstr);
return false; return false;
} }

View File

@ -78,21 +78,22 @@ if (options['newpassword'] == undefined) {
var attrs = new Array("defaultNamingContext"); var attrs = new Array("defaultNamingContext");
var attrs2 = new Array("cn"); var attrs2 = new Array("cn");
res = ldb.search("defaultNamingContext=*", "", ldb.SCOPE_BASE, attrs); res = ldb.search("defaultNamingContext=*", "", ldb.SCOPE_BASE, attrs);
assert(res.length == 1 && res[0].defaultNamingContext != undefined); assert(res.error == 0);
var domain_dn = res[0].defaultNamingContext; assert(res.msgs.length == 1 && res.msgs[0].defaultNamingContext != undefined);
var domain_dn = res.msgs[0].defaultNamingContext;
assert(domain_dn != undefined); assert(domain_dn != undefined);
if (options['filter'] != undefined) { if (options['filter'] != undefined) {
var res = ldb.search(options['filter'], var res = ldb.search(options['filter'],
domain_dn, ldb.SCOPE_SUBTREE, attrs2); 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']); message("Failed to find record for filter %s\n", options['filter']);
exit(1); exit(1);
} }
} else { } else {
var res = ldb.search(sprintf("samAccountName=%s", options['username']), var res = ldb.search(sprintf("samAccountName=%s", options['username']),
domain_dn, ldb.SCOPE_SUBTREE, attrs2); 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']); message("Failed to find record for user %s\n", options['username']);
exit(1); exit(1);
} }
@ -106,9 +107,9 @@ sambaPassword: %s
", ",
res[0].dn, options['newpassword']); res[0].dn, options['newpassword']);
var ok = ldb.modify(mod); var ok = ldb.modify(mod);
if (!ok) { if (ok.error != 0) {
message("set password for %s failed - %s\n", message("set password for %s failed - %s\n",
res[0].dn, ldb.errstring()); res[0].dn, ok.errstr);
ldb.transaction_cancel(); ldb.transaction_cancel();
exit(1); exit(1);
} else { } else {

View File

@ -37,11 +37,11 @@ objectClass: user
objectClass: person objectClass: person
cn: LDAPtestUSER cn: LDAPtestUSER
"); ");
if (!ok) { if (ok.error != 0) {
ok = ldb.del("cn=ldaptestuser,cn=users," + base_dn); ok = ldb.del("cn=ldaptestuser,cn=users," + base_dn);
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
ok = ldb.add(" ok = ldb.add("
dn: cn=ldaptestuser,cn=users," + base_dn + " dn: cn=ldaptestuser,cn=users," + base_dn + "
@ -49,9 +49,9 @@ objectClass: user
objectClass: person objectClass: person
cn: LDAPtestUSER cn: LDAPtestUSER
"); ");
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
} }
@ -60,20 +60,20 @@ dn: cn=ldaptestcomputer,cn=computers," + base_dn + "
objectClass: computer objectClass: computer
cn: LDAPtestCOMPUTER cn: LDAPtestCOMPUTER
"); ");
if (!ok) { if (ok.error != 0) {
ok = ldb.del("cn=ldaptestcomputer,cn=computers," + base_dn); ok = ldb.del("cn=ldaptestcomputer,cn=computers," + base_dn);
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
ok = ldb.add(" ok = ldb.add("
dn: cn=ldaptestcomputer,cn=computers," + base_dn + " dn: cn=ldaptestcomputer,cn=computers," + base_dn + "
objectClass: computer objectClass: computer
cn: LDAPtestCOMPUTER cn: LDAPtestCOMPUTER
"); ");
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
} }
@ -83,11 +83,11 @@ objectClass: computer
cn: LDAPtest2COMPUTER cn: LDAPtest2COMPUTER
userAccountControl: 4096 userAccountControl: 4096
"); ");
if (!ok) { if (ok.error != 0) {
ok = ldb.del("cn=ldaptest2computer,cn=computers," + base_dn); ok = ldb.del("cn=ldaptest2computer,cn=computers," + base_dn);
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
ok = ldb.add(" ok = ldb.add("
dn: cn=ldaptest2computer,cn=computers," + base_dn + " dn: cn=ldaptest2computer,cn=computers," + base_dn + "
@ -95,9 +95,9 @@ objectClass: computer
cn: LDAPtest2COMPUTER cn: LDAPtest2COMPUTER
userAccountControl: 4096 userAccountControl: 4096
"); ");
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
} }
@ -107,11 +107,11 @@ objectClass: person
objectClass: user objectClass: user
cn: LDAPtestUSER2 cn: LDAPtestUSER2
"); ");
if (!ok) { if (ok.error != 0) {
ok = ldb.del("cn=ldaptestuser2,cn=users," + base_dn); ok = ldb.del("cn=ldaptestuser2,cn=users," + base_dn);
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
ok = ldb.add(" ok = ldb.add("
dn: cn=ldaptestuser2,cn=users," + base_dn + " dn: cn=ldaptestuser2,cn=users," + base_dn + "
@ -119,9 +119,9 @@ objectClass: person
objectClass: user objectClass: user
cn: LDAPtestUSER2 cn: LDAPtestUSER2
"); ");
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
} }
@ -129,19 +129,19 @@ cn: LDAPtestUSER2
dn: cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn + " dn: cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn + "
objectClass: user objectClass: user
"); ");
if (!ok) { if (ok.error != 0) {
ok = ldb.del("cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn); ok = ldb.del("cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn);
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
ok = ldb.add(" ok = ldb.add("
dn: cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn + " dn: cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn + "
objectClass: user objectClass: user
"); ");
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
} }
@ -149,276 +149,296 @@ objectClass: user
dn: cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn + " dn: cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn + "
objectClass: user objectClass: user
"); ");
if (!ok) { if (ok.error != 0) {
ok = ldb.del("cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn); ok = ldb.del("cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn);
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
ok = ldb.add(" ok = ldb.add("
dn: cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn + " dn: cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn + "
objectClass: user objectClass: user
"); ");
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
} }
println("Testing ldb.search for (&(cn=ldaptestuser)(objectClass=user))"); println("Testing ldb.search for (&(cn=ldaptestuser)(objectClass=user))");
var res = ldb.search("(&(cn=ldaptestuser)(objectClass=user))"); var res = ldb.search("(&(cn=ldaptestuser)(objectClass=user))");
if (res.length != 1) { if (res.error != 0 || res.msgs.length != 1) {
println("Could not find (&(cn=ldaptestuser)(objectClass=user))"); println("Could not find (&(cn=ldaptestuser)(objectClass=user))");
assert(res.length == 1); assert(res.error == 0);
assert(res.msgs.length == 1);
} }
assert(res[0].dn == "cn=ldaptestuser,cn=users," + base_dn); assert(res.msgs[0].dn == "cn=ldaptestuser,cn=users," + base_dn);
assert(res[0].cn == "ldaptestuser"); assert(res.msgs[0].cn == "ldaptestuser");
assert(res[0].name == "ldaptestuser"); assert(res.msgs[0].name == "ldaptestuser");
assert(res[0].objectClass[0] == "top"); assert(res.msgs[0].objectClass[0] == "top");
assert(res[0].objectClass[1] == "person"); assert(res.msgs[0].objectClass[1] == "person");
assert(res[0].objectClass[2] == "organizationalPerson"); assert(res.msgs[0].objectClass[2] == "organizationalPerson");
assert(res[0].objectClass[3] == "user"); assert(res.msgs[0].objectClass[3] == "user");
assert(res[0].objectGUID != undefined); assert(res.msgs[0].objectGUID != undefined);
assert(res[0].whenCreated != undefined); assert(res.msgs[0].whenCreated != undefined);
assert(res[0].objectCategory == "cn=Person,cn=Schema,cn=Configuration," + base_dn); assert(res.msgs[0].objectCategory == "cn=Person,cn=Schema,cn=Configuration," + base_dn);
assert(res[0].sAMAccountType == 805306368); assert(res.msgs[0].sAMAccountType == 805306368);
// assert(res[0].userAccountControl == 546); // assert(res[0].userAccountControl == 546);
println("Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))"); println("Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))");
var res2 = ldb.search("(&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))"); var res2 = ldb.search("(&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))");
if (res2.length != 1) { if (res2.error != 0 || res2.msgs.length != 1) {
println("Could not find (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))"); println("Could not find (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))");
assert(res2.length == 1); assert(res2.error == 0);
assert(res2.msgs.length == 1);
} }
assert(res[0].dn == res2[0].dn); assert(res.msgs[0].dn == res2.msgs[0].dn);
println("Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon))"); println("Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon))");
var res3 = ldb.search("(&(cn=ldaptestuser)(objectCategory=PerSon))"); var res3 = ldb.search("(&(cn=ldaptestuser)(objectCategory=PerSon))");
if (res3.length != 1) { if (res3.error != 0 || res3.msgs.length != 1) {
println("Could not find (&(cn=ldaptestuser)(objectCategory=PerSon))"); println("Could not find (&(cn=ldaptestuser)(objectCategory=PerSon))");
assert(res3.length == 1); assert(res3.error == 0);
assert(res3.msgs.length == 1);
} }
assert(res[0].dn == res3[0].dn); assert(res.msgs[0].dn == res3.msgs[0].dn);
if (gc_ldb != undefined) { if (gc_ldb != undefined) {
println("Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog"); println("Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog");
var res3gc = gc_ldb.search("(&(cn=ldaptestuser)(objectCategory=PerSon))"); var res3gc = gc_ldb.search("(&(cn=ldaptestuser)(objectCategory=PerSon))");
if (res3gc.length != 1) { if (res3gc.error != 0 || res3gc.msgs.length != 1) {
println("Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog"); println("Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog");
assert(res3gc.length == 1); assert(res3gc.error == 0);
assert(res3gc.msgs.length == 1);
} }
assert(res[0].dn == res3gc[0].dn); assert(res.msgs[0].dn == res3gc.msgs[0].dn);
} }
ok = ldb.del(res[0].dn); ok = ldb.del(res.msgs[0].dn);
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectClass=user))"); println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectClass=user))");
var res = ldb.search("(&(cn=ldaptestcomputer)(objectClass=user))"); var res = ldb.search("(&(cn=ldaptestcomputer)(objectClass=user))");
if (res.length != 1) { if (res.error != 0 || res.msgs.length != 1) {
println("Could not find (&(cn=ldaptestuser)(objectClass=user))"); println("Could not find (&(cn=ldaptestuser)(objectClass=user))");
assert(res.length == 1); assert(res.error == 0);
assert(res.msgs.length == 1);
} }
assert(res[0].dn == "cn=ldaptestcomputer,cn=computers," + base_dn); assert(res.msgs[0].dn == "cn=ldaptestcomputer,cn=computers," + base_dn);
assert(res[0].cn == "ldaptestcomputer"); assert(res.msgs[0].cn == "ldaptestcomputer");
assert(res[0].name == "ldaptestcomputer"); assert(res.msgs[0].name == "ldaptestcomputer");
assert(res[0].objectClass[0] == "top"); assert(res.msgs[0].objectClass[0] == "top");
assert(res[0].objectClass[1] == "person"); assert(res.msgs[0].objectClass[1] == "person");
assert(res[0].objectClass[2] == "organizationalPerson"); assert(res.msgs[0].objectClass[2] == "organizationalPerson");
assert(res[0].objectClass[3] == "user"); assert(res.msgs[0].objectClass[3] == "user");
assert(res[0].objectClass[4] == "computer"); assert(res.msgs[0].objectClass[4] == "computer");
assert(res[0].objectGUID != undefined); assert(res.msgs[0].objectGUID != undefined);
assert(res[0].whenCreated != undefined); assert(res.msgs[0].whenCreated != undefined);
assert(res[0].objectCategory == "cn=Computer,cn=Schema,cn=Configuration," + base_dn); assert(res.msgs[0].objectCategory == "cn=Computer,cn=Schema,cn=Configuration," + base_dn);
// assert(res[0].sAMAccountType == 805306368); // assert(res.msgs[0].sAMAccountType == 805306368);
// assert(res[0].userAccountControl == 546); // assert(res.msgs[0].userAccountControl == 546);
println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))"); println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))");
var res2 = ldb.search("(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))"); var res2 = ldb.search("(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))");
if (res2.length != 1) { if (res2.error != 0 || res2.msgs.length != 1) {
println("Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))"); println("Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))");
assert(res2.length == 1); assert(res2.error == 0);
assert(res2.msgs.length == 1);
} }
assert(res[0].dn == res2[0].dn); assert(res.msgs[0].dn == res2.msgs[0].dn);
if (gc_ldb != undefined) { if (gc_ldb != undefined) {
println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + ")) in Global Catlog"); println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + ")) in Global Catlog");
var res2gc = gc_ldb.search("(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))"); var res2gc = gc_ldb.search("(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))");
if (res2gc.length != 1) { if (res2gc.error != 0 || res2gc.msgs.length != 1) {
println("Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + ")) in Global Catlog"); println("Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + ")) in Global Catlog");
assert(res2gc.length == 1); assert(res2gc.error == 0);
assert(res2gc.msgs.length == 1);
} }
assert(res[0].dn == res2gc[0].dn); assert(res.msgs[0].dn == res2gc.msgs[0].dn);
} }
println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER))"); println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER))");
var res3 = ldb.search("(&(cn=ldaptestcomputer)(objectCategory=compuTER))"); var res3 = ldb.search("(&(cn=ldaptestcomputer)(objectCategory=compuTER))");
if (res3.length != 1) { if (res3.error != 0 || res3.msgs.length != 1) {
println("Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER))"); println("Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER))");
assert(res3.length == 1); assert(res3.error == 0);
assert(res3.msgs.length == 1);
} }
assert(res[0].dn == res3[0].dn); assert(res.msgs[0].dn == res3.msgs[0].dn);
if (gc_ldb != undefined) { if (gc_ldb != undefined) {
println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog"); println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog");
var res3gc = gc_ldb.search("(&(cn=ldaptestcomputer)(objectCategory=compuTER))"); var res3gc = gc_ldb.search("(&(cn=ldaptestcomputer)(objectCategory=compuTER))");
if (res3gc.length != 1) { if (res3gc.error != 0 || res3gc.msgs.length != 1) {
println("Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog"); println("Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog");
assert(res3gc.length == 1); assert(res3gc.error == 0);
assert(res3gc.msgs.length == 1);
} }
assert(res[0].dn == res3gc[0].dn); assert(res.msgs[0].dn == res3gc.msgs[0].dn);
} }
println("Testing ldb.search for (&(cn=ldaptestcomp*r)(objectCategory=compuTER))"); println("Testing ldb.search for (&(cn=ldaptestcomp*r)(objectCategory=compuTER))");
var res4 = ldb.search("(&(cn=ldaptestcomp*r)(objectCategory=compuTER))"); var res4 = ldb.search("(&(cn=ldaptestcomp*r)(objectCategory=compuTER))");
if (res4.length != 1) { if (res4.error != 0 || res4.msgs.length != 1) {
println("Could not find (&(cn=ldaptestcomp*r)(objectCategory=compuTER))"); println("Could not find (&(cn=ldaptestcomp*r)(objectCategory=compuTER))");
assert(res4.length == 1); assert(res4.error == 0);
assert(res4.msgs.length == 1);
} }
assert(res[0].dn == res4[0].dn); assert(res.msgs[0].dn == res4.msgs[0].dn);
println("Testing ldb.search for (&(cn=ldaptestcomput*)(objectCategory=compuTER))"); println("Testing ldb.search for (&(cn=ldaptestcomput*)(objectCategory=compuTER))");
var res5 = ldb.search("(&(cn=ldaptestcomput*)(objectCategory=compuTER))"); var res5 = ldb.search("(&(cn=ldaptestcomput*)(objectCategory=compuTER))");
if (res5.length != 1) { if (res5.error != 0 || res5.msgs.length != 1) {
println("Could not find (&(cn=ldaptestcomput*)(objectCategory=compuTER))"); println("Could not find (&(cn=ldaptestcomput*)(objectCategory=compuTER))");
assert(res5.length == 1); assert(res5.error == 0);
assert(res5.msgs.length == 1);
} }
assert(res[0].dn == res5[0].dn); assert(res.msgs[0].dn == res5.msgs[0].dn);
println("Testing ldb.search for (&(cn=*daptestcomputer)(objectCategory=compuTER))"); println("Testing ldb.search for (&(cn=*daptestcomputer)(objectCategory=compuTER))");
var res6 = ldb.search("(&(cn=*daptestcomputer)(objectCategory=compuTER))"); var res6 = ldb.search("(&(cn=*daptestcomputer)(objectCategory=compuTER))");
if (res6.length != 1) { if (res6.error != 0 || res6.msgs.length != 1) {
println("Could not find (&(cn=*daptestcomputer)(objectCategory=compuTER))"); println("Could not find (&(cn=*daptestcomputer)(objectCategory=compuTER))");
assert(res6.length == 1); assert(res6.error == 0);
assert(res6.msgs.length == 1);
} }
assert(res[0].dn == res6[0].dn); assert(res.msgs[0].dn == res6.msgs[0].dn);
ok = ldb.del(res[0].dn); ok = ldb.del(res.msgs[0].dn);
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
println("Testing ldb.search for (&(cn=ldaptest2computer)(objectClass=user))"); println("Testing ldb.search for (&(cn=ldaptest2computer)(objectClass=user))");
var res = ldb.search("(&(cn=ldaptest2computer)(objectClass=user))"); var res = ldb.search("(&(cn=ldaptest2computer)(objectClass=user))");
if (res.length != 1) { if (res.error != 0 || res.msgs.length != 1) {
println("Could not find (&(cn=ldaptest2computer)(objectClass=user))"); println("Could not find (&(cn=ldaptest2computer)(objectClass=user))");
assert(res.length == 1); assert(res.error == 0);
assert(res.msgs.length == 1);
} }
assert(res[0].dn == "cn=ldaptest2computer,cn=computers," + base_dn); assert(res.msgs[0].dn == "cn=ldaptest2computer,cn=computers," + base_dn);
assert(res[0].cn == "ldaptest2computer"); assert(res.msgs[0].cn == "ldaptest2computer");
assert(res[0].name == "ldaptest2computer"); assert(res.msgs[0].name == "ldaptest2computer");
assert(res[0].objectClass[0] == "top"); assert(res.msgs[0].objectClass[0] == "top");
assert(res[0].objectClass[1] == "person"); assert(res.msgs[0].objectClass[1] == "person");
assert(res[0].objectClass[2] == "organizationalPerson"); assert(res.msgs[0].objectClass[2] == "organizationalPerson");
assert(res[0].objectClass[3] == "user"); assert(res.msgs[0].objectClass[3] == "user");
assert(res[0].objectClass[4] == "computer"); assert(res.msgs[0].objectClass[4] == "computer");
assert(res[0].objectGUID != undefined); assert(res.msgs[0].objectGUID != undefined);
assert(res[0].whenCreated != undefined); assert(res.msgs[0].whenCreated != undefined);
assert(res[0].objectCategory == "cn=Computer,cn=Schema,cn=Configuration," + base_dn); assert(res.msgs[0].objectCategory == "cn=Computer,cn=Schema,cn=Configuration," + base_dn);
assert(res[0].sAMAccountType == 805306369); assert(res.msgs[0].sAMAccountType == 805306369);
// assert(res[0].userAccountControl == 4098); // assert(res.msgs[0].userAccountControl == 4098);
println("Testing ldb.search for (&(cn=ldaptestUSer2)(objectClass=user))"); println("Testing ldb.search for (&(cn=ldaptestUSer2)(objectClass=user))");
var res = ldb.search("(&(cn=ldaptestUSer2)(objectClass=user))"); var res = ldb.search("(&(cn=ldaptestUSer2)(objectClass=user))");
if (res.length != 1) { if (res.error != 0 || res.msgs.length != 1) {
println("Could not find (&(cn=ldaptestUSer2)(objectClass=user))"); println("Could not find (&(cn=ldaptestUSer2)(objectClass=user))");
assert(res.length == 1); assert(res.error == 0);
assert(res.msgs.length == 1);
} }
assert(res[0].dn == "cn=ldaptestuser2,cn=users," + base_dn); assert(res.msgs[0].dn == "cn=ldaptestuser2,cn=users," + base_dn);
assert(res[0].cn == "ldaptestuser2"); assert(res.msgs[0].cn == "ldaptestuser2");
assert(res[0].name == "ldaptestuser2"); assert(res.msgs[0].name == "ldaptestuser2");
assert(res[0].objectClass[0] == "top"); assert(res.msgs[0].objectClass[0] == "top");
assert(res[0].objectClass[1] == "person"); assert(res.msgs[0].objectClass[1] == "person");
assert(res[0].objectClass[2] == "organizationalPerson"); assert(res.msgs[0].objectClass[2] == "organizationalPerson");
assert(res[0].objectClass[3] == "user"); assert(res.msgs[0].objectClass[3] == "user");
assert(res[0].objectGUID != undefined); assert(res.msgs[0].objectGUID != undefined);
assert(res[0].whenCreated != undefined); assert(res.msgs[0].whenCreated != undefined);
ok = ldb.del(res[0].dn); ok = ldb.del(res.msgs[0].dn);
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
println("Testing ldb.search for (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))"); println("Testing ldb.search for (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))");
var res = ldb.search("(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))"); var res = ldb.search("(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))");
if (res.length != 1) { if (res.error != 0 || res.msgs.length != 1) {
println("Could not find (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))"); println("Could not find (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))");
assert(res.length == 1); assert(res.error == 0);
assert(res.msgs.length == 1);
} }
assert(res[0].dn == "cn=ldaptestutf8user èùéìòà,cn=users," + base_dn); assert(res.msgs[0].dn == "cn=ldaptestutf8user èùéìòà,cn=users," + base_dn);
assert(res[0].cn == "ldaptestutf8user èùéìòà"); assert(res.msgs[0].cn == "ldaptestutf8user èùéìòà");
assert(res[0].name == "ldaptestutf8user èùéìòà"); assert(res.msgs[0].name == "ldaptestutf8user èùéìòà");
assert(res[0].objectClass[0] == "top"); assert(res.msgs[0].objectClass[0] == "top");
assert(res[0].objectClass[1] == "person"); assert(res.msgs[0].objectClass[1] == "person");
assert(res[0].objectClass[2] == "organizationalPerson"); assert(res.msgs[0].objectClass[2] == "organizationalPerson");
assert(res[0].objectClass[3] == "user"); assert(res.msgs[0].objectClass[3] == "user");
assert(res[0].objectGUID != undefined); assert(res.msgs[0].objectGUID != undefined);
assert(res[0].whenCreated != undefined); assert(res.msgs[0].whenCreated != undefined);
ok = ldb.del(res[0].dn); ok = ldb.del(res.msgs[0].dn);
if (!ok) { if (ok.error != 0) {
println(ldb.errstring()); println(ok.errstr);
assert(ok); assert(ok.error == 0);
} }
println("Testing ldb.search for (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))"); println("Testing ldb.search for (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))");
var res = ldb.search("(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))"); var res = ldb.search("(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))");
if (res.length != 1) { if (res.error != 0 || res.msgs.length != 1) {
println("Could not find (expect space collapse, win2k3 fails) (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))"); println("Could not find (expect space collapse, win2k3 fails) (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))");
} else { } else {
assert(res[0].dn == "cn=ldaptestutf8user2 èùéìòà,cn=users," + base_dn); assert(res.msgs[0].dn == "cn=ldaptestutf8user2 èùéìòà,cn=users," + base_dn);
assert(res[0].cn == "ldaptestutf8user2 èùéìòà"); assert(res.msgs[0].cn == "ldaptestutf8user2 èùéìòà");
} }
println("Testing that we can't get at the configuration DN from the main search base"); println("Testing that we can't get at the configuration DN from the main search base");
var attrs = new Array("cn"); var attrs = new Array("cn");
var res = ldb.search("objectClass=crossRef", base_dn, ldb.SCOPE_SUBTREE, attrs); var res = ldb.search("objectClass=crossRef", base_dn, ldb.SCOPE_SUBTREE, attrs);
assert (res.length == 0); assert(res.error == 0);
assert(res.msgs.length == 0);
if (gc_ldb != undefined) { if (gc_ldb != undefined) {
println("Testing that we do find configuration elements in the global catlog"); println("Testing that we do find configuration elements in the global catlog");
var attrs = new Array("cn"); var attrs = new Array("cn");
var res = gc_ldb.search("objectClass=crossRef", base_dn, ldb.SCOPE_SUBTREE, attrs); var res = gc_ldb.search("objectClass=crossRef", base_dn, ldb.SCOPE_SUBTREE, attrs);
assert (res.length > 0); assert(res.error == 0);
assert (res.msgs.length > 0);
println("Testing that we do find configuration elements and user elements at the same time"); println("Testing that we do find configuration elements and user elements at the same time");
var attrs = new Array("cn"); var attrs = new Array("cn");
var res = gc_ldb.search("(|(objectClass=crossRef)(objectClass=person))", base_dn, ldb.SCOPE_SUBTREE, attrs); var res = gc_ldb.search("(|(objectClass=crossRef)(objectClass=person))", base_dn, ldb.SCOPE_SUBTREE, attrs);
assert (res.length > 0); assert(res.error == 0);
assert (res.msgs.length > 0);
println("Testing that we do find configuration elements in the global catlog, with the configuration basedn"); println("Testing that we do find configuration elements in the global catlog, with the configuration basedn");
var attrs = new Array("cn"); var attrs = new Array("cn");
var res = gc_ldb.search("objectClass=crossRef", configuration_dn, ldb.SCOPE_SUBTREE, attrs); var res = gc_ldb.search("objectClass=crossRef", configuration_dn, ldb.SCOPE_SUBTREE, attrs);
assert (res.length > 0); assert(res.error == 0);
assert (res.msgs.length > 0);
} }
println("Testing that we can get at the configuration DN on the main LDAP port"); println("Testing that we can get at the configuration DN on the main LDAP port");
var attrs = new Array("cn"); var attrs = new Array("cn");
var res = ldb.search("objectClass=crossRef", configuration_dn, ldb.SCOPE_SUBTREE, attrs); var res = ldb.search("objectClass=crossRef", configuration_dn, ldb.SCOPE_SUBTREE, attrs);
assert (res.length > 0); assert(res.error == 0);
assert (res.msgs.length > 0);
} }
@ -427,40 +447,46 @@ function basedn_tests(ldb, gc_ldb)
println("Testing for all rootDSE attributes"); println("Testing for all rootDSE attributes");
var attrs = new Array(); var attrs = new Array();
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs); var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
assert(res.length == 1); assert(res.error == 0);
assert(res.msgs.length == 1);
println("Testing for highestCommittedUSN"); println("Testing for highestCommittedUSN");
var attrs = new Array("highestCommittedUSN"); var attrs = new Array("highestCommittedUSN");
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs); var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
assert(res.length == 1); assert(res.error == 0);
assert(res[0].highestCommittedUSN != undefined); assert(res.msgs.length == 1);
assert(res[0].highestCommittedUSN != 0); assert(res.msgs[0].highestCommittedUSN != undefined);
assert(res.msgs[0].highestCommittedUSN != 0);
println("Testing for netlogon via LDAP"); println("Testing for netlogon via LDAP");
var attrs = new Array("netlogon"); var attrs = new Array("netlogon");
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs); var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
assert(res.length == 0); assert(res.error == 0);
assert(res.msgs.length == 0);
println("Testing for netlogon and highestCommittedUSN via LDAP"); println("Testing for netlogon and highestCommittedUSN via LDAP");
var attrs = new Array("netlogon", "highestCommittedUSN"); var attrs = new Array("netlogon", "highestCommittedUSN");
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs); var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
assert(res.length == 0); assert(res.error == 0);
assert(res.msgs.length == 0);
} }
function find_basedn(ldb) function find_basedn(ldb)
{ {
var attrs = new Array("defaultNamingContext"); var attrs = new Array("defaultNamingContext");
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs); var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
assert(res.length == 1); assert(res.error == 0);
return res[0].defaultNamingContext; assert(res.msgs.length == 1);
return res.msgs[0].defaultNamingContext;
} }
function find_configurationdn(ldb) function find_configurationdn(ldb)
{ {
var attrs = new Array("configurationNamingContext"); var attrs = new Array("configurationNamingContext");
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs); var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
assert(res.length == 1); assert(res.error == 0);
return res[0].configurationNamingContext; assert(res.msgs.length == 1);
return res.msgs[0].configurationNamingContext;
} }
/* use command line creds if available */ /* use command line creds if available */

View File

@ -32,33 +32,33 @@ dn: cn=x,cn=test
objectClass: foo objectClass: foo
x: 3 x: 3
"); ");
assert(ok); assert(ok.error == 0);
println("Testing ldb.search"); println("Testing ldb.search");
var res = ldb.search("(objectClass=*)"); var res = ldb.search("(objectClass=*)");
assert(res[0].objectClass[0] == "foo"); assert(res.msgs[0].objectClass[0] == "foo");
assert(res[0].dn == "cn=x,cn=test"); assert(res.msgs[0].dn == "cn=x,cn=test");
assert(res[0].x == 3); assert(res.msgs[0].x == 3);
ok = ldb.add(" ok = ldb.add("
dn: cn=x2,cn=test dn: cn=x2,cn=test
objectClass: foo objectClass: foo
x: 4 x: 4
"); ");
assert(ok); assert(ok.error == 0);
var attrs = new Array("x"); var attrs = new Array("x");
res = ldb.search("x=4", NULL, ldb.SCOPE_DEFAULT, attrs); res = ldb.search("x=4", NULL, ldb.SCOPE_DEFAULT, attrs);
assert(res[0].x == 4); assert(res.msgs[0].x == 4);
assert(res[0].objectClass == undefined); assert(res.msgs[0].objectClass == undefined);
assert(res[0].dn == "cn=x2,cn=test"); assert(res.msgs[0].dn == "cn=x2,cn=test");
ok = ldb.del("cn=x,cn=test"); ok = ldb.del("cn=x,cn=test");
assert(ok); assert(ok.error == 0);
ok = ldb.rename("cn=x2,cn=test", "cn=x3,cn=test"); ok = ldb.rename("cn=x2,cn=test", "cn=x3,cn=test");
assert(ok); assert(ok.error == 0);
res = ldb.search("x=4", NULL, ldb.SCOPE_DEFAULT, attrs); res = ldb.search("x=4", NULL, ldb.SCOPE_DEFAULT, attrs);
assert(res[0].dn == "cn=x3,cn=test"); assert(res.msgs[0].dn == "cn=x3,cn=test");
ok = ldb.modify(" ok = ldb.modify("
dn: cn=x3,cn=test dn: cn=x3,cn=test
@ -68,13 +68,13 @@ x: 7
"); ");
res = ldb.search("x=7"); res = ldb.search("x=7");
assert(res.length == 1); assert(res.msgs.length == 1);
assert(res[0].x.length == 2); assert(res.msgs[0].x.length == 2);
/* Check a few things before we add modules */ /* Check a few things before we add modules */
assert(res[0].objectGUID == undefined); assert(res.msgs[0].objectGUID == undefined);
assert(res[0].createTimestamp == undefined); assert(res.msgs[0].createTimestamp == undefined);
assert(res[0].whenCreated == undefined); assert(res.msgs[0].whenCreated == undefined);
} }
@ -111,23 +111,23 @@ dn: @ATTRIBUTES
cn: CASE_INSENSITIVE cn: CASE_INSENSITIVE
caseattr: CASE_INSENSITIVE caseattr: CASE_INSENSITIVE
"); ");
if (!ok) { if (ok.error != 0) {
println("Failed to add: " + ldb.errstring()); println("Failed to add: " + ok.errstr);
assert(ok); assert(ok.error == 0);
} }
/* Confirm that the attributes were replicated */ /* Confirm that the attributes were replicated */
var res_attrs = parttestldb.search("cn=*", "@ATTRIBUTES", parttestldb.SCOPE_BASE); var res_attrs = parttestldb.search("cn=*", "@ATTRIBUTES", parttestldb.SCOPE_BASE);
assert(res_attrs[0].cn == "CASE_INSENSITIVE"); assert(res_attrs.msgs[0].cn == "CASE_INSENSITIVE");
ok = ldb.add(" ok = ldb.add("
dn: cn=x8,cn=PartTest dn: cn=x8,cn=PartTest
objectClass: foo objectClass: foo
x: 8 x: 8
"); ");
if (!ok) { if (ok.error != 0) {
println("Failed to add: " + ldb.errstring()); println("Failed to add: " + ok.errstr);
assert(ok); assert(ok.error == 0);
} }
ok = ldb.add(" ok = ldb.add("
@ -136,9 +136,9 @@ objectClass: foo
x: 9 x: 9
cn: X9 cn: X9
"); ");
if (!ok) { if (ok.error != 0) {
println("Failed to add: " + ldb.errstring()); println("Failed to add: " + ok.errstr);
assert(ok); assert(ok.error == 0);
} }
ok = ldb.add(" ok = ldb.add("
@ -147,59 +147,59 @@ objectClass: foo
x: 9 x: 9
cn: X9 cn: X9
"); ");
if (ok) { if (ok.error == 0) {
println("Should have failed to add cn=X9,cn=PartTest"); println("Should have failed to add cn=X9,cn=PartTest");
assert(!ok); assert(ok.error != 0);
} }
var res = ldb.search("x=8", "cn=PartTest", ldb.SCOPE_DEFAULT); var res = ldb.search("x=8", "cn=PartTest", ldb.SCOPE_DEFAULT);
assert(res[0].objectGUID != undefined); assert(res.msgs[0].objectGUID != undefined);
assert(res[0].uSNCreated != undefined); assert(res.msgs[0].uSNCreated != undefined);
assert(res[0].uSNChanged != undefined); assert(res.msgs[0].uSNChanged != undefined);
assert(res[0].createTimestamp == undefined); assert(res.msgs[0].createTimestamp == undefined);
assert(res[0].whenCreated != undefined); assert(res.msgs[0].whenCreated != undefined);
assert(res[0].name == "x8"); assert(res.msgs[0].name == "x8");
assert(res[0].cn == "x8"); assert(res.msgs[0].cn == "x8");
/* Confirm that this ended up in the correct LDB */ /* Confirm that this ended up in the correct LDB */
var res_otherldb = parttestldb.search("x=8", "cn=PartTest", parttestldb.SCOPE_DEFAULT); var res_otherldb = parttestldb.search("x=8", "cn=PartTest", parttestldb.SCOPE_DEFAULT);
assert(res_otherldb[0].objectGUID != undefined); assert(res_otherldb.msgs[0].objectGUID != undefined);
assert(res_otherldb[0].createTimestamp == undefined); assert(res_otherldb.msgs[0].createTimestamp == undefined);
assert(res_otherldb[0].whenCreated != undefined); assert(res_otherldb.msgs[0].whenCreated != undefined);
assert(res_otherldb[0].name == "x8"); assert(res_otherldb.msgs[0].name == "x8");
assert(res_otherldb[0].cn == "x8"); assert(res_otherldb.msgs[0].cn == "x8");
var attrs = new Array("*", "createTimestamp"); var attrs = new Array("*", "createTimestamp");
var res2 = ldb.search("x=9", "cn=PartTest", ldb.SCOPE_DEFAULT, attrs); var res2 = ldb.search("x=9", "cn=PartTest", ldb.SCOPE_DEFAULT, attrs);
assert(res2[0].objectGUID != undefined); assert(res2.msgs[0].objectGUID != undefined);
assert(res2[0].createTimestamp != undefined); assert(res2.msgs[0].createTimestamp != undefined);
assert(res2[0].whenCreated != undefined); assert(res2.msgs[0].whenCreated != undefined);
assert(res2[0].name == "x9"); assert(res2.msgs[0].name == "x9");
assert(res2[0].cn == "x9"); assert(res2.msgs[0].cn == "x9");
assert(res[0].objectGUID != res2[0].objectGUID); assert(res.msgs[0].objectGUID != res2.msgs[0].objectGUID);
var attrs = new Array("*"); var attrs = new Array("*");
var res3 = ldb.search("", "", ldb.SCOPE_BASE, attrs); var res3 = ldb.search("", "", ldb.SCOPE_BASE, attrs);
assert(res3[0].cn == undefined); assert(res3.msgs[0].cn == undefined);
assert(res3[0].distinguishedName == undefined); assert(res3.msgs[0].distinguishedName == undefined);
assert(res3[0].name == undefined); assert(res3.msgs[0].name == undefined);
assert(res3[0].currentTime != undefined); assert(res3.msgs[0].currentTime != undefined);
assert(res3[0].highestCommittedUSN != undefined); assert(res3.msgs[0].highestCommittedUSN != undefined);
assert(res3[0].namingContexts[0] == "cn=Sub,cn=Sub,cn=PartTest"); assert(res3.msgs[0].namingContexts[0] == "cn=Sub,cn=Sub,cn=PartTest");
assert(res3[0].namingContexts[1] == "cn=Sub,cn=PartTest"); assert(res3.msgs[0].namingContexts[1] == "cn=Sub,cn=PartTest");
assert(res3[0].namingContexts[2] == "cn=PartTest"); assert(res3.msgs[0].namingContexts[2] == "cn=PartTest");
assert(res3[0].namingContexts[3] == "cn=SideTest"); assert(res3.msgs[0].namingContexts[3] == "cn=SideTest");
var usn = res3[0].highestCommittedUSN; var usn = res3.msgs[0].highestCommittedUSN;
/* Start a transaction. We are going to abort it later, to /* Start a transaction. We are going to abort it later, to
* show we clean up all partitions */ * show we clean up all partitions */
ok = ldb.transaction_start() ok = ldb.transaction_start()
if (!ok) { if (!ok) {
println("Failed to start a transaction: " + ldb.errstring()); println("Failed to start a transaction: " + ok.errstr);
assert(ok); assert(ok.error == 0);
} }
@ -208,53 +208,53 @@ dn: cn=x10,cn=parttest
objectClass: foo objectClass: foo
x: 10 x: 10
"); ");
if (!ok) { if (ok.error != 0) {
println("Failed to add: " + ldb.errstring()); println("Failed to add: " + ok.errstr);
assert(ok); assert(ok.error == 0);
} }
var attrs = new Array("highestCommittedUSN"); var attrs = new Array("highestCommittedUSN");
var res4 = ldb.search("", "", ldb.SCOPE_BASE, attrs); var res4 = ldb.search("", "", ldb.SCOPE_BASE, attrs);
var usn2 = res4[0].highestCommittedUSN; var usn2 = res4.msgs[0].highestCommittedUSN;
assert(usn < res4[0].highestCommittedUSN); assert(usn < res4.msgs[0].highestCommittedUSN);
ok = ldb.add(" ok = ldb.add("
dn: cn=x11,cn=sub,cn=parttest dn: cn=x11,cn=sub,cn=parttest
objectClass: foo objectClass: foo
x: 11 x: 11
"); ");
if (!ok) { if (ok.error != 0) {
println("Failed to add: " + ldb.errstring()); println("Failed to add: " + ok.errstr);
assert(ok); assert(ok.error == 0);
} }
var attrs = new Array("highestCommittedUSN"); var attrs = new Array("highestCommittedUSN");
var res5 = ldb.search("", "", ldb.SCOPE_BASE, attrs); var res5 = ldb.search("", "", ldb.SCOPE_BASE, attrs);
assert(usn2 < res5[0].highestCommittedUSN); assert(usn2 < res5.msgs[0].highestCommittedUSN);
var attrs = new Array("*", "createTimestamp"); var attrs = new Array("*", "createTimestamp");
var res6 = ldb.search("x=11", "cn=parttest", ldb.SCOPE_SUB, attrs); var res6 = ldb.search("x=11", "cn=parttest", ldb.SCOPE_SUB, attrs);
assert(res6.length == 0); assert(res6.msgs.length == 0);
var attrs = new Array("*", "createTimestamp"); var attrs = new Array("*", "createTimestamp");
var res7 = ldb.search("x=10", "cn=sub,cn=parttest", ldb.SCOPE_DEFAULT, attrs); var res7 = ldb.search("x=10", "cn=sub,cn=parttest", ldb.SCOPE_DEFAULT, attrs);
assert(res7.length == 0); assert(res7.msgs.length == 0);
var res8 = ldb.search("x=11", "cn=sub,cn=parttest", ldb.SCOPE_DEFAULT, attrs); var res8 = ldb.search("x=11", "cn=sub,cn=parttest", ldb.SCOPE_DEFAULT, attrs);
assert(res8[0].objectGUID == undefined); /* The objectGUID module is not loaded here */ assert(res8.msgs[0].objectGUID == undefined); /* The objectGUID module is not loaded here */
assert(res8[0].uSNCreated == undefined); /* The objectGUID module is not loaded here */ assert(res8.msgs[0].uSNCreated == undefined); /* The objectGUID module is not loaded here */
assert(res8[0].name == "x11"); assert(res8.msgs[0].name == "x11");
assert(res8[0].cn == "x11"); assert(res8.msgs[0].cn == "x11");
ok = ldb.add(" ok = ldb.add("
dn: caseattr=XY,cn=PartTest dn: caseattr=XY,cn=PartTest
objectClass: foo objectClass: foo
x: Y x: Y
"); ");
if (!ok) { if (ok.error != 0) {
println("Failed to add: " + ldb.errstring()); println("Failed to add: " + ok.errstr);
assert(ok); assert(ok.error == 0);
} }
ok = ldb.add(" ok = ldb.add("
@ -263,9 +263,9 @@ objectClass: foo
x: Z x: Z
caseattr: XZ caseattr: XZ
"); ");
if (!ok) { if (ok.error != 0) {
println("Failed to add: " + ldb.errstring()); println("Failed to add: " + ok.errstr);
assert(ok); assert(ok.error == 0);
} }
ok = ldb.add(" ok = ldb.add("
@ -274,9 +274,9 @@ objectClass: foo
x: Z x: Z
caseattr: xz caseattr: xz
"); ");
if (ok) { if (ok.error == 0) {
println("Should have failed to add caseattr=xz,cn=PartTest"); println("Should have failed to add caseattr=xz,cn=PartTest");
assert(!ok); assert(ok.error != 0);
} }
ok = ldb.add(" ok = ldb.add("
@ -285,9 +285,9 @@ objectClass: foo
x: Z x: Z
caseattr2: XZ caseattr2: XZ
"); ");
if (!ok) { if (ok.error != 0) {
println("Failed to add: " + ldb.errstring()); println("Failed to add: " + ok.errstr);
assert(ok); assert(ok.error == 0);
} }
ok = ldb.add(" ok = ldb.add("
@ -296,35 +296,35 @@ objectClass: foo
x: Z x: Z
caseattr2: Xz caseattr2: Xz
"); ");
if (!ok) { if (ok.error != 0) {
println("Failed to add: " + ldb.errstring()); println("Failed to add: " + ok.errstr);
assert(ok); assert(ok.error == 0);
} }
var resX = ldb.search("caseattr=xz", "cn=parttest", ldb.SCOPE_DEFAULT, attrs); var resX = ldb.search("caseattr=xz", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
assert(resX.length == 1); assert(resX.msgs.length == 1);
assert(resX[0].objectGUID != undefined); assert(resX.msgs[0].objectGUID != undefined);
assert(resX[0].createTimestamp != undefined); assert(resX.msgs[0].createTimestamp != undefined);
assert(resX[0].whenCreated != undefined); assert(resX.msgs[0].whenCreated != undefined);
assert(resX[0].name == "XZ"); assert(resX.msgs[0].name == "XZ");
var rescount = ldb.search("(|(caseattr=*)(cn=*))", "cn=parttest", ldb.SCOPE_DEFAULT, attrs); var rescount = ldb.search("(|(caseattr=*)(cn=*))", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
assert(rescount.length == 5); assert(rescount.msgs.length == 5);
/* Check this attribute is *not* case sensitive */ /* Check this attribute is *not* case sensitive */
var resXcount = ldb.search("caseattr=x*", "cn=parttest", ldb.SCOPE_DEFAULT, attrs); var resXcount = ldb.search("caseattr=x*", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
assert(resXcount.length == 2); assert(resXcount.msgs.length == 2);
/* Check that this attribute *is* case sensitive */ /* Check that this attribute *is* case sensitive */
var resXcount2 = ldb.search("caseattr2=xz", "cn=parttest", ldb.SCOPE_DEFAULT, attrs); var resXcount2 = ldb.search("caseattr2=xz", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
assert(resXcount2.length == 0); assert(resXcount2.msgs.length == 0);
/* Now abort the transaction to show that even with /* Now abort the transaction to show that even with
* partitions, it is aborted everywhere */ * partitions, it is aborted everywhere */
ok = ldb.transaction_cancel(); ok = ldb.transaction_cancel();
if (!ok) { if (!ok) {
println("Failed to cancel a transaction: " + ldb.errstring()); println("Failed to cancel a transaction: " + ok.errstr);
assert(ok); assert(ok);
} }
@ -332,19 +332,19 @@ caseattr2: Xz
var attrs = new Array("highestCommittedUSN"); var attrs = new Array("highestCommittedUSN");
var res9 = ldb.search("", "", ldb.SCOPE_BASE, attrs); var res9 = ldb.search("", "", ldb.SCOPE_BASE, attrs);
assert(usn == res9[0].highestCommittedUSN); assert(usn == res9.msgs[0].highestCommittedUSN);
var attrs = new Array("*"); var attrs = new Array("*");
var res10 = ldb.search("x=11", "cn=sub,cn=parttest", ldb.SCOPE_DEFAULT, attrs); var res10 = ldb.search("x=11", "cn=sub,cn=parttest", ldb.SCOPE_DEFAULT, attrs);
assert(res10.length == 0); assert(res10.msgs.length == 0);
var attrs = new Array("*"); var attrs = new Array("*");
var res11 = ldb.search("x=10", "cn=parttest", ldb.SCOPE_DEFAULT, attrs); var res11 = ldb.search("x=10", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
assert(res11.length == 0); assert(res11.msgs.length == 0);
var attrs = new Array("*"); var attrs = new Array("*");
var res12 = ldb.search("caseattr=*", "cn=parttest", ldb.SCOPE_DEFAULT, attrs); var res12 = ldb.search("caseattr=*", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
assert(res12.length == 0); assert(res12.msgs.length == 0);
} }

View File

@ -157,9 +157,9 @@ function get_object_cn(ldb, name) {
var res = ldb.search(sprintf("(ldapDisplayName=%s)", name), rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs); var res = ldb.search(sprintf("(ldapDisplayName=%s)", name), rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs);
assert(res != undefined); assert(res != undefined);
assert(res.length == 1); assert(res.msgs.length == 1);
var cn = res[0]["cn"]; var cn = res.msgs[0]["cn"];
assert(cn != undefined); assert(cn != undefined);
if (typeof(cn) == "string") { if (typeof(cn) == "string") {
return cn; return cn;
@ -287,8 +287,8 @@ function find_objectclass_properties(ldb, o) {
sprintf("(ldapDisplayName=%s)", o.name), sprintf("(ldapDisplayName=%s)", o.name),
rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, class_attrs); rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, class_attrs);
assert(res != undefined); assert(res != undefined);
assert(res.length == 1); assert(res.msgs.length == 1);
var msg = res[0]; var msg = res.msgs[0];
var a; var a;
for (a in msg) { for (a in msg) {
o[a] = msg[a]; o[a] = msg[a];
@ -303,8 +303,8 @@ function find_attribute_properties(ldb, o) {
sprintf("(ldapDisplayName=%s)", o.name), sprintf("(ldapDisplayName=%s)", o.name),
rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrib_attrs); rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrib_attrs);
assert(res != undefined); assert(res != undefined);
assert(res.length == 1); assert(res.msgs.length == 1);
var msg = res[0]; var msg = res.msgs[0];
var a; var a;
for (a in msg) { for (a in msg) {
/* special case for oMObjectClass, which is a binary object */ /* special case for oMObjectClass, which is a binary object */
@ -332,18 +332,18 @@ function find_objectclass_auto(ldb, o) {
var ldif = "dn: " + testdn; var ldif = "dn: " + testdn;
ldif = ldif + "\nobjectClass: " + o.name; ldif = ldif + "\nobjectClass: " + o.name;
ok = ldb.add(ldif); ok = ldb.add(ldif);
if (!ok) { if (ok.error != 0) {
dprintf("error adding %s: %s\n", o.name, ldb.errstring()); dprintf("error adding %s: %s\n", o.name, ok.errstr);
dprintf("%s\n", ldif); dprintf("%s\n", ldif);
return; return;
} }
var res = ldb.search("", testdn, ldb.SCOPE_BASE); var res = ldb.search("", testdn, ldb.SCOPE_BASE);
ok = ldb.del(testdn); ok = ldb.del(testdn);
assert(ok); assert(ok.error == 0);
var a; var a;
for (a in res[0]) { for (a in res.msgs[0]) {
attributes[a].autocreate = true; attributes[a].autocreate = true;
} }
} }
@ -363,8 +363,8 @@ function expand_objectclass(ldb, o) {
var a; var a;
dprintf("Expanding class %s\n", o.name); dprintf("Expanding class %s\n", o.name);
assert(res != undefined); assert(res != undefined);
assert(res.length == 1); assert(res.msgs.length == 1);
var msg = res[0]; var msg = res.msgs[0];
for (a=0;a<attrs.length;a++) { for (a=0;a<attrs.length;a++) {
var aname = attrs[a]; var aname = attrs[a];
if (msg[aname] == undefined) { if (msg[aname] == undefined) {
@ -422,20 +422,20 @@ function walk_dn(ldb, dn) {
/* get a list of all possible attributes for this object */ /* get a list of all possible attributes for this object */
var attrs = new Array("allowedAttributes"); var attrs = new Array("allowedAttributes");
var res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, attrs); var res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, attrs);
if (res == undefined) { if (res.error != 0) {
dprintf("Unable to fetch allowedAttributes for '%s' - %s\n", dprintf("Unable to fetch allowedAttributes for '%s' - %s\n",
dn, ldb.errstring()); dn, res.errstr);
return; return;
} }
var allattrs = res[0].allowedAttributes; var allattrs = res.msgs[0].allowedAttributes;
res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, allattrs); res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, allattrs);
if (res == undefined) { if (res.error != 0) {
dprintf("Unable to fetch all attributes for '%s' - %s\n", dprintf("Unable to fetch all attributes for '%s' - %s\n",
dn, ldb.errstring()); dn, res.errstr);
return; return;
} }
var a; var a;
var msg = res[0]; var msg = res.msgs[0];
for (a in msg) { for (a in msg) {
if (attributes[a] == undefined) { if (attributes[a] == undefined) {
attributes[a] = obj_attribute(ldb, a); attributes[a] = obj_attribute(ldb, a);
@ -449,23 +449,23 @@ function walk_dn(ldb, dn) {
function walk_naming_context(ldb, namingContext) { function walk_naming_context(ldb, namingContext) {
var attrs = new Array("objectClass"); var attrs = new Array("objectClass");
var res = ldb.search("objectClass=*", namingContext, ldb.SCOPE_DEFAULT, attrs); var res = ldb.search("objectClass=*", namingContext, ldb.SCOPE_DEFAULT, attrs);
if (res == undefined) { if (res.error != 0) {
dprintf("Unable to fetch objectClasses for '%s' - %s\n", dprintf("Unable to fetch objectClasses for '%s' - %s\n",
namingContext, ldb.errstring()); namingContext, res.errstr);
return; return;
} }
var r; var r;
for (r=0;r<res.length;r++) { for (r=0;r<res.msgs.length;r++) {
var msg = res[r].objectClass; var msg = res.msgs[r].objectClass;
var c; var c;
for (c=0;c<msg.length;c++) { for (c=0;c<msg.length;c++) {
var objectClass = msg[c]; var objectClass = msg[c];
if (objectclasses[objectClass] == undefined) { if (objectclasses[objectClass] == undefined) {
objectclasses[objectClass] = obj_objectClass(ldb, objectClass); objectclasses[objectClass] = obj_objectClass(ldb, objectClass);
objectclasses[objectClass].exampleDN = res[r].dn; objectclasses[objectClass].exampleDN = res.msgs[r].dn;
} }
} }
walk_dn(ldb, res[r].dn); walk_dn(ldb, res.msgs[r].dn);
} }
} }
@ -557,11 +557,11 @@ function build_objectclass(ldb, name) {
var res = ldb.search( var res = ldb.search(
sprintf("(&(objectClass=classSchema)(ldapDisplayName=%s))", name), sprintf("(&(objectClass=classSchema)(ldapDisplayName=%s))", name),
rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs); rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs);
if (res == undefined) { if (res.error != 0) {
dprintf("unknown class '%s'\n", name); dprintf("unknown class '%s'\n", name);
return undefined; return undefined;
} }
if (res.length == 0) { if (res.msgs.length == 0) {
dprintf("unknown class '%s'\n", name); dprintf("unknown class '%s'\n", name);
return undefined; return undefined;
} }
@ -734,7 +734,7 @@ function load_list(file) {
/* get the rootDSE */ /* get the rootDSE */
var res = ldb.search("", "", ldb.SCOPE_BASE); var res = ldb.search("", "", ldb.SCOPE_BASE);
rootDse = res[0]; rootDse = res.msgs[0];
/* load the list of classes we are interested in */ /* load the list of classes we are interested in */
var classes = load_list(classfile); var classes = load_list(classfile);

File diff suppressed because it is too large Load Diff