2 * Unix SMB/CIFS implementation.
4 * WINREG client routines
6 * Copyright (c) 2011 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "../librpc/gen_ndr/ndr_winreg_c.h"
24 #include "rpc_client/cli_winreg.h"
26 NTSTATUS dcerpc_winreg_query_dword(TALLOC_CTX *mem_ctx,
27 struct dcerpc_binding_handle *h,
28 struct policy_handle *key_handle,
33 struct winreg_String wvalue;
34 enum winreg_Type type;
35 uint32_t value_len = 0;
36 uint32_t data_size = 0;
37 WERROR result = WERR_OK;
43 status = dcerpc_winreg_QueryValue(h,
52 if (!NT_STATUS_IS_OK(status)) {
55 if (!W_ERROR_IS_OK(result)) {
60 if (type != REG_DWORD) {
61 *pwerr = WERR_INVALID_DATATYPE;
66 *pwerr = WERR_INVALID_DATA;
70 blob = data_blob_talloc(mem_ctx, NULL, data_size);
71 if (blob.data == NULL) {
77 status = dcerpc_winreg_QueryValue(h,
86 if (!NT_STATUS_IS_OK(status)) {
89 if (!W_ERROR_IS_OK(result)) {
95 *data = IVAL(blob.data, 0);
101 NTSTATUS dcerpc_winreg_query_binary(TALLOC_CTX *mem_ctx,
102 struct dcerpc_binding_handle *h,
103 struct policy_handle *key_handle,
108 struct winreg_String wvalue;
109 enum winreg_Type type;
110 WERROR result = WERR_OK;
111 uint32_t value_len = 0;
112 uint32_t data_size = 0;
118 status = dcerpc_winreg_QueryValue(h,
127 if (!NT_STATUS_IS_OK(status)) {
130 if (!W_ERROR_IS_OK(result)) {
135 if (type != REG_BINARY) {
136 *pwerr = WERR_INVALID_DATATYPE;
140 blob = data_blob_talloc(mem_ctx, NULL, data_size);
141 if (blob.data == NULL) {
147 status = dcerpc_winreg_QueryValue(h,
156 if (!NT_STATUS_IS_OK(status)) {
159 if (!W_ERROR_IS_OK(result)) {
165 data->data = blob.data;
166 data->length = blob.length;
172 NTSTATUS dcerpc_winreg_query_multi_sz(TALLOC_CTX *mem_ctx,
173 struct dcerpc_binding_handle *h,
174 struct policy_handle *key_handle,
179 struct winreg_String wvalue;
180 enum winreg_Type type;
181 WERROR result = WERR_OK;
182 uint32_t value_len = 0;
183 uint32_t data_size = 0;
189 status = dcerpc_winreg_QueryValue(h,
198 if (!NT_STATUS_IS_OK(status)) {
201 if (!W_ERROR_IS_OK(result)) {
206 if (type != REG_MULTI_SZ) {
207 *pwerr = WERR_INVALID_DATATYPE;
211 blob = data_blob_talloc(mem_ctx, NULL, data_size);
212 if (blob.data == NULL) {
218 status = dcerpc_winreg_QueryValue(h,
227 if (!NT_STATUS_IS_OK(status)) {
230 if (!W_ERROR_IS_OK(result)) {
238 ok = pull_reg_multi_sz(mem_ctx, &blob, data);
247 NTSTATUS dcerpc_winreg_set_dword(TALLOC_CTX *mem_ctx,
248 struct dcerpc_binding_handle *h,
249 struct policy_handle *key_handle,
254 struct winreg_String wvalue;
256 WERROR result = WERR_OK;
260 blob = data_blob_talloc(mem_ctx, NULL, 4);
261 SIVAL(blob.data, 0, data);
263 status = dcerpc_winreg_SetValue(h,
271 if (!NT_STATUS_IS_OK(status)) {
274 if (!W_ERROR_IS_OK(result)) {
281 NTSTATUS dcerpc_winreg_set_sz(TALLOC_CTX *mem_ctx,
282 struct dcerpc_binding_handle *h,
283 struct policy_handle *key_handle,
288 struct winreg_String wvalue;
290 WERROR result = WERR_OK;
295 blob = data_blob_string_const("");
297 if (!push_reg_sz(mem_ctx, &blob, data)) {
298 DEBUG(2, ("dcerpc_winreg_set_sz: Could not marshall "
299 "string %s for %s\n",
306 status = dcerpc_winreg_SetValue(h,
314 if (!NT_STATUS_IS_OK(status)) {
317 if (!W_ERROR_IS_OK(result)) {
324 NTSTATUS dcerpc_winreg_set_expand_sz(TALLOC_CTX *mem_ctx,
325 struct dcerpc_binding_handle *h,
326 struct policy_handle *key_handle,
331 struct winreg_String wvalue;
333 WERROR result = WERR_OK;
338 blob = data_blob_string_const("");
340 if (!push_reg_sz(mem_ctx, &blob, data)) {
341 DEBUG(2, ("dcerpc_winreg_set_expand_sz: Could not marshall "
342 "string %s for %s\n",
349 status = dcerpc_winreg_SetValue(h,
357 if (!NT_STATUS_IS_OK(status)) {
360 if (!W_ERROR_IS_OK(result)) {
367 NTSTATUS dcerpc_winreg_set_multi_sz(TALLOC_CTX *mem_ctx,
368 struct dcerpc_binding_handle *h,
369 struct policy_handle *key_handle,
374 struct winreg_String wvalue;
376 WERROR result = WERR_OK;
380 if (!push_reg_multi_sz(mem_ctx, &blob, data)) {
381 DEBUG(2, ("dcerpc_winreg_set_multi_sz: Could not marshall "
382 "string multi sz for %s\n",
388 status = dcerpc_winreg_SetValue(h,
396 if (!NT_STATUS_IS_OK(status)) {
399 if (!W_ERROR_IS_OK(result)) {
406 NTSTATUS dcerpc_winreg_add_multi_sz(TALLOC_CTX *mem_ctx,
407 struct dcerpc_binding_handle *h,
408 struct policy_handle *key_handle,
413 const char **a = NULL;
416 WERROR result = WERR_OK;
419 status = dcerpc_winreg_query_multi_sz(mem_ctx,
426 /* count the elements */
427 for (p = a, i = 0; p && *p; p++, i++);
429 p = TALLOC_REALLOC_ARRAY(mem_ctx, a, const char *, i + 2);
438 status = dcerpc_winreg_set_multi_sz(mem_ctx,
448 NTSTATUS dcerpc_winreg_enum_keys(TALLOC_CTX *mem_ctx,
449 struct dcerpc_binding_handle *h,
450 struct policy_handle *key_hnd,
451 uint32_t *pnum_subkeys,
452 const char ***psubkeys,
455 const char **subkeys;
456 uint32_t num_subkeys, max_subkeylen, max_classlen;
457 uint32_t num_values, max_valnamelen, max_valbufsize;
459 NTTIME last_changed_time;
460 uint32_t secdescsize;
461 struct winreg_String classname;
462 WERROR result = WERR_OK;
466 tmp_ctx = talloc_stackframe();
467 if (tmp_ctx == NULL) {
468 return NT_STATUS_NO_MEMORY;
471 ZERO_STRUCT(classname);
473 status = dcerpc_winreg_QueryInfoKey(h,
486 if (!NT_STATUS_IS_OK(status)) {
489 if (!W_ERROR_IS_OK(result)) {
494 subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
495 if (subkeys == NULL) {
500 if (num_subkeys == 0) {
501 subkeys[0] = talloc_strdup(subkeys, "");
502 if (subkeys[0] == NULL) {
508 *psubkeys = talloc_move(mem_ctx, &subkeys);
511 TALLOC_FREE(tmp_ctx);
515 for (i = 0; i < num_subkeys; i++) {
519 struct winreg_StringBuf class_buf;
520 struct winreg_StringBuf name_buf;
524 class_buf.size = max_classlen + 2;
525 class_buf.length = 0;
528 name_buf.size = max_subkeylen + 2;
531 ZERO_STRUCT(modtime);
533 status = dcerpc_winreg_EnumKey(h,
541 if (!NT_STATUS_IS_OK(status)) {
542 DEBUG(5, ("dcerpc_winreg_enum_keys: Could not enumerate keys: %s\n",
547 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
551 if (!W_ERROR_IS_OK(result)) {
552 DEBUG(5, ("dcerpc_winreg_enum_keys: Could not enumerate keys: %s\n",
553 win_errstr(result)));
558 if (name_buf.name == NULL) {
559 *pwerr = WERR_INVALID_PARAMETER;
563 name = talloc_strdup(subkeys, name_buf.name);
572 *pnum_subkeys = num_subkeys;
574 *psubkeys = talloc_move(mem_ctx, &subkeys);
578 TALLOC_FREE(tmp_ctx);
583 /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */