1 /*
2    Unix SMB/CIFS implementation.
3    test suite for winreg ndr operations
4 
5    Copyright (C) Jelmer Vernooij 2007
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 3 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, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "includes.h"
22 #include "torture/ndr/ndr.h"
23 #include "librpc/gen_ndr/ndr_winreg.h"
24 #include "librpc/gen_ndr/ndr_security.h"
25 #include "libcli/security/security.h"
26 #include "torture/ndr/proto.h"
27 
28 static const uint8_t closekey_in_data[] = {
29         0x00, 0x00, 0x00, 0x00, 0x1d, 0xd8, 0xd7, 0xaa, 0x8d, 0x6c, 0x3f, 0x48,
30         0xa7, 0x1e, 0x02, 0x6a, 0x47, 0xf6, 0x7b, 0xae
31 };
32 
closekey_in_check(struct torture_context * tctx,struct winreg_CloseKey * ck)33 static bool closekey_in_check(struct torture_context *tctx,
34 								  struct winreg_CloseKey *ck)
35 {
36 	torture_assert(tctx, ck->in.handle != NULL, "handle invalid");
37 	torture_assert_int_equal(tctx, ck->in.handle->handle_type, 0, "handle type");
38 	return true;
39 }
40 
41 const static uint8_t closekey_out_data[] = {
42   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
44 };
45 
closekey_out_check(struct torture_context * tctx,struct winreg_CloseKey * ck)46 static bool closekey_out_check(struct torture_context *tctx,
47 							   struct winreg_CloseKey *ck)
48 {
49 	torture_assert_int_equal(tctx, ck->out.handle->handle_type, 0, "handle type");
50 	torture_assert_werr_ok(tctx, ck->out.result, "return code");
51 	return true;
52 }
53 
54 static const uint8_t OpenHKLM_In[] = {
55   0x01, 0x00, 0x00, 0x00, 0xe0, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02
56 };
57 
openhklm_in_check(struct torture_context * tctx,struct winreg_OpenHKLM * r)58 static bool openhklm_in_check(struct torture_context *tctx,
59 								  struct winreg_OpenHKLM *r)
60 {
61 	torture_assert(tctx, r->in.system_name != NULL, "system name pointer");
62 	torture_assert_int_equal(tctx, *r->in.system_name, 34016, "system name");
63 	torture_assert_int_equal(tctx, r->in.access_mask, 0x02000000, "access mask");
64 	return true;
65 }
66 
67 static const uint8_t openhklm_out_data[] = {
68   0x00, 0x00, 0x00, 0x00, 0xb2, 0x64, 0xbc, 0xb3, 0x7f, 0x90, 0x29, 0x4a,
69   0xb4, 0xb3, 0x91, 0xe7, 0xe4, 0x4a, 0x58, 0xe3, 0x00, 0x00, 0x00, 0x00
70 };
71 
openhklm_out_check(struct torture_context * tctx,struct winreg_OpenHKLM * r)72 static bool openhklm_out_check(struct torture_context *tctx,
73 								  struct winreg_OpenHKLM *r)
74 {
75 	torture_assert(tctx, r->out.handle != NULL, "handle pointer");
76 	torture_assert_int_equal(tctx, r->out.handle->handle_type, 0, "handle_type");
77 	torture_assert_werr_ok(tctx, r->out.result, "return code");
78 	return true;
79 }
80 
81 static const uint8_t createkey_in_data[] = {
82   0x00, 0x00, 0x00, 0x00, 0xb2, 0x64, 0xbc, 0xb3, 0x7f, 0x90, 0x29, 0x4a,
83   0xb4, 0xb3, 0x91, 0xe7, 0xe4, 0x4a, 0x58, 0xe3, 0x16, 0x00, 0x16, 0x00,
84   0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85   0x0b, 0x00, 0x00, 0x00, 0x73, 0x00, 0x70, 0x00, 0x6f, 0x00, 0x74, 0x00,
86   0x74, 0x00, 0x79, 0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00,
87   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
89   0x00, 0x00, 0x00, 0x00
90 };
91 
createkey_in_check(struct torture_context * tctx,struct winreg_CreateKey * r)92 static bool createkey_in_check(struct torture_context *tctx,
93 								  struct winreg_CreateKey *r)
94 {
95 	torture_assert_str_equal(tctx, r->in.name.name, "spottyfoot", "name");
96 	torture_assert(tctx, r->in.keyclass.name == NULL, "keyclass");
97 	torture_assert_int_equal(tctx, r->in.options, 0, "option");
98 	torture_assert_int_equal(tctx, r->in.access_mask, 0x2000000, "access mask");
99 	torture_assert(tctx, r->in.secdesc == NULL, "secdesc");
100 	torture_assert(tctx, r->in.action_taken == NULL, "action_taken");
101 
102 	return true;
103 }
104 
105 static const uint8_t createkey_out_data[] = {
106   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108   0x57, 0x00, 0x00, 0x00
109 };
110 
createkey_out_check(struct torture_context * tctx,struct winreg_CreateKey * r)111 static bool createkey_out_check(struct torture_context *tctx,
112 								  struct winreg_CreateKey *r)
113 {
114 	torture_assert(tctx, GUID_all_zero(&r->out.new_handle->uuid), "new_handle");
115 	torture_assert(tctx, r->out.action_taken == NULL, "action_taken pointer");
116 	torture_assert_werr_equal(tctx, r->out.result, WERR_INVALID_PARAMETER,
117 							  "return code");
118 
119 	return true;
120 }
121 
122 static const uint8_t enumvalue_in_data[] = {
123   0x00, 0x00, 0x00, 0x00, 0xae, 0x1a, 0xbd, 0xbe, 0xbb, 0x94, 0xce, 0x4e,
124   0xba, 0xcf, 0x56, 0xeb, 0xe5, 0xb3, 0x6c, 0xa3, 0x05, 0x00, 0x00, 0x00,
125   0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
126   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
127   0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00,
128   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
129   0xff, 0xff, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
130 };
131 
enumvalue_in_check(struct torture_context * tctx,struct winreg_EnumValue * r)132 static bool enumvalue_in_check(struct torture_context *tctx,
133 								  struct winreg_EnumValue *r)
134 {
135 	torture_assert_int_equal(tctx, r->in.enum_index, 5, "enum index");
136 	torture_assert(tctx, r->in.type != NULL, "type pointer");
137 	torture_assert_int_equal(tctx, *r->in.type, 0, "type");
138 	torture_assert_int_equal(tctx, *r->in.size, 65535, "size");
139 	torture_assert_int_equal(tctx, *r->in.length, 0, "length");
140 	torture_assert_int_equal(tctx, r->in.name->size, 512, "name size");
141 	torture_assert_int_equal(tctx, r->in.name->length, 0, "name length");
142 
143 	return true;
144 }
145 
146 static const uint8_t enumvalue_out_data[] = {
147   0x12, 0x00, 0x00, 0x02, 0x28, 0x91, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00,
148   0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x48, 0x00, 0x4f, 0x00,
149   0x4d, 0x00, 0x45, 0x00, 0x50, 0x00, 0x41, 0x00, 0x54, 0x00, 0x48, 0x00,
150   0x00, 0x00, 0x00, 0x00, 0xd8, 0x8c, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00,
151   0xe0, 0x00, 0x0c, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
152   0x4c, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x44, 0x00, 0x6f, 0x00, 0x63, 0x00,
153   0x75, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x6e, 0x00, 0x74, 0x00, 0x73, 0x00,
154   0x20, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x20, 0x00, 0x53, 0x00,
155   0x65, 0x00, 0x74, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x67, 0x00,
156   0x73, 0x00, 0x5c, 0x00, 0x41, 0x00, 0x64, 0x00, 0x6d, 0x00, 0x69, 0x00,
157   0x6e, 0x00, 0x69, 0x00, 0x73, 0x00, 0x74, 0x00, 0x72, 0x00, 0x61, 0x00,
158   0x74, 0x00, 0x6f, 0x00, 0x72, 0x00, 0x00, 0x00, 0xf0, 0x8c, 0x07, 0x00,
159   0x4c, 0x00, 0x00, 0x00, 0xf8, 0x8c, 0x07, 0x00, 0x4c, 0x00, 0x00, 0x00,
160   0x00, 0x00, 0x00, 0x00
161 };
162 
enumvalue_out_check(struct torture_context * tctx,struct winreg_EnumValue * r)163 static bool enumvalue_out_check(struct torture_context *tctx,
164 								  struct winreg_EnumValue *r)
165 {
166 	torture_assert_int_equal(tctx, r->out.name->size, 512, "name size");
167 	torture_assert_int_equal(tctx, r->out.name->length, 18, "name length");
168 	torture_assert_str_equal(tctx, r->out.name->name, "HOMEPATH", "name");
169 	torture_assert_int_equal(tctx, *r->out.type, 1, "type");
170 	torture_assert_int_equal(tctx, *r->out.size, 76, "size");
171 	torture_assert_int_equal(tctx, *r->out.length, 76, "length");
172 	torture_assert_werr_ok(tctx, r->out.result, "return code");
173 
174 	return true;
175 }
176 
177 unsigned char enumvalue_in_data2[] = {
178   0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179   0xda, 0x45, 0x9c, 0xed, 0xe2, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180   0x00, 0x00, 0x00, 0x02, 0xcc, 0xf9, 0x06, 0x00, 0x00, 0x01, 0x00, 0x00,
181   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0xf9, 0x06, 0x00,
182   0x39, 0xa6, 0x07, 0x00, 0x00, 0xc4, 0x04, 0x01, 0x00, 0x80, 0x00, 0x00,
183   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0xf9, 0x06, 0x00,
184   0x00, 0x80, 0x00, 0x00, 0x94, 0xf9, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00
185 };
186 
187 static const uint8_t queryvalue_in_data[] = {
188   0x00, 0x00, 0x00, 0x00, 0xae, 0x1a, 0xbd, 0xbe, 0xbb, 0x94, 0xce, 0x4e,
189   0xba, 0xcf, 0x56, 0xeb, 0xe5, 0xb3, 0x6c, 0xa3, 0x12, 0x00, 0x12, 0x00,
190   0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
191   0x09, 0x00, 0x00, 0x00, 0x48, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x45, 0x00,
192   0x50, 0x00, 0x41, 0x00, 0x54, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00,
193   0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194   0x03, 0x00, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
195   0x00, 0x00, 0x00, 0x00
196 };
197 
queryvalue_in_check(struct torture_context * tctx,struct winreg_QueryValue * r)198 static bool queryvalue_in_check(struct torture_context *tctx,
199 								  struct winreg_QueryValue *r)
200 {
201 	torture_assert_str_equal(tctx, r->in.value_name->name, "HOMEPATH", "name");
202 	torture_assert_int_equal(tctx, *r->in.type, 0, "type");
203 	torture_assert_int_equal(tctx, *r->in.data_size, 4095, "size");
204 	torture_assert_int_equal(tctx, *r->in.data_length, 0, "length");
205 	torture_assert(tctx, r->in.data == NULL, "data pointer");
206 
207 	return true;
208 }
209 
210 static const uint8_t queryvalue_out_data[] = {
211   0xd8, 0xf5, 0x0b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
212   0xe4, 0xf5, 0x0b, 0x00, 0x4c, 0x00, 0x00, 0x00, 0xec, 0xf5, 0x0b, 0x00,
213   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
214 };
215 
queryvalue_out_check(struct torture_context * tctx,struct winreg_QueryValue * r)216 static bool queryvalue_out_check(struct torture_context *tctx,
217 								  struct winreg_QueryValue *r)
218 {
219 	torture_assert_werr_ok(tctx, r->out.result, "return code");
220 	torture_assert_int_equal(tctx, *r->out.type, 1, "type");
221 	torture_assert(tctx, r->out.data == NULL, "data pointer");
222 	torture_assert_int_equal(tctx, *r->out.data_size, 76, "size");
223 	torture_assert_int_equal(tctx, *r->out.data_length, 0, "length");
224 
225 	return true;
226 }
227 
228 static const uint8_t querymultiplevalues_in_data[] = {
229   0x00, 0x00, 0x00, 0x00, 0xae, 0x1a, 0xbd, 0xbe, 0xbb, 0x94, 0xce, 0x4e,
230   0xba, 0xcf, 0x56, 0xeb, 0xe5, 0xb3, 0x6c, 0xa3, 0x01, 0x00, 0x00, 0x00,
231   0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
232   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233   0x12, 0x00, 0x12, 0x00, 0x02, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
234   0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x48, 0x00, 0x4f, 0x00,
235   0x4d, 0x00, 0x45, 0x00, 0x50, 0x00, 0x41, 0x00, 0x54, 0x00, 0x48, 0x00,
236   0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
237   0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
238   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00
241 };
242 
querymultiplevalues_in_check(struct torture_context * tctx,struct winreg_QueryMultipleValues * r)243 static bool querymultiplevalues_in_check(struct torture_context *tctx,
244 					 struct winreg_QueryMultipleValues *r)
245 {
246 	torture_assert_int_equal(tctx, r->in.num_values, 1, "num values");
247 	torture_assert_str_equal(tctx, r->in.values_in[0].ve_valuename->name, "HOMEPATH", "name");
248 	torture_assert_int_equal(tctx, r->in.values_in[0].ve_valuename->length, 18, "name len");
249 	torture_assert_int_equal(tctx, r->in.values_in[0].ve_valuename->size, 18, "name size");
250 	torture_assert_int_equal(tctx, r->in.values_in[0].ve_valuelen, 0, "length");
251 	torture_assert_int_equal(tctx, r->in.values_in[0].ve_valueptr, 0, "ve_valueptr");
252 	torture_assert_int_equal(tctx, r->in.values_in[0].ve_type, 0, "type");
253 	torture_assert_int_equal(tctx, *r->in.buffer_size, 32, "buffer size");
254 
255 	return true;
256 }
257 
258 static const uint8_t querymultiplevalues_out_data[] = {
259   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
260   0xd8, 0x8c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
261   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x12, 0x00, 0x38, 0x87, 0x07, 0x00,
262   0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
263   0x48, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x45, 0x00, 0x50, 0x00, 0x41, 0x00,
264   0x54, 0x00, 0x48, 0x00, 0xc8, 0x95, 0x08, 0x00, 0x4c, 0x00, 0x00, 0x00,
265   0x00, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268   0x00, 0x00, 0x00, 0x00, 0x4c, 0x4d, 0x45, 0x4d, 0xc8, 0x95, 0x08, 0x00,
269   0x50, 0x87, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x07, 0x00,
270   0x00, 0x01, 0x0c, 0x00, 0x50, 0x95, 0x08, 0x00, 0x48, 0x96, 0x08, 0x00,
271   0xdc, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x00, 0x01, 0x0d, 0xf0, 0xff, 0xff,
272   0x4c, 0x00, 0x00, 0x00, 0xea, 0x00, 0x00, 0x00
273 };
274 
querymultiplevalues_out_check(struct torture_context * tctx,struct winreg_QueryMultipleValues * r)275 static bool querymultiplevalues_out_check(struct torture_context *tctx,
276 					  struct winreg_QueryMultipleValues *r)
277 {
278 	torture_assert_str_equal(tctx, r->out.values_out[0].ve_valuename->name, "HOMEPATH", "name");
279 	torture_assert_int_equal(tctx, r->out.values_out[0].ve_type, 0, "type");
280 	torture_assert_int_equal(tctx, r->out.values_out[0].ve_valuelen, 0, "length");
281 	/* FIXME: r->out.buffer */
282 	torture_assert_int_equal(tctx, *r->out.buffer_size, 76, "buffer size");
283 	torture_assert_werr_equal(tctx, r->out.result, WERR_MORE_DATA, "return code");
284 
285 	return true;
286 }
287 
288 const uint8_t querymultiplevalues2_in_data[] = {
289 	0x00, 0x00, 0x00, 0x00, 0x98, 0xe4, 0xdf, 0x3c, 0x70, 0xde, 0x69, 0x4a,
290 	0x90, 0xb4, 0x85, 0x36, 0x33, 0x79, 0x89, 0x32, 0x01, 0x00, 0x00, 0x00,
291 	0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
292 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 	0x0a, 0x00, 0x0a, 0x00, 0x04, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00,
294 	0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x54, 0x00, 0x45, 0x00,
295 	0x4d, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
296 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
297 };
298 
querymultiplevalues2_in_check(struct torture_context * tctx,struct winreg_QueryMultipleValues2 * r)299 static bool querymultiplevalues2_in_check(struct torture_context *tctx,
300 					  struct winreg_QueryMultipleValues2 *r)
301 {
302 	torture_assert_int_equal(tctx, r->in.num_values, 1, "num values");
303 	torture_assert_str_equal(tctx, r->in.values_in[0].ve_valuename->name, "TEMP", "name");
304 	torture_assert_int_equal(tctx, r->in.values_in[0].ve_valuename->length, 10, "name len");
305 	torture_assert_int_equal(tctx, r->in.values_in[0].ve_valuename->size, 10, "name size");
306 	torture_assert_int_equal(tctx, r->in.values_in[0].ve_valuelen, 0, "length");
307 	torture_assert_int_equal(tctx, r->in.values_in[0].ve_valueptr, 0,  "ve_valueptr");
308 	torture_assert_int_equal(tctx, r->in.values_in[0].ve_type, 0, "type");
309 	torture_assert_int_equal(tctx, *r->in.offered, 0, "buffer size");
310 
311 	return true;
312 }
313 
314 const uint8_t querymultiplevalues2_out_data[] = {
315 	0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
316 	0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
317 	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x04, 0x00, 0x02, 0x00,
318 	0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
319 	0x54, 0x00, 0x45, 0x00, 0x4d, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
320 	0x42, 0x00, 0x00, 0x00, 0xea, 0x00, 0x00, 0x00
321 };
322 
querymultiplevalues2_out_check(struct torture_context * tctx,struct winreg_QueryMultipleValues2 * r)323 static bool querymultiplevalues2_out_check(struct torture_context *tctx,
324 					   struct winreg_QueryMultipleValues2 *r)
325 {
326 	return true;
327 }
328 
329 static const uint8_t flushkey_in_data[] = {
330   0x00, 0x00, 0x00, 0x00, 0xb2, 0x64, 0xbc, 0xb3, 0x7f, 0x90, 0x29, 0x4a,
331   0xb4, 0xb3, 0x91, 0xe7, 0xe4, 0x4a, 0x58, 0xe3
332 };
333 
flushkey_in_check(struct torture_context * tctx,struct winreg_FlushKey * r)334 static bool flushkey_in_check(struct torture_context *tctx,
335 							   struct winreg_FlushKey *r)
336 {
337 	torture_assert_int_equal(tctx, r->in.handle->handle_type, 0, "handle type");
338 	return true;
339 }
340 
341 static const uint8_t flushkey_out_data[] = {
342   0x00, 0x00, 0x00, 0x00
343 };
344 
flushkey_out_check(struct torture_context * tctx,struct winreg_FlushKey * r)345 static bool flushkey_out_check(struct torture_context *tctx,
346 							   struct winreg_FlushKey *r)
347 {
348 	torture_assert_werr_ok(tctx, r->out.result, "return code");
349 	return true;
350 }
351 
352 
353 static const uint8_t openkey_in_data[] = {
354   0x00, 0x00, 0x00, 0x00, 0xb2, 0x64, 0xbc, 0xb3, 0x7f, 0x90, 0x29, 0x4a,
355   0xb4, 0xb3, 0x91, 0xe7, 0xe4, 0x4a, 0x58, 0xe3, 0x16, 0x00, 0x16, 0x00,
356   0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
357   0x0b, 0x00, 0x00, 0x00, 0x73, 0x00, 0x70, 0x00, 0x6f, 0x00, 0x74, 0x00,
358   0x74, 0x00, 0x79, 0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00,
359   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02
360 };
361 
openkey_in_check(struct torture_context * tctx,struct winreg_OpenKey * r)362 static bool openkey_in_check(struct torture_context *tctx, struct winreg_OpenKey *r)
363 {
364 	torture_assert_int_equal(tctx, r->in.options, 0, "unknown");
365 	torture_assert_int_equal(tctx, r->in.access_mask, 0x02000000, "access mask");
366 	torture_assert_str_equal(tctx, r->in.keyname.name, "spottyfoot", "keyname");
367 	/* FIXME: parent handle */
368 	return true;
369 }
370 
371 static const uint8_t openkey_out_data[] = {
372   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
373   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00
374 };
375 
openkey_out_check(struct torture_context * tctx,struct winreg_OpenKey * r)376 static bool openkey_out_check(struct torture_context *tctx, struct winreg_OpenKey *r)
377 {
378 	torture_assert(tctx, GUID_all_zero(&r->out.handle->uuid), "handle");
379 	torture_assert_werr_equal(tctx, r->out.result, WERR_FILE_NOT_FOUND, "return code");
380 	return true;
381 }
382 
383 static const uint8_t deletekey_in_data[] = {
384   0x00, 0x00, 0x00, 0x00, 0xb2, 0x64, 0xbc, 0xb3, 0x7f, 0x90, 0x29, 0x4a,
385   0xb4, 0xb3, 0x91, 0xe7, 0xe4, 0x4a, 0x58, 0xe3, 0x16, 0x00, 0x16, 0x00,
386   0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
387   0x0b, 0x00, 0x00, 0x00, 0x73, 0x00, 0x70, 0x00, 0x6f, 0x00, 0x74, 0x00,
388   0x74, 0x00, 0x79, 0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00,
389   0x00, 0x00
390 };
391 
deletekey_in_check(struct torture_context * tctx,struct winreg_DeleteKey * r)392 static bool deletekey_in_check(struct torture_context *tctx, struct winreg_DeleteKey *r)
393 {
394 	/* FIXME: Handle */
395 	torture_assert_str_equal(tctx, r->in.key.name, "spottyfoot", "key name");
396 	return true;
397 }
398 
399 static const uint8_t deletekey_out_data[] = {
400   0x02, 0x00, 0x00, 0x00
401 };
402 
deletekey_out_check(struct torture_context * tctx,struct winreg_DeleteKey * r)403 static bool deletekey_out_check(struct torture_context *tctx, struct winreg_DeleteKey *r)
404 {
405 	torture_assert_werr_equal(tctx, r->out.result, WERR_FILE_NOT_FOUND, "return code");
406 	return true;
407 }
408 
409 static const uint8_t getversion_in_data[] = {
410   0x00, 0x00, 0x00, 0x00, 0xb2, 0x64, 0xbc, 0xb3, 0x7f, 0x90, 0x29, 0x4a,
411   0xb4, 0xb3, 0x91, 0xe7, 0xe4, 0x4a, 0x58, 0xe3
412 };
413 
getversion_in_check(struct torture_context * tctx,struct winreg_GetVersion * r)414 static bool getversion_in_check(struct torture_context *tctx, struct winreg_GetVersion *r)
415 {
416 	/* FIXME: Handle */
417 	return true;
418 }
419 
420 static const uint8_t getversion_out_data[] = {
421   0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
422 };
423 
getversion_out_check(struct torture_context * tctx,struct winreg_GetVersion * r)424 static bool getversion_out_check(struct torture_context *tctx, struct winreg_GetVersion *r)
425 {
426 	torture_assert_int_equal(tctx, *r->out.version, 5, "version");
427 	torture_assert_werr_ok(tctx, r->out.result, "return code");
428 	return true;
429 }
430 
431 static const uint8_t queryinfokey_in_data[] = {
432   0x00, 0x00, 0x00, 0x00, 0xb2, 0x64, 0xbc, 0xb3, 0x7f, 0x90, 0x29, 0x4a,
433   0xb4, 0xb3, 0x91, 0xe7, 0xe4, 0x4a, 0x58, 0xe3, 0x00, 0x00, 0x00, 0x00,
434   0x00, 0x00, 0x00, 0x00
435 };
436 
queryinfokey_in_check(struct torture_context * tctx,struct winreg_QueryInfoKey * r)437 static bool queryinfokey_in_check(struct torture_context *tctx, struct winreg_QueryInfoKey *r)
438 {
439 	/* FIXME: Handle */
440 	torture_assert(tctx, r->in.classname->name == NULL, "class in");
441 	return true;
442 }
443 
444 #if 0
445 static const uint8_t queryinfokey_out_data[] = {
446   0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
447   0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
448   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00,
449   0x10, 0x48, 0x02, 0x3a, 0xcf, 0xfd, 0xc4, 0x01, 0x00, 0x00, 0x00, 0x00
450 };
451 
452 static bool queryinfokey_out_check(struct torture_context *tctx, struct winreg_QueryInfoKey *r)
453 {
454 	torture_assert(tctx, r->out.classname != NULL, "class out");
455 	torture_assert(tctx, r->out.classname->name != NULL, "class out name");
456 	torture_assert_str_equal(tctx, r->out.classname->name, "", "class out name");
457 	torture_assert_int_equal(tctx, *r->out.num_subkeys, 0, "num subkeys");
458 	torture_assert_int_equal(tctx, *r->out.max_subkeylen, 0, "subkey length");
459 	torture_assert_int_equal(tctx, *r->out.max_classlen, 140, "subkey size");
460 	torture_assert_werr_ok(tctx, r->out.result, "return code");
461 	return true;
462 }
463 #endif
464 
465 static const uint8_t notifychangekeyvalue_in_data[] = {
466   0x00, 0x00, 0x00, 0x00, 0xb2, 0x64, 0xbc, 0xb3, 0x7f, 0x90, 0x29, 0x4a,
467   0xb4, 0xb3, 0x91, 0xe7, 0xe4, 0x4a, 0x58, 0xe3, 0x01, 0x00, 0x00, 0x00,
468   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
469   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
470   0x00, 0x00, 0x00, 0x00
471 };
472 
notifychangekeyvalue_in_check(struct torture_context * tctx,struct winreg_NotifyChangeKeyValue * r)473 static bool notifychangekeyvalue_in_check(struct torture_context *tctx, struct winreg_NotifyChangeKeyValue *r)
474 {
475 	torture_assert_int_equal(tctx, r->in.watch_subtree, 1, "watch subtree");
476 	torture_assert_int_equal(tctx, r->in.notify_filter, 0, "notify filter");
477 	torture_assert_int_equal(tctx, r->in.unknown, 0, "unknown");
478 	torture_assert(tctx, r->in.string1.name == NULL, "string1");
479 	torture_assert(tctx, r->in.string2.name == NULL, "string2");
480 	torture_assert_int_equal(tctx, r->in.unknown2, 0, "unknown2");
481 	return true;
482 }
483 
484 static const uint8_t notifychangekeyvalue_out_data[] = {
485   0x57, 0x00, 0x00, 0x00
486 };
487 
notifychangekeyvalue_out_check(struct torture_context * tctx,struct winreg_NotifyChangeKeyValue * r)488 static bool notifychangekeyvalue_out_check(struct torture_context *tctx, struct winreg_NotifyChangeKeyValue *r)
489 {
490 	torture_assert_werr_equal(tctx, r->out.result, WERR_INVALID_PARAMETER, "notify change key value");
491 	return true;
492 }
493 
494 #if 0
495 static const uint8_t getkeysecurity_in_data[] = {
496   0x00, 0x00, 0x00, 0x00, 0xbd, 0xaa, 0xf6, 0x59, 0xc1, 0x82, 0x1f, 0x4d,
497   0x84, 0xa9, 0xdd, 0xae, 0x60, 0x77, 0x1e, 0x45, 0x00, 0x00, 0x00, 0x02,
498   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
499 };
500 
501 static bool getkeysecurity_in_check(struct torture_context *tctx,
502 				    struct winreg_GetKeySecurity *r)
503 {
504 	/* FIXME: Handle */
505 	torture_assert_int_equal(tctx, r->in.sec_info, 2, "sec info");
506 	torture_assert_int_equal(tctx, r->in.sd->size, 65536, "sd size");
507 	torture_assert_int_equal(tctx, r->in.sd->len, 0, "sd len");
508 	torture_assert(tctx, r->in.sd->data == NULL, "sd data");
509 	return true;
510 }
511 
512 static const uint8_t getkeysecurity_out_data[] = {
513   0x08, 0x91, 0x08, 0x00, 0x14, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
514   0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
515   0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
516   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
517 };
518 
519 static bool getkeysecurity_out_check(struct torture_context *tctx,
520 				     struct winreg_GetKeySecurity *r)
521 {
522 	torture_assert_int_equal(tctx, r->in.sd->size, 20, "sd size");
523 	torture_assert_int_equal(tctx, r->in.sd->len, 20, "sd len");
524 	torture_assert_werr_ok(tctx, r->out.result, "return code");
525 	return true;
526 }
527 #endif
528 
529 static const uint8_t enumkey_in_data[] = {
530   0x00, 0x00, 0x00, 0x00, 0x85, 0xb8, 0x41, 0xb0, 0x17, 0xe4, 0x28, 0x45,
531   0x8a, 0x69, 0xbf, 0x40, 0x79, 0x82, 0x8b, 0xcb, 0x00, 0x00, 0x00, 0x00,
532   0x00, 0x00, 0x14, 0x04, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x02, 0x00, 0x00,
533   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
534   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
535   0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f
536 };
537 
enumkey_in_check(struct torture_context * tctx,struct winreg_EnumKey * r)538 static bool enumkey_in_check(struct torture_context *tctx, struct winreg_EnumKey *r)
539 {
540 	torture_assert_int_equal(tctx, r->in.enum_index, 0, "enum index");
541 	torture_assert_int_equal(tctx, r->in.name->size, 1044, "name size");
542 	torture_assert_int_equal(tctx, r->in.name->length, 0, "name len");
543 	torture_assert(tctx, r->in.keyclass != NULL, "keyclass pointer");
544 	torture_assert(tctx, r->in.keyclass->name == NULL, "keyclass");
545 	torture_assert(tctx, r->in.last_changed_time != NULL, "last_changed_time != NULL");
546 	return true;
547 }
548 
549 static const uint8_t enumkey_out_data[] = {
550   0x08, 0x00, 0x14, 0x04, 0x18, 0xe8, 0x07, 0x00, 0x0a, 0x02, 0x00, 0x00,
551   0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x53, 0x00, 0x41, 0x00,
552   0x4d, 0x00, 0x00, 0x00, 0xd0, 0x62, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
553   0x00, 0x00, 0x00, 0x00, 0xdc, 0x62, 0x07, 0x00, 0x50, 0x67, 0xd0, 0x8b,
554   0x16, 0x06, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x00
555 };
556 
enumkey_out_check(struct torture_context * tctx,struct winreg_EnumKey * r)557 static bool enumkey_out_check(struct torture_context *tctx, struct winreg_EnumKey *r)
558 {
559 	torture_assert_int_equal(tctx, r->out.name->size, 1044, "name size");
560 	torture_assert_int_equal(tctx, r->out.name->length, 8, "name len");
561 	torture_assert(tctx, r->out.keyclass != NULL, "keyclass pointer");
562 	torture_assert(tctx, r->out.keyclass->name == NULL, "keyclass");
563 	torture_assert(tctx, r->out.last_changed_time != NULL, "last_changed_time pointer");
564 	/* FIXME: *last_changed_time */
565 	return true;
566 }
567 
ndr_winreg_suite(TALLOC_CTX * ctx)568 struct torture_suite *ndr_winreg_suite(TALLOC_CTX *ctx)
569 {
570 	struct torture_suite *suite = torture_suite_create(ctx, "winreg");
571 
572 	torture_suite_add_ndr_pull_fn_test(suite, winreg_CloseKey, closekey_in_data, NDR_IN, closekey_in_check );
573 	torture_suite_add_ndr_pull_fn_test(suite, winreg_CloseKey, closekey_out_data, NDR_OUT, closekey_out_check );
574 
575 	torture_suite_add_ndr_pull_fn_test(suite, winreg_OpenHKLM, OpenHKLM_In, NDR_IN, openhklm_in_check );
576 	torture_suite_add_ndr_pull_fn_test(suite, winreg_OpenHKLM, openhklm_out_data, NDR_OUT, openhklm_out_check );
577 
578 	torture_suite_add_ndr_pull_fn_test(suite, winreg_CreateKey, createkey_in_data, NDR_IN, createkey_in_check );
579 	torture_suite_add_ndr_pull_fn_test(suite, winreg_CreateKey, createkey_out_data, NDR_OUT, createkey_out_check );
580 
581 	torture_suite_add_ndr_pull_fn_test(suite, winreg_EnumValue, enumvalue_in_data, NDR_IN, enumvalue_in_check );
582 	torture_suite_add_ndr_pull_fn_test(suite, winreg_EnumValue, enumvalue_out_data, NDR_OUT, enumvalue_out_check );
583 	torture_suite_add_ndr_pull_fn_test(suite, winreg_EnumValue, enumvalue_in_data2, NDR_IN, NULL);
584 
585 	torture_suite_add_ndr_pull_fn_test(suite, winreg_QueryValue, queryvalue_in_data, NDR_IN, queryvalue_in_check );
586 	torture_suite_add_ndr_pull_fn_test(suite, winreg_QueryValue, queryvalue_out_data, NDR_OUT, queryvalue_out_check );
587 
588 	torture_suite_add_ndr_pull_fn_test(suite, winreg_QueryMultipleValues, querymultiplevalues_in_data, NDR_IN, querymultiplevalues_in_check );
589 	torture_suite_add_ndr_pull_io_test(suite, winreg_QueryMultipleValues, querymultiplevalues_in_data, querymultiplevalues_out_data, querymultiplevalues_out_check);
590 
591 	torture_suite_add_ndr_pull_fn_test(suite, winreg_QueryMultipleValues2, querymultiplevalues2_in_data, NDR_IN, querymultiplevalues2_in_check );
592 	torture_suite_add_ndr_pull_io_test(suite, winreg_QueryMultipleValues2, querymultiplevalues2_in_data, querymultiplevalues2_out_data, querymultiplevalues2_out_check);
593 
594 	torture_suite_add_ndr_pull_fn_test(suite, winreg_FlushKey, flushkey_in_data, NDR_IN, flushkey_in_check );
595 	torture_suite_add_ndr_pull_fn_test(suite, winreg_FlushKey, flushkey_out_data, NDR_OUT, flushkey_out_check );
596 
597 	torture_suite_add_ndr_pull_fn_test(suite, winreg_OpenKey, openkey_in_data, NDR_IN, openkey_in_check );
598 	torture_suite_add_ndr_pull_fn_test(suite, winreg_OpenKey, openkey_out_data, NDR_OUT, openkey_out_check );
599 
600 	torture_suite_add_ndr_pull_fn_test(suite, winreg_DeleteKey, deletekey_in_data, NDR_IN, deletekey_in_check );
601 	torture_suite_add_ndr_pull_fn_test(suite, winreg_DeleteKey, deletekey_out_data, NDR_OUT, deletekey_out_check );
602 
603 	torture_suite_add_ndr_pull_fn_test(suite, winreg_GetVersion, getversion_in_data, NDR_IN, getversion_in_check );
604 	torture_suite_add_ndr_pull_fn_test(suite, winreg_GetVersion, getversion_out_data, NDR_OUT, getversion_out_check );
605 
606 	torture_suite_add_ndr_pull_fn_test(suite, winreg_QueryInfoKey, queryinfokey_in_data, NDR_IN, queryinfokey_in_check );
607 	/*torture_suite_add_ndr_pull_fn_test(suite, winreg_QueryInfoKey, queryinfokey_out_data, NDR_OUT, queryinfokey_out_check );*/
608 
609 	torture_suite_add_ndr_pull_fn_test(suite, winreg_NotifyChangeKeyValue, notifychangekeyvalue_in_data, NDR_IN, notifychangekeyvalue_in_check );
610 	torture_suite_add_ndr_pull_fn_test(suite, winreg_NotifyChangeKeyValue, notifychangekeyvalue_out_data, NDR_OUT, notifychangekeyvalue_out_check );
611 
612 	/*torture_suite_add_ndr_pull_fn_test(suite, winreg_GetKeySecurity, getkeysecurity_in_data, NDR_IN, getkeysecurity_in_check );
613 	torture_suite_add_ndr_pull_fn_test(suite, winreg_GetKeySecurity, getkeysecurity_out_data, NDR_OUT, getkeysecurity_out_check );*/
614 
615 	torture_suite_add_ndr_pull_fn_test(suite, winreg_EnumKey, enumkey_in_data, NDR_IN, enumkey_in_check );
616 	torture_suite_add_ndr_pull_fn_test(suite, winreg_EnumKey, enumkey_out_data, NDR_OUT, enumkey_out_check );
617 
618 	return suite;
619 }
620 
621