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 2 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, write to the Free Software Foundation, Inc., 675
18 * Mass Ave, Cambridge, MA 02139, USA.
23 const char *reg_type_lookup(enum winreg_Type type)
35 result = "REG_EXPAND_SZ";
38 result = "REG_BINARY";
43 case REG_DWORD_BIG_ENDIAN:
44 result = "REG_DWORD_BIG_ENDIAN";
50 result = "REG_MULTI_SZ";
52 case REG_RESOURCE_LIST:
53 result = "REG_RESOURCE_LIST";
55 case REG_FULL_RESOURCE_DESCRIPTOR:
56 result = "REG_FULL_RESOURCE_DESCRIPTOR";
58 case REG_RESOURCE_REQUIREMENTS_LIST:
59 result = "REG_RESOURCE_REQUIREMENTS_LIST";
65 result = "REG TYPE IS UNKNOWN";
71 WERROR reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len,
72 uint32 *num_values, char ***values)
74 const smb_ucs2_t *p = (const smb_ucs2_t *)buf;
78 * Make sure that a talloc context for the strings retrieved exists
81 if (!(*values = TALLOC_ARRAY(mem_ctx, char *, 1))) {
85 len /= 2; /* buf is a set of UCS2 strings */
89 size_t dstlen, thislen;
91 thislen = strnlen_w(p, len) + 1;
92 dstlen = convert_string_allocate(*values, CH_UTF16LE, CH_UNIX,
93 p, thislen*2, (void *)&val,
95 if (dstlen == (size_t)-1) {
100 ADD_TO_ARRAY(*values, char *, val, values, num_values);
101 if (*values == NULL) {
112 WERROR registry_pull_value(TALLOC_CTX *mem_ctx,
113 struct registry_value **pvalue,
114 enum winreg_Type type, uint8 *data,
115 uint32 size, uint32 length)
117 struct registry_value *value;
120 if (!(value = TALLOC_ZERO_P(mem_ctx, struct registry_value))) {
128 if ((size != 4) || (length != 4)) {
129 err = WERR_INVALID_PARAM;
132 value->v.dword = IVAL(data, 0);
138 * Make sure we get a NULL terminated string for
139 * convert_string_talloc().
143 uint32 num_ucs2 = length / 2;
145 if ((length % 2) != 0) {
146 err = WERR_INVALID_PARAM;
150 if (!(tmp = SMB_MALLOC_ARRAY(smb_ucs2_t, num_ucs2+1))) {
155 memcpy((void *)tmp, (const void *)data, length);
158 value->v.sz.len = convert_string_talloc(
159 value, CH_UTF16LE, CH_UNIX, tmp, length+2,
160 &value->v.sz.str, False);
164 if (value->v.sz.len == (size_t)-1) {
165 err = WERR_INVALID_PARAM;
171 err = reg_pull_multi_sz(value, (void *)data, length,
172 &value->v.multi_sz.num_strings,
173 &value->v.multi_sz.strings);
174 if (!(W_ERROR_IS_OK(err))) {
179 value->v.binary.data = talloc_move(value, &data);
180 value->v.binary.length = length;
183 err = WERR_INVALID_PARAM;
195 WERROR registry_push_value(TALLOC_CTX *mem_ctx,
196 const struct registry_value *value,
199 switch (value->type) {
202 SIVAL(buf, 0, value->v.dword);
203 *presult = data_blob_talloc(mem_ctx, (void *)buf, 4);
204 if (presult->data == NULL) {
210 case REG_EXPAND_SZ: {
211 presult->length = convert_string_talloc(
212 mem_ctx, CH_UNIX, CH_UTF16LE, value->v.sz.str,
213 MIN(value->v.sz.len, strlen(value->v.sz.str)+1),
214 (void *)&(presult->data), False);
215 if (presult->length == (size_t)-1) {
221 return WERR_INVALID_PARAM;