summaryrefslogtreecommitdiff
path: root/source4/torture
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2011-01-25 18:49:32 +0100
committerGünther Deschner <gd@samba.org>2011-01-27 14:41:41 +0100
commit3e29bb0b925051aa2398bff6eef7b01ea9ca6e2f (patch)
treeefcac7885b937e0183c34b88824d53da7552d7b8 /source4/torture
parent357fd2cecc6ee1cd0eb8b3d377454d3f02825ea1 (diff)
downloadsamba-3e29bb0b925051aa2398bff6eef7b01ea9ca6e2f.tar.gz
samba-3e29bb0b925051aa2398bff6eef7b01ea9ca6e2f.tar.bz2
samba-3e29bb0b925051aa2398bff6eef7b01ea9ca6e2f.zip
s4-torture: Added a full epm_Map test.
Diffstat (limited to 'source4/torture')
-rw-r--r--source4/torture/rpc/epmapper.c326
1 files changed, 231 insertions, 95 deletions
diff --git a/source4/torture/rpc/epmapper.c b/source4/torture/rpc/epmapper.c
index 326a5bfdee..d5115807ba 100644
--- a/source4/torture/rpc/epmapper.c
+++ b/source4/torture/rpc/epmapper.c
@@ -23,7 +23,7 @@
#include "librpc/ndr/ndr_table.h"
#include "librpc/rpc/dcerpc_proto.h"
#include "torture/rpc/torture_rpc.h"
-
+#include "lib/util/util_net.h"
/*
display any protocol tower
@@ -40,9 +40,232 @@ static void display_tower(struct torture_context *tctx, struct epm_tower *twr)
torture_comment(tctx, "\n");
}
-static bool test_Map(struct dcerpc_binding_handle *b,
- struct torture_context *tctx,
- struct epm_twr_t *twr)
+static bool test_Insert(struct torture_context *tctx,
+ struct dcerpc_binding_handle *h,
+ struct ndr_syntax_id object,
+ const char *annotation,
+ struct dcerpc_binding *b)
+{
+ struct epm_Insert r;
+ NTSTATUS status;
+
+ r.in.num_ents = 1;
+ r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
+
+ if (torture_setting_bool(tctx, "samba4", false)) {
+ torture_skip(tctx, "Skip Insert test against Samba4");
+ }
+
+ /* FIXME zero */
+ ZERO_STRUCT(r.in.entries[0].object);
+ r.in.entries[0].annotation = annotation;
+
+ r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
+
+ status = dcerpc_binding_build_tower(tctx,
+ b,
+ &r.in.entries[0].tower->tower);
+
+ torture_assert_ntstatus_ok(tctx,
+ status,
+ "Unable to build tower from binding struct");
+ r.in.replace = 0;
+
+ /* shoot! */
+ status = dcerpc_epm_Insert_r(h, tctx, &r);
+
+ if (NT_STATUS_IS_ERR(status)) {
+ torture_comment(tctx,
+ "epm_Insert failed - %s\n",
+ nt_errstr(status));
+ return false;
+ }
+
+ if (r.out.result != EPMAPPER_STATUS_OK) {
+ torture_comment(tctx,
+ "epm_Insert failed - internal error: 0x%.4x\n",
+ r.out.result);
+ return false;
+ }
+
+ return true;
+}
+
+static bool test_Delete(struct torture_context *tctx,
+ struct dcerpc_binding_handle *h,
+ const char *annotation,
+ struct dcerpc_binding *b)
+{
+ NTSTATUS status;
+ struct epm_Delete r;
+
+ r.in.num_ents = 1;
+ r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
+
+ ZERO_STRUCT(r.in.entries[0].object);
+ r.in.entries[0].annotation = annotation;
+
+ r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
+
+ status = dcerpc_binding_build_tower(tctx,
+ b,
+ &r.in.entries[0].tower->tower);
+
+ torture_assert_ntstatus_ok(tctx,
+ status,
+ "Unable to build tower from binding struct");
+ r.in.num_ents = 1;
+
+ status = dcerpc_epm_Delete_r(h, tctx, &r);
+ if (NT_STATUS_IS_ERR(status)) {
+ torture_comment(tctx,
+ "epm_Delete failed - %s\n",
+ nt_errstr(status));
+ return false;
+ }
+
+ if (r.out.result != EPMAPPER_STATUS_OK) {
+ torture_comment(tctx,
+ "epm_Delete failed - internal error: 0x%.4x\n",
+ r.out.result);
+ return false;
+ }
+
+ return true;
+}
+
+static bool test_Map_tcpip(struct torture_context *tctx,
+ struct dcerpc_binding_handle *h,
+ struct ndr_syntax_id map_syntax)
+{
+ struct epm_Map r;
+ struct GUID uuid;
+ struct policy_handle entry_handle;
+ struct ndr_syntax_id syntax;
+ struct dcerpc_binding map_binding;
+ struct epm_twr_t map_tower;
+ struct epm_twr_p_t towers[20];
+ struct epm_tower t;
+ uint32_t num_towers;
+ uint32_t port;
+ uint32_t i;
+ long int p;
+ const char *tmp;
+ const char *ip;
+ char *ptr;
+ NTSTATUS status;
+
+ torture_comment(tctx, "Testing epm_Map\n");
+
+ ZERO_STRUCT(uuid);
+ ZERO_STRUCT(entry_handle);
+
+ r.in.object = &uuid;
+ r.in.map_tower = &map_tower;
+ r.in.entry_handle = &entry_handle;
+ r.out.entry_handle = &entry_handle;
+ r.in.max_towers = 10;
+ r.out.towers = towers;
+ r.out.num_towers = &num_towers;
+
+ /* Create map tower */
+ map_binding.transport = NCACN_IP_TCP;
+ map_binding.object = map_syntax;
+ map_binding.host = "0.0.0.0";
+ map_binding.endpoint = "135";
+
+ status = dcerpc_binding_build_tower(tctx, &map_binding,
+ &map_tower.tower);
+ torture_assert_ntstatus_ok(tctx, status,
+ "epm_Map_tcpip failed: can't create map_tower");
+
+ torture_comment(tctx,
+ "epm_Map request for '%s':\n",
+ ndr_interface_name(&map_syntax.uuid, map_syntax.if_version));
+ display_tower(tctx, &r.in.map_tower->tower);
+
+ status = dcerpc_epm_Map_r(h, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "epm_Map_simple failed");
+ torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK,
+ "epm_Map_tcpip failed: result is not EPMAPPER_STATUS_OK");
+
+ /* Check the result */
+ t = r.out.towers[0].twr->tower;
+
+ /* Check if we got the correct RPC interface identifier */
+ dcerpc_floor_get_lhs_data(&t.floors[0], &syntax);
+ torture_assert(tctx, ndr_syntax_id_equal(&syntax, &map_syntax),
+ "epm_Map_tcpip failed: Interface identifier mismatch");
+
+ torture_comment(tctx,
+ "epm_Map_tcpip response for '%s':\n",
+ ndr_interface_name(&syntax.uuid, syntax.if_version));
+
+ dcerpc_floor_get_lhs_data(&t.floors[1], &syntax);
+ torture_assert(tctx, ndr_syntax_id_equal(&syntax, &ndr_transfer_syntax),
+ "epm_Map_tcpip failed: floor 2 is not NDR encoded");
+
+ torture_assert(tctx, t.floors[2].lhs.protocol == EPM_PROTOCOL_NCACN,
+ "epm_Map_tcpip failed: floor 3 is not NCACN_IP_TCP");
+
+ tmp = dcerpc_floor_get_rhs_data(tctx, &t.floors[3]);
+ p = strtol(tmp, &ptr, 10);
+ port = p & 0xffff;
+ torture_assert(tctx, port > 1024 && port < 65535, "epm_Map_tcpip failed");
+
+ ip = dcerpc_floor_get_rhs_data(tctx, &t.floors[4]);
+ torture_assert(tctx, is_ipaddress(ip), "epm_Map_tcpip failed");
+
+ for (i = 0; i < *r.out.num_towers; i++) {
+ if (r.out.towers[i].twr) {
+ display_tower(tctx, &t);
+ }
+ }
+
+ return true;
+}
+
+static bool test_Map_full(struct torture_context *tctx,
+ struct dcerpc_pipe *p)
+{
+ const struct ndr_syntax_id obj = {
+ { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
+ 2
+ };
+ struct dcerpc_binding_handle *h = p->binding_handle;
+ const char *annotation = "SMBTORTURE";
+ struct dcerpc_binding *b;
+ NTSTATUS status;
+ bool ok;
+
+ status = dcerpc_parse_binding(tctx, "ncacn_ip_tcp:216.83.154.106[41768]", &b);
+ torture_assert_ntstatus_ok(tctx,
+ status,
+ "Unable to generate dcerpc_binding struct");
+ b->object = obj;
+
+ ok = test_Insert(tctx, h, obj, annotation, b);
+ if (!ok) {
+ return false;
+ }
+
+ ok = test_Map_tcpip(tctx, h, obj);
+ if (!ok) {
+ return false;
+ }
+
+ ok = test_Delete(tctx, h, annotation, b);
+ if (!ok) {
+ return false;
+ }
+
+ return true;
+}
+
+static bool test_Map_display(struct dcerpc_binding_handle *b,
+ struct torture_context *tctx,
+ struct epm_twr_t *twr)
{
NTSTATUS status;
struct epm_Map r;
@@ -176,7 +399,7 @@ static bool test_Map_simple(struct torture_context *tctx,
for (i = 0; i < *r.out.num_ents; i++) {
if (r.out.entries[i].tower->tower.num_floors == 5) {
- test_Map(h, tctx, r.out.entries[i].tower);
+ test_Map_display(h, tctx, r.out.entries[i].tower);
}
}
} while (NT_STATUS_IS_OK(status) &&
@@ -348,95 +571,6 @@ static bool test_Lookup_terminate_search(struct torture_context *tctx,
return true;
}
-static bool test_Delete(struct torture_context *tctx,
- struct dcerpc_binding_handle *h,
- const char *annotation,
- struct dcerpc_binding *b)
-{
- NTSTATUS status;
- struct epm_Delete r;
-
- r.in.num_ents = 1;
- r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
-
- ZERO_STRUCT(r.in.entries[0].object);
- r.in.entries[0].annotation = annotation;
-
- r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
-
- status = dcerpc_binding_build_tower(tctx,
- b,
- &r.in.entries[0].tower->tower);
-
- torture_assert_ntstatus_ok(tctx,
- status,
- "Unable to build tower from binding struct");
- r.in.num_ents = 1;
-
- status = dcerpc_epm_Delete_r(h, tctx, &r);
- if (NT_STATUS_IS_ERR(status)) {
- torture_comment(tctx,
- "epm_Delete failed - %s\n",
- nt_errstr(status));
- return false;
- }
-
- if (r.out.result != EPMAPPER_STATUS_OK) {
- torture_comment(tctx,
- "epm_Delete failed - internal error: 0x%.4x\n",
- r.out.result);
- return false;
- }
-
- return true;
-}
-
-static bool test_Insert(struct torture_context *tctx,
- struct dcerpc_binding_handle *h,
- const char *annotation,
- struct dcerpc_binding *b)
-{
- struct epm_Insert r;
- NTSTATUS status;
-
- r.in.num_ents = 1;
- r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
-
- ZERO_STRUCT(r.in.entries[0].object);
- r.in.entries[0].annotation = annotation;
-
-
- r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
-
- status = dcerpc_binding_build_tower(tctx,
- b,
- &r.in.entries[0].tower->tower);
-
- torture_assert_ntstatus_ok(tctx,
- status,
- "Unable to build tower from binding struct");
- r.in.replace = 0;
-
- /* shoot! */
- status = dcerpc_epm_Insert_r(h, tctx, &r);
-
- if (NT_STATUS_IS_ERR(status)) {
- torture_comment(tctx,
- "epm_Insert failed - %s\n",
- nt_errstr(status));
- return false;
- }
-
- if (r.out.result != EPMAPPER_STATUS_OK) {
- torture_comment(tctx,
- "epm_Insert failed - internal error: 0x%.4x\n",
- r.out.result);
- return false;
- }
-
- return true;
-}
-
static bool test_Insert_noreplace(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
@@ -526,10 +660,12 @@ struct torture_suite *torture_rpc_epmapper(TALLOC_CTX *mem_ctx)
"Lookup_simple",
test_Lookup_simple);
torture_rpc_tcase_add_test(tcase,
+ "Map_full",
+ test_Map_full);
+ torture_rpc_tcase_add_test(tcase,
"Map_simple",
test_Map_simple);
-
return suite;
}