From 492773a20f8a1deb1c94e25d40023970dd9608a1 Mon Sep 17 00:00:00 2001
From: Glenn Strauss <gstrauss@gluelogic.com>
Date: Sun, 5 Dec 2021 07:50:17 -0500
Subject: [PATCH] [core] fix trace issued for loading mod_auth (fixes #3121)

Origin:https://github.com/lighttpd/lighttpd1.4/commit/492773a20f8a1deb1c94e25d40023970dd9608a1

fix trace issued for loading mod_auth after dynamic modules

x-ref:
  "Curious message on startup with version 1.4.63"
  https://redmine.lighttpd.net/boards/2/topics/10182
  "mod_auth warning on startup"
  https://redmine.lighttpd.net/issues/3121
---
 src/configfile.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/configfile.c b/src/configfile.c
index 5760bb43..033f2c46 100644
--- a/src/configfile.c
+++ b/src/configfile.c
@@ -369,6 +369,7 @@ static void config_compat_module_load (server *srv) {
     int contains_mod_auth      = 0;
     int prepend_mod_auth       = 0;
     int prepend_mod_vhostdb    = 0;
+    const char *dyn_name = NULL;
 
     for (uint32_t i = 0; i < srv->srvconf.modules->used; ++i) {
         buffer *m = &((data_string *)srv->srvconf.modules->data[i])->value;
@@ -390,8 +391,15 @@ static void config_compat_module_load (server *srv) {
         else if (buffer_eq_slen(m, CONST_STR_LEN("mod_wolfssl")))
             append_mod_openssl = 0;
         else if (0 == strncmp(m->ptr, "mod_auth", sizeof("mod_auth")-1)) {
-            if (buffer_eq_slen(m, CONST_STR_LEN("mod_auth")))
-                contains_mod_auth = 1;
+            if (buffer_eq_slen(m, CONST_STR_LEN("mod_auth"))) {
+                if (!contains_mod_auth) {
+                    contains_mod_auth = 1;
+                    if (dyn_name)
+                        log_error(srv->errh, __FILE__, __LINE__,
+                          "Warning: mod_auth should be listed in server.modules"
+                          " before dynamic backends such as %s", dyn_name);
+                }
+            }
             else if (!contains_mod_auth)
                 prepend_mod_auth = 1;
 
@@ -422,11 +430,8 @@ static void config_compat_module_load (server *srv) {
                                          sizeof("mod_sockproxy")-1)
                  || 0 == strncmp(m->ptr, "mod_wstunnel",
                                          sizeof("mod_wstunnel")-1)) {
-            if (!contains_mod_auth) {
-                log_error(srv->errh, __FILE__, __LINE__,
-                  "Warning: mod_auth should be listed in server.modules before "
-                  "dynamic backends such as %s", m->ptr);
-            }
+            if (NULL == dyn_name)
+                dyn_name = m->ptr;
         }
     }
 
