r24998: Add a function regval_compose() to compose a REGISTRY_VALUE from
authorMichael Adam <obnox@samba.org>
Fri, 7 Sep 2007 14:41:49 +0000 (14:41 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:30:32 +0000 (12:30 -0500)
input data. Use this function in a first step to refactor
the canonicalization code of smbconf_store_values().

Michael

source/registry/reg_objects.c
source/registry/reg_smbconf.c

index f759a921d23530965c6202f76b66e26408c60f6e..ba37b9014b540ca501f790ba1b56cafcaa79a7f4 100644 (file)
@@ -270,6 +270,36 @@ BOOL regval_ctr_key_exists( REGVAL_CTR *ctr, const char *value )
        
        return False;
 }
+
+/***********************************************************************
+ * compose a REGISTRY_VALUE from input data
+ **********************************************************************/
+
+REGISTRY_VALUE *regval_compose(TALLOC_CTX *ctx, const char *name, uint16 type,
+                              const char *data_p, size_t size)
+{
+       REGISTRY_VALUE *regval = TALLOC_P(ctx, REGISTRY_VALUE);
+
+       if (regval == NULL) {
+               return NULL;
+       }
+
+       fstrcpy(regval->valuename, name);
+       regval->type = type;
+       if (size) {
+               regval->data_p = (uint8 *)TALLOC_MEMDUP(regval, data_p, size);
+               if (!regval->data_p) {
+                       TALLOC_FREE(regval);
+                       return NULL;
+               }
+       } else {
+               regval->data_p = NULL;
+       }
+       regval->size = size;
+
+       return regval;
+}
+
 /***********************************************************************
  Add a new registry value to the array
  **********************************************************************/
index e2c7e7ea08220aea9f8f95c494ead8d21cfe25f4..f2a8b6ee8bd9cc1f739d9a37b655306e99fc74e9 100644 (file)
@@ -167,10 +167,18 @@ static BOOL smbconf_store_values( const char *key, REGVAL_CTR *val )
 
                        DEBUG(10, ("adding canonicalized parameter to "
                                   "container.\n"));
-                       res = regval_ctr_addvalue(new_val_ctr, canon_valname,
-                                                 value->type,
-                                                 (char *)value_data.data,
-                                                 value_data.length);
+
+                       theval = regval_compose(mem_ctx, canon_valname,
+                                               value->type,
+                                               (char *)value_data.data,
+                                               value_data.length);
+                       if (theval == NULL) {
+                               DEBUG(10, ("error composing registry value. "
+                                          "(no memory?)\n"));
+                               TALLOC_FREE(mem_ctx);
+                               return False;
+                       }
+                       res = regval_ctr_copyvalue(new_val_ctr, theval);
                        if (res == 0) {
                                DEBUG(10, ("error calling regval_ctr_addvalue. "
                                      "(no memory?)\n"));