r8237: expanded the samr.js test to do a samr_Connect(), samr_EnumDomains() and samr_...
[samba.git] / testprogs / ejs / samr.js
1 /*
2   test samr calls from ejs
3 */      
4
5
6 /*
7   helper function to setup a rpc io object, ready for input
8 */
9 function irpcObj()
10 {
11         var o = new Object();
12         o.input = new Object();
13         return o;
14 }
15
16 /*
17   check that a status result is OK
18 */
19 function check_status_ok(status)
20 {
21         if (status.is_ok != true) {
22                 printVars(status);
23         }
24         assert(status.is_ok == true);
25 }
26
27 /*
28   test the samr_Connect interface
29 */
30 function test_Connect(conn)
31 {
32         var io = irpcObj();
33         print("Testing samr_Connect\n");
34         io.input.system_name = NULL;
35         io.input.access_mask = 0;
36         status = dcerpc_samr_Connect(conn, io);
37         check_status_ok(status);
38         return io.output.connect_handle;
39 }
40
41 /*
42   test the samr_Close interface
43 */
44 function test_Close(conn, handle)
45 {
46         var io = irpcObj();
47         print("Testing samr_Close\n");
48         io.input.handle = handle;
49         status = dcerpc_samr_Close(conn, io);
50         check_status_ok(status);
51 }
52
53 /*
54   test the samr_EnumDomains interface
55 */
56 function test_EnumDomains(conn, handle)
57 {
58         var io = irpcObj();
59         print("Testing samr_EnumDomains\n");
60         io.input.connect_handle = handle;
61         io.input.resume_handle = 0;
62         io.input.buf_size = 0;
63         status = dcerpc_samr_EnumDomains(conn, io);
64         check_status_ok(status);
65         print("Found " + io.output.num_entries + " domains\n");
66         entries = io.output.sam.entries;
67         for (i=0;i<io.output.num_entries;i++) {
68                 print("\t" + entries[i].name.string + "\n");
69         }
70 }
71
72
73
74 if (ARGV.length == 0) {
75    print("Usage: samr.js <RPCBINDING>\n");
76    exit(0);
77 }
78
79 var binding = ARGV[0];
80 var conn = new Object();
81
82 print("Connecting to " + binding + "\n");
83 status = rpc_connect(conn, binding, "samr");
84 if (status.is_ok != true) {
85    print("Failed to connect to " + binding + " - " + status.errstr + "\n");
86    return;
87 }
88
89 handle = test_Connect(conn);
90 test_EnumDomains(conn, handle);
91 test_Close(conn, handle);
92
93 print("All OK\n");