r21696: Run the RPC-COUNTCALLS test to try and walk some of the NDR layer for
[Samba/ekacnet.git] / source4 / torture / rpc / countcalls.c
blob80fdfd04c4cdb7bb8f676e1cd8f92cf46f900cc1
1 /*
2 Unix SMB/CIFS implementation.
4 count number of calls on an interface
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2007
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.
24 #include "includes.h"
25 #include "torture/torture.h"
26 #include "librpc/rpc/dcerpc.h"
27 #include "librpc/rpc/dcerpc_table.h"
28 #include "torture/rpc/rpc.h"
32 BOOL count_calls(TALLOC_CTX *mem_ctx,
33 const struct dcerpc_interface_table *iface,
34 BOOL all)
36 struct dcerpc_pipe *p;
37 DATA_BLOB stub_in, stub_out;
38 int i;
39 NTSTATUS status = torture_rpc_connection(mem_ctx, &p, iface);
40 if (NT_STATUS_EQUAL(NT_STATUS_OBJECT_NAME_NOT_FOUND, status)
41 || NT_STATUS_EQUAL(NT_STATUS_NET_WRITE_FAULT, status)
42 || NT_STATUS_EQUAL(NT_STATUS_PORT_UNREACHABLE, status)
43 || NT_STATUS_EQUAL(NT_STATUS_ACCESS_DENIED, status)) {
44 if (all) {
45 /* Not fatal if looking for all pipes */
46 return True;
47 } else {
48 printf("Failed to open '%s' to count calls - %s\n", iface->name, nt_errstr(status));
49 return False;
51 } else if (!NT_STATUS_IS_OK(status)) {
52 printf("Failed to open '%s' to count calls - %s\n", iface->name, nt_errstr(status));
53 return False;
56 stub_in = data_blob_talloc(p, mem_ctx, 0);
58 printf("\nScanning pipe '%s'\n", iface->name);
60 for (i=0;i<500;i++) {
61 status = dcerpc_request(p, mem_ctx, i, False, p, &stub_in, &stub_out);
62 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT) &&
63 p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
64 i--;
65 break;
67 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT) &&
68 p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
69 i--;
70 break;
72 if (NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED)) {
73 i--;
74 break;
76 if (NT_STATUS_EQUAL(status, NT_STATUS_PIPE_DISCONNECTED)) {
77 i--;
78 break;
80 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
81 i--;
82 break;
84 if (NT_STATUS_EQUAL(status, NT_STATUS_LOGON_FAILURE)) {
85 i--;
86 break;
90 if (i==500) {
91 talloc_free(p);
92 printf("no limit on calls: %s!?\n", nt_errstr(status));
93 return False;
96 printf("Found %d calls\n", i);
98 talloc_free(p);
100 return True;
104 BOOL torture_rpc_countcalls(struct torture_context *torture)
106 const struct dcerpc_interface_table *iface;
107 const char *iface_name;
108 BOOL ret = True;
109 const struct dcerpc_interface_list *l;
110 TALLOC_CTX *mem_ctx = talloc_named(torture, 0, "torture_rpc_countcalls context");
111 if (!mem_ctx) {
112 return False;
114 iface_name = lp_parm_string(-1, "countcalls", "interface");
115 if (iface_name != NULL) {
116 iface = idl_iface_by_name(iface_name);
117 if (!iface) {
118 printf("Unknown interface '%s'\n", iface_name);
119 return False;
121 return count_calls(mem_ctx, iface, False);
124 for (l=librpc_dcerpc_pipes();l;l=l->next) {
125 TALLOC_CTX *loop_ctx;
126 loop_ctx = talloc_named(mem_ctx, 0, "torture_rpc_councalls loop context");
127 ret &= count_calls(loop_ctx, l->table, True);
128 talloc_free(loop_ctx);
130 return ret;