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 "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_mgmt_c.h"
25 #include "librpc/ndr/ndr_table.h"
26 #include "torture/rpc/rpc.h"
27 #include "param/param.h"
28 #include "librpc/rpc/dcerpc_proto.h"
31 work out how many calls there are for an interface
33 static bool test_num_calls(struct torture_context
*tctx
,
34 const struct ndr_interface_table
*iface
,
36 struct ndr_syntax_id
*id
)
38 struct dcerpc_pipe
*p
;
41 DATA_BLOB stub_in
, stub_out
;
43 struct ndr_interface_table tbl
;
45 /* FIXME: This should be fixed when torture_rpc_connection
46 * takes a ndr_syntax_id */
47 tbl
.name
= iface
->name
;
50 status
= torture_rpc_connection(tctx
, &p
, iface
);
51 if (!NT_STATUS_IS_OK(status
)) {
52 char *uuid_str
= GUID_string(mem_ctx
, &id
->uuid
);
53 printf("Failed to connect to '%s' on '%s' - %s\n",
54 uuid_str
, iface
->name
, nt_errstr(status
));
55 talloc_free(uuid_str
);
60 stub_in
= data_blob(NULL
, 1000);
61 memset(stub_in
.data
, 0xFF, stub_in
.length
);
64 status
= dcerpc_request(p
, NULL
, i
, mem_ctx
, &stub_in
, &stub_out
);
65 if (!NT_STATUS_IS_OK(status
) &&
66 p
->last_fault_code
== DCERPC_FAULT_OP_RNG_ERROR
) {
70 if (!NT_STATUS_IS_OK(status
) && p
->last_fault_code
== 5) {
71 printf("\tpipe disconnected at %d\n", i
);
75 if (!NT_STATUS_IS_OK(status
) && p
->last_fault_code
== 0x80010111) {
76 printf("\terr 0x80010111 at %d\n", i
);
81 printf("\t%d calls available\n", i
);
82 idl_calls
= ndr_interface_num_calls(&id
->uuid
, id
->if_version
);
83 if (idl_calls
== -1) {
84 printf("\tinterface not known in local IDL\n");
85 } else if (i
!= idl_calls
) {
86 printf("\tWARNING: local IDL defines %u calls\n", idl_calls
);
88 printf("\tOK: matches num_calls in local IDL\n");
98 bool torture_rpc_scanner(struct torture_context
*torture
)
101 struct dcerpc_pipe
*p
;
102 TALLOC_CTX
*loop_ctx
;
104 const struct ndr_interface_list
*l
;
105 struct dcerpc_binding
*b
;
107 status
= torture_rpc_binding(torture
, &b
);
108 if (!NT_STATUS_IS_OK(status
)) {
112 for (l
=ndr_table_list();l
;l
=l
->next
) {
113 loop_ctx
= talloc_named(torture
, 0, "torture_rpc_scanner loop context");
114 /* some interfaces are not mappable */
115 if (l
->table
->num_calls
== 0 ||
116 strcmp(l
->table
->name
, "mgmt") == 0) {
117 talloc_free(loop_ctx
);
121 printf("\nTesting pipe '%s'\n", l
->table
->name
);
123 if (b
->transport
== NCACN_IP_TCP
) {
124 status
= dcerpc_epm_map_binding(torture
, b
, l
->table
, NULL
, torture
->lp_ctx
);
125 if (!NT_STATUS_IS_OK(status
)) {
126 printf("Failed to map port for uuid %s\n",
127 GUID_string(loop_ctx
, &l
->table
->syntax_id
.uuid
));
128 talloc_free(loop_ctx
);
132 b
->endpoint
= talloc_strdup(b
, l
->table
->name
);
135 lp_set_cmdline(torture
->lp_ctx
, "torture:binding", dcerpc_binding_string(torture
, b
));
137 status
= torture_rpc_connection(torture
, &p
, &ndr_table_mgmt
);
138 if (!NT_STATUS_IS_OK(status
)) {
139 talloc_free(loop_ctx
);
144 if (!test_inq_if_ids(torture
, p
, torture
, test_num_calls
, l
->table
)) {