r10007: Merge data_blk and data_len member of registry_value into a DATA_BLOB.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 3 Sep 2005 17:17:30 +0000 (17:17 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:36:28 +0000 (13:36 -0500)
Fix handling of REG_DWORD in the LDB backend.
Fix a couple of warnings
(This used to be commit 709fdc7ebf5a77cfb50359fad978884777decc3b)

14 files changed:
source4/gtk/tools/gregedit.c
source4/include/registry.h
source4/lib/registry/TODO
source4/lib/registry/common/reg_interface.c
source4/lib/registry/common/reg_util.c
source4/lib/registry/reg_backend_ldb.c
source4/lib/registry/reg_backend_nt4.c
source4/lib/registry/reg_backend_rpc.c
source4/lib/registry/reg_backend_w95.c
source4/lib/registry/regf.idl
source4/lib/registry/tools/regdiff.c
source4/lib/registry/tools/regpatch.c
source4/lib/registry/tools/regshell.c
source4/rpc_server/winreg/rpc_winreg.c

index 5501059c5a673392458bbc80a1d09d8d95333d27..26aedf2084e16dd76e7b064d6990aaf575041d4f 100644 (file)
@@ -269,7 +269,7 @@ static void expand_key(GtkTreeView *treeview, GtkTreeIter *parent, GtkTreePath *
        g_assert(k);
        
        for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(mem_ctx, k, i, &sub)); i++) {
        g_assert(k);
        
        for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(mem_ctx, k, i, &sub)); i++) {
-               int count;
+               uint32_t count;
                /* Replace the blank child with the first directory entry
            You may be tempted to remove the blank child node and then 
            append a new one.  Don't.  If you remove the blank child 
                /* Replace the blank child with the first directory entry
            You may be tempted to remove the blank child node and then 
            append a new one.  Don't.  If you remove the blank child 
@@ -559,7 +559,7 @@ static void on_value_activate(GtkTreeView *treeview, GtkTreePath *arg1,
                
                reg_string_to_val(mem_ctx,str_regtype(gtk_combo_box_get_active(GTK_COMBO_BOX(entry_type))), gtk_entry_get_text(GTK_ENTRY(entry_value)), &val);
                
                
                reg_string_to_val(mem_ctx,str_regtype(gtk_combo_box_get_active(GTK_COMBO_BOX(entry_type))), gtk_entry_get_text(GTK_ENTRY(entry_value)), &val);
                
-               error = reg_val_set(current_key, gtk_entry_get_text(GTK_ENTRY(entry_name)), val->data_type, val->data_blk, val->data_len);
+               error = reg_val_set(current_key, gtk_entry_get_text(GTK_ENTRY(entry_name)), val->data_type, val->data);
 
                if (!W_ERROR_IS_OK(error)) {
                        gtk_show_werror(NULL, "Error while setting value", error);
 
                if (!W_ERROR_IS_OK(error)) {
                        gtk_show_werror(NULL, "Error while setting value", error);
@@ -580,7 +580,7 @@ static void on_set_value_activate(GtkMenuItem *menuitem, gpointer user_data)
                
                reg_string_to_val(mem_ctx,str_regtype(gtk_combo_box_get_active(GTK_COMBO_BOX(entry_type))), gtk_entry_get_text(GTK_ENTRY(entry_value)), &val);
                
                
                reg_string_to_val(mem_ctx,str_regtype(gtk_combo_box_get_active(GTK_COMBO_BOX(entry_type))), gtk_entry_get_text(GTK_ENTRY(entry_value)), &val);
                
-               error = reg_val_set(current_key, gtk_entry_get_text(GTK_ENTRY(entry_name)), val->data_type, val->data_blk, val->data_len);
+               error = reg_val_set(current_key, gtk_entry_get_text(GTK_ENTRY(entry_name)), val->data_type, val->data);
 
                if (!W_ERROR_IS_OK(error)) {
                        gtk_show_werror(NULL, "Error while setting value", error);
 
                if (!W_ERROR_IS_OK(error)) {
                        gtk_show_werror(NULL, "Error while setting value", error);
index e472ed6a876e2b1150a3e36e3899bcb7017f8869..dc17eb06b1345ad6515134ce4de03b2c5fcbda45 100644 (file)
@@ -64,8 +64,7 @@ struct registry_key {
 struct registry_value {
   char *name;
   unsigned int data_type;
 struct registry_value {
   char *name;
   unsigned int data_type;
-  int data_len;
-  void *data_blk;    /* Might want a separate block */
+  DATA_BLOB data;
 };
 
 /* FIXME */
 };
 
 /* FIXME */
