wmi-1.3.16 from opsview.com
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
demonstrate use of GetOptions
|
||||
*/
|
||||
|
||||
var options = GetOptions(ARGV,
|
||||
"POPT_AUTOHELP",
|
||||
"POPT_COMMON_SAMBA",
|
||||
"myopt=s",
|
||||
"intopt=i",
|
||||
"noopt");
|
||||
|
||||
println("You called this script with arguments:");
|
||||
|
||||
printVars(options);
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
exec smbscript "$0" ${1+"$@"}
|
||||
|
||||
var options = GetOptions(ARGV,
|
||||
"POPT_COMMON_SAMBA");
|
||||
if (options == undefined) {
|
||||
println("Failed to parse options");
|
||||
return -1;
|
||||
}
|
||||
|
||||
libinclude("base.js");
|
||||
|
||||
var obj = new Object();
|
||||
obj.FOO = "foo";
|
||||
obj.BAR = "bar";
|
||||
var str1 = "${FOO}:${BAR}";
|
||||
var str2 = "${FOO}:${BAR} "; // note the space after the brace
|
||||
var sub1 = substitute_var(str1, obj);
|
||||
var sub2 = substitute_var(str2, obj);
|
||||
|
||||
assert(str1 + " " == str2);
|
||||
assert(sub1 + " " == sub2);
|
||||
exit(0);
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
demonstrate some bugs in ejs
|
||||
|
||||
tridge <appweb@tridgell.net>
|
||||
*/
|
||||
|
||||
|
||||
/****************************************
|
||||
demo a bug in constructing arrays
|
||||
fix at http://build.samba.org/build.pl?function=diff;tree=samba4;revision=7124
|
||||
status: FIXED
|
||||
*****************************************/
|
||||
function arraybug() {
|
||||
var a;
|
||||
|
||||
println("First with 3 elements");
|
||||
a = new Array("one", "two", "three");
|
||||
printVars(a);
|
||||
assert(a.length == 3);
|
||||
assert(a[0] == "one");
|
||||
assert(a[1] == "two");
|
||||
assert(a[2] == "three");
|
||||
|
||||
println("with a array length");
|
||||
a = new Array(5);
|
||||
printVars(a);
|
||||
assert(a.length == 5);
|
||||
|
||||
println("\nNow with 1 element");
|
||||
a = new Array("one");
|
||||
printVars(a);
|
||||
assert(a.length == 1);
|
||||
assert(a[0] == "one");
|
||||
|
||||
println("ALL OK");
|
||||
}
|
||||
|
||||
|
||||
/****************************************
|
||||
demo a bug in variable arguments
|
||||
fix at http://build.samba.org/build.pl?function=diff;tree=samba4;revision=7085
|
||||
status: FIXED
|
||||
*****************************************/
|
||||
function argsbug() {
|
||||
println("we should have been called with 3 arguments");
|
||||
assert(arguments.length == 3);
|
||||
assert(arguments[0] == "one");
|
||||
assert(arguments[1] == "two");
|
||||
assert(arguments[2] == "three");
|
||||
}
|
||||
|
||||
|
||||
/****************************************
|
||||
demo a bug in constructing objects
|
||||
no fix available yet
|
||||
status: SUBMITTED
|
||||
*****************************************/
|
||||
function MyObj() {
|
||||
var o = new Object();
|
||||
o.test = 42;
|
||||
return o;
|
||||
}
|
||||
|
||||
function objbug() {
|
||||
println("the docs say you should use 'new'");
|
||||
var o1 = new MyObj();
|
||||
var o2 = MyObj();
|
||||
printVars(o1);
|
||||
printVars(o2);
|
||||
assert(o1.test == 42);
|
||||
assert(o2.test == 42);
|
||||
}
|
||||
|
||||
/*
|
||||
demo a expression handling bug
|
||||
status: FIXED
|
||||
*/
|
||||
function exprbug() {
|
||||
var a = new Array(10);
|
||||
var i;
|
||||
for (i=0;i<4;i++) {
|
||||
a[1+(i*2)] = i;
|
||||
a[2+(i*2)] = i*2;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************
|
||||
demo lack of recursion
|
||||
fix in http://build.samba.org/build.pl?function=diff;tree=samba4;revision=7127
|
||||
status: FIXED
|
||||
*****************************************/
|
||||
function fibonacci(n) {
|
||||
if (n < 3) {
|
||||
return 1;
|
||||
}
|
||||
return fibonacci(n-1) + fibonacci(n-2);
|
||||
}
|
||||
|
||||
function recursebug() {
|
||||
println("First 10 fibonacci numbers:");
|
||||
for (i=0;i<10;i++) {
|
||||
println("fibonacci(" + i + ")=" + fibonacci(i));
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************
|
||||
demo lack of function variables inside functions
|
||||
status: FIXED IN SAMBA
|
||||
*****************************************/
|
||||
function callback()
|
||||
{
|
||||
return "testing";
|
||||
}
|
||||
|
||||
function fnbug(c)
|
||||
{
|
||||
s = c();
|
||||
assert(s == "testing");
|
||||
}
|
||||
|
||||
/****************************************
|
||||
demo incorrect handling of reserved words in strings
|
||||
status: SUBMITTED
|
||||
*****************************************/
|
||||
function reservedbug()
|
||||
{
|
||||
assert("funct" + "ion" == 'function');
|
||||
}
|
||||
|
||||
|
||||
/****************************************
|
||||
demo incorrect handling of boolean functions
|
||||
status: SUBMITTED
|
||||
*****************************************/
|
||||
function no()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
function boolbug()
|
||||
{
|
||||
assert(false == no());
|
||||
assert(!no());
|
||||
}
|
||||
|
||||
|
||||
/* run the tests */
|
||||
arraybug();
|
||||
argsbug("one", "two", "three");
|
||||
recursebug();
|
||||
exprbug();
|
||||
fnbug(callback);
|
||||
reservedbug();
|
||||
boolbug();
|
||||
objbug();
|
||||
Executable
+235
@@ -0,0 +1,235 @@
|
||||
#!/usr/bin/env smbscript
|
||||
/*
|
||||
test echo pipe calls from ejs
|
||||
*/
|
||||
|
||||
var options = GetOptions(ARGV,
|
||||
"POPT_AUTOHELP",
|
||||
"POPT_COMMON_SAMBA",
|
||||
"POPT_COMMON_CREDENTIALS");
|
||||
if (options == undefined) {
|
||||
println("Failed to parse options");
|
||||
return -1;
|
||||
}
|
||||
|
||||
libinclude("base.js");
|
||||
|
||||
/*
|
||||
generate a ramp as an integer array
|
||||
*/
|
||||
function ramp_array(N)
|
||||
{
|
||||
var a = new Array(N);
|
||||
var data = datablob_init();
|
||||
for (i=0;i<N;i++) {
|
||||
a[i] = i;
|
||||
}
|
||||
return data.blobFromArray(a);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
test the echo_AddOne interface
|
||||
*/
|
||||
function test_AddOne(echo)
|
||||
{
|
||||
var io = irpcObj();
|
||||
|
||||
print("Testing echo_AddOne\n");
|
||||
|
||||
for (i=0;i<10;i++) {
|
||||
io.input.in_data = i;
|
||||
status = echo.echo_AddOne(io);
|
||||
check_status_ok(status);
|
||||
assert(io.output.out_data == i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
test the echo_EchoData interface
|
||||
*/
|
||||
function test_EchoData(echo)
|
||||
{
|
||||
var io = irpcObj();
|
||||
|
||||
print("Testing echo_EchoData\n");
|
||||
|
||||
for (i=0; i<30; i=i+5) {
|
||||
io.input.len = i;
|
||||
io.input.in_data = ramp_array(i);
|
||||
status = echo.echo_EchoData(io);
|
||||
check_status_ok(status);
|
||||
assert(true == echo.blobCompare(io.input.in_data, io.output.out_data));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
test the echo_SinkData interface
|
||||
*/
|
||||
function test_SinkData(echo)
|
||||
{
|
||||
var io = irpcObj();
|
||||
|
||||
print("Testing echo_SinkData\n");
|
||||
|
||||
for (i=0; i<30; i=i+5) {
|
||||
io.input.len = i;
|
||||
io.input.data = ramp_array(i);
|
||||
status = echo.echo_SinkData(io);
|
||||
check_status_ok(status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
test the echo_SourceData interface
|
||||
*/
|
||||
function test_SourceData(echo)
|
||||
{
|
||||
var io = irpcObj();
|
||||
|
||||
print("Testing echo_SourceData\n");
|
||||
|
||||
for (i=0; i<30; i=i+5) {
|
||||
io.input.len = i;
|
||||
status = echo.echo_SourceData(io);
|
||||
check_status_ok(status);
|
||||
correct = ramp_array(i);
|
||||
assert(true == echo.blobCompare(correct, io.output.data));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
test the echo_TestCall interface
|
||||
*/
|
||||
function test_TestCall(echo)
|
||||
{
|
||||
var io = irpcObj();
|
||||
|
||||
print("Testing echo_TestCall\n");
|
||||
|
||||
io.input.s1 = "my test string";
|
||||
status = echo.echo_TestCall(io);
|
||||
check_status_ok(status);
|
||||
assert("this is a test string" == io.output.s2);
|
||||
}
|
||||
|
||||
/*
|
||||
test the echo_TestCall2 interface
|
||||
*/
|
||||
function test_TestCall2(echo)
|
||||
{
|
||||
var io = irpcObj();
|
||||
|
||||
print("Testing echo_TestCall2\n");
|
||||
|
||||
for (i=1;i<=7;i++) {
|
||||
io.input.level = i;
|
||||
status = echo.echo_TestCall2(io);
|
||||
check_status_ok(status);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
test the echo_TestSleep interface
|
||||
*/
|
||||
function test_TestSleep(echo)
|
||||
{
|
||||
var io = irpcObj();
|
||||
|
||||
print("Testing echo_TestSleep\n");
|
||||
|
||||
io.input.seconds = 1;
|
||||
status = echo.echo_TestSleep(io);
|
||||
check_status_ok(status);
|
||||
}
|
||||
|
||||
/*
|
||||
test the echo_TestEnum interface
|
||||
*/
|
||||
function test_TestEnum(echo)
|
||||
{
|
||||
var io = irpcObj();
|
||||
|
||||
print("Testing echo_TestEnum\n");
|
||||
|
||||
io.input.foo1 = echo.ECHO_ENUM1;
|
||||
io.input.foo2 = new Object();
|
||||
io.input.foo2.e1 = echo.ECHO_ENUM1;
|
||||
io.input.foo2.e2 = echo.ECHO_ENUM1_32;
|
||||
io.input.foo3 = new Object();
|
||||
io.input.foo3.e1 = echo.ECHO_ENUM2;
|
||||
status = echo.echo_TestEnum(io);
|
||||
check_status_ok(status);
|
||||
assert(io.output.foo1 == echo.ECHO_ENUM1);
|
||||
assert(io.output.foo2.e1 == echo.ECHO_ENUM2);
|
||||
assert(io.output.foo2.e2 == echo.ECHO_ENUM1_32);
|
||||
assert(io.output.foo3.e1 == echo.ECHO_ENUM2);
|
||||
}
|
||||
|
||||
/*
|
||||
test the echo_TestSurrounding interface
|
||||
*/
|
||||
function test_TestSurrounding(echo)
|
||||
{
|
||||
var io = irpcObj();
|
||||
|
||||
print("Testing echo_TestSurrounding\n");
|
||||
|
||||
io.input.data = new Object();
|
||||
io.input.data.x = 10;
|
||||
io.input.data.surrounding = new Array(10);
|
||||
status = echo.echo_TestSurrounding(io);
|
||||
check_status_ok(status);
|
||||
assert(io.output.data.surrounding.length == 20);
|
||||
check_array_zero(io.output.data.surrounding);
|
||||
}
|
||||
|
||||
/*
|
||||
test the echo_TestDoublePointer interface
|
||||
*/
|
||||
function test_TestDoublePointer(echo)
|
||||
{
|
||||
var io = irpcObj();
|
||||
|
||||
print("Testing echo_TestDoublePointer\n");
|
||||
|
||||
io.input.data = 7;
|
||||
status = echo.echo_TestDoublePointer(io);
|
||||
check_status_ok(status);
|
||||
assert(io.input.data == io.input.data);
|
||||
}
|
||||
|
||||
|
||||
if (options.ARGV.length != 1) {
|
||||
println("Usage: echo.js <BINDING>");
|
||||
return -1;
|
||||
}
|
||||
var binding = options.ARGV[0];
|
||||
var echo = rpcecho_init();
|
||||
datablob_init(echo);
|
||||
|
||||
print("Connecting to " + binding + "\n");
|
||||
status = echo.connect(binding);
|
||||
if (status.is_ok != true) {
|
||||
printf("Failed to connect to %s - %s\n", binding, status.errstr);
|
||||
return;
|
||||
}
|
||||
|
||||
test_AddOne(echo);
|
||||
test_EchoData(echo);
|
||||
test_SinkData(echo);
|
||||
test_SourceData(echo);
|
||||
|
||||
print("SKIPPING test_TestCall as pidl cannot generate code for it\n");
|
||||
/* test_TestCall(echo); */
|
||||
test_TestCall2(echo);
|
||||
test_TestSleep(echo);
|
||||
test_TestEnum(echo);
|
||||
test_TestSurrounding(echo);
|
||||
test_TestDoublePointer(echo);
|
||||
|
||||
println("All OK\n");
|
||||
return 0;
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env smbscript
|
||||
|
||||
var options = GetOptions(ARGV,
|
||||
"POPT_AUTOHELP",
|
||||
"POPT_COMMON_SAMBA",
|
||||
"POPT_COMMON_CREDENTIALS");
|
||||
if (options == undefined) {
|
||||
println("Failed to parse options");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (options.ARGV.length != 2) {
|
||||
println("Usage: ejsnet.js <DOMAIN> <NEW USER NAME>");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* use command line creds if available */
|
||||
var creds = options.get_credentials();
|
||||
|
||||
var ctx = NetContext(creds);
|
||||
var usr_ctx = ctx.UserMgr(options.ARGV[0]);
|
||||
if (usr_ctx == undefined) {
|
||||
println("Couldn't get user management context.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
var status = usr_ctx.Create(options.ARGV[1]);
|
||||
if (status.is_ok != true) {
|
||||
println("Failed to create user account " + options.ARGV[1] + ": " + status.errstr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
var status = usr_ctx.Delete(options.ARGV[1]);
|
||||
if (status.is_ok != true) {
|
||||
println("Failed to delete user account " + options.ARGV[1] + ": " + status.errstr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
print ("OK\n");
|
||||
return 0;
|
||||
Executable
+485
@@ -0,0 +1,485 @@
|
||||
#!/bin/sh
|
||||
exec smbscript "$0" ${1+"$@"}
|
||||
/*
|
||||
test certin LDAP behaviours
|
||||
*/
|
||||
|
||||
var ldb = ldb_init();
|
||||
var gc_ldb = ldb_init();
|
||||
|
||||
var options = GetOptions(ARGV,
|
||||
"POPT_AUTOHELP",
|
||||
"POPT_COMMON_SAMBA",
|
||||
"POPT_COMMON_CREDENTIALS");
|
||||
if (options == undefined) {
|
||||
println("Failed to parse options");
|
||||
return -1;
|
||||
}
|
||||
|
||||
libinclude("base.js");
|
||||
|
||||
if (options.ARGV.length != 1) {
|
||||
println("Usage: ldap.js <HOST>");
|
||||
return -1;
|
||||
}
|
||||
|
||||
var host = options.ARGV[0];
|
||||
|
||||
function basic_tests(ldb, gc_ldb, base_dn, configuration_dn)
|
||||
{
|
||||
println("Running basic tests");
|
||||
|
||||
ldb.del("cn=ldaptestuser,cn=users," + base_dn);
|
||||
|
||||
var ok = ldb.add("
|
||||
dn: cn=ldaptestuser,cn=users," + base_dn + "
|
||||
objectClass: user
|
||||
objectClass: person
|
||||
cn: LDAPtestUSER
|
||||
");
|
||||
if (!ok) {
|
||||
ok = ldb.del("cn=ldaptestuser,cn=users," + base_dn);
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
ok = ldb.add("
|
||||
dn: cn=ldaptestuser,cn=users," + base_dn + "
|
||||
objectClass: user
|
||||
objectClass: person
|
||||
cn: LDAPtestUSER
|
||||
");
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
}
|
||||
|
||||
var ok = ldb.add("
|
||||
dn: cn=ldaptestcomputer,cn=computers," + base_dn + "
|
||||
objectClass: computer
|
||||
cn: LDAPtestCOMPUTER
|
||||
");
|
||||
if (!ok) {
|
||||
ok = ldb.del("cn=ldaptestcomputer,cn=computers," + base_dn);
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
ok = ldb.add("
|
||||
dn: cn=ldaptestcomputer,cn=computers," + base_dn + "
|
||||
objectClass: computer
|
||||
cn: LDAPtestCOMPUTER
|
||||
");
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
}
|
||||
|
||||
var ok = ldb.add("
|
||||
dn: cn=ldaptest2computer,cn=computers," + base_dn + "
|
||||
objectClass: computer
|
||||
cn: LDAPtest2COMPUTER
|
||||
userAccountControl: 4096
|
||||
");
|
||||
if (!ok) {
|
||||
ok = ldb.del("cn=ldaptest2computer,cn=computers," + base_dn);
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
ok = ldb.add("
|
||||
dn: cn=ldaptest2computer,cn=computers," + base_dn + "
|
||||
objectClass: computer
|
||||
cn: LDAPtest2COMPUTER
|
||||
userAccountControl: 4096
|
||||
");
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
}
|
||||
|
||||
ok = ldb.add("
|
||||
dn: cn=ldaptestuser2,cn=users," + base_dn + "
|
||||
objectClass: person
|
||||
objectClass: user
|
||||
cn: LDAPtestUSER2
|
||||
");
|
||||
if (!ok) {
|
||||
ok = ldb.del("cn=ldaptestuser2,cn=users," + base_dn);
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
ok = ldb.add("
|
||||
dn: cn=ldaptestuser2,cn=users," + base_dn + "
|
||||
objectClass: person
|
||||
objectClass: user
|
||||
cn: LDAPtestUSER2
|
||||
");
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
}
|
||||
|
||||
ok = ldb.add("
|
||||
dn: cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn + "
|
||||
objectClass: user
|
||||
");
|
||||
if (!ok) {
|
||||
ok = ldb.del("cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn);
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
ok = ldb.add("
|
||||
dn: cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn + "
|
||||
objectClass: user
|
||||
");
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
}
|
||||
|
||||
ok = ldb.add("
|
||||
dn: cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn + "
|
||||
objectClass: user
|
||||
");
|
||||
if (!ok) {
|
||||
ok = ldb.del("cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn);
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
ok = ldb.add("
|
||||
dn: cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn + "
|
||||
objectClass: user
|
||||
");
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
}
|
||||
|
||||
println("Testing ldb.search for (&(cn=ldaptestuser)(objectClass=user))");
|
||||
var res = ldb.search("(&(cn=ldaptestuser)(objectClass=user))");
|
||||
if (res.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestuser)(objectClass=user))");
|
||||
assert(res.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == "cn=ldaptestuser,cn=users," + base_dn);
|
||||
assert(res[0].cn == "ldaptestuser");
|
||||
assert(res[0].name == "ldaptestuser");
|
||||
assert(res[0].objectClass[0] == "top");
|
||||
assert(res[0].objectClass[1] == "person");
|
||||
assert(res[0].objectClass[2] == "organizationalPerson");
|
||||
assert(res[0].objectClass[3] == "user");
|
||||
assert(res[0].objectGUID != undefined);
|
||||
assert(res[0].whenCreated != undefined);
|
||||
assert(res[0].objectCategory == "cn=Person,cn=Schema,cn=Configuration," + base_dn);
|
||||
assert(res[0].sAMAccountType == 805306368);
|
||||
// assert(res[0].userAccountControl == 546);
|
||||
|
||||
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 + "))");
|
||||
if (res2.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))");
|
||||
assert(res2.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == res2[0].dn);
|
||||
|
||||
println("Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon))");
|
||||
var res3 = ldb.search("(&(cn=ldaptestuser)(objectCategory=PerSon))");
|
||||
if (res3.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestuser)(objectCategory=PerSon))");
|
||||
assert(res3.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == res3[0].dn);
|
||||
|
||||
if (gc_ldb != undefined) {
|
||||
println("Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog");
|
||||
var res3gc = gc_ldb.search("(&(cn=ldaptestuser)(objectCategory=PerSon))");
|
||||
if (res3gc.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog");
|
||||
assert(res3gc.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == res3gc[0].dn);
|
||||
}
|
||||
|
||||
ok = ldb.del(res[0].dn);
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectClass=user))");
|
||||
var res = ldb.search("(&(cn=ldaptestcomputer)(objectClass=user))");
|
||||
if (res.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestuser)(objectClass=user))");
|
||||
assert(res.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == "cn=ldaptestcomputer,cn=computers," + base_dn);
|
||||
assert(res[0].cn == "ldaptestcomputer");
|
||||
assert(res[0].name == "ldaptestcomputer");
|
||||
assert(res[0].objectClass[0] == "top");
|
||||
assert(res[0].objectClass[1] == "person");
|
||||
assert(res[0].objectClass[2] == "organizationalPerson");
|
||||
assert(res[0].objectClass[3] == "user");
|
||||
assert(res[0].objectClass[4] == "computer");
|
||||
assert(res[0].objectGUID != undefined);
|
||||
assert(res[0].whenCreated != undefined);
|
||||
assert(res[0].objectCategory == "cn=Computer,cn=Schema,cn=Configuration," + base_dn);
|
||||
// assert(res[0].sAMAccountType == 805306368);
|
||||
// assert(res[0].userAccountControl == 546);
|
||||
|
||||
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 + "))");
|
||||
if (res2.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))");
|
||||
assert(res2.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == res2[0].dn);
|
||||
|
||||
if (gc_ldb != undefined) {
|
||||
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 + "))");
|
||||
if (res2gc.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + ")) in Global Catlog");
|
||||
assert(res2gc.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == res2gc[0].dn);
|
||||
}
|
||||
|
||||
println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER))");
|
||||
var res3 = ldb.search("(&(cn=ldaptestcomputer)(objectCategory=compuTER))");
|
||||
if (res3.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER))");
|
||||
assert(res3.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == res3[0].dn);
|
||||
|
||||
if (gc_ldb != undefined) {
|
||||
println("Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog");
|
||||
var res3gc = gc_ldb.search("(&(cn=ldaptestcomputer)(objectCategory=compuTER))");
|
||||
if (res3gc.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog");
|
||||
assert(res3gc.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == res3gc[0].dn);
|
||||
}
|
||||
|
||||
println("Testing ldb.search for (&(cn=ldaptestcomp*r)(objectCategory=compuTER))");
|
||||
var res4 = ldb.search("(&(cn=ldaptestcomp*r)(objectCategory=compuTER))");
|
||||
if (res4.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestcomp*r)(objectCategory=compuTER))");
|
||||
assert(res4.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == res4[0].dn);
|
||||
|
||||
println("Testing ldb.search for (&(cn=ldaptestcomput*)(objectCategory=compuTER))");
|
||||
var res5 = ldb.search("(&(cn=ldaptestcomput*)(objectCategory=compuTER))");
|
||||
if (res5.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestcomput*)(objectCategory=compuTER))");
|
||||
assert(res5.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == res5[0].dn);
|
||||
|
||||
println("Testing ldb.search for (&(cn=*daptestcomputer)(objectCategory=compuTER))");
|
||||
var res6 = ldb.search("(&(cn=*daptestcomputer)(objectCategory=compuTER))");
|
||||
if (res6.length != 1) {
|
||||
println("Could not find (&(cn=*daptestcomputer)(objectCategory=compuTER))");
|
||||
assert(res6.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == res6[0].dn);
|
||||
|
||||
ok = ldb.del(res[0].dn);
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
println("Testing ldb.search for (&(cn=ldaptest2computer)(objectClass=user))");
|
||||
var res = ldb.search("(&(cn=ldaptest2computer)(objectClass=user))");
|
||||
if (res.length != 1) {
|
||||
println("Could not find (&(cn=ldaptest2computer)(objectClass=user))");
|
||||
assert(res.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == "cn=ldaptest2computer,cn=computers," + base_dn);
|
||||
assert(res[0].cn == "ldaptest2computer");
|
||||
assert(res[0].name == "ldaptest2computer");
|
||||
assert(res[0].objectClass[0] == "top");
|
||||
assert(res[0].objectClass[1] == "person");
|
||||
assert(res[0].objectClass[2] == "organizationalPerson");
|
||||
assert(res[0].objectClass[3] == "user");
|
||||
assert(res[0].objectClass[4] == "computer");
|
||||
assert(res[0].objectGUID != undefined);
|
||||
assert(res[0].whenCreated != undefined);
|
||||
assert(res[0].objectCategory == "cn=Computer,cn=Schema,cn=Configuration," + base_dn);
|
||||
assert(res[0].sAMAccountType == 805306369);
|
||||
// assert(res[0].userAccountControl == 4098);
|
||||
|
||||
|
||||
println("Testing ldb.search for (&(cn=ldaptestUSer2)(objectClass=user))");
|
||||
var res = ldb.search("(&(cn=ldaptestUSer2)(objectClass=user))");
|
||||
if (res.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestUSer2)(objectClass=user))");
|
||||
assert(res.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == "cn=ldaptestuser2,cn=users," + base_dn);
|
||||
assert(res[0].cn == "ldaptestuser2");
|
||||
assert(res[0].name == "ldaptestuser2");
|
||||
assert(res[0].objectClass[0] == "top");
|
||||
assert(res[0].objectClass[1] == "person");
|
||||
assert(res[0].objectClass[2] == "organizationalPerson");
|
||||
assert(res[0].objectClass[3] == "user");
|
||||
assert(res[0].objectGUID != undefined);
|
||||
assert(res[0].whenCreated != undefined);
|
||||
|
||||
ok = ldb.del(res[0].dn);
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
println("Testing ldb.search for (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))");
|
||||
var res = ldb.search("(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))");
|
||||
|
||||
if (res.length != 1) {
|
||||
println("Could not find (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))");
|
||||
assert(res.length == 1);
|
||||
}
|
||||
|
||||
assert(res[0].dn == "cn=ldaptestutf8user èùéìòà,cn=users," + base_dn);
|
||||
assert(res[0].cn == "ldaptestutf8user èùéìòà");
|
||||
assert(res[0].name == "ldaptestutf8user èùéìòà");
|
||||
assert(res[0].objectClass[0] == "top");
|
||||
assert(res[0].objectClass[1] == "person");
|
||||
assert(res[0].objectClass[2] == "organizationalPerson");
|
||||
assert(res[0].objectClass[3] == "user");
|
||||
assert(res[0].objectGUID != undefined);
|
||||
assert(res[0].whenCreated != undefined);
|
||||
|
||||
ok = ldb.del(res[0].dn);
|
||||
if (!ok) {
|
||||
println(ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
println("Testing ldb.search for (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))");
|
||||
var res = ldb.search("(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))");
|
||||
|
||||
if (res.length != 1) {
|
||||
println("Could not find (expect space collapse, win2k3 fails) (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))");
|
||||
} else {
|
||||
assert(res[0].dn == "cn=ldaptestutf8user2 èùéìòà,cn=users," + base_dn);
|
||||
assert(res[0].cn == "ldaptestutf8user2 èùéìòà");
|
||||
}
|
||||
|
||||
println("Testing that we can't get at the configuration DN from the main search base");
|
||||
var attrs = new Array("cn");
|
||||
var res = ldb.search("objectClass=crossRef", base_dn, ldb.SCOPE_SUBTREE, attrs);
|
||||
assert (res.length == 0);
|
||||
|
||||
if (gc_ldb != undefined) {
|
||||
println("Testing that we do find configuration elements in the global catlog");
|
||||
var attrs = new Array("cn");
|
||||
var res = gc_ldb.search("objectClass=crossRef", base_dn, ldb.SCOPE_SUBTREE, attrs);
|
||||
assert (res.length > 0);
|
||||
|
||||
println("Testing that we do find configuration elements and user elements at the same time");
|
||||
var attrs = new Array("cn");
|
||||
var res = gc_ldb.search("(|(objectClass=crossRef)(objectClass=person))", base_dn, ldb.SCOPE_SUBTREE, attrs);
|
||||
assert (res.length > 0);
|
||||
|
||||
println("Testing that we do find configuration elements in the global catlog, with the configuration basedn");
|
||||
var attrs = new Array("cn");
|
||||
var res = gc_ldb.search("objectClass=crossRef", configuration_dn, ldb.SCOPE_SUBTREE, attrs);
|
||||
assert (res.length > 0);
|
||||
}
|
||||
|
||||
println("Testing that we can get at the configuration DN on the main LDAP port");
|
||||
var attrs = new Array("cn");
|
||||
var res = ldb.search("objectClass=crossRef", configuration_dn, ldb.SCOPE_SUBTREE, attrs);
|
||||
assert (res.length > 0);
|
||||
|
||||
}
|
||||
|
||||
function basedn_tests(ldb, gc_ldb)
|
||||
{
|
||||
println("Testing for all rootDSE attributes");
|
||||
var attrs = new Array();
|
||||
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
|
||||
assert(res.length == 1);
|
||||
|
||||
println("Testing for highestCommittedUSN");
|
||||
var attrs = new Array("highestCommittedUSN");
|
||||
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
|
||||
assert(res.length == 1);
|
||||
assert(res[0].highestCommittedUSN != undefined);
|
||||
assert(res[0].highestCommittedUSN != 0);
|
||||
|
||||
println("Testing for netlogon via LDAP");
|
||||
var attrs = new Array("netlogon");
|
||||
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
|
||||
assert(res.length == 0);
|
||||
|
||||
println("Testing for netlogon and highestCommittedUSN via LDAP");
|
||||
var attrs = new Array("netlogon", "highestCommittedUSN");
|
||||
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
|
||||
assert(res.length == 0);
|
||||
}
|
||||
|
||||
function find_basedn(ldb)
|
||||
{
|
||||
var attrs = new Array("defaultNamingContext");
|
||||
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
|
||||
assert(res.length == 1);
|
||||
return res[0].defaultNamingContext;
|
||||
}
|
||||
|
||||
function find_configurationdn(ldb)
|
||||
{
|
||||
var attrs = new Array("configurationNamingContext");
|
||||
var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
|
||||
assert(res.length == 1);
|
||||
return res[0].configurationNamingContext;
|
||||
}
|
||||
|
||||
/* use command line creds if available */
|
||||
ldb.credentials = options.get_credentials();
|
||||
gc_ldb.credentials = options.get_credentials();
|
||||
|
||||
var ok = ldb.connect("ldap://" + host);
|
||||
var base_dn = find_basedn(ldb);
|
||||
var configuration_dn = find_configurationdn(ldb);
|
||||
|
||||
printf("baseDN: %s\n", base_dn);
|
||||
|
||||
var ok = gc_ldb.connect("ldap://" + host + ":3268");
|
||||
if (!ok) {
|
||||
gc_ldb = undefined;
|
||||
}
|
||||
|
||||
basic_tests(ldb, gc_ldb, base_dn, configuration_dn)
|
||||
|
||||
basedn_tests(ldb, gc_ldb)
|
||||
|
||||
return 0;
|
||||
Executable
+381
@@ -0,0 +1,381 @@
|
||||
#!/bin/sh
|
||||
exec smbscript "$0" ${1+"$@"}
|
||||
/*
|
||||
demonstrate access to ldb databases from ejs
|
||||
*/
|
||||
|
||||
|
||||
var ldb = ldb_init();
|
||||
var sys;
|
||||
var options = GetOptions(ARGV,
|
||||
"POPT_AUTOHELP",
|
||||
"POPT_COMMON_SAMBA");
|
||||
if (options == undefined) {
|
||||
println("Failed to parse options");
|
||||
return -1;
|
||||
}
|
||||
|
||||
libinclude("base.js");
|
||||
|
||||
if (options.ARGV.length != 1) {
|
||||
println("Usage: ldb.js <prefix>");
|
||||
return -1;
|
||||
}
|
||||
|
||||
prefix = options.ARGV[0];
|
||||
|
||||
function basic_tests(ldb)
|
||||
{
|
||||
println("Running basic tests");
|
||||
ok = ldb.add("
|
||||
dn: cn=x,cn=test
|
||||
objectClass: foo
|
||||
x: 3
|
||||
");
|
||||
assert(ok);
|
||||
|
||||
println("Testing ldb.search");
|
||||
var res = ldb.search("(objectClass=*)");
|
||||
assert(res[0].objectClass[0] == "foo");
|
||||
assert(res[0].dn == "cn=x,cn=test");
|
||||
assert(res[0].x == 3);
|
||||
|
||||
ok = ldb.add("
|
||||
dn: cn=x2,cn=test
|
||||
objectClass: foo
|
||||
x: 4
|
||||
");
|
||||
assert(ok);
|
||||
var attrs = new Array("x");
|
||||
res = ldb.search("x=4", NULL, ldb.SCOPE_DEFAULT, attrs);
|
||||
assert(res[0].x == 4);
|
||||
assert(res[0].objectClass == undefined);
|
||||
assert(res[0].dn == "cn=x2,cn=test");
|
||||
|
||||
ok = ldb.del("cn=x,cn=test");
|
||||
assert(ok);
|
||||
|
||||
ok = ldb.rename("cn=x2,cn=test", "cn=x3,cn=test");
|
||||
assert(ok);
|
||||
res = ldb.search("x=4", NULL, ldb.SCOPE_DEFAULT, attrs);
|
||||
assert(res[0].dn == "cn=x3,cn=test");
|
||||
|
||||
ok = ldb.modify("
|
||||
dn: cn=x3,cn=test
|
||||
changetype: modify
|
||||
add: x
|
||||
x: 7
|
||||
");
|
||||
|
||||
res = ldb.search("x=7");
|
||||
assert(res.length == 1);
|
||||
assert(res[0].x.length == 2);
|
||||
|
||||
/* Check a few things before we add modules */
|
||||
assert(res[0].objectGUID == undefined);
|
||||
assert(res[0].createTimestamp == undefined);
|
||||
assert(res[0].whenCreated == undefined);
|
||||
|
||||
}
|
||||
|
||||
function setup_modules(ldb)
|
||||
{
|
||||
ok = ldb.add("
|
||||
dn: @MODULES
|
||||
@LIST: rootdse,operational,rdn_name,partition
|
||||
|
||||
dn: cn=ROOTDSE
|
||||
defaultNamingContext: cn=Test
|
||||
|
||||
dn: @PARTITION
|
||||
partition: cn=SideTest:" + prefix + "/" + "testside.ldb
|
||||
partition: cn=Sub,cn=PartTest:" + prefix + "/" + "testsub.ldb
|
||||
partition: cn=PartTest:" + prefix + "/" + "testpartition.ldb
|
||||
partition: cn=Sub,cn=Sub,cn=PartTest:" + prefix + "/" + "testsubsub.ldb
|
||||
replicateEntries: @SUBCLASSES
|
||||
replicateEntries: @ATTRIBUTES
|
||||
replicateEntries: @INDEXLIST
|
||||
modules: cn=PartTest:objectguid
|
||||
");
|
||||
}
|
||||
|
||||
/* Test the basic operation of the timestamps,objectguid and name_rdn
|
||||
modules */
|
||||
|
||||
function modules_test(ldb, parttestldb)
|
||||
{
|
||||
println("Running modules tests");
|
||||
|
||||
ok = ldb.add("
|
||||
dn: @ATTRIBUTES
|
||||
cn: CASE_INSENSITIVE
|
||||
caseattr: CASE_INSENSITIVE
|
||||
");
|
||||
if (!ok) {
|
||||
println("Failed to add: " + ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
/* Confirm that the attributes were replicated */
|
||||
var res_attrs = parttestldb.search("cn=*", "@ATTRIBUTES", parttestldb.SCOPE_BASE);
|
||||
assert(res_attrs[0].cn == "CASE_INSENSITIVE");
|
||||
|
||||
ok = ldb.add("
|
||||
dn: cn=x8,cn=PartTest
|
||||
objectClass: foo
|
||||
x: 8
|
||||
");
|
||||
if (!ok) {
|
||||
println("Failed to add: " + ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
ok = ldb.add("
|
||||
dn: cn=x9,cn=PartTest
|
||||
objectClass: foo
|
||||
x: 9
|
||||
cn: X9
|
||||
");
|
||||
if (!ok) {
|
||||
println("Failed to add: " + ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
ok = ldb.add("
|
||||
dn: cn=X9,cn=PartTest
|
||||
objectClass: foo
|
||||
x: 9
|
||||
cn: X9
|
||||
");
|
||||
if (ok) {
|
||||
println("Should have failed to add cn=X9,cn=PartTest");
|
||||
assert(!ok);
|
||||
}
|
||||
|
||||
var res = ldb.search("x=8", "cn=PartTest", ldb.SCOPE_DEFAULT);
|
||||
assert(res[0].objectGUID != undefined);
|
||||
assert(res[0].uSNCreated != undefined);
|
||||
assert(res[0].uSNChanged != undefined);
|
||||
assert(res[0].createTimestamp == undefined);
|
||||
assert(res[0].whenCreated != undefined);
|
||||
assert(res[0].name == "x8");
|
||||
assert(res[0].cn == "x8");
|
||||
|
||||
/* Confirm that this ended up in the correct LDB */
|
||||
var res_otherldb = parttestldb.search("x=8", "cn=PartTest", parttestldb.SCOPE_DEFAULT);
|
||||
assert(res_otherldb[0].objectGUID != undefined);
|
||||
assert(res_otherldb[0].createTimestamp == undefined);
|
||||
assert(res_otherldb[0].whenCreated != undefined);
|
||||
assert(res_otherldb[0].name == "x8");
|
||||
assert(res_otherldb[0].cn == "x8");
|
||||
|
||||
var attrs = new Array("*", "createTimestamp");
|
||||
var res2 = ldb.search("x=9", "cn=PartTest", ldb.SCOPE_DEFAULT, attrs);
|
||||
assert(res2[0].objectGUID != undefined);
|
||||
assert(res2[0].createTimestamp != undefined);
|
||||
assert(res2[0].whenCreated != undefined);
|
||||
assert(res2[0].name == "x9");
|
||||
assert(res2[0].cn == "x9");
|
||||
|
||||
assert(res[0].objectGUID != res2[0].objectGUID);
|
||||
|
||||
var attrs = new Array("*");
|
||||
var res3 = ldb.search("", "", ldb.SCOPE_BASE, attrs);
|
||||
assert(res3[0].cn == undefined);
|
||||
assert(res3[0].distinguishedName == undefined);
|
||||
assert(res3[0].name == undefined);
|
||||
assert(res3[0].currentTime != undefined);
|
||||
assert(res3[0].highestCommittedUSN != undefined);
|
||||
|
||||
assert(res3[0].namingContexts[0] == "cn=Sub,cn=Sub,cn=PartTest");
|
||||
assert(res3[0].namingContexts[1] == "cn=Sub,cn=PartTest");
|
||||
assert(res3[0].namingContexts[2] == "cn=PartTest");
|
||||
assert(res3[0].namingContexts[3] == "cn=SideTest");
|
||||
var usn = res3[0].highestCommittedUSN;
|
||||
|
||||
/* Start a transaction. We are going to abort it later, to
|
||||
* show we clean up all partitions */
|
||||
|
||||
ok = ldb.transaction_start()
|
||||
if (!ok) {
|
||||
println("Failed to start a transaction: " + ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
|
||||
ok = ldb.add("
|
||||
dn: cn=x10,cn=parttest
|
||||
objectClass: foo
|
||||
x: 10
|
||||
");
|
||||
if (!ok) {
|
||||
println("Failed to add: " + ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
var attrs = new Array("highestCommittedUSN");
|
||||
var res4 = ldb.search("", "", ldb.SCOPE_BASE, attrs);
|
||||
var usn2 = res4[0].highestCommittedUSN;
|
||||
assert(usn < res4[0].highestCommittedUSN);
|
||||
|
||||
ok = ldb.add("
|
||||
dn: cn=x11,cn=sub,cn=parttest
|
||||
objectClass: foo
|
||||
x: 11
|
||||
");
|
||||
if (!ok) {
|
||||
println("Failed to add: " + ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
var attrs = new Array("highestCommittedUSN");
|
||||
var res5 = ldb.search("", "", ldb.SCOPE_BASE, attrs);
|
||||
assert(usn2 < res5[0].highestCommittedUSN);
|
||||
|
||||
var attrs = new Array("*", "createTimestamp");
|
||||
var res6 = ldb.search("x=11", "cn=parttest", ldb.SCOPE_SUB, attrs);
|
||||
assert(res6.length == 0);
|
||||
|
||||
var attrs = new Array("*", "createTimestamp");
|
||||
var res7 = ldb.search("x=10", "cn=sub,cn=parttest", ldb.SCOPE_DEFAULT, attrs);
|
||||
assert(res7.length == 0);
|
||||
|
||||
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[0].uSNCreated == undefined); /* The objectGUID module is not loaded here */
|
||||
assert(res8[0].name == "x11");
|
||||
assert(res8[0].cn == "x11");
|
||||
|
||||
ok = ldb.add("
|
||||
dn: caseattr=XY,cn=PartTest
|
||||
objectClass: foo
|
||||
x: Y
|
||||
");
|
||||
if (!ok) {
|
||||
println("Failed to add: " + ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
ok = ldb.add("
|
||||
dn: caseattr=XZ,cn=PartTest
|
||||
objectClass: foo
|
||||
x: Z
|
||||
caseattr: XZ
|
||||
");
|
||||
if (!ok) {
|
||||
println("Failed to add: " + ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
ok = ldb.add("
|
||||
dn: caseattr=xz,cn=PartTest
|
||||
objectClass: foo
|
||||
x: Z
|
||||
caseattr: xz
|
||||
");
|
||||
if (ok) {
|
||||
println("Should have failed to add caseattr=xz,cn=PartTest");
|
||||
assert(!ok);
|
||||
}
|
||||
|
||||
ok = ldb.add("
|
||||
dn: caseattr2=XZ,cn=PartTest
|
||||
objectClass: foo
|
||||
x: Z
|
||||
caseattr2: XZ
|
||||
");
|
||||
if (!ok) {
|
||||
println("Failed to add: " + ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
ok = ldb.add("
|
||||
dn: caseattr2=Xz,cn=PartTest
|
||||
objectClass: foo
|
||||
x: Z
|
||||
caseattr2: Xz
|
||||
");
|
||||
if (!ok) {
|
||||
println("Failed to add: " + ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
var resX = ldb.search("caseattr=xz", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
|
||||
assert(resX.length == 1);
|
||||
assert(resX[0].objectGUID != undefined);
|
||||
assert(resX[0].createTimestamp != undefined);
|
||||
assert(resX[0].whenCreated != undefined);
|
||||
assert(resX[0].name == "XZ");
|
||||
|
||||
var rescount = ldb.search("(|(caseattr=*)(cn=*))", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
|
||||
assert(rescount.length == 5);
|
||||
|
||||
/* Check this attribute is *not* case sensitive */
|
||||
var resXcount = ldb.search("caseattr=x*", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
|
||||
assert(resXcount.length == 2);
|
||||
|
||||
/* Check that this attribute *is* case sensitive */
|
||||
var resXcount2 = ldb.search("caseattr2=xz", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
|
||||
assert(resXcount2.length == 0);
|
||||
|
||||
|
||||
/* Now abort the transaction to show that even with
|
||||
* partitions, it is aborted everywhere */
|
||||
ok = ldb.transaction_cancel();
|
||||
if (!ok) {
|
||||
println("Failed to cancel a transaction: " + ldb.errstring());
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
/* now check it all went away */
|
||||
|
||||
var attrs = new Array("highestCommittedUSN");
|
||||
var res9 = ldb.search("", "", ldb.SCOPE_BASE, attrs);
|
||||
assert(usn == res9[0].highestCommittedUSN);
|
||||
|
||||
var attrs = new Array("*");
|
||||
var res10 = ldb.search("x=11", "cn=sub,cn=parttest", ldb.SCOPE_DEFAULT, attrs);
|
||||
assert(res10.length == 0);
|
||||
|
||||
var attrs = new Array("*");
|
||||
var res11 = ldb.search("x=10", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
|
||||
assert(res11.length == 0);
|
||||
|
||||
var attrs = new Array("*");
|
||||
var res12 = ldb.search("caseattr=*", "cn=parttest", ldb.SCOPE_DEFAULT, attrs);
|
||||
assert(res12.length == 0);
|
||||
|
||||
}
|
||||
|
||||
sys = sys_init();
|
||||
var dbfile = "test.ldb";
|
||||
|
||||
sys.unlink(prefix + "/" + dbfile);
|
||||
sys.unlink(prefix + "/" + "testpartition.ldb");
|
||||
sys.unlink(prefix + "/" + "testsub.ldb");
|
||||
sys.unlink(prefix + "/" + "testsubsub.ldb");
|
||||
sys.unlink(prefix + "/" + "testside.ldb");
|
||||
|
||||
var ok = ldb.connect("tdb://" + prefix + "/" + dbfile);
|
||||
assert(ok);
|
||||
|
||||
basic_tests(ldb);
|
||||
|
||||
setup_modules(ldb);
|
||||
ldb = ldb_init();
|
||||
var ok = ldb.connect("tdb://" + prefix + "/" + dbfile);
|
||||
assert(ok);
|
||||
|
||||
parttestldb = ldb_init();
|
||||
var ok = parttestldb.connect("tdb://" + prefix + "/" + "testpartition.ldb");
|
||||
assert(ok);
|
||||
|
||||
modules_test(ldb, parttestldb);
|
||||
|
||||
sys.unlink(prefix + "/" + dbfile);
|
||||
sys.unlink(prefix + "/" + "testpartition.ldb");
|
||||
sys.unlink(prefix + "/" + "testsub.ldb");
|
||||
sys.unlink(prefix + "/" + "testsubsub.ldb");
|
||||
sys.unlink(prefix + "/" + "testside.ldb");
|
||||
return 0;
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
demonstrate access to loadparm functions from ejs
|
||||
*/
|
||||
|
||||
loadparm_init(local);
|
||||
|
||||
function showParameter(name) {
|
||||
print(name + ": ");
|
||||
printVars(get(name));
|
||||
}
|
||||
|
||||
for (v in ARGV) {
|
||||
showParameter(ARGV[v]);
|
||||
}
|
||||
|
||||
print("defined services: ");
|
||||
printVars(services());
|
||||
|
||||
showParameter("server services");
|
||||
showParameter("netbios name");
|
||||
showParameter("security");
|
||||
showParameter("workgroup");
|
||||
showParameter("log level");
|
||||
showParameter("server signing");
|
||||
showParameter("interfaces");
|
||||
Executable
+761
@@ -0,0 +1,761 @@
|
||||
#!/bin/sh
|
||||
exec smbscript "$0" ${1+"$@"}
|
||||
/*
|
||||
work out the minimal schema for a set of objectclasses
|
||||
*/
|
||||
|
||||
libinclude("base.js");
|
||||
|
||||
var ldb = ldb_init();
|
||||
|
||||
var options = GetOptions(ARGV,
|
||||
"POPT_AUTOHELP",
|
||||
"POPT_COMMON_SAMBA",
|
||||
"POPT_COMMON_CREDENTIALS",
|
||||
"verbose");
|
||||
if (options == undefined) {
|
||||
println("Failed to parse options");
|
||||
return -1;
|
||||
}
|
||||
verbose = options["verbose"];
|
||||
|
||||
if (options.ARGV.length != 2) {
|
||||
println("Usage: minschema.js <URL> <classfile>");
|
||||
return -1;
|
||||
}
|
||||
|
||||
var url = options.ARGV[0];
|
||||
var classfile = options.ARGV[1];
|
||||
|
||||
/* use command line creds if available */
|
||||
ldb.credentials = options.get_credentials();
|
||||
|
||||
var ok = ldb.connect(url);
|
||||
assert(ok);
|
||||
|
||||
objectclasses = new Object();
|
||||
attributes = new Object();
|
||||
rootDse = new Object();
|
||||
|
||||
objectclasses_expanded = new Object();
|
||||
|
||||
/* the attributes we need for objectclasses */
|
||||
class_attrs = new Array("objectClass",
|
||||
"auxiliaryClass", "systemAuxiliaryClass",
|
||||
"possSuperiors", "systemPossSuperiors",
|
||||
"lDAPDisplayName", "governsID",
|
||||
"rDNAttID", "mustContain", "systemMustContain",
|
||||
"mayContain", "systemMayContain",
|
||||
"objectClassCategory", "subClassOf",
|
||||
"defaultObjectCategory", "defaultHidingValue",
|
||||
"systemFlags", "systemOnly", "defaultSecurityDescriptor",
|
||||
"objectCategory", "possibleInferiors", "displaySpecification",
|
||||
"schemaIDGUID");
|
||||
|
||||
attrib_attrs = new Array("objectClass", "lDAPDisplayName",
|
||||
"isSingleValued", "linkID", "systemFlags", "systemOnly",
|
||||
"schemaIDGUID", "adminDisplayName", "attributeID",
|
||||
"attributeSyntax", "oMSyntax", "oMObjectClass");
|
||||
|
||||
/*
|
||||
notes:
|
||||
|
||||
objectClassCategory
|
||||
1: structural
|
||||
2: abstract
|
||||
3: auxiliary
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
print only if verbose is set
|
||||
*/
|
||||
function dprintf() {
|
||||
if (verbose != undefined) {
|
||||
print(vsprintf(arguments));
|
||||
}
|
||||
}
|
||||
|
||||
function get_object_cn(ldb, name) {
|
||||
var attrs = new Array("cn");
|
||||
|
||||
var res = ldb.search(sprintf("(ldapDisplayName=%s)", name), rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs);
|
||||
assert(res != undefined);
|
||||
assert(res.length == 1);
|
||||
|
||||
var cn = res[0]["cn"];
|
||||
assert(cn != undefined);
|
||||
if (typeof(cn) == "string") {
|
||||
return cn;
|
||||
}
|
||||
return cn[0];
|
||||
}
|
||||
/*
|
||||
create an objectclass object
|
||||
*/
|
||||
function obj_objectClass(ldb, name) {
|
||||
var o = new Object();
|
||||
o.name = name;
|
||||
o.cn = get_object_cn(ldb, name);
|
||||
return o;
|
||||
}
|
||||
|
||||
/*
|
||||
create an attribute object
|
||||
*/
|
||||
function obj_attribute(ldb, name) {
|
||||
var o = new Object();
|
||||
o.name = name;
|
||||
o.cn = get_object_cn(ldb, name);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
syntaxmap = new Object();
|
||||
|
||||
syntaxmap['2.5.5.1'] = '1.3.6.1.4.1.1466.115.121.1.12';
|
||||
syntaxmap['2.5.5.2'] = '1.3.6.1.4.1.1466.115.121.1.38';
|
||||
syntaxmap['2.5.5.3'] = '1.2.840.113556.1.4.1362';
|
||||
syntaxmap['2.5.5.4'] = '1.2.840.113556.1.4.905';
|
||||
syntaxmap['2.5.5.5'] = '1.3.6.1.4.1.1466.115.121.1.26';
|
||||
syntaxmap['2.5.5.6'] = '1.3.6.1.4.1.1466.115.121.1.36';
|
||||
syntaxmap['2.5.5.7'] = '1.2.840.113556.1.4.903';
|
||||
syntaxmap['2.5.5.8'] = '1.3.6.1.4.1.1466.115.121.1.7';
|
||||
syntaxmap['2.5.5.9'] = '1.3.6.1.4.1.1466.115.121.1.27';
|
||||
syntaxmap['2.5.5.10'] = '1.3.6.1.4.1.1466.115.121.1.40';
|
||||
syntaxmap['2.5.5.11'] = '1.3.6.1.4.1.1466.115.121.1.24';
|
||||
syntaxmap['2.5.5.12'] = '1.3.6.1.4.1.1466.115.121.1.15';
|
||||
syntaxmap['2.5.5.13'] = '1.3.6.1.4.1.1466.115.121.1.43';
|
||||
syntaxmap['2.5.5.14'] = '1.2.840.113556.1.4.904';
|
||||
syntaxmap['2.5.5.15'] = '1.2.840.113556.1.4.907';
|
||||
syntaxmap['2.5.5.16'] = '1.2.840.113556.1.4.906';
|
||||
syntaxmap['2.5.5.17'] = '1.3.6.1.4.1.1466.115.121.1.40';
|
||||
|
||||
/*
|
||||
map some attribute syntaxes from some apparently MS specific
|
||||
syntaxes to the standard syntaxes
|
||||
*/
|
||||
function map_attribute_syntax(s) {
|
||||
if (syntaxmap[s] != undefined) {
|
||||
return syntaxmap[s];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
fix a string DN to use ${BASEDN}
|
||||
*/
|
||||
function fix_dn(dn) {
|
||||
var s = strstr(dn, rootDse.defaultNamingContext);
|
||||
if (s == NULL) {
|
||||
return dn;
|
||||
}
|
||||
return substr(dn, 0, strlen(dn) - strlen(s)) + "${BASEDN}";
|
||||
}
|
||||
|
||||
/*
|
||||
dump an object as ldif
|
||||
*/
|
||||
function write_ldif_one(o, attrs) {
|
||||
var i;
|
||||
printf("dn: CN=%s,CN=Schema,CN=Configuration,${BASEDN}\n", o.cn);
|
||||
printf("cn: %s\n", o.cn);
|
||||
printf("name: %s\n", o.cn);
|
||||
for (i=0;i<attrs.length;i++) {
|
||||
var a = attrs[i];
|
||||
if (o[a] == undefined) {
|
||||
continue;
|
||||
}
|
||||
/* special case for oMObjectClass, which is a binary object */
|
||||
if (a == "oMObjectClass") {
|
||||
printf("%s:: %s\n", a, o[a]);
|
||||
continue;
|
||||
}
|
||||
var v = o[a];
|
||||
if (typeof(v) == "string") {
|
||||
v = new Array(v);
|
||||
}
|
||||
var j;
|
||||
for (j=0;j<v.length;j++) {
|
||||
printf("%s: %s\n", a, fix_dn(v[j]));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/*
|
||||
dump an array of objects as ldif
|
||||
*/
|
||||
function write_ldif(o, attrs) {
|
||||
var i;
|
||||
for (i in o) {
|
||||
write_ldif_one(o[i], attrs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
create a testDN based an an example DN
|
||||
the idea is to ensure we obey any structural rules
|
||||
*/
|
||||
function create_testdn(exampleDN) {
|
||||
var a = split(",", exampleDN);
|
||||
a[0] = "CN=TestDN";
|
||||
return join(",", a);
|
||||
}
|
||||
|
||||
/*
|
||||
find the properties of an objectclass
|
||||
*/
|
||||
function find_objectclass_properties(ldb, o) {
|
||||
var res = ldb.search(
|
||||
sprintf("(ldapDisplayName=%s)", o.name),
|
||||
rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, class_attrs);
|
||||
assert(res != undefined);
|
||||
assert(res.length == 1);
|
||||
var msg = res[0];
|
||||
var a;
|
||||
for (a in msg) {
|
||||
o[a] = msg[a];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
find the properties of an attribute
|
||||
*/
|
||||
function find_attribute_properties(ldb, o) {
|
||||
var res = ldb.search(
|
||||
sprintf("(ldapDisplayName=%s)", o.name),
|
||||
rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrib_attrs);
|
||||
assert(res != undefined);
|
||||
assert(res.length == 1);
|
||||
var msg = res[0];
|
||||
var a;
|
||||
for (a in msg) {
|
||||
/* special case for oMObjectClass, which is a binary object */
|
||||
if (a == "oMObjectClass") {
|
||||
o[a] = ldb.encode(msg[a]);
|
||||
continue;
|
||||
}
|
||||
o[a] = msg[a];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
find the auto-created properties of an objectclass. Only works for classes
|
||||
that can be created using just a DN and the objectclass
|
||||
*/
|
||||
function find_objectclass_auto(ldb, o) {
|
||||
if (o["exampleDN"] == undefined) {
|
||||
return;
|
||||
}
|
||||
var testdn = create_testdn(o.exampleDN);
|
||||
var ok;
|
||||
|
||||
dprintf("testdn is '%s'\n", testdn);
|
||||
|
||||
var ldif = "dn: " + testdn;
|
||||
ldif = ldif + "\nobjectClass: " + o.name;
|
||||
ok = ldb.add(ldif);
|
||||
if (!ok) {
|
||||
dprintf("error adding %s: %s\n", o.name, ldb.errstring());
|
||||
dprintf("%s\n", ldif);
|
||||
return;
|
||||
}
|
||||
|
||||
var res = ldb.search("", testdn, ldb.SCOPE_BASE);
|
||||
ok = ldb.del(testdn);
|
||||
assert(ok);
|
||||
|
||||
var a;
|
||||
for (a in res[0]) {
|
||||
attributes[a].autocreate = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
look at auxiliary information from a class to intuit the existance of more
|
||||
classes needed for a minimal schema
|
||||
*/
|
||||
function expand_objectclass(ldb, o) {
|
||||
var attrs = new Array("auxiliaryClass", "systemAuxiliaryClass",
|
||||
"possSuperiors", "systemPossSuperiors",
|
||||
"subClassOf");
|
||||
var res = ldb.search(
|
||||
sprintf("(&(objectClass=classSchema)(ldapDisplayName=%s))", o.name),
|
||||
rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs);
|
||||
var a;
|
||||
dprintf("Expanding class %s\n", o.name);
|
||||
assert(res != undefined);
|
||||
assert(res.length == 1);
|
||||
var msg = res[0];
|
||||
for (a=0;a<attrs.length;a++) {
|
||||
var aname = attrs[a];
|
||||
if (msg[aname] == undefined) {
|
||||
continue;
|
||||
}
|
||||
var list = msg[aname];
|
||||
if (typeof(list) == "string") {
|
||||
list = new Array(msg[aname]);
|
||||
}
|
||||
var i;
|
||||
for (i=0;i<list.length;i++) {
|
||||
var name = list[i];
|
||||
if (objectclasses[name] == undefined) {
|
||||
dprintf("Found new objectclass '%s'\n", name);
|
||||
objectclasses[name] = obj_objectClass(ldb, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
add the must and may attributes from an objectclass to the full list
|
||||
of attributes
|
||||
*/
|
||||
function add_objectclass_attributes(ldb, class) {
|
||||
var attrs = new Array("mustContain", "systemMustContain",
|
||||
"mayContain", "systemMayContain");
|
||||
var i;
|
||||
for (i=0;i<attrs.length;i++) {
|
||||
var aname = attrs[i];
|
||||
if (class[aname] == undefined) {
|
||||
continue;
|
||||
}
|
||||
var alist = class[aname];
|
||||
if (typeof(alist) == "string") {
|
||||
alist = new Array(alist);
|
||||
}
|
||||
var j;
|
||||
var len = alist.length;
|
||||
for (j=0;j<len;j++) {
|
||||
var a = alist[j];
|
||||
if (attributes[a] == undefined) {
|
||||
attributes[a] = obj_attribute(ldb, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
process an individual record, working out what attributes it has
|
||||
*/
|
||||
function walk_dn(ldb, dn) {
|
||||
/* get a list of all possible attributes for this object */
|
||||
var attrs = new Array("allowedAttributes");
|
||||
var res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, attrs);
|
||||
if (res == undefined) {
|
||||
dprintf("Unable to fetch allowedAttributes for '%s' - %s\n",
|
||||
dn, ldb.errstring());
|
||||
return;
|
||||
}
|
||||
var allattrs = res[0].allowedAttributes;
|
||||
res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, allattrs);
|
||||
if (res == undefined) {
|
||||
dprintf("Unable to fetch all attributes for '%s' - %s\n",
|
||||
dn, ldb.errstring());
|
||||
return;
|
||||
}
|
||||
var a;
|
||||
var msg = res[0];
|
||||
for (a in msg) {
|
||||
if (attributes[a] == undefined) {
|
||||
attributes[a] = obj_attribute(ldb, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
walk a naming context, looking for all records
|
||||
*/
|
||||
function walk_naming_context(ldb, namingContext) {
|
||||
var attrs = new Array("objectClass");
|
||||
var res = ldb.search("objectClass=*", namingContext, ldb.SCOPE_DEFAULT, attrs);
|
||||
if (res == undefined) {
|
||||
dprintf("Unable to fetch objectClasses for '%s' - %s\n",
|
||||
namingContext, ldb.errstring());
|
||||
return;
|
||||
}
|
||||
var r;
|
||||
for (r=0;r<res.length;r++) {
|
||||
var msg = res[r].objectClass;
|
||||
var c;
|
||||
for (c=0;c<msg.length;c++) {
|
||||
var objectClass = msg[c];
|
||||
if (objectclasses[objectClass] == undefined) {
|
||||
objectclasses[objectClass] = obj_objectClass(ldb, objectClass);
|
||||
objectclasses[objectClass].exampleDN = res[r].dn;
|
||||
}
|
||||
}
|
||||
walk_dn(ldb, res[r].dn);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
trim the may attributes for an objectClass
|
||||
*/
|
||||
function trim_objectclass_attributes(ldb, class) {
|
||||
var i,j,n;
|
||||
|
||||
/* trim possibleInferiors,
|
||||
* include only the classes we extracted */
|
||||
var possinf = class["possibleInferiors"];
|
||||
if (possinf != undefined) {
|
||||
var newpossinf = new Array();
|
||||
if (typeof(possinf) == "string") {
|
||||
possinf = new Array(possinf);
|
||||
}
|
||||
n = 0;
|
||||
for (j = 0;j < possinf.length; j++) {
|
||||
var x = possinf[j];
|
||||
if (objectclasses[x] != undefined) {
|
||||
newpossinf[n] = x;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
class["possibleInferiors"] = newpossinf;
|
||||
}
|
||||
|
||||
/* trim systemMayContain,
|
||||
* remove duplicates */
|
||||
var sysmay = class["systemMayContain"];
|
||||
if (sysmay != undefined) {
|
||||
var newsysmay = new Array();
|
||||
if (typeof(sysmay) == "string") {
|
||||
sysmay = new Array(sysmay);
|
||||
}
|
||||
for (j = 0;j < sysmay.length; j++) {
|
||||
var x = sysmay[j];
|
||||
var dup = false;
|
||||
if (newsysmay[0] == undefined) {
|
||||
newsysmay[0] = x;
|
||||
} else {
|
||||
for (n = 0; n < newsysmay.length; n++) {
|
||||
if (newsysmay[n] == x) {
|
||||
dup = true;
|
||||
}
|
||||
}
|
||||
if (dup == false) {
|
||||
newsysmay[n] = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
class["systemMayContain"] = newsysmay;
|
||||
}
|
||||
|
||||
/* trim mayContain,
|
||||
* remove duplicates */
|
||||
var may = class["mayContain"];
|
||||
if (may != undefined) {
|
||||
var newmay = new Array();
|
||||
if (typeof(may) == "string") {
|
||||
may = new Array(may);
|
||||
}
|
||||
for (j = 0;j < may.length; j++) {
|
||||
var x = may[j];
|
||||
var dup = false;
|
||||
if (newmay[0] == undefined) {
|
||||
newmay[0] = x;
|
||||
} else {
|
||||
for (n = 0; n < newmay.length; n++) {
|
||||
if (newmay[n] == x) {
|
||||
dup = true;
|
||||
}
|
||||
}
|
||||
if (dup == false) {
|
||||
newmay[n] = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
class["mayContain"] = newmay;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
load the basic attributes of an objectClass
|
||||
*/
|
||||
function build_objectclass(ldb, name) {
|
||||
var attrs = new Array("name");
|
||||
var res = ldb.search(
|
||||
sprintf("(&(objectClass=classSchema)(ldapDisplayName=%s))", name),
|
||||
rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs);
|
||||
if (res == undefined) {
|
||||
dprintf("unknown class '%s'\n", name);
|
||||
return undefined;
|
||||
}
|
||||
if (res.length == 0) {
|
||||
dprintf("unknown class '%s'\n", name);
|
||||
return undefined;
|
||||
}
|
||||
return obj_objectClass(ldb, name);
|
||||
}
|
||||
|
||||
/*
|
||||
append 2 lists
|
||||
*/
|
||||
function list_append(a1, a2) {
|
||||
var i;
|
||||
if (a1 == undefined) {
|
||||
return a2;
|
||||
}
|
||||
if (a2 == undefined) {
|
||||
return a1;
|
||||
}
|
||||
for (i=0;i<a2.length;i++) {
|
||||
a1[a1.length] = a2[i];
|
||||
}
|
||||
return a1;
|
||||
}
|
||||
|
||||
/*
|
||||
form a coalesced attribute list
|
||||
*/
|
||||
function attribute_list(class, attr1, attr2) {
|
||||
var a1 = class[attr1];
|
||||
var a2 = class[attr2];
|
||||
if (typeof(a1) == "string") {
|
||||
a1 = new Array(a1);
|
||||
}
|
||||
if (typeof(a2) == "string") {
|
||||
a2 = new Array(a2);
|
||||
}
|
||||
return list_append(a1, a2);
|
||||
}
|
||||
|
||||
/*
|
||||
write out a list in aggregate form
|
||||
*/
|
||||
function aggregate_list(name, list) {
|
||||
if (list == undefined) {
|
||||
return;
|
||||
}
|
||||
var i;
|
||||
printf("%s ( ", name);
|
||||
for (i=0;i<list.length;i++) {
|
||||
printf("%s ", list[i]);
|
||||
if (i < (list.length - 1)) {
|
||||
printf("$ ");
|
||||
}
|
||||
}
|
||||
printf(") ");
|
||||
}
|
||||
|
||||
/*
|
||||
write the aggregate record for an objectclass
|
||||
*/
|
||||
function write_aggregate_objectclass(class) {
|
||||
printf("objectClasses: ( %s NAME '%s' ", class.governsID, class.name);
|
||||
if (class['subClassOf'] != undefined) {
|
||||
printf("SUP %s ", class['subClassOf']);
|
||||
}
|
||||
if (class.objectClassCategory == 1) {
|
||||
printf("STRUCTURAL ");
|
||||
} else if (class.objectClassCategory == 2) {
|
||||
printf("ABSTRACT ");
|
||||
} else if (class.objectClassCategory == 3) {
|
||||
printf("AUXILIARY ");
|
||||
}
|
||||
|
||||
var list;
|
||||
|
||||
list = attribute_list(class, "systemMustContain", "mustContain");
|
||||
aggregate_list("MUST", list);
|
||||
|
||||
list = attribute_list(class, "systemMayContain", "mayContain");
|
||||
aggregate_list("MAY", list);
|
||||
|
||||
printf(")\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
write the aggregate record for an ditcontentrule
|
||||
*/
|
||||
function write_aggregate_ditcontentrule(class) {
|
||||
var list = attribute_list(class, "auxiliaryClass", "systemAuxiliaryClass");
|
||||
var i;
|
||||
if (list == undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf("dITContentRules: ( %s NAME '%s' ", class.governsID, class.name);
|
||||
|
||||
aggregate_list("AUX", list);
|
||||
|
||||
var may_list = undefined;
|
||||
var must_list = undefined;
|
||||
|
||||
for (i=0;i<list.length;i++) {
|
||||
var c = list[i];
|
||||
var list2;
|
||||
list2 = attribute_list(objectclasses[c],
|
||||
"mayContain", "systemMayContain");
|
||||
may_list = list_append(may_list, list2);
|
||||
list2 = attribute_list(objectclasses[c],
|
||||
"mustContain", "systemMustContain");
|
||||
must_list = list_append(must_list, list2);
|
||||
}
|
||||
|
||||
aggregate_list("MUST", must_list);
|
||||
aggregate_list("MAY", may_list);
|
||||
|
||||
printf(")\n");
|
||||
}
|
||||
|
||||
/*
|
||||
write the aggregate record for an attribute
|
||||
*/
|
||||
function write_aggregate_attribute(attrib) {
|
||||
printf("attributeTypes: ( %s NAME '%s' SYNTAX '%s' ",
|
||||
attrib.attributeID, attrib.name,
|
||||
map_attribute_syntax(attrib.attributeSyntax));
|
||||
if (attrib['isSingleValued'] == "TRUE") {
|
||||
printf("SINGLE-VALUE ");
|
||||
}
|
||||
printf(")\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
write the aggregate record
|
||||
*/
|
||||
function write_aggregate() {
|
||||
printf("dn: CN=Aggregate,CN=Schema,CN=Configuration,${BASEDN}\n");
|
||||
print("objectClass: top
|
||||
objectClass: subSchema
|
||||
cn: Aggregate
|
||||
instanceType: 4
|
||||
name: Aggregate
|
||||
objectCategory: CN=SubSchema,CN=Schema,CN=Configuration,${BASEDN}
|
||||
");
|
||||
for (i in objectclasses) {
|
||||
write_aggregate_objectclass(objectclasses[i]);
|
||||
}
|
||||
for (i in attributes) {
|
||||
write_aggregate_attribute(attributes[i]);
|
||||
}
|
||||
for (i in objectclasses) {
|
||||
write_aggregate_ditcontentrule(objectclasses[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
load a list from a file
|
||||
*/
|
||||
function load_list(file) {
|
||||
var sys = sys_init();
|
||||
var s = sys.file_load(file);
|
||||
var a = split("\n", s);
|
||||
return a;
|
||||
}
|
||||
|
||||
/* get the rootDSE */
|
||||
var res = ldb.search("", "", ldb.SCOPE_BASE);
|
||||
rootDse = res[0];
|
||||
|
||||
/* load the list of classes we are interested in */
|
||||
var classes = load_list(classfile);
|
||||
var i;
|
||||
for (i=0;i<classes.length;i++) {
|
||||
var classname = classes[i];
|
||||
var class = build_objectclass(ldb, classname);
|
||||
if (class != undefined) {
|
||||
objectclasses[classname] = class;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
expand the objectclass list as needed
|
||||
*/
|
||||
var num_classes = 0;
|
||||
var expanded = 0;
|
||||
/* calculate the actual number of classes */
|
||||
for (i in objectclasses) {
|
||||
num_classes++;
|
||||
}
|
||||
/* so EJS do not have while nor the break statement
|
||||
can't find any other way than doing more loops
|
||||
than necessary to recursively expand all classes
|
||||
*/
|
||||
var inf;
|
||||
for (inf = 0;inf < 500; inf++) {
|
||||
if (expanded < num_classes) {
|
||||
for (i in objectclasses) {
|
||||
var n = objectclasses[i];
|
||||
if (objectclasses_expanded[i] != "DONE") {
|
||||
expand_objectclass(ldb, objectclasses[i]);
|
||||
objectclasses_expanded[i] = "DONE";
|
||||
expanded++;
|
||||
}
|
||||
}
|
||||
/* recalculate the actual number of classes */
|
||||
num_classes = 0;
|
||||
for (i in objectclasses) {
|
||||
num_classes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
find objectclass properties
|
||||
*/
|
||||
for (i in objectclasses) {
|
||||
find_objectclass_properties(ldb, objectclasses[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
form the full list of attributes
|
||||
*/
|
||||
for (i in objectclasses) {
|
||||
add_objectclass_attributes(ldb, objectclasses[i]);
|
||||
}
|
||||
|
||||
/* and attribute properties */
|
||||
for (i in attributes) {
|
||||
find_attribute_properties(ldb, attributes[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
trim the 'may' attribute lists to those really needed
|
||||
*/
|
||||
for (i in objectclasses) {
|
||||
trim_objectclass_attributes(ldb, objectclasses[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
dump an ldif form of the attributes and objectclasses
|
||||
*/
|
||||
write_ldif(attributes, attrib_attrs);
|
||||
write_ldif(objectclasses, class_attrs);
|
||||
|
||||
write_aggregate();
|
||||
|
||||
if (verbose == undefined) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
dump list of objectclasses
|
||||
*/
|
||||
printf("objectClasses:\n")
|
||||
for (i in objectclasses) {
|
||||
printf("\t%s\n", i);
|
||||
}
|
||||
printf("attributes:\n")
|
||||
for (i in attributes) {
|
||||
printf("\t%s\n", i);
|
||||
}
|
||||
|
||||
printf("autocreated attributes:\n");
|
||||
for (i in attributes) {
|
||||
if (attributes[i].autocreate == true) {
|
||||
printf("\t%s\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -0,0 +1,32 @@
|
||||
applicationSettings
|
||||
builtinDomain
|
||||
classSchema
|
||||
computer
|
||||
configuration
|
||||
container
|
||||
crossRef
|
||||
crossRefContainer
|
||||
dMD
|
||||
domain
|
||||
domainDNS
|
||||
foreignSecurityPrincipal
|
||||
group
|
||||
infrastructureUpdate
|
||||
leaf
|
||||
nTDSDSA
|
||||
nTDSService
|
||||
organizationalPerson
|
||||
organizationalUnit
|
||||
person
|
||||
primaryDomain
|
||||
rIDManager
|
||||
secret
|
||||
server
|
||||
serversContainer
|
||||
site
|
||||
sitesContainer
|
||||
subSchema
|
||||
user
|
||||
displaySpecifier
|
||||
foreignSecurityPrincipal
|
||||
trustedDomain
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env smbscript
|
||||
/*
|
||||
demonstrate access to irpc calls from ejs
|
||||
*/
|
||||
|
||||
var options = GetOptions(ARGV,
|
||||
"POPT_AUTOHELP",
|
||||
"POPT_COMMON_SAMBA");
|
||||
if (options == undefined) {
|
||||
println("Failed to parse options");
|
||||
return -1;
|
||||
}
|
||||
|
||||
var conn = new Object();
|
||||
var irpc = irpc_init();
|
||||
|
||||
status = irpc_connect(conn, "nbt_server");
|
||||
assert(status.is_ok == true);
|
||||
|
||||
io = new Object();
|
||||
io.input = new Object();
|
||||
io.input.level = irpc.NBTD_INFO_STATISTICS;
|
||||
status = irpc.nbtd_information(conn, io);
|
||||
assert(status.is_ok == true);
|
||||
assert(io.results.length == 1);
|
||||
|
||||
print("nbt_server statistics:\n");
|
||||
stats = io.results[0].info.stats;
|
||||
|
||||
for (r in stats) {
|
||||
print("\t" + r + ":\t" + stats[r] + "\n");
|
||||
}
|
||||
return 0;
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
Demonstrate use of resolveName() js function
|
||||
*/
|
||||
|
||||
var result = new Object();
|
||||
|
||||
res = resolveName(result, ARGV[0]);
|
||||
|
||||
if (res.is_ok) {
|
||||
println(result.value);
|
||||
} else {
|
||||
println(res.errstr);
|
||||
}
|
||||
Executable
+1210
File diff suppressed because it is too large
Load Diff
Executable
+126
@@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env smbscript
|
||||
/*
|
||||
test samr calls from ejs
|
||||
*/
|
||||
|
||||
var options = GetOptions(ARGV,
|
||||
"POPT_AUTOHELP",
|
||||
"POPT_COMMON_SAMBA",
|
||||
"POPT_COMMON_CREDENTIALS");
|
||||
if (options == undefined) {
|
||||
println("Failed to parse options");
|
||||
return -1;
|
||||
}
|
||||
|
||||
libinclude("base.js");
|
||||
libinclude("samr.js");
|
||||
|
||||
|
||||
/*
|
||||
test the samr_Connect interface
|
||||
*/
|
||||
function test_Connect(samr)
|
||||
{
|
||||
print("Testing samr_Connect\n");
|
||||
return samrConnect(samr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
test the samr_LookupDomain interface
|
||||
*/
|
||||
function test_LookupDomain(samr, handle, domain)
|
||||
{
|
||||
print("Testing samr_LookupDomain\n");
|
||||
return samrLookupDomain(samr, handle, domain);
|
||||
}
|
||||
|
||||
/*
|
||||
test the samr_OpenDomain interface
|
||||
*/
|
||||
function test_OpenDomain(samr, handle, sid)
|
||||
{
|
||||
print("Testing samr_OpenDomain\n");
|
||||
return samrOpenDomain(samr, handle, sid);
|
||||
}
|
||||
|
||||
/*
|
||||
test the samr_EnumDomainUsers interface
|
||||
*/
|
||||
function test_EnumDomainUsers(samr, dom_handle)
|
||||
{
|
||||
var i, users;
|
||||
print("Testing samr_EnumDomainUsers\n");
|
||||
users = samrEnumDomainUsers(samr, dom_handle);
|
||||
print("Found " + users.length + " users\n");
|
||||
for (i=0;i<users.length;i++) {
|
||||
println("\t" + users[i].name + "\t(" + users[i].idx + ")");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
test the samr_EnumDomainGroups interface
|
||||
*/
|
||||
function test_EnumDomainGroups(samr, dom_handle)
|
||||
{
|
||||
print("Testing samr_EnumDomainGroups\n");
|
||||
var i, groups = samrEnumDomainGroups(samr, dom_handle);
|
||||
print("Found " + groups.length + " groups\n");
|
||||
for (i=0;i<groups.length;i++) {
|
||||
println("\t" + groups[i].name + "\t(" + groups[i].idx + ")");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
test domain specific ops
|
||||
*/
|
||||
function test_domain_ops(samr, dom_handle)
|
||||
{
|
||||
test_EnumDomainUsers(samr, dom_handle);
|
||||
test_EnumDomainGroups(samr, dom_handle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
test the samr_EnumDomains interface
|
||||
*/
|
||||
function test_EnumDomains(samr, handle)
|
||||
{
|
||||
var i, domains;
|
||||
print("Testing samr_EnumDomains\n");
|
||||
|
||||
domains = samrEnumDomains(samr, handle);
|
||||
print("Found " + domains.length + " domains\n");
|
||||
for (i=0;i<domains.length;i++) {
|
||||
print("\t" + domains[i].name + "\n");
|
||||
}
|
||||
for (i=0;i<domains.length;i++) {
|
||||
print("Testing domain " + domains[i].name + "\n");
|
||||
sid = samrLookupDomain(samr, handle, domains[i].name);
|
||||
dom_handle = test_OpenDomain(samr, handle, sid);
|
||||
test_domain_ops(samr, dom_handle);
|
||||
samrClose(samr, dom_handle);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.ARGV.length != 1) {
|
||||
println("Usage: samr.js <BINDING>");
|
||||
return -1;
|
||||
}
|
||||
var binding = options.ARGV[0];
|
||||
var samr = samr_init();
|
||||
|
||||
print("Connecting to " + binding + "\n");
|
||||
status = samr.connect(binding);
|
||||
if (status.is_ok != true) {
|
||||
print("Failed to connect to " + binding + " - " + status.errstr + "\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle = test_Connect(samr);
|
||||
test_EnumDomains(samr, handle);
|
||||
samrClose(samr, handle);
|
||||
|
||||
print("All OK\n");
|
||||
return 0;
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env smbscript
|
||||
/*
|
||||
test sprintf function
|
||||
*/
|
||||
|
||||
string_init(local);
|
||||
|
||||
function check_result(s, v)
|
||||
{
|
||||
if (s != v) {
|
||||
println("expected '" + v + "' but got '" + s + "'");
|
||||
}
|
||||
assert(s == v);
|
||||
}
|
||||
|
||||
function xprintf()
|
||||
{
|
||||
return "XX{" + vsprintf(arguments) + "}XX";
|
||||
}
|
||||
|
||||
check_result(sprintf("%d", 7), "7");
|
||||
check_result(sprintf("%04d", 42), "0042");
|
||||
check_result(sprintf("my string=%7.2s", "foo%7"), "my string= fo");
|
||||
check_result(sprintf("blah=0x%*x", 4, 19), "blah=0x 13");
|
||||
check_result(sprintf("blah=0x%0*x", 4, 19), "blah=0x0013");
|
||||
check_result(sprintf("blah=%.0f", 1032), "blah=1032");
|
||||
check_result(sprintf("%4.2f%%", 72.32), "72.32%");
|
||||
|
||||
check_result(xprintf("%4.2f%% and %s", 72.32, "foo"),"XX{72.32% and foo}XX");
|
||||
|
||||
println("ALL OK");
|
||||
Reference in New Issue
Block a user