Changeset 1152
- Timestamp:
- 03/09/08 16:23:12 (9 months ago)
- Files:
-
- trunk/pdns/modules/ldapbackend/Makefile.am (modified) (1 diff)
- trunk/pdns/modules/ldapbackend/OBJECTLIBS (modified) (1 diff)
- trunk/pdns/modules/ldapbackend/ldapbackend.cc (modified) (1 diff)
- trunk/pdns/modules/ldapbackend/ldapbackend.hh (modified) (2 diffs)
- trunk/pdns/modules/ldapbackend/powerldap.cc (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/pdns/modules/ldapbackend/Makefile.am
r1096 r1152 1 1 AM_CPPFLAGS=@THREADFLAGS@ 2 2 3 EXTRA_DIST =OBJECTFILES OBJECTLIBS3 EXTRA_DIST = OBJECTFILES OBJECTLIBS 4 4 5 5 lib_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 6 libldapbackend_la_SOURCES = ldapbackend.cc ldapbackend.hh powerldap.hh powerldap.cc utils.hh 7 libldapbackend_la_LDFLAGS =-module -avoid-version 8 libldapbackend_la_LIBADD =-l@LIBLDAP@ trunk/pdns/modules/ldapbackend/OBJECTLIBS
r149 r1152 1 -lldap 1 -lldap_r trunk/pdns/modules/ldapbackend/ldapbackend.cc
r1107 r1152 132 132 133 133 // search for SOARecord of target 134 filter = strbind( ":target:", " associatedDomain=" + qesc, getArg( "filter-axfr" ) );134 filter = strbind( ":target:", "&(associatedDomain=" + qesc + ")(sOARecord=*)", getArg( "filter-axfr" ) ); 135 135 m_msgid = m_pldap->search( dn, LDAP_SCOPE_SUBTREE, filter, (const char**) ldap_attrany ); 136 136 m_pldap->getSearchEntry( m_msgid, m_result, true ); trunk/pdns/modules/ldapbackend/ldapbackend.hh
r1107 r1152 50 50 51 51 52 /* 53 * Known DNS RR types 54 * Types which aren't active are currently not supported by PDNS 55 */ 56 52 57 static const char* ldap_attrany[] = { 53 58 "associatedDomain", … … 62 67 "tXTRecord", 63 68 "rPRecord", 69 "aFSDBRecord", 64 70 // "SigRecord", 65 // "KeyRecord", 71 "KeyRecord", 72 // "gPosRecord", 66 73 "aAAARecord", 67 74 "lOCRecord", 68 // "nXTRecord",69 75 "sRVRecord", 70 76 "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", 73 90 "modifyTimestamp", 74 91 NULL trunk/pdns/modules/ldapbackend/powerldap.cc
r1094 r1152 1 1 #include "powerldap.hh" 2 // for timeval 2 #include <pdns/misc.hh> 3 3 #include <sys/time.h> 4 4 5 5 6 6 7 PowerLDAP::PowerLDAP( const string& hosts, uint16_t port, bool tls ) 7 8 { 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 8 35 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 25 36 if( ldap_set_option( d_ld, LDAP_OPT_PROTOCOL_VERSION, &protocol ) != LDAP_OPT_SUCCESS ) 26 37 { … … 28 39 if( ldap_set_option( d_ld, LDAP_OPT_PROTOCOL_VERSION, &protocol ) != LDAP_OPT_SUCCESS ) 29 40 { 30 ldap_unbind ( d_ld);41 ldap_unbind_ext( d_ld, NULL, NULL ); 31 42 throw LDAPException( "Couldn't set protocol version to LDAPv3 or LDAPv2" ); 32 43 } 33 44 } 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 } 34 51 } 35 52 … … 37 54 PowerLDAP::~PowerLDAP() 38 55 { 39 ldap_unbind ( d_ld);56 ldap_unbind_ext( d_ld, NULL, NULL ); 40 57 } 41 58 … … 63 80 int msgid; 64 81 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 65 94 if( ( msgid = ldap_bind( d_ld, ldapbinddn.c_str(), ldapsecret.c_str(), method ) ) == -1 ) 66 95 { 67 96 throw LDAPException( "Failed to bind to LDAP server: " + getError( msgid ) ); 68 97 } 98 #endif 69 99 70 100 waitResult( msgid, timeout, NULL ); … … 72 102 73 103 104 /** 105 * Depricated, use PowerLDAP::bind() instead 106 */ 107 74 108 void PowerLDAP::simpleBind( const string& ldapbinddn, const string& ldapsecret ) 75 109 { 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 ); 81 111 } 82 112 … … 84 114 int PowerLDAP::search( const string& base, int scope, const string& filter, const char** attr ) 85 115 { 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 ) ); 90 121 } 91 122 … … 210 241 const string PowerLDAP::getError( int rc ) 211 242 { 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 ) );; 220 246 } 221 247