diff options
-rw-r--r-- | swat/esptest/menu.js | 1 | ||||
-rw-r--r-- | swat/esptest/samr.esp | 35 | ||||
-rw-r--r-- | swat/scripting/common.js | 24 | ||||
-rw-r--r-- | swat/scripting/samr.js | 167 | ||||
-rw-r--r-- | testprogs/ejs/samr.js | 20 |
5 files changed, 214 insertions, 33 deletions
diff --git a/swat/esptest/menu.js b/swat/esptest/menu.js index b78ca68ee8..d46561f311 100644 --- a/swat/esptest/menu.js +++ b/swat/esptest/menu.js @@ -2,6 +2,7 @@ simple_menu( "ESP Tests", "ldb database", session_uri("/esptest/ldb.esp"), + "samr calls", session_uri("/esptest/samr.esp"), "html forms", session_uri("/esptest/formtest.esp"), "esp includes", session_uri("/esptest/include.esp"), "session variables", session_uri("/esptest/session.esp"), diff --git a/swat/esptest/samr.esp b/swat/esptest/samr.esp new file mode 100644 index 0000000000..f0159fcafa --- /dev/null +++ b/swat/esptest/samr.esp @@ -0,0 +1,35 @@ +<% page_header("columns", "ESP samr test"); + + include("/scripting/samr.js"); +%> + +<h1>Samba4 samr rpc test</h1> + +<% +var conn = new Object(); +var binding = "ncalrpc:"; +status = rpc_connect(conn, binding, "samr"); +check_status_ok(status); + +handle = samrConnect(conn); + +domains = samrEnumDomains(conn, handle); + +for (i=0;i<domains.length;i++) { + write("<h2>Domain " + domains[i].name + "</h2>\n"); + sid = samrLookupDomain(conn, handle, domains[i].name); + dom_handle = samrOpenDomain(conn, handle, sid); + users = samrEnumDomainUsers(conn, dom_handle); + samrFillUserInfo(conn, dom_handle, users, 3); + if (users.length == 0) { + write("no users in domain<br>\n"); + } else { + multi_table(users, "name"); + } + samrClose(dom_handle); +} + +%> + + +<% page_footer(); %> diff --git a/swat/scripting/common.js b/swat/scripting/common.js index 4fc3884db6..3321cfb772 100644 --- a/swat/scripting/common.js +++ b/swat/scripting/common.js @@ -115,7 +115,7 @@ function simple_menu() { function table_element(i, o) { write("<tr><td>" + i + "</td><td>"); if (typeof(o[i]) == "object") { - var first; + var j, first; first = true; for (j in o[i]) { if (first == false) { @@ -131,24 +131,14 @@ function table_element(i, o) { } /* - return the number of elements in an object -*/ -function elcount(o) { - var count = 0; - for (i in o) { - count++; - } - return count; -} - -/* display a ejs object as a table. The header is optional */ function simple_table(v) { - if (elcount(v) == 0) { + if (v.length == 0) { return; } write("<table class=\"data\">\n"); + var r; for (r in v) { table_element(r, v); } @@ -160,12 +150,10 @@ function simple_table(v) { attribute */ function multi_table(array, header) { - if (elcount(array) == 0) { - return; - } + var i, n; write("<table class=\"data\">\n"); - for (i in array) { - var v = array[i]; + for (i=0;i<array.length;i++) { + var r, v = array[i]; write('<tr><th colspan="2">' + v[header] + "</th></tr>\n"); for (r in v) { if (r != header) { diff --git a/swat/scripting/samr.js b/swat/scripting/samr.js new file mode 100644 index 0000000000..474e704550 --- /dev/null +++ b/swat/scripting/samr.js @@ -0,0 +1,167 @@ +/* + samr rpc utility functions +*/ + +/* + 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); +} + +/* + return a list of names and indexes from a samArray +*/ +function samArray(output) +{ + var list = new Array(output.num_entries); + if (output.sam == NULL) { + return list; + } + var entries = output.sam.entries; + for (i=0;i<output.num_entries;i++) { + list[i] = new Object(); + list[i].name = entries[i].name; + list[i].idx = entries[i].idx; + } + return list; +} + +/* + connect to the sam database +*/ +function samrConnect(conn) +{ + var io = irpcObj(); + 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; +} + +/* + close a handle +*/ +function samrClose(conn, handle) +{ + var io = irpcObj(); + io.input.handle = handle; + status = dcerpc_samr_Close(conn, io); + check_status_ok(status); +} + +/* + get the sid for a domain +*/ +function samrLookupDomain(conn, handle, domain) +{ + var io = irpcObj(); + io.input.connect_handle = handle; + io.input.domain_name = domain; + status = dcerpc_samr_LookupDomain(conn, io); + check_status_ok(status); + return io.output.sid; +} + +/* + open a domain by sid +*/ +function samrOpenDomain(conn, handle, sid) +{ + var io = irpcObj(); + 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; +} + +/* + open a user by rid +*/ +function samrOpenUser(conn, handle, rid) +{ + var io = irpcObj(); + io.input.domain_handle = handle; + io.input.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + io.input.rid = rid; + status = dcerpc_samr_OpenUser(conn, io); + check_status_ok(status); + return io.output.user_handle; +} + +/* + return a list of all users +*/ +function samrEnumDomainUsers(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_EnumDomainUsers(conn, io); + check_status_ok(status); + return samArray(io.output); +} + +/* + return a list of domains +*/ +function samrEnumDomains(conn, handle) +{ + var io = irpcObj(); + 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); + return samArray(io.output); +} + +/* + return information about a user +*/ +function samrQueryUserInfo(conn, user_handle, level) +{ + var r, io = irpcObj(); + io.input.user_handle = user_handle; + io.input.level = level; + status = dcerpc_samr_QueryUserInfo(conn, io); + check_status_ok(status); + return io.output.info.info3; +} + + +/* + fill a user array with user information from samrQueryUserInfo +*/ +function samrFillUserInfo(conn, dom_handle, users, level) +{ + var i; + for (i=0;i<users.length;i++) { + var r, user_handle, info; + user_handle = samrOpenUser(conn, dom_handle, users[i].idx); + info = samrQueryUserInfo(conn, user_handle, level); + info.name = users[i].name; + info.idx = users[i].idx; + users[i] = info; + samrClose(conn, user_handle); + } +} diff --git a/testprogs/ejs/samr.js b/testprogs/ejs/samr.js index 4cbe7b9bc8..df54ca6062 100644 --- a/testprogs/ejs/samr.js +++ b/testprogs/ejs/samr.js @@ -25,16 +25,6 @@ function check_status_ok(status) } /* - 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) @@ -67,7 +57,7 @@ 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); + io.input.domain_name = domain; status = dcerpc_samr_LookupDomain(conn, io); check_status_ok(status); return io.output.sid; @@ -107,7 +97,7 @@ function test_EnumDomainUsers(conn, dom_handle) } var entries = io.output.sam.entries; for (i=0;i<io.output.num_entries;i++) { - print("\t" + entries[i].name.string + "\n"); + print("\t" + entries[i].name + "\n"); } } @@ -130,7 +120,7 @@ function test_EnumDomainGroups(conn, dom_handle) } var entries = io.output.sam.entries; for (i=0;i<io.output.num_entries;i++) { - print("\t" + entries[i].name.string + "\n"); + print("\t" + entries[i].name + "\n"); } } @@ -163,10 +153,10 @@ function test_EnumDomains(conn, handle) } var entries = io.output.sam.entries; for (i=0;i<io.output.num_entries;i++) { - print("\t" + entries[i].name.string + "\n"); + print("\t" + entries[i].name + "\n"); } for (i=0;i<io.output.num_entries;i++) { - domain = entries[i].name.string; + domain = entries[i].name; print("Testing domain " + domain + "\n"); sid = test_LookupDomain(conn, handle, domain); dom_handle = test_OpenDomain(conn, handle, sid); |