2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Stefan (metze) Metzmacher 2004
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 static void reopen(struct dcerpc_pipe **p, const struct dcerpc_interface_table *iface)
32 dcerpc_pipe_close(*p);
35 status = torture_rpc_connection(p, iface->endpoints->names[0], iface->uuid, iface->if_version);
36 if (!NT_STATUS_IS_OK(status)) {
37 printf("Failed to reopen '%s' - %s\n", iface->name, nt_errstr(status));
42 static void print_depth(int depth)
45 for (i=0;i<depth;i++) {
50 static void test_ptr_scan(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *iface,
51 int opnum, DATA_BLOB *base_in, int min_ofs, int max_ofs, int depth);
53 static void try_expand(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *iface,
54 int opnum, DATA_BLOB *base_in, int insert_ofs, int depth)
56 DATA_BLOB stub_in, stub_out;
59 struct dcerpc_pipe *p = NULL;
63 /* work out how much to expand to get a non fault */
64 for (n=0;n<2000;n++) {
65 stub_in = data_blob(NULL, base_in->length + n);
66 data_blob_clear(&stub_in);
67 memcpy(stub_in.data, base_in->data, insert_ofs);
68 memcpy(stub_in.data+insert_ofs+n, base_in->data+insert_ofs, base_in->length-insert_ofs);
70 status = dcerpc_request(p, opnum, mem_ctx, &stub_in, &stub_out);
72 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
74 printf("expand by %d gives %s\n", n, nt_errstr(status));
76 test_ptr_scan(mem_ctx, iface, opnum, &stub_in,
77 insert_ofs, insert_ofs+n, depth+1);
83 printf("expand by %d gives fault 0x%x\n", n, p->last_fault_code);
86 if (p->last_fault_code == 5) {
95 static void test_ptr_scan(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *iface,
96 int opnum, DATA_BLOB *base_in, int min_ofs, int max_ofs, int depth)
98 DATA_BLOB stub_in, stub_out;
101 struct dcerpc_pipe *p = NULL;
105 stub_in = data_blob(NULL, base_in->length);
106 memcpy(stub_in.data, base_in->data, base_in->length);
108 /* work out which elements are pointers */
109 for (ofs=min_ofs;ofs<=max_ofs-4;ofs+=4) {
110 SIVAL(stub_in.data, ofs, 1);
111 status = dcerpc_request(p, opnum, mem_ctx, &stub_in, &stub_out);
113 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
115 printf("possible ptr at ofs %d - fault 0x%08x\n",
116 ofs-min_ofs, p->last_fault_code);
117 if (p->last_fault_code == 5) {
121 try_expand(mem_ctx, iface, opnum, &stub_in, ofs+4, depth+1);
123 try_expand(mem_ctx, iface, opnum, &stub_in, max_ofs, depth+1);
125 SIVAL(stub_in.data, ofs, 0);
128 SIVAL(stub_in.data, ofs, 0);
131 dcerpc_pipe_close(p);
135 static void test_scan_call(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *iface, int opnum)
137 DATA_BLOB stub_in, stub_out;
140 struct dcerpc_pipe *p = NULL;
144 /* work out the minimum amount of input data */
145 for (i=0;i<2000;i++) {
146 stub_in = data_blob(NULL, i);
147 data_blob_clear(&stub_in);
150 status = dcerpc_request(p, opnum, mem_ctx, &stub_in, &stub_out);
152 if (NT_STATUS_IS_OK(status)) {
153 printf("opnum %d min_input %d - output %d\n",
154 opnum, stub_in.length, stub_out.length);
155 dump_data(0, stub_out.data, stub_out.length);
156 dcerpc_pipe_close(p);
157 test_ptr_scan(mem_ctx, iface, opnum, &stub_in, 0, stub_in.length, 0);
161 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
162 printf("opnum %d size %d fault 0x%08x\n", opnum, i, p->last_fault_code);
163 if (p->last_fault_code == 5) {
169 printf("opnum %d size %d error %s\n", opnum, i, nt_errstr(status));
172 printf("opnum %d minimum not found!?\n", opnum);
173 dcerpc_pipe_close(p);
177 static BOOL test_scan(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
179 test_scan_call(mem_ctx, &dcerpc_table_drsuapi, 0x0);
183 static BOOL test_DRSBind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
186 struct DRSUAPI_BIND r;
189 ZERO_STRUCT(r.in.blob);
191 status = dcerpc_DRSUAPI_BIND(p, mem_ctx, &r);
192 if (!NT_STATUS_IS_OK(status)) {
193 printf("DRSUAPI_BIND level failed - %s\n", nt_errstr(status));
200 BOOL torture_rpc_drsuapi(int dummy)
203 struct dcerpc_pipe *p;
207 mem_ctx = talloc_init("torture_rpc_srvsvc");
209 status = torture_rpc_connection(&p,
212 DCERPC_DRSUAPI_VERSION);
213 if (!NT_STATUS_IS_OK(status)) {
217 if (!test_DRSBind(p, mem_ctx)) {
221 if (!test_scan(p, mem_ctx)) {
225 talloc_destroy(mem_ctx);
227 torture_rpc_close(p);