1
0
mirror of https://github.com/samba-team/samba.git synced 2025-07-23 20:59:10 +03:00

s4:dlz_bind9: let dlz_bind9 use dns_common_lookup() for name lookup

Bug: https://bugzilla.samba.org/show_bug.cgi?id=10749

Change-Id: I2632fa0ce120a978f6f400fa5cbf18a7fbbd64a3
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Stefan Metzmacher
2014-07-30 08:40:32 +02:00
parent 914a366747
commit 96dcebe8c2
2 changed files with 21 additions and 53 deletions

View File

@ -38,7 +38,7 @@
#include "lib/cmdline/popt_common.h"
#include "lib/util/dlinklist.h"
#include "dlz_minimal.h"
#include "dns_server/dnsserver_common.h"
struct b9_options {
const char *url;
@ -808,11 +808,10 @@ static isc_result_t dlz_lookup_types(struct dlz_bind9_data *state,
const char **types)
{
TALLOC_CTX *tmp_ctx = talloc_new(state);
const char *attrs[] = { "dnsRecord", NULL };
int ret = LDB_SUCCESS, i;
struct ldb_result *res;
struct ldb_message_element *el;
struct ldb_dn *dn;
WERROR werr = WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
struct dnsp_DnssrvRpcRecord *records = NULL;
uint16_t num_records = 0, i;
for (i=0; zone_prefixes[i]; i++) {
dn = ldb_dn_copy(tmp_ctx, ldb_get_default_basedn(state->samdb));
@ -826,38 +825,21 @@ static isc_result_t dlz_lookup_types(struct dlz_bind9_data *state,
return ISC_R_NOMEMORY;
}
ret = ldb_search(state->samdb, tmp_ctx, &res, dn, LDB_SCOPE_BASE,
attrs, "objectClass=dnsNode");
if (ret == LDB_SUCCESS) {
werr = dns_common_lookup(state->samdb, tmp_ctx, dn,
&records, &num_records, NULL);
if (W_ERROR_IS_OK(werr)) {
break;
}
}
if (ret != LDB_SUCCESS || res->count == 0) {
if (!W_ERROR_IS_OK(werr)) {
talloc_free(tmp_ctx);
return ISC_R_NOTFOUND;
}
el = ldb_msg_find_element(res->msgs[0], "dnsRecord");
if (el == NULL || el->num_values == 0) {
talloc_free(tmp_ctx);
return ISC_R_NOTFOUND;
}
for (i=0; i<el->num_values; i++) {
struct dnsp_DnssrvRpcRecord rec;
enum ndr_err_code ndr_err;
for (i=0; i < num_records; i++) {
isc_result_t result;
ndr_err = ndr_pull_struct_blob(&el->values[i], tmp_ctx, &rec,
(ndr_pull_flags_fn_t)ndr_pull_dnsp_DnssrvRpcRecord);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
state->log(ISC_LOG_ERROR, "samba_dlz: failed to parse dnsRecord for %s",
ldb_dn_get_linearized(dn));
talloc_free(tmp_ctx);
return ISC_R_FAILURE;
}
result = b9_putrr(state, lookup, &rec, types);
result = b9_putrr(state, lookup, &records[i], types);
if (result != ISC_R_SUCCESS) {
talloc_free(tmp_ctx);
return result;
@ -1066,39 +1048,25 @@ _PUBLIC_ void dlz_closeversion(const char *zone, isc_boolean_t commit,
*/
static bool b9_has_soa(struct dlz_bind9_data *state, struct ldb_dn *dn, const char *zone)
{
const char *attrs[] = { "dnsRecord", NULL };
struct ldb_result *res;
struct ldb_message_element *el;
TALLOC_CTX *tmp_ctx = talloc_new(state);
int ret, i;
WERROR werr;
struct dnsp_DnssrvRpcRecord *records = NULL;
uint16_t num_records = 0, i;
if (!ldb_dn_add_child_fmt(dn, "DC=@,DC=%s", zone)) {
talloc_free(tmp_ctx);
return false;
}
ret = ldb_search(state->samdb, tmp_ctx, &res, dn, LDB_SCOPE_BASE,
attrs, "objectClass=dnsNode");
if (ret != LDB_SUCCESS) {
werr = dns_common_lookup(state->samdb, tmp_ctx, dn,
&records, &num_records, NULL);
if (!W_ERROR_IS_OK(werr)) {
talloc_free(tmp_ctx);
return false;
}
el = ldb_msg_find_element(res->msgs[0], "dnsRecord");
if (el == NULL) {
talloc_free(tmp_ctx);
return false;
}
for (i=0; i<el->num_values; i++) {
struct dnsp_DnssrvRpcRecord rec;
enum ndr_err_code ndr_err;
ndr_err = ndr_pull_struct_blob(&el->values[i], tmp_ctx, &rec,
(ndr_pull_flags_fn_t)ndr_pull_dnsp_DnssrvRpcRecord);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
continue;
}
if (rec.wType == DNS_TYPE_SOA) {
for (i=0; i < num_records; i++) {
if (records[i].wType == DNS_TYPE_SOA) {
talloc_free(tmp_ctx);
return true;
}

View File

@ -24,7 +24,7 @@ bld.SAMBA_LIBRARY('dlz_bind9',
link_name='modules/bind9/dlz_bind9.so',
realname='dlz_bind9.so',
install_path='${MODULESDIR}/bind9',
deps='samba-hostconfig samdb-common gensec popt',
deps='samba-hostconfig samdb-common gensec popt dnsserver_common',
enabled=bld.AD_DC_BUILD_IS_ENABLED())
bld.SAMBA_LIBRARY('dlz_bind9_9',
@ -34,12 +34,12 @@ bld.SAMBA_LIBRARY('dlz_bind9_9',
link_name='modules/bind9/dlz_bind9_9.so',
realname='dlz_bind9_9.so',
install_path='${MODULESDIR}/bind9',
deps='samba-hostconfig samdb-common gensec popt',
deps='samba-hostconfig samdb-common gensec popt dnsserver_common',
enabled=bld.AD_DC_BUILD_IS_ENABLED())
bld.SAMBA_LIBRARY('dlz_bind9_for_torture',
source='dlz_bind9.c',
cflags='-DBIND_VERSION_9_8',
private_library=True,
deps='samba-hostconfig samdb-common gensec popt',
deps='samba-hostconfig samdb-common gensec popt dnsserver_common',
enabled=bld.AD_DC_BUILD_IS_ENABLED())