]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
applied Norbert's patch, which closes ticket #37
authorBert Hubert <bert.hubert@netherlabs.nl>
Sun, 15 Jan 2006 21:03:43 +0000 (21:03 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sun, 15 Jan 2006 21:03:43 +0000 (21:03 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@558 d19b8d6e-7fed-0310-83ef-9ca221ded41b

modules/ldapbackend/ldapbackend.cc
modules/ldapbackend/ldapbackend.hh
modules/ldapbackend/powerldap.cc
modules/ldapbackend/powerldap.hh

index 96dae35c6819807af8248298e9f5ddb7515892ed..77ddddd7df3963a61e8f15bf6d4d5129ca3996b2 100644 (file)
@@ -10,7 +10,6 @@ LdapBackend::LdapBackend( const string &suffix )
 {
        string hoststr;
        unsigned int i, idx;
-       string::size_type end, begin = 0;
        vector<string> 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", "" );
index 50f6dbb88c0b7ff6ec9c0eb3c4b298abc57b482f..13858af8950ba8cef7e0633d6af5eda89d9bdb09 100644 (file)
 #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 @@ 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:
 
index 050e592065f696686ac8203df0600565c7632815..7c2abd790fda6408496471b7799e9ed97ab9f0d0 100644 (file)
@@ -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" ) );
-       }
 }
 
 
index 9e53ec9d9f976201f9bf258218dd9a8dedb4122e..c58bc870d6f8484967053f84f0b7c4b242e5bade 100644 (file)
 #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 @@ public:
        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 );