Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 :
4 : scanner for rpc calls
5 :
6 : Copyright (C) Andrew Tridgell 2003
7 :
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.
12 :
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.
17 :
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/>.
20 : */
21 :
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"
27 :
28 : /*
29 : work out how many calls there are for an interface
30 : */
31 0 : 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)
35 : {
36 0 : struct dcerpc_pipe *p;
37 0 : NTSTATUS status;
38 0 : unsigned int i;
39 0 : DATA_BLOB stub_in, stub_out;
40 0 : struct ndr_interface_table _tbl;
41 0 : const struct ndr_interface_table *tbl;
42 :
43 : /* FIXME: This should be fixed when torture_rpc_connection
44 : * takes a ndr_syntax_id */
45 0 : tbl = ndr_table_by_syntax(id);
46 0 : if (tbl == NULL) {
47 0 : _tbl = *iface;
48 0 : _tbl.name = "__unknown__";
49 0 : _tbl.syntax_id = *id;
50 0 : _tbl.num_calls = UINT32_MAX;
51 0 : tbl = &_tbl;
52 : }
53 :
54 0 : status = torture_rpc_connection(tctx, &p, tbl);
55 0 : if (!NT_STATUS_IS_OK(status)) {
56 0 : char *uuid_str = GUID_string(mem_ctx, &id->uuid);
57 0 : printf("Failed to connect to '%s' on '%s' - %s\n",
58 0 : uuid_str, iface->name, nt_errstr(status));
59 0 : talloc_free(uuid_str);
60 0 : return true;
61 : }
62 :
63 : /* make null calls */
64 0 : stub_in = data_blob_talloc(mem_ctx, NULL, 1000);
65 0 : memset(stub_in.data, 0xFF, stub_in.length);
66 :
67 0 : for (i=0;i<200;i++) {
68 0 : bool ok;
69 0 : uint32_t out_flags = 0;
70 :
71 0 : status = dcerpc_binding_handle_raw_call(p->binding_handle,
72 : NULL, i,
73 : 0, /* in_flags */
74 0 : stub_in.data,
75 : stub_in.length,
76 : mem_ctx,
77 : &stub_out.data,
78 : &stub_out.length,
79 : &out_flags);
80 0 : ok = dcerpc_binding_handle_is_connected(p->binding_handle);
81 0 : if (!ok) {
82 0 : printf("\tpipe disconnected at %u\n", i);
83 0 : goto done;
84 : }
85 :
86 0 : if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
87 0 : break;
88 : }
89 :
90 0 : if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
91 0 : printf("\taccess denied at %u\n", i);
92 0 : goto done;
93 : }
94 :
95 0 : if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTOCOL_ERROR)) {
96 0 : printf("\tprotocol error at %u\n", i);
97 : }
98 : }
99 :
100 0 : printf("\t%d calls available\n", i);
101 0 : if (tbl->num_calls == UINT32_MAX) {
102 0 : printf("\tinterface not known in local IDL\n");
103 0 : } else if (tbl->num_calls != i) {
104 0 : printf("\tWARNING: local IDL defines %u calls\n",
105 0 : (unsigned int)tbl->num_calls);
106 : } else {
107 0 : printf("\tOK: matches num_calls in local IDL\n");
108 : }
109 :
110 0 : done:
111 0 : talloc_free(p);
112 0 : return true;
113 : }
114 :
115 :
116 :
117 0 : bool torture_rpc_scanner(struct torture_context *torture)
118 : {
119 0 : NTSTATUS status;
120 0 : struct dcerpc_pipe *p;
121 0 : TALLOC_CTX *loop_ctx;
122 0 : bool ret = true;
123 0 : const struct ndr_interface_list *l;
124 0 : struct dcerpc_binding *b;
125 0 : enum dcerpc_transport_t transport;
126 :
127 0 : status = torture_rpc_binding(torture, &b);
128 0 : if (!NT_STATUS_IS_OK(status)) {
129 0 : return false;
130 : }
131 0 : transport = dcerpc_binding_get_transport(b);
132 :
133 0 : for (l=ndr_table_list();l;l=l->next) {
134 0 : loop_ctx = talloc_named(torture, 0, "torture_rpc_scanner loop context");
135 : /* some interfaces are not mappable */
136 0 : if (l->table->num_calls == 0 ||
137 0 : strcmp(l->table->name, "mgmt") == 0) {
138 0 : talloc_free(loop_ctx);
139 0 : continue;
140 : }
141 :
142 0 : printf("\nTesting pipe '%s'\n", l->table->name);
143 :
144 0 : if (transport == NCACN_IP_TCP) {
145 0 : status = dcerpc_epm_map_binding(torture, b, l->table,
146 : torture->ev,
147 : torture->lp_ctx);
148 0 : if (!NT_STATUS_IS_OK(status)) {
149 0 : printf("Failed to map port for uuid %s\n",
150 0 : GUID_string(loop_ctx, &l->table->syntax_id.uuid));
151 0 : talloc_free(loop_ctx);
152 0 : continue;
153 : }
154 : } else {
155 0 : status = dcerpc_binding_set_string_option(b, "endpoint",
156 0 : l->table->name);
157 0 : if (!NT_STATUS_IS_OK(status)) {
158 0 : talloc_free(loop_ctx);
159 0 : ret = false;
160 0 : continue;
161 : }
162 0 : status = dcerpc_binding_set_abstract_syntax(b,
163 0 : &l->table->syntax_id);
164 0 : if (!NT_STATUS_IS_OK(status)) {
165 0 : talloc_free(loop_ctx);
166 0 : ret = false;
167 0 : continue;
168 : }
169 : }
170 :
171 0 : lpcfg_set_cmdline(torture->lp_ctx, "torture:binding", dcerpc_binding_string(torture, b));
172 :
173 0 : status = torture_rpc_connection(torture, &p, &ndr_table_mgmt);
174 0 : if (!NT_STATUS_IS_OK(status)) {
175 0 : talloc_free(loop_ctx);
176 0 : ret = false;
177 0 : continue;
178 : }
179 :
180 0 : if (!test_inq_if_ids(torture, p->binding_handle, torture, test_num_calls, l->table)) {
181 0 : ret = false;
182 : }
183 : }
184 :
185 0 : return ret;
186 : }
187 :
|