Ensure that recipient is well-defined for expansion-called acl at RCPT-time.
[exim.git] / src / src / expand.c
index 0e969788a5d4f0250c2c4ddc0ad66e15f3cde67f..9fc00cf41a346384e25433634e4a214a4903d62b 100644 (file)
@@ -1853,6 +1853,7 @@ if (Ustrncmp(name, "acl_", 4) == 0)
 
 /*
 Load args from sub array to globals, and call acl_check().
+Sub array will be corrupted on return.
 
 Returns:       OK         access is granted by an ACCEPT verb
                DISCARD    access is granted by a DISCARD verb
@@ -1865,13 +1866,24 @@ static int
 eval_acl(uschar ** sub, int nsub, uschar ** user_msgp)
 {
 int i;
-uschar *dummy_log_msg;
+uschar *tmp;
+int sav_narg = acl_narg;
+int ret;
+extern int acl_where;
 
-for (i = 1; i < nsub && sub[i]; i++)
-  acl_arg[i-1] = sub[i];
-acl_narg = i-1;
+if(--nsub > sizeof(acl_arg)/sizeof(*acl_arg)) nsub = sizeof(acl_arg)/sizeof(*acl_arg);
+for (i = 0; i < nsub && sub[i+1]; i++)
+  {
+  tmp = acl_arg[i];
+  acl_arg[i] = sub[i+1];       /* place callers args in the globals */
+  sub[i+1] = tmp;              /* stash the old args using our caller's storage */
+  }
+acl_narg = i;
 while (i < nsub)
-  acl_arg[i++ - 1] = NULL;
+  {
+  sub[i+1] = acl_arg[i];
+  acl_arg[i++] = NULL;
+  }
 
 DEBUG(D_expand)
   debug_printf("expanding: acl: %s  arg: %s%s\n",
@@ -1879,7 +1891,13 @@ DEBUG(D_expand)
     acl_narg>0 ? sub[1]   : US"<none>",
     acl_narg>1 ? " +more" : "");
 
-return acl_check(ACL_WHERE_EXPANSION, NULL, sub[0], user_msgp, &dummy_log_msg);
+ret = acl_eval(acl_where, sub[0], user_msgp, &tmp);
+
+for (i = 0; i < nsub; i++)
+  acl_arg[i] = sub[i+1];       /* restore old args */
+acl_narg = sav_narg;
+
+return ret;
 }
 
 
@@ -2130,14 +2148,13 @@ switch(cond_type)
   case ECOND_ACL:
     /* ${if acl {{name}{arg1}{arg2}...}  {yes}{no}} */
     {
-    uschar *nameargs;
     uschar *user_msg;
     BOOL cond = FALSE;
     int size = 0;
     int ptr = 0;
 
     while (isspace(*s)) s++;
-    if (*s++ != '{') goto COND_FAILED_CURLY_START;
+    if (*s++ != '{') goto COND_FAILED_CURLY_START;     /*}*/
 
     switch(read_subs(sub, sizeof(sub)/sizeof(*sub), 1,
       &s, yield == NULL, TRUE, US"acl"))
@@ -5663,7 +5680,7 @@ while (*s != 0)
        uschar * list;
        int sep = 0;
        uschar * item;
-       uschar * suffix = "";
+       uschar * suffix = US"";
        BOOL needsep = FALSE;
        uschar buffer[256];
 
@@ -5677,10 +5694,10 @@ while (*s != 0)
          }
        else switch(*arg)       /* specific list-type version */
          {
-         case 'a': t = tree_search(addresslist_anchor,   sub); suffix = "_a"; break;
-         case 'd': t = tree_search(domainlist_anchor,    sub); suffix = "_d"; break;
-         case 'h': t = tree_search(hostlist_anchor,      sub); suffix = "_h"; break;
-         case 'l': t = tree_search(localpartlist_anchor, sub); suffix = "_l"; break;
+         case 'a': t = tree_search(addresslist_anchor,   sub); suffix = US"_a"; break;
+         case 'd': t = tree_search(domainlist_anchor,    sub); suffix = US"_d"; break;
+         case 'h': t = tree_search(hostlist_anchor,      sub); suffix = US"_h"; break;
+         case 'l': t = tree_search(localpartlist_anchor, sub); suffix = US"_l"; break;
          default:
             expand_string_message = string_sprintf("bad suffix on \"list\" operator");
            goto EXPAND_FAILED;
@@ -5724,13 +5741,13 @@ while (*s != 0)
              if (*cp++ == ':') /* colon in a non-colon-sep list item, needs doubling */
                {
                 yield = string_cat(yield, &size, &ptr, US"::", 2);
-               item = cp;
+               item = (uschar *)cp;
                }
              else              /* sep in item; should already be doubled; emit once */
                {
                 yield = string_cat(yield, &size, &ptr, (uschar *)tok, 1);
                if (*cp == sep) cp++;
-               item = cp;
+               item = (uschar *)cp;
                }
              }
            }