I found that it would be very useful to have the "port" option to smtp
take an expanded string rather than a literal string; I'll explain the
situation for which I needed it after the patch.
Anyhow, the required patch is a small one, to smtp_out.c. It shouldn't
break anything for anyone who doesn't need this, and it should add a
minimal amount of overhead, since expand_string returns very quickly if
there are no "$" characters in the string.
I submit this in the hope that a) it may be useful to someone else, and
b) that it may get accepted into the mainstream tree, in case it *is*
useful to other people.
Adam
**********CUT HERE****************
--- smtp_out.c.orig 2003-10-29 14:57:34.000000000 -0600
+++ smtp_out.c 2003-10-29 17:38:19.000000000 -0600
@@ -89,7 +89,7 @@
produces the number in network byte order.
Arguments:
- pstring string representation of the port
+ istring string representation of the port (may be expanded)
addr the mail address being handled (for setting errors)
port stick the port in here
msg for adding to error message
@@ -99,8 +99,21 @@
*/
BOOL
-smtp_get_port(uschar *pstring, address_item *addr, int *port, uschar
*msg)
+smtp_get_port(uschar *istring, address_item *addr, int *port, uschar
*msg)
{
+ uschar *pstring;
+
+ pstring=expand_string(istring);
+ if (pstring == NULL)
+ {
+ if (expand_string_forcedfail) return TRUE;
+ addr->transport_return = PANIC;
+ addr->message = string_sprintf("failed to expand \"port\" "
+ "option for %s: %s", msg, expand_string_message);
+ return FALSE;
+ }
+
+
if (isdigit(*pstring))
{
uschar *end;
**********CUT HERE****************
So, why did I need an expandable port?
Well, I'm working on a product that uses exim in a Linux/390-under-VM
context. Basically, I'm replacing VM's built-in SMTP handler with a new
virtual machine that runs Exim under the covers.
This needs to be a drop-in replacement, which means that mail has to
appear to the outside world to both go to and come from the VM IP stack.
VM does not provide port-forwarding or NAT capabilities in its stack.
Hence I needed a port forwarder. Doing inbound port 25 to the Linux
Exim-running guest was easy. Outbound, from that guest to an arbitrary
host, was a little more problematic. What I ended up with was a VM
service that listens on a control port and maps requested host/port
combos to a local port (on VM's stack), and then returns the local port
number (don't worry--the forwarder will only take commands from
localhost or from the IP address assigned to the Linux guest, which is
usually connected on a virtual point-to-point link, which only exists in
the S/390 or zSeries box's memory). The idea, then, is that I use Exim
to connect to my VM TCP/IP stack, only for the port number, I use '${run
{blah....} }' to get the dynamically assigned port. Then I deliver that
mail to the port, which is, in turn, forwarded to the actual host's SMTP
port, but which appears to that host to have come directly from VM.
Adam