summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>2010-03-14 10:30:19 +0100
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>2010-03-14 18:46:22 +0100
commitfbce5ded301a79846356b3809275e10b0a4b6860 (patch)
tree31d4af480c7cc86e0675571182b99da18ad7f63d
parent95bfd17e080e439ab3185a1544c64bbe17067306 (diff)
downloadsamba-fbce5ded301a79846356b3809275e10b0a4b6860.tar.gz
samba-fbce5ded301a79846356b3809275e10b0a4b6860.tar.bz2
samba-fbce5ded301a79846356b3809275e10b0a4b6860.zip
s4:registry - ldb.c - provide a mechansim for storing UTF8/binary REG_SZ/REG_EXPAND_SZ values
We need to support this as gd's WINREG torture test shows.
-rw-r--r--source4/lib/registry/ldb.c46
1 files changed, 39 insertions, 7 deletions
diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c
index 2b77f8f58a..07bc874fb3 100644
--- a/source4/lib/registry/ldb.c
+++ b/source4/lib/registry/ldb.c
@@ -61,9 +61,22 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx,
case REG_SZ:
case REG_EXPAND_SZ:
if (val != NULL) {
- convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16,
- val->data, val->length,
- (void **)&data->data, &data->length, false);
+ if (val->data[0] != '\0') {
+ /* The data should be provided as UTF16 string */
+ convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16,
+ val->data, val->length,
+ (void **)&data->data, &data->length, false);
+ } else {
+ /* Provide a possibility to store also UTF8
+ * REG_SZ/REG_EXPAND_SZ values. This is done
+ * by adding a '\0' in front of the data */
+ data->data = talloc_size(mem_ctx, val->length - 1);
+ if (data->data != NULL) {
+ memcpy(data->data, val->data + 1,
+ val->length - 1);
+ }
+ data->length = val->length - 1;
+ }
} else {
data->data = NULL;
data->length = 0;
@@ -138,10 +151,29 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
return NULL;
}
- ret2 = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8,
- (void *)data.data, data.length,
- (void **)&val->data, &val->length,
- false);
+ if (data.length % 2 == 0) {
+ /* The data is provided as UTF16 string */
+ ret2 = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8,
+ (void *)data.data, data.length,
+ (void **)&val->data, &val->length,
+ false);
+ if (!ret2) {
+ talloc_free(msg);
+ return NULL;
+ }
+ } else {
+ /* Provide a possibility to store also UTF8
+ * REG_SZ/REG_EXPAND_SZ values. This is done
+ * by adding a '\0' in front of the data */
+ val->data = talloc_size(msg, data.length + 1);
+ if (val->data == NULL) {
+ talloc_free(msg);
+ return NULL;
+ }
+ val->data[0] = '\0';
+ memcpy(val->data + 1, data.data, data.length);
+ val->length = data.length + 1;
+ }
ret = ldb_msg_add_value(msg, "data", val, NULL);
} else {
ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);