summaryrefslogtreecommitdiffstats
path: root/ldap_driver.c
diff options
context:
space:
mode:
authorAdam Tkac <atkac@redhat.com>2008-12-18 12:33:37 +0100
committerMartin Nagy <mnagy@redhat.com>2008-12-18 13:04:34 +0100
commit775589b664fd810d3617b9a995fdce2cb5e92f52 (patch)
treec204b4fbff77d8c272e9e06da666322e3fdcbe11 /ldap_driver.c
parent58b836cf410a1204894ab254f7e1f726f2f7a684 (diff)
downloadldap_driver_testing-775589b664fd810d3617b9a995fdce2cb5e92f52.tar.gz
ldap_driver_testing-775589b664fd810d3617b9a995fdce2cb5e92f52.tar.xz
ldap_driver_testing-775589b664fd810d3617b9a995fdce2cb5e92f52.zip
- added ldapdb_create function which creates per-zone dns_db_t - document what should ldap zone manager do
Diffstat (limited to 'ldap_driver.c')
-rw-r--r--ldap_driver.c113
1 files changed, 103 insertions, 10 deletions
diff --git a/ldap_driver.c b/ldap_driver.c
index ccb5be9..44b4fca 100644
--- a/ldap_driver.c
+++ b/ldap_driver.c
@@ -43,7 +43,14 @@
typedef struct {
dns_db_t common;
isc_refcount_t refs;
- isc_mem_t *mctx;
+ isc_mutex_t lock; /* convert to isc_rwlock_t ? */
+ /*
+ * XXX LDAP:
+ *
+ * Add connection specification here - probably pointer to one shared
+ * connection info for multiple zones? Will be used by all
+ * ldapdb_methods to take information from LDAP.
+ */
} ldapdb_t;
typedef struct {
@@ -73,6 +80,8 @@ ldapdbnode_create(isc_mem_t *mctx, ldapdbnode_t **nodep)
dns_name_init(node->owner, NULL);
+ *nodep = node;
+
return ISC_R_SUCCESS;
cleanup:
@@ -83,9 +92,9 @@ cleanup:
static void
ldapdbnode_destroy(isc_mem_t *mctx, ldapdbnode_t **nodep)
{
- UNUSED(mctx);
- UNUSED(nodep);
- /* XXX Do it */
+ REQUIRE(nodep != NULL && VALID_LDAPDBNODE(*nodep));
+
+ isc_mem_put(mctx, *nodep, sizeof (**nodep));
}
/*
@@ -132,7 +141,6 @@ beginload(dns_db_t *db, dns_addrdatasetfunc_t *addp, dns_dbload_t **dbloadp)
UNUSED(addp);
UNUSED(dbloadp);
- /* Should be never called */
fatal_error("ldapdb: method beginload() should never be called");
/* Not reached */
@@ -146,7 +154,6 @@ endload(dns_db_t *db, dns_dbload_t **dbloadp)
UNUSED(db);
UNUSED(dbloadp);
- /* Should be never called */
fatal_error("ldapdb: method endload() should never be called");
/* Not reached */
@@ -163,7 +170,6 @@ dump(dns_db_t *db, dns_dbversion_t *version, const char *filename,
UNUSED(filename);
UNUSED(masterformat);
- /* Should be never called */
fatal_error("ldapdb: method dump() should never be called");
/* Not reached */
@@ -562,6 +568,73 @@ static dns_dbmethods_t ldapdb_methods = {
getrrsetstats
};
+static isc_result_t
+ldapdb_create(isc_mem_t *mctx, dns_name_t *name, dns_dbtype_t type,
+ dns_rdataclass_t rdclass, unsigned int argc, char *argv[],
+ void *driverarg, dns_db_t **dbp)
+{
+ ldapdb_t *ldapdb;
+ isc_result_t result;
+
+ UNUSED(driverarg); /* Currently we don't need any data */
+
+ /* LDAP server has to be specified at least */
+ REQUIRE(argc > 0);
+
+ REQUIRE(type == dns_dbtype_zone);
+ REQUIRE(rdclass == dns_rdataclass_in);
+ REQUIRE(dbp != NULL && *dbp == NULL);
+
+ ldapdb = isc_mem_get(mctx, sizeof(*ldapdb));
+ if (ldapdb == NULL)
+ return ISC_R_NOMEMORY;
+
+ ldapdb->common.methods = &ldapdb_methods;
+ ldapdb->common.attributes = 0;
+ ldapdb->common.rdclass = rdclass;
+
+ dns_name_init(&ldapdb->common.origin, NULL);
+ result = dns_name_dupwithoffsets(name, mctx, &ldapdb->common.origin);
+ if (result != ISC_R_SUCCESS)
+ goto clean_ldapdb;
+
+ isc_ondestroy_init(&ldapdb->common.ondest);
+ isc_mem_attach(mctx, &ldapdb->common.mctx);
+
+ result = isc_mutex_init(&ldapdb->lock);
+ if (result != ISC_R_SUCCESS)
+ goto clean_origin;
+
+ result = isc_refcount_init(&ldapdb->refs, 1);
+ if (result != ISC_R_SUCCESS)
+ goto clean_lock;
+
+ /*
+ * XXX LDAP:
+ *
+ * Now we have to setup connection info. Parameters passed in
+ * configuration file are in arg && argv. So use them and setup
+ * per-zone connection (will be used by ldapdb_methods). Parameters were
+ * passed by ldap zone manager and by dns_zone_setdbtype method.
+ */
+
+ ldapdb->common.magic = DNS_DB_MAGIC;
+ ldapdb->common.impmagic = LDAPDB_MAGIC;
+
+ *dbp = (dns_db_t *)ldapdb;
+
+ return ISC_R_SUCCESS;
+
+clean_lock:
+ DESTROYLOCK(&ldapdb->lock);
+clean_origin:
+ dns_name_free(&ldapdb->common.origin, mctx);
+clean_ldapdb:
+ isc_mem_put(mctx, ldapdb, sizeof(*ldapdb));
+
+ return result;
+}
+
static dns_dbimplementation_t *ldapdb_imp;
static const char *ldapdb_impname = "dynamic-ldap";
@@ -582,15 +655,35 @@ dynamic_driver_init(isc_mem_t *mctx, const char *name, const char * const *argv,
argv++;
}
- result = dns_db_register(ldapdb_impname, NULL, NULL, mctx, &ldapdb_imp);
+ result = dns_db_register(ldapdb_impname, &ldapdb_create, NULL, mctx,
+ &ldapdb_imp);
if (result == ISC_R_EXISTS)
result = ISC_R_SUCCESS;
if (result != ISC_R_SUCCESS)
return result;
- /* XXX now fetch all zones and initialize ldap zone manager
- * (periodically check for new zones) */
+ /*
+ * XXX now fetch all zones and initialize ldap zone manager
+ * (periodically check for new zones)
+ * - manager has to share server zonemgr (ns_g_server->zonemgr)
+ *
+ * XXX manager has to this this for each zone:
+ * - dns_zone_create
+ * - dns_zone_setorigin
+ * - dns_zone_setview
+ * - dns_zone_setacache (probably not needed)
+ * - dns_zone_setclass
+ * - dns_zone_settype
+ * - dns_zone_setdbtype (note: pass all connection arguments etc here -
+ * will be used by ldapdb_create)
+ * - continue as in bin/server.c - ns_zone_configure()
+ * - dns_zonemgr_managezone
+ *
+ * zone has to be bind-ed to specified view:
+ * - dns_view_findzone (check if zone already exists)
+ * - dns_view_addzone
+ */
return ISC_R_SUCCESS;
}