[exim-cvs] Lookups: ret=key option

Top Page
Delete this message
Reply to this message
Author: Exim Git Commits Mailing List
Date:  
To: exim-cvs
Subject: [exim-cvs] Lookups: ret=key option
Gitweb: https://git.exim.org/exim.git/commitdiff/0006e6d8e151bb4b34452da30da60184736bb5ae
Commit:     0006e6d8e151bb4b34452da30da60184736bb5ae
Parent:     b16c9f8bdcfd4cce490af9e493489e128f5c8f52
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Thu May 7 16:38:04 2020 +0100
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Thu May 7 17:19:06 2020 +0100


    Lookups: ret=key option
---
 doc/doc-txt/NewStuff           | 21 ++++++++-------
 src/src/search.c               | 17 ++++++++++--
 test/aux-fixed/0625.lsearch    |  1 +
 test/confs/0153                | 17 +++++++-----
 test/confs/0625                |  1 +
 test/log/0625                  |  6 +++++
 test/scripts/0000-Basic/0625   | 18 +++++++++++++
 test/scripts/2500-dsearch/2500 |  1 +
 test/stderr/0625               | 59 ++++++++++++++++++++++++++++++++++++++++++
 test/stdout/0625               | 10 +++++++
 test/stdout/2500               |  1 +
 11 files changed, 135 insertions(+), 17 deletions(-)


diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff
index cf142af..c29525d 100644
--- a/doc/doc-txt/NewStuff
+++ b/doc/doc-txt/NewStuff
@@ -54,20 +54,23 @@ Version 4.94
 15. Options on pgsql and mysql lookups, to specify server separate from the
     lookup string.


-16. Expansion item ${listquote {<char} {<item>}}.
+16. An option on all single-key lookups, to return (on a hit) a de-tainted
+    version of the lookup key rather than the looked-up data.


-17. An option for the ${readsocket {}{}{}} expansion to make the result data
-    cacheable.
-
-18. dkim_verify_min_keysizes, a list of minimum acceptable public-key sizes.
-
-19. bounce_message_file and warn_message_file are now expanded before use.
-
-20. $domain_data and $localpart_data are now set by all list-match successes.
+17. $domain_data and $localpart_data are now set by all list-match successes.
     Previously only list items that performed lookups did so.
     Also, matching list items that are tail-match or RE-match now set the
     numeric variables $0 (etc) in the same way os other RE matches.


+18. Expansion item ${listquote {<char} {<item>}}.
+
+19. An option for the ${readsocket {}{}{}} expansion to make the result data
+    cacheable.
+
+20. dkim_verify_min_keysizes, a list of minimum acceptable public-key sizes.
+
+21. bounce_message_file and warn_message_file are now expanded before use.
+



Version 4.93
diff --git a/src/src/search.c b/src/src/search.c
index db56b61..94a5889 100644
--- a/src/src/search.c
+++ b/src/src/search.c
@@ -189,7 +189,7 @@ if ((t = Ustrchr(t, ',')))
*opts = string_copy(t+1);
}
else
- * opts = NULL;
+ *opts = NULL;

/* Check for the individual search type. Only those that are actually in the
binary are valid. For query-style types, "partial" and default types are
@@ -715,7 +715,7 @@ else if (partial >= 0)
/* The key in its entirety did not match a wild entry; try chopping off
leading components. */

-  if (yield == NULL)
+  if (!yield)
     {
     int dotcount = 0;
     uschar *keystring3 = keystring2 + affixlen;
@@ -839,6 +839,19 @@ if (set_null_wild && expand_setup && *expand_setup >= 0)
   expand_nlength[*expand_setup] = Ustrlen(keystring);
   }


+/* If we have a result, check the options to see if the key was wanted rather
+than the result.  Return a de-tainted version of the key on the grounds that
+it have been validated by the lookup. */
+
+if (yield && opts)
+  {
+  int sep = ',';
+  uschar * ele;
+  while ((ele = string_nextinlist(&opts, &sep, NULL, 0)))
+    if (Ustrcmp(ele, "ret=key") == 0)
+      { yield = string_copy_taint(keystring, FALSE); break; }
+  }
+
 return yield;
 }


