diff options
author | Stefan Metzmacher <metze@samba.org> | 2014-07-30 08:24:10 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2014-08-26 09:13:06 +0200 |
commit | 342a087349f8a10833338a3fa49fbd4d4d29f3e5 (patch) | |
tree | 77d8753d159ca4cefec4b4f0ca09665dcab8d644 /source4 | |
parent | 99d5a5ead4f33723c25e8716a79d34b53822521e (diff) | |
download | samba-342a087349f8a10833338a3fa49fbd4d4d29f3e5.tar.gz |
s4:dns_server: split out dns_common_extract() and dns_common_lookup()
Bug: https://bugzilla.samba.org/show_bug.cgi?id=10749
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4')
-rw-r--r-- | source4/dns_server/dns_utils.c | 45 | ||||
-rw-r--r-- | source4/dns_server/dnsserver_common.c | 78 | ||||
-rw-r--r-- | source4/dns_server/dnsserver_common.h | 13 |
3 files changed, 92 insertions, 44 deletions
diff --git a/source4/dns_server/dns_utils.c b/source4/dns_server/dns_utils.c index 461e58d1add..3bfa98b7621 100644 --- a/source4/dns_server/dns_utils.c +++ b/source4/dns_server/dns_utils.c @@ -154,50 +154,7 @@ WERROR dns_lookup_records(struct dns_server *dns, struct dnsp_DnssrvRpcRecord **records, uint16_t *rec_count) { - static const char * const attrs[] = { "dnsRecord", NULL}; - struct ldb_message_element *el; - uint16_t ri; - int ret; - struct ldb_message *msg = NULL; - struct dnsp_DnssrvRpcRecord *recs; - - *records = NULL; - *rec_count = 0; - - ret = dsdb_search_one(dns->samdb, mem_ctx, &msg, dn, - LDB_SCOPE_BASE, attrs, 0, "%s", "(objectClass=dnsNode)"); - if (ret == LDB_ERR_NO_SUCH_OBJECT) { - return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST; - } - if (ret != LDB_SUCCESS) { - /* TODO: we need to check if there's a glue record we need to - * create a referral to */ - return DNS_ERR(NAME_ERROR); - } - - el = ldb_msg_find_element(msg, attrs[0]); - if (el == NULL) { - return DNS_ERR(NAME_ERROR); - } - - recs = talloc_zero_array(mem_ctx, struct dnsp_DnssrvRpcRecord, el->num_values); - if (recs == NULL) { - return WERR_NOMEM; - } - for (ri = 0; ri < el->num_values; ri++) { - struct ldb_val *v = &el->values[ri]; - enum ndr_err_code ndr_err; - - ndr_err = ndr_pull_struct_blob(v, recs, &recs[ri], - (ndr_pull_flags_fn_t)ndr_pull_dnsp_DnssrvRpcRecord); - if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { - DEBUG(0, ("Failed to grab dnsp_DnssrvRpcRecord\n")); - return DNS_ERR(SERVER_FAILURE); - } - } - *records = recs; - *rec_count = el->num_values; - return WERR_OK; + return dns_common_lookup(dns->samdb, mem_ctx, dn, records, rec_count); } WERROR dns_replace_records(struct dns_server *dns, diff --git a/source4/dns_server/dnsserver_common.c b/source4/dns_server/dnsserver_common.c index 997ce034509..c1d08b23176 100644 --- a/source4/dns_server/dnsserver_common.c +++ b/source4/dns_server/dnsserver_common.c @@ -66,3 +66,81 @@ uint8_t werr_to_dns_err(WERROR werr) DEBUG(5, ("No mapping exists for %s\n", win_errstr(werr))); return DNS_RCODE_SERVFAIL; } + +WERROR dns_common_extract(const struct ldb_message_element *el, + TALLOC_CTX *mem_ctx, + struct dnsp_DnssrvRpcRecord **records, + uint16_t *num_records) +{ + uint16_t ri; + struct dnsp_DnssrvRpcRecord *recs; + + *records = NULL; + *num_records = 0; + + recs = talloc_zero_array(mem_ctx, struct dnsp_DnssrvRpcRecord, + el->num_values); + if (recs == NULL) { + return WERR_NOMEM; + } + for (ri = 0; ri < el->num_values; ri++) { + struct ldb_val *v = &el->values[ri]; + enum ndr_err_code ndr_err; + + ndr_err = ndr_pull_struct_blob(v, recs, &recs[ri], + (ndr_pull_flags_fn_t)ndr_pull_dnsp_DnssrvRpcRecord); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + TALLOC_FREE(recs); + DEBUG(0, ("Failed to grab dnsp_DnssrvRpcRecord\n")); + return DNS_ERR(SERVER_FAILURE); + } + } + *records = recs; + *num_records = el->num_values; + return WERR_OK; +} + +WERROR dns_common_lookup(struct ldb_context *samdb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn, + struct dnsp_DnssrvRpcRecord **records, + uint16_t *num_records) +{ + static const char * const attrs[] = { + "dnsRecord", + NULL + }; + int ret; + WERROR werr; + struct ldb_message *msg = NULL; + struct ldb_message_element *el; + + *records = NULL; + *num_records = 0; + + ret = dsdb_search_one(samdb, mem_ctx, &msg, dn, + LDB_SCOPE_BASE, attrs, 0, + "(objectClass=dnsNode)"); + if (ret == LDB_ERR_NO_SUCH_OBJECT) { + return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST; + } + if (ret != LDB_SUCCESS) { + /* TODO: we need to check if there's a glue record we need to + * create a referral to */ + return DNS_ERR(NAME_ERROR); + } + + el = ldb_msg_find_element(msg, "dnsRecord"); + if (el == NULL) { + TALLOC_FREE(msg); + return DNS_ERR(NAME_ERROR); + } + + werr = dns_common_extract(el, mem_ctx, records, num_records); + TALLOC_FREE(msg); + if (!W_ERROR_IS_OK(werr)) { + return werr; + } + + return WERR_OK; +} diff --git a/source4/dns_server/dnsserver_common.h b/source4/dns_server/dnsserver_common.h index 41febe28d39..4731780eea6 100644 --- a/source4/dns_server/dnsserver_common.h +++ b/source4/dns_server/dnsserver_common.h @@ -25,4 +25,17 @@ uint8_t werr_to_dns_err(WERROR werr); #define DNS_ERR(err_str) WERR_DNS_ERROR_RCODE_##err_str +struct ldb_message_element; + +WERROR dns_common_extract(const struct ldb_message_element *el, + TALLOC_CTX *mem_ctx, + struct dnsp_DnssrvRpcRecord **records, + uint16_t *num_records); + +WERROR dns_common_lookup(struct ldb_context *samdb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn, + struct dnsp_DnssrvRpcRecord **records, + uint16_t *num_records); + #endif /* __DNSSERVER_COMMON_H__ */ |