--- pdns-2.9.20-svn/modules/ldapbackend/powerldap.hh	2005-11-12 18:25:18.000000000 +0100
+++ pdns-svn.new/modules/ldapbackend/powerldap.hh	2005-11-06 19:20:54.000000000 +0100
@@ -29,6 +29,16 @@
 #include <lber.h>
 #include <ldap.h>
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <sys/types.h>
+#endif
+
 
 
 #ifndef POWERLDAP_HH
@@ -69,7 +79,7 @@
 	typedef map<string, vector<string> > sentry_t;
 	typedef vector<sentry_t> sresult_t;
 
-	PowerLDAP( const string& host = "127.0.0.1", uint16_t port = LDAP_PORT, bool tls = false );
+	PowerLDAP( const string& hosts = "ldap://127.0.0.1/", uint16_t port = LDAP_PORT, bool tls = false );
 	~PowerLDAP();
 
 	void getOption( int option, int* value );
--- pdns-2.9.20-svn/modules/ldapbackend/powerldap.cc	2005-11-12 18:25:18.000000000 +0100
+++ pdns-svn.new/modules/ldapbackend/powerldap.cc	2005-10-30 12:04:21.000000000 +0100
@@ -2,13 +2,23 @@
 
 
 
-PowerLDAP::PowerLDAP( const string& host, uint16_t port, bool tls )
+PowerLDAP::PowerLDAP( const string& hosts, uint16_t port, bool tls )
 {
 	int protocol = LDAP_VERSION3;
 
-	if( ( d_ld = ldap_init( host.c_str(), port ) ) == NULL )
+
+	if( ldap_initialize( &d_ld, hosts.c_str() ) != LDAP_SUCCESS )
 	{
-		throw LDAPException( "Error initializing LDAP connection: " + string( strerror( errno ) ) );
+		if( ( d_ld = ldap_init( hosts.c_str(), port ) ) == NULL )
+		{
+			throw LDAPException( "Error initializing LDAP connection: " + string( strerror( errno ) ) );
+		}
+
+		if( tls && ldap_start_tls_s( d_ld, NULL, NULL ) != LDAP_SUCCESS )
+		{
+			ldap_unbind( d_ld );
+			throw( LDAPException( "Couldn't perform STARTTLS" ) );
+		}
 	}
 
 	if( ldap_set_option( d_ld, LDAP_OPT_PROTOCOL_VERSION, &protocol ) != LDAP_OPT_SUCCESS )
@@ -20,12 +30,6 @@
 			throw LDAPException( "Couldn't set protocol version to LDAPv3 or LDAPv2" );
 		}
 	}
-
-	if( tls && ldap_start_tls_s( d_ld, NULL, NULL ) != LDAP_SUCCESS )
-	{
-		ldap_unbind( d_ld );
-		throw( LDAPException( "Couldn't perform STARTTLS" ) );
-	}
 }
 
 
--- pdns-2.9.20-svn/modules/ldapbackend/ldapbackend.hh	2005-11-12 18:25:18.000000000 +0100
+++ pdns-svn.new/modules/ldapbackend/ldapbackend.hh	2005-11-06 19:32:00.000000000 +0100
@@ -36,6 +36,16 @@
 #include "powerldap.hh"
 #include "utils.hh"
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <sys/types.h>
+#endif
+
 
 #ifndef LDAPBACKEND_HH
 #define LDAPBACKEND_HH
@@ -81,7 +91,6 @@
 	unsigned int m_axfrqlen;
 	string m_myname;
 	string m_qname;
-	QType m_qtype;
 	PowerLDAP* m_pldap;
 	PowerLDAP::sentry_t m_result;
 	PowerLDAP::sentry_t::iterator m_attribute;
@@ -102,6 +111,8 @@
 	bool prepare();
 	bool prepare_simple();
 	bool prepare_strict();
+	
+	bool getDomainInfo( const string& domain, DomainInfo& di );
 
 public:
 
--- pdns-2.9.20-svn/modules/ldapbackend/ldapbackend.cc	2005-11-12 18:25:18.000000000 +0100
+++ pdns-svn.new/modules/ldapbackend/ldapbackend.cc	2005-11-06 19:31:43.000000000 +0100
@@ -10,7 +10,6 @@
 {
 	string hoststr;
 	unsigned int i, idx;
-	string::size_type end, begin = 0;
 	vector<string> hosts;
 
 
@@ -24,7 +23,6 @@
 		m_myname = "[LdapBackend]";
 
 		setArgPrefix( "ldap" + suffix );
-		hoststr = getArg( "host" );
 
 		m_getdn = false;
 		m_list_fcnt = &LdapBackend::list_simple;
@@ -43,13 +41,7 @@
 			m_prepare_fcnt = &LdapBackend::prepare_strict;
 		}
 
-		while( ( end = hoststr.find_first_of( ", \t\n", begin ) ) != string::npos )
-		{
-			hosts.push_back( hoststr.substr( begin, end - begin ) );
-			begin = end + 1;
-		}
-		hosts.push_back( hoststr.substr( begin, hoststr.length() - begin ) );
-
+		stringtok( hosts, getArg( "host" ), ", " );
 		idx = ldap_host_index++ % hosts.size();
 		hoststr = hosts[idx];
 
@@ -171,7 +163,6 @@
 	try
 	{
 		m_axfrqlen = 0;
-		m_qtype = qtype;
 		m_qname = qname;
 		m_adomain = m_adomains.end();   // skip loops in get() first time
 
@@ -479,6 +470,38 @@
 
 
 
+ bool LdapBackend::getDomainInfo( const string& domain, DomainInfo& di )
+{
+	string filter;
+	SOAData sd;
+	char* attronly[] = { "sOARecord", NULL };
+
+
+	// search for SOARecord of domain
+	filter = "(&(associatedDomain=" + toLower( m_pldap->escape( domain ) ) + ")(SOARecord=*))";
+	m_msgid = m_pldap->search( getArg( "basedn" ), LDAP_SCOPE_SUBTREE, filter, (const char**) attronly );
+	m_pldap->getSearchEntry( m_msgid, m_result );
+
+	if( m_result.count( "sOARecord" ) && !m_result["sOARecord"].empty() )
+	{
+		sd.serial = 0;
+		DNSPacket::fillSOAData( m_result["sOARecord"][0], sd );
+	
+		di.id = 0;
+		di.serial = sd.serial;
+		di.zone = domain;
+		di.last_check = 0;
+		di.backend = this;
+		di.kind = DomainInfo::Master;
+
+		return true;
+	}
+	
+	return false;
+}
+
+
+
 
 
 class LdapFactory : public BackendFactory
@@ -491,8 +514,8 @@
 
 	void declareArguments( const string &suffix="" )
 	{
-		declare( suffix, "host", "One or more ldap server","127.0.0.1:389" );
-		declare( suffix, "starttls", "Use TLS to encrypt connection", "no" );
+		declare( suffix, "host", "One or more LDAP server with ports or LDAP URIs (separated by spaces)","ldap://127.0.0.1:389/" );
+		declare( suffix, "starttls", "Use TLS to encrypt connection (unused for LDAP URIs)", "no" );
 		declare( suffix, "basedn", "Search root in ldap tree (must be set)","" );
 		declare( suffix, "binddn", "User dn for non anonymous binds","" );
 		declare( suffix, "secret", "User password for non anonymous binds", "" );
