r24667: Finally merge the registry improvements that Wilco Baan Hofman and I have
[sfrench/samba-autobuild/.git] / source4 / torture / rpc / rpc.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB torture tester
4    Copyright (C) Andrew Tridgell 1997-2003
5    Copyright (C) Jelmer Vernooij 2006
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "auth/credentials/credentials.h"
23 #include "lib/cmdline/popt_common.h"
24 #include "librpc/rpc/dcerpc.h"
25 #include "torture/rpc/rpc.h"
26 #include "torture/torture.h"
27 #include "librpc/ndr/ndr_table.h"
28 #include "lib/util/dlinklist.h"
29
30 /* open a rpc connection to the chosen binding string */
31 _PUBLIC_ NTSTATUS torture_rpc_connection(TALLOC_CTX *parent_ctx, 
32                                 struct dcerpc_pipe **p, 
33                                 const struct ndr_interface_table *table)
34 {
35         NTSTATUS status;
36         const char *binding = lp_parm_string(-1, "torture", "binding");
37
38         if (!binding) {
39                 printf("You must specify a ncacn binding string\n");
40                 return NT_STATUS_INVALID_PARAMETER;
41         }
42
43         status = dcerpc_pipe_connect(parent_ctx, 
44                                      p, binding, table,
45                                      cmdline_credentials, NULL);
46  
47         if (!NT_STATUS_IS_OK(status)) {
48                 printf("Failed to connect to remote server: %s %s\n", binding, nt_errstr(status));
49         }
50
51         return status;
52 }
53
54 /* open a rpc connection to a specific transport */
55 NTSTATUS torture_rpc_connection_transport(TALLOC_CTX *parent_ctx, 
56                                           struct dcerpc_pipe **p, 
57                                           const struct ndr_interface_table *table,
58                                           enum dcerpc_transport_t transport,
59                                           uint32_t assoc_group_id)
60 {
61         NTSTATUS status;
62         const char *binding = lp_parm_string(-1, "torture", "binding");
63         struct dcerpc_binding *b;
64         TALLOC_CTX *mem_ctx = talloc_named(parent_ctx, 0, "torture_rpc_connection_smb");
65
66         if (!binding) {
67                 printf("You must specify a ncacn binding string\n");
68                 talloc_free(mem_ctx);
69                 return NT_STATUS_INVALID_PARAMETER;
70         }
71
72         status = dcerpc_parse_binding(mem_ctx, binding, &b);
73         if (!NT_STATUS_IS_OK(status)) {
74                 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
75                 talloc_free(mem_ctx);
76                 return status;
77         }
78
79         b->transport = transport;
80         b->assoc_group_id = assoc_group_id;
81
82         status = dcerpc_pipe_connect_b(mem_ctx, p, b, table,
83                                        cmdline_credentials, NULL);
84                                            
85         if (NT_STATUS_IS_OK(status)) {
86                 *p = talloc_reference(parent_ctx, *p);
87         } else {
88                 *p = NULL;
89         }
90         talloc_free(mem_ctx);
91         return status;
92 }
93
94 static bool torture_rpc_setup (struct torture_context *tctx, void **data)
95 {
96         NTSTATUS status;
97         
98         status = torture_rpc_connection(tctx, 
99                                 (struct dcerpc_pipe **)data, 
100                                 (const struct ndr_interface_table *)tctx->active_tcase->data);
101
102         torture_assert_ntstatus_ok(tctx, status, "Error connecting to server");
103
104         return true;
105 }
106
107 static bool torture_rpc_teardown (struct torture_context *tcase, void *data)
108 {
109         talloc_free(data);
110         return true;
111 }
112
113 _PUBLIC_ struct torture_tcase *torture_suite_add_rpc_iface_tcase(struct torture_suite *suite, 
114                                                                 const char *name,
115                                                                 const struct ndr_interface_table *table)
116 {
117         struct torture_tcase *tcase = torture_suite_add_tcase(suite, name);
118
119         tcase->setup = torture_rpc_setup;
120         tcase->teardown = torture_rpc_teardown;
121         tcase->data = discard_const(table);
122
123         return tcase;
124 }
125
126 static bool torture_rpc_wrap_test(struct torture_context *tctx, 
127                                                                   struct torture_tcase *tcase,
128                                                                   struct torture_test *test)
129 {
130         bool (*fn) (struct torture_context *, struct dcerpc_pipe *);
131
132         fn = test->fn;
133
134         return fn(tctx, (struct dcerpc_pipe *)tcase->data);
135 }
136
137 static bool torture_rpc_wrap_test_ex(struct torture_context *tctx, 
138                                                                   struct torture_tcase *tcase,
139                                                                   struct torture_test *test)
140 {
141         bool (*fn) (struct torture_context *, struct dcerpc_pipe *, const void *);
142
143         fn = test->fn;
144
145         return fn(tctx, (struct dcerpc_pipe *)tcase->data, test->data);
146 }
147
148 _PUBLIC_ struct torture_test *torture_rpc_tcase_add_test(
149                                         struct torture_tcase *tcase, 
150                                         const char *name, 
151                                         bool (*fn) (struct torture_context *, struct dcerpc_pipe *))
152 {
153         struct torture_test *test;
154
155         test = talloc(tcase, struct torture_test);
156
157         test->name = talloc_strdup(test, name);
158         test->description = NULL;
159         test->run = torture_rpc_wrap_test;
160         test->dangerous = false;
161         test->data = NULL;
162         test->fn = fn;
163
164         DLIST_ADD(tcase->tests, test);
165
166         return test;
167 }
168
169 _PUBLIC_ struct torture_test *torture_rpc_tcase_add_test_ex(
170                                         struct torture_tcase *tcase, 
171                                         const char *name, 
172                                         bool (*fn) (struct torture_context *, struct dcerpc_pipe *,
173                                                                 void *),
174                                         void *userdata)
175 {
176         struct torture_test *test;
177
178         test = talloc(tcase, struct torture_test);
179
180         test->name = talloc_strdup(test, name);
181         test->description = NULL;
182         test->run = torture_rpc_wrap_test_ex;
183         test->dangerous = false;
184         test->data = userdata;
185         test->fn = fn;
186
187         DLIST_ADD(tcase->tests, test);
188
189         return test;
190 }
191
192 NTSTATUS torture_rpc_init(void)
193 {
194         struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "RPC");
195
196         dcerpc_init();
197
198         ndr_table_init();
199
200         torture_suite_add_simple_test(suite, "LSA", torture_rpc_lsa);
201         torture_suite_add_simple_test(suite, "LSALOOKUP", torture_rpc_lsa_lookup);
202         torture_suite_add_simple_test(suite, "LSA-GETUSER", torture_rpc_lsa_get_user);
203         torture_suite_add_simple_test(suite, "SECRETS", torture_rpc_lsa_secrets);
204         torture_suite_add_suite(suite, torture_rpc_echo());
205         torture_suite_add_suite(suite, torture_rpc_dfs());
206         torture_suite_add_suite(suite, torture_rpc_unixinfo());
207         torture_suite_add_suite(suite, torture_rpc_eventlog());
208         torture_suite_add_suite(suite, torture_rpc_atsvc());
209         torture_suite_add_suite(suite, torture_rpc_wkssvc());
210         torture_suite_add_suite(suite, torture_rpc_handles(suite));
211         torture_suite_add_suite(suite, torture_rpc_winreg(suite));
212         torture_suite_add_simple_test(suite, "SPOOLSS", torture_rpc_spoolss);
213         torture_suite_add_simple_test(suite, "SAMR", torture_rpc_samr);
214         torture_suite_add_simple_test(suite, "SAMR-USERS", torture_rpc_samr_users);
215         torture_suite_add_simple_test(suite, "SAMR-PASSWORDS", torture_rpc_samr_passwords);
216         torture_suite_add_simple_test(suite, "NETLOGON", torture_rpc_netlogon);
217         torture_suite_add_simple_test(suite, "SAMLOGON", torture_rpc_samlogon);
218         torture_suite_add_simple_test(suite, "SAMSYNC", torture_rpc_samsync);
219         torture_suite_add_simple_test(suite, "SCHANNEL", torture_rpc_schannel);
220         torture_suite_add_simple_test(suite, "SCHANNEL2", torture_rpc_schannel2);
221         torture_suite_add_simple_test(suite, "SRVSVC", torture_rpc_srvsvc);
222         torture_suite_add_simple_test(suite, "SVCCTL", torture_rpc_svcctl);
223         torture_suite_add_simple_test(suite, "EPMAPPER", torture_rpc_epmapper);
224         torture_suite_add_simple_test(suite, "INITSHUTDOWN", torture_rpc_initshutdown);
225         torture_suite_add_simple_test(suite, "OXIDRESOLVE", torture_rpc_oxidresolve);
226         torture_suite_add_simple_test(suite, "REMACT", torture_rpc_remact);
227         torture_suite_add_simple_test(suite, "MGMT", torture_rpc_mgmt);
228         torture_suite_add_simple_test(suite, "SCANNER", torture_rpc_scanner);
229         torture_suite_add_simple_test(suite, "AUTOIDL", torture_rpc_autoidl);
230         torture_suite_add_simple_test(suite, "COUNTCALLS", torture_rpc_countcalls);
231         torture_suite_add_simple_test(suite, "MULTIBIND", torture_multi_bind);
232         torture_suite_add_simple_test(suite, "AUTHCONTEXT", torture_bind_authcontext);
233         torture_suite_add_simple_test(suite, "BINDSAMBA3", torture_bind_samba3);
234         torture_suite_add_simple_test(suite, "NETLOGSAMBA3", torture_netlogon_samba3);
235         torture_suite_add_simple_test(suite, "SAMBA3SESSIONKEY", torture_samba3_sessionkey);
236         torture_suite_add_simple_test(suite, "SAMBA3-SRVSVC", torture_samba3_rpc_srvsvc);
237         torture_suite_add_simple_test(suite, "SAMBA3-SHARESEC",
238                             torture_samba3_rpc_sharesec);
239         torture_suite_add_simple_test(suite, "SAMBA3-GETUSERNAME",
240                             torture_samba3_rpc_getusername);
241         torture_suite_add_simple_test(suite, "SAMBA3-LSA", torture_samba3_rpc_lsa);
242         torture_suite_add_simple_test(suite, "SAMBA3-SPOOLSS", torture_samba3_rpc_spoolss);
243         torture_suite_add_simple_test(suite, "SAMBA3-WKSSVC", torture_samba3_rpc_wkssvc);
244         torture_suite_add_simple_test(suite, "RPC-SAMBA3-WINREG", torture_samba3_rpc_winreg);
245         torture_suite_add_simple_test(suite, "DRSUAPI", torture_rpc_drsuapi);
246         torture_suite_add_simple_test(suite, "CRACKNAMES", torture_rpc_drsuapi_cracknames);
247         torture_suite_add_simple_test(suite, "ROT", torture_rpc_rot);
248         torture_suite_add_simple_test(suite, "DSSETUP", torture_rpc_dssetup);
249         torture_suite_add_simple_test(suite, "ALTERCONTEXT", torture_rpc_alter_context);
250         torture_suite_add_simple_test(suite, "JOIN", torture_rpc_join);
251         torture_suite_add_simple_test(suite, "DSSYNC", torture_rpc_dssync);
252         torture_suite_add_simple_test(suite, "BENCH-RPC", torture_bench_rpc);
253         torture_suite_add_simple_test(suite, "ASYNCBIND", torture_async_bind);
254
255         suite->description = talloc_strdup(suite, "DCE/RPC protocol and interface tests");
256
257         torture_register_suite(suite);
258
259         return NT_STATUS_OK;
260 }