X-Git-Url: http://git.samba.org/?p=samba.git;a=blobdiff_plain;f=source4%2Fdsdb%2Fsamdb%2Fsamdb.c;h=2fcc71a8a90d942e2f71d74f98ee583d15052c9b;hp=209599b9dc977bb2c4353440fe1e89f82a71fc2f;hb=77529ae7926e2d299e7703c5f1b84cb849b4563b;hpb=b29b10e48ee351c19cb7a0e9766718fa1715f747 diff --git a/source4/dsdb/samdb/samdb.c b/source4/dsdb/samdb/samdb.c index 209599b9dc9..2fcc71a8a90 100644 --- a/source4/dsdb/samdb/samdb.c +++ b/source4/dsdb/samdb/samdb.c @@ -710,6 +710,60 @@ int samdb_msg_add_delete(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg return ldb_msg_add_empty(sam_ctx->ldb, msg, a, LDB_FLAG_MOD_REPLACE); } +/* + add a add attribute value to a message +*/ +int samdb_msg_add_addval(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, const char *value) +{ + struct ldb_wrap *sam_ctx = ctx; + struct ldb_message_element *el; + char *a, *v; + int ret; + a = talloc_strdup(mem_ctx, attr_name); + if (a == NULL) + return -1; + v = talloc_strdup(mem_ctx, value); + if (v == NULL) + return -1; + ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx); + ret = ldb_msg_add_string(sam_ctx->ldb, msg, a, v); + if (ret != 0) + return ret; + el = ldb_msg_find_element(msg, a); + if (el == NULL) + return -1; + el->flags = LDB_FLAG_MOD_ADD; + return 0; +} + +/* + add a delete attribute value to a message +*/ +int samdb_msg_add_delval(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, const char *value) +{ + struct ldb_wrap *sam_ctx = ctx; + struct ldb_message_element *el; + char *a, *v; + int ret; + a = talloc_strdup(mem_ctx, attr_name); + if (a == NULL) + return -1; + v = talloc_strdup(mem_ctx, value); + if (v == NULL) + return -1; + ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx); + ret = ldb_msg_add_string(sam_ctx->ldb, msg, a, v); + if (ret != 0) + return ret; + el = ldb_msg_find_element(msg, a); + if (el == NULL) + return -1; + el->flags = LDB_FLAG_MOD_DELETE; + return 0; +} + /* add a uint_t element to a message */