@@ -94,9 +93,8 @@ struct hive_operations {
        /* Or this one */
        WERROR (*open_key) (TALLOC_CTX *, struct registry_key *, const char *name, struct registry_key **);
 
        /* Or this one */
        WERROR (*open_key) (TALLOC_CTX *, struct registry_key *, const char *name, struct registry_key **);
 
-       /* Either implement these */
-       WERROR (*num_subkeys) (struct registry_key *, int *count);
-       WERROR (*num_values) (struct registry_key *, int *count);
+       WERROR (*num_subkeys) (struct registry_key *, uint32_t *count);
+       WERROR (*num_values) (struct registry_key *, uint32_t *count);
        WERROR (*get_subkey_by_index) (TALLOC_CTX *, struct registry_key *, int idx, struct registry_key **);
 
        /* Can not contain more then one level */
        WERROR (*get_subkey_by_index) (TALLOC_CTX *, struct registry_key *, int idx, struct registry_key **);
 
        /* Can not contain more then one level */
@@ -120,7 +118,7 @@ struct hive_operations {
        WERROR (*flush_key) (struct registry_key *);
 
        /* Value management */
        WERROR (*flush_key) (struct registry_key *);
 
        /* Value management */
-       WERROR (*set_value)(struct registry_key *, const char *name, uint32_t type, void *data, int len); 
+       WERROR (*set_value)(struct registry_key *, const char *name, uint32_t type, DATA_BLOB data); 
        WERROR (*del_value)(struct registry_key *, const char *valname);
 };
 
        WERROR (*del_value)(struct registry_key *, const char *valname);
 };
 
@@ -139,12 +137,8 @@ struct registry_context {
 };
 
 struct reg_init_function_entry {
 };
 
 struct reg_init_function_entry {
-       /* Function to create a member of the pdb_methods list */
        const struct hive_operations *hive_functions;
        struct reg_init_function_entry *prev, *next;
 };
 
        const struct hive_operations *hive_functions;
        struct reg_init_function_entry *prev, *next;
 };
 
-/* Used internally */
-#define SMB_REG_ASSERT(a) { if(!(a)) { DEBUG(0,("%s failed! (%s:%d)", #a, __FILE__, __LINE__)); }}
-
 #endif /* _REGISTRY_H */
 #endif /* _REGISTRY_H */
index 1dea9d2650c580bafd3b00104d57047588774549..3f48d031e1293f184393996b4b0c0e4eea365888 100644 (file)
@@ -31,3 +31,5 @@ gregedit.c:
  - support for editing values / adding values / deleting values
  - support for adding/deleting keys
  - support for security descriptors
  - support for editing values / adding values / deleting values
  - support for adding/deleting keys
  - support for security descriptors
+
+- pass parsed paths around rather then strings (i.e. just a list of strings)
index 2abe90f2d10ba6afe5c1fd924227fda2d58aaf42..7f745143e64af7ecc2077ce54efba778fde4f49e 100644 (file)
@@ -252,7 +252,7 @@ WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx, struct registry_key *key,
        return WERR_OK;
 }
 
        return WERR_OK;
 }
 
-WERROR reg_key_num_subkeys(struct registry_key *key, int *count)
+WERROR reg_key_num_subkeys(struct registry_key *key, uint32_t *count)
 {
        if(!key) return WERR_INVALID_PARAM;
        
 {
        if(!key) return WERR_INVALID_PARAM;
        
@@ -277,7 +277,7 @@ WERROR reg_key_num_subkeys(struct registry_key *key, int *count)
        return WERR_NOT_SUPPORTED;
 }
 
        return WERR_NOT_SUPPORTED;
 }
 
