2 Unix SMB/CIFS implementation.
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/>.
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
,
34 struct ndr_syntax_id
*id
)
36 struct dcerpc_pipe
*p
;
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
);
48 _tbl
.name
= "__unknown__";
50 _tbl
.num_calls
= UINT32_MAX
;
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
);
64 stub_in
= data_blob_talloc(mem_ctx
, NULL
, 1000);
65 memset(stub_in
.data
, 0xFF, stub_in
.length
);
69 uint32_t out_flags
= 0;
71 status
= dcerpc_binding_handle_raw_call(p
->binding_handle
,
80 ok
= dcerpc_binding_handle_is_connected(p
->binding_handle
);
82 printf("\tpipe disconnected at %u\n", i
);
86 if (NT_STATUS_EQUAL(status
, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE
)) {
90 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
91 printf("\taccess denied at %u\n", i
);
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
);
107 printf("\tOK: matches num_calls in local IDL\n");
117 bool torture_rpc_scanner(struct torture_context
*torture
)
120 struct dcerpc_pipe
*p
;
121 TALLOC_CTX
*loop_ctx
;
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
)) {
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
);
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
,
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
);
155 status
= dcerpc_binding_set_string_option(b
, "endpoint",
157 if (!NT_STATUS_IS_OK(status
)) {
158 talloc_free(loop_ctx
);
162 status
= dcerpc_binding_set_abstract_syntax(b
,
163 &l
->table
->syntax_id
);
164 if (!NT_STATUS_IS_OK(status
)) {
165 talloc_free(loop_ctx
);
171 lpcfg_set_cmdline(torture
->lp_ctx
, "torture:binding", dcerpc_binding_string(torture
, b
));
173 status
= torture_rpc_connection(torture
, &p
, &ndr_table_mgmt
);
174 if (!NT_STATUS_IS_OK(status
)) {
175 talloc_free(loop_ctx
);
180 if (!test_inq_if_ids(torture
, p
->binding_handle
, torture
, test_num_calls
, l
->table
)) {