From: Ruediger Pluem Date: Mon, 16 Oct 2023 11:42:54 +0000 (+0000) Subject: Merge r1909137, r1911067 from trunk: X-Git-Tag: 2.4.58-rc2-candidate~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f02e37d1a9a4797168cdb3127ed285ad9248949;p=thirdparty%2Fapache%2Fhttpd.git Merge r1909137, r1911067 from trunk: mod_alias: When an alias is declared inside a Location, make sure the balance of the URL is preserved to match the alias declared outside a location. Fixes an error where all requests are mapped to the root of the location. mod_alias: Add AliasPreservePath directive to map the full path after the alias in a location. Submitted by: minfrin Reviewed by: minfrin, rpluem, covener git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1913009 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index d2110493482..3e46c0ae6a8 100644 --- a/CHANGES +++ b/CHANGES @@ -149,6 +149,9 @@ Changes with Apache 2.4.58 *) mod_dav: Add DavBasePath directive to configure the repository root path. PR 35077. [Joe Orton] + *) mod_alias: Add AliasPreservePath directive to map the full + path after the alias in a location. [Graham Leggett] + *) mod_alias: Add RedirectRelative to allow relative redirect targets to be issued as-is. [Eric Covener, Graham Leggett] diff --git a/STATUS b/STATUS index 7882d5944bc..5510333e4b7 100644 --- a/STATUS +++ b/STATUS @@ -152,15 +152,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - *) mod_alias: Add AliasPreservePath directive to map the full path after the - alias in a location. Requires r1861542 / r1861569 above. - Trunk version of patch: - https://svn.apache.org/r1909137 - https://svn.apache.org/r1911067 - Backport version for 2.4.x of patch: - https://svn.apache.org/repos/asf/httpd/httpd/patches/2.4.x/alias-preserve-path3.diff - +1: minfrin, rpluem, covener - *) mod_ssl: Silence info log message "SSL Library Error: error:0A000126: SSL routines::unexpected eof while reading" when using OpenSSL 3 by setting SSL_OP_IGNORE_UNEXPECTED_EOF if diff --git a/docs/manual/mod/mod_alias.xml b/docs/manual/mod/mod_alias.xml index deee28ccb07..6af8099e104 100644 --- a/docs/manual/mod/mod_alias.xml +++ b/docs/manual/mod/mod_alias.xml @@ -194,6 +194,24 @@ Alias "/image" "/ftp/pub/image" </LocationMatch> +

Note that when the AliasPreservePath + directive is on, the full path is mapped to the destination. When + the directive is off, all URLs are mapped to the single target + URL.

+ + +# /files/foo and /files/bar mapped to /ftp/pub/files/foo and /ftp/pub/files/bar +<Location "/files"> + AliasPreservePath on + Alias "/ftp/pub/files" +</Location> +# /errors/foo and /errors/bar mapped to /var/www/errors.html +<Location "/errors"> + AliasPreservePath off + Alias "/var/www/errors.html" +</Location> + + @@ -638,5 +656,30 @@ ScriptAliasMatch "(?i)^/cgi-bin(.*)" "/usr/local/apache/cgi-bin$1" + +AliasPreservePath +Map the full path after the alias in a location. +AliasPreservePath OFF|ON +AliasPreservePath OFF +server configvirtual host +directory + +2.5.1 and later + + +

When using the two parameter version of the + Alias directive, the full path after the alias + is preserved. When using the one parameter version of the + Alias directive inside a + Location directive, the full path is dropped, + and all URLs are mapped to the target expression.

+ +

To make the one parameter version of the + Alias directive preserve paths in the same way + that the two parameter version of the Alias + directive, enable this setting.

+ +
+
diff --git a/modules/mappers/mod_alias.c b/modules/mappers/mod_alias.c index 569d331e7f4..35eca74b283 100644 --- a/modules/mappers/mod_alias.c +++ b/modules/mappers/mod_alias.c @@ -41,6 +41,8 @@ #define ALIAS_FLAG_OFF 0 #define ALIAS_FLAG_ON 1 +#define ALIAS_PRESERVE_PATH_DEFAULT 0 + typedef struct { const char *real; const char *fake; @@ -59,10 +61,12 @@ typedef struct { unsigned int redirect_set:1; apr_array_header_t *redirects; const ap_expr_info_t *alias; + const char *alias_fake; char *handler; const ap_expr_info_t *redirect; int redirect_status; /* 301, 302, 303, 410, etc */ int allow_relative; /* skip ap_construct_url() */ + int alias_preserve_path; /* map full path */ } alias_dir_conf; module AP_MODULE_DECLARE_DATA alias_module; @@ -86,6 +90,7 @@ static void *create_alias_dir_config(apr_pool_t *p, char *d) (alias_dir_conf *) apr_pcalloc(p, sizeof(alias_dir_conf)); a->redirects = apr_array_make(p, 2, sizeof(alias_entry)); a->allow_relative = ALIAS_FLAG_DEFAULT; + a->alias_preserve_path = ALIAS_FLAG_DEFAULT; return a; } @@ -111,6 +116,7 @@ static void *merge_alias_dir_config(apr_pool_t *p, void *basev, void *overridesv a->redirects = apr_array_append(p, overrides->redirects, base->redirects); a->alias = (overrides->alias_set == 0) ? base->alias : overrides->alias; + a->alias_fake = (overrides->alias_set == 0) ? base->alias_fake : overrides->alias_fake; a->handler = (overrides->alias_set == 0) ? base->handler : overrides->handler; a->alias_set = overrides->alias_set || base->alias_set; @@ -120,6 +126,10 @@ static void *merge_alias_dir_config(apr_pool_t *p, void *basev, void *overridesv a->allow_relative = (overrides->allow_relative != ALIAS_FLAG_DEFAULT) ? overrides->allow_relative : base->allow_relative; + a->alias_preserve_path = (overrides->alias_preserve_path != ALIAS_FLAG_DEFAULT) + ? overrides->alias_preserve_path + : base->alias_preserve_path; + return a; } @@ -218,6 +228,7 @@ static const char *add_alias(cmd_parms *cmd, void *dummy, const char *fake, NULL); } + dirconf->alias_fake = cmd->path; dirconf->handler = cmd->info; dirconf->alias_set = 1; @@ -436,6 +447,17 @@ static char *try_alias(request_rec *r) return PREGSUB_ERROR; } + if (dirconf->alias_fake && dirconf->alias_preserve_path == ALIAS_FLAG_ON) { + int l; + + l = alias_matches(r->uri, dirconf->alias_fake); + + if (l > 0) { + ap_set_context_info(r, dirconf->alias_fake, found); + found = apr_pstrcat(r->pool, found, r->uri + l, NULL); + } + } + if (dirconf->handler) { /* Set handler, and leave a note for mod_cgi */ r->handler = dirconf->handler; apr_table_setn(r->notes, "alias-forced-type", r->handler); @@ -715,6 +737,9 @@ static const command_rec alias_cmds[] = AP_INIT_FLAG("RedirectRelative", ap_set_flag_slot, (void*)APR_OFFSETOF(alias_dir_conf, allow_relative), OR_FILEINFO, "Set to ON to allow relative redirect targets to be issued as-is"), + AP_INIT_FLAG("AliasPreservePath", ap_set_flag_slot, + (void*)APR_OFFSETOF(alias_dir_conf, alias_preserve_path), OR_FILEINFO, + "Set to ON to map the full path after the fakename to the realname."), {NULL} };