From 1a8ac120b49132f8983400f1817a6b8bd1f31188 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Sat, 22 May 2021 16:32:00 -0400 Subject: [PATCH] [mod_auth,mod_vhostdb] move helper funcs to mods link http_auth.c into mod_auth link http_vhostdb.c into mod_vhostdb ensure that mod_auth loads before mod_authn_* ensure that mod_vhostdb loads before mod_vhostdb_* --- src/CMakeLists.txt | 6 ++-- src/Makefile.am | 6 ++-- src/SConscript | 6 ++-- src/configfile.c | 68 ++++++++++++++++++++++++++++------------------ src/meson.build | 6 ++-- src/mod_auth.c | 2 ++ src/mod_vhostdb.c | 2 ++ src/server.c | 4 --- 8 files changed, 53 insertions(+), 47 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c7b8e38..9ac774c5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -761,10 +761,8 @@ set(COMMON_SRC connections-glue.c configfile-glue.c http-header-glue.c - http_auth.c http_cgi.c http_date.c - http_vhostdb.c request.c sock_addr.c rand.c @@ -812,7 +810,7 @@ add_and_install_library(mod_access mod_access.c) add_and_install_library(mod_accesslog mod_accesslog.c) add_and_install_library(mod_ajp13 mod_ajp13.c) add_and_install_library(mod_alias mod_alias.c) -add_and_install_library(mod_auth "mod_auth.c") +add_and_install_library(mod_auth "mod_auth.c;http_auth.c") add_and_install_library(mod_authn_file "mod_authn_file.c") if(NOT WIN32) add_and_install_library(mod_cgi mod_cgi.c) @@ -841,7 +839,7 @@ add_and_install_library(mod_status mod_status.c) add_and_install_library(mod_uploadprogress mod_uploadprogress.c) add_and_install_library(mod_userdir mod_userdir.c) add_and_install_library(mod_usertrack mod_usertrack.c) -add_and_install_library(mod_vhostdb mod_vhostdb.c) +add_and_install_library(mod_vhostdb "mod_vhostdb.c;http_vhostdb.c") add_and_install_library(mod_webdav mod_webdav.c) add_and_install_library(mod_wstunnel mod_wstunnel.c) diff --git a/src/Makefile.am b/src/Makefile.am index ae502f4d..ff493171 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -81,10 +81,8 @@ common_src=base64.c buffer.c burl.c log.c \ connections-glue.c \ configfile-glue.c \ http-header-glue.c \ - http_auth.c \ http_cgi.c \ http_date.c \ - http_vhostdb.c \ rand.c \ request.c \ sock_addr.c \ @@ -175,7 +173,7 @@ mod_trigger_b4_dl_la_LIBADD = $(GDBM_LIB) $(MEMCACHED_LIB) $(common_libadd) endif lib_LTLIBRARIES += mod_vhostdb.la -mod_vhostdb_la_SOURCES = mod_vhostdb.c +mod_vhostdb_la_SOURCES = mod_vhostdb.c http_vhostdb.c mod_vhostdb_la_LDFLAGS = $(common_module_ldflags) mod_vhostdb_la_LIBADD = $(common_libadd) @@ -334,7 +332,7 @@ mod_deflate_la_LDFLAGS = $(BROTLI_CFLAGS) $(common_module_ldflags) mod_deflate_la_LIBADD = $(Z_LIB) $(ZSTD_LIB) $(BZ_LIB) $(BROTLI_LIBS) $(common_libadd) lib_LTLIBRARIES += mod_auth.la -mod_auth_la_SOURCES = mod_auth.c +mod_auth_la_SOURCES = mod_auth.c http_auth.c mod_auth_la_LDFLAGS = $(common_module_ldflags) mod_auth_la_LIBADD = $(CRYPTO_LIB) $(common_libadd) diff --git a/src/SConscript b/src/SConscript index ce0f13b4..a004d1aa 100644 --- a/src/SConscript +++ b/src/SConscript @@ -67,10 +67,8 @@ common_src = Split("base64.c buffer.c burl.c log.c \ connections-glue.c \ configfile-glue.c \ http-header-glue.c \ - http_auth.c \ http_cgi.c \ http_date.c \ - http_vhostdb.c \ request.c \ sock_addr.c \ rand.c \ @@ -103,7 +101,7 @@ modules = { 'mod_accesslog' : { 'src' : [ 'mod_accesslog.c' ] }, 'mod_ajp13' : { 'src' : [ 'mod_ajp13.c' ] }, 'mod_alias' : { 'src' : [ 'mod_alias.c' ] }, - 'mod_auth' : { 'src' : [ 'mod_auth.c' ], 'lib' : [ env['LIBCRYPTO'] ] }, + 'mod_auth' : { 'src' : [ 'mod_auth.c', 'http_auth.c' ], 'lib' : [ env['LIBCRYPTO'] ] }, 'mod_authn_file' : { 'src' : [ 'mod_authn_file.c' ], 'lib' : [ env['LIBCRYPT'], env['LIBCRYPTO'] ] }, 'mod_cgi' : { 'src' : [ 'mod_cgi.c' ] }, 'mod_deflate' : { 'src' : [ 'mod_deflate.c' ], 'lib' : [ env['LIBZ'], env['LIBZSTD'], env['LIBBZ2'], env['LIBBROTLI'], 'm' ] }, @@ -130,7 +128,7 @@ modules = { 'mod_uploadprogress' : { 'src' : [ 'mod_uploadprogress.c' ] }, 'mod_userdir' : { 'src' : [ 'mod_userdir.c' ] }, 'mod_usertrack' : { 'src' : [ 'mod_usertrack.c' ], 'lib' : [ env['LIBCRYPTO'] ] }, - 'mod_vhostdb' : { 'src' : [ 'mod_vhostdb.c' ] }, + 'mod_vhostdb' : { 'src' : [ 'mod_vhostdb.c', 'http_vhostdb.c' ] }, 'mod_webdav' : { 'src' : [ 'mod_webdav.c' ], 'lib' : [ env['LIBXML2'], env['LIBSQLITE3'], env['LIBUUID'] ] }, 'mod_wstunnel' : { 'src' : [ 'mod_wstunnel.c' ], 'lib' : [ env['LIBCRYPTO'] ] }, } diff --git a/src/configfile.c b/src/configfile.c index bf2e3a22..56555fb3 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -324,6 +324,19 @@ static const char * config_has_opt_and_value (const server * const srv, const ch return NULL; } +static void config_compat_module_prepend (server *srv, const char *module, uint32_t len) { + array *modules = array_init(srv->srvconf.modules->used+4); + array_insert_value(modules, module, len); + + for (uint32_t i = 0; i < srv->srvconf.modules->used; ++i) { + data_string *ds = (data_string *)srv->srvconf.modules->data[i]; + array_insert_value(modules, CONST_BUF_LEN(&ds->value)); + } + + array_free(srv->srvconf.modules); + srv->srvconf.modules = modules; +} + static void config_warn_authn_module (server *srv, const char *module, uint32_t len, const char *v) { buffer * const tb = srv->tmp_buf; buffer_copy_string_len(tb, CONST_STR_LEN("mod_authn_")); @@ -346,6 +359,8 @@ static void config_compat_module_load (server *srv) { int append_mod_authn_mysql = 1; int append_mod_openssl = 1; int contains_mod_auth = 0; + int prepend_mod_auth = 0; + int prepend_mod_vhostdb = 0; for (uint32_t i = 0; i < srv->srvconf.modules->used; ++i) { buffer *m = &((data_string *)srv->srvconf.modules->data[i])->value; @@ -366,24 +381,24 @@ static void config_compat_module_load (server *srv) { append_mod_openssl = 0; else if (buffer_eq_slen(m, CONST_STR_LEN("mod_wolfssl"))) append_mod_openssl = 0; - else if (buffer_eq_slen(m, CONST_STR_LEN("mod_authn_file"))) - append_mod_authn_file = 0; - else if (buffer_eq_slen(m, CONST_STR_LEN("mod_authn_ldap"))) - append_mod_authn_ldap = 0; - else if (buffer_eq_slen(m, CONST_STR_LEN("mod_authn_mysql"))) - append_mod_authn_mysql = 0; - else if (buffer_eq_slen(m, CONST_STR_LEN("mod_auth"))) - contains_mod_auth = 1; + 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; + else if (!contains_mod_auth) + prepend_mod_auth = 1; - if (0 == prepend_mod_indexfile && - 0 == append_mod_dirlisting && - 0 == append_mod_staticfile && - 0 == append_mod_openssl && - 0 == append_mod_authn_file && - 0 == append_mod_authn_ldap && - 0 == append_mod_authn_mysql && - 1 == contains_mod_auth) { - break; + if (buffer_eq_slen(m, CONST_STR_LEN("mod_authn_file"))) + append_mod_authn_file = 0; + else if (buffer_eq_slen(m, CONST_STR_LEN("mod_authn_ldap"))) + append_mod_authn_ldap = 0; + else if (buffer_eq_slen(m, CONST_STR_LEN("mod_authn_mysql"))) + append_mod_authn_mysql = 0; + } + else if (0 == strncmp(m->ptr, "mod_vhostdb", sizeof("mod_vhostdb")-1)) { + if (buffer_eq_slen(m, CONST_STR_LEN("mod_vhostdb"))) + prepend_mod_vhostdb |= 2; + else if (!(prepend_mod_vhostdb & 2)) + prepend_mod_vhostdb |= 1; } } @@ -391,16 +406,7 @@ static void config_compat_module_load (server *srv) { if (prepend_mod_indexfile) { /* mod_indexfile has to be loaded before mod_fastcgi and friends */ - array *modules = array_init(srv->srvconf.modules->used+4); - array_insert_value(modules, CONST_STR_LEN("mod_indexfile")); - - for (uint32_t i = 0; i < srv->srvconf.modules->used; ++i) { - data_string *ds = (data_string *)srv->srvconf.modules->data[i]; - array_insert_value(modules, CONST_BUF_LEN(&ds->value)); - } - - array_free(srv->srvconf.modules); - srv->srvconf.modules = modules; + config_compat_module_prepend(srv, CONST_STR_LEN("mod_indexfile")); } /* append default modules */ @@ -448,6 +454,14 @@ static void config_compat_module_load (server *srv) { #endif } } + + if (prepend_mod_auth) { + config_compat_module_prepend(srv, CONST_STR_LEN("mod_auth")); + } + + if (prepend_mod_vhostdb & 1) { + config_compat_module_prepend(srv, CONST_STR_LEN("mod_vhostdb")); + } } static void config_deprecate_module_compress (server *srv) { diff --git a/src/meson.build b/src/meson.build index 9c1210fb..04013f42 100644 --- a/src/meson.build +++ b/src/meson.build @@ -727,13 +727,11 @@ common_src = [ 'fdevent_solaris_port.c', 'fdevent.c', 'gw_backend.c', - 'http_auth.c', 'http_cgi.c', 'http_chunk.c', 'http_date.c', 'http_header.c', 'http_kv.c', - 'http_vhostdb.c', 'http-header-glue.c', 'keyvalue.c', 'log.c', @@ -986,7 +984,7 @@ modules = [ [ 'mod_accesslog', [ 'mod_accesslog.c' ] ], [ 'mod_ajp13', [ 'mod_ajp13.c' ] ], [ 'mod_alias', [ 'mod_alias.c' ] ], - [ 'mod_auth', [ 'mod_auth.c' ], [ libcrypto ] ], + [ 'mod_auth', [ 'mod_auth.c', 'http_auth.c' ], [ libcrypto ] ], [ 'mod_authn_file', [ 'mod_authn_file.c' ], [ libcrypt, libcrypto ] ], [ 'mod_deflate', [ 'mod_deflate.c' ], libbz2 + libz + libzstd + libbrotli ], [ 'mod_dirlisting', [ 'mod_dirlisting.c' ] ], @@ -1012,7 +1010,7 @@ modules = [ [ 'mod_uploadprogress', [ 'mod_uploadprogress.c' ] ], [ 'mod_userdir', [ 'mod_userdir.c' ] ], [ 'mod_usertrack', [ 'mod_usertrack.c' ], libcrypto ], - [ 'mod_vhostdb', [ 'mod_vhostdb.c' ] ], + [ 'mod_vhostdb', [ 'mod_vhostdb.c', 'http_vhostdb.c' ] ], [ 'mod_webdav', [ 'mod_webdav.c' ], libsqlite3 + libuuid + libxml2 + libelftc ], [ 'mod_wstunnel', [ 'mod_wstunnel.c' ], libcrypto ], ] diff --git a/src/mod_auth.c b/src/mod_auth.c index 693fab86..60d7b49d 100644 --- a/src/mod_auth.c +++ b/src/mod_auth.c @@ -242,6 +242,8 @@ FREE_FUNC(mod_auth_free) { } } } + + http_auth_dumbdata_reset(); } /* data type for mod_auth structured data diff --git a/src/mod_vhostdb.c b/src/mod_vhostdb.c index 546409df..a28f17e8 100644 --- a/src/mod_vhostdb.c +++ b/src/mod_vhostdb.c @@ -150,6 +150,8 @@ FREE_FUNC(mod_vhostdb_free) { } } } + + http_vhostdb_dumbdata_reset(); } static void mod_vhostdb_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { diff --git a/src/server.c b/src/server.c index 45ff6cb0..f065bff7 100644 --- a/src/server.c +++ b/src/server.c @@ -7,8 +7,6 @@ #include "rand.h" #include "chunk.h" #include "h2.h" /* h2_send_1xx() */ -#include "http_auth.h" /* http_auth_dumbdata_reset() */ -#include "http_vhostdb.h" /* http_vhostdb_dumbdata_reset() */ #include "fdevent.h" #include "connections.h" #include "sock_addr.h" @@ -1077,8 +1075,6 @@ static int server_main_setup (server * const srv, int argc, char **argv) { handle_sig_hup = 0; idle_limit = 0; chunkqueue_set_tempdirs_default_reset(); - http_auth_dumbdata_reset(); - http_vhostdb_dumbdata_reset(); /*graceful_restart = 0;*//*(reset below to avoid further daemonizing)*/ /*(intentionally preserved)*/ /*memset(graceful_sockets, 0, sizeof(graceful_sockets));*/