Blame SOURCES/vsftpd-3.0.0-tz.patch

d83721
diff -up vsftpd-2.2.2/sysutil.c.tz vsftpd-2.2.2/sysutil.c
d83721
--- vsftpd-2.2.2/sysutil.c.tz	2012-04-26 12:45:21.095145878 +0200
d83721
+++ vsftpd-2.2.2/sysutil.c	2012-04-26 12:48:08.729618686 +0200
d83721
@@ -26,8 +26,10 @@
d83721
 /* For Linux, this adds nothing :-) */
d83721
 #include "port/porting_junk.h"
d83721
 
d83721
+#define F_LOCALTIME "/etc/localtime"
d83721
+#define BUFTZSIZ 64
d83721
+
d83721
 #include <signal.h>
d83721
-#include <string.h>
d83721
 #include <stdlib.h>
d83721
 #include <unistd.h>
d83721
 #include <sys/types.h>
d83721
@@ -55,6 +57,11 @@
d83721
 #include <utime.h>
d83721
 #include <netdb.h>
d83721
 #include <sys/resource.h>
d83721
+ 
d83721
+#ifndef __USE_GNU
d83721
+  #define __USE_GNU
d83721
+#endif
d83721
+#include <string.h>
d83721
 
d83721
 /* Private variables to this file */
d83721
 /* Current umask() */
d83721
@@ -2558,49 +2565,92 @@ error:
d83721
   die("reopening standard file descriptors to /dev/null failed");
d83721
 }
d83721
 
d83721
+char* vsf_sysutil_get_tz()
d83721
+{
d83721
+  char *ret_tz = NULL;
d83721
+  char buff[BUFTZSIZ];
d83721
+  off_t s_pos, e_pos;
d83721
+  size_t rcnt, rest;
d83721
+  int fd;
d83721
+
d83721
+  if ((fd = open(F_LOCALTIME, O_RDONLY)) > -1)
d83721
+  {
d83721
+    if ((e_pos = lseek(fd, 0, SEEK_END)) <= 0)
d83721
+    {
d83721
+      close(fd);
d83721
+      return NULL;
d83721
+    }
d83721
+    s_pos = e_pos > BUFTZSIZ ? e_pos - BUFTZSIZ : 0;
d83721
+    lseek(fd, s_pos, SEEK_SET);
d83721
+    rcnt = read(fd, buff, BUFTZSIZ);
d83721
+
d83721
+    if (rcnt && buff[rcnt-1] == '\n')
d83721
+    {
d83721
+      buff[rcnt-1] = 0;
d83721
+      e_pos--;
d83721
+    }
d83721
+
d83721
+    do {
d83721
+       char *nl = memrchr(buff, '\n', rcnt);
d83721
+       if (rcnt && nl)
d83721
+       {
d83721
+         int offset = (++nl) - buff;
d83721
+         int len = e_pos - s_pos - offset;
d83721
+         if (len)
d83721
+         {
d83721
+           lseek(fd, s_pos + offset, SEEK_SET);
d83721
+           ret_tz = calloc(1, len+4);
d83721
+           memcpy(ret_tz, "TZ=", 3);
d83721
+           rcnt = read(fd, ret_tz+3, len);
d83721
+         }
d83721
+         break;
d83721
+       }
d83721
+       if (!s_pos)
d83721
+       {
d83721
+         break;
d83721
+       }
d83721
+       rest = s_pos > BUFTZSIZ ? s_pos - BUFTZSIZ : 0;
d83721
+       s_pos -= rest;
d83721
+       lseek(fd, s_pos, SEEK_SET);
d83721
+       rcnt = read(fd, buff, rest);
d83721
+    } while (rcnt > 0);
d83721
+
d83721
+    close (fd);
d83721
+  }
d83721
+
d83721
+  return ret_tz;
d83721
+}
d83721
+
d83721
 void
d83721
 vsf_sysutil_tzset(void)
d83721
 {
d83721
   int retval;
d83721
-  char tzbuf[sizeof("+HHMM!")];
d83721
+  char *tz=NULL, tzbuf[sizeof("+HHMM!")];
d83721
   time_t the_time = time(NULL);
d83721
   struct tm* p_tm;
d83721
+
d83721
+  /* Set our timezone in the TZ environment variable to cater for the fact
d83721
+   * that modern glibc does not cache /etc/localtime (which becomes inaccessible
d83721
+   * when we chroot().
d83721
+   */
d83721
+  tz = vsf_sysutil_get_tz();;
d83721
+  if (tz)
d83721
+  {
d83721
+    putenv(tz);
d83721
+  }
d83721
   tzset();
d83721
   p_tm = localtime(&the_time);
d83721
   if (p_tm == NULL)
d83721
   {
d83721
     die("localtime");
d83721
   }
d83721
-  /* Set our timezone in the TZ environment variable to cater for the fact
d83721
-   * that modern glibc does not cache /etc/localtime (which becomes inaccessible
d83721
-   * when we chroot().
d83721
-   */
d83721
   retval = strftime(tzbuf, sizeof(tzbuf), "%z", p_tm);
d83721
   tzbuf[sizeof(tzbuf) - 1] = '\0';
d83721
   if (retval == 5)
d83721
   {
d83721
-    /* Static because putenv() does not copy the string. */
d83721
-    static char envtz[sizeof("TZ=UTC-hh:mm")];
d83721
-    /* Insert a colon so we have e.g. -05:00 instead of -0500 */
d83721
-    tzbuf[5] = tzbuf[4];
d83721
-    tzbuf[4] = tzbuf[3];
d83721
-    tzbuf[3] = ':';
d83721
-    /* Invert the sign - we just got the offset _from_ UTC but for TZ, we need
d83721
-     * the offset _to_ UTC.
d83721
-     */
d83721
-    if (tzbuf[0] == '+')
d83721
-    {
d83721
-      tzbuf[0] = '-';
d83721
-    }
d83721
-    else
d83721
-    {
d83721
-      tzbuf[0] = '+';
d83721
-    }
d83721
-    snprintf(envtz, sizeof(envtz), "TZ=UTC%s", tzbuf);
d83721
-    putenv(envtz);
d83721
     s_timezone = ((tzbuf[1] - '0') * 10 + (tzbuf[2] - '0')) * 60 * 60;
d83721
-    s_timezone += ((tzbuf[4] - '0') * 10 + (tzbuf[5] - '0')) * 60;
d83721
-    if (tzbuf[0] == '-')
d83721
+    s_timezone += ((tzbuf[3] - '0') * 10 + (tzbuf[4] - '0')) * 60;
d83721
+    if (tzbuf[0] == '+')
d83721
     {
d83721
       s_timezone *= -1;
d83721
     }