diff --git a/test/aux-fixed/0625.lsearch b/test/aux-fixed/0625.lsearch
new file mode 100644
index 0000000..7ec3b5b
--- /dev/null
+++ b/test/aux-fixed/0625.lsearch
@@ -0,0 +1 @@
+trythiskey.ex: has this data
diff --git a/test/confs/0153 b/test/confs/0153
index 35a004a..7b5f023 100644
--- a/test/confs/0153
+++ b/test/confs/0153
@@ -13,17 +13,22 @@ begin routers
 virtual:
   driver = redirect
   domains = *.virt.test.ex
-  address_data = ${if match{$domain}{^(.*)\\.virt\\.test\\.ex\$}{${bless:$1}}}
-  data = ${if exists{DIR/aux-fixed/TESTNUM.alias.$address_data} \
-           {${lookup{$local_part}lsearch{DIR/aux-fixed/TESTNUM.alias.$address_data}}} \
-          fail}
+#  address_data = ${if match{$domain}{^(.*)\\.virt\\.test\\.ex\$}{${bless:$1}}}
+  address_data = $1
+#  data = ${if exists{DIR/aux-fixed/TESTNUM.alias.$address_data} \
+#           {${lookup{$local_part}lsearch{DIR/aux-fixed/TESTNUM.alias.$address_data}}} \
+#          fail}
+  data = ${lookup {TESTNUM.alias.$address_data} dsearch,ret=full {DIR/aux-fixed} \
+           {${lookup{$local_part}lsearch{$value}}} \
+       fail}
   no_more


 list:
   driver = redirect
   domains = list.test.ex
-  file = ${if exists{DIR/aux-fixed/TESTNUM.list.${bless:$local_part}} \
-            {DIR/aux-fixed/TESTNUM.list.${bless:$local_part}}fail}
+#  file = ${if exists{DIR/aux-fixed/TESTNUM.list.${bless:$local_part}} \
+#            {DIR/aux-fixed/TESTNUM.list.${bless:$local_part}}fail}
+  file = ${lookup {TESTNUM.list.$local_part} dsearch,ret=full {DIR/aux-fixed} {$value}fail}
   no_more


 real:
diff --git a/test/confs/0625 b/test/confs/0625
new file mode 120000
index 0000000..f9ae37c
--- /dev/null
+++ b/test/confs/0625
@@ -0,0 +1 @@
+0624
\ No newline at end of file
diff --git a/test/log/0625 b/test/log/0625
new file mode 100644
index 0000000..3cd4ee1
--- /dev/null
+++ b/test/log/0625
@@ -0,0 +1,6 @@
+1999-03-02 09:44:33 domain trythiskey.ex
+1999-03-02 09:44:33 value  has this data
+1999-03-02 09:44:33 $0 'trythiskey.ex'  $1 ''
+1999-03-02 09:44:33 domain trythiskey.ex
+1999-03-02 09:44:33 value  trythiskey.ex
+1999-03-02 09:44:33 $0 'trythiskey.ex'  $1 ''
diff --git a/test/scripts/0000-Basic/0625 b/test/scripts/0000-Basic/0625
new file mode 100644
index 0000000..0958775
--- /dev/null
+++ b/test/scripts/0000-Basic/0625
@@ -0,0 +1,18 @@
+# singlekey lookup ret-key
+#
+# baseline, get the data
+exim -d-all+expand -bs '-DOPT=notthis : lsearch;DIR/aux-fixed/TESTNUM.lsearch : nothiseither'
+HELO test
+MAIL FROM:<testclient>
+RCPT TO:<a@???>
+QUIT
+****
+#
+# get the key
+exim -d-all+expand -bs '-DOPT=notthis : lsearch,ret=key;DIR/aux-fixed/TESTNUM.lsearch : nothiseither'
+HELO test
+MAIL FROM:<testclient>
+RCPT TO:<a@???>
+QUIT
+****
+#
diff --git a/test/scripts/2500-dsearch/2500 b/test/scripts/2500-dsearch/2500
index 5886903..381ef25 100644
--- a/test/scripts/2500-dsearch/2500
+++ b/test/scripts/2500-dsearch/2500
@@ -8,6 +8,7 @@ fail(case): ${lookup{TESTNUM.TST}        dsearch{DIR/aux-fixed}{$value}{FAIL}}
 fail(case): ${lookup{TESTNUM.TST}        dsearch{DIR/AUX-fixed}{$value}{FAIL}}
 fail(path): ${lookup{TESTNUM.tst}        dsearch{.}{$value}{OTHER}}
 ok,full:    ${lookup{TESTNUM.tst} dsearch,ret=full      {DIR/aux-fixed}{$value}{FAIL}}
