r14497: Fix build with shared libraries
[bbaumbach/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 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 "torture/rpc/rpc.h"
26 #include "torture/torture.h"
27 #include "librpc/rpc/dcerpc_table.h"
28
29 /* open a rpc connection to the chosen binding string */
30 NTSTATUS torture_rpc_connection(TALLOC_CTX *parent_ctx, 
31                                 struct dcerpc_pipe **p, 
32                                 const struct dcerpc_interface_table *table)
33 {
34         NTSTATUS status;
35         const char *binding = lp_parm_string(-1, "torture", "binding");
36
37         if (!binding) {
38                 printf("You must specify a ncacn binding string\n");
39                 return NT_STATUS_INVALID_PARAMETER;
40         }
41
42         status = dcerpc_pipe_connect(parent_ctx, 
43                                      p, binding, table,
44                                      cmdline_credentials, NULL);
45  
46         return status;
47 }
48
49 /* open a rpc connection to a specific transport */
50 NTSTATUS torture_rpc_connection_transport(TALLOC_CTX *parent_ctx, 
51                                           struct dcerpc_pipe **p, 
52                                           const struct dcerpc_interface_table *table,
53                                           enum dcerpc_transport_t transport)
54 {
55         NTSTATUS status;
56         const char *binding = lp_parm_string(-1, "torture", "binding");
57         struct dcerpc_binding *b;
58         TALLOC_CTX *mem_ctx = talloc_named(parent_ctx, 0, "torture_rpc_connection_smb");
59
60         if (!binding) {
61                 printf("You must specify a ncacn binding string\n");
62                 talloc_free(mem_ctx);
63                 return NT_STATUS_INVALID_PARAMETER;
64         }
65
66         status = dcerpc_parse_binding(mem_ctx, binding, &b);
67         if (!NT_STATUS_IS_OK(status)) {
68                 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
69                 talloc_free(mem_ctx);
70                 return status;
71         }
72
73         b->transport = transport;
74
75         status = dcerpc_pipe_connect_b(mem_ctx, p, b, table,
76                                        cmdline_credentials, NULL);
77                                            
78         if (NT_STATUS_IS_OK(status)) {
79                 *p = talloc_reference(parent_ctx, *p);
80         } else {
81                 *p = NULL;
82         }
83         talloc_free(mem_ctx);
84         return status;
85 }
86
87 NTSTATUS torture_rpc_init(void)
88 {
89         dcerpc_init();
90
91         dcerpc_table_init();
92
93     register_torture_op("RPC-LSA", torture_rpc_lsa, 0);
94     register_torture_op("RPC-LSALOOKUP", torture_rpc_lsa_lookup, 0);
95     register_torture_op("RPC-SECRETS", torture_rpc_lsa_secrets, 0);
96     register_torture_op("RPC-ECHO", torture_rpc_echo, 0);
97     register_torture_op("RPC-DFS", torture_rpc_dfs, 0);
98     register_torture_op("RPC-SPOOLSS", torture_rpc_spoolss, 0);
99     register_torture_op("RPC-SAMR", torture_rpc_samr, 0);
100     register_torture_op("RPC-UNIXINFO", torture_rpc_unixinfo, 0);
101     register_torture_op("RPC-NETLOGON", torture_rpc_netlogon, 0);
102     register_torture_op("RPC-SAMLOGON", torture_rpc_samlogon, 0);
103     register_torture_op("RPC-SAMSYNC", torture_rpc_samsync, 0);
104     register_torture_op("RPC-SCHANNEL", torture_rpc_schannel, 0);
105     register_torture_op("RPC-WKSSVC", torture_rpc_wkssvc, 0);
106     register_torture_op("RPC-SRVSVC", torture_rpc_srvsvc, 0);
107     register_torture_op("RPC-SVCCTL", torture_rpc_svcctl, 0);
108     register_torture_op("RPC-ATSVC", torture_rpc_atsvc, 0);
109     register_torture_op("RPC-EVENTLOG", torture_rpc_eventlog, 0);
110     register_torture_op("RPC-EPMAPPER", torture_rpc_epmapper, 0);
111     register_torture_op("RPC-WINREG", torture_rpc_winreg, 0);
112     register_torture_op("RPC-INITSHUTDOWN", torture_rpc_initshutdown, 0);
113     register_torture_op("RPC-OXIDRESOLVE", torture_rpc_oxidresolve, 0);
114     register_torture_op("RPC-REMACT", torture_rpc_remact, 0);
115     register_torture_op("RPC-MGMT", torture_rpc_mgmt, 0);
116     register_torture_op("RPC-SCANNER", torture_rpc_scanner, 0);
117     register_torture_op("RPC-AUTOIDL", torture_rpc_autoidl, 0);
118     register_torture_op("RPC-COUNTCALLS", torture_rpc_countcalls, 0);
119         register_torture_op("RPC-MULTIBIND", torture_multi_bind, 0);
120         register_torture_op("RPC-DRSUAPI", torture_rpc_drsuapi, 0);
121         register_torture_op("RPC-CRACKNAMES", torture_rpc_drsuapi_cracknames, 0);
122         register_torture_op("RPC-ROT", torture_rpc_rot, 0);
123         register_torture_op("RPC-DSSETUP", torture_rpc_dssetup, 0);
124     register_torture_op("RPC-ALTERCONTEXT", torture_rpc_alter_context, 0);
125     register_torture_op("RPC-JOIN", torture_rpc_join, 0);
126     register_torture_op("RPC-DSSYNC", torture_rpc_dssync, 0);
127         register_torture_op("BENCH-RPC", torture_bench_rpc, 0);
128
129         return NT_STATUS_OK;
130 }