diff options
author | Matthias Dieter Wallnöfer <mwallnoefer@yahoo.de> | 2010-03-06 19:36:01 +0100 |
---|---|---|
committer | Matthias Dieter Wallnöfer <mwallnoefer@yahoo.de> | 2010-03-06 19:59:04 +0100 |
commit | ed678a2234dda656d0a2d5bbf65b22afa7a47144 (patch) | |
tree | 18c127390eb1551c655faa9271476974e33e8618 /source4/lib/registry | |
parent | f5b86cdac52c1eb7f30c1900cce880ed868789c8 (diff) | |
download | samba-ed678a2234dda656d0a2d5bbf65b22afa7a47144.tar.gz samba-ed678a2234dda656d0a2d5bbf65b22afa7a47144.tar.bz2 samba-ed678a2234dda656d0a2d5bbf65b22afa7a47144.zip |
s4:registry library - fix up "reg_ldb_set_value"
The previous logic was wrong since it tried to add empty data in some cases
which always ended in an error. This problem should be fixed with the new logic.
Diffstat (limited to 'source4/lib/registry')
-rw-r--r-- | source4/lib/registry/ldb.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c index df06798f74..d8a786cf8a 100644 --- a/source4/lib/registry/ldb.c +++ b/source4/lib/registry/ldb.c @@ -700,13 +700,14 @@ static WERROR ldb_set_value(struct hive_key *parent, { struct ldb_message *msg; struct ldb_key_data *kd = talloc_get_type(parent, struct ldb_key_data); + unsigned int i; int ret; TALLOC_CTX *mem_ctx = talloc_init("ldb_set_value"); msg = reg_ldb_pack_value(kd->ldb, mem_ctx, name, type, data); msg->dn = ldb_dn_copy(msg, kd->dn); - - if (strlen(name) > 0) { + + if (name[0] != '\0') { /* For a default value, we add/overwrite the attributes to/of the hive. For a normal value, we create a new child. */ if (!ldb_dn_add_child_fmt(msg->dn, "value=%s", @@ -717,14 +718,27 @@ static WERROR ldb_set_value(struct hive_key *parent, } } - ret = ldb_add(kd->ldb, msg); - if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) { - unsigned int i; - for (i = 0; i < msg->num_elements; i++) { - if (msg->elements[i].flags != LDB_FLAG_MOD_DELETE) - msg->elements[i].flags = LDB_FLAG_MOD_REPLACE; + /* Try first a "modify" and if this doesn't work do try an "add" */ + for (i = 0; i < msg->num_elements; i++) { + if (msg->elements[i].flags != LDB_FLAG_MOD_DELETE) { + msg->elements[i].flags = LDB_FLAG_MOD_REPLACE; } - ret = ldb_modify(kd->ldb, msg); + } + ret = ldb_modify(kd->ldb, msg); + if (ret == LDB_ERR_NO_SUCH_OBJECT) { + i = 0; + while (i < msg->num_elements) { + if (msg->elements[i].flags == LDB_FLAG_MOD_DELETE) { + ldb_msg_remove_element(msg, &msg->elements[i]); + } else { + ++i; + } + } + ret = ldb_add(kd->ldb, msg); + } + if (ret == LDB_ERR_NO_SUCH_ATTRIBUTE) { + /* ignore this -> the value didn't exist and also now doesn't */ + ret = LDB_SUCCESS; } if (ret != LDB_SUCCESS) { |