7edbd5742d1aeb0a6795bc3ba09edf608e7d6313
[abartlet/samba.git/.git] / source4 / torture / libnet / domain.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Test suite for libnet calls.
4
5    Copyright (C) Rafal Szczesniak 2005
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 "librpc/gen_ndr/ndr_samr.h"
24 #include "libnet/composite.h"
25 #include "libcli/composite/monitor.h"
26
27 static BOOL test_domainopen(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
28                             struct lsa_String *domname,
29                             struct policy_handle *domain_handle)
30 {
31         NTSTATUS status;
32         struct libnet_rpc_domain_open io;
33         
34         printf("opening domain\n");
35         
36         io.in.domain_name  = talloc_strdup(mem_ctx, domname->string);
37         io.in.access_mask  = SEC_FLAG_MAXIMUM_ALLOWED;
38
39         status = libnet_rpc_domain_open(p, mem_ctx, &io);
40         if (!NT_STATUS_IS_OK(status)) {
41                 printf("Composite domain open failed - %s\n", nt_errstr(status));
42                 return False;
43         }
44
45         *domain_handle = io.out.domain_handle;
46         return True;
47 }
48
49
50 static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
51                          struct policy_handle *domain_handle)
52 {
53         NTSTATUS status;
54         struct samr_Close r;
55         struct policy_handle handle;
56
57         r.in.handle   = domain_handle;
58         r.out.handle  = &handle;
59         
60         printf("closing domain handle\n");
61         
62         status = dcerpc_samr_Close(p, mem_ctx, &r);
63         if (!NT_STATUS_IS_OK(status)) {
64                 printf("Close failed - %s\n", nt_errstr(status));
65                 return False;
66         }
67         
68         return True;
69 }
70
71
72 BOOL torture_domainopen(void)
73 {
74         NTSTATUS status;
75         const char *binding;
76         struct dcerpc_pipe *p;
77         TALLOC_CTX *mem_ctx;
78         BOOL ret = True;
79         struct policy_handle h;
80         struct lsa_String name;
81
82         mem_ctx = talloc_init("test_domain_open");
83         binding = lp_parm_string(-1, "torture", "binding");
84
85         status = torture_rpc_connection(mem_ctx, 
86                                         &p,
87                                         DCERPC_SAMR_NAME,
88                                         DCERPC_SAMR_UUID,
89                                         DCERPC_SAMR_VERSION);
90         
91         if (!NT_STATUS_IS_OK(status)) {
92                 return False;
93         }
94
95         name.string = lp_workgroup();
96
97         /*
98          * Testing synchronous version
99          */
100         if (!test_domainopen(p, mem_ctx, &name, &h)) {
101                 ret = False;
102                 goto done;
103         }
104
105         if (!test_cleanup(p, mem_ctx, &h)) {
106                 ret = False;
107                 goto done;
108         }
109
110 done:
111         talloc_free(mem_ctx);
112
113         return ret;
114 }