diff options
author | Andrew Tridgell <tridge@samba.org> | 2010-01-06 09:20:35 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-01-08 13:02:59 +1100 |
commit | e6f14ac2c4f0d1eaae93980b3628250de945e71e (patch) | |
tree | e52db269017b6c391095a953aaa28c4837f8ae44 /source4/dsdb/samdb/ldb_modules | |
parent | f24011059b8b656eeb32c2724c0350f135dd2309 (diff) | |
download | samba-e6f14ac2c4f0d1eaae93980b3628250de945e71e.tar.gz samba-e6f14ac2c4f0d1eaae93980b3628250de945e71e.tar.bz2 samba-e6f14ac2c4f0d1eaae93980b3628250de945e71e.zip |
s4-dsdb: added dsdb_module_constrainted_update_integer()
This provides a convenient way to update a integer attribute with a
constrained delete/add
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/dsdb/samdb/ldb_modules')
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/util.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/util.c b/source4/dsdb/samdb/ldb_modules/util.c index 16d5ddecd6..f642160397 100644 --- a/source4/dsdb/samdb/ldb_modules/util.c +++ b/source4/dsdb/samdb/ldb_modules/util.c @@ -535,3 +535,53 @@ int dsdb_module_rid_manager_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx, s "rIDManagerReference", dn); } + +/* + update an integer attribute safely via a constrained delete/add + */ +int dsdb_module_constrainted_update_integer(struct ldb_module *module, struct ldb_dn *dn, + const char *attr, uint64_t old_val, uint64_t new_val) +{ + struct ldb_message *msg; + struct ldb_message_element *el; + struct ldb_val v1, v2; + int ret; + char *vstring; + + msg = ldb_msg_new(module); + msg->dn = dn; + + ret = ldb_msg_add_empty(msg, attr, LDB_FLAG_MOD_DELETE, &el); + if (ret != LDB_SUCCESS) { + talloc_free(msg); + return ret; + } + el->num_values = 1; + el->values = &v1; + vstring = talloc_asprintf(msg, "%llu", (unsigned long long)old_val); + if (!vstring) { + ldb_module_oom(module); + talloc_free(msg); + return LDB_ERR_OPERATIONS_ERROR; + } + v1 = data_blob_string_const(vstring); + + ret = ldb_msg_add_empty(msg, attr, LDB_FLAG_MOD_ADD, &el); + if (ret != LDB_SUCCESS) { + talloc_free(msg); + return ret; + } + el->num_values = 1; + el->values = &v2; + vstring = talloc_asprintf(msg, "%llu", (unsigned long long)new_val); + if (!vstring) { + ldb_module_oom(module); + talloc_free(msg); + return LDB_ERR_OPERATIONS_ERROR; + } + v2 = data_blob_string_const(vstring); + + ret = dsdb_module_modify(module, msg, 0); + talloc_free(msg); + return ret; +} |