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/>.
22 WERROR
registry_pull_value(TALLOC_CTX
*mem_ctx
,
23 struct registry_value
**pvalue
,
24 enum winreg_Type type
, uint8
*data
,
25 uint32 size
, uint32 length
)
27 struct registry_value
*value
;
30 if (!(value
= TALLOC_ZERO_P(mem_ctx
, struct registry_value
))) {
38 if ((size
!= 4) || (length
!= 4)) {
39 err
= WERR_INVALID_PARAM
;
42 value
->v
.dword
= IVAL(data
, 0);
48 * Make sure we get a NULL terminated string for
49 * convert_string_talloc().
55 /* win2k regedit gives us a string of 1 byte when
56 * creating a new value of type REG_SZ. this workaround
57 * replaces the input by using the same string as
60 if (!(tmp
= SMB_MALLOC_ARRAY(smb_ucs2_t
, 2))) {
67 else if ((length
% 2) != 0) {
68 err
= WERR_INVALID_PARAM
;
72 uint32 num_ucs2
= length
/ 2;
73 if (!(tmp
= SMB_MALLOC_ARRAY(smb_ucs2_t
, num_ucs2
+1))) {
78 memcpy((void *)tmp
, (const void *)data
, length
);
82 if (length
+ 2 < length
) {
85 err
= WERR_INVALID_PARAM
;
89 value
->v
.sz
.len
= convert_string_talloc(
90 value
, CH_UTF16LE
, CH_UNIX
, tmp
, length
+2,
91 &value
->v
.sz
.str
, False
);
95 if (value
->v
.sz
.len
== (size_t)-1) {
96 err
= WERR_INVALID_PARAM
;
102 err
= reg_pull_multi_sz(value
, (void *)data
, length
,
103 &value
->v
.multi_sz
.num_strings
,
104 &value
->v
.multi_sz
.strings
);
105 if (!(W_ERROR_IS_OK(err
))) {
110 value
->v
.binary
= data_blob_talloc(mem_ctx
, data
, length
);
113 err
= WERR_INVALID_PARAM
;
125 WERROR
registry_push_value(TALLOC_CTX
*mem_ctx
,
126 const struct registry_value
*value
,
129 switch (value
->type
) {
132 SIVAL(buf
, 0, value
->v
.dword
);
133 *presult
= data_blob_talloc(mem_ctx
, (void *)buf
, 4);
134 if (presult
->data
== NULL
) {
140 case REG_EXPAND_SZ
: {
141 presult
->length
= convert_string_talloc(
142 mem_ctx
, CH_UNIX
, CH_UTF16LE
, value
->v
.sz
.str
,
143 MIN(value
->v
.sz
.len
, strlen(value
->v
.sz
.str
)+1),
144 (void *)&(presult
->data
), False
);
145 if (presult
->length
== (size_t)-1) {
151 *presult
= data_blob_talloc(mem_ctx
,
152 value
->v
.binary
.data
,
153 value
->v
.binary
.length
);
156 return WERR_INVALID_PARAM
;