Logging: fix lookups "obsolete syntax" message. Bug 3112
authorJeremy Harris <jgh146exb@wizmail.org>
Tue, 10 Sep 2024 09:29:45 +0000 (10:29 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Tue, 10 Sep 2024 09:29:45 +0000 (10:29 +0100)
doc/doc-txt/ChangeLog
src/src/acl.c
src/src/exim.c
src/src/globals.c
src/src/globals.h
src/src/log.c
src/src/readconf.c
test/stderr/2610
test/stderr/2620

index 22c934b82e7fa88367a03fac8d46fa796027b508..1c8e060c18ead559c1dbe75c12d77285f1e733ed 100644 (file)
@@ -56,6 +56,9 @@ JH/11 Lookups built as dynamic-load modules which support a single lookup
       modules present in the modules directory were loaded; this now applies
       only to those supporting multiple types.
 
+JH/12 Bug 3112: Fix logging of config-file position for "obsolete lookup
+      syntax". Previously, the end of the top-level file was reported.
+
 Exim version 4.98
 -----------------
 
index 18d892ec56913fd60833bb5e4e344de2c4476ea1..9eb4c133ff11e5d9c172f573054a2ed861fe0d43 100644 (file)
@@ -4666,8 +4666,11 @@ while ((acl_current = acl))
   *log_msgptr = *user_msgptr = NULL;
   f.acl_temp_details = FALSE;
 
+  config_filename = acl->srcfile;
+  config_lineno = acl->srcline;
+
   HDEBUG(D_acl) debug_printf_indent("processing \"%s\" (%s %d)\n",
-    verbs[acl->verb], acl->srcfile, acl->srcline);
+    verbs[acl->verb], config_filename, config_lineno);
 
   /* Clear out any search error message from a previous check before testing
   this condition. */
@@ -4877,6 +4880,7 @@ while (i < 9)
 acl_level++;
 ret = acl_check_internal(where, addr, name, user_msgptr, log_msgptr);
 acl_level--;
+config_lineno = 0;
 
 acl_narg = sav_narg;
 for (i = 0; i < 9; i++) acl_arg[i] = sav_arg[i];
@@ -4922,6 +4926,7 @@ if (where == ACL_WHERE_RCPT)
 acl_level++;
 rc = acl_check_internal(where, addr, s, user_msgptr, log_msgptr);
 acl_level--;
+config_lineno = 0;
 return rc;
 }
 
@@ -4945,7 +4950,6 @@ Returns:       OK         access is granted by an ACCEPT verb
                DEFER      can't tell at the moment
                ERROR      disaster
 */