-WERROR reg_key_num_values(struct registry_key *key, int *count)
+WERROR reg_key_num_values(struct registry_key *key, uint32_t *count)
 {
        
        if(!key) return WERR_INVALID_PARAM;
 {
        
        if(!key) return WERR_INVALID_PARAM;
@@ -416,11 +416,11 @@ WERROR reg_key_add_name(TALLOC_CTX *mem_ctx, struct registry_key *parent, const
        return WERR_OK;
 }
 
        return WERR_OK;
 }
 
-WERROR reg_val_set(struct registry_key *key, const char *value, uint32_t type, void *data, int len)
+WERROR reg_val_set(struct registry_key *key, const char *value, uint32_t type, DATA_BLOB data)
 {
        /* A 'real' set function has preference */
        if (key->hive->functions->set_value) 
 {
        /* A 'real' set function has preference */
        if (key->hive->functions->set_value) 
-               return key->hive->functions->set_value(key, value, type, data, len);
+               return key->hive->functions->set_value(key, value, type, data);
 
        DEBUG(1, ("Backend '%s' doesn't support method set_value\n", key->hive->functions->name));
        return WERR_NOT_SUPPORTED;
 
        DEBUG(1, ("Backend '%s' doesn't support method set_value\n", key->hive->functions->name));
        return WERR_NOT_SUPPORTED;
@@ -501,7 +501,7 @@ WERROR reg_key_valuesizes(struct registry_key *key, uint32_t *max_valnamelen, ui
                        if (value->name) {
                                *max_valnamelen = MAX(*max_valnamelen, strlen(value->name));
                        }
                        if (value->name) {
                                *max_valnamelen = MAX(*max_valnamelen, strlen(value->name));
                        }
-                       *max_valbufsize = MAX(*max_valbufsize, value->data_len);
+                       *max_valbufsize = MAX(*max_valbufsize, value->data.length);
                }
 
                i++;
                }
 
                i++;
index 65f116783216fdb27919ba1711d2ce5cf0e982f3..a0d4db6f57740f7f6c53929b1707cf7a510af676 100644 (file)
@@ -48,35 +48,25 @@ const char *str_regtype(int type)
 
 char *reg_val_data_string(TALLOC_CTX *mem_ctx, struct registry_value *v)
 { 
 
 char *reg_val_data_string(TALLOC_CTX *mem_ctx, struct registry_value *v)
 { 
-  char *asciip;
   char *ret = NULL;
   char *ret = NULL;
-  int i;
 
 
-  if(v->data_len == 0) return talloc_strdup(mem_ctx, "");
+  if(v->data.length == 0) return talloc_strdup(mem_ctx, "");
 
   switch (v->data_type) {
   case REG_EXPAND_SZ:
   case REG_SZ:
 
   switch (v->data_type) {
   case REG_EXPAND_SZ:
   case REG_SZ:
-      convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, v->data_blk, v->data_len, (void **)&ret);
+      convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, v->data.data, v->data.length, (void **)&ret);
          return ret;
 
   case REG_BINARY:
          return ret;
 
   case REG_BINARY:
-         ret = talloc_array_size(mem_ctx, 3, v->data_len+1);
-         asciip = ret;
-         for (i=0; i<v->data_len; i++) { 
-                 int str_rem = v->data_len * 3 - (asciip - ret);
-                 asciip += snprintf(asciip, str_rem, "%02x", *(uint8_t *)(((char *)v->data_blk)+i));
-                 if (i < v->data_len && str_rem > 0)
-                         *asciip = ' '; asciip++;      
-         }
-         *asciip = '\0';
+         ret = data_blob_hex_string(mem_ctx, &v->data);
          return ret;
 
   case REG_DWORD:
          return ret;
 
   case REG_DWORD:
-         if (*(int *)v->data_blk == 0)
+         if (*(int *)v->data.data == 0)
                  return talloc_strdup(mem_ctx, "0");
 
                  return talloc_strdup(mem_ctx, "0");
 
-         return talloc_asprintf(mem_ctx, "0x%x", *(int *)v->data_blk);
+         return talloc_asprintf(mem_ctx, "0x%x", *(int *)v->data.data);
 
   case REG_MULTI_SZ:
        /* FIXME */
 
   case REG_MULTI_SZ:
        /* FIXME */
@@ -117,17 +107,17 @@ BOOL reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, const char *da
        {
                case REG_SZ:
                case REG_EXPAND_SZ:
        {
                case REG_SZ:
                case REG_EXPAND_SZ:
-               (*value)->data_len = convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16, data_str, strlen(data_str), &(*value)->data_blk);
+               (*value)->data.length = convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16, data_str, strlen(data_str), (void **)&(*value)->data.data);
                        break;
                        break;
-               case REG_DWORD:
-                       (*value)->data_len = sizeof(uint32_t);
-                       (*value)->data_blk = talloc(mem_ctx, uint32_t);
-                       *((uint32_t *)(*value)->data_blk) = strtol(data_str, NULL, 0);
+
+               case REG_DWORD: {
+                       uint32_t tmp = strtol(data_str, NULL, 0);
+                       (*value)->data = data_blob_talloc(mem_ctx, &tmp, 4);
+                       }
                        break;
 
                case REG_NONE:
                        break;
 
                case REG_NONE:
-                       (*value)->data_len = 0;
-                       (*value)->data_blk = NULL;
+                       ZERO_STRUCT((*value)->data);
                        break;
        
                default:
                        break;
        
                default:
index 76ad1facc1f86fa0b5a94e4c9d6cdea2bead1224..f51c02a286e37ecf4fc122a576d5a4b972ed2143 100644 (file)
@@ -38,7 +38,7 @@ static int ldb_free_hive (void *_hive)
        return 0;
 }
 
        return 0;
 }
 
-static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, struct ldb_message *msg, char **name, uint32_t *type, void **data, int *len)
+static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, struct ldb_message *msg, char **name, uint32_t *type, DATA_BLOB *data)
 {
        const struct ldb_val *val;
        *name = talloc_strdup(mem_ctx, ldb_msg_find_string(msg, "value", NULL));
 {
        const struct ldb_val *val;
        *name = talloc_strdup(mem_ctx, ldb_msg_find_string(msg, "value", NULL));
@@ -49,23 +49,22 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, struct ldb_message *msg, c
        {
        case REG_SZ:
        case REG_EXPAND_SZ:
        {
        case REG_SZ:
        case REG_EXPAND_SZ:
-               *len = convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16, val->data, val->length, data);
+               data->length = convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16, val->data, val->length, (void **)&data->data);
                break;
 
                break;
 
-       case REG_DWORD:
-               *len = 4;
-               *data = talloc(mem_ctx, uint32_t);
-               SIVAL(*data, 0, strtol(val->data, NULL, 0));
+       case REG_DWORD: {
+               uint32_t tmp = strtoul((char *)val->data, NULL, 0);
+               *data = data_blob_talloc(mem_ctx, &tmp, 4);
+               }
                break;
 
        default:
                break;
 
        default:
-               *data = talloc_memdup(mem_ctx, val->data, val->length);
-               *len = val->length;
+               *data = data_blob_talloc(mem_ctx, val->data, val->length);
                break;
        }
 }
 
                break;
        }
 }
 
