[Pdns-dev] Re: bug in LDAP backend: patch included

Otheus otheus+tiscover at gmail.com
Tue Mar 10 16:54:44 CET 2009


In the LDAP backend, the constructor initializes the TZ variable to
UTC, which is then later used by a timestring conversion code in
utils.hh. This method of using TZ to set the time is a dirty hack, and
throws off all timestamps sent to syslog. Here is code that, according
to all the documentation I can find, is clean, portable, and correctly
converts the LDAP strings into UTC time while maintaining timestamps
sent to syslog.

diff -U3 -rw pdns-2.9.22/modules/ldapbackend/ldapbackend.cc
pdns-2.9.22a/modules/ldapbackend/ldapbackend.cc
--- pdns-2.9.22/modules/ldapbackend/ldapbackend.cc      2008-03-02
09:20:13.000000000 +0100
+++ pdns-2.9.22a/modules/ldapbackend/ldapbackend.cc     2009-03-10
13:51:57.000000000 +0100
@@ -22,9 +22,6 @@
               m_default_ttl = arg().asNum( "default-ttl" );
               m_myname = "[LdapBackend]";

-               // we need UTC time for timestamps
-               setenv( "TZ", "", 1 ); tzset();
-
               setArgPrefix( "ldap" + suffix );

               m_getdn = false;
diff -U3 -rw pdns-2.9.22/modules/ldapbackend/utils.hh
pdns-2.9.22a/modules/ldapbackend/utils.hh
--- pdns-2.9.22/modules/ldapbackend/utils.hh    2008-02-03
13:14:00.000000000 +0100
+++ pdns-2.9.22a/modules/ldapbackend/utils.hh   2009-03-10
13:51:57.000000000 +0100
@@ -141,12 +141,21 @@
 {
       char* tmp;
       struct tm tm;
+       time_t tout;

       tmp =  strptime( str.c_str(), "%Y%m%d%H%M%SZ", &tm );

       if( tmp != NULL && *tmp == 0 )
       {
-               return mktime( &tm );
+               tout=mktime( &tm );
+
+               // mktime() returns negative quantity on failure.
+               if (tout > 0)  {
+                       // account for timezone() information and then reset TZ
+                       tout -= timezone;
+                       tzset();
+                       return tout;
+               }
       }

       return 0;


More information about the Pdns-dev mailing list