-int acl_where = ACL_WHERE_UNKNOWN;
 
 int
 acl_check(int where, const uschar * recipient, uschar * s,
@@ -4990,6 +4994,7 @@ acl_level = 0;
 rc = acl_check_internal(where, addr, s, user_msgptr, log_msgptr);
 acl_level = 0;
 acl_where = ACL_WHERE_UNKNOWN;
+config_lineno = 0;
 
 /* Cutthrough - if requested,
 and WHERE_RCPT and not yet opened conn as result of recipient-verify,
index 9774281e49911e20d5592312741fa0564163d4c0..3d1b7f1d9f8a2e292c86630875f093619c2ee0d4 100644 (file)
@@ -5494,8 +5494,12 @@ if (expansion_test)
   /* Expand command line items */
 
   if (recipients_arg < argc)
-    while (recipients_arg < argc)
-      expansion_test_line(exim_str_fail_toolong(argv[recipients_arg++], EXIM_EMAILADDR_MAX, "recipient"));
+    {
+    config_filename = US"-be args";
+    for (config_lineno = 1; recipients_arg < argc; config_lineno++)
+      expansion_test_line(exim_str_fail_toolong(argv[recipients_arg++],
+                                             EXIM_EMAILADDR_MAX, "-be arg"));
+    }
 
   /* Read stdin */
 
@@ -5509,7 +5513,9 @@ if (expansion_test)
     void *dlhandle = set_readline(&fn_readline, &fn_addhist);
 #endif
 
-    while (s = get_stdinput(fn_readline, fn_addhist))
+    config_filename = US"-be stdin";
+    for (config_lineno = 1; s = get_stdinput(fn_readline, fn_addhist);
+       config_lineno++)
       expansion_test_line(s);
 
 #ifdef USE_READLINE
index c65ddf41368d778eea6415dd0095b67cb72f870b..e887c27410aefc9b2ec40275ee157c16b01ad3b5 100644 (file)
@@ -472,6 +472,7 @@ tree_node *acl_var_c           = NULL;
 tree_node *acl_var_m           = NULL;
 uschar *acl_verify_message     = NULL;
 string_item *acl_warn_logged   = NULL;
+int acl_where                 = ACL_WHERE_UNKNOWN;
 
 /* Names of SMTP places for use in ACL error messages, and corresponding SMTP
 error codes (only those used) */
@@ -713,7 +714,7 @@ int     clmacro_count          = 0;
 uschar *clmacros[MAX_CLMACROS];
 FILE   *config_file            = NULL;
 const uschar *config_filename  = NULL;
-int     config_lineno          = 0;
+unsigned config_lineno         = 0;
 #ifdef CONFIGURE_GROUP
 gid_t   config_gid             = CONFIGURE_GROUP;
 #else
index 2f2f023e336d7d70f78f1896f9360b99f766d3f3..a172d9abc8aa35f10dc567fd76b2a88570c729ee 100644 (file)
@@ -349,6 +349,7 @@ extern tree_node *acl_var_c;           /* ACL connection variables */
 extern tree_node *acl_var_m;           /* ACL message variables */
 extern uschar *acl_verify_message;     /* User message for verify failure */
 extern string_item *acl_warn_logged;   /* Logged lines */
+extern int acl_where;                 /* Current running ACL */
 extern uschar *acl_wherecodes[];       /* Response codes for ACL fails */
 extern uschar *acl_wherenames[];       /* Names for messages */
 extern address_item *addr_duplicate;   /* Duplicate address list */
@@ -433,7 +434,7 @@ extern int     connection_max_messages;/* Max down one SMTP connection */
 extern FILE   *config_file;            /* Configuration file */
 extern const uschar *config_filename;  /* Configuration file name */
 extern gid_t   config_gid;             /* Additional group owner */
-extern int     config_lineno;          /* Line number */
+extern unsigned config_lineno;         /* Line number */
 extern const uschar *config_main_filelist; /* List of possible config files */
 extern uschar *config_main_filename;   /* File name actually used */
 extern uschar *config_main_directory;  /* Directory where the main config file was found */
index 1b4cea1552d4db78f138a99db890bff88dfab455..a7bc2aab7460c154302071d644f3ed856a54b37a 100644 (file)
@@ -642,8 +642,20 @@ if (flags & (LOG_CONFIG_FOR & ~LOG_CONFIG))
 else
   {
   if (flags & (LOG_CONFIG_IN & ~LOG_CONFIG))
-    string_fmt_append_noextend(g, " in line %d of %s",
+    if (config_lineno > 0)
+      {
+      if (acl_where != ACL_WHERE_UNKNOWN)
+       string_fmt_append_noextend(g, " in ACL verb at");
+      else
+       string_fmt_append_noextend(g, " in");
+
+      string_fmt_append_noextend(g, " line %d of %s",
                                  config_lineno, config_filename);
+      }
+    else if (router_name)
+      string_fmt_append_noextend(g, " in %s router", router_name);
+    else if (transport_name)
+      string_fmt_append_noextend(g, " in %s transport", transport_name);
 
   string_fmt_append_noextend(g, ":\n  ");
   }
index 5aabd019456eae1a9232c1a1981cb23ea94c4938..3f49691e47bccd4625f924737fe143f30d030d91 100644 (file)
@@ -4621,6 +4621,7 @@ while(next_section[0] != 0)
   }
 
 (void)fclose(config_file);
+config_lineno = 0;             /* Ensure we don't log a spurious position */
 }
 
 /* Init the storage for the pre-parsed config lines */
index f253cac9d002b52ffdc5747fbf15e3ca22ce0ae3..f66ff8eae07699580af3adbd9f8d2620a75f2ce0 100644 (file)
@@ -137,7 +137,7 @@ dropping to exim gid; retaining priv uid
  database lookup required for servers=x:127.0.0.1::PORT_N; select name from them where id='ph10';
  MySQL query: "servers=x:127.0.0.1::PORT_N; select name from them where id='ph10';" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 89 of TESTSUITE/test-config:
+  Exim configuration error in line 11 of -be stdin:
   WARNING: obsolete syntax used for lookup
  lookup deferred: MySQL server "x" not found in mysql_servers
  search_open: mysql "NULL"
@@ -150,7 +150,7 @@ LOG: MAIN
  database lookup required for servers=127.0.0.1::PORT_N:x; select name from them where id='ph10';
  MySQL query: "servers=127.0.0.1::PORT_N:x; select name from them where id='ph10';" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 89 of TESTSUITE/test-config:
+  Exim configuration error in line 12 of -be stdin:
   WARNING: obsolete syntax used for lookup
  MYSQL using cached connection for 127.0.0.1:PORT_N/test/root
  creating new cache entry
@@ -165,7 +165,7 @@ LOG: MAIN
  database lookup required for servers=127.0.0.1::PORT_N/test/root/:x; select name from them where id='ph10';
  MySQL query: "servers=127.0.0.1::PORT_N/test/root/:x; select name from them where id='ph10';" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 89 of TESTSUITE/test-config:
