| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD: Dynamic Shared Objects (DSOs)</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center><h2><b>ProFTPD: Dynamic Shared Objects (DSOs)</b></h2></center> |
| 11 | <hr> |
| 12 | |
| 13 | <p> |
| 14 | <b>What are DSOs?</b><br> |
| 15 | DSOs (<b>D</b>ynamic <b>S</b>hared <b>O</b>bjects) are specially built |
| 16 | binary files that can be loaded by an application while it is running, |
| 17 | extending the functionality of the application on-the-fly. One of the best |
| 18 | known applications that makes use of DSOs is the Apache web server; see |
| 19 | the Apache documentation for an in-depth description of DSOs: |
| 20 | <pre> |
| 21 | <a href="http://httpd.apache.org/docs/dso.html">http://httpd.apache.org/docs/dso.html</a> |
| 22 | </pre> |
| 23 | |
| 24 | <p> |
| 25 | <b>DSOs and ProFTPD</b><br> |
| 26 | ProFTPD gained the ability to use DSOs starting with the 1.3.0rc1 release. |
| 27 | To make sure the compiled <code>proftpd</code> binary can load DSO modules, |
| 28 | use the <code>--enable-dso</code> configure option: |
| 29 | <pre> |
| 30 | $ ./configure --enable-dso ... |
| 31 | </pre> |
| 32 | This causes the build system to build the <code>libltdl</code> supporting |
| 33 | library, which is used to handle OS-specific ways of loading and unloading |
| 34 | DSO files, and also to include the <a href="../../doc/modules/mod_dso.html"><code>mod_dso</code></a> module in the compiled <code>proftpd</code>. The |
| 35 | <code>mod_dso</code> module provides the <code>LoadModule</code> configuration |
| 36 | directive, for loading modules via the <code>proftpd.conf</code> configuration |
| 37 | file. |
| 38 | |
| 39 | <p> |
| 40 | The <code>contrib</code> modules that are distributed with the ProFTPD source, |
| 41 | <i>e.g.</i> <code>mod_ldap</code>, <code>mod_sql</code>, |
| 42 | <code>mod_quotatab</code>, <code>mod_ifsession</code>, <i>etc</i>, can |
| 43 | easily be built as DSO modules, rather than statically linked into the |
| 44 | <code>proftpd</code> binary. Instead of using the normal |
| 45 | <code>--with-modules</code> configure option, you use the |
| 46 | <code>--with-shared</code> option: |
| 47 | <pre> |
| 48 | $ ./configure --enable-dso --with-shared=mod_sql:mod_sql_mysql --with-includes=... --with-libraries=... |
| 49 | </pre> |
| 50 | These DSO modules will be installed under the <code>libexec/</code> directory |
| 51 | of your ProFTPD install location. To control the location of this |
| 52 | <code>libexec/</code> directory from which the <code>mod_dso</code> module |
| 53 | will load modules, you can use the <code>--libexecdir</code> configure |
| 54 | option, <i>e.g.</i>: |
| 55 | <pre> |
| 56 | $ ./configure --libexecdir=/path/to/custom/libexec --enable-dso ... |
| 57 | </pre> |
| 58 | |
| 59 | <p> |
| 60 | Note that ProFTPD uses the GNU <code>libtool</code> utility for creating |
| 61 | shared modules. This tool creates files with <code>.la</code> file extensions. |
| 62 | It is these <code>.la</code> files that will be installed into the |
| 63 | <code>libexec/</code> directory. This differs from the <code>.so</code> |
| 64 | files that Apache's DSO support generates, so do not be surprised. |
| 65 | |
| 66 | <p> |
| 67 | <b>Loading Modules</b><br> |
| 68 | There are two ways to load DSO modules into <code>proftpd</code>: the |
| 69 | <a href="../../doc/modules/mod_dso.html#LoadModule"><code>LoadModule</code></a> configuration directive, and the <a href="../../doc/modules/mod_dso.html#insmod"><code>insmod</code></a> <code>ftpdctl</code> action. Note that the latter |
| 70 | possibility is only available if your <code>proftpd</code> has been built with |
| 71 | <a href="Controls.html">Controls</a> support. |
| 72 | |
| 73 | <p> |
| 74 | Loading a module using <code>LoadModule</code> is quite simple. Simply use |
| 75 | the directive at the top of your <code>proftpd.conf</code> file, which makes |
| 76 | sure the module is loaded by <code>proftpd</code> before it processes other |
| 77 | directives: |
| 78 | <pre> |
| 79 | LoadModule mod_sql.c |
| 80 | LoadModule mod_sql_mysql.c |
| 81 | ... |
| 82 | |
| 83 | <IfModule mod_sql.c> |
| 84 | ... |
| 85 | </IfModule> |
| 86 | </pre> |
| 87 | |
| 88 | If a module fails to load properly, you might see messages like: |
| 89 | <pre> |
| 90 | Fatal: unknown configuration directive 'SQLConnectInfo' on line 86 of '/usr/local/proftpd/etc/proftpd.conf' |
| 91 | </pre> |
| 92 | This can happen if you forget to use the <code>LoadModule</code> directive |
| 93 | in your <code>proftpd.conf</code> prior to using directives from the |
| 94 | module. If you are using <code>LoadModule</code>, the error message may |
| 95 | look like: |
| 96 | <pre> |
| 97 | LoadModule: error loading module 'mod_sql_mysql.c': permission denied on line 65 of proftpd.conf |
| 98 | </pre> |
| 99 | Check the <code>libexec/</code> directory where you installed |
| 100 | <code>proftpd</code>, to see if the appropriate <code>.la</code> and/or |
| 101 | <code>.so</code> files are present. Then check your dynamic loader |
| 102 | configuration file (<i>e.g.</i> <code>/etc/ld.so.conf</code> on Linux) and |
| 103 | make sure that the <code>libexec/</code> directory is configured, so that the |
| 104 | dynamic loader knows to look in the correct locations. Note that the |
| 105 | <code>LD_LIBRARY_PATH</code> and/or <code>LD_RUN_PATH</code> environment |
| 106 | variables may also be used to inform the dynamic loader of |
| 107 | <code>proftpd</code>'s <code>libexec/</code> directory. |
| 108 | |
| 109 | <p> |
| 110 | Using <code>ftpdctl insmod</code> to load modules is tricky, as the loading of |
| 111 | a module directly into the running <code>proftpd</code>, without restarting the |
| 112 | server, can cause unexpected behavior. Many modules are not designed to |
| 113 | handle being loaded directly, and may cause bugs or unexpected crashes. |
| 114 | Support for this mode of loading modules will stabilize as the modules |
| 115 | are updated properly. |
| 116 | |
| 117 | <p> |
| 118 | <b>Module Ordering</b><br> |
| 119 | Is the order in which your <code>LoadModule</code> directives appear in |
| 120 | <code>proftpd.conf</code> important? The short answer is: <em>maybe</em>. |
| 121 | It depends on the modules. Some modules are self-sufficient, do not make |
| 122 | use of any other modules, and so can appear in any orders. Others, like |
| 123 | <code>mod_sql_mysql</code> or <code>mod_quotatab_sql</code>, require |
| 124 | that the frontend module (<i>e.g.</i> <code>mod_sql</code> or |
| 125 | <code>mod_quotatab</code>) be loaded first. Still others, like |
| 126 | <code>mod_ifsession</code>, do not directly require other modules, yet they |
| 127 | have effects that are dependent on the order; <code>mod_ifsession</code> |
| 128 | works best when it is the <b>last</b> module loaded. |
| 129 | |
| 130 | <p> |
| 131 | To achieve the necessary module order, you can make sure that your |
| 132 | <code>LoadModule</code> directives appear in the correct order, or you can |
| 133 | use the <a href="../../doc/modules/mod_dso.html#ModuleOrder"><code>ModuleOrder</code></a> directive. Note that using <code>ModuleOrder</code> can be |
| 134 | difficult, as it is very easy to use <code>ModuleOrder</code> to configure a |
| 135 | nonfunctional <code>proftpd</code>. |
| 136 | |
| 137 | <p> |
| 138 | <b>Compiling Custom Modules as DSOs</b><br> |
| 139 | The <code>--with-shared</code> configure option can be used to build DSOs |
| 140 | from the modules already distributed with ProFTPD, but what about building |
| 141 | a custom ProFTPD module as a DSO? Right now, this requires the ProFTPD |
| 142 | source, and not just an installed ProFTPD. |
| 143 | |
| 144 | <p> |
| 145 | Once you have your custom module written (<i>e.g.</i> |
| 146 | <code>mod_custom.c</code>), you create the <code>Makefile</code> that will |
| 147 | be used to compile it as a DSO module. The following can be used as a template |
| 148 | for the <code>Makefile</code>: |
| 149 | <pre> |
| 150 | PROFTPD_INSTALL=/usr/local/proftpd |
| 151 | |
| 152 | top_srcdir=$(PROFTPD_INSTALL) |
| 153 | srcdir=$(PROFTPD_INSTALL) |
| 154 | VPATH=$(PROFTPD_INSTALL) |
| 155 | |
| 156 | MODULE_NAME= |
| 157 | MODULE_CFLAGS= |
| 158 | MODULE_DEFS= |
| 159 | MODULE_LDFLAGS= |
| 160 | MODULE_LIBS= |
| 161 | |
| 162 | CC=gcc |
| 163 | DEFS=-DPR_SHARED_MODULE $(MODULE_DEFS) |
| 164 | CFLAGS=$(DEFS) -I. -I$(PROFTPD_INSTALL)/include/proftpd $(MODULE_CFLAGS) |
| 165 | LDFLAGS=-L$(PROFTPD_INSTALL)/lib $(MODULE_LDFLAGS) |
| 166 | LIBEXEC_DIR=$(PROFTPD_INSTALL)/libexec |
| 167 | LIBS=$(MODULE_LIBS) |
| 168 | |
| 169 | INSTALL=/usr/bin/install -c |
| 170 | INSTALL_BIN=$(INSTALL) -s -m 0755 |
| 171 | |
| 172 | LIBTOOL=$(SHELL) /usr/bin/libtool |
| 173 | LTDL_FLAGS=-avoid-version -export-dynamic -module |
| 174 | |
| 175 | # Targets |
| 176 | |
| 177 | all: $(MODULE_NAME).la |
| 178 | |
| 179 | $(MODULE_NAME).lo: |
| 180 | $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $(MODULE_NAME).c |
| 181 | |
| 182 | $(MODULE_NAME).la: $(MODULE_NAME).lo |
| 183 | $(LIBTOOL) --mode=link $(CC) -o $(MODULE_NAME).la -rpath $(LIBEXEC_DIR) $(LDFLAGS) $(LTDL_FLAGS) $(MODULE_NAME).lo $(LIBS) |
| 184 | |
| 185 | install: $(MODULE_NAME).la |
| 186 | if [ -f $(MODULE_NAME).la ] ; then \ |
| 187 | $(LIBTOOL) --mode=install $(INSTALL_BIN) $(MODULE_NAME).la $(DESTDIR)$(LIBEXEC_DIR) ; \ |
| 188 | fi |
| 189 | |
| 190 | clean: |
| 191 | $(LIBTOOL) --mode=clean $(RM) $(MODULE_NAME).la $(MODULE_NAME).lo config.* |
| 192 | |
| 193 | distclean: |
| 194 | $(RM) Makefile config.* |
| 195 | $(RM) -r autom4te.cache |
| 196 | </pre> |
| 197 | Fill in <code>MODULE_NAME</code> with the name of your module: |
| 198 | <pre> |
| 199 | MODULE_NAME=mod_custom |
| 200 | </pre> |
| 201 | The remaining <code>MODULE_</code> variables are used to specify additional |
| 202 | compiler and linker flags. If, for example, your <code>mod_custom.c</code> |
| 203 | module relied on a header file <code><custom.h></code> as well as |
| 204 | a library <code>libcustom.so</code>, you might have the following: |
| 205 | <pre> |
| 206 | MODULE_CFLAGS=-I/path/to/custom/include |
| 207 | MODULE_DEFS=-DUSE_LIBCUSTOM |
| 208 | MODULE_LDFLAGS=-L/path/to/custom/lib |
| 209 | MODULE_LIBS=-lcustom |
| 210 | </pre> |
| 211 | Place the <code>Makefile</code> in a directory with your |
| 212 | <code>mod_custom.c</code> source file, then do: |
| 213 | <pre> |
| 214 | $ make |
| 215 | $ make install |
| 216 | </pre> |
| 217 | The <code>make install</code> step will install the DSO module into the |
| 218 | <code>libexec/</code> directory of your ProFTPD install location. |
| 219 | |
| 220 | <p> |
| 221 | Once installed, update your <code>proftpd.conf</code> to make sure your |
| 222 | module is loaded: |
| 223 | <pre> |
| 224 | LoadModule mod_custom.c |
| 225 | </pre> |
| 226 | Then restart <code>proftpd</code>, and your custom module will be in use. |
| 227 | |
| 228 | <p><a name="prxs"></a> |
| 229 | <b>Using <code>prxs</code></b><br> |
| 230 | You may find yourself wanting to compile some third-party module, for which |
| 231 | you have the source code, as a DSO module for proftpd. But you may not have |
| 232 | the source code for proftpd, <i>e.g.</i> you might have installed proftpd |
| 233 | as a binary package. The build system for proftpd would let you compile |
| 234 | your third-party module as a DSO module, but what do you do if you don't have |
| 235 | access to the proftpd build system? |
| 236 | |
| 237 | <p> |
| 238 | The answer is to use the <code>prxs</code> script, which comes with proftpd. |
| 239 | The <code>prxs</code> (<b>PR</b>oFTPD E<b>X</b>tension<b>S</b>) tool will |
| 240 | compile and install third-party modules, from source code, as DSO modules |
| 241 | for your installed proftpd. |
| 242 | |
| 243 | <p> |
| 244 | The <code>prxs</code> tool supports the following actions: |
| 245 | <pre> |
| 246 | -c, --compile Compiles the listed <code>.c</code> source files |
| 247 | into a proftpd DSO module. |
| 248 | |
| 249 | -i, --install Installs a compiled proftpd DSO module into the |
| 250 | directory where proftpd expects to find loadable |
| 251 | DSO modules. |
| 252 | |
| 253 | -d, --clean Removes any generated files, returning the build |
| 254 | directory to a clean state. |
| 255 | </pre> |
| 256 | At least one of the above actions must be specified when using |
| 257 | <code>prxs</code>. More than one action can be specified at the same time. |
| 258 | |
| 259 | <p> |
| 260 | To use <code>prxs</code> all in one step, you could do: |
| 261 | <pre> |
| 262 | $ prxs -c -i -d mod_custom.c |
| 263 | </pre> |
| 264 | which will do the compile, install, and clean actions in order. Once |
| 265 | installed, update your <code>proftpd.conf</code> to make sure your module is |
| 266 | loaded: |
| 267 | <pre> |
| 268 | LoadModule mod_custom.c |
| 269 | </pre> |
| 270 | Then restart <code>proftpd</code>, and your custom module will be in use. |
| 271 | |
| 272 | <p> |
| 273 | For example, you might use <code>prxs</code> to compile the |
| 274 | <code>mod_sql_sqlite</code> module like so, from the top level of the |
| 275 | ProFTPD source directory: |
| 276 | <pre> |
| 277 | $ prxs -c -i -d contrib/mod_sql_sqlite.c |
| 278 | </pre> |
| 279 | |
| 280 | <p> |
| 281 | The following options are also supported: |
| 282 | <pre> |
| 283 | -n, --name Tells prxs the name of the module being compiled. |
| 284 | By default, prxs determines the module name from |
| 285 | the list of .c files listed, expecting to see a |
| 286 | "mod_<i>name</i>.c" file. |
| 287 | |
| 288 | -D key Passes these macros through to the compilation step. |
| 289 | -D key=value Note that the space before the key is important. |
| 290 | |
| 291 | -I <em>includedir</em> Specify additional include file search directories. |
| 292 | Note that the space before the directory is important. |
| 293 | |
| 294 | -L <em>libdir</em> Specify additional library file search directories. |
| 295 | Note that the space before the directory is important. |
| 296 | |
| 297 | -l <em>library</em> Specify additional libraries for linking. |
| 298 | Note that the space before the library name is important. |
| 299 | </pre> |
| 300 | |
| 301 | <p> |
| 302 | Using <code>prxs</code>, the above <code>mod_custom</code> example would |
| 303 | become: |
| 304 | <pre> |
| 305 | $ cd /path/to/mod_custom/dir |
| 306 | $ prxs -c -i -D USE_CUSTOM -I /path/to/custom/include -L /path/to/custom/lib -l custom mod_custom.c |
| 307 | </pre> |
| 308 | That's it! No need for a special Makefile, and no need to edit/replace any |
| 309 | variables. |
| 310 | |
| 311 | <p> |
| 312 | The <code>prxs</code> tool uses the <code>libtool</code> command that your |
| 313 | system should support. If you need to tell <code>prxs</code> to use a |
| 314 | different <code>libtool</code> for any reason (such as using a specially |
| 315 | installed <code>libtool</code>), you can use the <code>LIBTOOL</code> |
| 316 | environment variable to point <code>prxs</code> to the <code>libtool</code> |
| 317 | to use. For example: |
| 318 | <pre> |
| 319 | $ LIBTOOL=/path/to/custom/libtool prxs -c -i -d mod_custom.c |
| 320 | </pre> |
| 321 | |
| 322 | <p> |
| 323 | When should you use <code>prxs</code> for compiling DSO modules, and when |
| 324 | should you use a Makefile? In general, if the third-party module comes with |
| 325 | its own <code>configure</code> script and <code>Makefile</code>, then you |
| 326 | should use those. Otherwise, <code>prxs</code> should suffice. |
| 327 | |
| 328 | <p><a name="FAQ"> |
| 329 | <b>Frequently Asked Questions</b><br> |
| 330 | <font color=red>Question</font>: My installed <code>proftpd</code> does not |
| 331 | include <code>mod_sql_passwd</code> (or some other module). How can I get |
| 332 | proftpd to use this module without recompiling?<br> |
| 333 | <font color=blue>Answer</font>: First, see if your proftpd package came |
| 334 | with the <a href="#prxs"><code>prxs</code></a> tool; by default, this tool |
| 335 | is installed as <code>/usr/local/bin/prxs</code>. If you do not find |
| 336 | <code>prxs</code> anywhere on your system, you will have to recompile proftpd |
| 337 | in order to add new modules. |
| 338 | |
| 339 | <p> |
| 340 | Second, you will need the source code for <code>mod_sql_passwd</code> (or |
| 341 | whatever other module you want to add to your proftpd). Assume, then, that |
| 342 | you have found the <code>mod_sql_passwd.c</code> source file. The next |
| 343 | step is to use <code>prxs</code> to build that module as a DSO module: |
| 344 | <pre> |
| 345 | $ /usr/local/bin/prxs -c -i -d mod_sql_passwd.c |
| 346 | </pre> |
| 347 | If the above fails with this error message: |
| 348 | <pre> |
| 349 | Your installed proftpd does not support shared modules/DSOs. |
| 350 | Make sure the --enable-dso configure option is used when |
| 351 | compiling proftpd. |
| 352 | </pre> |
| 353 | It means that your <code>proftpd</code> does not have DSO support -- and |
| 354 | that means that you will have to recompile proftpd to add the new module. |
| 355 | |
| 356 | <p> |
| 357 | If, on the other hand, your <code>prxs</code> succeeded, the last steps are |
| 358 | to update your <code>proftpd.conf</code> to load the new module, and then |
| 359 | restart proftpd so that it reads the updated configuration. Continuing with |
| 360 | the example of <code>mod_sql_passwd</code>, you would add the following line |
| 361 | near the top of your <code>proftpd.conf</code>: |
| 362 | <pre> |
| 363 | LoadModule mod_sql_passwd.c |
| 364 | </pre> |
| 365 | and later in the config file, configure your newly added module: |
| 366 | <pre> |
| 367 | <IfModule mod_sql_passwd.c> |
| 368 | SQLPasswordEngine on |
| 369 | ... |
| 370 | </IfModule> |
| 371 | </pre> |
| 372 | Last, restart proftpd, and enjoy your new module's functionality, all without |
| 373 | needing to recompile/reinstall proftpd itself. |
| 374 | |
| 375 | <p> |
| 376 | <hr> |
| 377 | <font size=2><b><i> |
| 378 | © Copyright 2017 The ProFTPD Project<br> |
| 379 | All Rights Reserved<br> |
| 380 | </i></b></font> |
| 381 | <hr> |
| 382 | |
| 383 | </body> |
| 384 | </html> |