s4:torture/rpc: make use of dcerpc_binding_[g|s]et_transport()
[Samba.git] / source4 / torture / rpc / scanner.c
blobe910bddedc504826a76376b2003fc38417117f4d
1 /*
2 Unix SMB/CIFS implementation.
4 scanner for rpc calls
6 Copyright (C) Andrew Tridgell 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "librpc/gen_ndr/ndr_mgmt_c.h"
24 #include "librpc/ndr/ndr_table.h"
25 #include "torture/rpc/torture_rpc.h"
26 #include "param/param.h"
29 work out how many calls there are for an interface
31 static bool test_num_calls(struct torture_context *tctx,
32 const struct ndr_interface_table *iface,
33 TALLOC_CTX *mem_ctx,
34 struct ndr_syntax_id *id)
36 struct dcerpc_pipe *p;
37 NTSTATUS status;
38 unsigned int i;
39 DATA_BLOB stub_in, stub_out;
40 struct ndr_interface_table _tbl;
41 const struct ndr_interface_table *tbl;
43 /* FIXME: This should be fixed when torture_rpc_connection
44 * takes a ndr_syntax_id */
45 tbl = ndr_table_by_syntax(id);
46 if (tbl == NULL) {
47 _tbl = *iface;
48 _tbl.name = "__unknown__";
49 _tbl.syntax_id = *id;
50 _tbl.num_calls = UINT32_MAX;
51 tbl = &_tbl;
54 status = torture_rpc_connection(tctx, &p, tbl);
55 if (!NT_STATUS_IS_OK(status)) {
56 char *uuid_str = GUID_string(mem_ctx, &id->uuid);
57 printf("Failed to connect to '%s' on '%s' - %s\n",
58 uuid_str, iface->name, nt_errstr(status));
59 talloc_free(uuid_str);
60 return true;
63 /* make null calls */
64 stub_in = data_blob_talloc(mem_ctx, NULL, 1000);
65 memset(stub_in.data, 0xFF, stub_in.length);
67 for (i=0;i<200;i++) {
68 bool ok;
69 uint32_t out_flags = 0;
71 status = dcerpc_binding_handle_raw_call(p->binding_handle,
72 NULL, i,
73 0, /* in_flags */
74 stub_in.data,
75 stub_in.length,
76 mem_ctx,
77 &stub_out.data,
78 &stub_out.length,
79 &out_flags);
80 ok = dcerpc_binding_handle_is_connected(p->binding_handle);
81 if (!ok) {
82 printf("\tpipe disconnected at %u\n", i);
83 goto done;
86 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
87 break;
90 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
91 printf("\taccess denied at %u\n", i);
92 goto done;
95 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTOCOL_ERROR)) {
96 printf("\tprotocol error at %u\n", i);
100 printf("\t%d calls available\n", i);
101 if (tbl->num_calls == UINT32_MAX) {
102 printf("\tinterface not known in local IDL\n");
103 } else if (tbl->num_calls != i) {
104 printf("\tWARNING: local IDL defines %u calls\n",
105 (unsigned int)tbl->num_calls);
106 } else {
107 printf("\tOK: matches num_calls in local IDL\n");
110 done:
111 talloc_free(p);
112 return true;
117 bool torture_rpc_scanner(struct torture_context *torture)
119 NTSTATUS status;
120 struct dcerpc_pipe *p;
121 TALLOC_CTX *loop_ctx;
122 bool ret = true;
123 const struct ndr_interface_list *l;
124 struct dcerpc_binding *b;
125 enum dcerpc_transport_t transport;
127 status = torture_rpc_binding(torture, &b);
128 if (!NT_STATUS_IS_OK(status)) {
129 return false;
131 transport = dcerpc_binding_get_transport(b);
133 for (l=ndr_table_list();l;l=l->next) {
134 loop_ctx = talloc_named(torture, 0, "torture_rpc_scanner loop context");
135 /* some interfaces are not mappable */
136 if (l->table->num_calls == 0 ||
137 strcmp(l->table->name, "mgmt") == 0) {
138 talloc_free(loop_ctx);
139 continue;
142 printf("\nTesting pipe '%s'\n", l->table->name);
144 if (transport == NCACN_IP_TCP) {
145 status = dcerpc_epm_map_binding(torture, b, l->table,
146 torture->ev,
147 torture->lp_ctx);
148 if (!NT_STATUS_IS_OK(status)) {
149 printf("Failed to map port for uuid %s\n",
150 GUID_string(loop_ctx, &l->table->syntax_id.uuid));
151 talloc_free(loop_ctx);
152 continue;
154 } else {
155 b->endpoint = talloc_strdup(b, l->table->name);
158 lpcfg_set_cmdline(torture->lp_ctx, "torture:binding", dcerpc_binding_string(torture, b));
160 status = torture_rpc_connection(torture, &p, &ndr_table_mgmt);
161 if (!NT_STATUS_IS_OK(status)) {
162 talloc_free(loop_ctx);
163 ret = false;
164 continue;
167 if (!test_inq_if_ids(torture, p->binding_handle, torture, test_num_calls, l->table)) {
168 ret = false;
172 return ret;