From: Phil Pennock Date: Sat, 5 Jun 2010 23:50:18 +0000 (+0000) Subject: New expansion operator: reverse_ip X-Git-Tag: exim-4_73_RC0~49 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=83e029d54f2edd11b1706609832693c9540f7783;p=exim.git New expansion operator: reverse_ip --- diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index 98048c6bc..003ae6db8 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -1,4 +1,4 @@ -. $Cambridge: exim/doc/doc-docbook/spec.xfpt,v 1.78 2010/06/05 21:42:53 pdp Exp $ +. $Cambridge: exim/doc/doc-docbook/spec.xfpt,v 1.79 2010/06/05 23:50:18 pdp Exp $ . . ///////////////////////////////////////////////////////////////////////////// . This is the primary source of the Exim Manual. It is an xfpt document that is @@ -9615,6 +9615,21 @@ srandomdev() or srandom(), or a custom implementation even weaker than random(). +.vitem &*${reverse_ip:*&<&'ipaddr'&>&*}*& +.cindex "expansion" "IP address" +This operator reverses an IP address; for IPv4 addresses, the result is in +dotted-quad decimal form, while for IPv6 addreses the result is in +dotted-nibble hexadecimal form. In both cases, this is the "natural" form +for DNS. For example, +.code +${reverse_ip:192.0.2.4} and ${reverse_ip:2001:0db8:c42:9:1:abcd:192.0.2.3} +.endd +returns +.code +4.2.0.192 and 3.0.2.0.0.0.0.c.d.c.b.a.1.0.0.0.9.0.0.0.2.4.c.0.8.b.d.0.1.0.0.2 +.endd + + .vitem &*${rfc2047:*&<&'string'&>&*}*& .cindex "expansion" "RFC 2047" .cindex "RFC 2047" "expansion operator" diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog index 421997b01..0591e4115 100644 --- a/doc/doc-txt/ChangeLog +++ b/doc/doc-txt/ChangeLog @@ -1,4 +1,4 @@ -$Cambridge: exim/doc/doc-txt/ChangeLog,v 1.621 2010/06/05 11:13:29 pdp Exp $ +$Cambridge: exim/doc/doc-txt/ChangeLog,v 1.622 2010/06/05 23:50:18 pdp Exp $ Change log file for Exim from version 4.21 ------------------------------------------- @@ -31,6 +31,8 @@ PP/08 Bugzilla 926: switch ClamAV to use the new zINSTREAM API for content filtering; old API available if built with WITH_OLD_CLAMAV_STREAM=yes NB: ClamAV planning to remove STREAM in "middle of 2010". +PP/09 Implemented reverse_ip expansion operator. + Exim version 4.72 ----------------- diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff index c4d38fd4f..35ed9a399 100644 --- a/doc/doc-txt/NewStuff +++ b/doc/doc-txt/NewStuff @@ -1,4 +1,4 @@ -$Cambridge: exim/doc/doc-txt/NewStuff,v 1.168 2010/06/05 11:13:29 pdp Exp $ +$Cambridge: exim/doc/doc-txt/NewStuff,v 1.169 2010/06/05 23:50:18 pdp Exp $ New Features in Exim -------------------- @@ -43,6 +43,14 @@ Version 4.73 malware-scanning framework. This is intended purely as a debugging aid to ensure that Exim's scanning is working, not to replace other tools. + 5. There is a new expansion operator, "reverse_ip", which will reverse IP + addresses; IPv4 into dotted quad, IPv6 into dotted nibble. Examples: + + ${reverse_ip:192.0.2.4} + -> 4.2.0.192 + ${reverse_ip:2001:0db8:c42:9:1:abcd:192.0.2.3} + -> 3.0.2.0.0.0.0.c.d.c.b.a.1.0.0.0.9.0.0.0.2.4.c.0.8.b.d.0.1.0.0.2 + Version 4.72 ------------ diff --git a/src/src/expand.c b/src/src/expand.c index 6e47125bb..e5daff1a8 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/expand.c,v 1.105 2009/11/16 19:50:36 nm4 Exp $ */ +/* $Cambridge: exim/src/src/expand.c,v 1.106 2010/06/05 23:50:18 pdp Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -156,6 +156,7 @@ static uschar *op_table_underscore[] = { US"from_utf8", US"local_part", US"quote_local_part", + US"reverse_ip", US"time_eval", US"time_interval"}; @@ -163,6 +164,7 @@ enum { EOP_FROM_UTF8, EOP_LOCAL_PART, EOP_QUOTE_LOCAL_PART, + EOP_REVERSE_IP, EOP_TIME_EVAL, EOP_TIME_INTERVAL }; @@ -5790,6 +5792,25 @@ while (*s != 0) continue; } + /* Reverse IP, including IPv6 to dotted-nibble */ + + case EOP_REVERSE_IP: + { + int family, maskptr; + uschar reversed[128]; + + family = string_is_ip_address(sub, &maskptr); + if (family == 0) + { + expand_string_message = string_sprintf( + "reverse_ip() not given an IP address [%s]", sub); + goto EXPAND_FAILED; + } + invert_address(reversed, sub); + yield = string_cat(yield, &size, &ptr, reversed, Ustrlen(reversed)); + continue; + } + /* Unknown operator */ default: diff --git a/src/src/functions.h b/src/src/functions.h index 436038735..00f8bb7ba 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/functions.h,v 1.49 2010/06/05 11:13:30 pdp Exp $ */ +/* $Cambridge: exim/src/src/functions.h,v 1.50 2010/06/05 23:50:18 pdp Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -141,6 +141,7 @@ extern int host_nmtoa(int, int *, int, uschar *, int); extern uschar *host_ntoa(int, const void *, uschar *, int *); extern int host_scan_for_local_hosts(host_item *, host_item **, BOOL *); +extern void invert_address(uschar *, uschar *); extern int ip_bind(int, int, uschar *, int); extern int ip_connect(int, int, uschar *, int, int); extern void ip_keepalive(int, uschar *, BOOL); diff --git a/src/src/verify.c b/src/src/verify.c index cc821a201..371883a37 100644 --- a/src/src/verify.c +++ b/src/src/verify.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/verify.c,v 1.54 2009/11/16 19:50:37 nm4 Exp $ */ +/* $Cambridge: exim/src/src/verify.c,v 1.55 2010/06/05 23:50:18 pdp Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -2513,16 +2513,18 @@ return verify_check_this_host(listptr, sender_host_cache, NULL, /************************************************* -* Invert an IP address for a DNS black list * +* Invert an IP address * *************************************************/ -/* +/* Originally just used for DNS xBL lists, now also used for the +reverse_ip expansion operator. + Arguments: buffer where to put the answer address the address to invert */ -static void +void invert_address(uschar *buffer, uschar *address) { int bin[4];