s3-registry: avoid using registry_value union.
[nivanova/samba-autobuild/.git] / source3 / utils / net_rpc_registry.c
index 005e3ca556085c831f543c07f6d7d00ad9090000..9fec13b371f7f5a7d78eb9894d8855055ef80b4e 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
  
 #include "includes.h"
+#include "registry.h"
 #include "utils/net.h"
 #include "utils/net_registry_util.h"
 #include "regfio.h"
-#include "reg_objects.h"
+#include "../librpc/gen_ndr/cli_winreg.h"
+#include "registry/reg_util_marshalling.h"
+#include "registry/reg_objects.h"
+#include "../librpc/gen_ndr/ndr_security.h"
+
+/*******************************************************************
+ connect to a registry hive root (open a registry policy)
+*******************************************************************/
+
+static NTSTATUS rpccli_winreg_Connect(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
+                                     uint32_t reg_type, uint32_t access_mask,
+                                     struct policy_handle *reg_hnd)
+{
+       ZERO_STRUCTP(reg_hnd);
+
+       switch (reg_type)
+       {
+       case HKEY_CLASSES_ROOT:
+               return rpccli_winreg_OpenHKCR( cli, mem_ctx, NULL,
+                       access_mask, reg_hnd, NULL);
+
+       case HKEY_LOCAL_MACHINE:
+               return rpccli_winreg_OpenHKLM( cli, mem_ctx, NULL,
+                       access_mask, reg_hnd, NULL);
+
+       case HKEY_USERS:
+               return rpccli_winreg_OpenHKU( cli, mem_ctx, NULL,
+                       access_mask, reg_hnd, NULL);
+
+       case HKEY_CURRENT_USER:
+               return rpccli_winreg_OpenHKCU( cli, mem_ctx, NULL,
+                       access_mask, reg_hnd, NULL);
+
+       case HKEY_PERFORMANCE_DATA:
+               return rpccli_winreg_OpenHKPD( cli, mem_ctx, NULL,
+                       access_mask, reg_hnd, NULL);
+
+       default:
+               /* fall through to end of function */
+               break;
+       }
+
+       return NT_STATUS_INVALID_PARAMETER;
+}
 
 static bool reg_hive_key(TALLOC_CTX *ctx, const char *fullname,
                         uint32 *reg_type, const char **key_name)
@@ -308,12 +352,14 @@ static NTSTATUS registry_enumvalues(TALLOC_CTX *ctx,
                        goto error;
                }
 
-               err = registry_pull_value(values, &values[i], type, data,
-                                         data_size, value_length);
-               if (!W_ERROR_IS_OK(err)) {
-                       status = werror_to_ntstatus(err);
+               values[i] = talloc_zero(values, struct registry_value);
+               if (values[i] == NULL) {
+                       status = NT_STATUS_NO_MEMORY;
                        goto error;
                }
+
+               values[i]->type = type;
+               values[i]->data = data_blob_talloc(values[i], data, data_size);
        }
 
        *pnum_values = num_values;
@@ -350,27 +396,19 @@ static NTSTATUS registry_setvalue(TALLOC_CTX *mem_ctx,
                                  const struct registry_value *value)
 {
        struct winreg_String name_string;
-       DATA_BLOB blob;
        NTSTATUS result;
-       WERROR err;
-
-       err = registry_push_value(mem_ctx, value, &blob);
-       if (!W_ERROR_IS_OK(err)) {
-               return werror_to_ntstatus(err);
-       }
 
        ZERO_STRUCT(name_string);
 
        name_string.name = name;
-       result = rpccli_winreg_SetValue(pipe_hnd, blob.data, key_hnd,
+       result = rpccli_winreg_SetValue(pipe_hnd, mem_ctx, key_hnd,
                                        name_string, value->type,
-                                       blob.data, blob.length, NULL);
-       TALLOC_FREE(blob.data);
+                                       value->data.data, value->data.length, NULL);
        return result;
 }
 
 static NTSTATUS rpc_registry_setvalue_internal(struct net_context *c,
-                                              const DOM_SID *domain_sid,
+                                              const struct dom_sid *domain_sid,
                                               const char *domain_name,
                                               struct cli_state *cli,
                                               struct rpc_pipe_client *pipe_hnd,
@@ -383,30 +421,34 @@ static NTSTATUS rpc_registry_setvalue_internal(struct net_context *c,
        struct registry_value value;
 
        status = registry_openkey(mem_ctx, pipe_hnd, argv[0],
-                                 SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                 SEC_FLAG_MAXIMUM_ALLOWED,
                                  &hive_hnd, &key_hnd);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "registry_openkey failed: %s\n",
+               d_fprintf(stderr, _("registry_openkey failed: %s\n"),
                          nt_errstr(status));
                return status;
        }
 
        if (!strequal(argv[2], "multi_sz") && (argc != 4)) {
-               d_fprintf(stderr, "Too many args for type %s\n", argv[2]);
+               d_fprintf(stderr, _("Too many args for type %s\n"), argv[2]);
                return NT_STATUS_NOT_IMPLEMENTED;
        }
 
        if (strequal(argv[2], "dword")) {
+               uint32_t v = strtoul(argv[3], NULL, 10);
                value.type = REG_DWORD;
-               value.v.dword = strtoul(argv[3], NULL, 10);
+               value.data = data_blob_talloc(mem_ctx, NULL, 4);
+               SIVAL(value.data.data, 0, v);
        }
        else if (strequal(argv[2], "sz")) {
                value.type = REG_SZ;
-               value.v.sz.len = strlen(argv[3])+1;
-               value.v.sz.str = CONST_DISCARD(char *, argv[3]);
+               if (!push_reg_sz(mem_ctx, &value.data, argv[3])) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto error;
+               }
        }
        else {
-               d_fprintf(stderr, "type \"%s\" not implemented\n", argv[2]);
+               d_fprintf(stderr, _("type \"%s\" not implemented\n"), argv[2]);
                status = NT_STATUS_NOT_IMPLEMENTED;
                goto error;
        }
