| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD module mod_exec</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr><br> |
| 10 | <center> |
| 11 | <h2><b>ProFTPD module <code>mod_exec</code></b></h2> |
| 12 | </center> |
| 13 | <hr><br> |
| 14 | |
| 15 | This module is contained in the <code>mod_exec.c</code> file for |
| 16 | ProFTPD 1.3.<i>x</i>, found |
| 17 | <a href="http://www.castaglia.org/proftpd/">here</a>, and is not compiled by |
| 18 | default. Installation instructions are discussed |
| 19 | <a href="#Installation">here</a>. |
| 20 | |
| 21 | <p> |
| 22 | The <code>mod_exec</code> module can be used to execute external programs |
| 23 | or scripts at various points in the process of handling FTP commands. By |
| 24 | conscious design, the core ProFTPD engine does not and will not execute |
| 25 | external programs. This is a security decision, as it was decided not to allow |
| 26 | ProFTPD to serve as a means of compromising a system or disclosing information |
| 27 | via bugs in external programs or scripts. Use of this module allows for such |
| 28 | external programs to be executed, and also opens up the server to the |
| 29 | mentioned possibilities of compromise or disclosure via those programs. |
| 30 | |
| 31 | <p> |
| 32 | <center> |
| 33 | <b>YOU HAVE BEEN WARNED</b><br> |
| 34 | <b>USE AT YOUR OWN RISK</b><br> |
| 35 | </center> |
| 36 | |
| 37 | <p> |
| 38 | Please read the <a href="#Usage">usage</a> section to know the other caveats |
| 39 | with this module. |
| 40 | |
| 41 | <p> |
| 42 | The most current version of <code>mod_exec</code> is distributed with the |
| 43 | ProFTPD source code. |
| 44 | |
| 45 | <h2>Author</h2> |
| 46 | <p> |
| 47 | Please contact TJ Saunders <tj <i>at</i> castaglia.org> with any |
| 48 | questions, concerns, or suggestions regarding this module. |
| 49 | |
| 50 | <h2>Directives</h2> |
| 51 | <ul> |
| 52 | <li><a href="#ExecBeforeCommand">ExecBeforeCommand</a> |
| 53 | <li><a href="#ExecEnable">ExecEnable</a> |
| 54 | <li><a href="#ExecEngine">ExecEngine</a> |
| 55 | <li><a href="#ExecEnviron">ExecEnviron</a> |
| 56 | <li><a href="#ExecLog">ExecLog</a> |
| 57 | <li><a href="#ExecOnCommand">ExecOnCommand</a> |
| 58 | <li><a href="#ExecOnConnect">ExecOnConnect</a> |
| 59 | <li><a href="#ExecOnError">ExecOnError</a> |
| 60 | <li><a href="#ExecOnEvent">ExecOnEvent</a> |
| 61 | <li><a href="#ExecOnExit">ExecOnExit</a> |
| 62 | <li><a href="#ExecOnRestart">ExecOnRestart</a> |
| 63 | <li><a href="#ExecOptions">ExecOptions</a> |
| 64 | <li><a href="#ExecTimeout">ExecTimeout</a> |
| 65 | </ul> |
| 66 | |
| 67 | <hr> |
| 68 | <h3><a name="ExecBeforeCommand">ExecBeforeCommand</a></h3> |
| 69 | <strong>Syntax:</strong> ExecBeforeCommand <em>cmds path [arg1 arg2 ...]</em><br> |
| 70 | <strong>Default:</strong> None<br> |
| 71 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code>, <code><Anonymous></code>, <code><Directory></code><br> |
| 72 | <strong>Module:</strong> mod_exec<br> |
| 73 | <strong>Compatibility:</strong> 1.2.8 and later |
| 74 | |
| 75 | <p> |
| 76 | The <code>ExecBeforeCommand</code> directive is used to execute the program or |
| 77 | script at <i>path</i> <b>before</b> the handling of any FTP command listed |
| 78 | in <i>cmds</i>, where <i>cmds</i> is a comma-delimited list of FTP commands. |
| 79 | The command groups of the <code><Limit></code> directive, such as |
| 80 | READ, WRITE, and ALL, may also be used. The program will be executed with |
| 81 | the privileges of the logged-in user. |
| 82 | |
| 83 | <p> |
| 84 | Any number of arbitrary arguments may be configured to pass to the script. |
| 85 | In addition, the variables supported by the <code>ExecEnviron</code> directive |
| 86 | may also be used in the script argument list. |
| 87 | |
| 88 | <p> |
| 89 | <b>Important</b>: use of <code>DefaultRoot</code> will cause complications |
| 90 | (to be elaborated upon soon). |
| 91 | |
| 92 | <p> |
| 93 | Example: |
| 94 | <pre> |
| 95 | ExecBeforeCommand RETR /path/to/ftp-prep --file %f |
| 96 | </pre> |
| 97 | |
| 98 | <p> |
| 99 | See Also: |
| 100 | <a href="#ExecEnviron">ExecEnviron</a>, |
| 101 | <a href="#ExecOnCommand">ExecOnCommand</a>, |
| 102 | <a href="#ExecOnConnect">ExecOnConnect</a>, |
| 103 | <a href="#ExecOnError">ExecOnError</a>, |
| 104 | <a href="#ExecOnExit">ExecOnExit</a>, |
| 105 | <a href="#ExecOnRestart">ExecOnRestart</a>, |
| 106 | <a href="http://www.proftpd.org/docs/modules/mod_core.html#Limit"><Limit></a> |
| 107 | |
| 108 | <p> |
| 109 | <hr> |
| 110 | <h3><a name="ExecEnable">ExecEnable</a></h3> |
| 111 | <strong>Syntax:</strong> ExecEnable <em>on|off</em><br> |
| 112 | <strong>Default:</strong> None<br> |
| 113 | <strong>Context:</strong> <code><Anonymous></code>, <code><Directory></code>, <code>.ftpaccess</code><br> |
| 114 | <strong>Module:</strong> mod_exec<br> |
| 115 | <strong>Compatibility:</strong> 1.3.6rc1 and later |
| 116 | |
| 117 | <p> |
| 118 | The <code>ExecEnable</code> directive can be used to disable the execution |
| 119 | of commands by <code>mod_exec</code> for particular directories or anonymous |
| 120 | logins. |
| 121 | |
| 122 | <p> |
| 123 | <hr> |
| 124 | <h3><a name="ExecEngine">ExecEngine</a></h3> |
| 125 | <strong>Syntax:</strong> ExecEngine <em>on|off</em><br> |
| 126 | <strong>Default:</strong> None<br> |
| 127 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 128 | <strong>Module:</strong> mod_exec<br> |
| 129 | <strong>Compatibility:</strong> 1.2.5rc2 and later |
| 130 | |
| 131 | <p> |
| 132 | The <code>ExecEngine</code> directive enables or disables the module's |
| 133 | runtime exec engine. If it is set to <em>off</em> this module will not |
| 134 | manipulate environment variables or execute external scripts. Use this |
| 135 | directive to disable the module instead of commenting out all |
| 136 | <code>mod_exec</code> directives. |
| 137 | |
| 138 | <p> |
| 139 | <hr> |
| 140 | <h3><a name="ExecEnviron">ExecEnviron</a></h3> |
| 141 | <strong>Syntax:</strong> ExecEnviron <em>key value</em><br> |
| 142 | <strong>Default:</strong> None<br> |
| 143 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 144 | <strong>Module:</strong> mod_exec<br> |
| 145 | <strong>Compatibility:</strong> 1.2.5rc2 and later |
| 146 | |
| 147 | <p> |
| 148 | The <code>ExecEnviron</code> directive is used to set the environment variables |
| 149 | in the environment created for the script to be executed. The current |
| 150 | environment is not passed directly to the script; this is to prevent unwanted |
| 151 | information leakage. The given <i>key</i> parameter will be uppercased, |
| 152 | to follow the convention for environment variable keys. |
| 153 | |
| 154 | <p> |
| 155 | The <i>value</i> parameter may be any arbitrary string which may contain any |
| 156 | of the normal <a href="../modules/mod_log.html#LogFormat"><code>LogFormat</code></a> variables. |
| 157 | |
| 158 | <p> |
| 159 | The <i>value</i> parameter may be also be "-", which indicates that |
| 160 | the current value of the environment variable of name <i>key</i> should be |
| 161 | used (<i>e.g.</i> PATH). If there is no environment of name <i>key</i> when |
| 162 | "-" is used, it will be created with a blank string as the value. |
| 163 | |
| 164 | <p> |
| 165 | <hr> |
| 166 | <h3><a name="ExecLog">ExecLog</a></h3> |
| 167 | <strong>Syntax:</strong> ExecLog <em>file|"none"</em><br> |
| 168 | <strong>Default:</strong> None<br> |
| 169 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 170 | <strong>Module:</strong> mod_exec<br> |
| 171 | <strong>Compatibility:</strong> 1.2.5rc2 and later |
| 172 | |
| 173 | <p> |
| 174 | The <code>ExecLog</code> directive is used to specify a log file for |
| 175 | <code>mod_exec</code> reporting and debugging, and can be done a per-server |
| 176 | basis. The <em>file</em> parameter must be the full path to the file to use for |
| 177 | logging. Note that this path must <b>not</b> be to a world-writeable |
| 178 | directory and, unless <code>AllowLogSymlinks</code> is explicitly set to |
| 179 | <em>on</em> (generally a bad idea), the path must <b>not</b> be a symbolic |
| 180 | link. |
| 181 | |
| 182 | <p> |
| 183 | If <em>file</em> is "none", no logging will be done at all; this |
| 184 | setting can be used to override an <code>ExecLog</code> setting inherited from |
| 185 | a <code><Global></code> context. |
| 186 | |
| 187 | <p> |
| 188 | <hr> |
| 189 | <h3><a name="ExecOnCommand">ExecOnCommand</a></h3> |
| 190 | <strong>Syntax:</strong> ExecOnCommand <em>cmds path [arg1 arg2 ...]</em><br> |
| 191 | <strong>Default:</strong> None<br> |
| 192 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code>, <code><Anonymous></code>, <code><Directory></code><br> |
| 193 | <strong>Module:</strong> mod_exec<br> |
| 194 | <strong>Compatibility:</strong> 1.2.5rc2 and later |
| 195 | |
| 196 | <p> |
| 197 | The <code>ExecOnCommand</code> directive is used to execute the program or |
| 198 | script at <i>path</i> <b>after</b> the successful completion of any FTP command |
| 199 | listed in <i>cmds</i>, where <i>cmds</i> is a comma-delimited list of FTP |
| 200 | commands. The command groups of the <code><Limit></code> directive, |
| 201 | such as READ, WRITE, and ALL, may also be used. The program will be executed |
| 202 | with the privileges of the logged-in user. |
| 203 | |
| 204 | <p> |
| 205 | Any number of arbitrary arguments may be configured to pass to the script. |
| 206 | In addition, the variables supported by the <code>ExecEnviron</code> directive |
| 207 | may also be used in the script argument list. |
| 208 | |
| 209 | <p> |
| 210 | <b>Important</b>: use of <code>DefaultRoot</code> will cause complications |
| 211 | (to be elaborated upon soon). |
| 212 | |
| 213 | <p> |
| 214 | Example: |
| 215 | <pre> |
| 216 | ExecOnCommand APPE,STOR /path/to/ftp-email-script --user %u --file %f |
| 217 | </pre> |
| 218 | |
| 219 | <p> |
| 220 | See Also: |
| 221 | <a href="#ExecBeforeCommand">ExecBeforeCommand</a>, |
| 222 | <a href="#ExecEnviron">ExecEnviron</a>, |
| 223 | <a href="#ExecOnConnect">ExecOnConnect</a>, |
| 224 | <a href="#ExecOnError">ExecOnError</a>, |
| 225 | <a href="#ExecOnExit">ExecOnExit</a>, |
| 226 | <A href="#ExecOnRestart">ExecOnRestart</a>, |
| 227 | <a href="http://www.proftpd.org/docs/modules/mod_core.html#Limit"><Limit></a> |
| 228 | |
| 229 | <p> |
| 230 | <hr> |
| 231 | <h3><a name="ExecOnConnect">ExecOnConnect</a></h3> |
| 232 | <strong>Syntax:</strong> ExecOnConnect <em>path [arg1 arg2 ...]</em><br> |
| 233 | <strong>Default:</strong> None<br> |
| 234 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code>, <code><Anonymous></code>, <code><Directory></code><br> |
| 235 | <strong>Module:</strong> mod_exec<br> |
| 236 | <strong>Compatibility:</strong> 1.2.5rc2 and later |
| 237 | |
| 238 | <p> |
| 239 | The <code>ExecOnConnect</code> directive is used to execute the program or |
| 240 | script at <i>path</i> whenever a client connects to the server. The program |
| 241 | will be executed with the privileges of the contacted server, which are |
| 242 | set via the <code>User</code>/<code>Group</code> directives. |
| 243 | |
| 244 | <p> |
| 245 | Any number of arbitrary arguments may be configured to pass to the script. |
| 246 | In addition, the variables supported by the <code>ExecEnviron</code> directive |
| 247 | may also be used in the script argument list. |
| 248 | |
| 249 | <p> |
| 250 | Example: |
| 251 | <pre> |
| 252 | ExecOnConnect /path/to/ftp-logger --ip %a --dns %h |
| 253 | </pre> |
| 254 | |
| 255 | <p> |
| 256 | See Also: |
| 257 | <a href="#ExecBeforeCommand">ExecBeforeCommand</a>, |
| 258 | <a href="#ExecEnviron">ExecEnviron</a>, |
| 259 | <a href="#ExecOnCommand">ExecOnCommand</a>, |
| 260 | <a href="#ExecOnError">ExecOnError</a>, |
| 261 | <a href="#ExecOnExit">ExecOnExit</a>, |
| 262 | <a href="#ExecOnRestart">ExecOnRestart</a> |
| 263 | |
| 264 | <p> |
| 265 | <hr> |
| 266 | <h3><a name="ExecOnError">ExecOnError</a></h3> |
| 267 | <strong>Syntax:</strong> ExecOnError <em>cmds path [arg1 arg2 ...]</em><br> |
| 268 | <strong>Default:</strong> None<br> |
| 269 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code>, <code><Anonymous></code>, <code><Directory></code><br> |
| 270 | <strong>Module:</strong> mod_exec<br> |
| 271 | <strong>Compatibility:</strong> 1.2.5rc2 and later |
| 272 | |
| 273 | <p> |
| 274 | The <code>ExecOnError</code> directive is used to execute the program or |
| 275 | script at <i>path</i> if an error occurs while processing any FTP command listed |
| 276 | in <i>cmds</i>, where <i>cmds</i> is a comma-delimited list of FTP commands. |
| 277 | The command groups of the <code><Limit></code> directive, such as |
| 278 | READ, WRITE, and ALL, may also be used. The program will be executed with |
| 279 | the privileges of the logged-in user. |
| 280 | |
| 281 | <p> |
| 282 | Any number of arbitrary arguments may be configured to pass to the script. |
| 283 | In addition, the variables supported by the <code>ExecEnviron</code> directive |
| 284 | may also be used in the script argument list. |
| 285 | |
| 286 | <p> |
| 287 | <b>Important</b>: use of <code>DefaultRoot</code> will cause complications |
| 288 | (to be elaborated upon soon). |
| 289 | |
| 290 | <p> |
| 291 | Example: |
| 292 | <pre> |
| 293 | ExecOnError APPE,STOR /path/to/ftp-cleanup-script --user %u --file %f |
| 294 | </pre> |
| 295 | |
| 296 | See Also: |
| 297 | <a href="#ExecBeforeCommand">ExecBeforeCommand</a>, |
| 298 | <a href="#ExecEnviron">ExecEnviron</a>, |
| 299 | <a href="#ExecOnCommand">ExecOnCommand</a>, |
| 300 | <a href="#ExecOnConnect">ExecOnConnect</a>, |
| 301 | <a href="#ExecOnExit">ExecOnExit</a>, |
| 302 | <a href="#ExecOnRestart">ExecOnRestart</a>, |
| 303 | <a href="http://www.proftpd.org/docs/modules/mod_core.html#Limit"><Limit></a> |
| 304 | |
| 305 | <p> |
| 306 | <hr> |
| 307 | <h3><a name="ExecOnEvent">ExecOnEvent</a></h3> |
| 308 | <strong>Syntax:</strong> ExecOnEvent <em>event[*|~] path [arg1 arg2 ...]</em><br> |
| 309 | <strong>Default:</strong> None<br> |
| 310 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 311 | <strong>Module:</strong> mod_exec<br> |
| 312 | <strong>Compatibility:</strong> 1.2.10rc1 and later |
| 313 | |
| 314 | <p> |
| 315 | The <code>ExecOnEvent</code> directive is used to execute the program or |
| 316 | script at <i>path</i> when the given <em>event</em> occurs. The program will |
| 317 | be executed with the privileges of the server (set via the <code>User</code> |
| 318 | and <code>Group</code> directives in the <code>proftpd.conf</code>file), |
| 319 | unless the <em>event</em> name is followed either by a "*" <em>or</em> |
| 320 | a "~" character. |
| 321 | |
| 322 | <p> |
| 323 | If the <em>event</em> name is followed by a "*", the program will be |
| 324 | executed with root privileges. <b>Note</b>: this feature should be used |
| 325 | <b>very carefully</b>. It allows scripts to modify things like firewall |
| 326 | rules, but should be used <b>only</b> for such sensitive tasks. |
| 327 | |
| 328 | <p> |
| 329 | If, on the other hand, the <em>eevent</em> name is followed by a "~", |
| 330 | the program will be executed with the privileges of the logged-in user. |
| 331 | <b>Note</b>: support for this feature first appeared in |
| 332 | <code>proftpd-1.3.5rc4</code>. |
| 333 | |
| 334 | <p> |
| 335 | Any number of arbitrary arguments may be configured to pass to the script. |
| 336 | In addition, the variables supported by the <code>ExecEnviron</code> directive |
| 337 | may also be used in the script argument list. |
| 338 | |
| 339 | <p> |
| 340 | Presently only two specific events are supported: <code>MaxConnectionRate</code> |
| 341 | and <code>MaxInstances</code>. These events happen when ever the limit |
| 342 | configured by these configuration directives is reached. |
| 343 | |
| 344 | <p> |
| 345 | This directive may be used several times to configure multiple programs |
| 346 | to be invoked when <em>event</em> occurs. |
| 347 | |
| 348 | <p> |
| 349 | <b>Important</b>: use of <code>DefaultRoot</code> will cause complications |
| 350 | (to be elaborated upon soon). |
| 351 | |
| 352 | <p> |
| 353 | Example: |
| 354 | <pre> |
| 355 | ExecOnEvent MaxConnectionRate* /path/to/ftp-firewall-script --ip %a |
| 356 | </pre> |
| 357 | |
| 358 | See Also: |
| 359 | <a href="#ExecBeforeCommand">ExecBeforeCommand</a>, |
| 360 | <a href="#ExecEnviron">ExecEnviron</a>, |
| 361 | <a href="#ExecOnCommand">ExecOnCommand</a>, |
| 362 | <a href="#ExecOnConnect">ExecOnConnect</a>, |
| 363 | <a href="#ExecOnExit">ExecOnExit</a>, |
| 364 | <a href="#ExecOnRestart">ExecOnRestart</a> |
| 365 | |
| 366 | <p> |
| 367 | <hr> |
| 368 | <h3><a name="ExecOnExit">ExecOnExit</a></h3> |
| 369 | <strong>Syntax:</strong> ExecOnExit <em>path [arg1 arg2 ...]</em><br> |
| 370 | <strong>Default:</strong> None<br> |
| 371 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code>, <code><Anonymous></code>, <code><Directory></code><br> |
| 372 | <strong>Module:</strong> mod_exec<br> |
| 373 | <strong>Compatibility:</strong> 1.2.8 and later |
| 374 | |
| 375 | <p> |
| 376 | The <code>ExecOnExit</code> directive is used to execute the program or |
| 377 | script at <i>path</i> whenever a client disconnects to the server. The program |
| 378 | will be executed with the privileges of the contacted server, which are |
| 379 | set via the <code>User</code>/<code>Group</code> directives. |
| 380 | |
| 381 | <p> |
| 382 | Any number of arbitrary arguments may be configured to pass to the script. |
| 383 | In addition, the variables supported by the <code>ExecEnviron</code> directive |
| 384 | may also be used in the script argument list. |
| 385 | |
| 386 | <p> |
| 387 | Example: |
| 388 | <pre> |
| 389 | ExecOnExit /path/to/ftp-logger --ip %a --dns %h |
| 390 | </pre> |
| 391 | |
| 392 | <p> |
| 393 | See Also: |
| 394 | <a href="#ExecBeforeCommand">ExecBeforeCommand</a>, |
| 395 | <a href="#ExecEnviron">ExecEnviron</a>, |
| 396 | <a href="#ExecOnCommand">ExecOnCommand</a>, |
| 397 | <a href="#ExecOnConnect">ExecOnConnect</a>, |
| 398 | <a href="#ExecOnError">ExecOnError</a>, |
| 399 | <a href="#ExecOnRestart">ExecOnRestart</a> |
| 400 | |
| 401 | <p> |
| 402 | <hr> |
| 403 | <h3><a name="ExecOnRestart">ExecOnRestart</a></h3> |
| 404 | <strong>Syntax:</strong> ExecOnRestart <em>path [arg1 arg2 ...]</em><br> |
| 405 | <strong>Default:</strong> None<br> |
| 406 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code>, <code><Anonymous></code>, <code><Directory></code><br> |
| 407 | <strong>Module:</strong> mod_exec<br> |
| 408 | <strong>Compatibility:</strong> 1.2.5rc2 and later |
| 409 | |
| 410 | <p> |
| 411 | The <code>ExecOnRestart</code> directive is used to execute the program or |
| 412 | script at <i>path</i> whenever the server receives a <code>SIGHUP</code> |
| 413 | signal. The program will be executed with the privileges of the contacted |
| 414 | server, which are set via the <code>User</code>/<code>Group</code> directives. |
| 415 | |
| 416 | <p> |
| 417 | Any number of arbitrary arguments may be configured to pass to the script. |
| 418 | In addition, the variables supported by the <code>ExecEnviron</code> directive |
| 419 | may also be used in the script argument list. |
| 420 | |
| 421 | <p> |
| 422 | Example: |
| 423 | <pre> |
| 424 | ExecOnRestart /path/to/ftp-counter-reset |
| 425 | </pre> |
| 426 | |
| 427 | See Also: |
| 428 | <a href="#ExecBeforeCommand">ExecBeforeCommand</a>, |
| 429 | <a href="#ExecEnviron">ExecEnviron</a>, |
| 430 | <a href="#ExecOnCommand">ExecOnCommand</a>, |
| 431 | <a href="#ExecOnConnect">ExecOnConnect</a>, |
| 432 | <a href="#ExecOnError">ExecOnError</a>, |
| 433 | <a href="#ExecOnExit">ExecOnExit</a> |
| 434 | |
| 435 | <p> |
| 436 | <hr> |
| 437 | <h3><a name="ExecOptions">ExecOptions</a></h3> |
| 438 | <strong>Syntax:</strong> ExecOptions <em>opt1 ...</em><br> |
| 439 | <strong>Default:</strong> None<br> |
| 440 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 441 | <strong>Module:</strong> mod_exec<br> |
| 442 | <strong>Compatibility:</strong> 1.2.9rc2 and later |
| 443 | |
| 444 | <p> |
| 445 | The <code>ExecOptions</code> directive is used to configure various optional |
| 446 | behavior of <code>mod_exec</code>. |
| 447 | |
| 448 | <p> |
| 449 | Example: |
| 450 | <pre> |
| 451 | ExecOptions logStderr sendStdout |
| 452 | </pre> |
| 453 | |
| 454 | <p> |
| 455 | The currently implemented options are: |
| 456 | <ul> |
| 457 | <li><code>logStderr</code><br> |
| 458 | <p>When executing commands, <code>mod_exec</code> usually ignore any |
| 459 | <code>stderr</code> output of the command. If this option is enabled, |
| 460 | <code>mod_exec</code> will monitor for and log any <code>stderr</code> |
| 461 | from the executed command to the <code>ExecLog</code>. |
| 462 | |
| 463 | <p> |
| 464 | <li><code>logStdout</code><br> |
| 465 | <p>When executing commands, <code>mod_exec</code> usually ignore any |
| 466 | <code>stdout</code> output of the command. If this option is enabled, |
| 467 | <code>mod_exec</code> will monitor for and log any <code>stdout</code> |
| 468 | from the executed command to the <code>ExecLog</code>. |
| 469 | |
| 470 | <p> |
| 471 | <li><code>sendStdout</code><br> |
| 472 | <p>If this option is enabled, <code>mod_exec</code> will attempt to |
| 473 | send any <code>stdout</code> output from the executed command to the |
| 474 | connected client. Note that this only works for commands that are |
| 475 | executed via <code>ExecOnCommand</code> or <code>ExecOnConnect</code>. |
| 476 | <p> |
| 477 | <b>Note</b> this this option should <b>not</b> be used for SSH2/SFTP/SCP |
| 478 | sessions, as it will only cause connection problems for SSH2/SFTP/SCP |
| 479 | clients. |
| 480 | |
| 481 | <p> |
| 482 | <li><code>useStdin</code><br> |
| 483 | <p>If this option is enabled, <code>mod_exec</code> will <b>not</b> |
| 484 | send arguments to the command being executed using the command line; |
| 485 | instead, those arguments will written to the <code>stdin</code> stream. |
| 486 | Each command-line argument will be written as a newline-terminated |
| 487 | string to <code>stdin</code>; the end of arguments is indicated by |
| 488 | writing the period ('.') character on a line by itself (again, terminated |
| 489 | with a newline). |
| 490 | |
| 491 | <p> |
| 492 | For example, a Perl script reading its arguments from <code>stdin</code> |
| 493 | would use something like: |
| 494 | <pre> |
| 495 | while (my $line = <STDIN>) { |
| 496 | chomp($line); |
| 497 | |
| 498 | if ($line eq ".") { |
| 499 | last; |
| 500 | } |
| 501 | |
| 502 | # Handle $line appropriately here |
| 503 | } |
| 504 | </pre> |
| 505 | The advantange of using this <code>useStdin</code> option is that some |
| 506 | systems have tools (<i>e.g.</i> <code>ps</code>) which will show the |
| 507 | command-line arguments to commands being executed. For the security |
| 508 | conscious, using <code>stdin</code> to pass arguments is less visible |
| 509 | to other users of the system. |
| 510 | </ul> |
| 511 | |
| 512 | <p> |
| 513 | <hr> |
| 514 | <h3><a name="ExecTimeout">ExecTimeout</a></h3> |
| 515 | <strong>Syntax:</strong> ExecTimeout <em>seconds</em><br> |
| 516 | <strong>Default:</strong> None<br> |
| 517 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 518 | <strong>Module:</strong> mod_exec<br> |
| 519 | <strong>Compatibility:</strong> 1.2.9rc2 and later |
| 520 | |
| 521 | <p> |
| 522 | The <code>ExecTimeout</code> directive is used to set a limit on how long |
| 523 | the executed commands can run. Processes that exceed the configured timeout |
| 524 | will first be sent SIGTERM, to allow them to cleanly shutdown. If the process |
| 525 | is still around, it will then be sent SIGKILL, which cannot be ignored. A |
| 526 | value of zero configures an infinite timeout (not recommended). |
| 527 | |
| 528 | <p> |
| 529 | <hr> |
| 530 | <h2><a name="Usage">Usage</a></h2> |
| 531 | Example configuration: |
| 532 | <pre> |
| 533 | <IfModule mod_exec.c> |
| 534 | ExecEngine on |
| 535 | ExecLog /var/log/ftpd/exec.log |
| 536 | ExecOnConnect /path/to/script |
| 537 | </IfModule> |
| 538 | </pre> |
| 539 | |
| 540 | <p> |
| 541 | This module will not work properly for <code><Anonymous></code> logins, |
| 542 | or for logins that are affected by <code>DefaultRoot</code>. These directives |
| 543 | use the <code>chroot(2)</code> system call, which wreaks havoc when it |
| 544 | comes to scripts. The path to script/shell interpreters often assume a certain |
| 545 | location that is no longer valid within a chroot. In addition, most modern |
| 546 | operating systems use dynamically loaded libraries (<code>.so</code> |
| 547 | libraries) for many binaries, including script/shell interpreters. The |
| 548 | location of these libraries, when they come to be loaded, are also assumed; |
| 549 | those assumptions break within a chroot. Perl, in particular, is so |
| 550 | wrought with filesystem location assumptions that it's almost impossible |
| 551 | to get a Perl script to work within a chroot, short of installing Perl |
| 552 | itself into the chroot environment. |
| 553 | |
| 554 | <p> |
| 555 | In short, this module is probably not what you want. And, try as I might, |
| 556 | I cannot convince users that this module is not what they want. Therefore, |
| 557 | I'll let you try to use this module yourself, and you can prove to yourself |
| 558 | that it probably won't do what you want. |
| 559 | |
| 560 | <p> |
| 561 | As an alternative to <code>mod_exec</code> for executing arbitrary |
| 562 | scripts/commands based on FTP command issued, file uploaded/downloaded, |
| 563 | <i>etc</i>, I recommend using a logging FIFO-based approach, similar to |
| 564 | what is illustrated <a href="../howto/Logging.html">here</a>. This approach |
| 565 | allows for any script you wish, and is not subject to the restrictions of a |
| 566 | chroot, meaning that you can use <code>DefaultRoot</code> and still have |
| 567 | arbitrary scripts executed. If requested, I can provide help in writing a |
| 568 | FIFO reader to execute the necessary scripts. |
| 569 | |
| 570 | <p> |
| 571 | <hr> |
| 572 | <h2><a name="Installation">Installation</a></h2> |
| 573 | The <code>mod_exec</code> module is distributed with ProFTPD. Follow the |
| 574 | usual steps for using third-party modules in ProFTPD: |
| 575 | <pre> |
| 576 | $ ./configure --with-modules=mod_exec |
| 577 | </pre> |
| 578 | To build <code>mod_exec</code> as a DSO module: |
| 579 | <pre> |
| 580 | $ ./configure --enable-dso --with-shared=mod_exec |
| 581 | </pre> |
| 582 | Then follow the usual steps: |
| 583 | <pre> |
| 584 | $ make |
| 585 | $ make install |
| 586 | </pre> |
| 587 | |
| 588 | <p> |
| 589 | Alternatively, if your <code>proftpd</code> was compiled with DSO support, you |
| 590 | can use the <code>prxs</code> tool to build <code>mod_exec</code> as a shared |
| 591 | module: |
| 592 | <pre> |
| 593 | $ prxs -c -i -d mod_exec.c |
| 594 | </pre> |
| 595 | |
| 596 | <p><a name="FAQ"></a> |
| 597 | <b>Frequently Asked Questions</b><br> |
| 598 | <font color=red>Question</font>: Why do <code>%U/%u</code> not work properly with <code>ExecOnConnect</code>?<br> |
| 599 | <font color=blue>Answer</font>: Both <code>%U</code> and <code>%u</code> will |
| 600 | be empty on <code>ExecOnConnect</code> because, at that point, the client has |
| 601 | done a TCP connect to the server, but has not sent any sort of information |
| 602 | (including user name). Which means that <code>mod_exec</code> does not have |
| 603 | a user name to use at connect time. |
| 604 | |
| 605 | <p> |
| 606 | One way to work around this limitation is to use a different trigger, |
| 607 | <i>e.g.</i>: |
| 608 | <pre> |
| 609 | ExecOnCommand PASS ... |
| 610 | </pre> |
| 611 | By the time the client sends the <code>USER</code> and <code>PASS</code> |
| 612 | commands, the server will have the necessary user information to populate |
| 613 | the <code>%U/%u</code> variables. |
| 614 | |
| 615 | <font color=red>Question</font>: When I use <code>DefaultRoot</code> to chroot |
| 616 | my sessions, my exec scripts no longer work; the <code>ExecLog</code> shows |
| 617 | errors like this: |
| 618 | <pre> |
| 619 | preparing to execute '/tmp/ftp-logger.py' with uid 1000 (euid 1000), gid 1000 (egid 1000) |
| 620 | + '/tmp/ftp-logger.py': argv[1] = --user |
| 621 | + '/tmp/ftp-logger.py': argv[2] = ftp |
| 622 | + '/tmp/ftp-logger.py': argv[3] = --file |
| 623 | + '/tmp/ftp-logger.py': argv[4] = /home/ftp/test-ftp-demo.py |
| 624 | + '/tmp/ftp-logger.py': argv[5] = 172.17.0.1 |
| 625 | error: unable to open /dev/null for stdin: No such file or directory |
| 626 | '/tmp/ftp-logger.py' terminated normally, with exit status 2 |
| 627 | STOR ExecOnCommand '/tmp/ftp-logger.py' failed: No such file or directory |
| 628 | </pre> |
| 629 | Is this a bug?<br> |
| 630 | <font color=blue>Answer</font>: No, this is not a bug. It is a consequence |
| 631 | of how the <code>DefaultRoot</code> directive works. |
| 632 | |
| 633 | <p> |
| 634 | The <code>DefaultRoot</code> directive uses the <code>chroot(2)</code> system |
| 635 | call, to effectively "jail" your sessions, by changing the root of the |
| 636 | filesystem for that process. This affects <i>everything</i>. Many scripts |
| 637 | are executed by interpreters; you can see these in the very first line of the |
| 638 | script, <i>e.g.</i>: |
| 639 | <pre> |
| 640 | #!/bin/bash |
| 641 | </pre> |
| 642 | or: |
| 643 | <pre> |
| 644 | #!/usr/bin/env python |
| 645 | </pre> |
| 646 | Within a chrooted environment, though, those interpreter paths are no longer |
| 647 | valid. Hence the "No such file or directory" error. This also explains why |
| 648 | <code>/dev/null</code> cannot be found; it does not exist in the chroot. |
| 649 | |
| 650 | <p> |
| 651 | <hr> |
| 652 | <font size=2><b><i> |
| 653 | © Copyright 2000-2023 TJ Saunders<br> |
| 654 | All Rights Reserved<br> |
| 655 | </i></b></font> |
| 656 | <hr> |
| 657 | |
| 658 | </body> |
| 659 | </html> |