2 Unix SMB/CIFS implementation.
3 test suite for winreg rpc operations
5 Copyright (C) Tim Potter 2003
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.
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.
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.
24 static void init_winreg_String(struct winreg_String *name, const char *s)
27 name->name_len = 2*strlen_m(s);
28 name->name_size = name->name_len;
31 static BOOL test_GetVersion(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
32 struct policy_handle *handle)
35 struct winreg_GetVersion r;
37 printf("\ntesting GetVersion\n");
41 status = dcerpc_winreg_GetVersion(p, mem_ctx, &r);
43 if (!NT_STATUS_IS_OK(status)) {
44 printf("GetVersion failed - %s\n", nt_errstr(status));
51 static BOOL test_CloseKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
52 struct policy_handle *handle)
55 struct winreg_CloseKey r;
57 printf("\ntesting CloseKey\n");
59 r.in.handle = r.out.handle = handle;
61 status = dcerpc_winreg_CloseKey(p, mem_ctx, &r);
63 if (!NT_STATUS_IS_OK(status)) {
64 printf("CloseKey failed - %s\n", nt_errstr(status));
71 static BOOL test_FlushKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
72 struct policy_handle *handle)
75 struct winreg_FlushKey r;
77 printf("\ntesting FlushKey\n");
81 status = dcerpc_winreg_FlushKey(p, mem_ctx, &r);
83 if (!NT_STATUS_IS_OK(status)) {
84 printf("FlushKey failed - %s\n", nt_errstr(status));
91 static BOOL test_OpenKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
92 struct policy_handle *hive_handle,
93 char *keyname, struct policy_handle *key_handle)
96 struct winreg_OpenKey r;
98 printf("\ntesting OpenKey\n");
100 r.in.handle = hive_handle;
101 init_winreg_String(&r.in.keyname, keyname);
102 r.in.unknown = 0x00000000;
103 r.in.access_mask = 0x02000000;
104 r.out.handle = key_handle;
106 status = dcerpc_winreg_OpenKey(p, mem_ctx, &r);
108 if (!W_ERROR_IS_OK(r.out.result)) {
109 printf("OpenKey failed - %s\n", win_errstr(r.out.result));
116 static BOOL test_DeleteKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
117 struct policy_handle *handle, char *key)
120 struct winreg_DeleteKey r;
122 printf("\ntesting DeleteKey\n");
124 r.in.handle = handle;
125 init_winreg_String(&r.in.key, key);
127 status = dcerpc_winreg_DeleteKey(p, mem_ctx, &r);
129 if (!NT_STATUS_IS_OK(status)) {
130 printf("DeleteKey failed - %s\n", nt_errstr(status));
137 static BOOL test_QueryInfoKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
138 struct policy_handle *handle, char *class)
141 struct winreg_QueryInfoKey r;
143 printf("\ntesting QueryInfoKey\n");
145 r.in.handle = handle;
146 init_winreg_String(&r.in.class, class);
148 status = dcerpc_winreg_QueryInfoKey(p, mem_ctx, &r);
150 if (!W_ERROR_IS_OK(r.out.result)) {
151 printf("QueryInfoKey failed - %s\n", win_errstr(r.out.result));
158 static BOOL test_EnumKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
159 struct policy_handle *handle)
162 struct winreg_EnumKey r;
163 struct winreg_EnumKeyNameRequest keyname;
164 struct winreg_String classname;
165 struct winreg_Time tm;
167 printf("\ntesting EnumKey\n");
169 r.in.handle = handle;
171 r.in.key_name_len = r.out.key_name_len = 0;
172 r.in.unknown = r.out.unknown = 0x0414;
173 keyname.unknown = 0x0000020a;
174 init_winreg_String(&keyname.key_name, NULL);
175 init_winreg_String(&classname, NULL);
176 r.in.name = &keyname;
177 r.in.class = &classname;
178 tm.low = tm.high = 0x7fffffff;
179 r.in.last_changed_time = &tm;
182 status = dcerpc_winreg_EnumKey(p, mem_ctx, &r);
184 } while (W_ERROR_IS_OK(r.out.result));
189 static BOOL test_EnumValue(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
190 struct policy_handle *handle)
193 struct winreg_QueryInfoKey qik;
194 struct winreg_EnumValue r;
195 struct winreg_String name;
197 uint32 value1, value2;
200 printf("\ntesting EnumValue\n");
202 qik.in.handle = handle;
203 init_winreg_String(&qik.in.class, NULL);
205 status = dcerpc_winreg_QueryInfoKey(p, mem_ctx, &qik);
207 if (!W_ERROR_IS_OK(r.out.result)) {
208 printf("QueryInfoKey failed - %s\n", win_errstr(r.out.result));
212 r.in.handle = handle;
214 init_winreg_String(&name, "");
217 r.in.type = r.out.type = &type;
221 r.in.value1 = &value1;
222 r.in.value2 = &value2;
225 status = dcerpc_winreg_EnumValue(p, mem_ctx, &r);
227 } while (W_ERROR_IS_OK(r.out.result));
232 static BOOL test_OpenHKLM(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
233 struct policy_handle *handle)
236 struct winreg_OpenHKLM r;
237 struct winreg_OpenUnknown unknown;
240 printf("\ntesting OpenHKLM\n");
242 unknown.unknown0 = 0x84e0;
243 unknown.unknown1 = 0x0000;
244 r.in.unknown = &unknown;
245 r.in.access_required = SEC_RIGHTS_MAXIMUM_ALLOWED;
246 r.out.handle = handle;
248 status = dcerpc_winreg_OpenHKLM(p, mem_ctx, &r);
250 if (!NT_STATUS_IS_OK(status)) {
251 printf("OpenHKLM failed - %s\n", nt_errstr(status));
258 static BOOL test_OpenHKU(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
259 struct policy_handle *handle)
262 struct winreg_OpenHKU r;
263 struct winreg_OpenUnknown unknown;
266 printf("\ntesting OpenHKU\n");
268 unknown.unknown0 = 0x84e0;
269 unknown.unknown1 = 0x0000;
270 r.in.unknown = &unknown;
271 r.in.access_required = SEC_RIGHTS_MAXIMUM_ALLOWED;
272 r.out.handle = handle;
274 status = dcerpc_winreg_OpenHKU(p, mem_ctx, &r);
276 if (!NT_STATUS_IS_OK(status)) {
277 printf("OpenHKU failed - %s\n", nt_errstr(status));
284 static BOOL test_OpenHKCR(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
285 struct policy_handle *handle)
288 struct winreg_OpenHKCR r;
289 struct winreg_OpenUnknown unknown;
292 printf("\ntesting OpenHKCR\n");
294 unknown.unknown0 = 0x84e0;
295 unknown.unknown1 = 0x0000;
296 r.in.unknown = &unknown;
297 r.in.access_required = SEC_RIGHTS_MAXIMUM_ALLOWED;
298 r.out.handle = handle;
300 status = dcerpc_winreg_OpenHKCR(p, mem_ctx, &r);
302 if (!NT_STATUS_IS_OK(status)) {
303 printf("OpenHKCR failed - %s\n", nt_errstr(status));
310 static BOOL test_OpenHKCU(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
311 struct policy_handle *handle)
314 struct winreg_OpenHKCU r;
315 struct winreg_OpenUnknown unknown;
318 printf("\ntesting OpenHKCU\n");
320 unknown.unknown0 = 0x84e0;
321 unknown.unknown1 = 0x0000;
322 r.in.unknown = &unknown;
323 r.in.access_required = SEC_RIGHTS_MAXIMUM_ALLOWED;
324 r.out.handle = handle;
326 status = dcerpc_winreg_OpenHKCU(p, mem_ctx, &r);
328 if (!NT_STATUS_IS_OK(status)) {
329 printf("OpenHKCU failed - %s\n", nt_errstr(status));
336 typedef BOOL (*winreg_open_fn)(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
337 struct policy_handle *handle);
339 BOOL torture_rpc_winreg(int dummy)
342 struct dcerpc_pipe *p;
345 winreg_open_fn open_fns[] = { test_OpenHKLM };
348 mem_ctx = talloc_init("torture_rpc_winreg");
350 status = torture_rpc_connection(&p,
353 DCERPC_WINREG_VERSION);
354 if (!NT_STATUS_IS_OK(status)) {
358 p->flags |= DCERPC_DEBUG_PRINT_BOTH;
360 for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
361 struct policy_handle handle;
363 if (!open_fns[i](p, mem_ctx, &handle))
367 if (!test_GetVersion(p, mem_ctx, &handle)) {
371 if (!test_DeleteKey(p, mem_ctx, &handle, "spottyfoot")) {
375 if (!test_EnumKey(p, mem_ctx, &handle)) {
379 if (!test_EnumValue(p, mem_ctx, &handle)) {
383 if (!test_CloseKey(p, mem_ctx, &handle)) {
388 talloc_destroy(mem_ctx);
390 torture_rpc_close(p);