/* Licensed to the Apache Software Foundation (ASF) under one or more *contributorlicenseagreements.SeetheNOTICEfiledistributedwith *thisworkforadditionalinformationregardingcopyrightownership. *TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0 *(the"License");youmaynotusethisfileexceptincompliancewith *theLicense.YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicenseisdistributedonan"ASIS"BASIS, *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicenseforthespecificlanguagegoverningpermissionsand *limitationsundertheLicense.
*/
if (use_regex) { new->regexp = ap_pregcomp(cmd->pool, fake, AP_REG_EXTENDED); if (new->regexp == NULL) return"Regular expression could not be compiled."; new->real = real;
} else { /* XXX This may be optimized, but we must know that new->real *exists.Ifso,wecandirmergelater,trusingnew->real *andjustcanonicalizingtheremainder.NottillIfinish *cleaningouttheoldap_canonicalstufffirst.
*/ new->real = real;
} new->fake = fake; new->handler = cmd->info;
/* check for overlapping (Script)Alias directives *andthrowawarningiffoundone
*/ if (!use_regex) { for (i = 0; i < conf->aliases->nelts - 1; ++i) {
alias_entry *alias = &entries[i];
if ( (!alias->regexp && alias_matches(fake, alias->fake) > 0)
|| (alias->regexp && !ap_regexec(alias->regexp, fake, 0, NULL, 0))) {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00671) "The %s directive in %s at line %d will probably " "never match because it overlaps an earlier " "%sAlias%s.",
cmd->cmd->name, cmd->directive->filename,
cmd->directive->line_num,
alias->handler ? "Script" : "",
alias->regexp ? "Match" : "");
break; /* one warning per alias should be sufficient */
}
}
}
if (use_regex) {
regex = ap_pregcomp(cmd->pool, fake, AP_REG_EXTENDED); if (regex == NULL) return"Regular expression could not be compiled.";
}
if (ap_is_HTTP_REDIRECT(status)) { if (!url) return"URL to redirect to is missing"; /* PR#35314: we can allow path components here; *theygetcorrectlyresolvedtofullURLs.
*/ if (!use_regex && !ap_is_url(url) && (url[0] != '/')) return"Redirect to non-URL";
} else { if (url) return"Redirect URL not valid for this status";
}
if (cmd->path) new = apr_array_push(dirconf->redirects); else new = apr_array_push(serverconf->redirects);
while (*aliasp) { if (*aliasp == '/') { /* any number of '/' in the alias matches any number in *thesuppliedURI,buttheremustbeatleastone...
*/ if (*urip != '/') return0;
do {
++aliasp;
} while (*aliasp == '/'); do {
++urip;
} while (*urip == '/');
} else { /* Other characters are compared literally */ if (*urip++ != *aliasp++) return0;
}
}
/* Check last alias path component matched all the way */
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);
} /* XXX This is as SLOW as can be, next step, we optimize *andmergetowhateverpartofthefoundpathwasalready *canonicalized.AfterIfinisheliminatingoscanonical. *Betterfailtestforap_server_root_relativeneededhere.
*/
found = ap_server_root_relative(r->pool, found); return found;
apr_uri_parse(r->pool, found, &uri); /* Do not escape the query string or fragment. */
found = apr_uri_unparse(r->pool, &uri, APR_URI_UNP_OMITQUERY);
found = ap_escape_uri(r->pool, found); if (uri.query) {
found = apr_pstrcat(r->pool, found, "?", uri.query, NULL);
} if (uri.fragment) {
found = apr_pstrcat(r->pool, found, "#", uri.fragment, NULL);
}
}
*status = dirconf->redirect_status; return found;
}
return NULL;
}
staticchar *try_alias_list(request_rec *r, apr_array_header_t *aliases, int is_redir, int *status)
{
alias_entry *entries = (alias_entry *) aliases->elts;
ap_regmatch_t regm[AP_MAX_REG_MATCH]; char *found = NULL; int i;
for (i = 0; i < aliases->nelts; ++i) {
alias_entry *alias = &entries[i]; int l;
if (alias->regexp) { if (!ap_regexec(alias->regexp, r->uri, AP_MAX_REG_MATCH, regm, 0)) { if (alias->real) {
found = ap_pregsub(r->pool, alias->real, r->uri,
AP_MAX_REG_MATCH, regm); if (found) { if (is_redir) {
apr_uri_t uri;
apr_uri_parse(r->pool, found, &uri); /* Do not escape the query string or fragment. */
found = apr_uri_unparse(r->pool, &uri,
APR_URI_UNP_OMITQUERY);
found = ap_escape_uri(r->pool, found); if (uri.query) {
found = apr_pstrcat(r->pool, found, "?",
uri.query, NULL);
} if (uri.fragment) {
found = apr_pstrcat(r->pool, found, "#",
uri.fragment, NULL);
}
}
} else {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00672) "Regex substitution in '%s' failed. " "Replacement too long?", alias->real); return PREGSUB_ERROR;
}
} else { /* need something non-null */
found = "";
}
}
} else {
l = alias_matches(r->uri, alias->fake);
if (l > 0) {
ap_set_context_info(r, alias->fake, alias->real); if (is_redir) { char *escurl;
escurl = ap_os_escape_path(r->pool, r->uri + l, 1);
found = apr_pstrcat(r->pool, alias->real, escurl, NULL);
} else
found = apr_pstrcat(r->pool, alias->real, r->uri + l, NULL);
}
}
if (found) { if (alias->handler) { /* Set handler, and leave a note for mod_cgi */
r->handler = alias->handler;
apr_table_setn(r->notes, "alias-forced-type", r->handler);
} /* XXX This is as SLOW as can be, next step, we optimize *andmergetowhateverpartofthefoundpathwasalready *canonicalized.AfterIfinisheliminatingoscanonical. *Betterfailtestforap_server_root_relativeneededhere.
*/ if (!is_redir) {
found = ap_server_root_relative(r->pool, found);
} if (found) {
*status = alias->redir_status;
} return found;
}
/* It may have changed since last time, so try again */
if ((ret = try_redirect(r, &status)) != NULL
|| (ret = try_alias_list(r, dirconf->redirects, 1, &status))
!= NULL) { if (ret == PREGSUB_ERROR) return HTTP_INTERNAL_SERVER_ERROR; if (ap_is_HTTP_REDIRECT(status)) { if (dirconf->allow_relative != ALIAS_FLAG_ON || ret[0] != '/') { if (ret[0] == '/') { char *orig_target = ret;
ret = ap_construct_url(r->pool, ret, r);
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00675) "incomplete redirection target of '%s' for " "URI '%s' modified to '%s'",
orig_target, r->uri, ret);
} if (!ap_is_url(ret)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00676) "cannot redirect '%s' to '%s'; " "target is not a valid absoluteURI or abs_path",
r->uri, ret); return HTTP_INTERNAL_SERVER_ERROR;
}
} /* append requested query only, if the config didn't *supplyitsown.
*/ if (r->args && !ap_strchr(ret, '?')) {
ret = apr_pstrcat(r->pool, ret, "?", r->args, NULL);
}
apr_table_setn(r->headers_out, "Location", ret);
} return status;
}
return DECLINED;
}
staticconst command_rec alias_cmds[] =
{
AP_INIT_TAKE12("Alias", add_alias, NULL, RSRC_CONF | ACCESS_CONF, "a fakename and a realname, or a realname in a Location"),
AP_INIT_TAKE12("ScriptAlias", add_alias, "cgi-script", RSRC_CONF | ACCESS_CONF, "a fakename and a realname, or a realname in a Location"),
AP_INIT_TAKE123("Redirect", add_redirect, (void *) HTTP_MOVED_TEMPORARILY,
OR_FILEINFO, "an optional status, then document to be redirected and " "destination URL"),
AP_INIT_TAKE2("AliasMatch", add_alias_regex, NULL, RSRC_CONF, "a regular expression and a filename"),
AP_INIT_TAKE2("ScriptAliasMatch", add_alias_regex, "cgi-script", RSRC_CONF, "a regular expression and a filename"),
AP_INIT_TAKE23("RedirectMatch", add_redirect_regex,
(void *) HTTP_MOVED_TEMPORARILY, OR_FILEINFO, "an optional status, then a regular expression and " "destination URL"),
AP_INIT_TAKE2("RedirectTemp", add_redirect2,
(void *) HTTP_MOVED_TEMPORARILY, OR_FILEINFO, "a document to be redirected, then the destination URL"),
AP_INIT_TAKE2("RedirectPermanent", add_redirect2,
(void *) HTTP_MOVED_PERMANENTLY, OR_FILEINFO, "a document to be redirected, then the destination URL"),
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."),
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.