summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--ldap_driver.c32
-rw-r--r--rdlist.c108
-rw-r--r--rdlist.h28
4 files changed, 141 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index 672e5e0..beb152c 100644
--- a/Makefile
+++ b/Makefile
@@ -5,8 +5,8 @@ LIBMINOR = 0
LIBNAME = libdnsldap.so.$(LIBMAJOR).$(LIBMINOR).0
LIBSONAME = libdnsldap.so.$(LIBMAJOR)
-OBJS = ldap_driver.o semaphore.o ldap_convert.o ldap_helper.o log.o settings.o
-OBJS += str.o zone_manager.o
+OBJS = ldap_driver.o semaphore.o ldap_convert.o ldap_helper.o log.o rdlist.o
+OBJS += settings.o str.o zone_manager.o
CFLAGS := -Wall -Wextra -pedantic -std=c99 -g -fPIC $(CFLAGS)
diff --git a/ldap_driver.c b/ldap_driver.c
index 05f2c91..f63cf59 100644
--- a/ldap_driver.c
+++ b/ldap_driver.c
@@ -33,6 +33,7 @@
#include "ldap_helper.h"
#include "log.h"
+#include "rdlist.h"
#include "util.h"
#include "zone_manager.h"
@@ -107,38 +108,11 @@ clone_rdatalist_to_rdataset(isc_mem_t *mctx, dns_rdatalist_t *rdlist,
dns_rdataset_t *rdataset)
{
isc_result_t result;
- dns_rdatalist_t *new_rdlist;
- dns_rdata_t *rdata;
- dns_rdata_t *new_rdata;
+ dns_rdatalist_t *new_rdlist = NULL;
REQUIRE(mctx != NULL);
- CHECKED_MEM_GET_PTR(mctx, new_rdlist);
-
- new_rdlist->rdclass = rdlist->rdclass;
- new_rdlist->type = rdlist->type;
- new_rdlist->covers = rdlist->covers;
- new_rdlist->ttl = rdlist->ttl;
-
- INIT_LIST(new_rdlist->rdata);
- INIT_LINK(new_rdlist, link);
-
- for (rdata = HEAD(rdlist->rdata);
- rdata != NULL;
- rdata = NEXT(rdata, link)) {
- CHECKED_MEM_GET_PTR(mctx, new_rdata);
- ZERO_PTR(new_rdata);
-
- CHECKED_MEM_GET(mctx, new_rdata->data, rdata->length);
- memcpy(new_rdata->data, rdata->data, rdata->length);
- new_rdata->length = rdata->length;
- new_rdata->rdclass = rdata->rdclass;
- new_rdata->type = rdata->type;
- new_rdata->flags = rdata->flags;
- INIT_LINK(new_rdata, link);
-
- APPEND(new_rdlist->rdata, new_rdata, link);
- }
+ CHECK(rdatalist_clone(mctx, rdlist, &new_rdlist));
CHECK(dns_rdatalist_tordataset(new_rdlist, rdataset));
rdataset->methods = &rdataset_methods;
diff --git a/rdlist.c b/rdlist.c
new file mode 100644
index 0000000..3976858
--- /dev/null
+++ b/rdlist.c
@@ -0,0 +1,108 @@
+/* Authors: Adam Tkac <atkac@redhat.com>
+ * Martin Nagy <mnagy@redhat.com>
+ *
+ * Copyright (C) 2009 Red Hat
+ * see file 'COPYING' for use and warranty information
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 only
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <isc/mem.h>
+#include <isc/result.h>
+#include <isc/util.h>
+
+#include <dns/rdata.h>
+#include <dns/rdatalist.h>
+
+#include <string.h>
+
+#include "ldap_helper.h" /* TODO: Move things from ldap_helper here? */
+#include "rdlist.h"
+#include "util.h"
+
+
+static isc_result_t
+rdata_clone(isc_mem_t *mctx, dns_rdata_t *source, dns_rdata_t **targetp)
+{
+ isc_result_t result;
+ dns_rdata_t *target = NULL;
+ isc_region_t target_region, source_region;
+
+ REQUIRE(mctx != NULL);
+ REQUIRE(source != NULL);
+ REQUIRE(targetp != NULL && *targetp == NULL);
+
+ CHECKED_MEM_GET_PTR(mctx, target);
+
+ dns_rdata_init(target);
+
+ dns_rdata_toregion(source, &source_region);
+
+ CHECKED_MEM_GET(mctx, target_region.base, source_region.length);
+
+ target_region.length = source_region.length;
+ memcpy(target_region.base, source_region.base, source_region.length);
+ dns_rdata_fromregion(target, source->rdclass, source->type,
+ &target_region);
+
+ *targetp = target;
+
+ return ISC_R_SUCCESS;
+
+cleanup:
+ SAFE_MEM_PUT_PTR(mctx, target);
+
+ return result;
+}
+
+isc_result_t
+rdatalist_clone(isc_mem_t *mctx, dns_rdatalist_t *source,
+ dns_rdatalist_t **targetp)
+{
+ dns_rdatalist_t *target;
+ dns_rdata_t *source_rdata;
+ dns_rdata_t *target_rdata;
+ isc_result_t result;
+
+ REQUIRE(mctx != NULL);
+ REQUIRE(source != NULL);
+ REQUIRE(targetp != NULL && *targetp == NULL);
+
+ CHECKED_MEM_GET_PTR(mctx, target);
+
+ dns_rdatalist_init(target);
+ target->rdclass = source->rdclass;
+ target->type = source->type;
+ target->covers = source->covers;
+ target->ttl = source->ttl;
+
+ source_rdata = HEAD(source->rdata);
+ while (source_rdata != NULL) {
+ target_rdata = NULL;
+ CHECK(rdata_clone(mctx, source_rdata, &target_rdata));
+ APPEND(target->rdata, target_rdata, link);
+ source_rdata = NEXT(source_rdata, link);
+ }
+
+ *targetp = target;
+
+ return ISC_R_SUCCESS;
+
+cleanup:
+ if (target)
+ free_rdatalist(mctx, target);
+ SAFE_MEM_PUT_PTR(mctx, target);
+
+ return result;
+}
diff --git a/rdlist.h b/rdlist.h
new file mode 100644
index 0000000..c9cf7df
--- /dev/null
+++ b/rdlist.h
@@ -0,0 +1,28 @@
+/* Authors: Adam Tkac <atkac@redhat.com>
+ * Martin Nagy <mnagy@redhat.com>
+ *
+ * Copyright (C) 2009 Red Hat
+ * see file 'COPYING' for use and warranty information
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 only
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _LD_RDLIST_H_
+#define _LD_RDLIST_H_
+
+isc_result_t
+rdatalist_clone(isc_mem_t *mctx, dns_rdatalist_t *source,
+ dns_rdatalist_t **targetp);
+
+#endif /* !_LD_RDLIST_H_ */