Blame SOURCES/httpd-2.4.34-r1842929+.patch

ad4e62
diff --git a/Makefile.in b/Makefile.in
ad4e62
index 33ff8fb..c22ce4c 100644
ad4e62
--- a/Makefile.in
ad4e62
+++ b/Makefile.in
ad4e62
@@ -213,6 +213,7 @@ install-cgi:
ad4e62
 install-other:
ad4e62
 	@test -d $(DESTDIR)$(logfiledir) || $(MKINSTALLDIRS) $(DESTDIR)$(logfiledir)
ad4e62
 	@test -d $(DESTDIR)$(runtimedir) || $(MKINSTALLDIRS) $(DESTDIR)$(runtimedir)
ad4e62
+	@test -d $(DESTDIR)$(statedir) || $(MKINSTALLDIRS) $(DESTDIR)$(statedir)
ad4e62
 	@for ext in dll x; do \
ad4e62
 		file=apachecore.$$ext; \
ad4e62
 		if test -f $$file; then \
ad4e62
diff --git a/acinclude.m4 b/acinclude.m4
ad4e62
index 0ad0c13..a8c2804 100644
ad4e62
--- a/acinclude.m4
ad4e62
+++ b/acinclude.m4
ad4e62
@@ -45,6 +45,7 @@ AC_DEFUN([APACHE_GEN_CONFIG_VARS],[
ad4e62
   APACHE_SUBST(installbuilddir)
ad4e62
   APACHE_SUBST(runtimedir)
ad4e62
   APACHE_SUBST(proxycachedir)
ad4e62
+  APACHE_SUBST(statedir)
ad4e62
   APACHE_SUBST(other_targets)
ad4e62
   APACHE_SUBST(progname)
ad4e62
   APACHE_SUBST(prefix)
ad4e62
@@ -663,6 +664,7 @@ AC_DEFUN([APACHE_EXPORT_ARGUMENTS],[
ad4e62
   APACHE_SUBST_EXPANDED_ARG(runtimedir)
ad4e62
   APACHE_SUBST_EXPANDED_ARG(logfiledir)
ad4e62
   APACHE_SUBST_EXPANDED_ARG(proxycachedir)
ad4e62
+  APACHE_SUBST_EXPANDED_ARG(statedir)
ad4e62
 ])
ad4e62
 
ad4e62
 dnl 
ad4e62
diff --git a/configure.in b/configure.in
ad4e62
index a208b53..de6a8ad 100644
ad4e62
--- a/configure.in
ad4e62
+++ b/configure.in
ad4e62
@@ -41,7 +41,7 @@ dnl Something seems broken here.
ad4e62
 AC_PREFIX_DEFAULT(/usr/local/apache2)
ad4e62
 
ad4e62
 dnl Get the layout here, so we can pass the required variables to apr
ad4e62
-APR_ENABLE_LAYOUT(Apache, [errordir iconsdir htdocsdir cgidir])
ad4e62
+APR_ENABLE_LAYOUT(Apache, [errordir iconsdir htdocsdir cgidir statedir])
ad4e62
 
ad4e62
 dnl reparse the configure arguments.
ad4e62
 APR_PARSE_ARGUMENTS
ad4e62
diff --git a/include/ap_config_layout.h.in b/include/ap_config_layout.h.in
ad4e62
index 2b4a70c..e076f41 100644
ad4e62
--- a/include/ap_config_layout.h.in
ad4e62
+++ b/include/ap_config_layout.h.in
ad4e62
@@ -60,5 +60,7 @@
ad4e62
 #define DEFAULT_REL_LOGFILEDIR "@rel_logfiledir@"
ad4e62
 #define DEFAULT_EXP_PROXYCACHEDIR "@exp_proxycachedir@"
ad4e62
 #define DEFAULT_REL_PROXYCACHEDIR "@rel_proxycachedir@"
ad4e62
+#define DEFAULT_EXP_STATEDIR "@exp_statedir@"
ad4e62
+#define DEFAULT_REL_STATEDIR "@rel_statedir@"
ad4e62
 
ad4e62
 #endif /* AP_CONFIG_LAYOUT_H */
ad4e62
diff --git a/include/http_config.h b/include/http_config.h
ad4e62
index adc5825..effccc1 100644
ad4e62
--- a/include/http_config.h
ad4e62
+++ b/include/http_config.h
ad4e62
@@ -757,6 +757,14 @@ AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *fname);
ad4e62
  */
ad4e62
 AP_DECLARE(char *) ap_runtime_dir_relative(apr_pool_t *p, const char *fname);
ad4e62
 
ad4e62
+/**
ad4e62
+ * Compute the name of a persistent state file (e.g. a database or
ad4e62
+ * long-lived cache) relative to the appropriate state directory.
ad4e62
+ * Absolute paths are returned as-is.  The state directory is
ad4e62
+ * configured via the DefaultStateDir directive or at build time.
ad4e62
+ */
ad4e62
+AP_DECLARE(char *) ap_state_dir_relative(apr_pool_t *p, const char *fname);
ad4e62
+
ad4e62
 /* Finally, the hook for dynamically loading modules in... */
ad4e62
 
ad4e62
 /**
ad4e62
diff --git a/modules/dav/fs/mod_dav_fs.c b/modules/dav/fs/mod_dav_fs.c
ad4e62
index addfd7e..2389f8f 100644
ad4e62
--- a/modules/dav/fs/mod_dav_fs.c
ad4e62
+++ b/modules/dav/fs/mod_dav_fs.c
ad4e62
@@ -29,6 +29,10 @@ typedef struct {
ad4e62
 
ad4e62
 extern module AP_MODULE_DECLARE_DATA dav_fs_module;
ad4e62
 
ad4e62
+#ifndef DEFAULT_DAV_LOCKDB
ad4e62
+#define DEFAULT_DAV_LOCKDB "davlockdb"
ad4e62
+#endif
ad4e62
+
ad4e62
 const char *dav_get_lockdb_path(const request_rec *r)
ad4e62
 {
ad4e62
     dav_fs_server_conf *conf;
ad4e62
@@ -57,6 +61,24 @@ static void *dav_fs_merge_server_config(apr_pool_t *p,
ad4e62
     return newconf;
ad4e62
 }
ad4e62
 
ad4e62
+static apr_status_t dav_fs_post_config(apr_pool_t *p, apr_pool_t *plog,
ad4e62
+                                       apr_pool_t *ptemp, server_rec *base_server)
ad4e62
+{
ad4e62
+    server_rec *s;
ad4e62
+
ad4e62
+    for (s = base_server; s; s = s->next) {
ad4e62
+        dav_fs_server_conf *conf;
ad4e62
+
ad4e62
+        conf = ap_get_module_config(s->module_config, &dav_fs_module);
ad4e62
+
ad4e62
+        if (!conf->lockdb_path) {
ad4e62
+            conf->lockdb_path = ap_state_dir_relative(p, DEFAULT_DAV_LOCKDB);
ad4e62
+        }
ad4e62
+    }
ad4e62
+
ad4e62
+    return OK;
ad4e62
+}
ad4e62
+
ad4e62
 /*
ad4e62
  * Command handler for the DAVLockDB directive, which is TAKE1
ad4e62
  */
ad4e62
@@ -87,6 +109,8 @@ static const command_rec dav_fs_cmds[] =
ad4e62
 
ad4e62
 static void register_hooks(apr_pool_t *p)
ad4e62
 {
ad4e62
+    ap_hook_post_config(dav_fs_post_config, NULL, NULL, APR_HOOK_MIDDLE);
ad4e62
+
ad4e62
     dav_hook_gather_propsets(dav_fs_gather_propsets, NULL, NULL,
ad4e62
                              APR_HOOK_MIDDLE);
ad4e62
     dav_hook_find_liveprop(dav_fs_find_liveprop, NULL, NULL, APR_HOOK_MIDDLE);
ad4e62
diff --git a/modules/md/mod_md_config.c b/modules/md/mod_md_config.c
ad4e62
index e968da3..b248cca 100644
ad4e62
--- a/modules/md/mod_md_config.c
ad4e62
+++ b/modules/md/mod_md_config.c
ad4e62
@@ -58,10 +58,18 @@
ad4e62
 #define MD_DEFAULT_STORE_DIR "state/md"
ad4e62
 #endif
ad4e62
 
ad4e62
+#ifndef MD_DEFAULT_BASE_DIR
ad4e62
+#define MD_DEFAULT_BASE_DIR "md"
ad4e62
+#endif
ad4e62
+
ad4e62
 /* Default settings for the global conf */
ad4e62
 static md_mod_conf_t defmc = {
ad4e62
     NULL,
ad4e62
-    MD_DEFAULT_STORE_DIR,
ad4e62
+#if 1
ad4e62
+    NULL, /* apply default state-dir-relative */
ad4e62
+#else
ad4e62
+    MD_DEFAULT_BASE_DIR,
ad4e62
+#endif
ad4e62
     NULL,
ad4e62
     NULL,
ad4e62
     80,
ad4e62
@@ -868,6 +876,12 @@ apr_status_t md_config_post_config(server_rec *s, apr_pool_t *p)
ad4e62
     if (mc->hsts_max_age > 0) {
ad4e62
         mc->hsts_header = apr_psprintf(p, "max-age=%d", mc->hsts_max_age);
ad4e62
     }
ad4e62
+
ad4e62
+#if 1
ad4e62
+    if (mc->base_dir == NULL) {
ad4e62
+        mc->base_dir = ap_state_dir_relative(p, MD_DEFAULT_BASE_DIR);
ad4e62
+    }
ad4e62
+#endif
ad4e62
     
ad4e62
     return APR_SUCCESS;
ad4e62
 }
ad4e62
diff --git a/server/core.c b/server/core.c
ad4e62
index ea786a3..0da1fd0 100644
ad4e62
--- a/server/core.c
ad4e62
+++ b/server/core.c
ad4e62
@@ -133,6 +133,8 @@ AP_DECLARE_DATA int ap_main_state = AP_SQ_MS_INITIAL_STARTUP;
ad4e62
 AP_DECLARE_DATA int ap_run_mode = AP_SQ_RM_UNKNOWN;
ad4e62
 AP_DECLARE_DATA int ap_config_generation = 0;
ad4e62
 
ad4e62
+static const char *core_state_dir;
ad4e62
+
ad4e62
 static void *create_core_dir_config(apr_pool_t *a, char *dir)
ad4e62
 {
ad4e62
     core_dir_config *conf;
ad4e62
@@ -1414,12 +1416,15 @@ AP_DECLARE(const char *) ap_resolve_env(apr_pool_t *p, const char * word)
ad4e62
     return res_buf;
ad4e62
 }
ad4e62
 
ad4e62
-static int reset_config_defines(void *dummy)
ad4e62
+/* pconf cleanup - clear global variables set from config here. */
ad4e62
+static apr_status_t reset_config(void *dummy)
ad4e62
 {
ad4e62
     ap_server_config_defines = saved_server_config_defines;
ad4e62
     saved_server_config_defines = NULL;
ad4e62
     server_config_defined_vars = NULL;
ad4e62
-    return OK;
ad4e62
+    core_state_dir = NULL;
ad4e62
+
ad4e62
+    return APR_SUCCESS;
ad4e62
 }
ad4e62
 
ad4e62
 /*
ad4e62
@@ -3115,6 +3120,24 @@ static const char *set_runtime_dir(cmd_parms *cmd, void *dummy, const char *arg)
ad4e62
     return NULL;
ad4e62
 }
ad4e62
 
ad4e62
+static const char *set_state_dir(cmd_parms *cmd, void *dummy, const char *arg)
ad4e62
+{
ad4e62
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
ad4e62
+
ad4e62
+    if (err != NULL) {
ad4e62
+        return err;
ad4e62
+    }
ad4e62
+
ad4e62
+    if ((apr_filepath_merge((char**)&core_state_dir, NULL,
ad4e62
+                            ap_server_root_relative(cmd->temp_pool, arg),
ad4e62
+                            APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS)
ad4e62
+        || !ap_is_directory(cmd->temp_pool, core_state_dir)) {
ad4e62
+        return "DefaultStateDir must be a valid directory, absolute or relative to ServerRoot";
ad4e62
+    }
ad4e62
+
ad4e62
+    return NULL;
ad4e62
+}
ad4e62
+
ad4e62
 static const char *set_timeout(cmd_parms *cmd, void *dummy, const char *arg)
ad4e62
 {
ad4e62
     const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT);
ad4e62
@@ -4416,6 +4439,8 @@ AP_INIT_TAKE1("ServerRoot", set_server_root, NULL, RSRC_CONF | EXEC_ON_READ,
ad4e62
   "Common directory of server-related files (logs, confs, etc.)"),
ad4e62
 AP_INIT_TAKE1("DefaultRuntimeDir", set_runtime_dir, NULL, RSRC_CONF | EXEC_ON_READ,
ad4e62
   "Common directory for run-time files (shared memory, locks, etc.)"),
ad4e62
+AP_INIT_TAKE1("DefaultStateDir", set_state_dir, NULL, RSRC_CONF | EXEC_ON_READ,
ad4e62
+  "Common directory for persistent state (databases, long-lived caches, etc.)"),
ad4e62
 AP_INIT_TAKE1("ErrorLog", set_server_string_slot,
ad4e62
   (void *)APR_OFFSETOF(server_rec, error_fname), RSRC_CONF,
ad4e62
   "The filename of the error log"),
ad4e62
@@ -4943,8 +4968,7 @@ static int core_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptem
ad4e62
 
ad4e62
     if (!saved_server_config_defines)
ad4e62
         init_config_defines(pconf);
ad4e62
-    apr_pool_cleanup_register(pconf, NULL, reset_config_defines,
ad4e62
-                              apr_pool_cleanup_null);
ad4e62
+    apr_pool_cleanup_register(pconf, NULL, reset_config, apr_pool_cleanup_null);
ad4e62
 
ad4e62
     ap_regcomp_set_default_cflags(AP_REG_DOLLAR_ENDONLY);
ad4e62
 
ad4e62
@@ -5213,6 +5237,27 @@ AP_DECLARE(int) ap_state_query(int query)
ad4e62
     }
ad4e62
 }
ad4e62
 
ad4e62
+AP_DECLARE(char *) ap_state_dir_relative(apr_pool_t *p, const char *file)
ad4e62
+{
ad4e62
+    char *newpath = NULL;
ad4e62
+    apr_status_t rv;
ad4e62
+    const char *state_dir;
ad4e62
+
ad4e62
+    state_dir = core_state_dir
ad4e62
+        ? core_state_dir
ad4e62
+        : ap_server_root_relative(p, DEFAULT_REL_STATEDIR);
ad4e62
+
ad4e62
+    rv = apr_filepath_merge(&newpath, state_dir, file, APR_FILEPATH_TRUENAME, p);
ad4e62
+    if (newpath && (rv == APR_SUCCESS || APR_STATUS_IS_EPATHWILD(rv)
ad4e62
+                                      || APR_STATUS_IS_ENOENT(rv)
ad4e62
+                                      || APR_STATUS_IS_ENOTDIR(rv))) {
ad4e62
+        return newpath;
ad4e62
+    }
ad4e62
+    else {
ad4e62
+        return NULL;
ad4e62
+    }
ad4e62
+}
ad4e62
+
ad4e62
 static apr_random_t *rng = NULL;
ad4e62
 #if APR_HAS_THREADS
ad4e62
 static apr_thread_mutex_t *rng_mutex = NULL;