Debian Codegraph @

doc/howto/Directory.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ProFTPD: Configuring a &lt;Directory&gt;</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <hr>
10 <center><h2><b>ProFTPD: Configuring a <code>&lt;Directory&gt;</code></b></h2></center>
11 <hr>
12
13 <p>
14 Use of the <code>&lt;Directory&gt;</code> configuration directive is, in
15 general, straightforward. However, there are a few caveats of which to
16 be aware.
17
18 <p>
19 First, it is not necessary to nest <code>&lt;Directory&gt;</code> sections,
20 like:
21 <pre>
22 &lt;Directory /path/to/dir&gt;
23 &lt;Directory /path/to/dir/subdir&gt;
24 ...
25 &lt;/Directory&gt;
26 &lt;/Directory&gt;
27 </pre>
28 The daemon will not let one do this, in fact. The daemon will determine
29 automatically the relations of <code>&lt;Directory&gt;</code> paths, depending
30 on the path given and surrounding configuration section.
31
32 <p>
33 Always use the normal, absolute path for a <code>&lt;Directory&gt;</code>
34 section, regardless of whether that directory will eventually be accessed
35 during a session which has been <code>chroot</code>'d, as for
36 <code>&lt;Anonymous&gt;</code> or <code>DefaultRoot</code>ed sessions.
37 There are two allowed exceptions to the rule of using absolute paths:
38 if the path has a <code>~</code> prefix, or if the
39 <code>&lt;Directory&gt;</code> occurs within a <code>&lt;Anonymous&gt;</code>
40 section. In the latter case, the path may be relative (<i>i.e.</i> does
41 not need to start with a <code>/</code>), in which case the path will be
42 relative to the directory to which anonymous sessions are restricted.
43
44 <p>
45 If the name of the directory contains spaces, you should enclose the entire
46 directory name in quotations, <i>e.g.</i>:
47 <pre>
48 &lt;Directory &quot;/path/to/My Directory&quot;&gt;
49 </pre>
50
51 <p>
52 Any configuration directives in a <code>&lt;Directory&gt;</code> section
53 will apply to that directory <i>and to all of the contents of that directory
54 recursively</i>. Thus if you use:
55 <pre>
56 &lt;Directory /path/to/dir&gt;
57 Umask 022
58 &lt;/Directory&gt;
59 </pre>
60 Then that <code>Umask</code> value will be used within the
61 "/path/to/dir/subdir/" directory as well.
62
63 <p>
64 As noted in the documentation, use of a <code>/*</code> suffix on a path
65 will change the effect of a <code>&lt;Directory&gt;</code> section
66 slightly. For example:
67 <pre>
68 &lt;Directory /path/to/dir&gt;
69 </pre>
70 applies the section's configuration directives to the <code>dir</code>
71 directory and its contents, while:
72 <pre>
73 &lt;Directory /path/to/dir/*&gt;
74 </pre>
75 applies the section's configuration directives only to the <i>contents</i>
76 of <code>dir</code>, not to the directory itself. This is a small
77 distinction, but it can often cause misconfigurations. In general, unless
78 you know what you're doing, it's best not to use a <code>/*</code> suffix.
79
80 <p>
81 Also, a <code>*</code> within a path, such as:
82 <pre>
83 &lt;Directory /path/to/*/dir&gt;
84 </pre>
85 will only match that single directory level, and will not match multiple
86 directory levels. This means that the above <code>&lt;Directory&gt;</code>
87 will match:
88 <pre>
89 /path/to/<b>a/</b>dir
90 /path/to/<b>b/</b>dir
91 </pre>
92 because <code>*</code> will match the <code>a/</code> and <code>b/</code>,
93 as they are on the same level in the path as <code>*</code>. However, the
94 following paths <b>will not</b> match:
95 <pre>
96 /path/to/<b>some/other/</b>dir
97 /path/to/<b>some/other/level/</b>dir
98 </pre>
99 since <code>*</code> does not expand to <code>some/other/</code> or
100 <code>/some/other/level/</code>; they cover multiple levels.
101
102 <p>
103 There is another case about which the administrator should know: for the
104 purposes of handling the <code>APPE</code>, <code>RETR</code>,
105 <code>RNTO</code>, <code>STOR</code>, and <code>STOU</code> FTP commands, the
106 daemon will match a <code>&lt;Directory&gt;</code> path with the filename
107 appended. As above, in most cases this will not matter much. However,
108 consider the case where the administrator specifically wants to use the
109 trailing <code>/*</code>, as when she wants a particular
110 <code>&lt;Limit&gt;</code> to apply to all subdirectories of a given directory,
111 but not to that directory itself. For example, the administrators wishes to
112 block anonymous uploads everywhere except for subdirectories of
113 <code>upload/</code>:
114 <pre>
115 &lt;Anonymous ~ftp&gt;
116 User ftp
117 Group ftp
118
119 UserAlias anonymous ftp
120
121 &lt;Limit WRITE&gt;
122 DenyAll
123 &lt;/Limit&gt;
124
125 &lt;Directory upload/*&gt;
126 &lt;Limit STOR&gt;
127 AllowAll
128 &lt;/Limit&gt;
129 &lt;/Directory&gt;
130 &lt;/Anonymous&gt;
131 </pre>
132 This configuration <i>looks</i> like it should work, allowing files to be
133 uploaded only to subdirectories of <code>upload/</code>, but not to the
134 <code>upload/</code> directory itself. As described above, though, the
135 daemon will append the filename being uploaded via <code>STOR</code> to the
136 path used when looking up <code>&lt;Directory&gt;</code>, meaning that
137 <code>upload/<i>filename</i></code> will match <code>upload/*</code>, and
138 allow files to be uploaded into <code>upload/</code>. In this particular case,
139 then, what is wanted is to use this <code>&lt;Directory&gt;</code> pattern:
140 <pre>
141 &lt;Directory upload/*/*&gt;
142 &lt;Limit STOR&gt;
143 AllowAll
144 &lt;/Limit&gt;
145 &lt;/Directory&gt;
146 </pre>
147 which will achieve the desired effect of allowing uploads only in
148 subdirectories of the given directory, <code>upload/</code>.
149
150 <p>
151 Also, it is good to keep in mind the <a href="ftpaccess.html">similarity</a>
152 between a <code>&lt;Directory&gt;</code> section and a <code>.ftpaccess</code>
153 file. In some cases, using <code>.ftpaccess</code> files might be more
154 convenient. The
155 <a href="../modules/mod_core.html#AllowOverride"><code>AllowOverride</code></a>
156 configuration directive (which first appeared in the 1.2.7rc1 release) provides
157 fine-grained control over when <code>.ftpaccess</code> files will be honored.
158
159 <p>
160 The fact that <code>&lt;Directory&gt;</code> sections can be used to
161 refer to specific <i>files</i>, in addition to directories, is not obvious.
162 However, there are some cases where it can be useful to use this feature.
163 One proftpd user used this feature in the following way: the
164 <a href="../modules/mod_ls.html#DirFakeMode"><code>DirFakeMode</code></a>
165 directive was used to make all files look read-only (mostly so that FTP
166 mirroring tools would create a read-only mirror of the site). However, a
167 particular file on the site needed have execute permissions,
168 even in the FTP mirrored site. A <code>&lt;Directory&gt;</code> section
169 was used just for this one file, <i>e.g.</i>:
170 <pre>
171 # Make all files look read-only to clients, regardless of the actual
172 # permissions on the filesystem
173 DirFakeMode 0444
174
175 &lt;Anonymous /var/ftpd&gt;
176
177 # However, for this script, we need it to look like it is executable, too
178 &lt;Directory /var/ftpd/bin/script&gt;
179 DirFakeMode 0555
180 &lt;/Directory&gt;
181
182 &lt;/Anonymous&gt;
183 </pre>
184
185 <p><a name="FAQ"></a>
186 <b>Frequently Asked Questions</b><br>
187
188 <p><a name="MultipleDirectoriesSamePath">
189 <font color=red>Question</font>: What happens if I configure two <code>&lt;Directory&gt;</code> sections for the exact same path?<br>
190 <font color=blue>Answer</font>: If you use explicit paths, then the config
191 parser will choke on the duplicate <code>&lt;Directory&gt;</code> sections.
192 For example, if you tried:
193 <pre>
194 &lt;Directory /path/to/dir&gt;
195 &lt;Limit ALL&gt;
196 DenyAll
197 &lt;/Limit&gt;
198 &lt;/Directory&gt;
199
200 &lt;Directory /path/to/dir&gt;
201 &lt;Limit ALL&gt;
202 AllowAll
203 &lt;/Limit&gt;
204
205 &lt;Limit WRITE&gt;
206 DenyAll
207 &lt;/Limit&gt;
208 &lt;/Directory&gt;
209 </pre>
210 When starting <code>proftpd</code>, you would see something like:
211 <pre>
212 - Fatal: &lt;Directory&gt;: &lt;Directory&gt; section already configured for '/path/to/dir' on line 39 of '/etc/ftpd/proftpd.conf'
213 </pre>
214
215 <p>
216 But what if you have the two <code>&lt;Directory&gt;</code> sections, but
217 one of the sections uses a wildcard character which would still match the
218 same path? For example:
219 <pre>
220 &lt;Directory /path/to/dir&gt;
221 &lt;Limit ALL&gt;
222 DenyAll
223 &lt;/Limit&gt;
224 &lt;/Directory&gt;
225
226 &lt;Directory /path/*/dir&gt;
227 &lt;Limit ALL&gt;
228 AllowAll
229 &lt;/Limit&gt;
230
231 &lt;Limit WRITE&gt;
232 DenyAll
233 &lt;/Limit&gt;
234 &lt;/Directory&gt;
235 </pre>
236 This time, the config parser would not choke; <code>proftpd</code> would start
237 up normally. When it came time to look up the <code>&lt;Directory&gt;</code>
238 section to use, <i>e.g.</i> for uploading to "/path/to/dir/test.txt",
239 the matching <code>&lt;Directory&gt;</code> section <i>which appears later in
240 the config file</i> wins. In the above example, the upload to
241 "/path/to/dir/test.txt" would be denied (because the wildcard-using
242 <code>&lt;Directory&gt;</code> section appears later, and it has a
243 <code>&lt;Limit WRITE&gt;</code> section denying writes).
244
245 <p>
246 However, if you simply reversed the order of the above
247 <code>&lt;Directory&gt;</code> sections and tried to upload to
248 "/path/to/subdir/test.txt", <i>e.g.</i>:
249 <pre>
250 &lt;Directory /path/*/dir&gt;
251 &lt;Limit ALL&gt;
252 AllowAll
253 &lt;/Limit&gt;
254
255 &lt;Limit WRITE&gt;
256 DenyAll
257 &lt;/Limit&gt;
258 &lt;/Directory&gt;
259
260 &lt;Directory /path/to/dir&gt;
261 &lt;Limit ALL&gt;
262 DenyAll
263 &lt;/Limit&gt;
264 &lt;/Directory&gt;
265 </pre>
266 the upload would succeed, since the non-wildcard-using
267 <code>&lt;Directory&gt;</code> section appeared later in the config.
268
269 <p><a name="PreventDirectoryRename"></a>
270 <font color=red>Question</font>: How can I prevent a specific directory from
271 being renamed? I am currently trying:
272 <pre>
273 &lt;Directory /dir/*&gt;
274 &lt;Limit CWD XCWD RNFR RNTO&gt;
275 AllowAll
276 &lt;/Limit&gt;
277
278 &lt;Limit ALL&gt;
279 DenyAll
280 &lt;/Limit&gt;
281 &lt;/Directory&gt;
282
283 &lt;Directory /dir/subdir&gt;
284 &lt;Limit WRITE&gt;
285 DenyAll
286 &lt;/Limit&gt;
287 &lt;/Directory&gt;
288 </pre>
289 to keep "/dir/subdir" from being renamed, but it doesn't work!<br>
290 <font color=blue>Answer</font>: The trick is to block the <code>RNFR</code>
291 command within the <code>&lt;Directory&gt;</code> section for that
292 specific directory, <i>i.e.</i>:
293 <pre>
294 &lt;Directory /dir/subdir&gt;
295 &lt;Limit RNFR WRITE&gt;
296 DenyAll
297 &lt;/Limit&gt;
298 &lt;/Directory&gt;
299 </pre>
300
301 <p>
302 The reason the original config did not work as expected is that
303 <code>proftpd</code>, when handling the <code>RNTO</code> command (<i>e.g.</i> "<code>RNTO subdir2</code>"), would <b>not</b> match the
304 <code>&lt;Directory /dir/subdir&gt;</code> section for the path "/dir/subdir2",
305 but instead matches the <code>&lt;Directory /dir/*&gt;</code> section.
306
307 <p>
308 Renaming of files via FTP is done by first sending the <code>RNFR</code>
309 command (for the old filename), then sending <code>RNTO</code> (with the
310 new filename). By placing <code>RNFR</code> in the
311 <code>&lt;Directory /dir/subdir&gt;</code> section's <code>&lt;Limit&gt;</code>
312 list, we make sure that the <code><i>RNFR</i></code> <i>does</i> match the
313 <code>&lt;Directory /dir/subdir&gt;</code> section, and is thus denied.
314
315 <p>
316 <hr>
317 <font size=2><b><i>
318 &copy; Copyright 2017 The ProFTPD Project<br>
319 All Rights Reserved<br>
320 </i></b></font>
321 <hr>
322
323 </body>
324 </html>