Skip to content

Commit

Permalink
Issue #515: Support the %b variable for ExecEnviron and friends.
Browse files Browse the repository at this point in the history
  • Loading branch information
Castaglia committed Jun 4, 2017
1 parent e9754b0 commit 9296060
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
20 changes: 17 additions & 3 deletions contrib/mod_exec.c
@@ -1,6 +1,6 @@
/*
* ProFTPD: mod_exec -- a module for executing external scripts
* Copyright (c) 2002-2016 TJ Saunders
* Copyright (c) 2002-2017 TJ Saunders
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,7 +31,7 @@
# include <sys/resource.h>
#endif

#define MOD_EXEC_VERSION "mod_exec/0.9.14"
#define MOD_EXEC_VERSION "mod_exec/0.9.15"

/* Make sure the version of proftpd is as necessary. */
#if PROFTPD_VERSION_NUMBER < 0x0001030402
Expand Down Expand Up @@ -241,7 +241,7 @@ static char **exec_prepare_environ(pool *env_pool, cmd_rec *cmd) {
array_header *env = make_array(env_pool, 0, sizeof(char *));

c = find_config(main_server->conf, CONF_PARAM, "ExecEnviron", FALSE);
while (c) {
while (c != NULL) {
pr_signals_handle();

if (strncmp("-", c->argv[1], 2) == 0) {
Expand Down Expand Up @@ -954,6 +954,20 @@ static const char *exec_subst_var(pool *tmp_pool, const char *varstr,
varstr = sreplace(tmp_pool, varstr, "%A", anon_pass, NULL);
}

ptr = strstr(varstr, "%b");
if (ptr != NULL) {
char buf[1024];

memset(buf, '\0', sizeof(buf));

if (session.xfer.p != NULL) {
snprintf(buf, sizeof(buf)-1, "%" PR_LU,
(pr_off_t) session.xfer.total_bytes);
}

varstr = sreplace(tmp_pool, varstr, "%b", buf, NULL);
}

ptr = strstr(varstr, "%C");
if (ptr != NULL) {
varstr = sreplace(tmp_pool, varstr, "%C",
Expand Down
35 changes: 18 additions & 17 deletions doc/contrib/mod_exec.html
Expand Up @@ -82,8 +82,8 @@ <h3><a name="ExecBeforeCommand">ExecBeforeCommand</a></h3>

<p>
Any number of arbitrary arguments may be configured to pass to the script.
In addition, the &quot;cookies&quot; supported by the <code>ExecEnviron</code>
directive may also be used in the script argument list.
In addition, the variables supported by the <code>ExecEnviron</code> directive
may also be used in the script argument list.

<p>
<b>Important</b>: use of <code>DefaultRoot</code> will cause complications
Expand Down Expand Up @@ -153,11 +153,12 @@ <h3><a name="ExecEnviron">ExecEnviron</a></h3>

<p>
The <i>value</i> parameter may be any arbitrary string which may contain
any of the following &quot;cookies&quot;, which will be substituted with the
any of the following variables, which will be substituted with the
corresponding value before the script is executed:
<ul>
<li><b>%A</b> - Anonymous login password
<li><b>%A</b> - anonymous login password
<li><b>%a</b> - client's IP address
<li><b>%b</b> - bytes transferred
<li><b>%C</b> - current working directory
<li><b>%c</b> - connection class
<li><b>%F</b> - transfered file as seen by client
Expand Down Expand Up @@ -218,8 +219,8 @@ <h3><a name="ExecOnCommand">ExecOnCommand</a></h3>

<p>
Any number of arbitrary arguments may be configured to pass to the script.
In addition, the &quot;cookies&quot; supported by the <code>ExecEnviron</code>
directive may also be used in the script argument list.
In addition, the variables supported by the <code>ExecEnviron</code> directive
may also be used in the script argument list.

<p>
<b>Important</b>: use of <code>DefaultRoot</code> will cause complications
Expand Down Expand Up @@ -258,8 +259,8 @@ <h3><a name="ExecOnConnect">ExecOnConnect</a></h3>

<p>
Any number of arbitrary arguments may be configured to pass to the script.
In addition, the &quot;cookies&quot; supported by the <code>ExecEnviron</code>
directive may also be used in the script argument list.
In addition, the variables supported by the <code>ExecEnviron</code> directive
may also be used in the script argument list.

<p>
Example:
Expand Down Expand Up @@ -295,8 +296,8 @@ <h3><a name="ExecOnError">ExecOnError</a></h3>

<p>
Any number of arbitrary arguments may be configured to pass to the script.
In addition, the &quot;cookies&quot; supported by the <code>ExecEnviron</code>
directive may also be used in the script argument list.
In addition, the variables supported by the <code>ExecEnviron</code> directive
may also be used in the script argument list.

<p>
<b>Important</b>: use of <code>DefaultRoot</code> will cause complications
Expand Down Expand Up @@ -348,8 +349,8 @@ <h3><a name="ExecOnEvent">ExecOnEvent</a></h3>

<p>
Any number of arbitrary arguments may be configured to pass to the script.
In addition, the &quot;cookies&quot; supported by the <code>ExecEnviron</code>
directive may also be used in the script argument list.
In addition, the variables supported by the <code>ExecEnviron</code> directive
may also be used in the script argument list.

<p>
Presently only two specific events are supported: <code>MaxConnectionRate</code>
Expand Down Expand Up @@ -395,8 +396,8 @@ <h3><a name="ExecOnExit">ExecOnExit</a></h3>

<p>
Any number of arbitrary arguments may be configured to pass to the script.
In addition, the &quot;cookies&quot; supported by the <code>ExecEnviron</code>
directive may also be used in the script argument list.
In addition, the variables supported by the <code>ExecEnviron</code> directive
may also be used in the script argument list.

<p>
Example:
Expand Down Expand Up @@ -430,8 +431,8 @@ <h3><a name="ExecOnRestart">ExecOnRestart</a></h3>

<p>
Any number of arbitrary arguments may be configured to pass to the script.
In addition, the &quot;cookies&quot; supported by the <code>ExecEnviron</code>
directive may also be used in the script argument list.
In addition, the variables supported by the <code>ExecEnviron</code> directive
may also be used in the script argument list.

<p>
Example:
Expand Down Expand Up @@ -630,7 +631,7 @@ <h2><a name="Installation">Installation</a></h2>
<p>
<hr>
<font size=2><b><i>
&copy; Copyright 2000-2014 TJ Saunders<br>
&copy; Copyright 2000-2017 TJ Saunders<br>
All Rights Reserved<br>
</i></b></font>
<hr>
Expand Down

0 comments on commit 9296060

Please sign in to comment.