r6961: Add RPC-WINREG to list of win2k3 tests
[samba.git] / source / torture / rpc / countcalls.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    count number of calls on an interface
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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25
26 BOOL torture_rpc_countcalls(void)
27 {
28         const struct dcerpc_interface_table *iface;
29         NTSTATUS status;
30         struct dcerpc_pipe *p;
31         int i;
32         const char *iface_name;
33         DATA_BLOB stub_in, stub_out;
34         
35         iface_name = lp_parm_string(-1, "countcalls", "interface");
36         if (iface_name == NULL) {
37                 printf("You must specify an interface name with countcalls:interface\n");
38                 return False;
39         }
40
41         iface = idl_iface_by_name(iface_name);
42         if (!iface) {
43                 printf("Unknown interface '%s'\n", iface_name);
44                 return False;
45         }
46
47         status = torture_rpc_connection(NULL, &p, iface->endpoints->names[0], 
48                                         iface->uuid, iface->if_version);
49         if (!NT_STATUS_IS_OK(status)) {
50                 printf("Failed to open '%s' - %s\n", iface->name, nt_errstr(status));
51                 return False;
52         }
53
54         stub_in = data_blob_talloc(p, NULL, 0);
55
56         printf("\nScanning pipe '%s'\n", iface->name);
57
58         for (i=0;i<5000;i++) {
59                 status = dcerpc_request(p, NULL, i, p, &stub_in, &stub_out);
60                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT) &&
61                     p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) break;
62                 if (NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED)) {
63                         break;
64                 }
65         }
66         
67         if (i==5000) {
68                 talloc_free(p);
69                 printf("no limit on calls!?\n");
70                 return False;
71         }
72
73         printf("Found %d calls\n", i);
74
75         talloc_free(p);
76
77         return True;
78 }