-static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx, TALLOC_CTX *mem_ctx, const char *name, uint32_t type, void *data, int len)
+static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx, TALLOC_CTX *mem_ctx, const char *name, uint32_t type, DATA_BLOB data)
 {
        struct ldb_val val;
        struct ldb_message *msg = talloc_zero(mem_ctx, struct ldb_message);
 {
        struct ldb_val val;
        struct ldb_message *msg = talloc_zero(mem_ctx, struct ldb_message);
@@ -76,16 +75,15 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx, TALLOC_CT
        switch (type) {
        case REG_SZ:
        case REG_EXPAND_SZ:
        switch (type) {
        case REG_SZ:
        case REG_EXPAND_SZ:
-               val.length = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8, data, len, &val.data);
+               val.length = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8, (void *)data.data, data.length, (void **)&val.data);
                ldb_msg_add_value(ctx, msg, "data", &val);
                break;
                ldb_msg_add_value(ctx, msg, "data", &val);
                break;
+
        case REG_DWORD:
        case REG_DWORD:
-               ldb_msg_add_string(ctx, msg, "data", talloc_asprintf(mem_ctx, "0x%x", IVAL(data, 0)));
+               ldb_msg_add_string(ctx, msg, "data", talloc_asprintf(mem_ctx, "0x%x", IVAL(data.data, 0)));
                break;
        default:
                break;
        default:
-               val.length = len;
-               val.data = data;
-               ldb_msg_add_value(ctx, msg, "data", &val);
+               ldb_msg_add_value(ctx, msg, "data", &data);
        }
 
 
        }
 
 
@@ -177,7 +175,7 @@ static WERROR ldb_get_subkey_by_id(TALLOC_CTX *mem_ctx, struct registry_key *k,
        
        *subkey = talloc(mem_ctx, struct registry_key);
        talloc_set_destructor(*subkey, reg_close_ldb_key);
        
        *subkey = talloc(mem_ctx, struct registry_key);
        talloc_set_destructor(*subkey, reg_close_ldb_key);
-       (*subkey)->name = talloc_strdup(mem_ctx, el->values[0].data);
+       (*subkey)->name = talloc_strdup(mem_ctx, (char *)el->values[0].data);
        (*subkey)->backend_data = newkd = talloc_zero(*subkey, struct ldb_key_data);
        (*subkey)->last_mod = 0; /* TODO: we need to add this to the
                                    ldb backend properly */
        (*subkey)->backend_data = newkd = talloc_zero(*subkey, struct ldb_key_data);
        (*subkey)->last_mod = 0; /* TODO: we need to add this to the
                                    ldb backend properly */
@@ -205,7 +203,7 @@ static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, struct registry_key *k, i
 
        *value = talloc(mem_ctx, struct registry_value);
 
 
        *value = talloc(mem_ctx, struct registry_value);
 
-       reg_ldb_unpack_value(mem_ctx, kd->values[idx], &(*value)->name, &(*value)->data_type, &(*value)->data_blk, &(*value)->data_len);
+       reg_ldb_unpack_value(mem_ctx, kd->values[idx], &(*value)->name, &(*value)->data_type, &(*value)->data);
 
        return WERR_OK;
 }
 
        return WERR_OK;
 }
@@ -333,7 +331,7 @@ static WERROR ldb_del_value (struct registry_key *key, const char *child)
        return WERR_OK;
 }
 
        return WERR_OK;
 }
 
