lib: Fix CID 1373389 Uninitialized scalar variable
[metze/samba/wip.git] / source4 / lib / registry / rpc.c
index bc49045ef7ffd4a2f025b211354a26346698da91..d4578480bad48db8f18f78206ebd723a7be00de5 100644 (file)
@@ -285,6 +285,56 @@ static WERROR rpc_get_value_by_name(TALLOC_CTX *mem_ctx,
        return r.out.result;
 }
 
+static WERROR rpc_set_value(struct registry_key *key, const char *value_name,
+                           uint32_t type, const DATA_BLOB data)
+{
+       struct rpc_key *mykeydata = talloc_get_type(key, struct rpc_key);
+       struct winreg_SetValue r;
+       struct winreg_String name;
+       NTSTATUS status;
+
+       name = (struct winreg_String) { .name = value_name };
+
+       ZERO_STRUCT(r);
+       r.in.handle = &mykeydata->pol;
+       r.in.name = name;
+       r.in.type = (enum winreg_Type)type;
+       r.in.data = data.data;
+       r.in.size = data.length;
+
+       status = dcerpc_winreg_SetValue_r(mykeydata->binding_handle, key, &r);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(1, ("SetValue failed - %s\n", nt_errstr(status)));
+               return ntstatus_to_werror(status);
+       }
+
+       return r.out.result;
+}
+
+static WERROR rpc_del_value(TALLOC_CTX *mem_ctx, struct registry_key *key,
+                           const char *value_name)
+{
+       struct rpc_key *mykeydata = talloc_get_type(key, struct rpc_key);
+       struct winreg_DeleteValue r;
+       struct winreg_String name;
+       NTSTATUS status;
+
+       name.name = value_name;
+
+       ZERO_STRUCT(r);
+       r.in.handle = &mykeydata->pol;
+       r.in.value = name;
+
+       status = dcerpc_winreg_DeleteValue_r(mykeydata->binding_handle,
+                                            mem_ctx, &r);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(1, ("DeleteValue failed - %s\n", nt_errstr(status)));
+               return ntstatus_to_werror(status);
+       }
+
+       return r.out.result;
+}
+
 static WERROR rpc_get_subkey_by_index(TALLOC_CTX *mem_ctx,
                                      const struct registry_key *parent,
                                      uint32_t n,
@@ -338,10 +388,19 @@ static WERROR rpc_add_key(TALLOC_CTX *mem_ctx,
 {
        struct winreg_CreateKey r;
        struct rpc_key *parentkd = talloc_get_type(parent, struct rpc_key);
-       struct rpc_key *rpck = talloc(mem_ctx, struct rpc_key);
+       struct rpc_key *rpck = talloc_zero(mem_ctx, struct rpc_key);
        
        NTSTATUS status;
 
+       if (rpck == NULL) {
+               return WERR_NOT_ENOUGH_MEMORY;
+       }
+
+       rpck->key.context = parentkd->key.context;
+       rpck->binding_handle = parentkd->binding_handle;
+       rpck->num_values = -1;
+       rpck->num_subkeys = -1;
+
        ZERO_STRUCT(r);
        r.in.handle = &parentkd->pol;
        r.in.name.name = path;
@@ -470,13 +529,15 @@ static struct registry_operations reg_backend_rpc = {
        .enum_key = rpc_get_subkey_by_index,
        .enum_value = rpc_get_value_by_index,
        .get_value = rpc_get_value_by_name,
+       .set_value = rpc_set_value,
+       .delete_value = rpc_del_value,
        .create_key = rpc_add_key,
        .delete_key = rpc_del_key,
        .get_key_info = rpc_get_info,
-       .get_predefined_key = rpc_get_predefined_key,
 };
 
-_PUBLIC_ WERROR reg_open_remote(struct registry_context **ctx,
+_PUBLIC_ WERROR reg_open_remote(TALLOC_CTX *mem_ctx,
+                               struct registry_context **ctx,
                                struct auth_session_info *session_info,
                                struct cli_credentials *credentials,
                                struct loadparm_context *lp_ctx,
@@ -486,9 +547,9 @@ _PUBLIC_ WERROR reg_open_remote(struct registry_context **ctx,
        struct dcerpc_pipe *p;
        struct rpc_registry_context *rctx;
 
-       dcerpc_init(lp_ctx);
+       dcerpc_init();
 
-       rctx = talloc(NULL, struct rpc_registry_context);
+       rctx = talloc(mem_ctx, struct rpc_registry_context);
        W_ERROR_HAVE_NO_MEMORY(rctx);
 
        /* Default to local smbd if no connection is specified */