From b381fba0892021f164223bae8b0951014a28735e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 29 Jun 2010 16:13:15 +0200 Subject: s3-registry: avoid using registry_value union. Just pull and push data as is. Guenther --- source3/lib/smbconf/smbconf_reg.c | 68 +++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 20 deletions(-) (limited to 'source3/lib/smbconf/smbconf_reg.c') diff --git a/source3/lib/smbconf/smbconf_reg.c b/source3/lib/smbconf/smbconf_reg.c index 4aa3c09def..08d559b3c7 100644 --- a/source3/lib/smbconf/smbconf_reg.c +++ b/source3/lib/smbconf/smbconf_reg.c @@ -208,8 +208,10 @@ static WERROR smbconf_reg_set_value(struct registry_key *key, ZERO_STRUCT(val); val.type = REG_SZ; - val.v.sz.str = CONST_DISCARD(char *, canon_valstr); - val.v.sz.len = strlen(canon_valstr) + 1; + if (!push_reg_sz(talloc_tos(), &val.data, canon_valstr)) { + werr = WERR_NOMEM; + goto done; + } werr = reg_setvalue(key, canon_valname, &val); if (!W_ERROR_IS_OK(werr)) { @@ -231,31 +233,40 @@ static WERROR smbconf_reg_set_multi_sz_value(struct registry_key *key, struct registry_value *value; uint32_t count; TALLOC_CTX *tmp_ctx = talloc_stackframe(); + const char **array; if (strings == NULL) { werr = WERR_INVALID_PARAM; goto done; } - value = TALLOC_ZERO_P(tmp_ctx, struct registry_value); + array = talloc_zero_array(tmp_ctx, const char *, num_strings + 1); + if (array == NULL) { + werr = WERR_NOMEM; + goto done; + } - value->type = REG_MULTI_SZ; - value->v.multi_sz.num_strings = num_strings; - value->v.multi_sz.strings = TALLOC_ARRAY(tmp_ctx, char *, num_strings); - if (value->v.multi_sz.strings == NULL) { + value = TALLOC_ZERO_P(tmp_ctx, struct registry_value); + if (value == NULL) { werr = WERR_NOMEM; goto done; } + + value->type = REG_MULTI_SZ; + for (count = 0; count < num_strings; count++) { - value->v.multi_sz.strings[count] = - talloc_strdup(value->v.multi_sz.strings, - strings[count]); - if (value->v.multi_sz.strings[count] == NULL) { + array[count] = talloc_strdup(value, strings[count]); + if (array[count] == NULL) { werr = WERR_NOMEM; goto done; } } + if (!push_reg_multi_sz(value, &value->data, array)) { + werr = WERR_NOMEM; + goto done; + } + werr = reg_setvalue(key, valname, value); if (!W_ERROR_IS_OK(werr)) { DEBUG(5, ("Error adding value '%s' to key '%s': %s\n", @@ -286,18 +297,30 @@ static char *smbconf_format_registry_value(TALLOC_CTX *mem_ctx, switch (value->type) { case REG_DWORD: - result = talloc_asprintf(mem_ctx, "%d", value->v.dword); + if (value->data.length >= 4) { + uint32_t v = IVAL(value->data.data, 0); + result = talloc_asprintf(mem_ctx, "%d", v); + } break; case REG_SZ: - case REG_EXPAND_SZ: - result = talloc_asprintf(mem_ctx, "%s", value->v.sz.str); + case REG_EXPAND_SZ: { + const char *s; + if (!pull_reg_sz(mem_ctx, &value->data, &s)) { + break; + } + result = talloc_strdup(mem_ctx, s); break; + } case REG_MULTI_SZ: { uint32 j; - for (j = 0; j < value->v.multi_sz.num_strings; j++) { + const char **a = NULL; + if (!pull_reg_multi_sz(mem_ctx, &value->data, &a)) { + break; + } + for (j = 0; a[j] != NULL; j++) { result = talloc_asprintf(mem_ctx, "%s\"%s\" ", result ? result : "" , - value->v.multi_sz.strings[j]); + a[j]); if (result == NULL) { break; } @@ -306,7 +329,7 @@ static char *smbconf_format_registry_value(TALLOC_CTX *mem_ctx, } case REG_BINARY: result = talloc_asprintf(mem_ctx, "binary (%d bytes)", - (int)value->v.binary.length); + (int)value->data.length); break; default: result = talloc_asprintf(mem_ctx, ""); @@ -324,6 +347,7 @@ static WERROR smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx, uint32_t count; struct registry_value *value = NULL; char **tmp_includes = NULL; + const char **array = NULL; TALLOC_CTX *tmp_ctx = talloc_stackframe(); if (!smbconf_value_exists(key, INCLUDES_VALNAME)) { @@ -344,12 +368,16 @@ static WERROR smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx, goto done; } - for (count = 0; count < value->v.multi_sz.num_strings; count++) - { + if (!pull_reg_multi_sz(tmp_ctx, &value->data, &array)) { + werr = WERR_NOMEM; + goto done; + } + + for (count = 0; array[count] != NULL; count++) { werr = smbconf_add_string_to_array(tmp_ctx, &tmp_includes, count, - value->v.multi_sz.strings[count]); + array[count]); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit