r25314: Add HKEY_CURRENT_USER to reg_hive_key().
[samba.git] / source3 / utils / net_rpc_registry.c
index f1c046c1817af2490cecb20582a8babaccebb070..64aad1f4dd8d0922de746047fe46d8386341a735 100644 (file)
@@ -6,7 +6,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -15,8 +15,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
  
 #include "includes.h"
 #include "utils/net.h"
@@ -49,6 +48,9 @@ static BOOL reg_hive_key(const char *fullname, uint32 *reg_type,
        else if (strnequal(fullname, "HKU", len) ||
                 strnequal(fullname, "HKEY_USERS", len))
                (*reg_type) = HKEY_USERS;
+       else if (strnequal(fullname, "HKCU", len) ||
+                strnequal(fullname, "HKEY_CURRENT_USER", len))
+               (*reg_type) = HKEY_CURRENT_USER;
        else if (strnequal(fullname, "HKPD", len) ||
                 strnequal(fullname, "HKEY_PERFORMANCE_DATA", len))
                (*reg_type) = HKEY_PERFORMANCE_DATA;
@@ -71,6 +73,8 @@ static NTSTATUS registry_openkey(TALLOC_CTX *mem_ctx,
        NTSTATUS status;
        struct winreg_String key;
 
+       ZERO_STRUCT(key);
+
        if (!reg_hive_key(name, &hive, &key.name)) {
                return NT_STATUS_INVALID_PARAMETER;
        }
@@ -263,7 +267,7 @@ static NTSTATUS registry_enumvalues(TALLOC_CTX *ctx,
                name_buf.size = max_valnamelen + 2;
 
                data_size = max_valbufsize;
-               data = TALLOC(mem_ctx, data_size);
+               data = (uint8 *)TALLOC(mem_ctx, data_size);
                value_length = 0;
 
                status = rpccli_winreg_EnumValue(pipe_hnd, mem_ctx, key_hnd,
@@ -331,6 +335,8 @@ static NTSTATUS registry_setvalue(TALLOC_CTX *mem_ctx,
                return werror_to_ntstatus(err);
        }
 
+       ZERO_STRUCT(name_string);
+
        name_string.name = name;
        result = rpccli_winreg_SetValue(pipe_hnd, blob.data, key_hnd,
                                        name_string, value->type,
@@ -351,7 +357,8 @@ static NTSTATUS rpc_registry_setvalue_internal(const DOM_SID *domain_sid,
        NTSTATUS status;
        struct registry_value value;
 
-       status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_WRITE,
+       status = registry_openkey(mem_ctx, pipe_hnd, argv[0], 
+                                 SEC_RIGHTS_MAXIMUM_ALLOWED,
                                  &hive_hnd, &key_hnd);
        if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "registry_openkey failed: %s\n",
@@ -418,7 +425,10 @@ static NTSTATUS rpc_registry_deletevalue_internal(const DOM_SID *domain_sid,
        NTSTATUS status;
        struct winreg_String valuename;
 
-       status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_WRITE,
+       ZERO_STRUCT(valuename);
+
+       status = registry_openkey(mem_ctx, pipe_hnd, argv[0],
+                                 SEC_RIGHTS_MAXIMUM_ALLOWED,
                                  &hive_hnd, &key_hnd);
        if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "registry_openkey failed: %s\n",
@@ -468,12 +478,15 @@ static NTSTATUS rpc_registry_createkey_internal(const DOM_SID *domain_sid,
        enum winreg_CreateAction action;
        NTSTATUS status;
 
+       ZERO_STRUCT(key);
+       ZERO_STRUCT(keyclass);
+
        if (!reg_hive_key(argv[0], &hive, &key.name)) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
        status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive,
-                                      REG_KEY_READ|REG_KEY_WRITE,
+                                      SEC_RIGHTS_MAXIMUM_ALLOWED,
                                       &hive_hnd);
        if (!(NT_STATUS_IS_OK(status))) {
                return status;
@@ -534,11 +547,14 @@ static NTSTATUS rpc_registry_deletekey_internal(const DOM_SID *domain_sid,
        struct winreg_String key;
        NTSTATUS status;
 
+       ZERO_STRUCT(key);
+
        if (!reg_hive_key(argv[0], &hive, &key.name)) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive, REG_KEY_WRITE,
+       status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive,
+                                      SEC_RIGHTS_MAXIMUM_ALLOWED,
                                       &hive_hnd);
        if (!(NT_STATUS_IS_OK(status))) {
                return status;