Debian Codegraph @

doc/contrib/mod_sql.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ProFTPD module mod_sql</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <hr>
10 <center>
11 <h2><b>ProFTPD module <code>mod_sql</code></b></h2>
12 </center>
13 <hr><br>
14
15 <p>
16 The <code>mod_sql</code> module is an authentication and logging module
17 for ProFTPD. It is comprised of a front end module (<code>mod_sql</code>)
18 and backend database-specific modules (<code>mod_sql_mysql</code>,
19 <code>mod_sql_postgres</code>, <code>mod_sql_sqlite</code>, <i>etc</i>). The
20 front end module leaves the specifics of handling database connections to the
21 backend modules.
22
23 <p>
24 The <code>mod_sql</code> module is not compiled by default. Installation
25 instructions are discussed <a href="#Installation">here</a>.
26
27 <p>
28 This product includes software developed by the OpenSSL Project for use in the
29 OpenSSL Toolkit (http://www.openssl.org/).
30
31 <p>
32 This product includes cryptographic software written by Eric Young
33 ([email protected]).
34
35 <p>
36 The most current version of <code>mod_sql</code> is distributed with ProFTPD.
37
38 <h2>Thanks</h2>
39 <ul>
40 <li>Johnie Ingram &lt;johnie <i>at</i> netgod.net&gt; for the original
41 <code>mod_sqlpw</code>.
42 <li>TJ Saunders and Jesse Sipprell for dealing with my inane questions.
43 <li>John Morrissey for <code>mod_ldap</code>, which lit the way, here and
44 there.
45 <li>Zeev Suraski &lt;bourbon <i>at</i> bourbon.netvision.net.il&gt; for the
46 Apache <code>mod_auth_mysql</code> module, which informed the
47 <code>SQLAuthTypes</code> directive.
48 <li>Avalon from IRC for doc-fixes and suggestions.
49 <li>and many others who've suggested various enhancements or security fixes.
50 </ul>
51
52 <h2>Directives</h2>
53 <ul>
54 <li><a href="#SQLAuthenticate">SQLAuthenticate</a>
55 <li><a href="#SQLAuthTypes">SQLAuthTypes</a>
56 <li><a href="#SQLBackend">SQLBackend</a>
57 <li><a href="#SQLConnectInfo">SQLConnectInfo</a>
58 <li><a href="#SQLDefaultGID">SQLDefaultGID</a>
59 <li><a href="#SQLDefaultHomedir">SQLDefaultHomedir</a>
60 <li><a href="#SQLDefaultUID">SQLDefaultUID</a>
61 <li><a href="#SQLEngine">SQLEngine</a>
62 <li><a href="#SQLGroupInfo">SQLGroupInfo</a>
63 <li><a href="#SQLGroupPrimaryKey">SQLGroupPrimaryKey</a>
64 <li><a href="#SQLGroupWhereClause">SQLGroupWhereClause</a>
65 <li><a href="#SQLKeepAlive">SQLKeepAlive</a>
66 <li><a href="#SQLLog">SQLLog</a>
67 <li><a href="#SQLLogFile">SQLLogFile</a>
68 <li><a href="#SQLLogOnEvent">SQLLogOnEvent</a>
69 <li><a href="#SQLMinID">SQLMinID</a>
70 <li><a href="#SQLMinUserGID">SQLMinUserGID</a>
71 <li><a href="#SQLMinUserUID">SQLMinUserUID</a>
72 <li><a href="#SQLNamedConnectInfo">SQLNamedConnectInfo</a>
73 <li><a href="#SQLNamedQuery">SQLNamedQuery</a>
74 <li><a href="#SQLNegativeCache">SQLNegativeCache</a>
75 <li><a href="#SQLOptions">SQLOptions</a>
76 <li><a href="#SQLRatios">SQLRatios</a>
77 <li><a href="#SQLRatioStats">SQLRatioStats</a>
78 <li><a href="#SQLShowInfo">SQLShowInfo</a>
79 <li><a href="#SQLUserInfo">SQLUserInfo</a>
80 <li><a href="#SQLUserPrimaryKey">SQLUserPrimaryKey</a>
81 <li><a href="#SQLUserWhereClause">SQLUserWhereClause</a>
82 </ul>
83
84 <hr>
85 <h3><a name="SQLAuthenticate">SQLAuthenticate</a></h3>
86 <strong>Syntax:</strong> SQLAuthenticate <em>on|off</em> <i>or</i><br>
87 <strong>Syntax:</strong> SQLAuthenticate <em>[users] [groups] [userset[fast]] [groupset[fast]]</em><br>
88 <strong>Default:</strong> on<br>
89 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
90 <strong>Module:</strong> mod_sql<br>
91 <strong>Compatibility:</strong> 1.2.5rc1 and later
92
93 <p>
94 The <code>SQLAuthenticate</code> directive configures <code>mod_sql</code>'s
95 authentication behavior, controlling whether to provide user and/or group
96 information during authentication, and how that provisioning is performed.
97 The parameters may appear in any order.
98
99 <p>
100 The available parameter values are:
101 <ul>
102 <li><b>on</b><br>
103 Shorthand for <code>SQLAuthenticate users groups userset groupset</code>.<br>
104 </li>
105 <br>
106
107 <li><b>off</b><br>
108 Disables all <code>mod_sql</code> authentication functions.<br>
109 </li>
110 <br>
111
112 <li><b>users</b><br>
113 If present, <code>mod_sql</code> will do user lookups. If not present,
114 <code>mod_sql</code> will do <b>no</b> user lookups at all, including the
115 <code>{set|get|end}pwent()</code> calls (see below).<br>
116 </li>
117 <br>
118
119 <li><b>groups</b><br>
120 If present, <code>mod_sql</code> will do group lookups. If not present,
121 <code>mod_sql</code> will do <b>no</b> group lookups at all, including the
122 <code>{set|get|end}grent()</code> calls (see below).<br>
123 </li>
124 <br>
125
126 <li><b>userset[fast]</b><br>
127 If present, <code>mod_sql</code> will process the potentially expensive
128 <code>{set|get|end}pwent()</code> calls. If not present,
129 <code>mod_sql</code> will not process these calls. Adding the suffix
130 &quot;fast&quot; tells <code>mod_sql</code> to process the users as a
131 single large query, rather than making a query per user. This may
132 significantly reduce the number of queries against the database at the
133 expense of increased memory use. This parameter will have no effect if
134 &quot;users&quot; is not specified.<br>
135 </li>
136 <br>
137
138 <li><b>groupset[fast]</b><br>
139 If present, <code>mod_sql</code> will process the potentially expensive
140 <code>{set|get|end}grent()</code> calls. If not present,
141 <code>mod_sql</code> will not process these calls. Adding the suffix
142 &quot;fast&quot; tells <code>mod_sql</code> to process the groups as a
143 single large query, rather than making a query per group. This may
144 significantly reduce the number of queries against the database at the
145 expense of increased memory use. This parameter will have no effect if
146 &quot;groups&quot; is not specified.<br>
147 </li>
148 <br>
149 </ul>
150
151 <p>
152 The <code>SQLLog</code> and <code>SQLShowInfo</code> directives will always be
153 processed by <code>mod_sql</code>. The <code>SQLAuthenticate</code> directive
154 only affects the user and group lookup/authentication portions of the module.
155
156 <p>
157 Turning off (<i>i.e.</i> by not including) the <em>userset</em> or
158 <em>groupset</em> parameters affects the functionality of <code>mod_sql</code>.
159 Not allowing these lookups may remove the ability to control access or control
160 functionality by group membership, depending on your other authentication
161 handlers and the data available to them. At the same time, choosing not to
162 do these lookups may dramatically speed login for many large sites.
163
164 <p>
165 The &quot;fast&quot; suffix is not appropriate for every site. Normally,
166 <code>mod_sql</code> will retrieve a list of users and groups, and get
167 information from the database on a per-user or per-group basis. This is query
168 intensive: it requires (<i>n</i>n + 1) queries, where <i>n</i> is the number
169 of users or groups to lookup. By choosing &quot;fast&quot; lookups,
170 <code>mod_sql</code> will make a single <code>SELECT</code> query to get
171 information from the database.
172
173 <p>
174 In exchange for the radical reduction in the number of queries, the single
175 query will increase the memory consumption of the process; all group or user
176 information will be read at once rather than in discrete chunks.
177
178 <p>
179 <b>Group Table Structure</b><br>
180 Normally <b>mod_sql</b> allows multiple group members per row, and multiple
181 rows per group. If you use the &quot;fast&quot; option for <em>groupset</em>,
182 you <b>must</b> use only one row per group. For example, normally
183 <code>mod_sql</code> treats the following three tables in exactly the same way:
184
185 <pre>
186 |--------------------------------------------------|
187 | GROUPNAME | GID | MEMBERS |
188 |--------------------------------------------------|
189 | group1 | 1000 | naomi |
190 | group1 | 1000 | priscilla |
191 | group1 | 1000 | gertrude |
192 |--------------------------------------------------|
193
194 |--------------------------------------------------|
195 | GROUPNAME | GID | MEMBERS |
196 |--------------------------------------------------|
197 | group1 | 1000 | naomi, priscilla |
198 | group1 | 1000 | gertrude |
199 |--------------------------------------------------|
200
201 |--------------------------------------------------|
202 | GROUPNAME | GID | MEMBERS |
203 |--------------------------------------------------|
204 | group1 | 1000 | naomi, priscilla, gertrude |
205 |--------------------------------------------------|
206 </pre>
207 If you use the &quot;fast&quot; option, <code>mod_sql</code> assumes that all
208 entries are structured like the last example.
209
210 <p>
211 <hr>
212 <h3><a name="SQLAuthTypes">SQLAuthTypes</a></h3>
213 <strong>Syntax:</strong> SQLAuthTypes <em>[&quot;Backend&quot;|&quot;Crypt&quot;|&quot;Empty&quot;|&quot;OpenSSL&quot;|&quot;Plaintext&quot;] ...</em><br>
214 <strong>Default:</strong> None<br>
215 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
216 <strong>Module:</strong> mod_sql<br>
217 <strong>Compatibility:</strong> 1.2.0 and later
218
219 <p>
220 The <code>SQLAuthTypes</code> directive specifies which authentication method
221 are to be allowed, and their order of use. <b>You must specify at least one
222 authentication method.</b>
223
224 <p>
225 The current supported authentication methods are:
226 <ul>
227 <li><b>Backend</b><br>
228 Allows database-specific backend passwords. Not all backend databases
229 support this option. For example, MySQL datatabases use this option
230 to authenticate MySQL <code>'PASSWORD()'</code> encrypted passwords.
231 The Postgres backend, however, does nothing. <b>Caveat</b>: if
232 your MySQL activity log is world-readable, the user password
233 <b>will be visible</b>. You have been warned.<br>
234 </li>
235 <br>
236
237 <li><b>Crypt</b><br>
238 Allows passwords in the database to be of Unix <code>crypt(3)</code>
239 form. <b>Note</b> that the traditional Unix <code>crypt(3)</code>
240 function only uses the first 8 characters of a password. If you have
241 passwords longer than 8 characters, and some of those passwords have
242 the same first 8 characters, then those users may be able to log into
243 each others accounts.<br>
244 </li>
245 <br>
246
247 <li><b>Empty</b><br>
248 Allows empty passwords in the database, which match against <b>any</b>
249 password the user may give. The database field must be a truly
250 empty string; <code>NULL</code> values are not acceptable as empty
251 passwords. <b>Be very careful if using this authentication method.</b><br>
252 </li>
253 <br>
254
255 <li><b>OpenSSL</b><br>
256 Allows passwords in the database to be of the form
257 <code>'{digest-name}hashed-value'</code>, where <code>hashed-value</code>
258 is the base64-encoded digest of the passsword. Only available if you
259 define <code>HAVE_OPENSSL</code> when you compile <code>proftpd</code>
260 and you link with OpenSSL's <code>libcrypto</code> library; the easiest
261 way to handle this is to use the <code>--enable-openssl</code> configure
262 option.<br>
263 </li>
264 <br>
265
266 <li><b>Plaintext</b><br>
267 Allows passwords in the database to be in plaintext.<br>
268 </li>
269 <br>
270 </ul>
271
272 <p>
273 For example:
274 <pre>
275 SQLAuthTypes Crypt Empty
276 </pre>
277 configures <code>mod_sql</code> to first attempt to verify the password
278 using the Unix <code>crypt(3)</code> function, then, if that fails, determine
279 if the password in the database is empty (thus matching <i>any</i> given
280 password). If all of the configured authentication methods fail,
281 <code>mod_sql</code> will fail to authenticate the user.
282
283 <p>
284 Note that the <a href="mod_sql_passwd.html"><code>mod_sql_passwd</code></a>
285 module also provides other <code>SQLAuthTypes</code> values.
286
287 <p>
288 <hr>
289 <h3><a name="SQLBackend">SQLBackend</a></h3>
290 <strong>Syntax:</strong> SQLBackend <em>backend</em><br>
291 <strong>Default:</strong> Depends<br>
292 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
293 <strong>Module:</strong> mod_sql<br>
294 <strong>Compatibility:</strong> 1.3.0rc1 and later
295
296 <p>
297 In 1.3.0rc1, the <code>mod_sql</code> module gained the ability to be
298 compiled with multiple backend modules supported, <i>e.g.</i> to have
299 both <code>mod_sql_mysql</code> and <code>mod_sql_postgres</code>
300 usable in the same <code>proftpd</code> daemon. The <code>SQLBackend</code>
301 directive configures which of these different database backends should
302 be used.
303
304 <p>
305 If there is only one backend module compiled in, the <code>SQLBackend</code>
306 directive is not needed. If there are multiple backend modules compiled
307 and no <code>SQLBackend</code> directive is specified, then
308 <code>mod_sql</code> will default to using the first backend module listed.
309 For instance, if you configured <code>proftpd</code> using a
310 <code>configure</code> command such as:
311 <pre>
312 ./configure --with-modules=mod_sql:mod_sql_postgres:mod_sql_mysql ...
313 </pre>
314 then <code>mod_sql</code> would default to using <code>mod_sql_postgres</code>
315 as the backend module to use.
316
317 <p>
318 You might have multiple <code>&lt;VirtualHost&gt;</code> sections which use
319 different SQL backends, <i>e.g.</i>:
320 <pre>
321 &lt;VirtualHost 1.2.3.4&gt;
322 SQLBackend mysql
323 ...
324 &lt;/VirtualHost&gt;
325
326 &lt;VirtualHost 5.6.7.8&gt;
327 SQLBackend postgres
328 ...
329 &lt;/VirtualHost&gt;
330 </pre>
331 Use &quot;mysql&quot; for the <code>mod_sql_mysql</code> module, and
332 &quot;postgres&quot; for the <code>mod_sql_postgres</code> module.
333
334 <p>
335 <hr>
336 <h3><a name="SQLConnectInfo">SQLConnectInfo</a></h3>
337 <strong>Syntax:</strong> SQLConnectInfo <em>connection-info [username] [password] [policy] [ssl-ca:&lt;path&gt;] [ssl-cert:&lt;path&gt;] [ssl-key:&lt;path&gt;] [ssl-ciphers:&lt;list&gt;]</em><br>
338 <strong>Default:</strong> None<br>
339 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
340 <strong>Module:</strong> mod_sql<br>
341 <strong>Compatibility:</strong> 1.2.0 and later
342
343 <p>
344 The <code>SQLConnectInfo</code> directive configures the information necessary
345 to connect to the backend database. The <em>connection-info</em> parameter
346 specifies the database, host, port, and other backend-specific information.
347 The optional <em>username</em> and <em>password</em> parameters specify a
348 username and password to use when connecting to the database. Both default to
349 <code>NULL</code>, which the backend will treat in some backend-specific
350 manner. If you specify a password, you <b>must</b> specify a username. If
351 no <code>SQLConnectInfo</code> directive is specified, <code>mod_sql</code>
352 will disable itself.
353
354 <p>
355 Any given database backend has the opportunity, though not necessarily the
356 responsibility, to check for syntax errors in the <em>connection-info</em>
357 field at server startup, but you should not expect semantic errors
358 (<i>i.e.</i>, cannot connect to the database) to be caught until
359 <code>mod_sql</code> attempts to connect for a given host.
360
361 <p>
362 A given database connection is governed by a connection policy that specifies
363 when a connection should be opened and when it should be closed. There are
364 three options:
365 <ul>
366 <li><b>PERCONNECTION</b><br>
367 Open a database connection when the client connects to the server,
368 and close the database connection when the client disconnects.<br>
369 </li>
370 <br>
371
372 <li><b>PERSESSION</b><br>
373 Open a database connection on first use (<i>e.g.</i> during authentication)
374 and close the database connection at the end of the session.<br>
375 </li>
376 <br>
377
378 <li><i>number</i> (<b>"timed"</b>)<br>
379 Timed database connections that close themselves after <i>number</i>
380 seconds of inactivity.<br>
381 </li>
382 <br>
383 </ul>
384 If a connection policy is not specified, if the policy is not a number or is
385 a number less than 1, or if the policy is the string &quot;PERSESSION&quot;,
386 the <code>PERSESSION</code> policy will be used.
387
388 <p>
389 If the connection policy is any number greater than 0, it specifies the number
390 of seconds that a connection will be held open without activity. After that
391 many seconds of database inactivity, the connection to the database will be
392 closed. As soon as database activity starts again, the connection will be
393 opened and the timer will restart.
394
395 <p>
396 The MySQL and Postgres backends' <em>connection-info</em> is expected to be of
397 the form:
398 <pre>
399 database[@hostname][:port]
400 </pre>
401 hostname will default to a backend-specific hostname (which happens to
402 be 'localhost' for both the MySQL and Postgres backends), and port will
403 default to a backend-specific default port (3306 for the MySQL backend,
404 5432 for the Postgres backend).
405
406 <p>
407 From the MySQL documentation:
408 <blockquote>
409 the value of host may be either a hostname or an IP address. If host is NULL
410 or the string &quot;localhost&quot;, a connection to the local host is
411 assumed. If the OS supports sockets (Unix) or named pipes (Windows), they are
412 used instead of TCP/IP to connect to the server.
413 </blockquote>
414 (<i>Note</i>: In <code>proftpd-1.3.1rc1</code>, if <em>hostname</em> starts
415 with a slash, it is interpreted as the Unix domain socket path by
416 <code>mod_sql_mysql</code>, similar to how <code>mod_sql_postgres</code>
417 handles the parameter.)
418
419 From the PostgreSQL documentation:
420 <blockquote>
421 If [the hostname] begins with a slash, it specifies Unix domain communication
422 rather than TCP/IP communication; the value is the name of the directory in
423 which the socket file is stored. The default is to connect to a Unix-domain
424 socket in <code>/tmp</code>.
425 </blockquote>
426
427 <p>
428 If you plan to use the <code>"timed"</code> connection policy, consider the
429 effect of directives such as <code>DefaultRoot</code> on local socket
430 communication: once a user has been <code>chroot()</code>ed, the local socket
431 file will probably not be available within the <code>chroot</code> directory
432 tree, and attempts to reopen communication will fail. One way around this may
433 be to use hardlinks within the user's directory tree; another is to use
434 network (<i>e.g.</i> TCP sockets, not Unix domain sockets) connections to
435 connect to the database. <code>PERSESSION</code> connections are not affected
436 by this because the database will be opened prior to the <code>chroot()</code>
437 call, and held open for the life of the session. Network communications are
438 not affected by this <code>chroot()</code> problem. For example, while
439 <code>localhost</code> would <i>not</i> work for MySQL since the MySQL client
440 library will try to use Unix domain socket communications for that host,
441 <code>127.0.0.1</code> will work (as long as your database is setup to accept
442 these connections).
443
444 <p>
445 In <code>proftpd-1.3.6rc2</code> and later, it is possible to configure SSL/TLS
446 parameters for a given connection, which tells <code>mod_sql</code> to try
447 to open an SSL session with the database server. Most of the time, all that
448 is needed for the SSL session is the CA (Certificate Authority) to use, for
449 verifying the certificate presented by the database server. Thus:
450 <pre>
451 SQLConnectInfo ... ssl-ca:/path/to/cacert.pem
452 </pre>
453 If your database server is configured to require SSL/TLS mutual authentication
454 (also called "client auth"), you may need the <code>ssl-cert:</code> and
455 <code>ssl-key:</code> parameters as well:
456 <pre>
457 SQLConnectInfo ... ssl-ca:/path/to/cacert.pem \
458 ssl-cert:/path/to/client-cert.pem \
459 ssl-key:/path/to/client-key.pem
460 </pre>
461 Finally, some database clients (such as MySQL) allow you to configure the
462 specific SSL/TLS ciphersuites that should be used; the <code>ssl-ciphers:</code>
463 parameter can be used for this:
464 <pre>
465 SQLConnectInfo ... ssl-ca:/path/to/cacert.pem \
466 ssl-cert:/path/to/client-cert.pem \
467 ssl-key:/path/to/client-key.pem \
468 ssl-ciphers:DEFAULT:!EXPORT:!DES
469 </pre>
470
471 <p>
472 Examples:
473 <pre>
474 # Connect to the database 'ftpusers' via the default port at host
475 # 'foo.com'. Use a NULL username and NULL password when connecting.
476 # A connection policy of PERSESSION is used.
477 SQLConnectInfo [email protected]
478
479 # Connect to the database 'ftpusers' via port 3000 at host 'localhost'.
480 # Use the username 'admin' and a NULL password when connecting.
481 # A connection policy of PERSESSION is used.
482 SQLConnectInfo ftpusers:3000 admin
483
484 # Connect to the database 'ftpusers' via port 3000 at host 'foo.com'.
485 # Use the username 'admin' and password 'mypassword' when connecting.
486 # A connection policy of PERSESSION is used.
487 SQLConnectInfo [email protected]:3000 admin mypassword
488
489 # Connect to the database 'ftpusers' via port 3000 at host 'foo.com'.
490 # Use a username of 'admin' and a password of 'mypassword' when
491 # connecting. A 30 second timer of connection inactivity is activated.
492 SQLConnectInfo [email protected]:3000 admin mypassword 30
493
494 # Connect to the database 'ftpusers' via port 3000 at host 'foo.com'.
495 # Use a username of 'admin' and a password of 'mypassword' when
496 # connection. A 30 second inactivity/idle timer is used. In addition,
497 # use SSL for the connection.
498 SQLConnectInfo [email protected]:3000 admin mypassword 30 ssl-ca:/path/to/cacert.pem
499 </pre>
500 Backends may require different information in the <em>connection-info</em>
501 field; check your backend module for more detailed information.
502
503 <p>
504 <hr>
505 <h3><a name="SQLDefaultGID">SQLDefaultGID</a></h3>
506 <strong>Syntax:</strong> SQLDefaultGID <em>default-gid</em><br>
507 <strong>Default:</strong> 65533<br>
508 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
509 <strong>Module:</strong> mod_sql<br>
510 <strong>Compatibility:</strong> 1.2.0 and later
511
512 <p>
513 The <code>SQLDefaultGID</code> directive configures the default GID for users.
514 This value must be greater than any configured <code>SQLMinUserGID</code>.
515
516 <p>
517 See also: <a href="#SQLMinUserGID"><code>SQLMinUserGID</code></a>
518
519 <p>
520 <hr>
521 <h3><a name="SQLDefaultHomedir">SQLDefaultHomedir</a></h3>
522 <strong>Syntax:</strong> SQLDefaultHomedir <em>path</em><br>
523 <strong>Default:</strong> None<br>
524 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
525 <strong>Module:</strong> mod_sql<br>
526 <strong>Compatibility:</strong> 1.2.5rc1 and later
527
528 <p>
529 The <code>SQLDefaultHomedir</code> directive configures a default home
530 directory for all users authenticated with this module. If no home directory
531 is set with either directive, authentication fails. This directive does not
532 change the data retrieved from the database: if you specify a home directory
533 field to <code>SQLUserInfo</code>, that field's data will be returned as the
534 user's home directory, whether that data is a legal directory, or an empty
535 string, or <code>NULL</code>.
536
537 <p>
538 See also: <a href="#SQLUserInfo">SQLUserInfo</a>
539
540 <p>
541 <hr>
542 <h3><a name="SQLDefaultUID">SQLDefaultUID</a></h3>
543 <strong>Syntax:</strong> SQLDefaultUID <em>default-uid</em><br>
544 <strong>Default:</strong> 65533<br>
545 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
546 <strong>Module:</strong> mod_sql<br>
547 <strong>Compatibility:</strong> 1.2.0 and later
548
549 <p>
550 The <code>SQLDefaultUID</code> directive configures the default UID for users.
551 This value must be greater than any configured <code>SQLMinUserUID</code>.
552
553 <p>
554 See also: <a href="#SQLMinUserUID"><code>SQLMinUserUID</code></a>
555
556 <p>
557 <hr>
558 <h3><a name="SQLEngine">SQLEngine</a></h3>
559 <strong>Syntax:</strong> SQLEngine <em>on|off|auth|log</em><br>
560 <strong>Default:</strong> SQLEngine on<br>
561 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code>, <code>&lt;Anonymous&gt;</code><br>
562 <strong>Module:</strong> mod_sql<br>
563 <strong>Compatibility:</strong> 1.3.0rc1 and later
564
565 <p>
566 The <code>SQLEngine</code> directive is used to specify how
567 <code>mod_sql</code> will operate. By default, <code>SQLEngine</code> is
568 <em>on</em>, and <code>mod_sql</code> will operate as normal. Setting
569 <code>SQLEngine</code> to <em>off</em> will effectively disable the module.
570
571 <p>
572 In addition to <em>on</em> and <em>off</em>, <code>SQLEngine</code> accepts
573 two other values: <em>auth</em> and <em>log</em>. If you wish to use
574 <code>mod_sql</code> for authentication and not for logging (via
575 <a href="#SQLLog"><code>SQLLog</code></a>), use <em>auth</em>. Conversely,
576 to do only <code>SQLLog</code>-type logging, and no authentication, use
577 <em>log</em>.
578
579 <p>
580 This directive can be used to have <code>&lt;Anonymous&gt;</code> sections
581 that do not use <code>mod_sql</code>, <i>e.g.</i>:
582 <pre>
583 &lt;Anonymous ~ftp&gt;
584 ...
585 SQLEngine off
586 ...
587 &lt;/Anonymous&gt;
588 </pre>
589
590 <p>
591 <hr>
592 <h3><a name="SQLGroupInfo">SQLGroupInfo</a></h3>
593 <strong>Syntax:</strong> SQLGroupInfo <em>group-table group-name gid members</em><br>
594 <strong>Default:</strong> &quot;groups groupname gid members&quot;<br>
595 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
596 <strong>Module:</strong> mod_sql<br>
597 <strong>Compatibility:</strong> 1.2.5rc1 and later
598
599 <p>
600 The <code>SQLGroupInfo</code> directive configures the group table and fields
601 that hold group information. The parameters for this directive are
602 described below:
603 <ul>
604 <li><b>grouptable</b><br>
605 Specifies the name of the table that holds group information.<br>
606 </li>
607 <br>
608
609 <li><b>groupname</b><br>
610 Specifies the field in the group table that holds the group name.<br>
611 </li>
612 <br>
613
614 <li><b>gid</b><br>
615 Specifies the field in the group table that holds the group's GID.<br>
616 </li>
617 <br>
618
619 <li><b>members</b><br>
620 Specifies the field in the group table that holds the group members.<br>
621 </li>
622 <br>
623 </ul>
624 If you need to change <b>any</b> of these field names from the default, you
625 need to specify <b>all</b> of them.
626
627 <p>
628 <b>Custom Queries</b><br>
629 As of <code>1.3.3rc1</code>, the <code>SQLGroupInfo</code> directive accepts
630 an alternate syntax:
631 <pre>
632 SQLGroupInfo custom:/<i>get-group-by-name</i>/<i>get-group-by-id</i>/<i>get-group-by-member</i>
633 </pre>
634 where <i>get-group-by-name</i> refers to a configured SELECT
635 <code>SQLNamedQuery</code>. This named query <b>must</b> return one row, and
636 return the following columns, in this order: <code>groupname, gid,
637 members</code>. The configured query may make use of the variables mentioned
638 in the <code>SQLLog</code> description. The <code>%{0}</code> variable will
639 be populated with the group name for which info is being retrieved. The
640 <i>get-group-by-id</i> here refers to a <code>SQLNamedQuery</code> which is
641 <i>just</i> like the lookup given a group name, only the <i>get-group-by-id</i>
642 query needs to return group information given a GID. For the
643 <i>get-group-by-id</i> query, the <code>%{0}</code> variable is populated with
644 the GID in question. Last, the <i>get-group-by-member</i> query returns group
645 information given a user member; again, the <code>%{0}</code> will contain
646 the member/user name by which to look up the group information.
647
648 <p>
649 <b><i>If</i></b> your custom <em>get-group-by-name</em> query references a table
650 other than the default groups table, then you <b>must</b> also supply a
651 custom <em>get-group-by-id</em> query as well. Otherwise, <code>mod_sql</code>
652 will fail with a "Table not found" error, and disconnect the client, whenever
653 the client asks for a directory listing.
654
655 <p>
656 <b>Note</b>, however, that if you use the <em>groupset</em> or
657 <em>groupsetfast</em> <a href="#SQLAuthenticate"><code>SQLAuthenticate</code></a>
658 options, you will need to supply some additional <code>SQLNamedQuery</code>
659 names in your custom <code>SQLGroupInfo</code> directive. The
660 <code>SQLGroupInfo</code> directive supports:
661 <pre>
662 SQLGroupInfo custom:/<i>lookup-by-name</i>/<i>lookup-by-id</i>/<i>lookup-by-member</i>/[/<i>groupset-lookup</i>[/<i>groupsetfast-lookup</i>]]
663 </pre>
664 where <em>groupset-lookup</em> is the name of a SELECT
665 <code>SQLNamedQuery</code> that returns the names (and <i>only the names</i>)
666 of all groups, and the <em>groupsetfast-lookup</em> refers to a SELECT
667 <code>SQLNamedQuery</code> that returns all the fields (<i>i.e.</i>
668 <code>groupname, gid, members</code> in that order) for all groups.
669
670 <p>
671 To provide a concrete example:
672 <pre>
673 SQLAuthenticate users groups groupsetfast
674 SQLGroupInfo custom:/get-group-by-name/get-group-by-id/get-group-by-member/get-all-groupnames/get-all-groups
675 SQLNamedQuery get-group-by-name SELECT "groupname, gid, members FROM ftpgroups WHERE groupname = '%{0}'"
676 SQLNamedQuery get-group-by-id SELECT "groupname, gid, members FROM ftpgroups WHERE gid = %{0}"
677 SQLNamedQuery get-group-by-member SELECT "groupname, gid, members FROM ftpgroups WHERE (members LIKE '%%,%{0},%%' OR members LIKE '%{0},%%' OR members LIKE '%%,%{0}')"
678 SQLNamedQuery get-all-groupnames SELECT "groupname FROM ftpgroups"
679 SQLNamedQuery get-all-groups SELECT "groupname, gid, members FROM ftpgroups"
680 </pre>
681 With a configuration similar to these, using either of the <em>groupset</em> or
682 <em>groupsetfast</em> in your <code>SQLAuthenticate</code> directive will
683 work as expected.
684
685 <p>
686 Another consideration when using custom <code>SQLGroupInfo</code> queries
687 is their relationship to the "useNormalizedGroupSchema" <code>SQLOption</code>.
688 <i>I.e.</i> does using the "useNormalizedGroupSchema" option affect how
689 the results of custom <code>SQLGroupInfo</code> queries are handled? No.
690 If custom <code>SQLGroupInfo</code> queries are used, <code>mod_sql</code>
691 <i>automatically</i> assumes that the custom group members query will return
692 <i>N</i> rows, where each row contains 3 columns: group name, group ID,
693 and member name. That is, the custom <code>SQLGroupInfo</code> queries act as
694 if "useNormalizedGroupSchema" is always in effect. (When support for custom
695 <code>SQLGroupInfo</code> queries was added, there was no good reason for
696 supporting the old, inefficient comma-delimited format for the members column.)
697
698 <p>
699 <b>See Also</b>:
700 <a href="#SQLAuthenticate"><code>SQLAuthenticate</code></a>,
701 <a href="#SQLLog"><code>SQLLog</code></a>,
702 <a href="#SQLNamedQuery"><code>SQLNamedQuery</code></a>,
703 <a href="#SQLUserInfo"><code>SQLUserInfo</code></a>
704
705 <p>
706 <hr>
707 <h3><a name="SQLGroupPrimaryKey">SQLGroupPrimaryKey</a></h3>
708 <strong>Syntax:</strong> SQLGroupPrimaryKey <em>column | &quot;custom:/&quot;named-query</em><br>
709 <strong>Default:</strong> gid<br>
710 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
711 <strong>Module:</strong> mod_sql<br>
712 <strong>Compatibility:</strong> 1.3.5rc3 and later
713
714 <p>
715 The <code>SQLGroupPrimaryKey</code> directive configures the column name
716 that is used as the "primary key" for group data; this primary key can
717 then be used in other SQL tables via foreign key constraints. The
718 <a href="../howto/SQL.html#SQLPrimaryKeys">SQL howto</a> covers using this
719 directive in more details.
720
721 <p>
722 See also: <a href="#SQLUserPrimaryKey"><code>SQLUserPrimaryKey</code></a>
723
724 <p>
725 <hr>
726 <h3><a name="SQLGroupWhereClause">SQLGroupWhereClause</a></h3>
727 <strong>Syntax:</strong> SQLGroupWhereClause <em>where-clause</em><br>
728 <strong>Default:</strong> off<br>
729 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
730 <strong>Module:</strong> mod_sql<br>
731 <strong>Compatibility:</strong> 1.2.5rc1 and later
732
733 <p>
734 The directive is used to configure a WHERE clause that is added to every group
735 query. The WHERE clause <b>must</b> contain all relevant punctuation, and
736 <b>must not</b> contain a leading &quot;and&quot;.
737
738 <p>
739 As an example of a possible use for this directive, imagine if your group table
740 included a &quot;LoginAllowed&quot; field:
741 <pre>
742 SQLGroupWhereClause "LoginAllowed = 'true'"
743 </pre>
744 would be appended to every group-related query as the string:
745 <pre>
746 " WHERE (LoginAllowed = 'true')"
747 </pre>
748
749 <p>
750 <b>Note</b> that if custom group <code>SQLNamedQuery</code> are configured,
751 those custom queries will be used <i>as is</i>; any configured
752 <code>SQLGroupWhereClause</code> will <b>not</b> be appended. Custom queries
753 can be of any format/syntax, and thus simply appending a
754 <code>SQLGroupWhereClause</code> to a custom query may be syntactically invalid.
755
756 <p>
757 As of ProFTPD 1.3.1rc2, the configured <code>SQLGroupWhereClause</code>
758 parameter can use the same set of variables as supported by the
759 <a href="#SQLNamedQuery"><code>SQLNamedQuery</code></a> directive.
760
761 <p>
762 <hr>
763 <h3><a name="SQLKeepAlive">SQLKeepAlive</a></h3>
764 <strong>Syntax:</strong> SQLKeepAlive <em>interval [stmt]</em><br>
765 <strong>Default:</strong> None<br>
766 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
767 <strong>Module:</strong> mod_sql<br>
768 <strong>Compatibility:</strong> 1.3.7rc4 and later
769
770 <p>
771 The <code>SQLKeepAlive</code> directive configures a periodic <em>stmt</em> to
772 be executed on a timer, every <em>interval</em> seconds, as way of keeping
773 the connection between <code>mod_sql</code> and the backend database server
774 alive.
775
776 <p>
777 Note that the default <em>stmt</em> used is:
778 <pre>
779 SELECT 1
780 </pre>
781 This SQL statement works for MySQL, Postgres, and SQLite.
782
783 <p>
784 Examples:
785 <pre>
786 # Schedule a "keepalive" query every 30 seconds
787 SQLKeepAlive 30
788
789 # Schedule a "keepalive" query every 30 seconds, using our custom SQL
790 SQLKeepAlive 30 "SELECT foo FROM bar"
791 </pre>
792 The <em>stmt</em> used does <b>not</b> have to suceed; the important behavior
793 is the sending (and receiving) of bytes across the network to the database
794 server, so that any networking gear in between, such as firewalls and load
795 balancers, know that the connection is not idle, is still in use.
796
797 <p>
798 <hr>
799 <h3><a name="SQLLog">SQLLog</a></h3>
800 <strong>Syntax:</strong> SQLLog <em>cmd-set query-name [&quot;IGNORE_ERRORS&quot;]</em><br>
801 <strong>Default:</strong> None<br>
802 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
803 <strong>Module:</strong> mod_sql<br>
804 <strong>Compatibility:</strong> 1.2.1 and later
805
806 <p>
807 This directive is used to log information to a database table. Multiple
808 <code>SQLLog</code> directives can be in effect for any command; for example,
809 a user changing directories can trigger multiple logging statements.
810 <b>Note</b> that this logging occurs <em>at the end of command processing</em>.
811
812 <p>
813 The first parameter to <code>SQLLog</code>, the <em>cmd-set</em>, is a
814 comma-separated (<b>no spaces</b>) list of FTP commands for which this log
815 command will trigger. The list of commands is too long to list in entirety;
816 commands include <code>CWD, DELE, HELP, LIST, MKD, MODE, NLST, PASS, PASV,
817 PORT</code> and many more. For the complete list check the FTP RFCs.
818 Normally <code>mod_sql</code> will log events after they have completed
819 successfully; in the case of the <code>QUIT</code> command,
820 <code>mod_sql</code> logs prior to the server's processing of the command.
821 (Note, however, that the client <i>may not</i> issue a <code>QUIT</code>
822 before logging out; in this case, use a command of <code>EXIT</code> rather
823 than <code>QUIT</code>. <code>EXIT</code> is not a real FTP command, but
824 it is used here to provide a means for having <code>SQLLog</code> work
825 whenever a session ends.)
826
827 <p>
828 FTP commands in the command set will only be logged if they complete
829 successfully. Prefixing any command with &quot;ERR_&quot; will cause logging
830 to occur only if there was an error in the command's processing. To log both
831 errors and successful completion of a given command <i>X</i>, therefore,
832 you'll need both &quot;<i>X</i>&quot; and &quot;ERR_<i>X</i>&quot; in your
833 <em>cmd-set</em>.
834
835 <p>
836 The special command &quot;*&quot; matches all FTP commands, while
837 &quot;ERR_*&quot; matches all errors.
838
839 <p>
840 The second parameter is the name of a query defined by a
841 <code>SQLNamedQuery</code> directive. The query must be an
842 <code>UPDATE</code>, <code>INSERT</code>, or <code>FREEFORM</code> type
843 query; explicit <code>SELECT</code> queries will not be processed.
844
845 <p>
846 The third parameter is optional. If you add &quot;IGNORE_ERRORS&quot; as the
847 third parameter, <code>SQLLog</code> <b><i>will not</i></b> check for errors
848 in the processing of the named query. Any value for this parameter other than
849 the string &quot;IGNORE_ERRORS&quot; (case-insensitive) will not cause errors
850 to be ignored.
851
852 <p>
853 Normally, <code>SQLLog</code> directives are considered important enough that
854 errors in their processing will cause <code>mod_sql</code> to abort the client
855 session. References to non-existent named queries will <b>not</b> abort the
856 client session, but may result in database corruption (in the sense that the
857 expected database <code>UPDATE</code> or <code>INSERT</code> will not occur).
858 Check your directives carefully.
859
860 <p>
861 Examples:
862 <pre>
863 SQLLog PASS updatecount
864 SQLNamedQuery updatecount UPDATE "count=count+1 WHERE userid='%u'" users
865 </pre>
866 If the current user was &quot;joe&quot;, this would translate into the query
867 &quot;UPDATE users SET count=count+1 WHERE userid='joe'&quot;. This query
868 would run whenever a user was first authenticated.
869
870 <pre>
871 SQLLog CWD updatedir
872 SQLNamedQuery updatedir UPDATE "cwd='%d' where userid='%u'" users
873 </pre>
874 If the current user was &quot;joe&quot; and the current working directory were
875 <code>/tmp</code>, this would translate into the query &quot;UPDATE users SET cwd='/tmp' WHERE userid='joe'&quot;. This query would run whenever a user
876 changed directories.
877
878 <pre>
879 SQLLog RETR,STOR insertfileinfo
880 SQLNamedQuery insertfileinfo INSERT "'%f', %b, '%u@%v', now()" filehistory
881 </pre>
882 would log the name of any file stored or retrieved, the number of bytes
883 transferred, the user and host doing the transfer, and the time of transfer
884 (at least in MySQL). This would translate into a query like:
885 &quot;INSERT INTO filehistory VALUES ('somefile', 12345, '[email protected]', '21-05-2001 20:01:00')&quot;
886
887 <p>
888 <hr>
889 <h3><a name="SQLLogFile">SQLLogFile</a></h3>
890 <strong>Syntax:</strong> SQLLogFile <em>file</em><br>
891 <strong>Default:</strong> None<br>
892 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
893 <strong>Module:</strong> mod_sql<br>
894 <strong>Compatibility:</strong> 1.2.8rc2 and later
895
896 <p>
897 The <code>SQLLogFile</code> directive is used to specify a log file for
898 <code>mod_sql</code> reporting and debugging, and can be done a per-server
899 basis. The <em>file</em> parameter must be the full path to the file to use for
900 logging. Note that this path must <b>not</b> be to a world-writeable
901 directory and, unless <code>AllowLogSymlinks</code> is explicitly set to
902 <em>on</em> (generally a bad idea), the path must <b>not</b> be a symbolic
903 link.
904
905 <p>
906 If <em>file</em> is &quot;none&quot;, no logging will be done at all; this
907 setting can be used to override a <code>SQLLogFile</code> setting inherited from
908 a <code>&lt;Global&gt;</code> context.
909
910 <p>
911 <hr>
912 <h3><a name="SQLLogOnEvent">SQLLogOnEvent</a></h3>
913 <strong>Syntax:</strong> SQLLogOnEvent <em>event query-name ["IGNORE_ERRORS"]</em><br>
914 <strong>Default:</strong> None<br>
915 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code>
916 <strong>Module:</strong> mod_sql<br>
917 <strong>Compatibility:</strong> 1.3.5rc2 and later
918
919 <p>
920 The <code>SQLLogOnEvent</code> directive is used to log information to database
921 tables via <em>query-name</em>. Multiple <code>SQLLogOnEvent</code> directives
922 can be in effect for any event.
923
924 <p>
925 The first parameter is the name of an <em>event</em>.
926
927 <p>
928 The second parameter is the name of a query defined by a
929 <code>SQLNamedQuery</code> directive. The query must be an
930 <code>UPDATE</code>, <code>INSERT</code>, or <code>FREEFORM</code> type
931 query; explicit <code>SELECT</code> queries will not be processed.
932
933 <p>
934 The third parameter is optional. If you add &quot;IGNORE_ERRORS&quot; as the
935 third parameter, <code>SQLLogOnEvent</code> <b><i>will not</i></b> check for
936 errors in the processing of the named query. Any value for this parameter
937 other than the string &quot;IGNORE_ERRORS&quot; (case-insensitive) will not
938 cause errors to be ignored.
939
940 <p>
941 Examples:
942 <pre>
943 SQLNamedQuery update_max_logins UPDATE "max_login_attempts=max_login_attempts+1 WHERE userid='%u'" users
944 SQLLogOnEvent mod_auth.max-login-attempts update_max_logins
945 </pre>
946 In this example, a <code>users.max_login_attempts</code> column is updated
947 for the user trying to login, whenever that user exceeds a
948 <code>MaxLoginAttempts</code> limit.
949
950 <p>
951 <pre>
952 SQLNamedQuery add_banned_host INSERT "host = '%a'" bans
953 SQLLogOnEvent mod_ban.ban-host add_banned_host
954 </pre>
955 Here, whenever <code>mod_ban</code> bans a host, we add a row to a
956 <code>bans</code> table.
957
958 <p>
959 <hr>
960 <h3><a name="SQLMinID">SQLMinID</a></h3>
961 <strong>Syntax:</strong> SQLMinID <em>minimum-id</em><br>
962 <strong>Default:</strong> 999<br>
963 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
964 <strong>Module:</strong> mod_sql<br>
965 <strong>Compatibility:</strong> 1.2.0 and later
966
967 <p>
968 <code>SQLMinID</code> is a quick way of setting both <code>SQLMinUserGID</code>
969 and <code>SQLMinUserUID</code>. These values are checked whenever retrieving
970 a user's GID or UID.
971
972 <p>
973 See also: <a href="#SQLMinUserGID"><code>SQLMinUserGID</code></a>,
974 <a href="#SQLMinUserUID"><code>SQLMinUserUID</code></a>
975
976 <p>
977 <hr>
978 <h3><a name="SQLMinUserGID">SQLMinUserGID</a></h3>
979 <strong>Syntax:</strong> SQLMinUserGID <em>minimum-gid</em><br>
980 <strong>Default:</strong> 999<br>
981 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
982 <strong>Module:</strong> mod_sql<br>
983 <strong>Compatibility:</strong> 1.2.0 and later
984
985 <p>
986 <code>SQLMinUserGID</code> is checked whenever retrieving a user's GID. If the
987 retrieved value for GID is less than the value of <code>SQLMinUserGID</code>,
988 it is reported as the value of <code>SQLDefaultGID</code>.
989
990 <p>
991 See also: <a href="#SQLDefaultGID"><code>SQLDefaultGID</code></a>
992
993 <p>
994 <hr>
995 <h3><a name="SQLMinUserUID">SQLMinUserUID</a></h3>
996 <strong>Syntax:</strong> SQLMinUserUID <em>minimum-uid</em><br>
997 <strong>Default:</strong> 999<br>
998 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
999 <strong>Module:</strong> mod_sql<br>
1000 <strong>Compatibility:</strong> 1.2.0 and later
1001
1002 <p>
1003 <code>SQLMinUserUID</code> is checked whenever retrieving a user's UID. If the
1004 retrieved value for UID is less than the value of <code>SQLMinUserUID</code>,
1005 it is reported as the value of <code>SQLDefaultUID</code>.
1006
1007 <p>
1008 See also: <a href="#SQLDefaultUID"><code>SQLDefaultUID</code></a>
1009
1010 <p>
1011 <hr>
1012 <h3><a name="SQLNamedConnectInfo">SQLNamedConnectInfo</a></h3>
1013 <strong>Syntax:</strong> SQLNamedConnectInfo <em>connection-name</em> <em>sql-backend</em> <em>connection-info [username] [password] [policy] [ssl-ca:&lt;path&gt;] [ssl-cert:&lt;path&gt;] [ssl-key:&lt;path&gt;] [ssl-ciphers:&lt;list&gt;]</em><br>
1014 <strong>Default:</strong> None<br>
1015 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
1016 <strong>Module:</strong> mod_sql<br>
1017 <strong>Compatibility:</strong> 1.3.4rc2 and later
1018
1019 <p>
1020 The <code>SQLNamedConnectInfo</code> directive configures the information
1021 necessary to connect to the backend database. This connection will be given
1022 the name <em>connection-name</em>; this named connection can then be referenced
1023 by that name in <i>e.g.</i> a <code>SQLNamedQuery</code>. The
1024 <em>sql-backend</em> name configures the backend SQL module to use for this
1025 connection; see <a href="#SQLBackend"><code>SQLBackend</code></a>. The
1026 <em>connection-info</em> parameter specifies the database, host, port, and
1027 other backend-specific information. The optional <em>username</em> and
1028 <em>password</em> parameters specify a username and password to use when
1029 connecting to the database. Both default to <code>NULL</code>, which the
1030 backend will treat in some backend-specific manner. If you specify a password,
1031 you <b>must</b> specify a username. Multiple <code>SQLNamedConnectInfo</code>
1032 directives may be configured.
1033
1034 <p>
1035 <b>Note</b> that <code>SQLNamedConnectInfo</code> directives <b>will only be
1036 honored</b> if a <a href="#SQLConnectInfo"><code>SQLConnectInfo</code></a>
1037 directive is configured.
1038
1039 <p>
1040 See also: <a href="#SQLBackend"><code>SQLBackend</code></a>,
1041 <a href="#SQLConnectInfo"><code>SQLConnectInfo</code></a>
1042
1043 <p>
1044 <hr>
1045 <h3><a name="SQLNamedQuery">SQLNamedQuery</a></h3>
1046 <strong>Syntax:</strong> SQLNamedQuery <em>name type query-string [table] [connection-name]</em><br>
1047 <strong>Default:</strong> None<br>
1048 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
1049 <strong>Module:</strong> mod_sql<br>
1050 <strong>Compatibility:</strong> 1.2.4 and later
1051
1052 <p>
1053 SQLNamedQuery specifies a query and an identifier (name) for later use by
1054 <code>SQLShowInfo</code> and <code>SQLLog</code>.
1055
1056 <p>
1057 It is <b><i>strongly recommended</i></b> that you read documentation on the
1058 <code>LogFormat</code> and <code>ExtendedLog</code> directives, as the
1059 meta-sequences available to <code>SQLNamedQuery</code> are largely equivalent.
1060
1061 <p>
1062 The first parameter, <em>name</em>, should be unique across all named queries
1063 and must not contain spaces. The result of re-using a name is undefined.
1064
1065 <p>
1066 The second parameter, <em>type</em>, is the type of query, either
1067 &quot;SELECT&quot;, &quot;UPDATE&quot;, &quot;INSERT&quot;, or
1068 &quot;FREEFORM&quot;. See the note below for information on FREEFORM type
1069 queries.
1070
1071 <p>
1072 The third parameter is the substance of the database query itself; this should
1073 match the form of the second parameter. The meta-sequences accepted are
1074 exactly equivalent to the <code>LogFormat</code> directive <b><i>except</i></b>
1075 the following <b><i>are not</i></b> accepted:
1076 <ul>
1077 <li><code>%{FOOBAR}e</code><br>
1078 For <code>LogFormat</code>, this logs the content of environment variable
1079 &quot;FOOBAR&quot;. In a <code>SQLNamedQuery</code> SQL statement,
1080 however, environment variables can be referenced using <code>%{env:FOOBAR}</code>.
1081 </li>
1082 <br>
1083
1084 <li><code>%{format}t</code> and <code>%t</code><br>
1085 These two meta-sequences logged the local server time; they
1086 <b><i>are not</i></b> available in <code>mod_sql</code>. Your database
1087 undoubtedly provides another way to get the time; for example, MySQL
1088 provides the <code>now()</code> function.<br>
1089
1090 <p>
1091 However, a <code>%{time:<em>format</em>}</code> meta-sequence <i>is</i>
1092 supported. This sequence allows for formatting time strings according
1093 to the rules of the <code>strftime(3)</code> function.
1094 </li>
1095 <br>
1096 </ul>
1097 and the following <b><i>is in addition to</i></b> the <code>LogFormat</code>
1098 meta-sequences:
1099 <ul>
1100 <li><code>%d</code><br>
1101 The current working directory or &quot;-&quot; if none.<br>
1102 </li>
1103 <br>
1104
1105 <li><code>%{n}</code><br>
1106 This meta-sequence is used internally by <code>mod_sql</code> and other
1107 third-party modules and patches to pass information to the database.
1108 Using this meta-sequence in anything other than an <code>INSERT</code> or
1109 <code>UPDATE</code> query is an error, and using this meta-sequence unless
1110 directed to by a third-party module or patch is also an error.<br>
1111 </li>
1112 <br>
1113 </ul>
1114 The correct form of a query will be built from the directive arguments, except
1115 in the case of <code>FREEFORM</code> queries which will be sent directly to the
1116 database. The examples below show the way queries are built from the
1117 arguments.
1118
1119 <p>
1120 The fourth parameter, <em>table</em>, is only necessary for
1121 <code>UPDATE</code> or <code>INSERT</code> type queries, but is
1122 <b><i>required</i></b> for those types.
1123
1124 <p>
1125 The last parameter, <em>connection-name</em>, is only necessary for telling
1126 <code>mod_sql</code> to use the specified connection name (from
1127 <a href="#SQLNamedConnectInfo"><code>SQLNamedConnectInfo</code></a>), rather
1128 than the default connection, for executing the query/statement.
1129
1130 <p>
1131 <i>Note</i>: <code>FREEFORM</code> queries are a necessary evil; the
1132 simplistic query semantics of the <code>UPDATE</code>, <code>INSERT</code>,
1133 and <code>SELECT</code> type queries do not sufficiently expose the
1134 capabilities of most backend databases. At the same time, using a
1135 <code>FREEFORM</code> query makes it impossible for <code>mod_sql</code> to
1136 check whether the query type is appropriate, making sure that a
1137 <code>SELECT</code> query is not used in a <code>SQLLog</code> directive, for
1138 instance. Wherever possible, it is recommended that a specific query type be
1139 used.
1140
1141 <p>
1142 Examples:
1143 <pre>
1144 SQLNamedQuery count SELECT "count from users where userid='%u'"
1145 </pre>
1146 creates a query named &quot;count&quot; which could be used by
1147 <code>SQLShowInfo</code> to inform a user of their login count. The actual
1148 query would look something like &quot;SELECT count FROM users WHERE
1149 userid='matilda'&quot; for user &quot;matilda&quot;.
1150
1151 <pre>
1152 SQLNamedQuery updatecount UPDATE "count=count+1 WHERE userid='%u'" users
1153 </pre>
1154 creates a query named &quot;updatecount&quot; which could be used by
1155 <code>SQLLog</code> to update a user login counter in the table
1156 <code>users</code>. The actual query would look something like &quot;UPDATE
1157 users SET count=count+1 WHERE userid='persephone'&quot; for user
1158 &quot;persephone&quot;.
1159
1160 <pre>
1161 SQLNamedQuery accesslog INSERT "now(), '%u'" accesslog
1162 </pre>
1163 creates a query named &quot;accesslog&quot; which could be used by
1164 <code>SQLLog</code> to track access times by clients. The actual query would
1165 look something like &quot;INSERT INTO accesslog VALUES (now(), 'pandora')&quot;
1166 for user &quot;pandora&quot;. Note that this may be too simplistic for your
1167 table structure, since most databases require data for all columns to be
1168 provided in an <code>INSERT</code> statement of this form. See the following
1169 <code>FREEFORM</code> query for an example of something which may suit your
1170 needs better.
1171
1172 <pre>
1173 SQLNamedQuery accesslog FREEFORM "INSERT INTO accesslog(date, user) VALUES (now(), '%u')"
1174 </pre>
1175 creates a query named &quot;accesslog&quot; which could be used by
1176 <code>SQLLog</code> to track access times by clients. The actual query would
1177 look something like
1178 &quot;INSERT INTO accesslog(date, user) VALUES (now(), 'tilda')&quot; for
1179 user &quot;tilda&quot;.
1180
1181 <p>
1182 <hr>
1183 <h3><a name="SQLNegativeCache">SQLNegativeCache</a></h3>
1184 <strong>Syntax:</strong> SQLNegativeCache <em>on|off</em><br>
1185 <strong>Default:</strong> off<br>
1186 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
1187 <strong>Module:</strong> mod_sql<br>
1188 <strong>Compatibility:</strong> 1.2.7rc1 and later
1189
1190 <p>
1191 <code>SQLNegativeCache</code> specifies whether or not to cache negative
1192 responses from SQL lookups when using SQL for UID/GID lookups. Depending on
1193 your SQL tables, there can be a significant delay when a directory listing is
1194 performed as the UIDs not in the SQL database are repeatedly looked up in an
1195 attempt to present usernames instead of UIDs in directory listings. With
1196 <code>SQLNegativeCache</code> set to <em>on</em>, negative
1197 (&quot;not found&quot;) responses from SQL queries will be cached and speed
1198 will improve on directory listings that contain many users not present in the
1199 SQL database.
1200
1201 <p>
1202 <hr>
1203 <h3><a name="SQLOptions">SQLOptions</a></h3>
1204 <strong>Syntax:</strong> SQLOptions <em>opt1 ...</em><br>
1205 <strong>Default:</strong> None<br>
1206 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
1207 <strong>Module:</strong> mod_sql<br>
1208 <strong>Compatibility:</strong> 1.3.1rc1 and later
1209
1210 <p>
1211 The <code>SQLOptions</code> directive is used to tweak various optional
1212 behavior of <code>mod_sql</code>.
1213
1214 <p>
1215 Example:
1216 <pre>
1217 SQLOptions NoDisconnectOnError
1218 </pre>
1219
1220 <p>
1221 The currently implemented options are:
1222 <ul>
1223 <li><code>IgnoreConfigfile</code><br>
1224 <p>
1225 If the database client library in use has its own configuration file
1226 (<i>e.g.</i> <code>my.cnf</code> for the MySQL client library), then
1227 the <code>mod_sql</code> sub-module will read that file. There are some
1228 cases, however, where access to that config file is restricted. For
1229 such cases, use "IgnoreConfigFile" to tell <code>mod_sql</code> to not
1230 attempt to read that client library configuration file.
1231
1232 <p>
1233 <b>Note</b> that this option first appeared in
1234 <code>proftpd-1.3.5rc4</code>.
1235 </li>
1236
1237 <p>
1238 <li><code>NoDisconnectOnError</code><br>
1239 <p>
1240 By default, <code>mod_sql</code> will automatically disconnect the client
1241 whenever there is a database error. If this option is enabled,
1242 <code>mod_sql</code> will attempt to continue functioning despite
1243 database errors.
1244
1245 <p>
1246 <li><code>NoReconnect</code><br>
1247 <p>
1248 If supported by the database client library, <code>mod_sql</code> will
1249 try to automatically reconnect <i>once</i>, if it determines that the
1250 connection to the database server was lost. Use "NoReconnect" to disable
1251 this auto-reconnection attempt.
1252
1253 <p>
1254 <li><code>UseNormalizedGroupSchema</code><br>
1255 <p>
1256 If this option is enabled, then <code>mod_sql</code>, when retrieving all
1257 of the groups for a user, will use a SQL statement like:
1258 <pre>
1259 SELECT groupname, groupid, member FROM grouptable WHERE member = $userName
1260 </pre>
1261 rather than the statement it uses by default, which is:
1262 <pre>
1263 SELECT groupname, groupid, member FROM grouptable WHERE member = $userName OR
1264 member LIKE '%,$userName' OR member LIKE '$username,%' OR
1265 member LIKE '%,$userName,%'
1266 </pre>
1267 To put it another way, when this <code>SQLOption</code> is used,
1268 <code>mod_sql</code> will not treat the <i>member</i> column of the group
1269 table as a comma-delimited list of user names, but rather as a single
1270 user name. Thus, to have a user belong in multiple groups with this
1271 normalized schema, the group table would have individual rows for each
1272 user/group pair.
1273 </ul>
1274
1275 <p>
1276 <hr>
1277 <h3><a name="SQLRatios">SQLRatios</a></h3>
1278 <strong>Syntax:</strong> <em> </em><br>
1279 <strong>Default:</strong> None<br>
1280 <strong>Context:</strong> <br>
1281 <strong>Module:</strong> mod_sql<br>
1282 <strong>Compatibility:</strong>
1283
1284 <p>
1285 <hr>
1286 <h3><a name="SQLRatioStats">SQLRatioStats</a></h3>
1287 <strong>Syntax:</strong> <em> </em><br>
1288 <strong>Default:</strong> None<br>
1289 <strong>Context:</strong> <br>
1290 <strong>Module:</strong> mod_sql<br>
1291 <strong>Compatibility:</strong>
1292
1293 <p>
1294 <hr>
1295 <h3><a name="SQLShowInfo">SQLShowInfo</a></h3>
1296 <strong>Syntax:</strong> SQLShowInfo <em>cmd-set numeric query-string</em><br>
1297 <strong>Default:</strong> None<br>
1298 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
1299 <strong>Module:</strong> mod_sql<br>
1300 <strong>Compatibility:</strong> 1.2.5rc1 and later
1301
1302 <p>
1303 This directive creates a message to be sent to the user after any successful
1304 command.
1305
1306 <p>
1307 The first parameter, the <em>cmd-set</em>, is a comma separated (<b><i>no
1308 spaces</i></b>) list of FTP commands for which this log command will trigger.
1309 The list of commands is too long to list in entirety; commands include:
1310 <code>CWD, DELE, HELP, LIST, MKD, MODE, NLST, PASS, PASV, PORT</code> and many
1311 more. For the complete list check the FTP RFCs.
1312
1313 <p>
1314 FTP commands in the command set will only be triggered if they complete
1315 successfully. Prefixing any command with &quot;ERR_&quot; will show
1316 information only if there was an error in command processing. To send a
1317 message on both errors and successful completion of a given command <i>X</i>,
1318 therefore, you'll need both &quot;<i>X</i>&quot; and &quot;ERR_<i>X</i>&quot;
1319 in your <em>cmd-set</em>.
1320
1321 <p>
1322 The special command &quot;*&quot; matches all FTP commands, while
1323 &quot;ERR_*&quot; matches all errors.
1324
1325 <p>
1326 The second parameter, <em>numeric</em>, specifies the numeric value of the
1327 message returned to the FTP client. <b><i>Do not</i></b> choose a number
1328 blindly: message numbers may be parsed by clients. In most cases you will
1329 want to use <code>214</code>, the &quot;Help message&quot; numeric. It
1330 specifies that the information is only meant to be human readable. Note
1331 that FTP clients can be <i>very</i> picky about these response codes; choosing
1332 the wrong code can cause clients not to work. Section 5.4 of <a href="http://www.faqs.org/rfcs/rfc959.html">RFC959</a> defines the acceptable response codes
1333 for each FTP command.
1334
1335 <p>
1336 The third parameter, <em>query-string</em>, is exactly equivalent to the
1337 <em>query-string</em> parameter to the <code>SQLLog</code> directive, with one
1338 addition:
1339 <ul>
1340 <li><code>%{name}</code><br>
1341 The <b>first</b> return value from the <code>SQLNamedQuery</code>
1342 identified by &quot;name&quot;. There is currently no way to retrieve more
1343 than one value from the database at a time.<br>
1344 </li>
1345 <br>
1346 </ul>
1347 Any references to non-existent named queries, non-<code>SELECT</code> or
1348 -<code>FREEFORM</code> type queries, or references to queries which return a
1349 NULL first value, will be replaced with the string &quot;{null}&quot;.
1350 For example:
1351 <pre>
1352 SQLNamedQuery count SELECT "count from users where userid='%u'"
1353 SQLShowInfo PASS 230 "You've logged on %{count} times, %u"
1354 </pre>
1355 As long as the information is in the database, these two directives specify
1356 that the user will be greeted with their login count each time they
1357 successfully login. Note the use of the &quot;230&quot; numeric, which means
1358 &quot;User logged in, proceed&quot;. &quot;230&quot; is appropriate in this
1359 case because the message will be sent immediately after their password has
1360 been accepted and the session has started.
1361
1362 <p>
1363 <hr>
1364 <h3><a name="SQLUserInfo">SQLUserInfo</a></h3>
1365 <strong>Syntax:</strong> SQLUserInfo <em>user-table user-name passwd uid gid home-dir shell</em><br>
1366 <strong>Default:</strong> &quot;users userid passwd uid gid homedir shell&quot;<br>
1367 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
1368 <strong>Module:</strong> mod_sql<br>
1369 <strong>Compatibility:</strong> 1.2.5rc1 and later
1370
1371 <p>
1372 The <code>SQLUserInfo</code> directive configures the user table and fields
1373 that hold user information. If you need to change <b><i>any</i></b> of these
1374 field names from the default, you must specify <b><i>all</i></b> of them,
1375 whether NULL or not. The parameters are described below:
1376 <ul>
1377 <li><b>usertable</b><br>
1378 Specifies the name of the table that holds user information.<br>
1379 </li>
1380 <br>
1381
1382 <li><b>username</b><br>
1383 Specifies the field in the user table that holds the username.<br>
1384 </li>
1385 <br>
1386
1387 <li><b>passwd</b><br>
1388 Specifies the field in the user table that holds the user's password.<br>
1389 </li>
1390 <br>
1391
1392 <li><b>uid</b><br>
1393 Specifies the field in the user table that holds the user's UID. When a
1394 UID is retrieved from the database it is checked against the value of
1395 <code>SQLMinUserUID</code>. If the field name is specified as
1396 &quot;NULL&quot; the database will not be queried for this value and the
1397 user's UID will be set to the value of <code>SQLDefaultUID</code>.<br>
1398 </li>
1399 <br>
1400
1401 <li><b>gid</b><br>
1402 Specifies the field in the user table that holds the user's GID. When a
1403 GID is retrieved from the database it is checked against the value of
1404 <code>SQLMinUserGID</code>. If the field name is specified as
1405 &quot;NULL&quot; the database will not be queried for this value and the
1406 user's GID will be set to the value of <code>SQLDefaultGID</code>.<br>
1407 </li>
1408 <br>
1409
1410 <li><b>homedir</b><br>
1411 Specifies the field in the user table that holds the user's home directory.
1412 If the fieldname is specified as &quot;NULL&quot; the database will not be
1413 queried for this value and the user's home directory will be set to the
1414 value of <code>SQLDefaultHomedir</code>. If no home directory is set with
1415 either directive, user authentication will be automatically turned off.<br>
1416 </li>
1417 <br>
1418
1419 <li><b>shell</b><br>
1420 Specifies the field in the user table that holds the user's shell. If the
1421 fieldname is specified as &quot;NULL&quot; the database will not be
1422 queried and the shell will be reported as an empty string
1423 (&quot;&quot;).<br>
1424 </li>
1425 <br>
1426 </ul>
1427
1428 <p>
1429 <b>Custom Queries</b><br>
1430 As of <code>1.2.9rc1</code>, the <code>SQLUserInfo</code> directive accepts
1431 an alternate syntax:
1432 <pre>
1433 SQLUserInfo custom:/<i>name</i>
1434 </pre>
1435 where <i>name</i> refers to a configured SELECT <code>SQLNamedQuery</code>.
1436 This named query <b>must</b> return one row, and return the following columns,
1437 in this order: <code>username, passwd, uid, gid, homedir, shell</code>. The
1438 configured query may make use of the variables mentioned in the
1439 <code>SQLLog</code> description. This syntax allows the administrator
1440 a flexible way of constructing queries as needed. Note that if you want
1441 use the given <code>USER</code> name, you should use the <code>%U</code>
1442 variable, not <code>%u</code>; the latter requires the locally authenticated
1443 user name, which is exactly what <code>SQLUserInfo</code> is meant to
1444 provide.
1445
1446 <p>
1447 Starting with <code>1.3.3rc1</code>, you can supply other queries as well.
1448 You can supply a SELECT <code>SQLNamedQuery</code> for returning the
1449 same information as above, only this query is given a <i>UID</i> instead of
1450 a user name. For example:
1451 <pre>
1452 SQLNamedQuery get-user-by-name SELECT "userid, passwd, uid, gid, homedir, shell FROM ftpusers WHERE userid = '%U'"
1453 SQLNamedQuery get-user-by-id SELECT "userid, passwd, uid, gid, homedir, shell FROM ftpusers WHERE uid = %{0}"
1454
1455 SQLUserInfo custom:/get-user-by-name/get-user-by-id
1456 </pre>
1457 <b><i>If</i></b> your custom <em>get-user-by-name</em> query references a table
1458 other than the default users table, then you <b>must</b> also supply a
1459 custom <em>get-user-by-id</em> query as well. Otherwise, <code>mod_sql</code>
1460 will fail with a "Table not found" error, and disconnect the client, whenever
1461 the client asks for a directory listing.
1462
1463 <p>
1464 <b>Note</b>, however, that if you use the <em>userset</em> or
1465 <em>usersetfast</em> <a href="#SQLAuthenticate"><code>SQLAuthenticate</code></a>
1466 options, you will need to supply some additional <code>SQLNamedQuery</code>
1467 names in your custom <code>SQLUserInfo</code> directive. The
1468 <code>SQLUserInfo</code> directive supports:
1469 <pre>
1470 SQLUserInfo custom:/<i>lookup-by-name</i>[/<i>lookup-by-id</i>[/<i>userset-lookup</i>[/<i>usersetfast-lookup</i>]]]
1471 </pre>
1472 where <em>userset-lookup</em> is the name of a SELECT <code>SQLNamedQuery</code>
1473 that returns the names (and <i>only the names</i>) of all users, and the
1474 <em>usersetfast-lookup</em> refers to a SELECT <code>SQLNamedQuery</code>
1475 that returns all the fields (<i>i.e.</i> <code>username, passwd, uid, gid,
1476 homedir, shell</code> in that order) for all users.
1477
1478 <p>
1479 To provide a concrete example:
1480 <pre>
1481 SQLAuthenticate users groups usersetfast
1482 SQLUserInfo custom:/get-user-by-name/get-user-by-id/get-user-names/get-all-users
1483 SQLNamedQuery get-user-by-name SELECT "userid, passwd, uid, gid, homedir, shell FROM users WHERE userid = '%U'"
1484 SQLNamedQuery get-user-by-id SELECT "userid, passwd, uid, gid, homedir, shell FROM users WHERE uid = %{0}"
1485 SQLNamedQuery get-user-names SELECT "userid FROM users"
1486 SQLNamedQuery get-all-users SELECT "userid, passwd, uid, gid, homedir, shell FROM users"
1487 </pre>
1488 With a configuration similar to these, using either of the <em>userset</em> or
1489 <em>usersetfast</em> in your <code>SQLAuthenticate</code> directive will
1490 work as expected.
1491
1492 <p>
1493 <b>See Also</b>:
1494 <a href="#SQLAuthenticate"><code>SQLAuthenticate</code></a>,
1495 <a href="#SQLGroupInfo"><code>SQLGroupInfo</code></a>,
1496 <a href="#SQLLog"><code>SQLLog</code></a>,
1497 <a href="#SQLNamedQuery"><code>SQLNamedQuery</code></a>
1498
1499 <p>
1500 <hr>
1501 <h3><a name="SQLUserPrimaryKey">SQLUserPrimaryKey</a></h3>
1502 <strong>Syntax:</strong> SQLUserPrimaryKey <em>column | &quot;custom:/&quot;named-query</em><br>
1503 <strong>Default:</strong> uid<br>
1504 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
1505 <strong>Module:</strong> mod_sql<br>
1506 <strong>Compatibility:</strong> 1.3.5rc3 and later
1507
1508 <p>
1509 The <code>SQLUserPrimaryKey</code> directive configures the column name
1510 that is used as the "primary key" for user data; this primary key can
1511 then be used in other SQL tables via foreign key constraints. The
1512 <a href="../howto/SQL.html#SQLPrimaryKeys">SQL howto</a> covers using this
1513 directive in more details.
1514
1515 <p>
1516 See also: <a href="#SQLGroupPrimaryKey"><code>SQLGroupPrimaryKey</code></a>
1517
1518 <p>
1519 <hr>
1520 <h3><a name="SQLUserWhereClause">SQLUserWhereClause</a></h3>
1521 <strong>Syntax:</strong> SQLUserWhereClause <em>where-clause </em><br>
1522 <strong>Default:</strong> None<br>
1523 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
1524 <strong>Module:</strong> mod_sql<br>
1525 <strong>Compatibility:</strong> 1.2.5rc1 and later
1526
1527 <p>
1528 The directive is used to configure a WHERE clause that is added to every user
1529 query. The WHERE clause <b>must</b> contain all relevant punctuation, and
1530 <b>must not</b> contain a leading &quot;and&quot;.
1531
1532 <p>
1533 As an example of a possible use for this directive, imagine if your user table
1534 included a &quot;LoginAllowed&quot; field:
1535 <pre>
1536 SQLUserWhereClause "LoginAllowed = 'true'"
1537 </pre>
1538 would be appended to every user-related query as the string:
1539 <pre>
1540 " WHERE (LoginAllowed = 'true')"
1541 </pre>
1542
1543 <p>
1544 <b>Note</b> that if custom user <code>SQLNamedQuery</code> are configured,
1545 those custom queries will be used <i>as is</i>; any configured
1546 <code>SQLUserWhereClause</code> will <b>not</b> be appended. Custom queries
1547 can be of any format/syntax, and thus simply appending a
1548 <code>SQLUserWhereClause</code> to a custom query may be syntactically invalid.
1549
1550 <p>
1551 As of ProFTPD 1.3.1rc2, the configured <code>SQLUserWhereClause</code>
1552 parameter can use the same set of variables as supported by the
1553 <a href="#SQLNamedQuery"><code>SQLNamedQuery</code></a> directive.
1554
1555 <p>
1556 <hr>
1557 <h2><a name="Installation">Installation</a></h2>
1558 The <code>mod_sql</code> module is distributed with ProFTPD. Simply
1559 follow the normal steps for using third-party modules in ProFTPD:
1560 <pre>
1561 $ ./configure --with-modules=<i>sql-module-opts</i>
1562 </pre>
1563 where the specific <i>sql-module-opts</i> depend on your database needs. For
1564 example, if using MySQL, <i>sql-module-opts</i> would be
1565 &quot;mod_sql:mod_sql_mysql&quot;. <code>mod_sql</code> is the main
1566 SQL-processing engine, and <code>mod_sql_mysql</code> is the backend
1567 sub-module that handles MySQL-specific details. If Postgres is your
1568 database of choice, <i>sql-module-opts</i> would be
1569 &quot;mod_sql:mod_sql_postgres&quot;.
1570
1571 <p>
1572 You will also need to tell <code>configure</code> how to find the
1573 database-specific libraries and header files:
1574 <pre>
1575 $ ./configure --with-modules=<i>sql-module-opts</i> \
1576 --with-includes=<i>/path/to/db/header/file/dir</i> \
1577 --with-libraries=<i>/path/to/db/library/file/dir</i>
1578 </pre>
1579
1580 <p>
1581 Complete the build with the following standard commands:
1582 <pre>
1583 $ make
1584 $ make install
1585 </pre>
1586
1587 <p>
1588 <b>Logging</b><br>
1589 The <code>mod_sql</code> module supports <a href="../howto/Tracing.html">trace logging</a>, via the module-specific log channels:
1590 <ul>
1591 <li>sql
1592 </ul>
1593 Thus for trace logging, to aid in debugging, you would use the following in
1594 your <code>proftpd.conf</code>:
1595 <pre>
1596 TraceLog /path/to/ftpd/trace.log
1597 Trace sql:20
1598 </pre>
1599 This trace logging can generate large files; it is intended for debugging use
1600 only, and should be removed from any production configuration.
1601
1602 <p>
1603 <hr>
1604 <font size=2><b><i>
1605 &copy; Copyright 2000-2020 The ProFTPD Project<br>
1606 All Rights Reserved<br>
1607 </i></b></font>
1608 <hr>
1609
1610 </body>
1611 </html>