| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD module mod_dso</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center> |
| 11 | <h2><b>ProFTPD module <code>mod_dso</code></b></h2> |
| 12 | </center> |
| 13 | <hr><br> |
| 14 | |
| 15 | <p> |
| 16 | <b>What are DSO modules?</b><br> |
| 17 | "On modern Unix derivatives there exists a nifty mechanism usually called |
| 18 | dynamic linking/loading of <i>Dynamic Shared Objects</i> (DSO) which provides |
| 19 | a way to build a piece of program code in a special format for loading it at |
| 20 | run-time into the address space of an executable program. |
| 21 | |
| 22 | <p> |
| 23 | This loading can usually be done in two ways: Automatically by a system program |
| 24 | called <code>ld.so</code> when an executable program is started, or manually |
| 25 | from within the executing program via a programmatic system interface to the |
| 26 | Unix loader through the system calls <code>dlopen()/dlsym()</code>. |
| 27 | |
| 28 | <p> |
| 29 | In the first way the DSO's are usually called <i>shared libraries</i> or |
| 30 | <i>DSO libraries</i> and named <code>libfoo.so</code> or |
| 31 | <code>libfoo.so.1.2</code>. They reside in a system directory (usually |
| 32 | <code>/usr/lib/</code>) and the link to the executable program is established |
| 33 | at build-time by specifying <code>-lfoo</code> to the linker command. This |
| 34 | hard-codes library references into the executable program file so that at |
| 35 | start-time the Unix loader is able to locate <code>libfoo.so</code> in |
| 36 | <code>/usr/lib/</code>, in paths hard-coded via linker-options like |
| 37 | <code>-R</code> or in paths configured via the environment variable |
| 38 | <code>LD_LIBRARY_PATH</code>. It then resolves any (yet unresolved) symbols in |
| 39 | the executable program which are available in the DSO. |
| 40 | |
| 41 | <p> |
| 42 | Symbols in the executable program are usually not referenced by the DSO |
| 43 | (because it's a reusable library of general code) and hence no further |
| 44 | resolving has to be done. The executable program has no need to do anything on |
| 45 | its own to use the symbols from the DSO because the complete resolving is done |
| 46 | by the Unix loader. (In fact, the code to invoke <code>ld.so</code> is part of |
| 47 | the run-time startup code which is linked into every executable program which |
| 48 | has been bound non-static.) The advantage of dynamic loading of common library |
| 49 | code is obvious: the library code needs to be stored only once, in a system |
| 50 | library like libc.so, saving disk space for every program. |
| 51 | |
| 52 | <p> |
| 53 | In the second way the DSO's are usually called <i>shared objects</i> or |
| 54 | <i>DSO files</i> and can be named with an arbitrary extension (although the |
| 55 | canonical name is <code>foo.so</code>). These files usually stay inside a |
| 56 | program-specific directory and there is no automatically established link to |
| 57 | the executable program where they are used. Instead the executable program |
| 58 | manually loads the DSO at run-time into its address space via |
| 59 | <code>dlopen()</code>. At this time no resolving of symbols from the DSO for |
| 60 | the executable program is done. Instead the Unix loader automatically resolves |
| 61 | any (yet unresolved) symbols in the DSO from the set of symbols exported by the |
| 62 | executable program and its already loaded DSO libraries (especially all symbols |
| 63 | from the ubiquitous <code>libc.so</code>). This way the DSO gets knowledge of |
| 64 | the executable program's symbol set as if it had been statically linked with |
| 65 | it in the first place." |
| 66 | |
| 67 | <p> |
| 68 | <i>(Taken from <a href="http://httpd.apache.org/docs/dso.html">http://httpd.apache.org/docs/dso.html</a>)</i> |
| 69 | |
| 70 | <p> |
| 71 | The <code>mod_dso</code> module is ProFTPD's module for handling the dynamic |
| 72 | loading of modules. This module is contained in the <code>mod_dso.c</code> |
| 73 | file for ProFTPD 1.3.<i>x</i>, and is not compiled by default. Installation |
| 74 | instructions are discussed <a href="#Installation">here</a>. |
| 75 | |
| 76 | <p> |
| 77 | The most current version of <code>mod_dso</code> can be found in the |
| 78 | ProFTPD source distribution: |
| 79 | <pre> |
| 80 | <a href="http://www.proftpd.org/">http://www.proftpd.org/</a> |
| 81 | </pre> |
| 82 | |
| 83 | <h2>Directives</h2> |
| 84 | <ul> |
| 85 | <li><a href="#LoadFile">LoadFile</a> |
| 86 | <li><a href="#LoadModule">LoadModule</a> |
| 87 | <li><a href="#ModuleControlsACLs">ModuleControlsACLs</a> |
| 88 | <li><a href="#ModuleOrder">ModuleOrder</a> |
| 89 | <li><a href="#ModulePath">ModulePath</a> |
| 90 | </ul> |
| 91 | |
| 92 | <p> |
| 93 | <h2>Control Actions</h2> |
| 94 | <ul> |
| 95 | <li><a href="#insmod">insmod</a> |
| 96 | <li><a href="#lsmod">lsmod</a> |
| 97 | <li><a href="#rmmod">rmmod</a> |
| 98 | </ul> |
| 99 | |
| 100 | <p> |
| 101 | <hr> |
| 102 | <h3><a name="LoadFile">LoadFile</a></h3> |
| 103 | <strong>Syntax:</strong> LoadFile <em>path</em><br> |
| 104 | <strong>Default:</strong> None<br> |
| 105 | <strong>Context:</strong> server config<br> |
| 106 | <strong>Module:</strong> mod_dso<br> |
| 107 | <strong>Compatibility:</strong> 1.3.0rc1 and later |
| 108 | |
| 109 | <p> |
| 110 | The <code>LoadFile</code> directive is used to load any shared object |
| 111 | (<code>.so</code> file extension), such as shared libraries. On some |
| 112 | platforms, it may be necessary to load all of the libraries needed by |
| 113 | a DSO module, using <code>LoadFile</code>, prior to loading the module itself. |
| 114 | |
| 115 | <p> |
| 116 | The <em>path</em> parameter must be the absolute path to the shared object |
| 117 | to load. |
| 118 | |
| 119 | <p> |
| 120 | Example: |
| 121 | <pre> |
| 122 | # Load the zlib library |
| 123 | LoadFile /usr/lib/libz.so |
| 124 | </pre> |
| 125 | |
| 126 | <p> |
| 127 | <hr> |
| 128 | <h3><a name="LoadModule">LoadModule</a></h3> |
| 129 | <strong>Syntax:</strong> LoadModule <em>name</em><br> |
| 130 | <strong>Default:</strong> None<br> |
| 131 | <strong>Context:</strong> server config<br> |
| 132 | <strong>Module:</strong> mod_dso<br> |
| 133 | <strong>Compatibility:</strong> 1.3.0rc1 and later |
| 134 | |
| 135 | <p> |
| 136 | The <code>LoadModule</code> directive is used to dynamically load a module |
| 137 | from the configuration file. |
| 138 | |
| 139 | <p> |
| 140 | Example: |
| 141 | <pre> |
| 142 | LoadModule mod_test.c |
| 143 | </pre> |
| 144 | |
| 145 | <p> |
| 146 | <hr> |
| 147 | <h3><a name="ModuleControlsACLs">ModuleControlsACLs</a></h3> |
| 148 | <strong>Syntax:</strong> ModuleControlsACLs <em>actions|all allow|deny user|group list</em><br> |
| 149 | <strong>Default:</strong> None<br> |
| 150 | <strong>Context:</strong> server config<br> |
| 151 | <strong>Module:</strong> mod_dso<br> |
| 152 | <strong>Compatibility:</strong> 1.3.0rc1 and later |
| 153 | |
| 154 | <p> |
| 155 | The <code>ModuleControlsACLs</code> directive configures access lists of |
| 156 | <em>users</em> or <em>groups</em> who are allowed (or denied) the ability to |
| 157 | use the <em>actions</em> implemented by <code>mod_dso</code>. The default |
| 158 | behavior is to deny everyone unless an ACL allowing access has been explicitly |
| 159 | configured. |
| 160 | |
| 161 | <p> |
| 162 | If "allow" is used, then <em>list</em>, a comma-delimited list |
| 163 | of <em>users</em> or <em>groups</em>, can use the given <em>actions</em>; all |
| 164 | others are denied. If "deny" is used, then the <em>list</em> of |
| 165 | <em>users</em> or <em>groups</em> cannot use <em>actions</em> all others are |
| 166 | allowed. Multiple <code>ModuleControlsACLs</code> directives may be used to |
| 167 | configure ACLs for different control actions, and for both users and groups. |
| 168 | |
| 169 | <p> |
| 170 | The <em>actions</em> provided by <code>mod_dso</code> are "insmod" |
| 171 | "lsmod", and "rmmod". |
| 172 | |
| 173 | <p> |
| 174 | Example: |
| 175 | <pre> |
| 176 | # Allow only user root to load and unload modules, but allow everyone |
| 177 | # to see which modules have been loaded |
| 178 | ModuleControlsACLs insmod,rmmod allow user root |
| 179 | ModuleControlsACLs lsmod allow user * |
| 180 | </pre> |
| 181 | |
| 182 | <p> |
| 183 | <hr> |
| 184 | <h3><a name="ModuleOrder">ModuleOrder</a></h3> |
| 185 | <strong>Syntax:</strong> ModuleOrder <em>...</em><br> |
| 186 | <strong>Default:</strong> None<br> |
| 187 | <strong>Context:</strong> server config<br> |
| 188 | <strong>Module:</strong> mod_dso<br> |
| 189 | <strong>Compatibility:</strong> 1.3.0rc1 and later |
| 190 | |
| 191 | <p> |
| 192 | The <code>ModuleOrder</code> directive can be used to explicitly set the |
| 193 | module order. <b>Note</b>: do not use this directive unless you know what |
| 194 | you are doing. It is <i>very</i> easy to configure a non-working server with |
| 195 | this directive. |
| 196 | |
| 197 | <p> |
| 198 | If you <i>are</i> going to use <code>ModuleOrder</code>, make sure it is |
| 199 | the very first directive in your <code>proftpd.conf</code> file. |
| 200 | |
| 201 | <p> |
| 202 | Example: |
| 203 | <pre> |
| 204 | # Make this one the very first things, if you're going to use it. |
| 205 | ModuleOrder \ |
| 206 | mod_core.c \ |
| 207 | mod_cap.c \ |
| 208 | mod_auth_unix.c \ |
| 209 | mod_auth_pam.c \ |
| 210 | mod_ls.c \ |
| 211 | mod_log.c \ |
| 212 | mod_site.c \ |
| 213 | mod_xfer.c \ |
| 214 | mod_auth.c \ |
| 215 | mod_ifsession.c \ |
| 216 | mod_auth_file.c |
| 217 | </pre> |
| 218 | |
| 219 | <p> |
| 220 | <hr> |
| 221 | <h3><a name="ModulePath">ModulePath</a></h3> |
| 222 | <strong>Syntax:</strong> ModulePath <em>path</em><br> |
| 223 | <strong>Default:</strong> None<br> |
| 224 | <strong>Context:</strong> server config<br> |
| 225 | <strong>Module:</strong> mod_dso<br> |
| 226 | <strong>Compatibility:</strong> 1.3.0rc1 and later |
| 227 | |
| 228 | <p> |
| 229 | The <code>ModulePath</code> directive is used to configure an alternative |
| 230 | directory from which <code>mod_dso</code> will load DSO modules. By |
| 231 | default, <code>mod_dso</code> uses <em>$prefix</em>/<code>libexec/</code>, |
| 232 | where <em>$prefix</em> is where you installed <code>proftpd</code>, |
| 233 | <i>e.g.</i> <code>/usr/local/</code>. |
| 234 | |
| 235 | <p> |
| 236 | The <em>path</em> parameter must be an absolute path. |
| 237 | |
| 238 | <p> |
| 239 | Example: |
| 240 | <pre> |
| 241 | ModulePath /etc/proftpd/libexec |
| 242 | </pre> |
| 243 | |
| 244 | <p> |
| 245 | <hr> |
| 246 | <h1>Control Actions</h1> |
| 247 | |
| 248 | <p> |
| 249 | <hr> |
| 250 | <h3><a name="insmod"><code>insmod</code></a></h3> |
| 251 | <strong>Syntax:</strong> ftpdctl insmod <em>module</em><br> |
| 252 | <strong>Purpose:</strong> Load a DSO module |
| 253 | |
| 254 | <p> |
| 255 | The <code>insmod</code> control action can be used to load a DSO module |
| 256 | into the running <code>proftpd</code> daemon. |
| 257 | |
| 258 | <p> |
| 259 | A module cannot be loaded multiple times. |
| 260 | |
| 261 | <p> |
| 262 | Example: |
| 263 | <pre> |
| 264 | ftpdctl rmmod mod_test.c |
| 265 | ftpdctl: 'mod_test.c' loaded |
| 266 | </pre> |
| 267 | |
| 268 | <p> |
| 269 | <hr> |
| 270 | <h3><a name="lsmod"><code>lsmod</code></a></h3> |
| 271 | <strong>Syntax:</strong> ftpdctl lsmod<br> |
| 272 | <strong>Purpose:</strong> Display list of all loaded modules |
| 273 | |
| 274 | <p> |
| 275 | The <code>lsmod</code> control action is used to display a list of all |
| 276 | loaded modules. |
| 277 | |
| 278 | <p> |
| 279 | Example: |
| 280 | <pre> |
| 281 | ftpdctl lsmod |
| 282 | ftpdctl: Loaded Modules: |
| 283 | ftpdctl: mod_core.c |
| 284 | ftpdctl: mod_xfer.c |
| 285 | ftpdctl: mod_auth_unix.c |
| 286 | ftpdctl: mod_auth_file.c |
| 287 | ftpdctl: mod_auth.c |
| 288 | ftpdctl: mod_ls.c |
| 289 | ftpdctl: mod_log.c |
| 290 | ftpdctl: mod_site.c |
| 291 | ftpdctl: mod_dso.c |
| 292 | ftpdctl: mod_ctrls.c |
| 293 | ftpdctl: mod_auth_pam.c |
| 294 | ftpdctl: mod_cap.c |
| 295 | </pre> |
| 296 | |
| 297 | <p> |
| 298 | <hr> |
| 299 | <h3><a name="rmmod"><code>rmmod</code></a></h3> |
| 300 | <strong>Syntax:</strong> ftpdctl rmmod <em>module</em><br> |
| 301 | <strong>Purpose:</strong> Unload a DSO module |
| 302 | |
| 303 | <p> |
| 304 | The <code>rmmod</code> control action can be used to unload a DSO module |
| 305 | from the running <code>proftpd</code> daemon. Note that it is also |
| 306 | possible to "unload" one of the statically-linked modules; this |
| 307 | does not remove that module from the process' memory space, but does remove |
| 308 | that module from the core engine, such that <code>proftpd</code> will |
| 309 | act as if the module is not present. |
| 310 | |
| 311 | <p> |
| 312 | Example: |
| 313 | <pre> |
| 314 | ftpdctl rmmod mod_test.c |
| 315 | ftpdctl: 'mod_test.c' unloaded |
| 316 | </pre> |
| 317 | |
| 318 | <p> |
| 319 | <hr> |
| 320 | <h2><a name="Usage">Usage</a></h2> |
| 321 | Note that <code>mod_dso</code>'s control actions are only available if |
| 322 | your <code>proftpd</code> has been compiled with Controls support. |
| 323 | |
| 324 | <p> |
| 325 | <hr> |
| 326 | <h2><a name="Installation">Installation</a></h2> |
| 327 | The <code>mod_dso</code> module is distributed with ProFTPD. To enable use |
| 328 | of DSO modules, use the <code>--enable-dso</code> configure option: |
| 329 | <pre> |
| 330 | $ ./configure --enable-dso |
| 331 | $ make |
| 332 | $ make install |
| 333 | </pre> |
| 334 | This option causes <code>mod_dso</code> to be compiled into |
| 335 | <code>proftpd</code>. |
| 336 | |
| 337 | <p> |
| 338 | <b>Logging</b><br> |
| 339 | The <code>mod_dso</code> module supports <a href="../howto/Tracing.html">trace logging</a>, via the module-specific log channels: |
| 340 | <ul> |
| 341 | <li>dso |
| 342 | </ul> |
| 343 | Thus for trace logging, to aid in debugging, you would use the following in |
| 344 | your <code>proftpd.conf</code>: |
| 345 | <pre> |
| 346 | TraceLog /path/to/ftpd/trace.log |
| 347 | Trace dso:20 |
| 348 | </pre> |
| 349 | This trace logging can generate large files; it is intended for debugging use |
| 350 | only, and should be removed from any production configuration. |
| 351 | |
| 352 | <p><a name="FAQ"> |
| 353 | <b>Frequently Asked Questions</b><br> |
| 354 | |
| 355 | <p><a name="DSOAlreadyLoaded"> |
| 356 | <font color=red>Question</font>: When I try to start <code>proftpd</code>, it |
| 357 | fails like this: |
| 358 | <pre> |
| 359 | proftpd[1234]: mod_dso/0.5: module 'mod_radius.c' already loaded |
| 360 | proftpd[1234]: Fatal: LoadModule: error loading module 'mod_radius.c': Operation not permitted on line 9 of '/etc/proftpd/proftpd.conf' |
| 361 | </pre> |
| 362 | How do I fix this "module already loaded" error?<br> |
| 363 | <font color=blue>Answer</font>: This happens when the proftpd configuration |
| 364 | either <i>a)</i> uses the <a href="#LoadModule"><code>LoadModule</code></a> |
| 365 | on a module which was compiled in as a static module, or <i>b)</i> is |
| 366 | inadvertently using <code>LoadModule</code> on the same module multiple times. |
| 367 | |
| 368 | <p> |
| 369 | To check if the module has been statically compiled into your |
| 370 | <code>proftpd</code> executable, use the <code>-l</code> command-line parameter, |
| 371 | <i>e.g.</i>: |
| 372 | <pre> |
| 373 | # proftpd -l |
| 374 | Compiled-in modules: |
| 375 | mod_core.c |
| 376 | mod_xfer.c |
| 377 | mod_auth_unix.c |
| 378 | mod_auth_file.c |
| 379 | mod_auth.c |
| 380 | mod_ls.c |
| 381 | mod_log.c |
| 382 | mod_site.c |
| 383 | mod_delay.c |
| 384 | mod_facts.c |
| 385 | mod_dso.c |
| 386 | mod_ident.c |
| 387 | mod_auth_pam.c |
| 388 | mod_tls.c |
| 389 | mod_cap.c |
| 390 | </pre> |
| 391 | The modules listed via the command are the static modules. So if your |
| 392 | <code>LoadModule</code> directive is used for one of the modules in this list, |
| 393 | you can remove that <code>LoadModule</code> directive; that module will already |
| 394 | be loaded. |
| 395 | |
| 396 | <p> |
| 397 | The other cause, that of having multiple <code>LoadModule</code> directives |
| 398 | for the same module, usually happens when your <code>proftpd.conf</code> |
| 399 | file includes other config files, <i>e.g.</i>: |
| 400 | <pre> |
| 401 | Include /path/to/modules.conf |
| 402 | </pre> |
| 403 | and it is those other config files which have <code>LoadModule</code> directives |
| 404 | of their own. |
| 405 | |
| 406 | <p> |
| 407 | If you find yourself needs to change the configuration to work around this |
| 408 | error, you can use the following to see if the module has already been |
| 409 | loaded, and if not, load it: |
| 410 | <pre> |
| 411 | <IfModule !mod_radius.c> |
| 412 | LoadModule mod_radius.c |
| 413 | </IfModule> |
| 414 | </pre> |
| 415 | |
| 416 | <p><a name="DSOAlreadyLoadedSpecialModules"> |
| 417 | <font color=red>Question</font>: When I try to start <code>proftpd</code>, it |
| 418 | fails like this: |
| 419 | <pre> |
| 420 | proftpd[1234]: mod_dso/0.5: module 'mod_ctrls.c' already loaded |
| 421 | proftpd[1234]: Fatal: LoadModule: error loading module 'mod_ctrls.c': Operation not permitted on line 9 of '/etc/proftpd/proftpd.conf' |
| 422 | </pre> |
| 423 | I do not have any other <code>LoadModule</code> directives in my config, nor |
| 424 | is the <code>mod_ctrls</code> module in my <code>--with-modules</code> |
| 425 | configure option.<br><br> |
| 426 | <font color=blue>Answer</font>: In this particular case, the |
| 427 | <code>mod_ctrls</code> module is automatically compiled in, as a static module, |
| 428 | when the <code>--enable-ctrls</code> configure option is used. There are only |
| 429 | a few such modules with this special handling: |
| 430 | <ul> |
| 431 | <li><code>mod_ctrls</code> (<i>via the <code>--enable-ctrls</code> configure option</i>) |
| 432 | <li><code>mod_dso</code> (<i>via the <code>--enable-dso</code> configure option</i>) |
| 433 | <li><code>mod_lang</code> (<i>via the <code>--enable-nls</code> configure option</i>) |
| 434 | <li><code>mod_memcache</code> (<i>via the <code>--enable-memcache</code> configure option</i>) |
| 435 | </ul> |
| 436 | All of these modules would appear in the <code>`proftpd -l'</code> static |
| 437 | module list. |
| 438 | |
| 439 | <p><a name="DSOLoadingStaticModule"></a> |
| 440 | <font color=red>Question</font>: If I use <a href="../utils/prxs.html"><code>prxs</code></a> to compile a module like <code>mod_ldap</code>, which is already |
| 441 | built into my <code>proftpd</code> as a static module, and then I use: |
| 442 | <pre> |
| 443 | LoadModule mod_ldap.c |
| 444 | </pre> |
| 445 | in my <code>proftpd.conf</code>, then which <code>mod_ldap</code> code is used, |
| 446 | the static module or the shared module?<br> |
| 447 | <font color=blue>Answer</font>: Excellent question. The short answer is: the |
| 448 | static module wins. |
| 449 | |
| 450 | <p> |
| 451 | When <code>mod_dso</code> goes to load a module, it first checks to see |
| 452 | whether that module is already loaded -- and if so, the module will |
| 453 | <b>not</b> be loaded again. Static modules, by definition, are always |
| 454 | "already loaded". This means that your <code>mod_ldap</code> shared module |
| 455 | code would not be loaded, and thus would not override the static module. |
| 456 | |
| 457 | <p><a name="DSOModulePathWorldWritable"> |
| 458 | <font color=red>Question</font>: I try to start my <code>proftpd</code> |
| 459 | instance, but it fails to start with this error: |
| 460 | <pre> |
| 461 | Fatal: ModulePath: <i>/usr/lib/proftpd</i> is world-writable on line <i>7</i> of <i>'/etc/proftpd/modules.conf'</i> |
| 462 | </pre> |
| 463 | Why?<br> |
| 464 | <font color=blue>Answer</font>: The <code>mod_dso</code> module, used by |
| 465 | ProFTPD for DSO/shared modules, ensures that the |
| 466 | <a href="#ModulePath"><code>ModulePath</code></a> directory is secure. DSO |
| 467 | modules are code that are loaded directly into <code>proftpd</code>; loading |
| 468 | these modules from a world-writable directory means that <b>any</b> system user |
| 469 | could inject/replace any of those DSO modules with their own code, and get |
| 470 | <code>proftpd</code> to do whatever they wanted. Thus <code>mod_dso</code> |
| 471 | will <b>refuse</b> to use a world-writable directory for loading of modules. |
| 472 | |
| 473 | <p> |
| 474 | To fix this, you simply need to ensure that the <code>ModulePath</code> directory is not world-writable, <i>e.g.</i>: |
| 475 | <pre> |
| 476 | $ chmod o-w /usr/lib/proftpd |
| 477 | </pre> |
| 478 | |
| 479 | <p> |
| 480 | <hr> |
| 481 | <font size=2><b><i> |
| 482 | © Copyright 2004-2017 TJ Saunders<br> |
| 483 | All Rights Reserved<br> |
| 484 | </i></b></font> |
| 485 | <hr> |
| 486 | |
| 487 | </body> |
| 488 | </html> |