r25026: Move param/param.h out of includes.h
[samba.git] / source4 / torture / rpc / scanner.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    scanner for rpc calls
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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_mgmt_c.h"
25 #include "librpc/ndr/ndr_table.h"
26 #include "torture/rpc/rpc.h"
27 #include "param/param.h"
28
29 /*
30   work out how many calls there are for an interface
31  */
32 static bool test_num_calls(struct torture_context *tctx, 
33                            const struct ndr_interface_table *iface,
34                            TALLOC_CTX *mem_ctx,
35                            struct ndr_syntax_id *id)
36 {
37         struct dcerpc_pipe *p;
38         NTSTATUS status;
39         int i;
40         DATA_BLOB stub_in, stub_out;
41         int idl_calls;
42         struct ndr_interface_table tbl;
43
44         /* FIXME: This should be fixed when torture_rpc_connection 
45          * takes a ndr_syntax_id */
46         tbl.name = iface->name;
47         tbl.syntax_id = *id;
48
49         status = torture_rpc_connection(tctx, &p, iface);
50         if (!NT_STATUS_IS_OK(status)) {
51                 char *uuid_str = GUID_string(mem_ctx, &id->uuid);
52                 printf("Failed to connect to '%s' on '%s' - %s\n", 
53                        uuid_str, iface->name, nt_errstr(status));
54                 talloc_free(uuid_str);
55                 return True;
56         }
57
58         /* make null calls */
59         stub_in = data_blob(NULL, 1000);
60         memset(stub_in.data, 0xFF, stub_in.length);
61
62         for (i=0;i<200;i++) {
63                 status = dcerpc_request(p, NULL, i, False, mem_ctx, &stub_in, &stub_out);
64                 if (!NT_STATUS_IS_OK(status) &&
65                     p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
66                         break;
67                 }
68
69                 if (!NT_STATUS_IS_OK(status) && p->last_fault_code == 5) {
70                         printf("\tpipe disconnected at %d\n", i);
71                         goto done;
72                 }
73
74                 if (!NT_STATUS_IS_OK(status) && p->last_fault_code == 0x80010111) {
75                         printf("\terr 0x80010111 at %d\n", i);
76                         goto done;
77                 }
78         }
79
80         printf("\t%d calls available\n", i);
81         idl_calls = ndr_interface_num_calls(&id->uuid, id->if_version);
82         if (idl_calls == -1) {
83                 printf("\tinterface not known in local IDL\n");
84         } else if (i != idl_calls) {
85                 printf("\tWARNING: local IDL defines %u calls\n", idl_calls);
86         } else {
87                 printf("\tOK: matches num_calls in local IDL\n");
88         }
89
90 done:
91         talloc_free(p);
92         return true;
93 }
94
95
96
97 bool torture_rpc_scanner(struct torture_context *torture)
98 {
99         NTSTATUS status;
100         struct dcerpc_pipe *p;
101         TALLOC_CTX *loop_ctx;
102         BOOL ret = True;
103         const struct ndr_interface_list *l;
104         struct dcerpc_binding *b;
105
106         status = torture_rpc_binding(torture, &b);
107         if (!NT_STATUS_IS_OK(status)) {
108                 return false;
109         }
110
111         for (l=ndr_table_list();l;l=l->next) {          
112                 loop_ctx = talloc_named(torture, 0, "torture_rpc_scanner loop context");
113                 /* some interfaces are not mappable */
114                 if (l->table->num_calls == 0 ||
115                     strcmp(l->table->name, "mgmt") == 0) {
116                         talloc_free(loop_ctx);
117                         continue;
118                 }
119
120                 printf("\nTesting pipe '%s'\n", l->table->name);
121
122                 if (b->transport == NCACN_IP_TCP) {
123                         status = dcerpc_epm_map_binding(torture, b, l->table, NULL);
124                         if (!NT_STATUS_IS_OK(status)) {
125                                 printf("Failed to map port for uuid %s\n", 
126                                            GUID_string(loop_ctx, &l->table->syntax_id.uuid));
127                                 talloc_free(loop_ctx);
128                                 continue;
129                         }
130                 } else {
131                         b->endpoint = talloc_strdup(b, l->table->name);
132                 }
133
134                 lp_set_cmdline("torture:binding", dcerpc_binding_string(torture, b));
135
136                 status = torture_rpc_connection(torture, &p, &ndr_table_mgmt);
137                 if (!NT_STATUS_IS_OK(status)) {
138                         talloc_free(loop_ctx);
139                         ret = False;
140                         continue;
141                 }
142         
143                 if (!test_inq_if_ids(torture, p, torture, test_num_calls, l->table)) {
144                         ret = False;
145                 }
146         }
147
148         return ret;
149 }
150