1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
Unix SMB/CIFS implementation.
auto-idl scanner
Copyright (C) Andrew Tridgell 2003
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
static void reopen(struct dcerpc_pipe **p, const struct dcerpc_interface_table *iface)
{
NTSTATUS status;
if (*p) {
dcerpc_pipe_close(*p);
}
status = torture_rpc_connection(p, iface->endpoints->names[0], iface->uuid, iface->if_version);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to reopen '%s' - %s\n", iface->name, nt_errstr(status));
exit(1);
}
}
static void test_ptr_scan(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *iface,
int opnum, int min_in)
{
DATA_BLOB stub_in, stub_out;
int ofs;
NTSTATUS status;
struct dcerpc_pipe *p = NULL;
reopen(&p, iface);
stub_in = data_blob(NULL, min_in);
data_blob_clear(&stub_in);
/* work out the minimum amount of input data */
for (ofs=0;ofs<min_in;ofs+=4) {
SIVAL(stub_in.data, ofs, 1);
status = dcerpc_request(p, opnum, mem_ctx, &stub_in, &stub_out);
SIVAL(stub_in.data, ofs, 0);
if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
printf("opnum %d ofs %d size %d fault 0x%08x\n",
opnum, ofs, min_in, p->last_fault_code);
if (p->last_fault_code == 5) {
reopen(&p, iface);
}
continue;
}
printf("opnum %d ofs %d error %s\n", opnum, ofs, nt_errstr(status));
}
dcerpc_pipe_close(p);
}
static void test_scan_call(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *iface, int opnum)
{
DATA_BLOB stub_in, stub_out;
int i;
NTSTATUS status;
struct dcerpc_pipe *p = NULL;
reopen(&p, iface);
/* work out the minimum amount of input data */
for (i=0;i<100;i++) {
stub_in = data_blob(NULL, i);
data_blob_clear(&stub_in);
status = dcerpc_request(p, opnum, mem_ctx, &stub_in, &stub_out);
if (NT_STATUS_IS_OK(status)) {
printf("opnum %d min_input %d - output %d\n",
opnum, stub_in.length, stub_out.length);
dcerpc_pipe_close(p);
test_ptr_scan(mem_ctx, iface, opnum, stub_in.length);
return;
}
if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
printf("opnum %d size %d fault 0x%08x\n", opnum, i, p->last_fault_code);
if (p->last_fault_code == 5) {
reopen(&p, iface);
}
continue;
}
printf("opnum %d size %d error %s\n", opnum, i, nt_errstr(status));
}
printf("opnum %d minimum not found!?\n", opnum);
dcerpc_pipe_close(p);
}
static void test_auto_scan(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *iface)
{
int i;
for (i=0;i<100;i++) {
test_scan_call(mem_ctx, iface, i);
}
}
BOOL torture_rpc_autoidl(int dummy)
{
NTSTATUS status;
TALLOC_CTX *mem_ctx;
const struct dcerpc_interface_table *iface;
char *host = lp_parm_string(-1, "torture", "host");
char *transport = lp_parm_string(-1, "torture", "transport");
iface = idl_iface_by_name("browser");
if (!iface) {
printf("Unknown interface!\n");
return False;
}
mem_ctx = talloc_init("torture_rpc_autoidl");
printf("\nProbing pipe '%s'\n", iface->name);
/* on TCP we need to find the right endpoint */
if (strcasecmp(transport, "ncacn_ip_tcp") == 0) {
uint32 port;
status = dcerpc_epm_map_tcp_port(host, iface->uuid, iface->if_version, &port);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
lp_set_cmdline("torture:share", talloc_asprintf(mem_ctx, "%u", port));
}
test_auto_scan(mem_ctx, iface);
return True;
}
|