Changeset 1152

Show
Ignore:
Timestamp:
03/09/08 16:23:12 (9 months ago)
Author:
ahu
Message:

Norbert has added support for far more record types to LDAP, plus Debian supplied improvements to 'PowerLDAP', plus improved autoconf detection of ldap

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pdns/modules/ldapbackend/Makefile.am

    r1096 r1152  
    11AM_CPPFLAGS=@THREADFLAGS@ 
    22 
    3 EXTRA_DIST=OBJECTFILES OBJECTLIBS 
     3EXTRA_DIST = OBJECTFILES OBJECTLIBS 
    44 
    55lib_LTLIBRARIES = libldapbackend.la 
    6 libldapbackend_la_CPPFLAGS = -DLDAP_DEPRECATED 
    7 libldapbackend_la_LIBADD = -lldap 
    8 libldapbackend_la_LDFLAGS=-module -avoid-version 
    9 libldapbackend_la_SOURCES = \ 
    10         ldapbackend.cc ldapbackend.hh \ 
    11         powerldap.hh powerldap.cc \ 
    12         utils.hh 
    13  
    14  
    15  
     6libldapbackend_la_SOURCES = ldapbackend.cc ldapbackend.hh powerldap.hh powerldap.cc utils.hh 
     7libldapbackend_la_LDFLAGS =-module -avoid-version 
     8libldapbackend_la_LIBADD =-l@LIBLDAP@ 
  • trunk/pdns/modules/ldapbackend/OBJECTLIBS

    r149 r1152  
    1 -lldap 
     1-lldap_r 
  • trunk/pdns/modules/ldapbackend/ldapbackend.cc

    r1107 r1152  
    132132 
    133133        // search for SOARecord of target 
    134         filter = strbind( ":target:", "associatedDomain=" + qesc, getArg( "filter-axfr" ) ); 
     134        filter = strbind( ":target:", "&(associatedDomain=" + qesc + ")(sOARecord=*)", getArg( "filter-axfr" ) ); 
    135135        m_msgid = m_pldap->search( dn, LDAP_SCOPE_SUBTREE, filter, (const char**) ldap_attrany ); 
    136136        m_pldap->getSearchEntry( m_msgid, m_result, true ); 
  • trunk/pdns/modules/ldapbackend/ldapbackend.hh

    r1107 r1152  
    5050 
    5151 
     52/* 
     53 *  Known DNS RR types 
     54 *  Types which aren't active are currently not supported by PDNS 
     55 */ 
     56 
    5257static const char* ldap_attrany[] = { 
    5358        "associatedDomain", 
     
    6267        "tXTRecord", 
    6368        "rPRecord", 
     69        "aFSDBRecord", 
    6470//      "SigRecord", 
    65 //      "KeyRecord", 
     71        "KeyRecord", 
     72//      "gPosRecord", 
    6673        "aAAARecord", 
    6774        "lOCRecord", 
    68 //      "nXTRecord", 
    6975        "sRVRecord", 
    7076        "nAPTRRecord", 
    71 //      "kXRecord", 
    72 //      "certRecord", 
     77        "kXRecord", 
     78        "certRecord", 
     79//      "a6Record", 
     80//      "dNameRecord", 
     81//      "aPLRecord", 
     82        "dSRecord", 
     83        "sSHFPRecord", 
     84        "iPSecKeyRecord", 
     85        "rRSIGRecord", 
     86        "nSECRecord", 
     87        "dNSKeyRecord", 
     88        "dHCIDRecord", 
     89        "sPFRecord", 
    7390        "modifyTimestamp", 
    7491        NULL 
  • trunk/pdns/modules/ldapbackend/powerldap.cc

    r1094 r1152  
    11#include "powerldap.hh" 
    2 // for timeval 
     2#include <pdns/misc.hh> 
    33#include <sys/time.h> 
    44 
    55 
     6 
    67PowerLDAP::PowerLDAP( const string& hosts, uint16_t port, bool tls ) 
    78{ 
     9        int err; 
     10 
     11#ifdef HAVE_LDAP_INITIALIZE 
     12        if( ( err = ldap_initialize( &d_ld, hosts.c_str() ) ) != LDAP_SUCCESS ) 
     13        { 
     14                string ldapuris; 
     15                vector<string> uris; 
     16                stringtok( uris, hosts ); 
     17 
     18                for( size_t i = 0; i < uris.size(); i++ ) 
     19                { 
     20                        ldapuris += " ldap://" + uris[i]; 
     21                } 
     22 
     23                if( ( err = ldap_initialize( &d_ld, ldapuris.c_str() ) ) != LDAP_SUCCESS ) 
     24                { 
     25                                throw LDAPException( "Error initializing LDAP connection to '" + ldapuris + ": " + getError( err ) ); 
     26                } 
     27        } 
     28#else 
     29        if( ( d_ld = ldap_init( hosts.c_str(), port ) ) == NULL ) 
     30        { 
     31                throw LDAPException( "Error initializing LDAP connection to '" + hosts + "': " + string( strerror( errno ) ) ); 
     32        } 
     33#endif 
     34 
    835        int protocol = LDAP_VERSION3; 
    9  
    10  
    11         if( ldap_initialize( &d_ld, hosts.c_str() ) != LDAP_SUCCESS ) 
    12         { 
    13                 if( ( d_ld = ldap_init( hosts.c_str(), port ) ) == NULL ) 
    14                 { 
    15                         throw LDAPException( "Error initializing LDAP connection: " + string( strerror( errno ) ) ); 
    16                 } 
    17  
    18                 if( tls && ldap_start_tls_s( d_ld, NULL, NULL ) != LDAP_SUCCESS ) 
    19                 { 
    20                         ldap_unbind( d_ld ); 
    21                         throw( LDAPException( "Couldn't perform STARTTLS" ) ); 
    22                 } 
    23         } 
    24  
    2536        if( ldap_set_option( d_ld, LDAP_OPT_PROTOCOL_VERSION, &protocol ) != LDAP_OPT_SUCCESS ) 
    2637        { 
     
    2839                if( ldap_set_option( d_ld, LDAP_OPT_PROTOCOL_VERSION, &protocol ) != LDAP_OPT_SUCCESS ) 
    2940                { 
    30                         ldap_unbind( d_ld ); 
     41                        ldap_unbind_ext( d_ld, NULL, NULL ); 
    3142                        throw LDAPException( "Couldn't set protocol version to LDAPv3 or LDAPv2" ); 
    3243                } 
    3344        } 
     45 
     46        if( tls && ( err = ldap_start_tls_s( d_ld, NULL, NULL ) ) != LDAP_SUCCESS ) 
     47        { 
     48                ldap_unbind_ext( d_ld, NULL, NULL ); 
     49                throw LDAPException( "Couldn't perform STARTTLS: " + getError( err ) ); 
     50        } 
    3451} 
    3552 
     
    3754PowerLDAP::~PowerLDAP() 
    3855{ 
    39         ldap_unbind( d_ld ); 
     56        ldap_unbind_ext( d_ld, NULL, NULL ); 
    4057} 
    4158 
     
    6380        int msgid; 
    6481 
     82#ifdef HAVE_LDAP_SASL_BIND 
     83        int rc; 
     84        struct berval passwd; 
     85 
     86        passwd.bv_val = (char *)ldapsecret.c_str(); 
     87        passwd.bv_len = strlen( passwd.bv_val ); 
     88 
     89        if( ( rc = ldap_sasl_bind( d_ld, ldapbinddn.c_str(), LDAP_SASL_SIMPLE, &passwd, NULL, NULL, &msgid ) ) != LDAP_SUCCESS ) 
     90        { 
     91                throw LDAPException( "Failed to bind to LDAP server: " + getError( rc ) ); 
     92        } 
     93#else 
    6594        if( ( msgid = ldap_bind( d_ld, ldapbinddn.c_str(), ldapsecret.c_str(), method ) ) == -1 ) 
    6695        { 
    6796                throw LDAPException( "Failed to bind to LDAP server: " + getError( msgid ) ); 
    6897        } 
     98#endif 
    6999 
    70100        waitResult( msgid, timeout, NULL ); 
     
    72102 
    73103 
     104/** 
     105 * Depricated, use PowerLDAP::bind() instead 
     106 */ 
     107 
    74108void PowerLDAP::simpleBind( const string& ldapbinddn, const string& ldapsecret ) 
    75109{ 
    76         int err; 
    77         if( ( err = ldap_simple_bind_s( d_ld, ldapbinddn.c_str(), ldapsecret.c_str() ) ) != LDAP_SUCCESS ) 
    78         { 
    79                 throw LDAPException( "Failed to bind to LDAP server: " + getError( err ) ); 
    80         } 
     110        this->bind( ldapbinddn, ldapsecret, LDAP_AUTH_SIMPLE, 30 ); 
    81111} 
    82112 
     
    84114int PowerLDAP::search( const string& base, int scope, const string& filter, const char** attr ) 
    85115{ 
    86         int msgid; 
    87         if( ( msgid = ldap_search( d_ld, base.c_str(), scope, filter.c_str(), const_cast<char**> (attr), 0 ) ) == -1 ) 
    88         { 
    89                 throw LDAPException( "Starting LDAP search: " + getError() ); 
     116        int msgid, rc; 
     117 
     118        if( ( rc = ldap_search_ext( d_ld, base.c_str(), scope, filter.c_str(), const_cast<char**> (attr), 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &msgid ) ) != LDAP_SUCCESS ) 
     119        { 
     120                throw LDAPException( "Starting LDAP search: " + getError( rc ) ); 
    90121        } 
    91122 
     
    210241const string PowerLDAP::getError( int rc ) 
    211242{ 
    212         int ld_errno = rc; 
    213  
    214         if( ld_errno == -1 ) 
    215         { 
    216                 getOption( LDAP_OPT_ERROR_NUMBER, &ld_errno ); 
    217         } 
    218  
    219         return ldap_err2string( ld_errno ); 
     243        if( rc == -1 ) { getOption( LDAP_OPT_ERROR_NUMBER, &rc ); } 
     244 
     245        return string( ldap_err2string( rc ) );; 
    220246} 
    221247