Start of winreg idl. Implement OpenHKLM, GetVersion and CloseKey.
[samba.git] / source4 / torture / rpc / winreg.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for winreg rpc operations
4
5    Copyright (C) Tim Potter 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 static BOOL test_GetVersion(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
25                             struct policy_handle *handle)
26 {
27         NTSTATUS status;
28         struct winreg_GetVersion r;
29
30         printf("\ntesting GetVersion\n");
31
32         r.in.handle = handle;
33
34         status = dcerpc_winreg_GetVersion(p, mem_ctx, &r);
35
36         if (!NT_STATUS_IS_OK(status)) {
37                 printf("GetVersion failed - %s\n", nt_errstr(status));
38                 return False;
39         }
40
41         return True;
42 }
43
44 static BOOL test_CloseKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
45                           struct policy_handle *handle)
46 {
47         NTSTATUS status;
48         struct winreg_CloseKey r;
49
50         printf("\ntesting CloseKey\n");
51
52         r.in.handle = r.out.handle = handle;
53
54         status = dcerpc_winreg_CloseKey(p, mem_ctx, &r);
55
56         if (!NT_STATUS_IS_OK(status)) {
57                 printf("CloseKey failed - %s\n", nt_errstr(status));
58                 return False;
59         }
60
61         return True;
62 }
63
64 static BOOL test_OpenHKLM(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
65 {
66         NTSTATUS status;
67         struct winreg_OpenHKLM r;
68         struct winreg_OpenHKLMUnknown unknown;
69         struct policy_handle handle;
70         BOOL ret = True;
71
72         printf("\ntesting OpenHKLM\n");
73
74         unknown.unknown0 = 0x84e0;
75         unknown.unknown1 = 0x0000;
76         r.in.unknown = &unknown;
77         r.in.access_required = SEC_RIGHTS_MAXIMUM_ALLOWED;
78         r.out.handle = &handle;
79
80         status = dcerpc_winreg_OpenHKLM(p, mem_ctx, &r);
81
82         if (!NT_STATUS_IS_OK(status)) {
83                 printf("OpenHKLM failed - %s\n", nt_errstr(status));
84                 return False;
85         }
86
87         if (!test_GetVersion(p, mem_ctx, &handle)) {
88                 ret = False;
89         }
90
91         if (!test_CloseKey(p, mem_ctx, &handle)) {
92                 ret = False;
93         }
94
95         return ret;
96 }
97
98 BOOL torture_rpc_winreg(int dummy)
99 {
100         NTSTATUS status;
101         struct dcerpc_pipe *p;
102         TALLOC_CTX *mem_ctx;
103         BOOL ret = True;
104
105         mem_ctx = talloc_init("torture_rpc_winreg");
106
107         status = torture_rpc_connection(&p, 
108                                         DCERPC_WINREG_NAME, 
109                                         DCERPC_WINREG_UUID, 
110                                         DCERPC_WINREG_VERSION);
111         if (!NT_STATUS_IS_OK(status)) {
112                 return False;
113         }
114         
115         p->flags |= DCERPC_DEBUG_PRINT_BOTH;
116
117         if (!test_OpenHKLM(p, mem_ctx)) {
118                 ret = False;
119         }
120
121         torture_rpc_close(p);
122
123         return ret;
124 }