added the first couple of calls from samr as IDL
[samba.git] / source / torture / rpc / samr.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for samr rpc operations
4
5    Copyright (C) Andrew Tridgell 2003
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
24
25 static BOOL test_EnumDomains(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
26                              struct policy_handle *handle)
27 {
28         NTSTATUS status;
29         struct samr_EnumDomains r;
30         uint32 resume_handle = 0;
31         uint32 num_entries;
32
33         r.in.handle = handle;
34         r.in.resume_handle = &resume_handle;
35         r.in.buf_size = (uint32)-1;
36         r.out.resume_handle = &resume_handle;
37         r.out.num_entries = &num_entries;
38
39         status = dcerpc_samr_EnumDomains(p, mem_ctx, &r);
40         if (!NT_STATUS_IS_OK(status)) {
41                 printf("EnumDomains failed - %s\n", nt_errstr(status));
42                 return False;
43         }
44
45         NDR_PRINT_DEBUG(samr_SamArray, r.out.sam);
46
47         return True;
48 }
49
50
51 static BOOL test_Connect(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
52                          struct policy_handle *handle)
53 {
54         NTSTATUS status;
55         struct samr_Connect r;
56
57         r.in.system_name = 0;
58         r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
59         r.out.handle = handle;
60
61         status = dcerpc_samr_Connect(p, mem_ctx, &r);
62         if (!NT_STATUS_IS_OK(status)) {
63                 printf("Connect failed - %s\n", nt_errstr(status));
64                 return False;
65         }
66
67         return True;
68 }
69
70
71 BOOL torture_rpc_samr(int dummy)
72 {
73         NTSTATUS status;
74         struct dcerpc_pipe *p;
75         TALLOC_CTX *mem_ctx;
76         BOOL ret = True;
77         struct policy_handle handle;
78
79         mem_ctx = talloc_init("torture_rpc_samr");
80
81         status = torture_rpc_connection(&p, "samr");
82         if (!NT_STATUS_IS_OK(status)) {
83                 return False;
84         }
85         
86         if (!test_Connect(p, mem_ctx, &handle)) {
87                 ret = False;
88         }
89
90         if (!test_EnumDomains(p, mem_ctx, &handle)) {
91                 ret = False;
92         }
93
94         torture_rpc_close(p);
95
96         return ret;
97 }