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.
26 static const char *machine_password;
28 #define TEST_MACHINE_NAME "torturetest"
31 static void reopen(struct dcerpc_pipe **p, const struct dcerpc_interface_table *iface)
36 dcerpc_pipe_close(*p);
39 status = torture_rpc_connection(p, iface->endpoints->names[0], iface->uuid, iface->if_version);
40 if (!NT_STATUS_IS_OK(status)) {
41 printf("Failed to reopen '%s' - %s\n", iface->name, nt_errstr(status));
46 static void print_depth(int depth)
49 for (i=0;i<depth;i++) {
54 static void test_ptr_scan(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *iface,
55 int opnum, DATA_BLOB *base_in, int min_ofs, int max_ofs, int depth);
57 static void try_expand(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *iface,
58 int opnum, DATA_BLOB *base_in, int insert_ofs, int depth)
60 DATA_BLOB stub_in, stub_out;
63 struct dcerpc_pipe *p = NULL;
67 /* work out how much to expand to get a non fault */
68 for (n=0;n<2000;n++) {
69 stub_in = data_blob(NULL, base_in->length + n);
70 data_blob_clear(&stub_in);
71 memcpy(stub_in.data, base_in->data, insert_ofs);
72 memcpy(stub_in.data+insert_ofs+n, base_in->data+insert_ofs, base_in->length-insert_ofs);
74 status = dcerpc_request(p, opnum, mem_ctx, &stub_in, &stub_out);
76 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
78 printf("expand by %d gives %s\n", n, nt_errstr(status));
80 test_ptr_scan(mem_ctx, iface, opnum, &stub_in,
81 insert_ofs, insert_ofs+n, depth+1);
87 printf("expand by %d gives fault 0x%x\n", n, p->last_fault_code);
90 if (p->last_fault_code == 5) {
99 static void test_ptr_scan(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *iface,
100 int opnum, DATA_BLOB *base_in, int min_ofs, int max_ofs, int depth)
102 DATA_BLOB stub_in, stub_out;
105 struct dcerpc_pipe *p = NULL;
109 stub_in = data_blob(NULL, base_in->length);
110 memcpy(stub_in.data, base_in->data, base_in->length);
112 /* work out which elements are pointers */
113 for (ofs=min_ofs;ofs<=max_ofs-4;ofs+=4) {
114 SIVAL(stub_in.data, ofs, 1);
115 status = dcerpc_request(p, opnum, mem_ctx, &stub_in, &stub_out);
117 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
119 printf("possible ptr at ofs %d - fault 0x%08x\n",
120 ofs-min_ofs, p->last_fault_code);
121 if (p->last_fault_code == 5) {
125 try_expand(mem_ctx, iface, opnum, &stub_in, ofs+4, depth+1);
127 try_expand(mem_ctx, iface, opnum, &stub_in, max_ofs, depth+1);
129 SIVAL(stub_in.data, ofs, 0);
132 SIVAL(stub_in.data, ofs, 0);
135 dcerpc_pipe_close(p);
139 static void test_scan_call(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *iface, int opnum)
141 DATA_BLOB stub_in, stub_out;
144 struct dcerpc_pipe *p = NULL;
148 /* work out the minimum amount of input data */
149 for (i=0;i<2000;i++) {
150 stub_in = data_blob(NULL, i);
151 data_blob_clear(&stub_in);
154 status = dcerpc_request(p, opnum, mem_ctx, &stub_in, &stub_out);
156 if (NT_STATUS_IS_OK(status)) {
157 printf("opnum %d min_input %d - output %d\n",
158 opnum, stub_in.length, stub_out.length);
159 dump_data(0, stub_out.data, stub_out.length);
160 dcerpc_pipe_close(p);
161 test_ptr_scan(mem_ctx, iface, opnum, &stub_in, 0, stub_in.length, 0);
165 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
166 printf("opnum %d size %d fault 0x%08x\n", opnum, i, p->last_fault_code);
167 if (p->last_fault_code == 5) {
173 printf("opnum %d size %d error %s\n", opnum, i, nt_errstr(status));
176 printf("opnum %d minimum not found!?\n", opnum);
177 dcerpc_pipe_close(p);
181 static BOOL test_scan(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
183 test_scan_call(mem_ctx, &dcerpc_table_drsuapi, 0x0);
188 static BOOL test_DRSBind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
191 struct DRSUAPI_BIND r;
194 ZERO_STRUCT(r.in.blob);
196 status = dcerpc_DRSUAPI_BIND(p, mem_ctx, &r);
197 if (!NT_STATUS_IS_OK(status)) {
198 const char *errstr = nt_errstr(status);
199 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
200 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
202 printf("DRSUAPI_BIND level failed - %s\n", errstr);
209 BOOL torture_rpc_drsuapi(int dummy)
212 struct dcerpc_pipe *p;
216 const char *binding = lp_parm_string(-1, "torture", "binding");
219 printf("You must specify a ncacn binding string\n");
223 lp_set_cmdline("netbios name", TEST_MACHINE_NAME);
225 join_ctx = torture_join_domain(TEST_MACHINE_NAME, lp_workgroup(), ACB_SVRTRUST,
228 printf("Failed to join as BDC\n");
232 status = dcerpc_pipe_connect(&p, binding,
234 DCERPC_DRSUAPI_VERSION,
236 TEST_MACHINE_NAME"$",
239 if (!NT_STATUS_IS_OK(status)) {
243 mem_ctx = talloc_init("torture_rpc_drsuapi");
245 if (!test_DRSBind(p, mem_ctx)) {
250 if (!test_scan(p, mem_ctx)) {
254 talloc_destroy(mem_ctx);
256 torture_rpc_close(p);
258 torture_leave_domain(join_ctx);