registry: Check for more specific LDB return codes, handle changing existing values...
authorJelmer Vernooij <jelmer@samba.org>
Fri, 18 Jan 2008 00:47:10 +0000 (01:47 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 18 Jan 2008 02:41:59 +0000 (03:41 +0100)
source/lib/registry/ldb.c

index 259315cc3955d93f87e776b9b8433084642c0af6..d56b63299d944e1f18460a5a56b5110c0aec51c0 100644 (file)
@@ -478,13 +478,18 @@ static WERROR ldb_set_value(struct hive_key *parent,
        ldb_dn_add_child_fmt(msg->dn, "value=%s", name);
 
        ret = ldb_add(kd->ldb, msg);
        ldb_dn_add_child_fmt(msg->dn, "value=%s", name);
 
        ret = ldb_add(kd->ldb, msg);
-       if (ret < 0) {
-               ret = ldb_modify(kd->ldb, msg);
-               if (ret < 0) {
-                       DEBUG(1, ("ldb_msg_add: %s\n", ldb_errstring(kd->ldb)));
-                       talloc_free(mem_ctx);
-                       return WERR_FOOBAR;
+       if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) {
+               int i;
+               for (i = 0; i < msg->num_elements; i++) {
+                       msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
                }
                }
+               ret = ldb_modify(kd->ldb, msg);
+       }
+
+       if (ret != LDB_SUCCESS) {
+               DEBUG(1, ("ldb_msg_add: %s\n", ldb_errstring(kd->ldb)));
+               talloc_free(mem_ctx);
+               return WERR_FOOBAR;
        }
 
        talloc_free(mem_ctx);
        }
 
        talloc_free(mem_ctx);