Debian Codegraph @

doc/howto/Timestamps.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ProFTPD: Timestamps</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <hr>
10 <center><h2><b>ProFTPD: Timestamps</b></h2></center>
11 <hr>
12
13 <p>
14 There have been various reports that timestamps displayed in various
15 ProFTPD log files, such as an <code>ExtendedLog</code> or
16 <code>TransferLog</code>, or even in directory listings, are not as expected.
17 Other applications (<i>e.g.</i> <code>sshd</code>) on the same machine do
18 not exhibit the same problem. So is <code>proftpd</code> having issues
19 with timestamps?
20
21 <p>
22 If the timestamps in question are those displayed in directory listings, then
23 you need to check your <a href="../modules/mod_core.html#TimesGMT"><code>TimesGMT</code></a> configuration. Otherwise,
24 depending on the logs at which you are looking, the timestamps will be correct
25 <i>until</i> the user logs in. After that, the timestamps are wrong. This
26 is one clue. The other clue is that these wrong timestamps go away when
27 the <code>DefaultRoot</code> directive is removed from the
28 <code>proftpd.conf</code> file.
29
30 <p>
31 The answer turns out to be the <code>chroot(2)</code> system call, which
32 <code>proftpd</code> uses to restrict users to certain directories, usually
33 their home directory. There are two configuration directives which tell
34 <code>proftpd</code> to use the <code>chroot(2)</code> system call:
35 <pre>
36 &lt;Anonymous&gt;
37 DefaultRoot
38 </pre>
39 The system <code>libc</code> library is responsible for generating times,
40 based on timezone settings and such. The GNU libc library (called
41 <code>glibc</code> for short), used on all Linux systems changed in later
42 versions, and now makes some assumptions. Specifically, <code>glibc</code>
43 assumes the location of the system timezone files. But once a process
44 has been chrooted, those assumptions break. The fallback behavior of
45 <code>glibc</code>, when it cannot find the system timezone files, is to
46 use GMT.
47
48 <p>
49 The good news is that the above behavior does <b>not</b> happen if the
50 <code>TZ</code> environment variable is set explicitly, to the required
51 timezone. That is, if <code>glibc</code> needs to detect the timezone and
52 it finds that <code>TZ</code> is set, then <code>glibc</code> will use that
53 <code>TZ</code> setting, rather than falling back to GMT.
54
55 <p>
56 <b>Affected Library Functions</b><br>
57 Once a process has chrooted, the following <code>libc</code> function
58 calls will have possibly-bad side effects, with regard to timezone detection:
59 <code>localtime(3)</code>, <code>ctime(3)</code>, and <code>mktime(3)</code>.
60 As documented in the man pages for these functions, each of them will
61 set the <code>tzname</code> global variable to the &quot;current&quot;
62 timezone. This &quot;current&quot; timezone is what changes, once the
63 process has become chrooted. (For more information on the <code>tzname</code>
64 global variable, read the <code>tzset(3)</code> man page.)
65
66 <p>
67 <b>Solutions</b><br>
68 Recent releases of ProFTPD attempt to work around these issues by
69 preserving the <code>tzname</code> global variable after calling
70 <code>localtime(3)</code>, and by automatting setting the <code>TZ</code>
71 environment variable, is not already set, before calling <code>chroot(2)</code>.
72 These measures are defensive at best, though.
73
74 <p>
75 The best way to deal with this issue, which is especially prominent on systems
76 running <code>glibc-2.3</code> or later, is to set the <code>TZ</code>
77 environment variable explicitly, before starting <code>proftpd</code>. This
78 can be done in an <code>init</code> script for <code>proftpd</code>, for
79 example.
80
81 <p>
82 You can also use the <code>SetEnv</code> configuration directive within the
83 <code>proftpd.conf</code> file to set the <code>TZ</code> environment variable,
84 <i>e.g.</i>:
85 <pre>
86 # Set the TZ environment variable to be Pacific Standard Time (PST)
87 SetEnv TZ PST
88 </pre>
89 Obviously you will need to set the timezone to whatever is appropriate for
90 your site. For example, some systems expect different values for the
91 <code>TZ</code> environment variable, <i>e.g.</i>:
92 <pre>
93 SetEnv TZ :/etc/localtime
94 </pre>
95 <b>Note</b>: Using a filesystem location such as ":/etc/localtime" for the
96 <code>TZ</code> environment variable can still result in log timestamp issues,
97 <i>e.g.</i> when the <code>MFMT</code>/<code>MFF</code> FTP commands are used.
98 The best solution is to always specify the timezone name, rather than a file,
99 whenever possible.
100
101 <p>
102 These are provided as <i>examples</i>; please consult your system documentation
103 for the proper syntax to use for the <code>TZ</code> value.
104
105 <p><a name="FAQ">
106 <b>Frequently Asked Questions</b><br>
107
108 <p>
109 <font color=red>Question</font>: Why is the timestamp on my newly uploaded file wrong?<br>
110 <font color=blue>Answer</font>: If by "wrong" you mean "different from
111 the timestamp of that file on my client machine", then that is the expected
112 behavior.
113
114 <p>
115 The modification timestamp on a file is <i>not</i> part of the data uploaded
116 over the data connection when uploading a file. Timestamps like that are
117 <i>metadata</i> for that file, not part of the bytes of the file itself.
118 FTP does not supporting sending of timestamps as part of the upload transfer
119 process. See below for a common follow-up question.
120
121 <p>
122 <font color=red>Question</font>: Does ProFTPD support changing the timestamp on a file using the <code>MDTM</code> command? That's what my client does.<br>
123 <font color=blue>Answer</font>: No.
124
125 <p>
126 Why not? For several reasons:
127 <ul>
128 <li>The <code>MDTM</code> command is <b>not</b> one of the commands
129 mandated by <a href="http://www.faqs.org/rfcs/rfc959.html">RFC 959</a>.
130 </li>
131
132 <li>Some FTP clients use <code>MDTM</code> for <i>retrieving</i> the
133 modification time, others try to use it to <i>set</i> the modification
134 time, and still others do both.
135 </li>
136
137 <li>Among those FTP clients that do use <code>MDTM</code>, there is no
138 consistent format of the timestamp used.
139 </li>
140 </ul>
141 In short, it is a royal mess. ProFTPD supports <code>MDTM</code> for
142 retrieving the modification time, in GMT. Period.
143
144 <p>
145 If you want to set the modification time, you can use the
146 <code>MFMT</code> command supported by the <code>mod_facts</code> module,
147 or the <code>mod_site_misc</code> module's
148 <a href="../contrib/mod_site_misc.html#SITE_UTIME"><code>SITE UTIME</code></a>
149 command.
150
151 <p>
152 <font color=red>Question</font>: I thought that the <code>TimesGMT</code> directive was affected the timestamps that proftpd uses?<br>
153 <font color=blue>Answer</font>: No. The <a href="../modules/mod_core.html#TimesGMT"><code>TimesGMT</code></a> directive only affects the timestamps as
154 displayed to FTP clients in <i>directory listings</i>; it does <b>not</b>
155 affect the timestamps used in log files.
156
157 <p>
158 <hr>
159 <font size=2><b><i>
160 &copy; Copyright 2017 The ProFTPD Project<br>
161 All Rights Reserved<br>
162 </i></b></font>
163 <hr>
164
165 </body>
166 </html>