+  Exim configuration error in line 13 of -be stdin:
   WARNING: obsolete syntax used for lookup
  MYSQL using cached connection for 127.0.0.1:PORT_N/test/root
  creating new cache entry
@@ -180,7 +180,7 @@ LOG: MAIN
  database lookup required for servers=ip4.ip4.ip4.ip4::1223/test/root/:127.0.0.1::PORT_N; select name from them where id='ph10';
  MySQL query: "servers=ip4.ip4.ip4.ip4::1223/test/root/:127.0.0.1::PORT_N; select name from them where id='ph10';" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 89 of TESTSUITE/test-config:
+  Exim configuration error in line 14 of -be stdin:
   WARNING: obsolete syntax used for lookup
  MYSQL new connection: host=ip4.ip4.ip4.ip4 port=PORT_N socket=NULL database=test user=root
  creating new cache entry
@@ -195,7 +195,7 @@ LOG: MAIN
  database lookup required for servers=localhost(TESTSUITE/mysql/sock)/test/root/pass; select name from them where id='ph10';
  MySQL query: "servers=localhost(TESTSUITE/mysql/sock)/test/root/pass; select name from them where id='ph10';" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 89 of TESTSUITE/test-config:
+  Exim configuration error in line 15 of -be stdin:
   WARNING: obsolete syntax used for lookup
  MYSQL new connection: host=localhost port=0 socket=TESTSUITE/mysql/sock database=test user=root
  creating new cache entry
@@ -505,7 +505,7 @@ close MYSQL connection: 127.0.0.1:PORT_N/test/root
 01:01:01 p1235                                (tainted, quoted:mysql)
 01:01:01 p1235   MySQL query: "servers=127.0.0.1::PORT_N/test/root/pass; select name from them where id = 'c'" opts 'NULL'
 01:01:01 p1235  LOG: MAIN
-01:01:01 p1235    Exim configuration error in line 89 of TESTSUITE/test-config:
+01:01:01 p1235    Exim configuration error in ACL verb at line 31 of TESTSUITE/test-config:
 01:01:01 p1235    WARNING: obsolete syntax used for lookup
 01:01:01 p1235   lookup deferred: MySQL server "127.0.0.1:PORT_N/test" is tainted
 01:01:01 p1235   â”œfailed to expand: FAIL2: ${lookup mysql     {servers=127.0.0.1::PORT_N/test/root/pass; select name from them where id = '${quote_mysql:$local_part}'}}
@@ -543,7 +543,7 @@ close MYSQL connection: 127.0.0.1:PORT_N/test/root
 01:01:01 p1235   required_quoter_id (mysql) quoting -1 (NULL)
 01:01:01 p1235   MySQL query: "servers=127.0.0.1::PORT_N; select name from them where id = 'c'" opts 'NULL'
 01:01:01 p1235  LOG: MAIN
-01:01:01 p1235    Exim configuration error in line 89 of TESTSUITE/test-config:
+01:01:01 p1235    Exim configuration error in ACL verb at line 39 of TESTSUITE/test-config:
 01:01:01 p1235    WARNING: obsolete syntax used for lookup
 01:01:01 p1235   MYSQL using cached connection for 127.0.0.1:PORT_N/test/root
 01:01:01 p1235   MYSQL: no data found
@@ -626,7 +626,7 @@ close MYSQL connection: 127.0.0.1:PORT_N/test/root
 01:01:01 p1235                                (tainted, quoted:mysql)
 01:01:01 p1235   MySQL query: "servers=127.0.0.1::PORT_N/test/root/pass; select * from them where id='c'" opts 'NULL'
 01:01:01 p1235  LOG: MAIN
-01:01:01 p1235    Exim configuration error in line 89 of TESTSUITE/test-config:
+01:01:01 p1235    Exim configuration error in ACL verb at line 45 of TESTSUITE/test-config:
 01:01:01 p1235    WARNING: obsolete syntax used for lookup
 01:01:01 p1235   lookup deferred: MySQL server "127.0.0.1:PORT_N/test" is tainted
 01:01:01 p1235  host in "<& net-mysql;servers=127.0.0.1::PORT_N/test/root/pass; select * from them where id='c'"? list match deferred for net-mysql;servers=127.0.0.1::1223/test/root/pass; select * from them where id='c'
index 3904277905a101c3103ab8e7c7e543755f1c79e4..b770a6267116f02c753103c0ae07401d141a559c 100644 (file)
@@ -135,7 +135,7 @@ dropping to exim gid; retaining priv uid
  database lookup required for servers=x:localhost; select name from them where id='ph10';
  PostgreSQL query: "servers=x:localhost; select name from them where id='ph10';" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 78 of TESTSUITE/test-config:
