ProFTPD and Timestamps


There have been various reports that timestamps displayed in various ProFTPD log files, such as an ExtendedLog or TransferLog, or even in directory listings, are not as expected. Other applications (e.g. sshd) on the same machine do not exhibit the same problem. So is proftpd having issues with timestamps?

Depending on the logs at which you are looking, the timestamps will be correct until the user logs in. After that, the timestamps are wrong. This is one clue. The other clue is that these wrong timestamps go away when the DefaultRoot directive is removed from the proftpd.conf file.

The answer turns out to be the chroot(2) system call, which proftpd uses to restrict users to certain directories, usually their home directory. There are two configuration directives which tell proftpd to use the chroot(2) system call:

  <Anonymous>
  DefaultRoot 
The system libc library is responsible for generating times, based on timezone settings and such. The GNU libc library (called glibc for short), used on all Linux systems changed in later versions, and now makes some assumptions. Specifically, glibc assumes the location of the system timezone files. But once a process has been chrooted, those assumptions break. The fallback behavior of glibc, when it cannot find the system timezone files, is to use GMT.

The good news is that the above behavior does not happen if the TZ environment variable is set explicitly, to the required timezone. That is, if glibc needs to detect the timezone and it finds that TZ is set, then glibc will use that TZ setting, rather than falling back to GMT.

Affected Library Functions
Once a process has chrooted, the following libc function calls will have possibly-bad side effects, with regard to timezone detection: localtime(3), ctime(3), and mktime(3). As documented in the man pages for these functions, each of them will set the tzname global variable to the "current" timezone. This "current" timezone is what changes, once the process has become chrooted. (For more information on the tzname global variable, read the tzset(3) man page.)

Solutions
Recent releases of ProFTPD attempt to work around these issues by preserving the tzname global variable after calling localtime(3), and by automatting setting the TZ environment variable, is not already set, before calling chroot(2). These measures are defensive at best, though.

The best way to deal with this issue, which is especially prominent on systems running glibc-2.3 or later, is to set the TZ environment variable explicitly, before starting proftpd. This can be done in an init script for proftpd, for example.

You can also use the SetEnv configuration directive within the proftpd.conf file to set the TZ environment variable, e.g.:

  # Set the TZ environment variable to be Pacific Standard Time (PST)
  SetEnv TZ PST
Obviously you will need to set the timezone to whatever is appropriate for your site.


$Date: 2007/02/15 19:00:17 $