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/>.
21 #include "../librpc/gen_ndr/ndr_winreg.h"
24 #define DBGC_CLASS DBGC_REGISTRY
26 extern REGISTRY_OPS smbconf_reg_ops
;
28 const char *reg_type_lookup(enum winreg_Type type
)
40 result
= "REG_EXPAND_SZ";
43 result
= "REG_BINARY";
48 case REG_DWORD_BIG_ENDIAN
:
49 result
= "REG_DWORD_BIG_ENDIAN";
55 result
= "REG_MULTI_SZ";
57 case REG_RESOURCE_LIST
:
58 result
= "REG_RESOURCE_LIST";
60 case REG_FULL_RESOURCE_DESCRIPTOR
:
61 result
= "REG_FULL_RESOURCE_DESCRIPTOR";
63 case REG_RESOURCE_REQUIREMENTS_LIST
:
64 result
= "REG_RESOURCE_REQUIREMENTS_LIST";
70 result
= "REG TYPE IS UNKNOWN";
76 WERROR
reg_pull_multi_sz(TALLOC_CTX
*mem_ctx
, const void *buf
, size_t len
,
77 uint32
*num_values
, char ***values
)
79 const smb_ucs2_t
*p
= (const smb_ucs2_t
*)buf
;
83 * Make sure that a talloc context for the strings retrieved exists
86 if (!(*values
= TALLOC_ARRAY(mem_ctx
, char *, 1))) {
90 len
/= 2; /* buf is a set of UCS2 strings */
94 size_t dstlen
, thislen
;
96 thislen
= strnlen_w(p
, len
) + 1;
97 if (!convert_string_allocate(*values
, CH_UTF16LE
, CH_UNIX
,
98 p
, thislen
*2, (void *)&val
, &dstlen
, true)) {
103 ADD_TO_ARRAY(*values
, char *, val
, values
, num_values
);
104 if (*values
== NULL
) {
115 /*******************************************************************
116 push a string in unix charset into a REG_SZ UCS2 null terminated blob
117 ********************************************************************/
119 bool push_reg_sz(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*blob
, const char *s
)
121 union winreg_Data data
;
122 enum ndr_err_code ndr_err
;
124 ndr_err
= ndr_push_union_blob(blob
, mem_ctx
, NULL
, &data
, REG_SZ
,
125 (ndr_push_flags_fn_t
)ndr_push_winreg_Data
);
126 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
129 /*******************************************************************
130 push a string_array in unix charset into a REG_MULTI_SZ UCS2 double-null
132 ********************************************************************/
134 bool push_reg_multi_sz(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*blob
, const char **a
)
136 union winreg_Data data
;
137 enum ndr_err_code ndr_err
;
138 data
.string_array
= a
;
139 ndr_err
= ndr_push_union_blob(blob
, mem_ctx
, NULL
, &data
, REG_MULTI_SZ
,
140 (ndr_push_flags_fn_t
)ndr_push_winreg_Data
);
141 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
144 /*******************************************************************
145 pull a string in unix charset out of a REG_SZ UCS2 null terminated blob
146 ********************************************************************/
148 bool pull_reg_sz(TALLOC_CTX
*mem_ctx
, const DATA_BLOB
*blob
, const char **s
)
150 union winreg_Data data
;
151 enum ndr_err_code ndr_err
;
152 ndr_err
= ndr_pull_union_blob(blob
, mem_ctx
, NULL
, &data
, REG_SZ
,
153 (ndr_pull_flags_fn_t
)ndr_pull_winreg_Data
);
154 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
161 /*******************************************************************
162 pull a string_array in unix charset out of a REG_MULTI_SZ UCS2 double-null
164 ********************************************************************/
166 bool pull_reg_multi_sz(TALLOC_CTX
*mem_ctx
, const DATA_BLOB
*blob
, const char ***a
)
168 union winreg_Data data
;
169 enum ndr_err_code ndr_err
;
170 ndr_err
= ndr_pull_union_blob(blob
, mem_ctx
, NULL
, &data
, REG_MULTI_SZ
,
171 (ndr_pull_flags_fn_t
)ndr_pull_winreg_Data
);
172 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
175 *a
= data
.string_array
;