summaryrefslogtreecommitdiff
path: root/source4/torture/ndr/winreg.c
blob: 8b47a08aac0db5e630aaa992dd0713882b36ac97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/* 
   Unix SMB/CIFS implementation.
   test suite for winreg ndr operations

   Copyright (C) Jelmer Vernooij 2007
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "includes.h"
#include "torture/ndr/ndr.h"
#include "librpc/gen_ndr/ndr_winreg.h"
#include "librpc/gen_ndr/ndr_security.h"
#include "libcli/security/security.h"

static const uint8_t closekey_in_data[] = { 
        0x00, 0x00, 0x00, 0x00, 0x1d, 0xd8, 0xd7, 0xaa, 0x8d, 0x6c, 0x3f, 0x48, 
        0xa7, 0x1e, 0x02, 0x6a, 0x47, 0xf6, 0x7b, 0xae
};

static bool closekey_in_check(struct torture_context *tctx, 
								  struct winreg_CloseKey *ck)
{
	torture_assert(tctx, ck->in.handle != NULL, "handle invalid");
	torture_assert_int_equal(tctx, ck->in.handle->handle_type, 0, "handle type");
	return true;
}

const static uint8_t closekey_out_data[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static bool closekey_out_check(struct torture_context *tctx, 
							   struct winreg_CloseKey *ck)
{
	torture_assert_int_equal(tctx, ck->out.handle->handle_type, 0, "handle type");
	torture_assert_werr_ok(tctx, ck->out.result, "return code");
	return true;
}

static const uint8_t OpenHKLM_In[] = {
  0x01, 0x00, 0x00, 0x00, 0xe0, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02
};

static bool openhklm_in_check(struct torture_context *tctx, 
								  struct winreg_OpenHKLM *r)
{
	torture_assert(tctx, r->in.system_name != NULL, "system name pointer");
	torture_assert_int_equal(tctx, *r->in.system_name, 34016, "system name");
	torture_assert_int_equal(tctx, r->in.access_mask, 0x02000000, "access mask");
	return true;
}

static const uint8_t openhklm_out_data[] = {
  0x00, 0x00, 0x00, 0x00, 0xb2, 0x64, 0xbc, 0xb3, 0x7f, 0x90, 0x29, 0x4a,
  0xb4, 0xb3, 0x91, 0xe7, 0xe4, 0x4a, 0x58, 0xe3, 0x00, 0x00, 0x00, 0x00
};

static bool openhklm_out_check(struct torture_context *tctx, 
								  struct winreg_OpenHKLM *r)
{
	torture_assert(tctx, r->out.handle != NULL, "handle pointer");
	torture_assert_int_equal(tctx, r->out.handle->handle_type, 0, "handle_type");
	torture_assert_werr_ok(tctx, r->out.result, "return code");
	return true;
}

static const uint8_t createkey_in_data[] = {
  0x00, 0x00, 0x00, 0x00, 0xb2, 0x64, 0xbc, 0xb3, 0x7f, 0x90, 0x29, 0x4a,
  0xb4, 0xb3, 0x91, 0xe7, 0xe4, 0x4a, 0x58, 0xe3, 0x16, 0x00, 0x16, 0x00,
  0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x0b, 0x00, 0x00, 0x00, 0x73, 0x00, 0x70, 0x00, 0x6f, 0x00, 0x74, 0x00,
  0x74, 0x00, 0x79, 0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00
};

static bool createkey_in_check(struct torture_context *tctx, 
								  struct winreg_CreateKey *r)
{
	torture_assert_str_equal(tctx, r->in.name.name, "spottyfoot", "name");
	torture_assert(tctx, r->in.keyclass.name == NULL, "keyclass");
	torture_assert_int_equal(tctx, r->in.options, 0, "option");
	torture_assert_int_equal(tctx, r->in.access_mask, 0x2000000, "access mask");
	torture_assert(tctx, r->in.secdesc == NULL, "secdesc");
	torture_assert(tctx, r->in.action_taken == NULL, "action_taken");

	return true;
}

static const uint8_t createkey_out_data[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x57, 0x00, 0x00, 0x00
};

static bool createkey_out_check(struct torture_context *tctx, 
								  struct winreg_CreateKey *r)
{
	torture_assert(tctx, GUID_all_zero(&r->out.new_handle->uuid), "new_handle");
	torture_assert(tctx, r->out.action_taken == NULL, "action_taken pointer");
	torture_assert_werr_equal(tctx, r->out.result, WERR_INVALID_PARAM, 
							  "return code");

	return true;
}

static const uint8_t enumvalue_in_data[] = {
  0x00, 0x00, 0x00, 0x00, 0xae, 0x1a, 0xbd, 0xbe, 0xbb, 0x94, 0xce, 0x4e,
  0xba, 0xcf, 0x56, 0xeb, 0xe5, 0xb3, 0x6c, 0xa3, 0x05, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
  0xff, 0xff, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static bool enumvalue_in_check(struct torture_context *tctx, 
								  struct winreg_EnumValue *r)
{
	torture_assert_int_equal(tctx, r->in.enum_index, 5, "enum index");
	torture_assert(tctx, r->in.type != NULL, "type pointer");
	torture_assert_int_equal(tctx, *r->in.type, 0, "type");
	torture_assert_int_equal(tctx, *r->in.size, 65535, "size");
	torture_assert_int_equal(tctx, *r->in.length, 0, "length");
	torture_assert_int_equal(tctx, r->in.name->size, 512, "name size");
	torture_assert_int_equal(tctx, r->in.name->length, 0, "name length");

	return true;
}

static const uint8_t enumvalue_out_data[] = {
  0x12, 0x00, 0x00, 0x02, 0x28, 0x91, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x48, 0x00, 0x4f, 0x00,
  0x4d, 0x00, 0x45, 0x00, 0x50, 0x00, 0x41, 0x00, 0x54, 0x00, 0x48, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xd8, 0x8c, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00,
  0xe0, 0x00, 0x0c, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x4c, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x44, 0x00, 0x6f, 0x00, 0x63, 0x00,
  0x75, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x6e, 0x00, 0x74, 0x00, 0x73, 0x00,
  0x20, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x20, 0x00, 0x53, 0x00,
  0x65, 0x00, 0x74, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x67, 0x00,
  0x73, 0x00, 0x5c, 0x00, 0x41, 0x00, 0x64, 0x00, 0x6d, 0x00, 0x69, 0x00,
  0x6e, 0x00, 0x69, 0x00, 0x73, 0x00, 0x74, 0x00, 0x72, 0x00, 0x61, 0x00,
  0x74, 0x00, 0x6f, 0x00, 0x72, 0x00, 0x00, 0x00, 0xf0, 0x8c, 0x07, 0x00,
  0x4c, 0x00, 0x00, 0x00, 0xf8, 0x8c, 0x07, 0x00, 0x4c, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00
};

static bool enumvalue_out_check(struct torture_context *tctx, 
								  struct winreg_EnumValue *r)
{
	torture_assert_int_equal(tctx, r->out.name->size, 512, "name size");
	torture_assert_int_equal(tctx, r->out.name->length, 18, "name length");
	torture_assert_str_equal(tctx, r->out.name->name, "HOMEPATH", "name");
	torture_assert_int_equal(tctx, *r->out.type, 1, "type");
	torture_assert_int_equal(tctx, *r->out.size, 76, "size");
	torture_assert_int_equal(tctx, *r->out.length, 76, "length");
	torture_assert_werr_ok(tctx, r->out.result, "return code");

	return true;
}

static const uint8_t queryvalue_in_data[] = {
  0x00, 0x00, 0x00, 0x00, 0xae, 0x1a, 0xbd, 0xbe, 0xbb, 0x94, 0xce, 0x4e,
  0xba, 0xcf, 0x56, 0xeb, 0xe5, 0xb3, 0x6c, 0xa3, 0x12, 0x00, 0x12, 0x00,
  0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x09, 0x00, 0x00, 0x00, 0x48, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x45, 0x00,
  0x50, 0x00, 0x41, 0x00, 0x54, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x03, 0x00, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00
};

static bool queryvalue_in_check(struct torture_context *tctx, 
								  struct winreg_QueryValue *r)
{
	torture_assert_str_equal(tctx, r->in.value_name.name, "HOMEPATH", "name");
	torture_assert_int_equal(tctx, *r->in.type, 0, "type");
	torture_assert_int_equal(tctx, *r->in.size, 4095, "size");
	torture_assert_int_equal(tctx, *r->in.length, 0, "length");
	torture_assert(tctx, r->in.data == NULL, "data pointer");

	return true;
}

static const uint8_t queryvalue_out_data[] = {
  0xd8, 0xf5, 0x0b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0xe4, 0xf5, 0x0b, 0x00, 0x4c, 0x00, 0x00, 0x00, 0xec, 0xf5, 0x0b, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static bool queryvalue_out_check(struct torture_context *tctx, 
								  struct winreg_QueryValue *r)
{
	torture_assert_werr_ok(tctx, r->out.result, "return code");
	torture_assert_int_equal(tctx, *r->out.type, 1, "type");
	torture_assert(tctx, r->out.data == NULL, "data pointer");
	torture_assert_int_equal(tctx, *r->out.size, 76, "size");
	torture_assert_int_equal(tctx, *r->out.length, 0, "length");

	return true;
}

static const uint8_t querymultiplevalues_in_data[] = {
  0x00, 0x00, 0x00, 0x00, 0xae, 0x1a, 0xbd, 0xbe, 0xbb, 0x94, 0xce, 0x4e,
  0xba, 0xcf, 0x56, 0xeb, 0xe5, 0xb3, 0x6c, 0xa3, 0x01, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x12, 0x00, 0x12, 0x00, 0x02, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x48, 0x00, 0x4f, 0x00,
  0x4d, 0x00, 0x45, 0x00, 0x50, 0x00, 0x41, 0x00, 0x54, 0x00, 0x48, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
  0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00
};

static bool querymultiplevalues_in_check(struct torture_context *tctx, 
										 struct winreg_QueryMultipleValues *r)
{
	torture_assert_int_equal(tctx, r->in.num_values, 1, "num values");
	torture_assert_str_equal(tctx, r->in.values[0].name->name, "HOMEPATH", 
							 "name");

	torture_assert_int_equal(tctx, r->in.values[0].type, 0, "type");
	torture_assert_int_equal(tctx, r->in.values[0].offset, 0, "offset");
	torture_assert_int_equal(tctx, r->in.values[0].length, 0, "length");
	torture_assert_int_equal(tctx, *r->in.buffer_size, 76, "buffer size");

	return true;
}

static const uint8_t querymultiplevalues_out_data[] = {
  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  0xd8, 0x8c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x12, 0x00, 0x38, 0x87, 0x07, 0x00,
  0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
  0x48, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x45, 0x00, 0x50, 0x00, 0x41, 0x00,
  0x54, 0x00, 0x48, 0x00, 0xc8, 0x95, 0x08, 0x00, 0x4c, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x4c, 0x4d, 0x45, 0x4d, 0xc8, 0x95, 0x08, 0x00,
  0x50, 0x87, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x07, 0x00,
  0x00, 0x01, 0x0c, 0x00, 0x50, 0x95, 0x08, 0x00, 0x48, 0x96, 0x08, 0x00,
  0xdc, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x00, 0x01, 0x0d, 0xf0, 0xff, 0xff,
  0x4c, 0x00, 0x00, 0x00, 0xea, 0x00, 0x00, 0x00
};

static bool querymultiplevalues_out_check(struct torture_context *tctx, 
										 struct winreg_QueryMultipleValues *r)
{
	torture_assert_str_equal(tctx, r->out.values[0].name->name, "HOMEPATH", 
							 "name");

	torture_assert_int_equal(tctx, r->out.values[0].type, 0, "type");
	torture_assert_int_equal(tctx, r->out.values[0].offset, 0, "offset");
	torture_assert_int_equal(tctx, r->out.values[0].length, 0, "length");
	/* FIXME: r->out.buffer */
	torture_assert_int_equal(tctx, *r->out.buffer_size, 76, "buffer size");
	torture_assert_werr_equal(tctx, r->out.result, WERR_MORE_DATA, 
								  "return code");

	return true;
}