-static WERROR ldb_set_value (struct registry_key *parent, const char *name, uint32_t type, void *data, int len)
+static WERROR ldb_set_value (struct registry_key *parent, const char *name, uint32_t type, DATA_BLOB data)
 {
        struct ldb_context *ctx = parent->hive->backend_data;
        struct ldb_message *msg;
 {
        struct ldb_context *ctx = parent->hive->backend_data;
        struct ldb_message *msg;
@@ -341,7 +339,7 @@ static WERROR ldb_set_value (struct registry_key *parent, const char *name, uint
        int ret;
        TALLOC_CTX *mem_ctx = talloc_init("ldb_set_value");
 
        int ret;
        TALLOC_CTX *mem_ctx = talloc_init("ldb_set_value");
 
-       msg = reg_ldb_pack_value(ctx, mem_ctx, name, type, data, len);
+       msg = reg_ldb_pack_value(ctx, mem_ctx, name, type, data);
 
        msg->dn = ldb_dn_build_child(msg, "value", name, kd->dn);
 
 
        msg->dn = ldb_dn_build_child(msg, "value", name, kd->dn);
 
index e07534884ce1b2f04e65ad0f448fc1a91f72d140..06c0d78c85d7f0effa86cfcd120d43ca962cb339 100644 (file)
@@ -624,7 +624,7 @@ static KEY_SEC_DESC *nt_create_init_sec(struct registry_hive *h)
 static REGF_HDR *nt_get_regf_hdr(struct registry_hive *h)
 {
        REGF *regf = h->backend_data;
 static REGF_HDR *nt_get_regf_hdr(struct registry_hive *h)
 {
        REGF *regf = h->backend_data;
-       SMB_REG_ASSERT(regf);
+       SMB_ASSERT(regf);
 
        if (!regf->base) { /* Try to mmap etc the file */
 
 
        if (!regf->base) { /* Try to mmap etc the file */
 
@@ -650,7 +650,7 @@ static REGF_HDR *nt_get_regf_hdr(struct registry_hive *h)
         * header 
         */
 
         * header 
         */
 
-       SMB_REG_ASSERT(regf->base != NULL);
+       SMB_ASSERT(regf->base != NULL);
 
        return (REGF_HDR *)regf->base;
 }
 
        return (REGF_HDR *)regf->base;
 }
@@ -828,7 +828,7 @@ static KEY_SEC_DESC *process_sk(struct registry_hive *regf, SK_HDR *sk_hdr, int
 
        /* Here, we have an item in the map that has been reserved, or tmp==NULL. */
 
 
        /* Here, we have an item in the map that has been reserved, or tmp==NULL. */
 
-       SMB_REG_ASSERT(tmp == NULL || (tmp && tmp->state != SEC_DESC_NON));
+       SMB_ASSERT(tmp == NULL || (tmp && tmp->state != SEC_DESC_NON));
 
        /*
         * Now, allocate a KEY_SEC_DESC, and parse the structure here, and add the
 
        /*
         * Now, allocate a KEY_SEC_DESC, and parse the structure here, and add the
@@ -870,10 +870,10 @@ static KEY_SEC_DESC *process_sk(struct registry_hive *regf, SK_HDR *sk_hdr, int
 
        sk_prev_off = IVAL(&sk_hdr->prev_off,0);
        tmp->prev = lookup_create_sec_key(regf, regf->sk_map, sk_prev_off);
 
        sk_prev_off = IVAL(&sk_hdr->prev_off,0);
        tmp->prev = lookup_create_sec_key(regf, regf->sk_map, sk_prev_off);
-       SMB_REG_ASSERT(tmp->prev != NULL);
+       SMB_ASSERT(tmp->prev != NULL);
        sk_next_off = IVAL(&sk_hdr->next_off,0);
        tmp->next = lookup_create_sec_key(regf, regf->sk_map, sk_next_off);
        sk_next_off = IVAL(&sk_hdr->next_off,0);
        tmp->next = lookup_create_sec_key(regf, regf->sk_map, sk_next_off);
-       SMB_REG_ASSERT(tmp->next != NULL);
+       SMB_ASSERT(tmp->next != NULL);
 
        return tmp;
 }
 
        return tmp;
 }
@@ -934,9 +934,7 @@ static WERROR vk_to_val(TALLOC_CTX *mem_ctx, struct registry_key *parent, VK_HDR
                        memcpy(dtmp, &dat_off, dat_len);
                }
 
                        memcpy(dtmp, &dat_off, dat_len);
                }
 
-
-               tmp->data_blk = dtmp;
-               tmp->data_len = dat_len;
+               tmp->data = data_blob_talloc(mem_ctx, dtmp, dat_len);
        }
 
        *value = tmp;
        }
 
        *value = tmp;
@@ -968,14 +966,14 @@ static WERROR lf_verify(struct registry_hive *h, LF_HDR *lf_hdr, int size)
        return WERR_OK;
 }
 
        return WERR_OK;
 }
 
-static WERROR lf_num_entries(struct registry_hive *h, LF_HDR *lf_hdr, int size, int *count)
+static WERROR lf_num_entries(struct registry_hive *h, LF_HDR *lf_hdr, int size, uint32_t *count)
 {
        WERROR error;
 
        error = lf_verify(h, lf_hdr, size);
        if(!W_ERROR_IS_OK(error)) return error;
 
 {
        WERROR error;
 
        error = lf_verify(h, lf_hdr, size);
        if(!W_ERROR_IS_OK(error)) return error;
 
-       SMB_REG_ASSERT(size < 0);
+       SMB_ASSERT(size < 0);
 
        *count = SVAL(&lf_hdr->key_count,0);
        DEBUG(2, ("Key Count: %u\n", *count));
 
        *count = SVAL(&lf_hdr->key_count,0);
        DEBUG(2, ("Key Count: %u\n", *count));
@@ -1004,7 +1002,7 @@ static WERROR lf_get_entry(TALLOC_CTX *mem_ctx, struct registry_key *parent, LF_
        error = lf_verify(parent->hive, lf_hdr, size);
        if(!W_ERROR_IS_OK(error)) return error;
 
        error = lf_verify(parent->hive, lf_hdr, size);
        if(!W_ERROR_IS_OK(error)) return error;
 
-       SMB_REG_ASSERT(size < 0);
+       SMB_ASSERT(size < 0);
 
        count = SVAL(&lf_hdr->key_count,0);
        DEBUG(2, ("Key Count: %u\n", count));
 
        count = SVAL(&lf_hdr->key_count,0);
        DEBUG(2, ("Key Count: %u\n", count));
@@ -1035,7 +1033,7 @@ static WERROR nk_to_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, NK_HDR *nk
                return WERR_INVALID_PARAM;
        }
 
                return WERR_INVALID_PARAM;
        }
 
-       SMB_REG_ASSERT(size < 0);
+       SMB_ASSERT(size < 0);
 
        namlen = SVAL(&nk_hdr->nam_len,0);
        clsname_len = SVAL(&nk_hdr->clsnam_len,0);
 
        namlen = SVAL(&nk_hdr->nam_len,0);
        clsname_len = SVAL(&nk_hdr->clsnam_len,0);
@@ -1059,7 +1057,7 @@ static WERROR nk_to_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, NK_HDR *nk
 
        /* Fish out the key name and process the LF list */
 
 
        /* Fish out the key name and process the LF list */
 
-       SMB_REG_ASSERT(namlen < sizeof(key_name));
+       SMB_ASSERT(namlen < sizeof(key_name));
 
        strncpy(key_name, nk_hdr->key_nam, namlen);
        key_name[namlen] = '\0';
 
        strncpy(key_name, nk_hdr->key_nam, namlen);
        key_name[namlen] = '\0';
@@ -1194,7 +1192,7 @@ static void *nt_alloc_regf_space(struct registry_hive *h, int size, uint_t *off)
 
        if (!regf || !size || !off) return NULL;
 
 
        if (!regf || !size || !off) return NULL;
 
-       SMB_REG_ASSERT(regf->blk_head != NULL);
+       SMB_ASSERT(regf->blk_head != NULL);
 
        /*
         * round up size to include header and then to 8-byte boundary
 
        /*
         * round up size to include header and then to 8-byte boundary
@@ -1653,7 +1651,7 @@ static WERROR nt_open_hive (struct registry_hive *h, struct registry_key **key)
 }
 
 
 }
 
 
-static WERROR nt_num_subkeys(struct registry_key *k, int *num) 
+static WERROR nt_num_subkeys(struct registry_key *k, uint32_t *num) 
 {
        REGF *regf = k->hive->backend_data;
        LF_HDR *lf_hdr;
 {
        REGF *regf = k->hive->backend_data;
        LF_HDR *lf_hdr;
@@ -1670,7 +1668,7 @@ static WERROR nt_num_subkeys(struct registry_key *k, int *num)
        return lf_num_entries(k->hive, lf_hdr, BLK_SIZE(lf_hdr), num);
 }
 
        return lf_num_entries(k->hive, lf_hdr, BLK_SIZE(lf_hdr), num);
 }
 
-static WERROR nt_num_values(struct registry_key *k, int *count)
+static WERROR nt_num_values(struct registry_key *k, uint32_t *count)
 {
        NK_HDR *nk_hdr = k->backend_data;
        *count = IVAL(&nk_hdr->val_cnt,0);
 {
        NK_HDR *nk_hdr = k->backend_data;
        *count = IVAL(&nk_hdr->val_cnt,0);
index 44de3bcd77078a15f57dbdd62a9f7b4aef8c26f5..a00accc6be337c1632c1da5d8299a1b01c98fec0 100644 (file)
@@ -204,8 +204,7 @@ static WERROR rpc_get_value_by_index(TALLOC_CTX *mem_ctx, struct registry_key *p
                *value = talloc(mem_ctx, struct registry_value);
                (*value)->name = talloc_strdup(mem_ctx, r.out.name->name);
                (*value)->data_type = type;
                *value = talloc(mem_ctx, struct registry_value);
                (*value)->name = talloc_strdup(mem_ctx, r.out.name->name);
                (*value)->data_type = type;
-               (*value)->data_len = *r.out.length;
-               (*value)->data_blk = talloc_memdup(mem_ctx, r.out.value, *r.out.length);
+               (*value)->data = data_blob_talloc(mem_ctx, r.out.value, *r.out.length);
                return WERR_OK;
        }
        
                return WERR_OK;
        }
        
@@ -318,7 +317,8 @@ static WERROR rpc_del_key(struct registry_key *parent, const char *name)
        return r.out.result;
 }
 
        return r.out.result;
 }
 
-static WERROR rpc_num_values(struct registry_key *key, int *count) {
+static WERROR rpc_num_values(struct registry_key *key, uint32_t *count) 
+{
        struct rpc_key_data *mykeydata = key->backend_data;
        WERROR error;
                
        struct rpc_key_data *mykeydata = key->backend_data;
        WERROR error;
                
@@ -331,7 +331,8 @@ static WERROR rpc_num_values(struct registry_key *key, int *count) {
        return WERR_OK;
 }
 
        return WERR_OK;
 }
 
-static WERROR rpc_num_subkeys(struct registry_key *key, int *count) {
+static WERROR rpc_num_subkeys(struct registry_key *key, uint32_t *count) 
+{
        struct rpc_key_data *mykeydata = key->backend_data;
        WERROR error;
 
        struct rpc_key_data *mykeydata = key->backend_data;
        WERROR error;
 
index 45b61058011d7f1f6cb90677b1e24e97bf92f576..03460052da29afea9b14b6355dc5fb5716accddb 100644 (file)
@@ -303,7 +303,7 @@ static WERROR w95_get_subkey_by_index (TALLOC_CTX *mem_ctx, struct registry_key
        return WERR_NO_MORE_ITEMS;
 }
 
        return WERR_NO_MORE_ITEMS;
 }
 
-static WERROR w95_num_values(struct registry_key *k, int *count)
+static WERROR w95_num_values(struct registry_key *k, uint32_t *count)
 {
        RGKN_KEY *rgkn_key = k->backend_data;
        RGDB_KEY *rgdb_key = LOCN_RGDB_KEY((CREG *)k->hive->backend_data, rgkn_key->id.rgdb, rgkn_key->id.id);
 {
        RGKN_KEY *rgkn_key = k->backend_data;
        RGDB_KEY *rgdb_key = LOCN_RGDB_KEY((CREG *)k->hive->backend_data, rgkn_key->id.rgdb, rgkn_key->id.id);
@@ -335,8 +335,7 @@ static WERROR w95_get_value_by_id(TALLOC_CTX *mem_ctx, struct registry_key *k, i
        *value = talloc(mem_ctx, struct registry_value);
        (*value)->name = talloc_strndup(mem_ctx, (char *)curval+sizeof(RGDB_VALUE), curval->name_len);
                
        *value = talloc(mem_ctx, struct registry_value);
        (*value)->name = talloc_strndup(mem_ctx, (char *)curval+sizeof(RGDB_VALUE), curval->name_len);
                
-       (*value)->data_len = curval->data_len;
-       (*value)->data_blk = talloc_memdup(mem_ctx, (char *)curval+sizeof(RGDB_VALUE)+curval->name_len, curval->data_len);
+       (*value)->data = data_blob_talloc(mem_ctx, curval+sizeof(RGDB_VALUE)+curval->name_len, curval->data_len);
        (*value)->data_type = curval->type;
        
        return WERR_OK;
        (*value)->data_type = curval->type;
        
        return WERR_OK;
index 8bef15c79e8430f000fbae847260da88adf0c46a..03f63debc8ddd244c4d7ea74ab76b1e956b0430d 100644 (file)
 
 interface regf
 {
 
 interface regf
 {
-       typedef struct {
-               uint32 major; 
-               uint32 minor;
-               uint32 release;
-               uint32 build;
-       } regf_version;
-
-       /* 1.3.0.1 for WinNT 4
+       /* 
+        * Registry version number
+        * 1.3.0.1 for WinNT 4
         * 1.5.0.1 for WinXP
         */
        
         * 1.5.0.1 for WinXP
         */
        
+       typedef struct {
+               [value(1)] uint32 major; 
+               [value(3)] uint32 minor;
+               [value(0)] uint32 release;
+               [value(1)] uint32 build;
+       } regf_version;
 
        /* 
                "regf" is obviously the abbreviation for "Registry file". "regf" is the
 
        /* 
                "regf" is obviously the abbreviation for "Registry file". "regf" is the
@@ -70,7 +71,7 @@ interface regf
 
        typedef enum { 
                REG_ROOT_KEY = 0x20, 
 
        typedef enum { 
                REG_ROOT_KEY = 0x20, 
-               REG_SUB_KEY = 0x2C, 
+               REG_SUB_KEY  = 0x2C, 
                REG_SYM_LINK = 0x10 
        } reg_key_type;
 
                REG_SYM_LINK = 0x10 
        } reg_key_type;
 
@@ -90,7 +91,7 @@ interface regf
                uint32 num_values;
                uint32 values_offset;
                uint32 sk_offset;
                uint32 num_values;
                uint32 values_offset;
                uint32 sk_offset;
-               uint32 clsnam_offset;
+               uint32 clsname_offset;
                uint32 unk4[5];
                uint16 name_length;
                uint16 clsname_length;
                uint32 unk4[5];
                uint16 name_length;
                uint16 clsname_length;
@@ -112,6 +113,7 @@ interface regf
                        uint32 base37; /* base37 of key name */
        } lh_hash;
        
                        uint32 base37; /* base37 of key name */
        } lh_hash;
        
+       /* Subkey listing with hash of first 4 characters */
        typedef struct {
                uint16 key_count;
                lh_hash hashes[key_count];
        typedef struct {
                uint16 key_count;
                lh_hash hashes[key_count];
index a9d189c03321c610b756920dbb574100e7da598b..307ec3793e3ecaf20f3db82276fe3453d2b683ab 100644 (file)
@@ -72,7 +72,7 @@ static void writediff(struct registry_key *oldkey, struct registry_key *newkey,
 
        for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_value_by_index(mem_ctx, newkey, i, &v1)); i++) {
                error2 = reg_key_get_value_by_name(mem_ctx, oldkey, v1->name, &v2);
 
        for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_value_by_index(mem_ctx, newkey, i, &v1)); i++) {
                error2 = reg_key_get_value_by_name(mem_ctx, oldkey, v1->name, &v2);
-               if ((W_ERROR_IS_OK(error2) && (v2->data_len != v1->data_len || memcmp(v1->data_blk, v2->data_blk, v1->data_len))) 
+               if ((W_ERROR_IS_OK(error2) && data_blob_equal(&v1->data, &v2->data)) 
                        || W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
                        fprintf(out, "\"%s\"=%s:%s\n", v1->name, str_regtype(v1->data_type), reg_val_data_string(mem_ctx, v1));
                }
                        || W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
                        fprintf(out, "\"%s\"=%s:%s\n", v1->name, str_regtype(v1->data_type), reg_val_data_string(mem_ctx, v1));
                }
index c2f01ce5b4f9a241e84bde92653bcabd6294b36f..5f7d4376d40707c2787fac38b20f330d2c17d075 100644 (file)
@@ -704,9 +704,11 @@ static int nt_apply_reg_command_file(struct registry_context *r, const char *cmd
                                        DEBUG(0, ("Error removing value '%s'\n", val->name));
                                  }
                                  modified = True;
                                        DEBUG(0, ("Error removing value '%s'\n", val->name));
                                  }
                                  modified = True;
-                         }
-                         else {
-                                 if(!W_ERROR_IS_OK(reg_val_set(tmp, val->name, val->type, val->val, strlen(val->val)))) {
+                         } else {
+                                 DATA_BLOB blob;
+                                 blob.data = (uint8_t *)val->val;
+                                 blob.length = strlen(val->val);
+                                 if(!W_ERROR_IS_OK(reg_val_set(tmp, val->name, val->type, blob))) {
                                          DEBUG(0, ("Error adding new value '%s'\n", val->name));
                                          continue;
                                  }
                                          DEBUG(0, ("Error adding new value '%s'\n", val->name));
                                          continue;
                                  }
index 108cc173364b210c764b2e99e92e7aa61993ef56..496b9dc7e5fcfefcc430ed8590a7c29c07ebbfcd 100644 (file)
@@ -80,7 +80,7 @@ static struct registry_key *cmd_set(TALLOC_CTX *mem_ctx, struct registry_context
        } else {
                struct registry_value *val;
                if (reg_string_to_val(mem_ctx, argv[2], argv[3], &val)) {
        } else {
                struct registry_value *val;
                if (reg_string_to_val(mem_ctx, argv[2], argv[3], &val)) {
-                       WERROR error = reg_val_set(cur, argv[1], val->data_type, val->data_blk, val->data_len);
+                       WERROR error = reg_val_set(cur, argv[1], val->data_type, val->data);
                        if (!W_ERROR_IS_OK(error)) {
                                fprintf(stderr, "Error setting value: %s\n", win_errstr(error));
                                return NULL;
                        if (!W_ERROR_IS_OK(error)) {
                                fprintf(stderr, "Error setting value: %s\n", win_errstr(error));
                                return NULL;
index f03ca2fa86388a9bf8166b0159ea56161bc223d8..ba11b071481a3a27f0cb2a4107ad5b681e39adb1 100644 (file)
@@ -225,7 +225,7 @@ static WERROR winreg_EnumValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *m
        /* check the client has enough room for the value */
        if (r->in.value != NULL &&
            r->in.size != NULL && 
        /* check the client has enough room for the value */
        if (r->in.value != NULL &&
            r->in.size != NULL && 
-           value->data_len > *r->in.size) {
+           value->data.length > *r->in.size) {
                return WERR_MORE_DATA;
        }
        
                return WERR_MORE_DATA;
        }
        
@@ -239,12 +239,12 @@ static WERROR winreg_EnumValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *m
        r->out.name->size = 2*strlen_m_term(value->name);
 
        if (r->in.value) {
        r->out.name->size = 2*strlen_m_term(value->name);
 
        if (r->in.value) {
-               r->out.value = value->data_blk;
+               r->out.value = value->data.data;
        }
 
        if (r->in.size) {
                r->out.size = talloc(mem_ctx, uint32_t);
        }
 
        if (r->in.size) {
                r->out.size = talloc(mem_ctx, uint32_t);
-               *r->out.size = value->data_len;
+               *r->out.size = value->data.length;
                r->out.length = r->out.size;
        }
        
                r->out.length = r->out.size;
        }
        
@@ -398,13 +398,13 @@ static WERROR winreg_QueryValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *
 
        /* Just asking for the size of the buffer */
        r->out.type = &val->data_type;
 
        /* Just asking for the size of the buffer */
        r->out.type = &val->data_type;
-       r->out.length = &val->data_len;
+       r->out.length = &val->data.length;
        if (!r->in.data) {
                r->out.size = talloc(mem_ctx, uint32_t);
        if (!r->in.data) {
                r->out.size = talloc(mem_ctx, uint32_t);
-               *r->out.size = val->data_len;
+               *r->out.size = val->data.length;
        } else {
                r->out.size = r->in.size;
        } else {
                r->out.size = r->in.size;
-               r->out.data = val->data_blk;
+               r->out.data = val->data.data;
        }
 
        return WERR_OK;
        }
 
        return WERR_OK;
@@ -460,12 +460,15 @@ static WERROR winreg_SetValue(struct dcesrv_call_state *dce_call, TALLOC_CTX *me
        struct dcesrv_handle *h;
        struct registry_key *key;
        WERROR result;
        struct dcesrv_handle *h;
        struct registry_key *key;
        WERROR result;
+       DATA_BLOB data;
 
        DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
 
        key = h->data;
        
 
        DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
 
        key = h->data;
        
-       result = reg_val_set(key, r->in.name.name, r->in.type, r->in.data, r->in.size);
+       data.data = r->in.data;
+       data.length = r->in.size;
+       result = reg_val_set(key, r->in.name.name, r->in.type, data);
 
        if (!W_ERROR_IS_OK(result)) { 
                return result;
 
        if (!W_ERROR_IS_OK(result)) { 
                return result;