@@ -415,7 +457,7 @@ static NTSTATUS rpc_registry_setvalue_internal(struct net_context *c,
                                   argv[1], &value);
 
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "registry_setvalue failed: %s\n",
+               d_fprintf(stderr, _("registry_setvalue failed: %s\n"),
                          nt_errstr(status));
        }
 
@@ -430,8 +472,10 @@ static int rpc_registry_setvalue(struct net_context *c, int argc,
                                 const char **argv )
 {
        if (argc < 4 || c->display_usage) {
-               d_fprintf(stderr, "usage: net rpc registry setvalue <key> "
-                         "<valuename> <type> [<val>]+\n");
+               d_fprintf(stderr, "%s\n%s",
+                         _("Usage:"),
+                         _("net rpc registry setvalue <key> <valuename> "
+                           "<type> [<val>]+\n"));
                return -1;
        }
 
@@ -440,7 +484,7 @@ static int rpc_registry_setvalue(struct net_context *c, int argc,
 }
 
 static NTSTATUS rpc_registry_deletevalue_internal(struct net_context *c,
-                                                 const DOM_SID *domain_sid,
+                                                 const struct dom_sid *domain_sid,
                                                  const char *domain_name,
                                                  struct cli_state *cli,
                                                  struct rpc_pipe_client *pipe_hnd,
@@ -455,10 +499,10 @@ static NTSTATUS rpc_registry_deletevalue_internal(struct net_context *c,
        ZERO_STRUCT(valuename);
 
        status = registry_openkey(mem_ctx, pipe_hnd, argv[0],
-                                 SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                 SEC_FLAG_MAXIMUM_ALLOWED,
                                  &hive_hnd, &key_hnd);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "registry_openkey failed: %s\n",
+               d_fprintf(stderr, _("registry_openkey failed: %s\n"),
                          nt_errstr(status));
                return status;
        }
@@ -469,7 +513,7 @@ static NTSTATUS rpc_registry_deletevalue_internal(struct net_context *c,
                                           valuename, NULL);
 
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "registry_deletevalue failed: %s\n",
+               d_fprintf(stderr, _("registry_deletevalue failed: %s\n"),
                          nt_errstr(status));
        }
 
@@ -483,8 +527,9 @@ static int rpc_registry_deletevalue(struct net_context *c, int argc,
                                    const char **argv )
 {
        if (argc != 2 || c->display_usage) {
-               d_fprintf(stderr, "usage: net rpc registry deletevalue <key> "
-                         "<valuename>\n");
+               d_fprintf(stderr, "%s\n%s",
+                         _("Usage:"),
+                         _("net rpc registry deletevalue <key> <valuename>\n"));
                return -1;
        }
 
@@ -493,7 +538,7 @@ static int rpc_registry_deletevalue(struct net_context *c, int argc,
 }
 
 static NTSTATUS rpc_registry_getvalue_internal(struct net_context *c,
-                                              const DOM_SID *domain_sid,
+                                              const struct dom_sid *domain_sid,
                                               const char *domain_name,
                                               struct cli_state *cli,
                                               struct rpc_pipe_client *pipe_hnd,
@@ -504,11 +549,9 @@ static NTSTATUS rpc_registry_getvalue_internal(struct net_context *c,
 {
        struct policy_handle hive_hnd, key_hnd;
        NTSTATUS status;
-       WERROR werr;
        struct winreg_String valuename;
        struct registry_value *value = NULL;
        enum winreg_Type type = REG_NONE;
-       uint8_t *data = NULL;
        uint32_t data_size = 0;
        uint32_t value_length = 0;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
@@ -516,16 +559,21 @@ static NTSTATUS rpc_registry_getvalue_internal(struct net_context *c,
        ZERO_STRUCT(valuename);
 
        status = registry_openkey(tmp_ctx, pipe_hnd, argv[0],
-                                 SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                 SEC_FLAG_MAXIMUM_ALLOWED,
                                  &hive_hnd, &key_hnd);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "registry_openkey failed: %s\n",
+               d_fprintf(stderr, _("registry_openkey failed: %s\n"),
                          nt_errstr(status));
                return status;
        }
 
        valuename.name = argv[1];
 
+       value = talloc_zero(tmp_ctx, struct registry_value);
+       if (value == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
        /*
         * call QueryValue once with data == NULL to get the
         * needed memory size to be allocated, then allocate
@@ -534,41 +582,33 @@ static NTSTATUS rpc_registry_getvalue_internal(struct net_context *c,
        status = rpccli_winreg_QueryValue(pipe_hnd, tmp_ctx, &key_hnd,
                                          &valuename,
                                          &type,
-                                         data,
+                                         NULL,
                                          &data_size,
                                          &value_length,
                                          NULL);
 
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "registry_queryvalue failed: %s\n",
+               d_fprintf(stderr, _("registry_queryvalue failed: %s\n"),
                          nt_errstr(status));
                goto done;
        }
 
-       data = (uint8 *)TALLOC(tmp_ctx, data_size);
-       value_length = 0;
+       value->data = data_blob_talloc(tmp_ctx, NULL, data_size);
 
        status = rpccli_winreg_QueryValue(pipe_hnd, tmp_ctx, &key_hnd,
                                          &valuename,
                                          &type,
-                                         data,
+                                         value->data.data,
                                          &data_size,
                                          &value_length,
                                          NULL);
 
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "registry_queryvalue failed: %s\n",
+               d_fprintf(stderr, _("registry_queryvalue failed: %s\n"),
                          nt_errstr(status));
                goto done;
        }
 
-       werr = registry_pull_value(tmp_ctx, &value, type, data,
-                                  data_size, value_length);
-       if (!W_ERROR_IS_OK(werr)) {
-               status = werror_to_ntstatus(werr);
-               goto done;
-       }
-
        print_registry_value(value, raw);
 
 done:
@@ -581,7 +621,7 @@ done:
 }
 
 static NTSTATUS rpc_registry_getvalue_full(struct net_context *c,
-                                          const DOM_SID *domain_sid,
+                                          const struct dom_sid *domain_sid,
                                           const char *domain_name,
                                           struct cli_state *cli,
                                           struct rpc_pipe_client *pipe_hnd,
@@ -598,8 +638,9 @@ static int rpc_registry_getvalue(struct net_context *c, int argc,
                                 const char **argv)
 {
        if (argc != 2 || c->display_usage) {
-               d_fprintf(stderr, "usage: net rpc registry getvalue <key> "
-                         "<valuename>\n");
+               d_fprintf(stderr, "%s\n%s",
+                         _("Usage:"),
+                         _("net rpc registry getvalue <key> <valuename>\n"));
                return -1;
        }
 
@@ -608,7 +649,7 @@ static int rpc_registry_getvalue(struct net_context *c, int argc,
 }
 
 static NTSTATUS rpc_registry_getvalue_raw(struct net_context *c,
-                                         const DOM_SID *domain_sid,
+                                         const struct dom_sid *domain_sid,
                                          const char *domain_name,
                                          struct cli_state *cli,
                                          struct rpc_pipe_client *pipe_hnd,
@@ -625,8 +666,9 @@ static int rpc_registry_getvalueraw(struct net_context *c, int argc,
                                    const char **argv)
 {
        if (argc != 2 || c->display_usage) {
-               d_fprintf(stderr, "usage: net rpc registry getvalue <key> "
-                         "<valuename>\n");
+               d_fprintf(stderr, "%s\n%s",
+                         _("Usage:"),
+                         _("net rpc registry getvalue <key> <valuename>\n"));
                return -1;
        }
 
@@ -635,7 +677,7 @@ static int rpc_registry_getvalueraw(struct net_context *c, int argc,
 }
 
 static NTSTATUS rpc_registry_createkey_internal(struct net_context *c,
-                                               const DOM_SID *domain_sid,
+                                               const struct dom_sid *domain_sid,
                                                const char *domain_name,
                                                struct cli_state *cli,
                                                struct rpc_pipe_client *pipe_hnd,
@@ -657,7 +699,7 @@ static NTSTATUS rpc_registry_createkey_internal(struct net_context *c,
        }
 
        status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive,
-                                      SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                      SEC_FLAG_MAXIMUM_ALLOWED,
                                       &hive_hnd);
        if (!(NT_STATUS_IS_OK(status))) {
                return status;
@@ -670,7 +712,7 @@ static NTSTATUS rpc_registry_createkey_internal(struct net_context *c,
                                         keyclass, 0, REG_KEY_READ, NULL,
                                         &key_hnd, &action, NULL);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "createkey returned %s\n",
+               d_fprintf(stderr, _("createkey returned %s\n"),
                          nt_errstr(status));
                rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd, NULL);
                return status;
@@ -678,13 +720,13 @@ static NTSTATUS rpc_registry_createkey_internal(struct net_context *c,
 
        switch (action) {
                case REG_ACTION_NONE:
-                       d_printf("createkey did nothing -- huh?\n");
+                       d_printf(_("createkey did nothing -- huh?\n"));
                        break;
                case REG_CREATED_NEW_KEY:
-                       d_printf("createkey created %s\n", argv[0]);
+                       d_printf(_("createkey created %s\n"), argv[0]);
                        break;
                case REG_OPENED_EXISTING_KEY:
-                       d_printf("createkey opened existing %s\n", argv[0]);
+                       d_printf(_("createkey opened existing %s\n"), argv[0]);
                        break;
        }
 
@@ -698,7 +740,9 @@ static int rpc_registry_createkey(struct net_context *c, int argc,
                                  const char **argv )
 {
        if (argc != 1 || c->display_usage) {
-               d_fprintf(stderr, "usage: net rpc registry createkey <key>\n");
+               d_fprintf(stderr, "%s\n%s",
+                         _("Usage:"),
+                         _("net rpc registry createkey <key>\n"));
                return -1;
        }
 
@@ -707,7 +751,7 @@ static int rpc_registry_createkey(struct net_context *c, int argc,
 }
 
 static NTSTATUS rpc_registry_deletekey_internal(struct net_context *c,
-                                               const DOM_SID *domain_sid,
+                                               const struct dom_sid *domain_sid,
                                                const char *domain_name,
                                                struct cli_state *cli,
                                                struct rpc_pipe_client *pipe_hnd,
@@ -727,7 +771,7 @@ static NTSTATUS rpc_registry_deletekey_internal(struct net_context *c,
        }
 
        status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive,
-                                      SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                      SEC_FLAG_MAXIMUM_ALLOWED,
                                       &hive_hnd);
        if (!(NT_STATUS_IS_OK(status))) {
                return status;
@@ -737,7 +781,7 @@ static NTSTATUS rpc_registry_deletekey_internal(struct net_context *c,
        rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd, NULL);
 
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "deletekey returned %s\n",
+               d_fprintf(stderr, _("deletekey returned %s\n"),
                          nt_errstr(status));
        }
 
@@ -747,7 +791,9 @@ static NTSTATUS rpc_registry_deletekey_internal(struct net_context *c,
 static int rpc_registry_deletekey(struct net_context *c, int argc, const char **argv )
 {
        if (argc != 1 || c->display_usage) {
-               d_fprintf(stderr, "usage: net rpc registry deletekey <key>\n");
+               d_fprintf(stderr, "%s\n%s",
+                         _("Usage:"),
+                         _("net rpc registry deletekey <key>\n"));
                return -1;
        }
 
@@ -759,7 +805,7 @@ static int rpc_registry_deletekey(struct net_context *c, int argc, const char **
 ********************************************************************/
 
 static NTSTATUS rpc_registry_enumerate_internal(struct net_context *c,
-                                               const DOM_SID *domain_sid,
+                                               const struct dom_sid *domain_sid,
                                                const char *domain_name,
                                                struct cli_state *cli,
                                                struct rpc_pipe_client *pipe_hnd,
@@ -767,7 +813,7 @@ static NTSTATUS rpc_registry_enumerate_internal(struct net_context *c,
                                                int argc,
                                                const char **argv )
 {
-       POLICY_HND pol_hive, pol_key;
+       struct policy_handle pol_hive, pol_key;
        NTSTATUS status;
        uint32 num_subkeys = 0;
        uint32 num_values = 0;
@@ -777,15 +823,18 @@ static NTSTATUS rpc_registry_enumerate_internal(struct net_context *c,
        struct registry_value **values = NULL;
 
        if (argc != 1 || c->display_usage) {
-               d_printf("Usage:    net rpc registry enumerate <path>\n");
-               d_printf("Example:  net rpc registry enumerate 'HKLM\\Software\\Samba'\n");
+               d_printf("%s\n%s",
+                        _("Usage:"),
+                        _("net rpc registry enumerate <path>\n"));
+               d_printf("%s  net rpc registry enumerate "
+                        "'HKLM\\Software\\Samba'\n", _("Example:"));
                return NT_STATUS_INVALID_PARAMETER;
        }
 
        status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_READ,
                                  &pol_hive, &pol_key);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "registry_openkey failed: %s\n",
+               d_fprintf(stderr, _("registry_openkey failed: %s\n"),
                          nt_errstr(status));
                return status;
        }
@@ -793,7 +842,7 @@ static NTSTATUS rpc_registry_enumerate_internal(struct net_context *c,
        status = registry_enumkeys(mem_ctx, pipe_hnd, &pol_key, &num_subkeys,
                                   &names, &classes, &modtimes);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "enumerating keys failed: %s\n",
+               d_fprintf(stderr, _("enumerating keys failed: %s\n"),
                          nt_errstr(status));
                return status;
        }
@@ -805,7 +854,7 @@ static NTSTATUS rpc_registry_enumerate_internal(struct net_context *c,
        status = registry_enumvalues(mem_ctx, pipe_hnd, &pol_key, &num_values,
                                     &names, &values);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "enumerating values failed: %s\n",
+               d_fprintf(stderr, _("enumerating values failed: %s\n"),
                          nt_errstr(status));
                return status;
        }
@@ -834,7 +883,7 @@ static int rpc_registry_enumerate(struct net_context *c, int argc,
 ********************************************************************/
 
 static NTSTATUS rpc_registry_save_internal(struct net_context *c,
-                                       const DOM_SID *domain_sid,
+                                       const struct dom_sid *domain_sid,
                                        const char *domain_name,
                                        struct cli_state *cli,
                                        struct rpc_pipe_client *pipe_hnd,
@@ -843,19 +892,21 @@ static NTSTATUS rpc_registry_save_internal(struct net_context *c,
                                        const char **argv )
 {
        WERROR result = WERR_GENERAL_FAILURE;
-       POLICY_HND pol_hive, pol_key;
+       struct policy_handle pol_hive, pol_key;
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
        struct winreg_String filename;
 
        if (argc != 2 || c->display_usage) {
-               d_printf("Usage:    net rpc registry backup <path> <file> \n");
+               d_printf("%s\n%s",
+                        _("Usage:"),
+                        _("net rpc registry backup <path> <file> \n"));
                return NT_STATUS_INVALID_PARAMETER;
        }
 
        status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_ALL,
                                  &pol_hive, &pol_key);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "registry_openkey failed: %s\n",
+               d_fprintf(stderr, _("registry_openkey failed: %s\n"),
                          nt_errstr(status));
                return status;
        }
@@ -863,7 +914,8 @@ static NTSTATUS rpc_registry_save_internal(struct net_context *c,
        filename.name = argv[1];
        status = rpccli_winreg_SaveKey( pipe_hnd, mem_ctx, &pol_key, &filename, NULL, NULL);
        if ( !W_ERROR_IS_OK(result) ) {
-               d_fprintf(stderr, "Unable to save [%s] to %s:%s\n", argv[0], cli->desthost, argv[1]);
+               d_fprintf(stderr, _("Unable to save [%s] to %s:%s\n"), argv[0],
+                         cli->desthost, argv[1]);
        }
 
        /* cleanup */
@@ -890,24 +942,22 @@ static int rpc_registry_save(struct net_context *c, int argc, const char **argv
 static void dump_values( REGF_NK_REC *nk )
 {
        int i, j;
-       char *data_str = NULL;
+       const char *data_str = NULL;
        uint32 data_size, data;
+       DATA_BLOB blob;
 
        if ( !nk->values )
                return;
 
        for ( i=0; i<nk->num_values; i++ ) {
                d_printf( "\"%s\" = ", nk->values[i].valuename ? nk->values[i].valuename : "(default)" );
-               d_printf( "(%s) ", reg_type_lookup( nk->values[i].type ) );
+               d_printf( "(%s) ", str_regtype( nk->values[i].type ) );
 
                data_size = nk->values[i].data_size & ~VK_DATA_IN_OFFSET;
                switch ( nk->values[i].type ) {
                        case REG_SZ:
-                               rpcstr_pull_talloc(talloc_tos(),
-                                               &data_str,
-                                               nk->values[i].data,
-                                               -1,
-                                               STR_TERMINATE);
+                               blob = data_blob_const(nk->values[i].data, data_size);
+                               pull_reg_sz(talloc_tos(), &blob, &data_str);
                                if (!data_str) {
                                        break;
                                }
@@ -929,7 +979,7 @@ static void dump_values( REGF_NK_REC *nk )
                                }
                                break;
                        default:
-                               d_printf("unknown");
+                               d_printf(_("unknown"));
                                break;
                }
 
@@ -970,30 +1020,34 @@ static bool write_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
                                 const char *parentpath )
 {
        REGF_NK_REC *key, *subkey;
-       REGVAL_CTR *values = NULL;
-       REGSUBKEY_CTR *subkeys = NULL;
+       struct regval_ctr *values = NULL;
+       struct regsubkey_ctr *subkeys = NULL;
        int i;
        char *path = NULL;
+       WERROR werr;
 
-       if ( !( subkeys = TALLOC_ZERO_P( infile->mem_ctx, REGSUBKEY_CTR )) ) {
-               DEBUG(0,("write_registry_tree: talloc() failed!\n"));
+       werr = regsubkey_ctr_init(infile->mem_ctx, &subkeys);
+       if (!W_ERROR_IS_OK(werr)) {
+               DEBUG(0, ("write_registry_tree: regsubkey_ctr_init failed: "
+                         "%s\n", win_errstr(werr)));
                return false;
        }
 
-       if ( !(values = TALLOC_ZERO_P( subkeys, REGVAL_CTR )) ) {
+       werr = regval_ctr_init(subkeys, &values);
+       if (!W_ERROR_IS_OK(werr)) {
                DEBUG(0,("write_registry_tree: talloc() failed!\n"));
                TALLOC_FREE(subkeys);
                return false;
        }
 
-       /* copy values into the REGVAL_CTR */
+       /* copy values into the struct regval_ctr */
 
        for ( i=0; i<nk->num_values; i++ ) {
                regval_ctr_addvalue( values, nk->values[i].valuename, nk->values[i].type,
-                       (const char *)nk->values[i].data, (nk->values[i].data_size & ~VK_DATA_IN_OFFSET) );
+                       nk->values[i].data, (nk->values[i].data_size & ~VK_DATA_IN_OFFSET) );
        }
 
-       /* copy subkeys into the REGSUBKEY_CTR */
+       /* copy subkeys into the struct regsubkey_ctr */
 
        while ( (subkey = regfio_fetch_subkey( infile, nk )) ) {
                regsubkey_ctr_addkey( subkeys, subkey->keyname );
@@ -1033,21 +1087,23 @@ static int rpc_registry_dump(struct net_context *c, int argc, const char **argv)
        REGF_NK_REC *nk;
 
        if (argc != 1 || c->display_usage) {
-               d_printf("Usage:    net rpc registry dump <file> \n");
+               d_printf("%s\n%s",
+                        _("Usage:"),
+                        _("net rpc registry dump <file> \n"));
                return -1;
        }
 
-       d_printf("Opening %s....", argv[0]);
+       d_printf(_("Opening %s...."), argv[0]);
        if ( !(registry = regfio_open( argv[0], O_RDONLY, 0)) ) {
-               d_fprintf(stderr, "Failed to open %s for reading\n", argv[0]);
+               d_fprintf(stderr, _("Failed to open %s for reading\n"),argv[0]);
                return 1;
        }
-       d_printf("ok\n");
+       d_printf(_("ok\n"));
 
        /* get the root of the registry file */
 
        if ((nk = regfio_rootkey( registry )) == NULL) {
-               d_fprintf(stderr, "Could not get rootkey\n");
+               d_fprintf(stderr, _("Could not get rootkey\n"));
                regfio_close( registry );
                return 1;
        }
@@ -1060,9 +1116,9 @@ static int rpc_registry_dump(struct net_context *c, int argc, const char **argv)
 #if 0
        talloc_report_full( registry->mem_ctx, stderr );
 #endif
-       d_printf("Closing registry...");
+       d_printf(_("Closing registry..."));
        regfio_close( registry );
-       d_printf("ok\n");
+       d_printf(_("ok\n"));
 
        return 0;
 }
@@ -1077,31 +1133,33 @@ static int rpc_registry_copy(struct net_context *c, int argc, const char **argv
        int result = 1;
 
        if (argc != 2 || c->display_usage) {
-               d_printf("Usage:    net rpc registry copy <srcfile> <newfile>\n");
+               d_printf("%s\n%s",
+                        _("Usage:"),
+                        _("net rpc registry copy <srcfile> <newfile>\n"));
                return -1;
        }
 
-       d_printf("Opening %s....", argv[0]);
+       d_printf(_("Opening %s...."), argv[0]);
        if ( !(infile = regfio_open( argv[0], O_RDONLY, 0 )) ) {
-               d_fprintf(stderr, "Failed to open %s for reading\n", argv[0]);
+               d_fprintf(stderr, _("Failed to open %s for reading\n"),argv[0]);
                return 1;
        }
-       d_printf("ok\n");
+       d_printf(_("ok\n"));
 
-       d_printf("Opening %s....", argv[1]);
+       d_printf(_("Opening %s...."), argv[1]);
        if ( !(outfile = regfio_open( argv[1], (O_RDWR|O_CREAT|O_TRUNC), (S_IREAD|S_IWRITE) )) ) {
-               d_fprintf(stderr, "Failed to open %s for writing\n", argv[1]);
+               d_fprintf(stderr, _("Failed to open %s for writing\n"),argv[1]);
                goto out;
        }
-       d_printf("ok\n");
+       d_printf(_("ok\n"));
 
        /* get the root of the registry file */
 
        if ((nk = regfio_rootkey( infile )) == NULL) {
-               d_fprintf(stderr, "Could not get rootkey\n");
+               d_fprintf(stderr, _("Could not get rootkey\n"));
                goto out;
        }
-       d_printf("RootKey: [%s]\n", nk->keyname);
+       d_printf(_("RootKey: [%s]\n"), nk->keyname);
 
        write_registry_tree( infile, nk, NULL, outfile, "" );
 
@@ -1109,17 +1167,17 @@ static int rpc_registry_copy(struct net_context *c, int argc, const char **argv
 
 out:
 
-       d_printf("Closing %s...", argv[1]);
+       d_printf(_("Closing %s..."), argv[1]);
        if (outfile) {
                regfio_close( outfile );
        }
-       d_printf("ok\n");
+       d_printf(_("ok\n"));
 
-       d_printf("Closing %s...", argv[0]);
+       d_printf(_("Closing %s..."), argv[0]);
        if (infile) {
                regfio_close( infile );
        }
-       d_printf("ok\n");
+       d_printf(_("ok\n"));
 
        return( result);
 }
@@ -1128,7 +1186,7 @@ out:
 ********************************************************************/
 
 static NTSTATUS rpc_registry_getsd_internal(struct net_context *c,
-                                           const DOM_SID *domain_sid,
+                                           const struct dom_sid *domain_sid,
                                            const char *domain_name,
                                            struct cli_state *cli,
                                            struct rpc_pipe_client *pipe_hnd,
@@ -1136,20 +1194,22 @@ static NTSTATUS rpc_registry_getsd_internal(struct net_context *c,
                                            int argc,
                                            const char **argv)
 {
-       POLICY_HND pol_hive, pol_key;
+       struct policy_handle pol_hive, pol_key;
        NTSTATUS status;
        enum ndr_err_code ndr_err;
        struct KeySecurityData *sd = NULL;
        uint32_t sec_info;
        DATA_BLOB blob;
        struct security_descriptor sec_desc;
-       uint32_t access_mask = REG_KEY_READ |
-                              SEC_RIGHT_MAXIMUM_ALLOWED |
-                              SEC_RIGHT_SYSTEM_SECURITY;
+       uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED |
+                              SEC_FLAG_SYSTEM_SECURITY;
 
        if (argc <1 || argc > 2 || c->display_usage) {
-               d_printf("Usage:    net rpc registry getsd <path> <secinfo>\n");
-               d_printf("Example:  net rpc registry getsd 'HKLM\\Software\\Samba'\n");
+               d_printf("%s\n%s",
+                        _("Usage:"),
+                        _("net rpc registry getsd <path> <secinfo>\n"));
+               d_printf("%s  net rpc registry getsd "
+                          "'HKLM\\Software\\Samba'\n", _("Example:"));
                return NT_STATUS_INVALID_PARAMETER;
        }
 
@@ -1157,7 +1217,7 @@ static NTSTATUS rpc_registry_getsd_internal(struct net_context *c,
                                  access_mask,
                                  &pol_hive, &pol_key);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "registry_openkey failed: %s\n",
+               d_fprintf(stderr, _("registry_openkey failed: %s\n"),
                          nt_errstr(status));
                return status;
        }
@@ -1178,7 +1238,7 @@ static NTSTATUS rpc_registry_getsd_internal(struct net_context *c,
 
        status = registry_getsd(mem_ctx, pipe_hnd, &pol_key, sec_info, sd);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "getting sd failed: %s\n",
+               d_fprintf(stderr, _("getting sd failed: %s\n"),
                          nt_errstr(status));
                goto out;
        }
@@ -1186,7 +1246,7 @@ static NTSTATUS rpc_registry_getsd_internal(struct net_context *c,
        blob.data = sd->data;
        blob.length = sd->size;
 
-       ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, NULL, &sec_desc,
+       ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &sec_desc,
                                       (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                status = ndr_map_error2ntstatus(ndr_err);
@@ -1220,89 +1280,89 @@ int net_rpc_registry(struct net_context *c, int argc, const char **argv)
                        "enumerate",
                        rpc_registry_enumerate,
                        NET_TRANSPORT_RPC,
-                       "Enumerate registry keys and values",
-                       "net rpc registry enumerate\n"
-                       "    Enumerate registry keys and values"
+                       N_("Enumerate registry keys and values"),
+                       N_("net rpc registry enumerate\n"
+                          "    Enumerate registry keys and values")
                },
                {
                        "createkey",
                        rpc_registry_createkey,
                        NET_TRANSPORT_RPC,
-                       "Create a new registry key",
-                       "net rpc registry createkey\n"
-                       "    Create a new registry key"
+                       N_("Create a new registry key"),
+                       N_("net rpc registry createkey\n"
+                          "    Create a new registry key")
                },
                {
                        "deletekey",
                        rpc_registry_deletekey,
                        NET_TRANSPORT_RPC,
-                       "Delete a registry key",
-                       "net rpc registry deletekey\n"
-                       "    Delete a registry key"
+                       N_("Delete a registry key"),
+                       N_("net rpc registry deletekey\n"
+                          "    Delete a registry key")
                },
                {
                        "getvalue",
                        rpc_registry_getvalue,
                        NET_TRANSPORT_RPC,
-                       "Print a registry value",
-                       "net rpc registry getvalue\n"
-                       "    Print a registry value"
+                       N_("Print a registry value"),
+                       N_("net rpc registry getvalue\n"
+                          "    Print a registry value")
                },
                {
                        "getvalueraw",
                        rpc_registry_getvalueraw,
                        NET_TRANSPORT_RPC,
-                       "Print a registry value",
-                       "net rpc registry getvalueraw\n"
-                       "    Print a registry value (raw version)"
+                       N_("Print a registry value"),
+                       N_("net rpc registry getvalueraw\n"
+                          "    Print a registry value (raw version)")
                },
                {
                        "setvalue",
                        rpc_registry_setvalue,
                        NET_TRANSPORT_RPC,
-                       "Set a new registry value",
-                       "net rpc registry setvalue\n"
-                       "    Set a new registry value"
+                       N_("Set a new registry value"),
+                       N_("net rpc registry setvalue\n"
+                          "    Set a new registry value")
                },
                {
                        "deletevalue",
                        rpc_registry_deletevalue,
                        NET_TRANSPORT_RPC,
-                       "Delete a registry value",
-                       "net rpc registry deletevalue\n"
-                       "    Delete a registry value"
+                       N_("Delete a registry value"),
+                       N_("net rpc registry deletevalue\n"
+                          "    Delete a registry value")
                },
                {
                        "save",
                        rpc_registry_save,
                        NET_TRANSPORT_RPC,
-                       "Save a registry file",
-                       "net rpc registry save\n"
-                       "    Save a registry file"
+                       N_("Save a registry file"),
+                       N_("net rpc registry save\n"
+                          "    Save a registry file")
                },
                {
                        "dump",
                        rpc_registry_dump,
                        NET_TRANSPORT_RPC,
-                       "Dump a registry file",
-                       "net rpc registry dump\n"
-                       "    Dump a registry file"
+                       N_("Dump a registry file"),
+                       N_("net rpc registry dump\n"
+                          "    Dump a registry file")
                },
                {
                        "copy",
                        rpc_registry_copy,
                        NET_TRANSPORT_RPC,
-                       "Copy a registry file",
-                       "net rpc registry copy\n"
-                       "    Copy a registry file"
+                       N_("Copy a registry file"),
+                       N_("net rpc registry copy\n"
+                          "    Copy a registry file")
                },
                {
                        "getsd",
                        rpc_registry_getsd,
                        NET_TRANSPORT_RPC,
-                       "Get security descriptor",
-                       "net rpc registry getsd\n"
-                       "    Get security descriptior"
+                       N_("Get security descriptor"),
+                       N_("net rpc registry getsd\n"
+                          "    Get security descriptior")
                },
                {NULL, NULL, 0, NULL, NULL}
        };