mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
s4 dns: Move record lookup to dns_utils.c
This commit is contained in:
parent
0922953b10
commit
8b82bad006
@ -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);
|
||||
}
|
||||
werror = dns_lookup_records(dns, mem_ctx, dn, &recs, &rec_count);
|
||||
W_ERROR_NOT_OK_RETURN(werror);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user