s3:registry: move the reg_api prototypes to their own header.
[amitay/samba.git] / source3 / lib / smbconf / smbconf_reg.c
index 6c500785a06ccfa564c33973b176fd302e26516a..f6d6bd7104a387a679816c050a8b741d14b874be 100644 (file)
 #include "includes.h"
 #include "lib/smbconf/smbconf_private.h"
 #include "registry.h"
+#include "registry/reg_api.h"
+#include "registry/reg_backend_db.h"
+#include "registry/reg_util_token.h"
+#include "registry/reg_api_util.h"
 #include "lib/smbconf/smbconf_init.h"
 #include "lib/smbconf/smbconf_reg.h"
 
@@ -206,8 +210,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)) {
@@ -229,31 +235,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",
@@ -284,18 +299,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;
                        }
@@ -304,7 +331,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, "<unprintable>");
@@ -322,6 +349,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)) {
@@ -342,12 +370,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;
                }
@@ -538,7 +570,7 @@ done:
 static WERROR smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
 {
        WERROR werr = WERR_OK;
-       struct nt_user_token *token;
+       struct security_token *token;
 
        if (path == NULL) {
                path = KEY_SMBCONF;
@@ -666,7 +698,7 @@ static WERROR smbconf_reg_drop(struct smbconf_ctx *ctx)
        struct registry_key *new_key = NULL;
        TALLOC_CTX* mem_ctx = talloc_stackframe();
        enum winreg_CreateAction action;
-       struct nt_user_token *token;
+       struct security_token *token;
 
        werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token));
        if (!W_ERROR_IS_OK(werr)) {