r19392: Use torture_setting_* rather than lp_parm_* where possible.
[gd/samba-autobuild/.git] / source4 / torture / rpc / async_bind.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    dcerpc torture tests
5
6    Copyright (C) Andrew Tridgell 2003
7    Copyright (C) Rafal Szczesniak 2006
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25 #include "torture/torture.h"
26 #include "lib/events/events.h"
27 #include "libcli/composite/composite.h"
28 #include "librpc/gen_ndr/ndr_lsa.h"
29 #include "lib/cmdline/popt_common.h"
30 #include "librpc/rpc/dcerpc.h"
31 #include "torture/rpc/rpc.h"
32
33 /*
34   This test initiates multiple rpc bind requests and verifies
35   whether all of them are served.
36 */
37
38
39 BOOL torture_async_bind(struct torture_context *torture)
40 {
41         NTSTATUS status;
42         TALLOC_CTX *mem_ctx;
43         struct event_context *evt_ctx;
44         int i;
45         const char *binding_string;
46         struct cli_credentials *creds;
47         extern int torture_numasync;
48
49         struct composite_context **bind_req;
50         struct dcerpc_pipe **pipe;
51         const struct dcerpc_interface_table **table;
52
53         if (!torture_setting_bool(torture, "async", False)) {
54                 printf("async bind test disabled - enable async tests to use\n");
55                 return True;
56         }
57         
58         binding_string = torture_setting_string(torture, "binding", NULL);
59
60         /* talloc context */
61         mem_ctx = talloc_init("torture_async_bind");
62         if (mem_ctx == NULL) return False;
63
64         bind_req = talloc_array(torture, struct composite_context*, torture_numasync);
65         if (bind_req == NULL) return False;
66         pipe     = talloc_array(torture, struct dcerpc_pipe*, torture_numasync);
67         if (pipe == NULL) return False;
68         table    = talloc_array(torture, const struct dcerpc_interface_table*, torture_numasync);
69         if (table == NULL) return False;
70         
71         /* event context */
72         evt_ctx = event_context_init(mem_ctx);
73         if (evt_ctx == NULL) return False;
74
75         /* credentials */
76         creds = cmdline_credentials;
77
78         /* send bind requests */
79         for (i = 0; i < torture_numasync; i++) {
80                 table[i] = &dcerpc_table_lsarpc;
81                 bind_req[i] = dcerpc_pipe_connect_send(mem_ctx, binding_string,
82                                                        table[i], creds, evt_ctx);
83         }
84
85         /* recv bind requests */
86         for (i = 0; i < torture_numasync; i++) {
87                 status = dcerpc_pipe_connect_recv(bind_req[i], mem_ctx, &pipe[i]);
88                 if (!NT_STATUS_IS_OK(status)) {
89                         printf("async rpc connection failed: %s\n", nt_errstr(status));
90                         return False;
91                 }
92         }
93
94         talloc_free(mem_ctx);
95         return True;
96 }