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/>.
24 #define DBGC_CLASS DBGC_REGISTRY
26 WERROR registry_pull_value(TALLOC_CTX *mem_ctx,
27 struct registry_value **pvalue,
28 enum winreg_Type type, uint8 *data,
29 uint32 size, uint32 length)
31 struct registry_value *value;
34 if (!(value = TALLOC_ZERO_P(mem_ctx, struct registry_value))) {
42 case REG_DWORD_BIG_ENDIAN:
43 if ((size != 4) || (length != 4)) {
44 err = WERR_INVALID_PARAM;
47 value->v.dword = IVAL(data, 0);
50 if ((size != 8) || (length != 8)) {
51 err = WERR_INVALID_PARAM;
54 value->v.qword = BVAL(data, 0);
60 * Make sure we get a NULL terminated string for
61 * convert_string_talloc().
67 /* win2k regedit gives us a string of 1 byte when
68 * creating a new value of type REG_SZ. this workaround
69 * replaces the input by using the same string as
72 if (!(tmp = SMB_MALLOC_ARRAY(smb_ucs2_t, 2))) {
78 DEBUG(10, ("got REG_SZ value of length 1 - workaround "
81 else if ((length % 2) != 0) {
82 err = WERR_INVALID_PARAM;
86 uint32 num_ucs2 = length / 2;
87 if (!(tmp = SMB_MALLOC_ARRAY(smb_ucs2_t, num_ucs2+1))) {
92 memcpy((void *)tmp, (const void *)data, length);
95 if (length + 2 < length) {
98 err = WERR_INVALID_PARAM;
102 if (!convert_string_talloc(value, CH_UTF16LE, CH_UNIX, tmp,
103 length+2, (void *)&value->v.sz.str,
104 &value->v.sz.len, False)) {
106 err = WERR_INVALID_PARAM;
118 blob = data_blob_const(data, length);
120 if (!pull_reg_multi_sz(mem_ctx, &blob, &vals)) {
125 for (i=0; vals[i]; i++) {
129 value->v.multi_sz.num_strings = i;
130 value->v.multi_sz.strings = (char **)vals;
135 value->v.binary = data_blob_talloc(mem_ctx, data, length);
138 err = WERR_INVALID_PARAM;
150 WERROR registry_push_value(TALLOC_CTX *mem_ctx,
151 const struct registry_value *value,
154 switch (value->type) {
156 case REG_DWORD_BIG_ENDIAN: {
158 SIVAL(buf, 0, value->v.dword);
159 *presult = data_blob_talloc(mem_ctx, (void *)buf, 4);
160 if (presult->data == NULL) {
167 SBVAL(buf, 0, value->v.qword);
168 *presult = data_blob_talloc(mem_ctx, (void *)buf, 8);
169 if (presult->data == NULL) {
175 case REG_EXPAND_SZ: {
176 if (!push_reg_sz(mem_ctx, presult, value->v.sz.str))
183 /* handle the case where we don't get a NULL terminated array */
187 array = talloc_array(mem_ctx, const char *,
188 value->v.multi_sz.num_strings + 1);
193 for (i=0; i < value->v.multi_sz.num_strings; i++) {
194 array[i] = value->v.multi_sz.strings[i];
198 if (!push_reg_multi_sz(mem_ctx, presult, array)) {
206 *presult = data_blob_talloc(mem_ctx,
207 value->v.binary.data,
208 value->v.binary.length);
211 return WERR_INVALID_PARAM;