From f5b041fc04f158d0462995d592359fa6bd74b2ff Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Mon, 27 Feb 2012 17:09:10 +1100 Subject: dlz_bind9: This fixes the problem with adding/deleting rdataset Fix commit 169db333033b72b6f9ac1e7b23f0f2c151218c1f. This change allowed for LDB records without dnsRecord attribute to exist to prevent large number of deleted records. This change fixes the handling of missing dnsRecord attribute and correctly deleting dnsRecord attribute. --- source4/dns_server/dlz_bind9.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'source4/dns_server') diff --git a/source4/dns_server/dlz_bind9.c b/source4/dns_server/dlz_bind9.c index 34320e01f6..6b38bc31dc 100644 --- a/source4/dns_server/dlz_bind9.c +++ b/source4/dns_server/dlz_bind9.c @@ -1458,17 +1458,20 @@ _PUBLIC_ isc_result_t dlz_addrdataset(const char *name, const char *rdatastr, vo return result; } - /* there are existing records. We need to see if this will - * replace a record or add to it - */ el = ldb_msg_find_element(res->msgs[0], "dnsRecord"); if (el == NULL) { - state->log(ISC_LOG_ERROR, "samba_dlz: no dnsRecord attribute for %s", - ldb_dn_get_linearized(dn)); - talloc_free(rec); - return ISC_R_FAILURE; + ret = ldb_msg_add_empty(res->msgs[0], "dnsRecord", LDB_FLAG_MOD_ADD, &el); + if (ret != LDB_SUCCESS) { + state->log(ISC_LOG_ERROR, "samba_dlz: failed to add dnsRecord for %s", + ldb_dn_get_linearized(dn)); + talloc_free(rec); + return ISC_R_FAILURE; + } } + /* there are existing records. We need to see if this will + * replace a record or add to it + */ for (i=0; inum_values; i++) { struct dnsp_DnssrvRpcRecord rec2; @@ -1614,9 +1617,10 @@ _PUBLIC_ isc_result_t dlz_subrdataset(const char *name, const char *rdatastr, vo } if (el->num_values == 0) { - ldb_msg_remove_element(res->msgs[0], el); + el->flags = LDB_FLAG_MOD_DELETE; + } else { + el->flags = LDB_FLAG_MOD_REPLACE; } - el->flags = LDB_FLAG_MOD_REPLACE; ret = ldb_modify(state->samdb, res->msgs[0]); b9_reset_session_info(state); @@ -1719,9 +1723,10 @@ _PUBLIC_ isc_result_t dlz_delrdataset(const char *name, const char *type, void * } if (el->num_values == 0) { - ldb_msg_remove_element(res->msgs[0], el); + el->flags = LDB_FLAG_MOD_DELETE; + } else { + el->flags = LDB_FLAG_MOD_REPLACE; } - el->flags = LDB_FLAG_MOD_REPLACE; ret = ldb_modify(state->samdb, res->msgs[0]); b9_reset_session_info(state); -- cgit