From: Bert Hubert Date: Sun, 15 Jan 2006 21:03:43 +0000 (+0000) Subject: applied Norbert's patch, which closes ticket #37 X-Git-Tag: pdns-2.9.20~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c533708a9e8d29c397d9769f2dd68ce5885d0b9d;p=thirdparty%2Fpdns.git applied Norbert's patch, which closes ticket #37 git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@558 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/modules/ldapbackend/ldapbackend.cc b/modules/ldapbackend/ldapbackend.cc index 96dae35c68..77ddddd7df 100644 --- a/modules/ldapbackend/ldapbackend.cc +++ b/modules/ldapbackend/ldapbackend.cc @@ -10,7 +10,6 @@ LdapBackend::LdapBackend( const string &suffix ) { string hoststr; unsigned int i, idx; - string::size_type end, begin = 0; vector hosts; @@ -24,7 +23,6 @@ LdapBackend::LdapBackend( const string &suffix ) m_myname = "[LdapBackend]"; setArgPrefix( "ldap" + suffix ); - hoststr = getArg( "host" ); m_getdn = false; m_list_fcnt = &LdapBackend::list_simple; @@ -43,13 +41,7 @@ LdapBackend::LdapBackend( const string &suffix ) 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 @@ void LdapBackend::lookup( const QType &qtype, const string &qname, DNSPacket *dn 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::get( DNSResourceRecord &rr ) + 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 @@ public: 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", "" ); diff --git a/modules/ldapbackend/ldapbackend.hh b/modules/ldapbackend/ldapbackend.hh index 50f6dbb88c..13858af895 100644 --- a/modules/ldapbackend/ldapbackend.hh +++ b/modules/ldapbackend/ldapbackend.hh @@ -36,6 +36,16 @@ #include "powerldap.hh" #include "utils.hh" +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_STDINT_H +#include +#else +#include +#endif + #ifndef LDAPBACKEND_HH #define LDAPBACKEND_HH @@ -81,7 +91,6 @@ class LdapBackend : public DNSBackend 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 @@ class LdapBackend : public DNSBackend bool prepare(); bool prepare_simple(); bool prepare_strict(); + + bool getDomainInfo( const string& domain, DomainInfo& di ); public: diff --git a/modules/ldapbackend/powerldap.cc b/modules/ldapbackend/powerldap.cc index 050e592065..7c2abd790f 100644 --- a/modules/ldapbackend/powerldap.cc +++ b/modules/ldapbackend/powerldap.cc @@ -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 @@ PowerLDAP::PowerLDAP( const string& host, uint16_t port, bool tls ) 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" ) ); - } } diff --git a/modules/ldapbackend/powerldap.hh b/modules/ldapbackend/powerldap.hh index 9e53ec9d9f..c58bc870d6 100644 --- a/modules/ldapbackend/powerldap.hh +++ b/modules/ldapbackend/powerldap.hh @@ -29,6 +29,16 @@ #include #include +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_STDINT_H +#include +#else +#include +#endif + #ifndef POWERLDAP_HH @@ -69,7 +79,7 @@ public: typedef map > sentry_t; typedef vector 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 );