+  Exim configuration error in line 11 of -be stdin:
   WARNING: obsolete syntax used for lookup
  lookup deferred: PostgreSQL server "x" not found in pgsql_servers
  search_open: pgsql "NULL"
@@ -148,7 +148,7 @@ LOG: MAIN
  database lookup required for servers=localhost::PORT_N:x; select name from them where id='ph10';
  PostgreSQL query: "servers=localhost::PORT_N:x; select name from them where id='ph10';" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 78 of TESTSUITE/test-config:
+  Exim configuration error in line 12 of -be stdin:
   WARNING: obsolete syntax used for lookup
  PGSQL using cached connection for localhost:PORT_N/test/CALLER
  creating new cache entry
@@ -163,7 +163,7 @@ LOG: MAIN
  database lookup required for servers=localhost::PORT_N/test/CALLER/:x; select name from them where id='ph10';
  PostgreSQL query: "servers=localhost::PORT_N/test/CALLER/:x; select name from them where id='ph10';" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 78 of TESTSUITE/test-config:
+  Exim configuration error in line 13 of -be stdin:
   WARNING: obsolete syntax used for lookup
  PGSQL using cached connection for localhost:PORT_N/test/CALLER
  creating new cache entry
@@ -178,7 +178,7 @@ LOG: MAIN
  database lookup required for servers=(TESTSUITE/pgsql/.s.PGSQL.1223)/test/CALLER/:x; select name from them where id='ph10';
  PostgreSQL query: "servers=(TESTSUITE/pgsql/.s.PGSQL.1223)/test/CALLER/:x; select name from them where id='ph10';" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 78 of TESTSUITE/test-config:
+  Exim configuration error in line 14 of -be stdin:
   WARNING: obsolete syntax used for lookup
  PGSQL new connection: socket=TESTSUITE/pgsql/.s.PGSQL.1223 database=test user=CALLER
  creating new cache entry
@@ -349,7 +349,7 @@ check set acl_m0 = ok:   ${lookup pgsql,servers=localhost::PORT_N    {select nam
                               (tainted, quoted:pgsql)
  PostgreSQL query: "servers=localhost::PORT_N/test/CALLER/; select name from them where id = 'c'" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 78 of TESTSUITE/test-config:
+  Exim configuration error in ACL verb at line 32 of TESTSUITE/test-config:
   WARNING: obsolete syntax used for lookup
  lookup deferred: PostgreSQL server "localhost:PORT_N/test" is tainted
 warn: condition test deferred in ACL "check_recipient"
@@ -392,7 +392,7 @@ host in "<& net-pgsql;servers=localhost::PORT_N/test/CALLER/; select * from them
                               (tainted, quoted:pgsql)
  PostgreSQL query: "servers=localhost::PORT_N/test/CALLER/; select * from them where id='c'" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 78 of TESTSUITE/test-config:
+  Exim configuration error in ACL verb at line 44 of TESTSUITE/test-config:
   WARNING: obsolete syntax used for lookup
  lookup deferred: PostgreSQL server "localhost:PORT_N/test" is tainted
 host in "<& net-pgsql;servers=localhost::PORT_N/test/CALLER/; select * from them where id='c'"? list match deferred for net-pgsql;servers=localhost::1223/test/CALLER/; select * from them where id='c'
@@ -545,7 +545,7 @@ check set acl_m0 = ok:   ${lookup pgsql,servers=localhost::PORT_N    {select nam
                               (tainted, quoted:pgsql)
  PostgreSQL query: "servers=localhost::PORT_N/test/CALLER/; select name from them where id = 'c'" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 78 of TESTSUITE/test-config:
+  Exim configuration error in ACL verb at line 32 of TESTSUITE/test-config:
   WARNING: obsolete syntax used for lookup
  lookup deferred: PostgreSQL server "localhost:PORT_N/test" is tainted
 warn: condition test deferred in ACL "check_recipient"
@@ -583,7 +583,7 @@ host in "<& net-pgsql;servers=localhost::PORT_N/test/CALLER/; select * from them
                               (tainted, quoted:pgsql)
  PostgreSQL query: "servers=localhost::PORT_N/test/CALLER/; select * from them where id='c'" opts 'NULL'
 LOG: MAIN
-  Exim configuration error in line 78 of TESTSUITE/test-config:
+  Exim configuration error in ACL verb at line 44 of TESTSUITE/test-config:
   WARNING: obsolete syntax used for lookup
  lookup deferred: PostgreSQL server "localhost:PORT_N/test" is tainted
 host in "<& net-pgsql;servers=localhost::PORT_N/test/CALLER/; select * from them where id='c'"? list match deferred for net-pgsql;servers=localhost::1223/test/CALLER/; select * from them where id='c'