Fix over-long line in DSN
[exim.git] / src / src / search.c
index d3511df31b58999dd2fc84ddfe9aab3ad1373251..94a58897f787da0115b9d6ef225f27de6b1083f5 100644 (file)
@@ -3,6 +3,7 @@
 *************************************************/
 
 /* Copyright (c) University of Cambridge 1995 - 2015 */
+/* Copyright (c) The Exim Maintainers 2020 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 /* A set of functions to search databases in various formats. An open
@@ -188,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
@@ -714,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;
@@ -838,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;
 }