Debian Codegraph @

doc/contrib/mod_wrap2_sql.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ProFTPD module mod_wrap2_sql</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <hr>
10 <center>
11 <h2><b>ProFTPD module <code>mod_wrap2_sql</code></b></h2>
12 </center>
13 <hr>
14
15 <p>
16 This submodule provides the SQL database &quot;driver&quot; for storing
17 IP/DNS-based access control information in SQL tables.
18
19 <p>
20 This <code>mod_wrap2</code> submodule is contained in the
21 <code>mod_wrap2_sql.c</code> file, and is not compiled by default. See the
22 <code>mod_wrap2</code> <a href="mod_wrap2.html#Installation">installation</a>
23 instructions.
24
25 <h2>Author</h2>
26 <p>
27 Please contact TJ Saunders &lt;tj <i>at</i> castaglia.org&gt; with any
28 questions, concerns, or suggestions regarding this module.
29
30 <p>
31 <hr><h2><a name="SQLTables">SQL Access Tables</a></h2>
32 The <code>mod_wrap2_sql</code> module supports the &quot;sql&quot; string
33 for the <em>source-type</em> parameter of the
34 <a href="mod_wrap2.html#WrapUserTables"><code>WrapUserTables</code></a>,
35 <a href="mod_wrap2.html#WrapGroupTables"><code>WrapGroupTables</code></a>,
36 and
37 <a href="mod_wrap2.html#WrapTables"><code>WrapTables</code></a>,
38 configuration directives. If the &quot;sql&quot; <em>source-type</em> is used,
39 then the <em>source-info</em> parameter must be as described below. Note
40 that support for SQL-based access tables <b>requires</b> the use of
41 <code>mod_sql</code>.
42
43 <p>
44 <code>mod_wrap2_sql</code> requires two to four SQL-related configuration
45 directives: <code>SQLConnectInfo</code>, and two, possibly four,
46 <code>SQLNamedQuery</code> directives. The <code>SQLConnectInfo</code> is
47 necessary to allow the module to connect to the SQL database. The other
48 directives define the SQL queries that will be used by <code>mod_wrap2</code>
49 for its retrieval operations involving access data.
50
51 <p>
52 When using SQL tables and <code>mod_sql</code>, the access tables should appear
53 in the database named by the <code>SQLConnectInfo</code> directive, which
54 will probably also contain the authentication information tables. This way
55 your <code>proftpd</code>-specific tables are kept together. Also, it is
56 probably better to use a connection policy of PERSESSION, otherwise there will
57 be more overhead associated with each new connection made to the database for
58 each transaction.
59
60 <p>
61 One <code>SQLNamedQuery</code> is needed to <code>SELECT</code> access
62 information from the allow table, and one to <code>SELECT</code> access
63 information from the deny table. These queries should return a list of words,
64 where each word is a host name, host address, pattern, or wildcard (see
65 <a href="mod_wrap2.html#AccessRules">here</a> for how these things are
66 defined). Failure to define either of these <code>SQLNamedQuery</code>
67 directives will cause an error during <code>mod_wrap2_sql</code>'s operation.
68
69 <p>
70 Optionally, other <code>SQLNamedQuery</code> directives can be defined
71 to look up access <a href="mod_wrap2.html#AccessOptions">options</a> from
72 the allow and deny tables.
73
74 <p>
75 For SQL tables, the format for the <code>WrapUserTables</code>,
76 <code>WrapGroupTables</code>, and <code>WrapTables</code> directives is:
77 <pre>
78 WrapTables sql:/<i>allow-<code>SQLNamedQuery</code></i>[/<i>allow-options-<code>SQLNamedQuery</code></i>] \
79 sql:<i>deny-<code>SQLNamedQuery</code></i>[/<i>deny-options-<code>SQLNamedQuery</code></i>]
80 </pre>
81 where the <i>allow-options-<code>SQLNamedQuery</code></i> and
82 <i>deny-options-<code>SQLNamedQuery</code></i> portions of the string are
83 optional.
84
85 <p>
86 <b>SQL Access Tables Example</b><br>
87 Here are example <code>SQLNamedQuery</code> directives to help demonstrate
88 how the <code>mod_sql</code> hooks are used by <code>mod_wrap2_sql</code>.
89 These example SQL statements assume the existence of two tables: a
90 <code>wrapallow</code> table that defines allowed clients, and a
91 <code>wrapdeny</code> table that defines the denied clients.
92
93 <pre>
94 SQLNamedQuery get-allowed-clients SELECT "allowed FROM wrapallow WHERE name = '%{0}'"
95 SQLNamedQuery get-denied-clients SELECT "denied FROM wrapdeny WHERE name = '%{0}'"
96 ...
97 SQLNamedQuery get-all-allowed-clients SELECT "allowed FROM wrapallow"
98 SQLNamedQuery get-all-denied-clients SELET "denied FROM wrapdeny"
99 </pre>
100 These define the SQL statements to return the required list of words. The
101 <code>%{0}</code> meta sequence will be substituted with the name being looked
102 up (<i>e.g.</i> user name for <code>WrapUserTables</code>, primary group name
103 for <code>WrapGroupTables</code>, or the empty string for
104 <code>WrapTables</code>).
105
106 <p>
107 If the administrator wants to make use of access options, then queries for
108 those options would need to be similarly defined:
109 <pre>
110 SQLNamedQuery get-allowed-options SELECT "options FROM wrapallow WHERE name = '%{0}'"
111 SQLNamedQuery get-denied-options SELECT "options FROM wrapdeny WHERE name = '%{0}'"
112 </pre>
113
114 <p>
115 Now, using the above defined queries, the table configuration directives would
116 be:
117 <pre>
118 # Access tables for users (with options)
119 WrapUserTables user1,user2 sql:/get-allowed-clients/get-allowed-options \
120 sql:/get-denied-clients/get-denied-options
121
122 # Access tables for groups (with options). Note that this directive
123 # uses the same SELECT queries used for looking up users. If group
124 # access information is in a different table, then separate group-specific
125 # SQLNamedQuery directives will need to be used.
126 WrapGroupTables group1,group2 sql:/get-allowed-clients/get-allowed-options \
127 sql:/get-denied-clients/get-denied-options
128
129 # Access tables for everyone else (without options). Note that these
130 # query names are different, since these tables are global, not
131 # per-user/group.
132 WrapTables sql:/get-all-allowed-clients sql:/get-all-denied-clients
133 </pre>
134 One thing to keep in mind, however, is that the <code>%{0}</code> part of an
135 SQL query will only be expanded with the client's <code>USER</code> argument
136 for <code>WrapUserTables</code> queries. For <code>WrapGroupTables</code>
137 queries, that <code>%{0}</code> will be expanded to contain the primary group
138 name of the connecting client's <code>USER</code>. For <code>WrapTables</code>
139 queries, an empty string is used. This means that the same query cannot
140 often be easily reused.
141
142 <p>
143 <b>Example Schema</b><br>
144 Here are some example table schema for SQL-based access tables:
145 <ul>
146 <li><b><i>Per-User/Group Allow Table</i></b><br>
147 <pre>
148 CREATE TABLE wrapallow (
149 name VARCHAR(64) PRIMARY KEY,
150 allowed VARCHAR(255) NOT NULL,
151 options VARCHAR(255)
152 );
153 </pre>
154 </li>
155
156 <p>
157 <li><b><i>Per-User/Group Deny Table</i></b><br>
158 <pre>
159 CREATE TABLE wrapdeny (
160 name VARCHAR(64) PRIMARY KEY,
161 denied VARCHAR(255) NOT NULL,
162 options VARCHAR(255)
163 );
164 </pre>
165 </li>
166
167 <p>
168 <li><b><i>Per-IP Allow Table</i></b><br>
169 <pre>
170 CREATE TABLE wrapallowip (
171 allowed VARCHAR(128) PRIMARY KEY
172 );
173 </pre>
174 The idea here is that the <code>allowed</code> column would contain the IP
175 address of the client to be allowed; one row per IP address. The
176 <code>SQLNamedQuery</code> for this would then be:
177 <pre>
178 SQLNamedQuery get-allowed-client-ip SELECT "allowed FROM wrapallowip WHERE allowed = '%a'"
179 </pre>
180 Yes, this looks odd, to be returning the value that is used for the lookup,
181 but this interface is necessary due to the <code>mod_wrap2</code> engine.
182 </li>
183
184 <p>
185 <li><b><i>Per-IP Deny Table</i></b><br>
186 <pre>
187 CREATE TABLE wrapdenyip (
188 denied VARCHAR(128) PRIMARY KEY
189 );
190 </pre>
191 The idea here is that the <code>denied</code> column would contain the IP
192 address of the client to be denied; one row per IP address. The
193 <code>SQLNamedQuery</code> for this would then be:
194 <pre>
195 SQLNamedQuery get-denied-client-ip SELECT "denied FROM wrapdenyip WHERE denied = '%a'"
196 </pre>
197 Yes, this looks odd, to be returning the value that is used for the lookup,
198 but this interface is necessary due to the <code>mod_wrap2</code> engine.
199 </li>
200 </ul>
201
202 <p>
203 When constructing the client and options lists to return to
204 <code>mod_wrap2</code>'s access control engine, <code>mod_wrap2_sql</code> will
205 parse each returned row separately, handling both comma- and space-limited
206 names in a row, into client list items. This means that the administrator can
207 store multiple client and option tokens in multiple rows, as in the above
208 schema, or the administrator can choose to store all of the clients and/or
209 options in a single row, in an appropriately formatted string.
210
211 <p>
212 <hr>
213 <font size=2><b><i>
214 &copy; Copyright 2000-2017 TJ Saunders<br>
215 All Rights Reserved<br>
216 </i></b></font>
217 <hr>
218
219 </body>
220 </html>