summaryrefslogtreecommitdiffstats
path: root/testprogs/ejs/samr.js
blob: fb444fb4b53d28234258db171eb708deee81e89a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
  test samr 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;
}

/*
  check that a status result is OK
*/
function check_status_ok(status)
{
	if (status.is_ok != true) {
		printVars(status);
	}
	assert(status.is_ok == true);
}

/*
  form a lsa_String
*/
function lsaString(s)
{
	var o = new Object();
	o.string = s;
	return o;
}

/*
  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;
}

/*
  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 = lsaString(domain);
	status = dcerpc_samr_LookupDomain(conn, io);
	check_status_ok(status);
	return io.output.sid;
}

/*
  test the samr_OpenDomain interface
*/
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;
}

/*
  test the samr_EnumDomainUsers interface
*/
function test_EnumDomainUsers(conn, dom_handle)
{
	var io = irpcObj();
	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.num_entries == 0) {
		return;
	}
	entries = io.output.sam.entries;
	for (i=0;i<io.output.num_entries;i++) {
		print("\t" + entries[i].name.string + "\n");
	}
}

/*
  test domain specific ops
*/
function test_domain_ops(conn, dom_handle)
{
	test_EnumDomainUsers(conn, dom_handle);
}



/*
  test the samr_EnumDomains interface
*/
function test_EnumDomains(conn, handle)
{
	var io = irpcObj();
	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");
	entries = io.output.sam.entries;
	for (i=0;i<io.output.num_entries;i++) {
		print("\t" + entries[i].name.string + "\n");
	}
	for (i=0;i<io.output.num_entries;i++) {
		domain = entries[i].name.string;
		print("Testing domain " + domain + "\n");
		sid = test_LookupDomain(conn, handle, domain);
		dom_handle = test_OpenDomain(conn, handle, sid);
		test_domain_ops(conn, dom_handle);
		test_Close(conn, dom_handle);
	}
}



if (ARGV.length == 0) {
   print("Usage: samr.js <RPCBINDING>\n");
   exit(0);
}

var binding = ARGV[0];
var conn = new Object();

print("Connecting to " + binding + "\n");
status = rpc_connect(conn, binding, "samr");
if (status.is_ok != true) {
   print("Failed to connect to " + binding + " - " + status.errstr + "\n");
   return;
}

handle = test_Connect(conn);
test_EnumDomains(conn, handle);
test_Close(conn, handle);

print("All OK\n");