libcli/cldap: make use of samba_tevent_context_init()
[Samba/gebeck_regimport.git] / source4 / torture / rpc / scanner.c
blob0af35fa3e68b5bb46737a8aa6d50f41268fa1994
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 int i;
39 DATA_BLOB stub_in, stub_out;
40 int idl_calls;
41 struct ndr_interface_table tbl;
43 /* FIXME: This should be fixed when torture_rpc_connection
44 * takes a ndr_syntax_id */
45 tbl.name = iface->name;
46 tbl.syntax_id = *id;
48 status = torture_rpc_connection(tctx, &p, iface);
49 if (!NT_STATUS_IS_OK(status)) {
50 char *uuid_str = GUID_string(mem_ctx, &id->uuid);
51 printf("Failed to connect to '%s' on '%s' - %s\n",
52 uuid_str, iface->name, nt_errstr(status));
53 talloc_free(uuid_str);
54 return true;
57 /* make null calls */
58 stub_in = data_blob_talloc(mem_ctx, NULL, 1000);
59 memset(stub_in.data, 0xFF, stub_in.length);
61 for (i=0;i<200;i++) {
62 uint32_t out_flags = 0;
63 status = dcerpc_binding_handle_raw_call(p->binding_handle,
64 NULL, i,
65 0, /* in_flags */
66 stub_in.data,
67 stub_in.length,
68 mem_ctx,
69 &stub_out.data,
70 &stub_out.length,
71 &out_flags);
72 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
73 break;
76 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
77 printf("\tpipe disconnected at %d\n", i);
78 goto done;
81 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTOCOL_ERROR)) {
82 printf("\tprotocol error at %d\n", i);
86 printf("\t%d calls available\n", i);
87 idl_calls = ndr_interface_num_calls(&id->uuid, id->if_version);
88 if (idl_calls == -1) {
89 printf("\tinterface not known in local IDL\n");
90 } else if (i != idl_calls) {
91 printf("\tWARNING: local IDL defines %u calls\n", idl_calls);
92 } else {
93 printf("\tOK: matches num_calls in local IDL\n");
96 done:
97 talloc_free(p);
98 return true;
103 bool torture_rpc_scanner(struct torture_context *torture)
105 NTSTATUS status;
106 struct dcerpc_pipe *p;
107 TALLOC_CTX *loop_ctx;
108 bool ret = true;
109 const struct ndr_interface_list *l;
110 struct dcerpc_binding *b;
112 status = torture_rpc_binding(torture, &b);
113 if (!NT_STATUS_IS_OK(status)) {
114 return false;
117 for (l=ndr_table_list();l;l=l->next) {
118 loop_ctx = talloc_named(torture, 0, "torture_rpc_scanner loop context");
119 /* some interfaces are not mappable */
120 if (l->table->num_calls == 0 ||
121 strcmp(l->table->name, "mgmt") == 0) {
122 talloc_free(loop_ctx);
123 continue;
126 printf("\nTesting pipe '%s'\n", l->table->name);
128 if (b->transport == NCACN_IP_TCP) {
129 status = dcerpc_epm_map_binding(torture, b, l->table, NULL, torture->lp_ctx);
130 if (!NT_STATUS_IS_OK(status)) {
131 printf("Failed to map port for uuid %s\n",
132 GUID_string(loop_ctx, &l->table->syntax_id.uuid));
133 talloc_free(loop_ctx);
134 continue;
136 } else {
137 b->endpoint = talloc_strdup(b, l->table->name);
140 lpcfg_set_cmdline(torture->lp_ctx, "torture:binding", dcerpc_binding_string(torture, b));
142 status = torture_rpc_connection(torture, &p, &ndr_table_mgmt);
143 if (!NT_STATUS_IS_OK(status)) {
144 talloc_free(loop_ctx);
145 ret = false;
146 continue;
149 if (!test_inq_if_ids(torture, p->binding_handle, torture, test_num_calls, l->table)) {
150 ret = false;
154 return ret;