2 * Unix SMB/CIFS implementation.
3 * Registry helper routines
4 * Copyright (C) Volker Lendecke 2006
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 3 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, see <http://www.gnu.org/licenses/>.
23 #define DBGC_CLASS DBGC_REGISTRY
25 WERROR registry_pull_value(TALLOC_CTX *mem_ctx,
26 struct registry_value **pvalue,
27 enum winreg_Type type, uint8 *data,
28 uint32 size, uint32 length)
30 struct registry_value *value;
33 if (!(value = TALLOC_ZERO_P(mem_ctx, struct registry_value))) {
41 if ((size != 4) || (length != 4)) {
42 err = WERR_INVALID_PARAM;
45 value->v.dword = IVAL(data, 0);
51 * Make sure we get a NULL terminated string for
52 * convert_string_talloc().
58 /* win2k regedit gives us a string of 1 byte when
59 * creating a new value of type REG_SZ. this workaround
60 * replaces the input by using the same string as
63 if (!(tmp = SMB_MALLOC_ARRAY(smb_ucs2_t, 2))) {
69 DEBUG(10, ("got REG_SZ value of length 1 - workaround "
72 else if ((length % 2) != 0) {
73 err = WERR_INVALID_PARAM;
77 uint32 num_ucs2 = length / 2;
78 if (!(tmp = SMB_MALLOC_ARRAY(smb_ucs2_t, num_ucs2+1))) {
83 memcpy((void *)tmp, (const void *)data, length);
87 if (length + 2 < length) {
90 err = WERR_INVALID_PARAM;
94 value->v.sz.len = convert_string_talloc(
95 value, CH_UTF16LE, CH_UNIX, tmp, length+2,
96 &value->v.sz.str, False);
100 if (value->v.sz.len == (size_t)-1) {
101 err = WERR_INVALID_PARAM;
107 err = reg_pull_multi_sz(value, (void *)data, length,
108 &value->v.multi_sz.num_strings,
109 &value->v.multi_sz.strings);
110 if (!(W_ERROR_IS_OK(err))) {
115 value->v.binary = data_blob_talloc(mem_ctx, data, length);
118 err = WERR_INVALID_PARAM;
130 WERROR registry_push_value(TALLOC_CTX *mem_ctx,
131 const struct registry_value *value,
134 switch (value->type) {
137 SIVAL(buf, 0, value->v.dword);
138 *presult = data_blob_talloc(mem_ctx, (void *)buf, 4);
139 if (presult->data == NULL) {
145 case REG_EXPAND_SZ: {
146 presult->length = convert_string_talloc(
147 mem_ctx, CH_UNIX, CH_UTF16LE, value->v.sz.str,
148 MIN(value->v.sz.len, strlen(value->v.sz.str)+1),
149 (void *)&(presult->data), False);
150 if (presult->length == (size_t)-1) {
156 *presult = data_blob_talloc(mem_ctx,
157 value->v.binary.data,
158 value->v.binary.length);
161 return WERR_INVALID_PARAM;