r8298: - started building a library of js routines in scripting/libjs/
authorAndrew Tridgell <tridge@samba.org>
Mon, 11 Jul 2005 00:23:57 +0000 (00:23 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:19:33 +0000 (13:19 -0500)
- switched the existing test programs over to using the library

- added install of js lib
(This used to be commit 2a444dedbe44347268affc6458196f93ca7d372b)

source4/build/smb_build/makefile.pm
source4/script/installswat.sh
source4/script/tests/selftest.sh
source4/scripting/libjs/base.js [new file with mode: 0644]
source4/scripting/libjs/samr.js [moved from swat/scripting/samr.js with 86% similarity]
testprogs/ejs/echo.js
testprogs/ejs/samr.js

index a32a93af0ae24768302a49fc6aac1e2050ed7ad7..2edda7408e527d02ad743aa6d104c438ec0cb292 100644 (file)
@@ -696,7 +696,7 @@ installdat: installdirs
        @$(SHELL) $(srcdir)/script/installdat.sh $(DESTDIR)$(LIBDIR) $(srcdir)
 
 installswat: installdirs
-       @$(SHELL) $(srcdir)/script/installswat.sh $(DESTDIR)$(SWATDIR) $(srcdir)
+       @$(SHELL) $(srcdir)/script/installswat.sh $(DESTDIR)$(SWATDIR) $(srcdir) $(DESTDIR)$(LIBDIR)
 
 installman: installdirs
        @$(SHELL) $(srcdir)/script/installman.sh $(DESTDIR)$(MANDIR) $(MANPAGES)
index 1d89c2e86c8e5dfe158e342b6fd86e320f596fce..05245d8f06fdfafc9fe1327f70814638afa9b58a 100644 (file)
@@ -2,6 +2,7 @@
 
 SWATDIR=$1
 SRCDIR=$2
+LIBDIR=$3
 
 echo Installing swat files in $SWATDIR
 
@@ -26,6 +27,12 @@ installdir scripting/*.ejs scripting/*.esp scripting/*.js
 installdir style/*.css
 installdir docs/*.js
 
+
+echo "Installing js libs"
+cd ../source/scripting || exit 1
+mkdir -p $LIBDIR/js
+cp libjs/*.js $LIBDIR/js
+
 cat << EOF
 ======================================================================
 The swat files have been installed. 
index 2993b0590e56f26fa9835a964cb5ff604694a528..5e94ea13e24ccff88e1b48e585cc3bf9a7cb8aa0 100755 (executable)
@@ -68,6 +68,7 @@ cat >$CONFFILE<<EOF
        pid directory = $PIDDIR
        ncalrpc dir = $NCALRPCDIR
        lock dir = $LOCKDIR
+       js include = $LIBDIR/js
        name resolve order = bcast
        interfaces = lo*
 
diff --git a/source4/scripting/libjs/base.js b/source4/scripting/libjs/base.js
new file mode 100644 (file)
index 0000000..504cd82
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+       base js library functions
+       Copyright Andrew Tridgell 2005
+       released under the GNU GPL v2 or later
+*/
+
+if (global["HAVE_BASE_JS"] != undefined) {
+   return;
+}
+HAVE_BASE_JS=1
+
+/*
+  helper function to setup a rpc io object, ready for input
+*/
+function irpcObj()
+{
+       var o = new Object();
+       o.input = new Object();
+       return o;
+}
+
+/*
+  check that a status result is OK
+*/
+function check_status_ok(status)
+{
+       if (status.is_ok != true) {
+               printVars(status);
+       }
+       assert(status.is_ok == true);
+}
+
+/*
+  check that two arrays are equal
+*/
+function check_array_equal(a1, a2)
+{
+       assert(a1.length == a2.length);
+       for (i=0; i<a1.length; i++) {
+               assert(a1[i] == a2[i]);
+       }
+}
+
+/*
+  check that an array is all zeros
+*/
+function check_array_zero(a)
+{
+       for (i=0; i<a.length; i++) {
+               assert(a[i] == 0);
+       }
+}
+
similarity index 86%
rename from swat/scripting/samr.js
rename to source4/scripting/libjs/samr.js
index 474e7045503f16020b9b1f3c859ddfcf94c4a575..a1f79b541a4a006d1b7fab578c8e4e15cedd7b9e 100644 (file)
@@ -1,27 +1,13 @@
 /*
        samr rpc utility functions 
+       Copyright Andrew Tridgell 2005
+       released under the GNU GPL v2 or later
 */     
 
-/*
-  helper function to setup a rpc io object, ready for input
-*/
-function irpcObj()
-{
-       var o = new Object();
-       o.input = new Object();
-       return o;
-}
-
-/*
-  check that a status result is OK
-*/
-function check_status_ok(status)
-{
-       if (status.is_ok != true) {
-               printVars(status);
-       }
-       assert(status.is_ok == true);
+if (global["HAVE_SAMR_JS"] != undefined) {
+   return;
 }
+HAVE_SAMR_JS=1
 
 /*
   return a list of names and indexes from a samArray
@@ -121,6 +107,21 @@ function samrEnumDomainUsers(conn, dom_handle)
        return samArray(io.output);
 }
 
+/*
+  return a list of all groups
+*/
+function samrEnumDomainGroups(conn, dom_handle)
+{
+       var io = irpcObj();
+       io.input.domain_handle = dom_handle;
+       io.input.resume_handle = 0;
+       io.input.acct_flags = 0;
+       io.input.max_size = -1;
+       status = dcerpc_samr_EnumDomainGroups(conn, io);
+       check_status_ok(status);
+       return samArray(io.output);
+}
+
 /*
   return a list of domains
 */
@@ -165,3 +166,5 @@ function samrFillUserInfo(conn, dom_handle, users, level)
                samrClose(conn, user_handle);
        }
 }
+
+
index 4f0fc79f9ac12d1e945ea8ff80c98791654b0d2c..312e599d50b03868bd2bff2ac61e0af9866687db 100755 (executable)
@@ -3,16 +3,7 @@
        test echo pipe calls from ejs
 */     
 
-
-/*
-  helper function to setup a rpc io object, ready for input
-*/
-function irpcObj()
-{
-       var o = new Object();
-       o.input = new Object();
-       return o;
-}
+libinclude("base.js");
 
 /*
   generate a ramp as an integer array
@@ -27,38 +18,6 @@ function ramp_array(N)
 }
 
 
-/*
-  check that a status result is OK
-*/
-function check_status_ok(status)
-{
-       if (status.is_ok != true) {
-               printVars(status);
-       }
-       assert(status.is_ok == true);
-}
-
-/*
-  check that two arrays are equal
-*/
-function check_array_equal(a1, a2)
-{
-       assert(a1.length == a2.length);
-       for (i=0; i<a1.length; i++) {
-               assert(a1[i] == a2[i]);
-       }
-}
-
-/*
-  check that an array is all zeros
-*/
-function check_array_zero(a)
-{
-       for (i=0; i<a.length; i++) {
-               assert(a[i] == 0);
-       }
-}
-
 /*
   test the echo_AddOne interface
 */
index ec2096b81805e08ce3626dd30a87be20b6bbe055..1c613d5619794cbc7ee1a1e997264eb4ac8c757c 100755 (executable)
@@ -3,65 +3,28 @@
   test samr calls from ejs
 */     
 
+libinclude("base.js");
+libinclude("samr.js");
+libinclude("samr.js");
 
-/*
-  helper function to setup a rpc io object, ready for input
-*/
-function irpcObj()
-{
-       var o = new Object();
-       o.input = new Object();
-       return o;
-}
-
-/*
-  check that a status result is OK
-*/
-function check_status_ok(status)
-{
-       if (status.is_ok != true) {
-               printVars(status);
-       }
-       assert(status.is_ok == true);
-}
 
 /*
   test the samr_Connect interface
 */
 function test_Connect(conn)
 {
-       var io = irpcObj();
        print("Testing samr_Connect\n");
-       io.input.system_name = NULL;
-       io.input.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
-       status = dcerpc_samr_Connect(conn, io);
-       check_status_ok(status);
-       return io.output.connect_handle;
+       return samrConnect(conn);
 }
 