struct torture_suite *ndr_winreg_suite(TALLOC_CTX *ctx)
{
	struct torture_suite *suite = torture_suite_create(ctx, "winreg");

	torture_suite_add_ndr_pull_fn_test(suite, winreg_CloseKey, closekey_in_data, NDR_IN, closekey_in_check );
	torture_suite_add_ndr_pull_fn_test(suite, winreg_CloseKey, closekey_out_data, NDR_IN, closekey_out_check );

	torture_suite_add_ndr_pull_fn_test(suite, winreg_OpenHKLM, OpenHKLM_In, NDR_IN, openhklm_in_check );
	torture_suite_add_ndr_pull_fn_test(suite, winreg_OpenHKLM, openhklm_out_data, NDR_OUT, openhklm_out_check );

	torture_suite_add_ndr_pull_fn_test(suite, winreg_CreateKey, createkey_in_data, NDR_IN, createkey_in_check );
	torture_suite_add_ndr_pull_fn_test(suite, winreg_CreateKey, createkey_out_data, NDR_OUT, createkey_out_check );

	torture_suite_add_ndr_pull_fn_test(suite, winreg_EnumValue, enumvalue_in_data, NDR_IN, enumvalue_in_check );
	torture_suite_add_ndr_pull_fn_test(suite, winreg_EnumValue, enumvalue_out_data, NDR_OUT, enumvalue_out_check );

	torture_suite_add_ndr_pull_fn_test(suite, winreg_QueryValue, queryvalue_in_data, NDR_IN, queryvalue_in_check );
	torture_suite_add_ndr_pull_fn_test(suite, winreg_QueryValue, queryvalue_out_data, NDR_OUT, queryvalue_out_check );

	/*torture_suite_add_ndr_pull_fn_test(suite, winreg_QueryMultipleValues, querymultiplevalues_in_data, NDR_IN, querymultiplevalues_in_check );
	torture_suite_add_ndr_pull_fn_test(suite, winreg_QueryMultipleValues, querymultiplevalues_out_data, NDR_OUT, querymultiplevalues_out_check );*/

	return suite;
}