diff options
author | Matthias Dieter Wallnöfer <mwallnoefer@yahoo.de> | 2010-03-14 17:18:29 +0100 |
---|---|---|
committer | Matthias Dieter Wallnöfer <mwallnoefer@yahoo.de> | 2010-03-14 18:46:22 +0100 |
commit | bb1ac0c75c2f42dff972bae36b3814e5ad1142f9 (patch) | |
tree | 5512ee63f182f04ff7987784b22234295a0c9753 /source4/lib | |
parent | fbce5ded301a79846356b3809275e10b0a4b6860 (diff) | |
download | samba-bb1ac0c75c2f42dff972bae36b3814e5ad1142f9.tar.gz samba-bb1ac0c75c2f42dff972bae36b3814e5ad1142f9.tar.bz2 samba-bb1ac0c75c2f42dff972bae36b3814e5ad1142f9.zip |
s4:registry - ldb.c - provide a mechanism for storing UTF8/binary REG_DWORD values
We need to support this as gd's WINREG torture test shows.
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/registry/ldb.c | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c index 07bc874fb3..9e77f1f6d5 100644 --- a/source4/lib/registry/ldb.c +++ b/source4/lib/registry/ldb.c @@ -85,12 +85,25 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, case REG_DWORD: if (val != NULL) { - uint32_t tmp = strtoul((char *)val->data, NULL, 0); - data->data = talloc_size(mem_ctx, sizeof(uint32_t) + 1); - if (data->data != NULL) { - SIVAL(data->data, 0, tmp); + if (val->data[0] != '\0') { + /* The data is a plain DWORD */ + uint32_t tmp = strtoul((char *)val->data, NULL, 0); + data->data = talloc_size(mem_ctx, sizeof(uint32_t) + 1); + if (data->data != NULL) { + SIVAL(data->data, 0, tmp); + } + data->length = sizeof(uint32_t); + } else { + /* Provide a possibility to store also UTF8 + * REG_DWORD 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; } - data->length = sizeof(uint32_t); } else { data->data = NULL; data->length = 0; @@ -182,15 +195,37 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx, case REG_DWORD: if ((data.length > 0) && (data.data != NULL)) { - char *conv_str; + if (data.length == sizeof(uint32_t)) { + char *conv_str; - conv_str = talloc_asprintf(msg, "0x%x", IVAL(data.data, 0)); - if (conv_str == NULL) { - talloc_free(msg); - return NULL; - } + conv_str = talloc_asprintf(msg, "0x%x", IVAL(data.data, 0)); + if (conv_str == NULL) { + talloc_free(msg); + return NULL; + } + ret = ldb_msg_add_string(msg, "data", conv_str); + } else { + /* Provide a possibility to store also UTF8 + * REG_DWORD values. This is done by adding a + * '\0' in front of the data */ + struct ldb_val *val; + + val = talloc_zero(msg, struct ldb_val); + if (val == NULL) { + talloc_free(msg); + return NULL; + } - ret = ldb_msg_add_string(msg, "data", conv_str); + 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); } |