+ok,key:     ${lookup{TESTNUM.tst} dsearch,ret=key       {DIR/aux-fixed}{$value}{FAIL}}
 ok,file:    ${lookup{TESTNUM.tst} dsearch,filter=file   {DIR/aux-fixed}{$value}{FAIL}}
 fail,file:  ${lookup{TESTNUM.dir} dsearch,filter=file   {DIR/aux-fixed}{$value}{FAIL}}
 ok,dir:     ${lookup{TESTNUM.dir} dsearch,filter=dir    {DIR/aux-fixed}{$value}{FAIL}}
diff --git a/test/stderr/0625 b/test/stderr/0625
new file mode 100644
index 0000000..455a3ee
--- /dev/null
+++ b/test/stderr/0625
@@ -0,0 +1,59 @@
+Exim version x.yz ....
+adding SSLKEYLOGFILE=TESTSUITE/spool/sslkeys
+configuration file is TESTSUITE/test-config
+admin user
+LOG: smtp_connection MAIN
+  SMTP connection from CALLER
+ ╭considering: $smtp_active_hostname ESMTP Exim $version_number $tod_full
+ ├──expanding: $smtp_active_hostname ESMTP Exim $version_number $tod_full
+ ╰─────result: primaryhostname.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000
+ ╭considering: domain $domain
+ ├──expanding: domain $domain
+ ╰─────result: domain trythiskey.ex
+            ╰──(tainted)
+LOG: MAIN
+  domain trythiskey.ex
+created log directory TESTSUITE/spool/log
+ ╭considering: value  $domain_data
+ ├──expanding: value  $domain_data
+ ╰─────result: value  has this data
+LOG: MAIN
+  value  has this data
+ ╭considering: \$0 '$0'  \$1 '$1'
+ ├──expanding: \$0 '$0'  \$1 '$1'
+ ╰─────result: $0 'trythiskey.ex'  $1 ''
+            ╰──(tainted)
+LOG: MAIN
+  $0 'trythiskey.ex'  $1 ''
+LOG: smtp_connection MAIN
+  SMTP connection from CALLER closed by QUIT
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
+Exim version x.yz ....
+adding SSLKEYLOGFILE=TESTSUITE/spool/sslkeys
+configuration file is TESTSUITE/test-config
+admin user
+LOG: smtp_connection MAIN
+  SMTP connection from CALLER
+ ╭considering: $smtp_active_hostname ESMTP Exim $version_number $tod_full
+ ├──expanding: $smtp_active_hostname ESMTP Exim $version_number $tod_full
+ ╰─────result: primaryhostname.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000
+ ╭considering: domain $domain
+ ├──expanding: domain $domain
+ ╰─────result: domain trythiskey.ex
+            ╰──(tainted)
+LOG: MAIN
+  domain trythiskey.ex
+ ╭considering: value  $domain_data
+ ├──expanding: value  $domain_data
+ ╰─────result: value  trythiskey.ex
+LOG: MAIN
+  value  trythiskey.ex
+ ╭considering: \$0 '$0'  \$1 '$1'
+ ├──expanding: \$0 '$0'  \$1 '$1'
+ ╰─────result: $0 'trythiskey.ex'  $1 ''
+            ╰──(tainted)
+LOG: MAIN
+  $0 'trythiskey.ex'  $1 ''
+LOG: smtp_connection MAIN
+  SMTP connection from CALLER closed by QUIT
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
diff --git a/test/stdout/0625 b/test/stdout/0625
new file mode 100644
index 0000000..e09987c
--- /dev/null
+++ b/test/stdout/0625
@@ -0,0 +1,10 @@
+220 primaryhostname.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000
+250 primaryhostname.ex Hello CALLER at test
+250 OK
+250 Accepted
+221 primaryhostname.ex closing connection
+220 primaryhostname.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000
+250 primaryhostname.ex Hello CALLER at test
+250 OK
+250 Accepted
+221 primaryhostname.ex closing connection
diff --git a/test/stdout/2500 b/test/stdout/2500
index ef5b2a1..7e413c0 100644
--- a/test/stdout/2500
+++ b/test/stdout/2500
@@ -5,6 +5,7 @@

 > Failed: failed to open TESTSUITE/AUX-fixed for directory search: No such file or directory
 > Failed: dirname '.' for dsearch is not absolute
 > ok,full:    TESTSUITE/aux-fixed/2500.tst

+> ok,key:     2500.tst

 > ok,file:    2500.tst
 > fail,file:  FAIL
 > ok,dir:     2500.dir