Debian Codegraph @

doc/howto/Quotas.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ProFTPD: Quotas</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <hr>
10 <center><h2><b>ProFTPD: Quotas</b></h2></center>
11 <hr>
12
13 <p>
14 A busy FTP server handles hundreds to thousands of files belonging to hundreds
15 to thousands of users. There is not an infinite capacity on the disks of
16 the server, however, and eventually those files will take up too much space.
17 Thus many sites have a pressing need to set limits on just how much can
18 be stored on the server by their users.
19
20 <p>
21 Most Unix systems have support for OS- or fileystem-level quotas. These
22 have the advantage of being transparent to applications like
23 <code>proftpd</code>, which means that the applications need not worry
24 about maintaining and enforcing quotas. The kernel/filesystem will handle
25 that. One disadvantage these OS-level quotas have, though, is that they
26 are strictly tied to OS and/or filesystem, and not all Unix kernels and
27 filesystems are the same. They also rely on each user having their own
28 separate user ID. In the case of
29 <a href="VirtualUsers.html">virtual users</a> for <code>proftpd</code>, it is
30 possible for many users to have the same user ID, which causes problems for
31 these traditional Unix quotas.
32
33 <p>
34 For these reasons, the <a href="../contrib/mod_quotatab.html"><code>mod_quotatab</code></a> module was developed for ProFTPD. This module, being part of the
35 application, applies to all the Unix kernels and filesystems which support
36 ProFTPD, and easily handles virtual users. The <code>mod_quotatab</code>
37 documentation covers how to configure <code>proftpd</code> for quotas.
38
39 <p>
40 <b>Note</b>: This howto is a work-in-progress. Please contact me with
41 suggestions, questions, requests, <i>etc</i> for what you would like to see
42 covered here. Thanks!
43
44 <p><a name="Config" title="#Config"></a>
45 <b>Example Configuration</b><br>
46 Here is an example <code>mod_quotatab</code> configuration for supporting
47 quotas via file tables and SQL tables. <b>This is an example only</b>.
48 <pre>
49 &lt;IfModule mod_quotatab.c&gt;
50 QuotaEngine on
51 QuotaLog /var/log/ftpd/quota.log
52
53 # For more information on using files for storing the limit and tally
54 # table quota data, please see the <a href="../contrib/mod_quotatab_file.html">mod_quotatab_file</a> documentation.
55 &lt;IfModule mod_quotatab_file.c&gt;
56 QuotaLimitTable file:/etc/ftpd/ftpquota.limittab
57 QuotaTallyTable file:/etc/ftpd/ftpquota.tallytab
58 &lt;/IfModule&gt;
59
60 # For more information on using a SQL database for storing the limit and
61 # tally table quota data, please see the <a href="../contrib/mod_quotatab_sql.html">mod_quotatab_sql</a> documentation
62 &lt;IfModule mod_quotatab_sql.c&gt;
63 SQLNamedQuery get-quota-limit SELECT "* FROM quotalimits WHERE name = '%{0}' AND quota_type = '%{1}'"
64 SQLNamedQuery get-quota-tally SELECT "* FROM quotatallies WHERE name = '%{0}' AND quota_type = '%{1}'"
65 SQLNamedQuery update-quota-tally UPDATE "bytes_in_used = bytes_in_used + %{0}, bytes_out_used = bytes_out_used + %{1}, bytes_xfer_used = bytes_xfer_used + %{2}, files_in_used = files_in_used + %{3}, files_out_used = files_out_used + %{4}, files_xfer_used = files_xfer_used + %{5} WHERE name = '%{6}' AND quota_type = '%{7}'" quotatallies
66 SQLNamedQuery insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" quotatallies
67
68 QuotaLock /var/lock/ftpd.quotatab.lock
69 QuotaLimitTable sql:/get-quota-limit
70 QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally
71 &lt;/IfModule&gt;
72 &lt;/IfModule&gt;
73 </pre>
74
75 <p><a name="FAQ" title="#FAQ"></a>
76 <b>Frequently Asked Questions</b><br>
77
78 <p><a name="QuotasDiskSpace" title="#QuotasDiskSpace"></a>
79 <font color=red>Question</font>: How do I set the disk space limit for a user?<br>
80 <font color=blue>Answer</font>: The short answer is to use the &quot;upload bytes limit&quot; setting.
81
82 <p>
83 It's true that the various limits maintained by <code>mod_quotatab</code>,
84 for either bytes or files (or both), are confusing. When designing
85 the module, I anticipated administrators wanting to limit download as well
86 as upload transfers; in reality, most administrators wish to limit the
87 disk space for their users. The bytes uploaded limit doubles as the
88 disk space limit, for there is no effective difference between them; any
89 bytes uploaded via FTP are automatically stored on disk.
90
91 <p><a name="QuotasExternalChanges" title="#QuotasExternalChanges"></a>
92 <font color=red>Question</font>: <code>mod_quotatab</code> only tracks changes
93 made using <code>proftpd</code>, and my users can add/remove files other ways.
94 What am I supposed to do?<br>
95 <font color=blue>Answer</font>: As the <code>mod_quotatab</code> documentation
96 states, the module was designed only to track changes done via FTP; it
97 made implementation of quotas simpler.
98
99 <p>
100 This question is also often posed as "Why can't mod_quotatab just calculate
101 the amount of space used by a user?" The module <i>could</i> do this,
102 but there are some considerations with this kind of approach.
103
104 <p>
105 The primary consideration is the time cost of having to recurse a directory.
106 If the directory is relatively small, the time needed is small. For very
107 large/deep directories, however, the time needed to do the scan could be
108 long, possibly long enough for users to notice and complain. Another
109 complication is the disk space used by a given user is not confined to
110 their home directory. Many sites have home directories for users, and
111 have a shared directory that all users can use. Somehow
112 <code>mod_quotatab</code> would need to know to scan these shared directories.
113
114 <p>
115 As of <code>proftpd-1.3.1rc1</code>, the <code>mod_quotatab</code> supports
116 this feature via the <code>ScanOnLogin</code> parameter of the
117 <code>QuotaOptions</code> directive.
118
119 <p><a name="QuotasExcludeFiles"></a>
120 <font color=red>Question</font>: If I use this <code>ScanOnLogin</code> option, how do I tell it to ignore certain files?</br>
121 <font color=blue>Answer</font>: Use the new
122 <a href="../contrib/mod_quotatab.html#QuotaExcludeFilter"><code>QuotaExcludeFilter</code></a> directive. For example, if you wanted to exclude all files
123 that ended in ".log" from the automatic quota calculation, you might use:
124 <pre>
125 &lt;IfModule mod_quotatab.c&gt;
126 ...
127
128 # Automatically calculate the used quota on login
129 QuotaOptions ScanOnLogin
130
131 # Do not include files ending in ".log" in the automatically
132 # calculated quota
133 QuotaExludeFilter \.log$
134 &lt;/IfModule&gt;
135 </pre>
136
137 <p><a name="QuotasInitialization" title="#QuotasInitialization"></a>
138 <font color=red>Question</font>: If <code>mod_quotatab</code> does not
139 automatically scan for disk space usage, how will it know about my existing
140 users?<br>
141 <font color=blue>Answer</font>: By default, <code>mod_quotatab</code>
142 indeed knows nothing about what disk space is already occupied by your
143 users; the tally table starts out blank.
144
145 <p>
146 To help address this, there is a <code>diskuse.pl</code> Perl script:
147 <pre>
148 <a href="http://www.castaglia.org/proftpd/contrib/diskuse">http://www.castaglia.org/proftpd/contrib/diskuse</a>
149 </pre>
150 which will display the number of bytes owned by a given user (or group) within
151 a list of directories. The parameters needed for running
152 <code>diskuse.pl</code> are documented
153 <a href="http://www.castaglia.org/proftpd/contrib/diskuse.html">here</a>.
154
155 <p>
156 Once you've run <code>diskuse.pl</code> to find out the current usage for
157 your users, you can enter those numbers into your tally table. Unfortunately
158 <code>diskuse.pl</code> cannot read your <code>proftpd.conf</code> file
159 to know whether you are using a file- or SQL-based tally table, so it cannot
160 automatically update your tally table.
161
162 <p><a name="QuotasDefaults" title="#QuotasDefaults"></a>
163 <font color=red>Question</font>: How can I set a default quota for all of my users?<br>
164 <font color=blue>Answer</font>: For this, you can use the <a href="../contrib/mod_quotatab.html#QuotaDefault"><code>QuotaDefault</code></a> directive, which
165 first appeared in ProFTPD 1.3.5rc1.
166
167 <p><a name="QuotasTallyTable" title="#QuotasTallyTable"></a>
168 <font color=red>Question</font>: What is a &quot;tally table&quot;?<br>
169 <font color=blue>Answer</font>: Tally tables, and limit tables, are
170 covered in the <code>mod_quotatab</code> <a href="../contrib/mod_quotatab.html#QuotaTables">documentation</a>.
171
172 <p><a name="QuotasCreatingFileTables" title="#QuotasCreatingFileTables"></a>
173 <font color=red>Question</font>: How do I construct the limit and tally files for file-based quotas?<br>
174 <font color=blue>Answer</font>: There is a Perl script called <a href="http://www.proftpd.org/docs/contrib/ftpquota.html"><code>ftpquota</code></a> which
175 can create the necessary files. This script can also be found under the
176 <code>contrib/</code> directory of the <code>proftpd</code> source
177 distribution.
178
179 <p><a name="QuotasCreatingSQLTables" title="#QuotasCreatingSQLTables"></a>
180 <font color=red>Question</font>: Is there a SQL script for the SQL quota tables used by <code>mod_quotatab_sql</code>?<br>
181 <font color=blue>Answer</font>: No. However, the <code>mod_quotatab_sql</code>
182 <a href="../contrib/mod_quotatab_sql.html">documentation</a> contains example schema for the necessary tables.
183
184 <p><a name="QuotasDirectorySize" title="#QuotasDirectorySize"></a>
185 <font color=red>Question</font>: How do I set a limit on the size of a
186 directory?<br>
187 <font color=blue>Answer</font>: Currently, you cannot.
188
189 <p>
190 Traditional Unix quotas are implemented in terms of <i>ownership</i>: the
191 thing that counts is not where a file is located on the filesystem, but
192 which user and/or group owns the file. Asking about directory quotas
193 assumes a different basis for quotas, based on <i>location</i> rather than
194 ownership (such quotas are often called <i>tree-based quotas</i>). The
195 <code>mod_quotatab</code> module followed the example of traditional Unix
196 quotas, but I have started designing how location-based quotas might be
197 implemented.
198
199 <p><a name="QuotasNotUpdating" title="#QuotasNotUpdating"></a>
200 <font color=red>Question</font>: Why isn't <code>mod_quotatab</code> updating my tally table?<br>
201 <font color=blue>Answer</font>: It depends.
202
203 <p>
204 One possibility is that the <em>per session</em> flag in the limit in
205 effect is set to <code>true</code>, which means that the limits will only
206 be applied to this session. When this happens, <code>mod_quotatab</code>
207 will not update the tally table.
208
209 <p>
210 Another possibility is that your configured limits are "unlimited" (<i>i.e.</i>
211 zero). As it states in the <a href="../contrib/mod_quotatab.html#Usage"><code>mod_quotatab</code></a> documentation:
212 <pre>
213 For any quota limit that is set as "unlimited", mod_quotatab will not keep the tally.
214 Many site administrators might want this ability, for accounting purposes. However,
215 that ability is outside of the intended design of this module; other logging modules
216 are much better suited for accounting purposes (<i>e.g</i>. mod_sql's <code>SQLLog</code> directive).
217 </pre>
218
219 <p>
220 If the above cases are not applicable, then consider looking in the
221 <a href="../contrib/mod_quotatab.html#QuotaLog"><code>QuotaLog</code></a> file for more information.
222
223 <p><a name="QuotasPerMonth" title="#QuotasPerMonth"></a>
224 <font color=red>Question</font>: Can I use <code>mod_quotatab</code> to set
225 monthly quotas?<br>
226 <font color=blue>Answer</font>: Sort of. <code>mod_quotatab</code> itself
227 has no concept of time, so this sort of capability is not built-in. However,
228 it can be approximated by having some other process, such as a cron job,
229 periodically (such as once a month) clear the tally table, yielding the
230 effect of monthly quotas.
231
232 <p><a name="QuotasDisplay" title="#QuotasDisplay"></a>
233 <font color=red>Question</font>: How can users see their current quota?<br>
234 <font color=blue>Answer</font>: There are two ways to show the current quota
235 to users. There is the <a href="../contrib//mod_quotatab.html#SITE_QUOTA"><code>SITE QUOTA</code></a> command. And there are
236 certain <a href="../contrib/mod_quotatab.html#QuotaDisplay"><code>Display</code></a> variables that are supported by the
237 <code>mod_quotatab</code> module.
238
239 <p><a name="QuotasPerFile" title="#QuotasPerFile"></a>
240 <font color=red>Question</font>: What if I want to set limits on the size of
241 individual files being transferred?<br>
242 <font color=blue>Answer</font>: For this, you do not need the
243 <code>mod_quotatab</code> module. ProFTPD has the
244 <a href="../modules/mod_xfer.html#MaxRetrieveFileSize"><code>MaxRetrieveFileSize</code></a> and
245 <a href="../modules/mod_xfer.html#MaxStoreFileSize"><code>MaxStoreFileSize</code></a> directives.
246
247 <p><a name="QuotasUnsupportedType" title="#QuotasUnsupportedType"></a>
248 <font color=red>Question</font>: Why do I see the following error?
249 <pre>
250 QuotaLimitTable: unsupported table source type: 'sql'
251 </pre>
252 <font color=blue>Answer</font>: The <code>mod_quotatab</code> module acts
253 as a general quota managing front-end; it relies on other backend modules
254 to handle the specifics of storage formats. Every backend module
255 (<i>e.g.</i>
256 <a href="../contrib/mod_quotatab_file.html"><code>mod_quotatab_file</code></a>, <a href="../contrib/mod_quotatab_sql.html"><code>mod_quotatab_sql</code></a>, <a href="../contrib/mod_quotatab_ldap.html"><code>mod_quotatab_ldap</code></a>) registers a supported <em>table type</em> with the main
257 <code>mod_quotatab</code> module. The error above indicates that the
258 <code>mod_quotatab_sql</code> module has not been compiled/loaded into
259 <code>proftpd</code>.
260
261 <p><a name="QuotasGroupQuotas" title="#QuotasGroupQuotas"></a>
262 <font color=red>Question</font>: How do group quotas work? If a user is in multiple groups, what happens?<br>
263 <font color=blue>Answer</font>: The <code>mod_quotatab</code> module
264 <a href="../contrib/mod_quotatab.html#QuotaLookup">searches</a> for applicable
265 quotas, by type, in the following order:
266 <ul>
267 <li>user quotas
268 <li>group quotas
269 <li>class quotas
270 <li>the "all" quota
271 </ul>
272 Thus if there is a user-specific quota, it will be used; the search stops there.
273 The <code>mod_quotatab</code> module does <b>not</b> combine multiple different
274 quotas.
275
276 <p>
277 What happens, then, if a user belongs to multiple different groups, and there
278 are different quotas set for those different groups? First, the <i>primary</i>
279 group of the user is checked; this is the group that is included, for example,
280 in the entry for the user in the <code>/etc/passwd</code> file. If no quota
281 for the primary group is found, the module then checks against each of
282 the user's <i>supplemental</i> groups. The order in which these groups
283 are checked is dependent up on the order in which the groups are returned
284 from the auth module providing them, <i>e.g.</i> <code>mod_sql</code>,
285 <code>mod_ldap</code>, or perhaps <code>mod_auth_unix</code>.
286
287 <p><a name="QuotasOverwrites" title="#QuotasOverwrites"></a>
288 <font color=red>Question</font>: Does <code>mod_quotatab</code> handle the case where a client might append to/overwrite an existing file, in terms of tracking bytes?<br>
289 <font color=blue>Answer</font>: Yes. The <code>mod_quotatab</code> module
290 checks the size of the file before the upload/append starts, and then checks
291 the size of the file again after the upload/append completes. The difference
292 in file sizes is used for tracking the byte-related tallies.
293
294 <p><a name="QuotasDeleteTransferBytes" title="#QuotasDeleteTransferBytes">
295 <font color=red>Question</font>: I configured limits for my users such that
296 only the transfer bytes limit is set. On uploads, my transfer bytes tally
297 is incremented properly. But when I delete a file, the transfer bytes tally
298 is not <i>decremented</i>. Is this a bug?<br>
299 <font color=blue>Answer</font>: No, it's not a bug.
300
301 <p>
302 Deleting a file does not count as transferred bytes (<i>i.e.</i> it does not
303 pertain to the <code>bytes_xfer</code> limit); it counts as uploaded bytes
304 (<i>i.e.</i> the <code>bytes_in</code> limit). And since there is only a limit,
305 in this case, on the transferred bytes, the <code>mod_quotatab</code> module
306 ends up not changing any tally value for a delete. More details on this
307 can be found in
308 <a href="http://bugs.proftpd.org/show_bug.cgi?id=2897">Bug#2897</a>.
309
310 <p><a name="QuotasZeroLimits" title="#QuotasZeroLimits"></a>
311 <font color=red>Question</font>: Why does the <code>ftpquota</code> tool
312 treat limit values of zero as "unlimited"?
313 <pre>
314 $ ftpquota --create-table --type=limit
315 $ ftpquota --add-record --type=limit --name=tj --quota-type=user <b>--files-download=0</b>
316 $ ftpquota --show-records --type=limit
317 -------------------------------------------
318 Name: tj
319 Quota Type: User
320 Per Session: False
321 Limit Type: Hard
322 Uploaded bytes: unlimited
323 Downloaded bytes: unlimited
324 Transferred bytes: unlimited
325 Uploaded files: unlimited
326 <b>Downloaded files: unlimited</b>
327 Transferred files: unlimited
328 </pre>
329 I want to use this to prevent a user from uploading/download files.<br>
330 <p>
331 <font color=blue>Answer</font>: If you wish to prevent users from uploading
332 or downloading, then you should use
333 <a href="Limit.html"><code>&lt;Limit&gt;</code></a> sections in your
334 ProFTPD configuration; that is what they are designed to do. The
335 <code>ftpquota</code> tool was <em>explicitly designed</em> to not allow
336 being used to prevent uploads/downloads; it is for managing <em>quotas</em>.
337
338 <p>
339 <hr>
340 <font size=2><b><i>
341 &copy; Copyright 2017 The ProFTPD Project<br>
342 All Rights Reserved<br>
343 </i></b></font>
344 <hr>
345
346 </body>
347 </html>