[exim] new expansion operator

Página Inicial
Delete this message
Reply to this message
Autor: Edgar Lovecraft
Data:  
Para: exim-users
Assunto: [exim] new expansion operator
I found that I wanted to be able to do base64 encoding of some strings in
exim, before a local_scan() would ever be invoked, and since all the code
to do base64 encoding is already in the source I did not see the need to
have an external program generate the encoded string, so here is a small
patch to add a 'str2b64' expansion operator, it works much the same as
the 'hex2b64' except that it is not limited to only hex numbers, so the
docs could read something like

------------------------------------------------------------------------
${str2b64:<string>}

This operator converts a string into one that is base64 encoded. This can
be useful for encoding strings that you would later want to decode.

For example using perls MIME::Base64::decode() function.
------------------------------------------------------------------------

I did some basic testing and all seems OK to me, I also noticed that the
hex2b64 exim expansion does not decode properly from perl....

To test it out, just add these lines to any acl:

<CONFIG>
#-------------------------------------
#Generate a base64 encoded string from a string
#-------------------------------------
warn hosts = *
     set acl_c0 = ${str2b64:${sender_helo_name}}
     set acl_c1 = ${str2b64:0123456789abcdef}
     set acl_c3 = ${str2b64:String with several other chars && CAPS 346<<}
     set acl_c4 = ${str2b64:$sender_host_address $tod_log}
</CONFIG>


The output from a exim -bhc <ip_addr> -d-all+expand can be checked with
the perl script that is listed after the patch, takes a little cut and
past, but it was just for a quick and easy confirmation of does it work.

Here is the patch against exim 4.42 (watch for wrapping)
<PATCH>
--- expand.c.orig       2004-08-26 09:09:59.000000000 -0500
+++ expand.c    2004-09-15 05:32:25.163465933 -0500
@@ -124,6 +124,7 @@
   US"sha1",
   US"stat",
   US"strlen",
+  US"str2b64",
   US"substr",
   US"uc" };


@@ -153,6 +154,7 @@
EOP_SHA1,
EOP_STAT,
EOP_STRLEN,
+ EOP_STR2B64,
EOP_SUBSTR,
EOP_UC };

@@ -4134,6 +4136,15 @@
         continue;
         }


+      /* Convert string to base64 encoding */
+
+      case EOP_STR2B64:
+        {
+        uschar *encstr = auth_b64encode(sub, Ustrlen(sub));
+        yield = string_cat(yield, &size, &ptr, encstr, Ustrlen(encstr));
+        continue;
+        }
+
       /* length_n or l_n takes just the first n characters or the whole 
string,
       whichever is the shorter;
</PATCH>


Here is the perl script to decode the base64 strings
<DECODE_PERL>
#!/usr/bin/perl
use strict;
use MIME::Base64();
my $string = 'host.domain.com';
my $str2b64 = 'aG9zdC5kb21haW4uY29t';
print "str2b64\t" . $str2b64 . "\n\t";
print MIME::Base64::encode($string) . "\n";
print "string\t" . $string . "\n\t";
print MIME::Base64::decode($str2b64) . "\n";
</DECODE_PERL>

--

--EAL--

--