r23090: a test showing two netlogon pipes open at once, using the LogonEx ops
[kai/samba.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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "auth/credentials/credentials.h"
24 #include "lib/cmdline/popt_common.h"
25 #include "librpc/rpc/dcerpc.h"
26 #include "torture/rpc/rpc.h"
27 #include "torture/torture.h"
28 #include "librpc/rpc/dcerpc_table.h"
29 #include "lib/util/dlinklist.h"
30
31 /* open a rpc connection to the chosen binding string */
32 _PUBLIC_ NTSTATUS torture_rpc_connection(TALLOC_CTX *parent_ctx, 
33                                 struct dcerpc_pipe **p, 
34                                 const struct dcerpc_interface_table *table)
35 {
36         NTSTATUS status;
37         const char *binding = lp_parm_string(-1, "torture", "binding");
38
39         if (!binding) {
40                 printf("You must specify a ncacn binding string\n");
41                 return NT_STATUS_INVALID_PARAMETER;
42         }
43
44         status = dcerpc_pipe_connect(parent_ctx, 
45                                      p, binding, table,
46                                      cmdline_credentials, NULL);
47  
48         if (!NT_STATUS_IS_OK(status)) {
49                 printf("Failed to connect to remote server: %s %s\n", binding, nt_errstr(status));
50         }
51
52         return status;
53 }
54
55 /* open a rpc connection to a specific transport */
56 NTSTATUS torture_rpc_connection_transport(TALLOC_CTX *parent_ctx, 
57                                           struct dcerpc_pipe **p, 
58                                           const struct dcerpc_interface_table *table,
59                                           enum dcerpc_transport_t transport,
60                                           uint32_t assoc_group_id)
61 {
62         NTSTATUS status;
63         const char *binding = lp_parm_string(-1, "torture", "binding");
64         struct dcerpc_binding *b;
65         TALLOC_CTX *mem_ctx = talloc_named(parent_ctx, 0, "torture_rpc_connection_smb");
66
67         if (!binding) {
68                 printf("You must specify a ncacn binding string\n");
69                 talloc_free(mem_ctx);
70                 return NT_STATUS_INVALID_PARAMETER;
71         }
72
73         status = dcerpc_parse_binding(mem_ctx, binding, &b);
74         if (!NT_STATUS_IS_OK(status)) {
75                 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
76                 talloc_free(mem_ctx);
77                 return status;
78         }
79
80         b->transport = transport;
81         b->assoc_group_id = assoc_group_id;
82
83         status = dcerpc_pipe_connect_b(mem_ctx, p, b, table,
84                                        cmdline_credentials, NULL);
85                                            
86         if (NT_STATUS_IS_OK(status)) {
87                 *p = talloc_reference(parent_ctx, *p);
88         } else {
89                 *p = NULL;
90         }
91         talloc_free(mem_ctx);
92         return status;
93 }
94
95 static bool torture_rpc_setup (struct torture_context *tctx, void **data)
96 {
97         NTSTATUS status;
98         
99         status = torture_rpc_connection(tctx, 
100                                 (struct dcerpc_pipe **)data, 
101                                 (const struct dcerpc_interface_table *)tctx->active_tcase->data);
102
103         torture_assert_ntstatus_ok(tctx, status, "Error connecting to server");
104
105         return true;
106 }
107
108 static bool torture_rpc_teardown (struct torture_context *tcase, void *data)
109 {
110         talloc_free(data);
111         return true;
112 }
113
114 _PUBLIC_ struct torture_tcase *torture_suite_add_rpc_iface_tcase(struct torture_suite *suite, 
115                                                                 const char *name,
116                                                                 const struct dcerpc_interface_table *table)
117 {
118         struct torture_tcase *tcase = torture_suite_add_tcase(suite, name);
119
120         tcase->setup = torture_rpc_setup;
121         tcase->teardown = torture_rpc_teardown;
122         tcase->data = discard_const(table);
123
124         return tcase;
125 }
126
127 static bool torture_rpc_wrap_test(struct torture_context *tctx, 
128                                                                   struct torture_tcase *tcase,
129                                                                   struct torture_test *test)
130 {
131         bool (*fn) (struct torture_context *, struct dcerpc_pipe *);
132
133         fn = test->fn;
134
135         return fn(tctx, (struct dcerpc_pipe *)tcase->data);
136 }
137
138 _PUBLIC_ struct torture_test *torture_rpc_tcase_add_test(
139                                         struct torture_tcase *tcase, 
140                                         const char *name, 
141                                         bool (*fn) (struct torture_context *, struct dcerpc_pipe *))
142 {
143         struct torture_test *test;
144
145         test = talloc(tcase, struct torture_test);
146
147         test->name = talloc_strdup(test, name);
148         test->description = NULL;
149         test->run = torture_rpc_wrap_test;
150         test->dangerous = false;
151         test->data = NULL;
152         test->fn = fn;
153
154         DLIST_ADD(tcase->tests, test);
155
156         return test;
157 }
158
159 NTSTATUS torture_rpc_init(void)
160 {
161         struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "RPC");
162
163         dcerpc_init();
164
165         dcerpc_table_init();
166
167         torture_suite_add_simple_test(suite, "LSA", torture_rpc_lsa);
168         torture_suite_add_simple_test(suite, "LSALOOKUP", torture_rpc_lsa_lookup);
169         torture_suite_add_simple_test(suite, "LSA-GETUSER", torture_rpc_lsa_get_user);
170         torture_suite_add_simple_test(suite, "SECRETS", torture_rpc_lsa_secrets);
171         torture_suite_add_suite(suite, torture_rpc_echo());
172         torture_suite_add_suite(suite, torture_rpc_dfs());
173         torture_suite_add_suite(suite, torture_rpc_unixinfo());
174         torture_suite_add_suite(suite, torture_rpc_eventlog());
175         torture_suite_add_suite(suite, torture_rpc_atsvc());
176         torture_suite_add_suite(suite, torture_rpc_wkssvc());
177         torture_suite_add_suite(suite, torture_rpc_handles());
178         torture_suite_add_simple_test(suite, "SPOOLSS", torture_rpc_spoolss);
179         torture_suite_add_simple_test(suite, "SAMR", torture_rpc_samr);
180         torture_suite_add_simple_test(suite, "SAMR-USERS", torture_rpc_samr_users);
181         torture_suite_add_simple_test(suite, "SAMR-PASSWORDS", torture_rpc_samr_passwords);
182         torture_suite_add_simple_test(suite, "NETLOGON", torture_rpc_netlogon);
183         torture_suite_add_simple_test(suite, "SAMLOGON", torture_rpc_samlogon);
184         torture_suite_add_simple_test(suite, "SAMSYNC", torture_rpc_samsync);
185         torture_suite_add_simple_test(suite, "SCHANNEL", torture_rpc_schannel);
186         torture_suite_add_simple_test(suite, "SCHANNEL2", torture_rpc_schannel2);
187         torture_suite_add_simple_test(suite, "SRVSVC", torture_rpc_srvsvc);
188         torture_suite_add_simple_test(suite, "SVCCTL", torture_rpc_svcctl);
189         torture_suite_add_simple_test(suite, "EPMAPPER", torture_rpc_epmapper);
190         torture_suite_add_simple_test(suite, "WINREG", torture_rpc_winreg);
191         torture_suite_add_simple_test(suite, "INITSHUTDOWN", torture_rpc_initshutdown);
192         torture_suite_add_simple_test(suite, "OXIDRESOLVE", torture_rpc_oxidresolve);
193         torture_suite_add_simple_test(suite, "REMACT", torture_rpc_remact);
194         torture_suite_add_simple_test(suite, "MGMT", torture_rpc_mgmt);
195         torture_suite_add_simple_test(suite, "SCANNER", torture_rpc_scanner);
196         torture_suite_add_simple_test(suite, "AUTOIDL", torture_rpc_autoidl);
197         torture_suite_add_simple_test(suite, "COUNTCALLS", torture_rpc_countcalls);
198         torture_suite_add_simple_test(suite, "MULTIBIND", torture_multi_bind);
199         torture_suite_add_simple_test(suite, "AUTHCONTEXT", torture_bind_authcontext);
200         torture_suite_add_simple_test(suite, "BINDSAMBA3", torture_bind_samba3);
201         torture_suite_add_simple_test(suite, "NETLOGSAMBA3", torture_netlogon_samba3);
202         torture_suite_add_simple_test(suite, "SAMBA3SESSIONKEY", torture_samba3_sessionkey);
203         torture_suite_add_simple_test(suite, "SAMBA3-SRVSVC", torture_samba3_rpc_srvsvc);
204         torture_suite_add_simple_test(suite, "SAMBA3-SHARESEC",
205                             torture_samba3_rpc_sharesec);
206         torture_suite_add_simple_test(suite, "SAMBA3-GETUSERNAME",
207                             torture_samba3_rpc_getusername);
208         torture_suite_add_simple_test(suite, "SAMBA3-LSA", torture_samba3_rpc_lsa);
209         torture_suite_add_simple_test(suite, "SAMBA3-SPOOLSS", torture_samba3_rpc_spoolss);
210         torture_suite_add_simple_test(suite, "SAMBA3-WKSSVC", torture_samba3_rpc_wkssvc);
211         torture_suite_add_simple_test(suite, "RPC-SAMBA3-WINREG", torture_samba3_rpc_winreg);
212         torture_suite_add_simple_test(suite, "DRSUAPI", torture_rpc_drsuapi);
213         torture_suite_add_simple_test(suite, "CRACKNAMES", torture_rpc_drsuapi_cracknames);
214         torture_suite_add_simple_test(suite, "ROT", torture_rpc_rot);
215         torture_suite_add_simple_test(suite, "DSSETUP", torture_rpc_dssetup);
216         torture_suite_add_simple_test(suite, "ALTERCONTEXT", torture_rpc_alter_context);
217         torture_suite_add_simple_test(suite, "JOIN", torture_rpc_join);
218         torture_suite_add_simple_test(suite, "DSSYNC", torture_rpc_dssync);
219         torture_suite_add_simple_test(suite, "BENCH-RPC", torture_bench_rpc);
220         torture_suite_add_simple_test(suite, "ASYNCBIND", torture_async_bind);
221
222         suite->description = talloc_strdup(suite, "DCE/RPC protocol and interface tests");
223
224         torture_register_suite(suite);
225
226         return NT_STATUS_OK;
227 }