summaryrefslogtreecommitdiff
path: root/source4/dns_server
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2011-12-16 09:43:47 +0100
committerKai Blin <kai@samba.org>2011-12-17 02:46:08 +0100
commit8b82bad0065895e0417f095c6b9ed2ada31fbdaa (patch)
tree33c534de5a01387f5fc6f3097b350dfaa00ca793 /source4/dns_server
parent0922953b10f3495e5d62867025e7e99ebc3e6613 (diff)
downloadsamba-8b82bad0065895e0417f095c6b9ed2ada31fbdaa.tar.gz
samba-8b82bad0065895e0417f095c6b9ed2ada31fbdaa.tar.bz2
samba-8b82bad0065895e0417f095c6b9ed2ada31fbdaa.zip
s4 dns: Move record lookup to dns_utils.c
Diffstat (limited to 'source4/dns_server')
-rw-r--r--source4/dns_server/dns_query.c43
-rw-r--r--source4/dns_server/dns_server.h5
-rw-r--r--source4/dns_server/dns_utils.c46
3 files changed, 58 insertions, 36 deletions
diff --git a/source4/dns_server/dns_query.c b/source4/dns_server/dns_query.c
index b233b25a81..5320e21f5c 100644
--- a/source4/dns_server/dns_query.c
+++ b/source4/dns_server/dns_query.c
@@ -89,48 +89,22 @@ static WERROR handle_question(struct dns_server *dns,
struct dns_res_rec **answers, uint16_t *ancount)
{
struct dns_res_rec *ans;
- struct ldb_dn *dn = NULL;
WERROR werror;
- static const char * const attrs[] = { "dnsRecord", NULL};
- int ret;
- uint16_t ai = *ancount;
unsigned int ri;
- struct ldb_message *msg = NULL;
struct dnsp_DnssrvRpcRecord *recs;
- struct ldb_message_element *el;
+ uint16_t rec_count, ai = 0;
+ struct ldb_dn *dn = NULL;
werror = dns_name2dn(dns, mem_ctx, question->name, &dn);
W_ERROR_NOT_OK_RETURN(werror);
- ret = dsdb_search_one(dns->samdb, mem_ctx, &msg, dn,
- LDB_SCOPE_BASE, attrs, 0, "%s", "(objectClass=dnsNode)");
- if (ret != LDB_SUCCESS) {
- return DNS_ERR(NAME_ERROR);
- }
-
- el = ldb_msg_find_element(msg, attrs[0]);
- if (el == NULL) {
- return DNS_ERR(NAME_ERROR);
- }
-
- recs = talloc_array(mem_ctx, struct dnsp_DnssrvRpcRecord, el->num_values);
- 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);
- }
- }
+ werror = dns_lookup_records(dns, mem_ctx, dn, &recs, &rec_count);
+ W_ERROR_NOT_OK_RETURN(werror);
- ans = talloc_realloc(mem_ctx, *answers, struct dns_res_rec,
- ai + el->num_values);
+ ans = talloc_zero_array(mem_ctx, struct dns_res_rec, rec_count);
W_ERROR_HAVE_NO_MEMORY(ans);
- for (ri = 0; ri < el->num_values; ri++) {
+ for (ri = 0; ri < rec_count; ri++) {
if ((question->question_type != DNS_QTYPE_ALL) &&
(recs[ri].wType != question->question_type)) {
continue;
@@ -138,7 +112,7 @@ static WERROR handle_question(struct dns_server *dns,
create_response_rr(question, &recs[ri], &ans, &ai);
}
- if (*ancount == ai) {
+ if (ai == 0) {
return DNS_ERR(NAME_ERROR);
}
@@ -169,9 +143,6 @@ WERROR dns_server_process_query(struct dns_server *dns,
return DNS_ERR(NOT_IMPLEMENTED);
}
- ans = talloc_array(mem_ctx, struct dns_res_rec, 0);
- W_ERROR_HAVE_NO_MEMORY(ans);
-
werror = handle_question(dns, mem_ctx, &in->questions[0], &ans, &num_answers);
W_ERROR_NOT_OK_GOTO(werror, query_failed);
diff --git a/source4/dns_server/dns_server.h b/source4/dns_server/dns_server.h
index 7387641c63..f1e9da5ffd 100644
--- a/source4/dns_server/dns_server.h
+++ b/source4/dns_server/dns_server.h
@@ -59,6 +59,11 @@ bool dns_name_match(const char *zone, const char *name, size_t *host_part_len);
bool dns_name_equal(const char *name1, const char *name2);
bool dns_records_match(struct dnsp_DnssrvRpcRecord *rec1,
struct dnsp_DnssrvRpcRecord *rec2);
+WERROR dns_lookup_records(struct dns_server *dns,
+ TALLOC_CTX *mem_ctx,
+ struct ldb_dn *dn,
+ struct dnsp_DnssrvRpcRecord **records,
+ uint16_t *rec_count);
WERROR dns_name2dn(struct dns_server *dns,
TALLOC_CTX *mem_ctx,
const char *name,
diff --git a/source4/dns_server/dns_utils.c b/source4/dns_server/dns_utils.c
index 5da32c0c53..c0e7ff7583 100644
--- a/source4/dns_server/dns_utils.c
+++ b/source4/dns_server/dns_utils.c
@@ -163,6 +163,52 @@ bool dns_records_match(struct dnsp_DnssrvRpcRecord *rec1,
return false;
}
+WERROR dns_lookup_records(struct dns_server *dns,
+ TALLOC_CTX *mem_ctx,
+ struct ldb_dn *dn,
+ 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;
+
+ ret = dsdb_search_one(dns->samdb, mem_ctx, &msg, dn,
+ LDB_SCOPE_BASE, attrs, 0, "%s", "(objectClass=dnsNode)");
+ 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) {
+ *records = NULL;
+ *rec_count = 0;
+ return WERR_OK;
+ }
+
+ recs = talloc_zero_array(mem_ctx, struct dnsp_DnssrvRpcRecord, el->num_values);
+ W_ERROR_HAVE_NO_MEMORY(recs);
+ 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;
+}
+
WERROR dns_name2dn(struct dns_server *dns,
TALLOC_CTX *mem_ctx,
const char *name,