-/*
-  test the samr_Close interface
-*/
-function test_Close(conn, handle)
-{
-       var io = irpcObj();
-       io.input.handle = handle;
-       status = dcerpc_samr_Close(conn, io);
-       check_status_ok(status);
-}
 
 /*
   test the samr_LookupDomain interface
 */
 function test_LookupDomain(conn, handle, domain)
 {
-       var io = irpcObj();
        print("Testing samr_LookupDomain\n");
-       io.input.connect_handle = handle;
-       io.input.domain_name = domain;
-       status = dcerpc_samr_LookupDomain(conn, io);
-       check_status_ok(status);
-       return io.output.sid;
+       return samrLookupDomain(conn, handle, domain);
 }
 
 /*
@@ -69,14 +32,8 @@ function test_LookupDomain(conn, handle, domain)
 */
 function test_OpenDomain(conn, handle, sid)
 {
-       var io = irpcObj();
        print("Testing samr_OpenDomain\n");
-       io.input.connect_handle = handle;
-       io.input.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
-       io.input.sid = sid;
-       status = dcerpc_samr_OpenDomain(conn, io);
-       check_status_ok(status);
-       return io.output.domain_handle;
+       return samrOpenDomain(conn, handle, sid);
 }
 
 /*
@@ -84,21 +41,12 @@ function test_OpenDomain(conn, handle, sid)
 */
 function test_EnumDomainUsers(conn, dom_handle)
 {
-       var i, io = irpcObj();
+       var i, users;
        print("Testing samr_EnumDomainUsers\n");
-       io.input.domain_handle = dom_handle;
-       io.input.resume_handle = 0;
-       io.input.acct_flags = 0;
-       io.input.max_size = -1;
-       status = dcerpc_samr_EnumDomainUsers(conn, io);
-       check_status_ok(status);
-       print("Found " + io.output.num_entries + " users\n");
-       if (io.output.sam == NULL) {
-               return;
-       }
-       var entries = io.output.sam.entries;
-       for (i=0;i<io.output.num_entries;i++) {
-               print("\t" + entries[i].name + "\n");
+       users = samrEnumDomainUsers(conn, dom_handle);
+       print("Found " + users.length + " users\n");
+       for (i=0;i<users.length;i++) {
+               println("\t" + users[i].name + "\t(" + users[i].idx + ")");
        }
 }
 
@@ -107,21 +55,11 @@ function test_EnumDomainUsers(conn, dom_handle)
 */
 function test_EnumDomainGroups(conn, dom_handle)
 {
-       var i, io = irpcObj();
        print("Testing samr_EnumDomainGroups\n");
-       io.input.domain_handle = dom_handle;
-       io.input.resume_handle = 0;
-       io.input.acct_flags = 0;
-       io.input.max_size = -1;
-       status = dcerpc_samr_EnumDomainGroups(conn, io);
-       check_status_ok(status);
-       print("Found " + io.output.num_entries + " groups\n");
-       if (io.output.sam == NULL) {
-               return;
-       }
-       var entries = io.output.sam.entries;
-       for (i=0;i<io.output.num_entries;i++) {
-               print("\t" + entries[i].name + "\n");
+       var i, groups = samrEnumDomainGroups(conn, dom_handle);
+       print("Found " + groups.length + " groups\n");
+       for (i=0;i<groups.length;i++) {
+               println("\t" + groups[i].name + "\t(" + groups[i].idx + ")");
        }
 }
 
@@ -141,28 +79,20 @@ function test_domain_ops(conn, dom_handle)
 */
 function test_EnumDomains(conn, handle)
 {
-       var i, io = irpcObj();
+       var i, domains;
        print("Testing samr_EnumDomains\n");
-       io.input.connect_handle = handle;
-       io.input.resume_handle = 0;
-       io.input.buf_size = -1;
-       status = dcerpc_samr_EnumDomains(conn, io);
-       check_status_ok(status);
-       print("Found " + io.output.num_entries + " domains\n");
-       if (io.output.sam == NULL) {
-               return;
-       }
-       var entries = io.output.sam.entries;
-       for (i=0;i<io.output.num_entries;i++) {
-               print("\t" + entries[i].name + "\n");
+
+       domains = samrEnumDomains(conn, handle);
+       print("Found " + domains.length + " domains\n");
+       for (i=0;i<domains.length;i++) {
+               print("\t" + domains[i].name + "\n");
        }
-       for (i=0;i<io.output.num_entries;i++) {
-               domain = entries[i].name;
-               print("Testing domain " + domain + "\n");
-               sid = test_LookupDomain(conn, handle, domain);
+       for (i=0;i<domains.length;i++) {
+               print("Testing domain " + domains[i].name + "\n");
+               sid = samrLookupDomain(conn, handle, domains[i].name);
                dom_handle = test_OpenDomain(conn, handle, sid);
                test_domain_ops(conn, dom_handle);
-               test_Close(conn, dom_handle);
+               samrClose(conn, dom_handle);
        }
 }
 
@@ -185,7 +115,7 @@ if (status.is_ok != true) {
 
 handle = test_Connect(conn);
 test_EnumDomains(conn, handle);
-test_Close(conn, handle);
+samrClose(conn, handle);
 
 print("All OK\n");
 return 0;