Merge branch 'v4-0-test' into id10ts-registry
[samba.git] / source4 / lib / registry / regf.c
index cf3e564c0e2c6d1369dd33eb39a9d66eae445ec7..a192f3be4ddc14c656435552d22ce3b0ed7d356a 100644 (file)
@@ -1618,10 +1618,55 @@ static WERROR regf_del_key(const struct hive_key *parent, const char *name)
                return WERR_BADFILE;
        }
 
-       if (key->nk->subkeys_offset != -1 ||
-               key->nk->values_offset != -1) {
-               DEBUG(0, ("Key '%s' is not empty.\n", name));
-               return WERR_FILE_EXISTS;
+       if (key->nk->subkeys_offset != -1) {
+               char *sk_name;
+               struct hive_key *sk = (struct hive_key *)key;
+               int i = key->nk->num_subkeys;
+               while (i--) {
+                       /* Get subkey information. */
+                       error = regf_get_subkey_by_index(parent_nk, sk, 0,
+                                                        (const char **)&sk_name,
+                                                        NULL, NULL);
+                       if (!W_ERROR_IS_OK(error)) {
+                               DEBUG(0, ("Can't retrieve subkey by index.\n"));
+                               return error;
+                       }
+
+                       /* Delete subkey. */
+                       error = regf_del_key(sk, sk_name);
+                       if (!W_ERROR_IS_OK(error)) {
+                               DEBUG(0, ("Can't delete key '%s'.\n", sk_name));
+                               return error;
+                       }
+
+                       talloc_free(sk_name);
+               }
+       }
+
+       if (key->nk->values_offset != -1) {
+               char *val_name;
+               struct hive_key *sk = (struct hive_key *)key;
+               DATA_BLOB data;
+               int i = key->nk->num_values;
+               while (i--) {
+                       /* Get value information. */
+                       error = regf_get_value(parent_nk, sk, 0,
+                                              (const char **)&val_name,
+                                              NULL, &data);
+                       if (!W_ERROR_IS_OK(error)) {
+                               DEBUG(0, ("Can't retrieve value by index.\n"));
+                               return error;
+                       }
+
+                       /* Delete value. */
+                       error = regf_del_value(sk, val_name);
+                       if (!W_ERROR_IS_OK(error)) {
+                               DEBUG(0, ("Can't delete value '%s'.\n", val_name));
+                               return error;
+                       }
+
+                       talloc_free(val_name);
+               }
        }
 
        /* Delete it from the subkey list. */