[prev in list] [next in list] [prev in thread] [next in thread]
List: pdns-dev
Subject: [Pdns-dev] default-ttl + ldapbackend improvements
From: Norbert Sendetzky <norbert () linuxnetworks ! de>
Date: 2003-08-30 15:46:31
Message-ID: 200308301746.33301.norbert () linuxnetworks ! de
[Download RAW message or body]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Bert
First please add the line below to common_startup.cc. Otherwise the
attached patch won't compile.
+ arg().set("default-ttl","Seconds a result is valid if not set
otherwise")="3600";
The diff contains the following improvments
- - use default-ttl instead of ldap-default-ttl (which is depricated)
- - allow a comma seperated list of host:port combinations for fail-over
(ldap-port is depricated)
- - Information about searches and results is now only available in
debug mode (for speedup and minimized syslog output)
- - Upper case IN-ADDR.ARPA requests are handled correctly
- - Various code improvements
Norbert
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iEYEARECAAYFAj9QxtcACgkQxMLs5v5/7eA27QCeMKTSuIX8duPnU8XsKZgcRti7
yAYAoLNMY1z3yfWT/SgijPQE6X67nKdc
=I4kQ
-----END PGP SIGNATURE-----
["ldapbackend.cc.2.9.11-2.diff" (text/x-diff)]
--- pdns-2.9.11.orig/modules/ldapbackend/ldapbackend.cc Sat Aug 30 14:09:40 2003
+++ pdns-2.9.11/modules/ldapbackend/ldapbackend.cc Sat Aug 30 17:25:59 2003
@@ -23,25 +23,43 @@
-static int Toupper(int c)
+static int to_upper( int c )
{
- return toupper(c);
+ return toupper( c );
+}
+
+
+static int to_lower( int c )
+{
+ return tolower( c );
+}
+
+
+static int comma2space( int c )
+{
+ if( c == 0x2c ) {
+ return 0x20;
+ }
+
+ return c;
}
LdapBackend::LdapBackend( const string &suffix )
{
- m_msgid = 0;
- m_qname = "";
setArgPrefix( "ldap" + suffix );
+ string hosts = getArg( "host" );
-
- m_default_ttl = (u_int32_t) strtol( getArg( "default-ttl" ).c_str(), NULL, 10 );
+ m_msgid = 0;
+ m_qname = "";
+ m_default_ttl = arg().asNum( "default-ttl" );
try
{
- L << Logger::Info << backendname << " LDAP Server = " << getArg( "host" ) << ":" \
<< getArg( "port" ) << endl;
- m_pldap = new PowerLDAP( getArg( "host" ), (u_int16_t) atoi( getArg( "port" \
).c_str() ) ); + transform( hosts.begin(), hosts.end(), hosts.begin(), &comma2space \
); + L << Logger::Info << backendname << " LDAP servers = " << hosts << endl;
+
+ m_pldap = new PowerLDAP( hosts.c_str(), atoi( getArg( "port" ).c_str() ) );
m_pldap->simpleBind( getArg( "binddn" ), getArg( "secret" ) );
}
catch( LDAPException &e )
@@ -70,8 +88,6 @@
try
{
- L << Logger::Notice << backendname << " AXFR request for " << target << endl;
-
// search for DN of SOA record which is SOA for target zone
filter = "(&(associatedDomain=" + target + ")(SOARecord=*))";
@@ -83,7 +99,7 @@
return false;
}
- if( m_result.empty() || m_result.find( "dn" ) == m_result.end() || \
m_result["dn"].empty() ) + if( m_result.empty() || !m_result.count( "dn" ) || \
m_result["dn"].empty() ) {
L << Logger::Error << backendname << " No SOA record for " << target << endl;
return false;
@@ -136,8 +152,9 @@
if( mustDo( "disable-ptrrecord" ) ) // PTRRecords will be derived from ARecords
{
- len = qesc.length();
+ transform( qesc.begin(), qesc.end(), qesc.begin(), &to_lower );
stringtok( parts, qesc, "." );
+ len = qesc.length();
if( parts.size() == 6 && len > 13 && qesc.substr( len - 13, 13 ) == \
".in-addr.arpa" ) // IPv4 reverse lookups {
@@ -175,13 +192,14 @@
}
}
+ DLOG( L << Logger::Debug << backendname << " Search = basedn: " << getArg( \
"basedn" ) << ", filter: " << filter << ", qtype: " << qtype.getName() << endl ); +
m_adomain = m_adomains.end(); // skip loops in get() first time
- L << Logger::Info << backendname << " Search = basedn: " << getArg( "basedn" ) << \
", filter: " << filter << ", qtype: " << qtype.getName() << endl; m_msgid = \
m_pldap->search( getArg("basedn"), LDAP_SCOPE_SUBTREE, filter, (const char**) \
attributes ); }
catch( LDAPException &le )
{
- L << Logger::Warning << backendname << " Unable to search LDAP directory: " << \
le.what() << endl; + L << Logger::Error << backendname << " Unable to search LDAP \
directory: " << le.what() << endl; return;
}
catch( exception &e )
@@ -214,7 +232,7 @@
{
attrname = m_attribute->first;
qstr = attrname.substr( 0, attrname.length() - 6 ); // extract qtype string \
from ldap attribute name
- transform( qstr.begin(), qstr.end(), qstr.begin(), &Toupper );
+ transform( qstr.begin(), qstr.end(), qstr.begin(), &to_upper );
qt = QType( const_cast<char*>(qstr.c_str()) );
while( m_value != m_attribute->second.end() )
@@ -244,7 +262,7 @@
rr.content = content;
m_value++;
- L << Logger::Info << backendname << " Record = qname: " << rr.qname << ", \
qtype: " << (rr.qtype).getName() << ", priority: " << rr.priority << ", content: " << \
rr.content << endl; + DLOG( L << Logger::Debug << backendname << " Record = \
qname: " << rr.qname << ", qtype: " << (rr.qtype).getName() << ", priority: " << \
rr.priority << ", content: " << rr.content << endl ); return true;
}
@@ -262,7 +280,7 @@
}
catch( LDAPException &le )
{
- L << Logger::Warning << backendname << " Search failed: " << le.what() << endl;
+ L << Logger::Error << backendname << " Search failed: " << le.what() << endl;
}
catch( exception &e )
{
@@ -301,7 +319,7 @@
m_adomains.clear();
m_ttl = m_default_ttl;
- if( m_result.find( "dNSTTL" ) != m_result.end() && !m_result["dNSTTL"].empty() )
+ if( m_result.count( "dNSTTL" ) && !m_result["dNSTTL"].empty() )
{
m_ttl = (u_int32_t) strtol( m_result["dNSTTL"][0].c_str(), NULL, 10 );
m_result.erase( "dNSTTL" );
@@ -310,7 +328,7 @@
if( !m_qname.empty() ) // request was a normal lookup()
{
m_adomains.push_back( m_qname );
- if( m_result.find( "associatedDomain" ) != m_result.end() )
+ if( m_result.count( "associatedDomain" ) )
{
m_result["PTRRecord"] = m_result["associatedDomain"];
m_result.erase( "associatedDomain" );
@@ -318,7 +336,7 @@
}
else // request was a list() for AXFR
{
- if( m_result.find( "associatedDomain" ) != m_result.end() )
+ if( m_result.count( "associatedDomain" ) )
{
m_adomains = m_result["associatedDomain"];
m_result.erase( "associatedDomain" );
@@ -342,13 +360,13 @@
void declareArguments( const string &suffix="" )
{
- declare( suffix, "host", "your ldap server","localhost" );
- declare( suffix, "port", "ldap server port","389" );
+ declare( suffix, "host", "one or more ldap server","localhost:389" );
+ declare( suffix, "port", "ldap server port (depricated, use ldap-host)","389" );
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", "" );
declare( suffix, "disable-ptrrecord", "disable necessity for seperate PTR \
records", "no" );
- declare( suffix, "default-ttl", "default ttl if DNSTTL is not set", "86400" );
+ declare( suffix, "default-ttl", "default ttl if DNSTTL is not set (depricated, use \
default-ttl)", "3600" ); }
@@ -369,7 +387,7 @@
Loader()
{
BackendMakers().report( new LdapFactory );
- L << Logger::Notice << backendname << " This is the ldap module version "VERSION" \
("__DATE__", "__TIME__") reporting" << endl; + L << Logger::Info << backendname << " \
This is the ldap module version "VERSION" ("__DATE__", "__TIME__") reporting" << \
endl; }
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic