4cbe7b9bc8ba10cbbf7bf454149420eeaf5259e3
[sfrench/samba-autobuild/.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   form a lsa_String
29 */
30 function lsaString(s)
31 {
32         var o = new Object();
33         o.string = s;
34         return o;
35 }
36
37 /*
38   test the samr_Connect interface
39 */
40 function test_Connect(conn)
41 {
42         var io = irpcObj();
43         print("Testing samr_Connect\n");
44         io.input.system_name = NULL;
45         io.input.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
46         status = dcerpc_samr_Connect(conn, io);
47         check_status_ok(status);
48         return io.output.connect_handle;
49 }
50
51 /*
52   test the samr_Close interface
53 */
54 function test_Close(conn, handle)
55 {
56         var io = irpcObj();
57         io.input.handle = handle;
58         status = dcerpc_samr_Close(conn, io);
59         check_status_ok(status);
60 }
61
62 /*
63   test the samr_LookupDomain interface
64 */
65 function test_LookupDomain(conn, handle, domain)
66 {
67         var io = irpcObj();
68         print("Testing samr_LookupDomain\n");
69         io.input.connect_handle = handle;
70         io.input.domain_name = lsaString(domain);
71         status = dcerpc_samr_LookupDomain(conn, io);
72         check_status_ok(status);
73         return io.output.sid;
74 }
75
76 /*
77   test the samr_OpenDomain interface
78 */
79 function test_OpenDomain(conn, handle, sid)
80 {
81         var io = irpcObj();
82         print("Testing samr_OpenDomain\n");
83         io.input.connect_handle = handle;
84         io.input.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
85         io.input.sid = sid;
86         status = dcerpc_samr_OpenDomain(conn, io);
87         check_status_ok(status);
88         return io.output.domain_handle;
89 }
90
91 /*
92   test the samr_EnumDomainUsers interface
93 */
94 function test_EnumDomainUsers(conn, dom_handle)
95 {
96         var i, io = irpcObj();
97         print("Testing samr_EnumDomainUsers\n");
98         io.input.domain_handle = dom_handle;
99         io.input.resume_handle = 0;
100         io.input.acct_flags = 0;
101         io.input.max_size = -1;
102         status = dcerpc_samr_EnumDomainUsers(conn, io);
103         check_status_ok(status);
104         print("Found " + io.output.num_entries + " users\n");
105         if (io.output.sam == NULL) {
106                 return;
107         }
108         var entries = io.output.sam.entries;
109         for (i=0;i<io.output.num_entries;i++) {
110                 print("\t" + entries[i].name.string + "\n");
111         }
112 }
113
114 /*
115   test the samr_EnumDomainGroups interface
116 */
117 function test_EnumDomainGroups(conn, dom_handle)
118 {
119         var i, io = irpcObj();
120         print("Testing samr_EnumDomainGroups\n");
121         io.input.domain_handle = dom_handle;
122         io.input.resume_handle = 0;
123         io.input.acct_flags = 0;
124         io.input.max_size = -1;
125         status = dcerpc_samr_EnumDomainGroups(conn, io);
126         check_status_ok(status);
127         print("Found " + io.output.num_entries + " groups\n");
128         if (io.output.sam == NULL) {
129                 return;
130         }
131         var entries = io.output.sam.entries;
132         for (i=0;i<io.output.num_entries;i++) {
133                 print("\t" + entries[i].name.string + "\n");
134         }
135 }
136
137 /*
138   test domain specific ops
139 */
140 function test_domain_ops(conn, dom_handle)
141 {
142         test_EnumDomainUsers(conn, dom_handle);
143         test_EnumDomainGroups(conn, dom_handle);
144 }
145
146
147
148 /*
149   test the samr_EnumDomains interface
150 */
151 function test_EnumDomains(conn, handle)
152 {
153         var i, io = irpcObj();
154         print("Testing samr_EnumDomains\n");
155         io.input.connect_handle = handle;
156         io.input.resume_handle = 0;
157         io.input.buf_size = -1;
158         status = dcerpc_samr_EnumDomains(conn, io);
159         check_status_ok(status);
160         print("Found " + io.output.num_entries + " domains\n");
161         if (io.output.sam == NULL) {
162                 return;
163         }
164         var entries = io.output.sam.entries;
165         for (i=0;i<io.output.num_entries;i++) {
166                 print("\t" + entries[i].name.string + "\n");
167         }
168         for (i=0;i<io.output.num_entries;i++) {
169                 domain = entries[i].name.string;
170                 print("Testing domain " + domain + "\n");
171                 sid = test_LookupDomain(conn, handle, domain);
172                 dom_handle = test_OpenDomain(conn, handle, sid);
173                 test_domain_ops(conn, dom_handle);
174                 test_Close(conn, dom_handle);
175         }
176 }
177
178
179
180 if (ARGV.length == 0) {
181    print("Usage: samr.js <RPCBINDING>\n");
182    exit(0);
183 }
184
185 var binding = ARGV[0];
186 var conn = new Object();
187
188 print("Connecting to " + binding + "\n");
189 status = rpc_connect(conn, binding, "samr");
190 if (status.is_ok != true) {
191    print("Failed to connect to " + binding + " - " + status.errstr + "\n");
192    return;
193 }
194
195 handle = test_Connect(conn);
196 test_EnumDomains(conn, handle);
197 test_Close(conn, handle);
198
199 print("All OK\n");