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_query_sz(TALLOC_CTX *mem_ctx,
248 struct dcerpc_binding_handle *h,
249 struct policy_handle *key_handle,
254 struct winreg_String wvalue;
255 enum winreg_Type type;
256 WERROR result = WERR_OK;
257 uint32_t value_len = 0;
258 uint32_t data_size = 0;
264 status = dcerpc_winreg_QueryValue(h,
273 if (!NT_STATUS_IS_OK(status)) {
276 if (!W_ERROR_IS_OK(result)) {
281 if (type != REG_SZ) {
282 *pwerr = WERR_INVALID_DATATYPE;
286 blob = data_blob_talloc(mem_ctx, NULL, data_size);
287 if (blob.data == NULL) {
293 status = dcerpc_winreg_QueryValue(h,
302 if (!NT_STATUS_IS_OK(status)) {
305 if (!W_ERROR_IS_OK(result)) {
313 ok = pull_reg_sz(mem_ctx, &blob, data);
322 NTSTATUS dcerpc_winreg_set_dword(TALLOC_CTX *mem_ctx,
323 struct dcerpc_binding_handle *h,
324 struct policy_handle *key_handle,
329 struct winreg_String wvalue;
331 WERROR result = WERR_OK;
335 blob = data_blob_talloc(mem_ctx, NULL, 4);
336 SIVAL(blob.data, 0, data);
338 status = dcerpc_winreg_SetValue(h,
346 if (!NT_STATUS_IS_OK(status)) {
349 if (!W_ERROR_IS_OK(result)) {
356 NTSTATUS dcerpc_winreg_set_sz(TALLOC_CTX *mem_ctx,
357 struct dcerpc_binding_handle *h,
358 struct policy_handle *key_handle,
363 struct winreg_String wvalue;
365 WERROR result = WERR_OK;
370 blob = data_blob_string_const("");
372 if (!push_reg_sz(mem_ctx, &blob, data)) {
373 DEBUG(2, ("dcerpc_winreg_set_sz: Could not marshall "
374 "string %s for %s\n",
381 status = dcerpc_winreg_SetValue(h,
389 if (!NT_STATUS_IS_OK(status)) {
392 if (!W_ERROR_IS_OK(result)) {
399 NTSTATUS dcerpc_winreg_set_expand_sz(TALLOC_CTX *mem_ctx,
400 struct dcerpc_binding_handle *h,
401 struct policy_handle *key_handle,
406 struct winreg_String wvalue;
408 WERROR result = WERR_OK;
413 blob = data_blob_string_const("");
415 if (!push_reg_sz(mem_ctx, &blob, data)) {
416 DEBUG(2, ("dcerpc_winreg_set_expand_sz: Could not marshall "
417 "string %s for %s\n",
424 status = dcerpc_winreg_SetValue(h,
432 if (!NT_STATUS_IS_OK(status)) {
435 if (!W_ERROR_IS_OK(result)) {
442 NTSTATUS dcerpc_winreg_set_multi_sz(TALLOC_CTX *mem_ctx,
443 struct dcerpc_binding_handle *h,
444 struct policy_handle *key_handle,
449 struct winreg_String wvalue;
451 WERROR result = WERR_OK;
455 if (!push_reg_multi_sz(mem_ctx, &blob, data)) {
456 DEBUG(2, ("dcerpc_winreg_set_multi_sz: Could not marshall "
457 "string multi sz for %s\n",
463 status = dcerpc_winreg_SetValue(h,
471 if (!NT_STATUS_IS_OK(status)) {
474 if (!W_ERROR_IS_OK(result)) {
481 NTSTATUS dcerpc_winreg_set_binary(TALLOC_CTX *mem_ctx,
482 struct dcerpc_binding_handle *h,
483 struct policy_handle *key_handle,
488 struct winreg_String wvalue;
489 WERROR result = WERR_OK;
494 status = dcerpc_winreg_SetValue(h,
502 if (!NT_STATUS_IS_OK(status)) {
505 if (!W_ERROR_IS_OK(result)) {
512 NTSTATUS dcerpc_winreg_add_multi_sz(TALLOC_CTX *mem_ctx,
513 struct dcerpc_binding_handle *h,
514 struct policy_handle *key_handle,
519 const char **a = NULL;
522 WERROR result = WERR_OK;
525 status = dcerpc_winreg_query_multi_sz(mem_ctx,
532 /* count the elements */
533 for (p = a, i = 0; p && *p; p++, i++);
535 p = TALLOC_REALLOC_ARRAY(mem_ctx, a, const char *, i + 2);
544 status = dcerpc_winreg_set_multi_sz(mem_ctx,
554 NTSTATUS dcerpc_winreg_enum_keys(TALLOC_CTX *mem_ctx,
555 struct dcerpc_binding_handle *h,
556 struct policy_handle *key_hnd,
557 uint32_t *pnum_subkeys,
558 const char ***psubkeys,
561 const char **subkeys;
562 uint32_t num_subkeys, max_subkeylen, max_classlen;
563 uint32_t num_values, max_valnamelen, max_valbufsize;
565 NTTIME last_changed_time;
566 uint32_t secdescsize;
567 struct winreg_String classname;
568 WERROR result = WERR_OK;
572 tmp_ctx = talloc_stackframe();
573 if (tmp_ctx == NULL) {
574 return NT_STATUS_NO_MEMORY;
577 ZERO_STRUCT(classname);
579 status = dcerpc_winreg_QueryInfoKey(h,
592 if (!NT_STATUS_IS_OK(status)) {
595 if (!W_ERROR_IS_OK(result)) {
600 subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
601 if (subkeys == NULL) {
606 if (num_subkeys == 0) {
607 subkeys[0] = talloc_strdup(subkeys, "");
608 if (subkeys[0] == NULL) {
614 *psubkeys = talloc_move(mem_ctx, &subkeys);
617 TALLOC_FREE(tmp_ctx);
621 for (i = 0; i < num_subkeys; i++) {
625 struct winreg_StringBuf class_buf;
626 struct winreg_StringBuf name_buf;
630 class_buf.size = max_classlen + 2;
631 class_buf.length = 0;
634 name_buf.size = max_subkeylen + 2;
637 ZERO_STRUCT(modtime);
639 status = dcerpc_winreg_EnumKey(h,
647 if (!NT_STATUS_IS_OK(status)) {
648 DEBUG(5, ("dcerpc_winreg_enum_keys: Could not enumerate keys: %s\n",
653 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
657 if (!W_ERROR_IS_OK(result)) {
658 DEBUG(5, ("dcerpc_winreg_enum_keys: Could not enumerate keys: %s\n",
659 win_errstr(result)));
664 if (name_buf.name == NULL) {
665 *pwerr = WERR_INVALID_PARAMETER;
669 name = talloc_strdup(subkeys, name_buf.name);
678 *pnum_subkeys = num_subkeys;
680 *psubkeys = talloc_move(mem_ctx, &subkeys);
684 TALLOC_FREE(tmp_ctx);
689 /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */