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