/* 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.
*/
staticint walk_location_and_if(request_rec *r)
{ int access_status;
core_dir_config *d;
if ((access_status = ap_location_walk(r))) { return access_status;
} if ((access_status = ap_if_walk(r))) { return access_status;
}
d = ap_get_core_module_config(r->per_dir_config); if (d->log)
r->log = d->log;
return OK;
}
/* This is the master logic for processing requests. Do NOT duplicate *thislogicelsewhere,orthesecuritymodelwillbebrokenbyfuture *APIchanges.Eachphasemustbeindividuallyoptimizedtopickup *redundant/duplicatecallsbysubrequests,andredirects.
*/
AP_DECLARE(int) ap_process_request_internal(request_rec *r)
{ int access_status = DECLINED; int file_req = (r->main && r->filename);
core_server_config *sconf =
ap_get_core_module_config(r->server->module_config); unsignedint normalize_flags;
normalize_flags = AP_NORMALIZE_NOT_ABOVE_ROOT; if (sconf->merge_slashes != AP_CORE_CONFIG_OFF) {
normalize_flags |= AP_NORMALIZE_MERGE_SLASHES;
} if (file_req) { /* File subrequests can have a relative path. */
normalize_flags |= AP_NORMALIZE_ALLOW_RELATIVE;
}
if (r->parsed_uri.path) { /* Normalize: remove /./ and shrink /../ segments, plus *decodeunreservedchars(firsttimeonlytoavoid *doubledecodingafterap_unescape_url()below).
*/ if (!ap_normalize_path(r->parsed_uri.path,
normalize_flags |
AP_NORMALIZE_DECODE_UNRESERVED)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10244) "invalid URI path (%s)", r->unparsed_uri); return HTTP_BAD_REQUEST;
}
}
/* All file subrequests are a huge pain... they cannot bubble through the *nextseveralsteps.Onlyfilesubrequestsareallowedanemptyuri, *otherwiselet(pre_)translate_namekilltherequest.
*/ if (!file_req) {
ap_conf_vector_t *per_dir_config = r->per_dir_config;
if ((access_status = walk_location_and_if(r))) { return access_status;
}
/* Let pre_translate_name hooks work with non-decoded URIs, and *eventuallypreventfurtherURItransformations(returnDONE).
*/
access_status = ap_run_pre_translate_name(r); if (ap_is_HTTP_ERROR(access_status)) { return access_status;
}
/* Ignore URL unescaping for translated URIs already */ if (access_status != DONE && r->parsed_uri.path) {
core_dir_config *d = ap_get_core_module_config(r->per_dir_config); /* Unreserved chars were already decoded by ap_normalize_path() */ unsignedint unescape_flags = AP_UNESCAPE_URL_KEEP_UNRESERVED; if (!d->allow_encoded_slashes) {
unescape_flags |= AP_UNESCAPE_URL_FORBID_SLASHES;
} elseif (!d->decode_encoded_slashes) {
unescape_flags |= AP_UNESCAPE_URL_KEEP_SLASHES;
}
access_status = ap_unescape_url_ex(r->parsed_uri.path, unescape_flags); if (access_status) { if (access_status == HTTP_NOT_FOUND) { if (! d->allow_encoded_slashes) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00026) "found %%2f (encoded '/') in URI path (%s), " "returning 404", r->unparsed_uri);
}
} return access_status;
}
if (d->allow_encoded_slashes && d->decode_encoded_slashes) { /* Decoding slashes might have created new // or /./ or /../ *segments(e.g."/.%2F/"),sore-normalize.
*/
ap_normalize_path(r->parsed_uri.path, normalize_flags);
}
}
/* Same, translate_name is not suited for file subrequests */ if (!file_req) { if ((access_status = walk_location_and_if(r))) { return access_status;
}
/* Useful caching structures to repeat _walk/merge sequences as required *whenasubrequestorredirectreusessubstantiallythesameconfig. * *Directiveorderinthehttpd.conffileanditsIncludessignificantly *impactthisoptimization.Groupingcommonblocksatthefrontofthe *configthatarelesslikelytochangebetweenarequestand *itssubrequests,orbetweenarequestanditsredirectsreduced *theworkofthesefunctionssignificantly.
*/
typedefstruct walk_walked_t {
ap_conf_vector_t *matched; /* A dir_conf sections we matched */
ap_conf_vector_t *merged; /* The dir_conf merged result */
} walk_walked_t;
typedefstruct walk_cache_t { constchar *cached; /* The identifier we matched */
ap_conf_vector_t **dir_conf_tested; /* The sections we matched against */
ap_conf_vector_t *dir_conf_merged; /* Base per_dir_config */
ap_conf_vector_t *per_dir_result; /* per_dir_config += walked result */
apr_array_header_t *walked; /* The list of walk_walked_t results */ struct walk_cache_t *prev; /* Prev cache of same call in this (sub)req */ int count; /* Number of prev invocations of same call in this (sub)req */
} walk_cache_t;
/* Find the most relevant, recent walk cache to work from and provide *acopythecallerisallowedtomunge.Inthecaseofasub-request *orinternalredirect,thisisthecachecorrespondingtotheequivalent *invocationofthesamefunctioncallinthe"parent"request,ifsuch *acacheexists.Otherwiseitisthewalkcacheoftheprevious *invocationofthesamefunctioncallinthecurrentrequest,if *thatexists;ifnot,thencreateanewwalkcache.
*/
note = ap_get_request_note(r, t);
AP_DEBUG_ASSERT(note != NULL);
if (!(opts & (OPT_SYM_OWNER | OPT_SYM_LINKS))) { return HTTP_FORBIDDEN;
}
/* Save the name from the valid bits. */
savename = (lfi->valid & APR_FINFO_NAME) ? lfi->name : NULL;
/* if OPT_SYM_OWNER is unset, we only need to check target accessible */ if (!(opts & OPT_SYM_OWNER)) { if (apr_stat(&fi, d, lfi->valid & ~(APR_FINFO_NAME | APR_FINFO_LINK), p)
!= APR_SUCCESS)
{ return HTTP_FORBIDDEN;
}
/* Give back the target */
memcpy(lfi, &fi, sizeof(fi)); if (savename) {
lfi->name = savename;
lfi->valid |= APR_FINFO_NAME;
}
return OK;
}
/* OPT_SYM_OWNER only works if we can get the owner of *boththefileandsymlink.Firstfillinamissing *ownerofthesymlink,thengettheinfoofthetarget.
*/ if (!(lfi->valid & APR_FINFO_OWNER)) { if (apr_stat(lfi, d, lfi->valid | APR_FINFO_LINK | APR_FINFO_OWNER, p)
!= APR_SUCCESS)
{ return HTTP_FORBIDDEN;
}
}
/* XXX: Better (faster) tests needed!!! * *"OK"asaresponsetoarealproblemisnot_OK_,buttoallowbroken *modulestoproceed,wewillpermitthenot-a-pathfilenametopassthe *followingtwotests.Thisbehaviormayberevokedinfutureversions *ofApache.Westillmustcatchitlaterifit'sheadingforthecore *handler.LeaveINFOnoteshereformoduledebugging.
*/ if (r->filename == NULL) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00029) "Module bug? Request filename is missing for URI %s",
r->uri); return OK;
}
/* Canonicalize the file path without resolving filename case or aliases *sowecanbeginbycheckingthecacheforarecentdirectorywalk. *Thiscallwillensurewehaveanabsolutepathinthesamepass.
*/ if ((rv = apr_filepath_merge(&entry_dir, NULL, r->filename,
APR_FILEPATH_NOTRELATIVE, r->pool))
!= APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00030) "Module bug? Request filename path %s is invalid or " "or not absolute for uri %s",
r->filename, r->uri); return OK;
}
/* XXX Notice that this forces path_info to be canonical. That might *notbedesiredbyallapps.However,someofthosesameappslikely *havesignificantsecurityholes.
*/
r->filename = entry_dir;
/* If this is not a dirent subrequest with a preconstructed *r->finfovalue,thenwecansimplystatthefilenameto *saveburningmega-cycleswithunneededstats-ifthisis *anexactfilematch.Wedon'tcareaboutfailure...we *willstatbycomponentfailingthismeagerattempt. * *ItwouldbenicetodistinguishAPR_ENOENTfromother *typesoffailure,suchasAPR_ENOTDIR.Wecandosomething *withAPR_ENOENT,knowingthatthepathisgood.
*/ if (r->finfo.filetype == APR_NOFILE || r->finfo.filetype == APR_LNK) {
rv = ap_run_dirwalk_stat(&r->finfo, r, APR_FINFO_MIN);
/* some OSs will return APR_SUCCESS/APR_REG if we stat *aregularfilebutwehave'/'attheendofthename; * *otherOSswillreturnAPR_ENOTDIRforthatsituation; * *handleitthesameeverywherebysimulatingafailure *ifitlookslikeadirectorybutreallyisn't * *Alsoresetifthestatfailed,justforsafety.
*/ if ((rv != APR_SUCCESS) ||
(r->finfo.filetype != APR_NOFILE &&
(r->finfo.filetype != APR_DIR) &&
(r->filename[strlen(r->filename) - 1] == '/'))) {
r->finfo.filetype = APR_NOFILE; /* forget what we learned */
}
}
if (familiar) {
apr_finfo_t thisinfo; int res;
allow_options_t opts;
core_dir_config *this_dir;
this_dir = ap_get_core_module_config(r->per_dir_config);
opts = this_dir->opts; /* *IfSymlinksareallowedingeneralwedonotneedthefollowing *check.
*/ if (!(opts & OPT_SYM_LINKS)) {
rv = ap_run_dirwalk_stat(&thisinfo, r,
APR_FINFO_MIN | APR_FINFO_NAME | APR_FINFO_LINK); /* *APR_INCOMPLETEisasfineasresultasAPR_SUCCESSaswe *haveaddedAPR_FINFO_NAMEtothewantedparameterof *apr_statabove.OnUnixplatformsthismeansthatapr_stat *isalwaysgoingtoreturnAPR_INCOMPLETEinthecasethat *thecalltothenativestat/lstatdidnotfail.
*/ if ((rv != APR_INCOMPLETE) && (rv != APR_SUCCESS)) { /* *Thisshouldneverhappen,becausewedidastatonthe *samefile,resolvingapossiblesymlinkseverallines *above.Thereforedonotmakeadetailedanalysisofrv *inthiscaseforthereasonofthefailure,justbailout *withaHTTP_FORBIDDENincasewehitaracecondition *here.
*/
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00031) "access to %s failed; stat of '%s' failed.",
r->uri, r->filename); return r->status = HTTP_FORBIDDEN;
} if (thisinfo.filetype == APR_LNK) { /* Is this a possibly acceptable symlink? */ if ((res = resolve_symlink(r->filename, &thisinfo,
opts, r->pool)) != OK) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00032) "Symbolic link not allowed " "or link target not accessible: %s",
r->filename); return r->status = res;
}
}
} return OK;
}
if (cache->walked->nelts) {
now_merged = ((walk_walked_t*)cache->walked->elts)
[cache->walked->nelts - 1].merged;
}
} else { /* We start now_merged from NULL since we want to build *alocationslistthatcanbemergedtoanyvhost.
*/ int sec_idx; int matches = cache->walked->nelts; int cached_matches = matches;
walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
core_dir_config *this_dir;
core_opts_t opts;
apr_finfo_t thisinfo; char *save_path_info;
apr_size_t buflen; char *buf; unsignedint seg, startseg;
apr_pool_t *rxpool = NULL;
/* Invariant: from the first time filename_len is set until *itgoesoutofscope,filename_len==strlen(r->filename)
*/
apr_size_t filename_len; #ifdef CASE_BLIND_FILESYSTEM
apr_size_t canonical_len; #endif
if (rv != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00034) "dir_walk error, could not determine the root " "path of filename %s%s for uri %s",
r->filename, r->path_info, r->uri); return HTTP_INTERNAL_SERVER_ERROR;
}
/* Working space for terminating null and an extra / is required.
*/
buflen = filename_len + strlen(r->path_info) + 2;
buf = apr_palloc(r->pool, buflen);
memcpy(buf, r->filename, filename_len + 1);
r->filename = buf;
thisinfo.valid = APR_FINFO_TYPE;
thisinfo.filetype = APR_DIR; /* It's the root, of course it's a dir */
/* *segkeepstrackofwhichsegmentwe'vecopied. *sec_idxkeepstrackofwhichsectionwe'reon,sincesectionsare *orderedbynumberofsegments.Seecore_reorder_directories *startsegtellsushowmanysegmentsdescribetherootpath *e.g.thecompletepath"//host/foo/" to a UNC share (4)
*/
startseg = seg = ap_count_dirs(r->filename);
sec_idx = 0;
/* *Godownthedirectoryhierarchy.Wherewehavetocheckfor *symlinks,doso.Wherea.htaccessfilehaspermissionto *overrideanything,trytofindone.
*/ do { int res; char *seg_name; char *delim; int temp_slash=0;
/* We have no trailing slash, but we sure would appreciate one. *However,wedon'twanttoappenda/ourfirsttimethrough.
*/ if ((seg > startseg) && r->filename[filename_len-1] != '/') {
r->filename[filename_len++] = '/';
r->filename[filename_len] = 0;
temp_slash=1;
}
/* Begin *this* level by looking for matching <Directory> sections *fromtheserverconfig.
*/ for (; sec_idx < num_sec; ++sec_idx) {
/* No more possible matches for this many segments? *Wearedonewhenwefindrelative/regex/longercomponents.
*/ if (entry_core->r || entry_core->d_components > seg) { break;
}
/* We will never skip '0' element components, e.g. plain old *<Directory>,and<Directory"/">areclassifiedaszero *sothatWin32/Netware/OS2etcallpickthemup. *Otherwise,skipoverthemismatches.
*/ if (entry_core->d_components
&& ((entry_core->d_components < seg)
|| (entry_core->d_is_fnmatch
? (apr_fnmatch(entry_core->d, r->filename,
APR_FNM_PATHNAME) != APR_SUCCESS)
: (strcmp(r->filename, entry_core->d) != 0)))) { continue;
}
/* If we haven't continue'd above, we have a match. * *Calculateourfull-contextcoreopts&override.
*/
core_opts_merge(sec_ent[sec_idx], &opts);
/* If we merged this same section last time, reuse it
*/ if (matches) { if (last_walk->matched == sec_ent[sec_idx]) {
now_merged = last_walk->merged;
++last_walk;
--matches; continue;
}
/* We fell out of sync. This is our own copy of walked, *sotruncatetheremainingmatchesandresetremaining.
*/
cache->walked->nelts -= matches;
matches = 0;
cached = 0;
}
/* If .htaccess files are enabled, check for one, provided we *havereachedarealpath.
*/ do { /* Not really a loop, just a break'able code block */
ap_conf_vector_t *htaccess_conf = NULL;
/* No htaccess in an incomplete root path, *norifit'sdisabled
*/ if (seg < startseg || (!opts.override
&& apr_is_empty_table(opts.override_list)
)) { break;
}
res = ap_parse_htaccess(&htaccess_conf, r, opts.override,
opts.override_opts, opts.override_list,
r->filename, sconf->access_name); if (res) { return res;
}
if (!htaccess_conf) { break;
}
/* If we are still here, we found our htaccess. * *Calculateourfull-contextcoreopts&override.
*/
core_opts_merge(htaccess_conf, &opts);
/* If we merged this same htaccess last time, reuse it... *thiswouldn'tworkexceptthatwecachethehtaccess *sectionsforthelifetimeoftherequest,sowematch *thesameconf.Goodplanning(no,pureluck;)
*/ if (matches) { if (last_walk->matched == htaccess_conf) {
now_merged = last_walk->merged;
++last_walk;
--matches; break;
}
/* We fell out of sync. This is our own copy of walked, *sotruncatetheremainingmatchesandreset *remaining.
*/
cache->walked->nelts -= matches;
matches = 0;
cached = 0;
}
/* We choose apr_stat with flag APR_FINFO_LINK here, rather that *plainapr_stat,sothatwecapturethispathobjectratherthan *itstarget.Wewillreplacetheinfowithourtarget'sinfo *below.Weespeciallywantthenameofthis'link'object,not *thenameofitstarget,ifwearefixingthefilename *case/resolvingaliases.
*/
rv = ap_run_dirwalk_stat(&thisinfo, r,
APR_FINFO_MIN | APR_FINFO_NAME | APR_FINFO_LINK);
if (APR_STATUS_IS_ENOENT(rv)) { /* Nothing? That could be nice. But our directory *walkisdone.
*/
thisinfo.filetype = APR_NOFILE; break;
} elseif (APR_STATUS_IS_EACCES(rv)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00035) "access to %s denied (filesystem path '%s') " "because search permissions are missing on a " "component of the path", r->uri, r->filename); return r->status = HTTP_FORBIDDEN;
} elseif ((rv != APR_SUCCESS && rv != APR_INCOMPLETE)
|| !(thisinfo.valid & APR_FINFO_TYPE)) { /* If we hit ENOTDIR, we must have over-optimized, deny *ratherthanassumenotfound.
*/
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00036) "access to %s failed (filesystem path '%s')",
r->uri, r->filename); return r->status = HTTP_FORBIDDEN;
}
/* Fix up the path now if we have a name, and they don't agree
*/ if ((thisinfo.valid & APR_FINFO_NAME)
&& strcmp(seg_name, thisinfo.name)) { /* TODO: provide users an option that an internal/external *redirectisrequiredhere?WeneedtowalktheURIand *filenameintandemtoproperlycorrelatethese.
*/
strcpy(seg_name, thisinfo.name);
filename_len = strlen(r->filename);
}
if (thisinfo.filetype == APR_LNK) { /* Is this a possibly acceptable symlink?
*/ if ((res = resolve_symlink(r->filename, &thisinfo,
opts.opts, r->pool)) != OK) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00037) "Symbolic link not allowed " "or link target not accessible: %s",
r->filename); return r->status = res;
}
}
/* Ok, we are done with the link's info, test the real target
*/ if (thisinfo.filetype == APR_REG ||
thisinfo.filetype == APR_NOFILE) { /* That was fun, nothing left for us here
*/ break;
} elseif (thisinfo.filetype != APR_DIR) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00038) "Forbidden: %s doesn't point to " "a file or directory",
r->filename); return r->status = HTTP_FORBIDDEN;
}
++seg;
} while (thisinfo.filetype == APR_DIR);
/* If we have _not_ optimized, this is the time to recover *thefinalstatresult.
*/ if (r->finfo.filetype == APR_NOFILE || r->finfo.filetype == APR_LNK) {
r->finfo = thisinfo;
}
/* Now splice the saved path_info back onto any new path_info
*/ if (save_path_info) { if (r->path_info && *r->path_info) {
r->path_info = ap_make_full_path(r->pool, r->path_info,
save_path_info);
} else {
r->path_info = save_path_info;
}
}
if (ap_regexec(entry_core->r, r->filename, nmatch, pmatch, 0)) { continue;
}
for (i = 0; i < nmatch; i++) { if (pmatch[i].rm_so >= 0 && pmatch[i].rm_eo >= 0 &&
((constchar **)entry_core->refs->elts)[i]) {
apr_table_setn(r->subprocess_env,
((constchar **)entry_core->refs->elts)[i],
apr_pstrndup(r->pool,
r->filename + pmatch[i].rm_so,
pmatch[i].rm_eo - pmatch[i].rm_so));
}
}
/* If we haven't already continue'd above, we have a match. * *Calculateourfull-contextcoreopts&override.
*/
core_opts_merge(sec_ent[sec_idx], &opts);
/* If we merged this same section last time, reuse it
*/ if (matches) { if (last_walk->matched == sec_ent[sec_idx]) {
now_merged = last_walk->merged;
++last_walk;
--matches; continue;
}
/* We fell out of sync. This is our own copy of walked, *sotruncatetheremainingmatchesandresetremaining.
*/
cache->walked->nelts -= matches;
matches = 0;
cached = 0;
}
/* Whoops - everything matched in sequence, but either the original *walkfoundsomeadditionalmatches(whichweneedtotruncate),or *thiswalkfoundsomeadditionalmatches.
*/ if (matches) {
cache->walked->nelts -= matches;
cached = 0;
} elseif (cache->walked->nelts > cached_matches) {
cached = 0;
}
}
/* It seems this shouldn't be needed anymore. We translated the xsymlinkaboveintoarealresource,andshouldhavediedupthere. xEvenifwekeepthis,itneedsmorethought(maybeanr->file_is_symlink) xperhapsitshouldactuallyhappeninfile_walk,sowecatchmore xobscurecasesinautoindexsubrequests,etc. x x*Symlinkpermissionsaredeterminedbytheparent.Iftherequestis x*foradirectorythenapplyingthesymlinktestherewouldusethe x*permissionsofthedirectoryasopposedtoitsparent.Considera x*symlinkpointingtoadirwitha.htaccessdisallowingsymlinks.If x*youaccess/symlink(or/symlink/)youwouldgeta403withoutthis x*APR_DIRtest.Butifyouaccessed/symlink/index.html,forexample, x*youwould*not*getthe403. x xif(r->finfo.filetype!=APR_DIR x&&(res=resolve_symlink(r->filename,r->info,ap_allow_options(r), xr->pool))){ xap_log_rerror(APLOG_MARK,APLOG_ERR,0,r, x"Symboliclinknotallowed:%s",r->filename); xreturnres; x}
*/
/* Save future sub-requestors much angst in processing *thissubrequest.Ifdir_walkcouldn'tcanonicalize *thefilepath,nothingcan.
*/
r->canonical_filename = r->filename;
/* No tricks here, there are no <Locations > to parse in this vhost. *Wewon'tdestroythecache,justincase_this_redirectislater *redirectedagaintoavhostwith<Location>blockstooptimize.
*/ if (!num_sec) { return OK;
}
/* If we have an cache->cached location that matches r->uri, *andthevhost'slistoflocationshasn'tchanged,wecanskip *rewalkingthelocation_walkentries.
*/ if (cached
&& (cache->dir_conf_tested == sec_ent)
&& (strcmp(entry_uri, cache->cached) == 0)) { /* Well this looks really familiar! If our end-result (per_dir_result) *didn'tchange,wehaveabsolutelynothingtodo:) *Otherwise(asisthecasewithmostdir_merged/file_mergedrequests) *wemustmergeourdir_conf_mergedontothisnewr->per_dir_config.
*/ if (r->per_dir_config == cache->per_dir_result) { return OK;
}
if (cache->walked->nelts) {
now_merged = ((walk_walked_t*)cache->walked->elts)
[cache->walked->nelts - 1].merged;
}
} else { /* We start now_merged from NULL since we want to build *alocationslistthatcanbemergedtoanyvhost.
*/ int len, sec_idx; int matches = cache->walked->nelts; int cached_matches = matches;
walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
apr_pool_t *rxpool = NULL;
/* Go through the location entries, and check for matches. *Weapplythedirectivesectionsingivenorder,weshould *reallytrythemwiththemostgeneralfirst.
*/ for (sec_idx = 0; sec_idx < num_sec; ++sec_idx) {
/* ### const strlen can be optimized in location config parsing */
len = strlen(entry_core->d);
/* Test the regex, fnmatch or string as appropriate. *Ifit'sastrcmp,andthe<Location>patternwas *notslashterminated,thenthisurimustbeslash *terminated(orattheendofthestring)tomatch.
*/ if (entry_core->r) {
int nmatch = 0; int i;
ap_regmatch_t *pmatch = NULL;
/* If we merged this same section last time, reuse it
*/ if (matches) { if (last_walk->matched == sec_ent[sec_idx]) {
now_merged = last_walk->merged;
++last_walk;
--matches; continue;
}
/* We fell out of sync. This is our own copy of walked, *sotruncatetheremainingmatchesandresetremaining.
*/
cache->walked->nelts -= matches;
matches = 0;
cached = 0;
}
/* To allow broken modules to proceed, we allow missing filenames to pass. *Wewillcatchitlaterifit'sheadingforthecorehandler. *directory_walkalreadypostedanINFOnoteformoduledebugging.
*/ if (r->filename == NULL) { return OK;
}
/* No tricks here, there are just no <Files > to parse in this context. *Wewon'tdestroythecache,justincase_this_redirectislater *redirectedagaintoacontextcontainingthesameorsimilar<Files>.
*/ if (!num_sec) { return OK;
}
/* Get the basename .. and copy for the cache just *incaser->filenameismungedbyanothermodule
*/
test_file = strrchr(r->filename, '/'); if (test_file == NULL) {
test_file = apr_pstrdup(r->pool, r->filename);
} else {
test_file = apr_pstrdup(r->pool, ++test_file);
}
/* If we have an cache->cached file name that matches test_file, *andthedirectory'slistoffilesectionshasn'tchanged,we *canskiprewalkingthefile_walkentries.
*/ if (cached
&& (cache->dir_conf_tested == sec_ent)
&& (strcmp(test_file, cache->cached) == 0)) { /* Well this looks really familiar! If our end-result (per_dir_result) *didn'tchange,wehaveabsolutelynothingtodo:) *Otherwise(asisthecasewithmostdir_mergedrequests) *wemustmergeourdir_conf_mergedontothisnewr->per_dir_config.
*/ if (r->per_dir_config == cache->per_dir_result) { return OK;
}
if (cache->walked->nelts) {
now_merged = ((walk_walked_t*)cache->walked->elts)
[cache->walked->nelts - 1].merged;
}
} else { /* We start now_merged from NULL since we want to build *afilesectionlistthatcanbemergedtoanydir_walk.
*/ int sec_idx; int matches = cache->walked->nelts; int cached_matches = matches;
walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
apr_pool_t *rxpool = NULL;
/* Go through the location entries, and check for matches. *Weapplythedirectivesectionsingivenorder,weshould *reallytrythemwiththemostgeneralfirst.
*/ for (sec_idx = 0; sec_idx < num_sec; ++sec_idx) {
core_dir_config *entry_core;
entry_core = ap_get_core_module_config(sec_ent[sec_idx]);
if (entry_core->r) {
int nmatch = 0; int i;
ap_regmatch_t *pmatch = NULL;
/* If we merged this same section last time, reuse it
*/ if (matches) { if (last_walk->matched == sec_ent[sec_idx]) {
now_merged = last_walk->merged;
++last_walk;
--matches; continue;
}
/* We fell out of sync. This is our own copy of walked, *sotruncatetheremainingmatchesandresetremaining.
*/
cache->walked->nelts -= matches;
matches = 0;
cached = 0;
}
/* No tricks here, there are just no <If > to parse in this context. *Wewon'tdestroythecache,justincase_this_redirectislater *redirectedagaintoacontextcontainingthesameorsimilar<If>.
*/ if (!num_sec) { return OK;
}
/* Go through the if entries, and check for matches */ for (sec_idx = 0; sec_idx < num_sec; ++sec_idx) { constchar *err = NULL;
core_dir_config *entry_core; int rc;
entry_core = ap_get_core_module_config(sec_ent[sec_idx]);
AP_DEBUG_ASSERT(entry_core->condition_ifelse != 0); if (entry_core->condition_ifelse & AP_CONDITION_ELSE) {
AP_DEBUG_ASSERT(prev_result != -1); if (prev_result == 1) continue;
}
/* If we merged this same section last time, reuse it
*/ if (matches) { if (last_walk->matched == sec_ent[sec_idx]) {
now_merged = last_walk->merged;
++last_walk;
--matches; continue;
}
/* We fell out of sync. This is our own copy of walked, *sotruncatetheremainingmatchesandresetremaining.
*/
cache->walked->nelts -= matches;
matches = 0;
cached = 0;
}
/* Everything matched in sequence, but it may be that the original *walkfoundsomeadditionalmatches(whichweneedtotruncate),or *thiswalkfoundsomeadditionalmatches.
*/ if (matches) {
cache->walked->nelts -= matches;
cached = 0;
} elseif (cache->walked->nelts > cached_matches) {
cached = 0;
}
/* Start a clean config from this subrequest's vhost. Optimization in *Location/File/Dirwalksfromtheparentrequestassurethatifthe *configblocksofthesubrequestmatchtheparentrequest,nomerges *willactuallyoccur(andgenerallyaminimalnumberofmergesare *required,eveniftheparentandsubrequestaren'tquiteidentical.)
*/
rnew->per_dir_config = r->server->lookup_defaults;
/* make a copy of the allowed-methods list */
ap_copy_method_list(rnew->allowed_methods, r->allowed_methods);
/* start with the same set of output filters */ if (next_filter) {
ap_filter_t *scan = next_filter;
/* while there are no input filters for a subrequest, we will *trytoinsertsome,soifwedon'thavevaliddata,thecode *willsegfault.
*/
rnew->input_filters = r->input_filters;
rnew->proto_input_filters = r->proto_input_filters;
rnew->output_filters = next_filter;
rnew->proto_output_filters = r->proto_output_filters; while (scan && (scan != r->proto_output_filters)) { if (scan->frec == ap_subreq_core_filter_handle) { break;
}
scan = scan->next;
} if (!scan || scan == r->proto_output_filters) {
ap_add_output_filter_handle(ap_subreq_core_filter_handle,
NULL, rnew, rnew->connection);
}
} else { /* If NULL - we are expecting to be internal_fast_redirect'ed *tothissubrequest-orthisrequestwillneverbeinvoked. *Ignoretheoriginalrequestfilterstackentirely,and *drilltheinputandoutputstacksbacktotheconnection.
*/
rnew->proto_input_filters = r->proto_input_filters;
rnew->proto_output_filters = r->proto_output_filters;
/* We have to run this after we fill in sub req vars, *orther->mainpointerwon'tbesetup
*/
ap_run_create_request(rnew);
/* Begin by presuming any module can make its own path_info assumptions, *untilsomemoduleinterjectsandchangesthevalue.
*/
rnew->used_path_info = AP_REQ_DEFAULT_PATH_INFO;
/* Pass on the kept body (if any) into the new request. */
rnew->kept_body = r->kept_body;
AP_DECLARE(int) ap_some_auth_required(request_rec *r)
{ /* Is there a require line configured for the type of *this* req? */ if (ap__authz_ap_some_auth_required) { return ap__authz_ap_some_auth_required(r);
} else return0;
}
/* We cannot return NULL without violating the API. So just turn this
* subrequest into a 500 to indicate the failure. */ if (ap_is_recursion_limit_exceeded(r)) {
rnew->status = HTTP_INTERNAL_SERVER_ERROR; return rnew;
}
/* lookup_uri *Ifthecontentcanbeservedbythequick_handler,wecan *safelybypassrequest_internalprocessing. * *Ifnext_filterisNULLweareexpectingtobe *internal_fast_redirect'edtothesubrequest,orthesubrequestwill *neverbeinvoked.Weneedtomakesurethatthequickhandlerisnot *invokedbyanylookups.Sinceaninternal_fast_redirectwillalways *occurtoolateforthequickhandlertohandletherequest.
*/ if (next_filter) {
res = ap_run_quick_handler(rnew, 1);
}
if (next_filter == NULL || res != OK) { if ((res = ap_process_request_internal(rnew))) {
rnew->status = res;
}
}
/* Special case: we are looking at a relative lookup in the same directory. *Thisis100%safe,sincedirent->namejustcamefromthefilesystem.
*/ if (r->path_info && *r->path_info) { /* strip path_info off the end of the uri to keep it in sync *withr->filename,whichhasalreadybeenstrippedbydirectory_walk, *mergethedirent->name,andthen,ifthecallerwantsustoremerge *theoriginalpathinfo,doso.Noteweneverfixthepath_infoback *tor->filename,sincedir_walkwoulddoso(butwedon'texpectit *tohappenintheusualcases)
*/
udir = apr_pstrdup(rnew->pool, r->uri);
udir[ap_find_path_info(udir, r->path_info)] = '\0';
udir = ap_make_dirstr_parent(rnew->pool, udir);
/* XXX This is now less relevant; we will do a full location walk *thesedaysforthiscase.Preservetheapr_statresults,and *perhapswealsotagthatsymlinksweretestedand/orfoundfor *r->filename.
*/
rnew->per_dir_config = r->server->lookup_defaults;
if (rnew->finfo.filetype == APR_DIR) { /* ap_make_full_path overallocated the buffers *byonecharactertohelpusouthere.
*/
strcat(rnew->filename, "/"); if (!rnew->path_info || !*rnew->path_info) {
strcat(rnew->uri, "/");
}
}
/* fill in parsed_uri values
*/ if (r->args && *r->args && (subtype == AP_SUBREQ_MERGE_ARGS)) {
ap_parse_uri(rnew, apr_pstrcat(r->pool, rnew->uri, "?",
r->args, NULL));
} else {
ap_parse_uri(rnew, rnew->uri);
}
/* We cannot return NULL without violating the API. So just turn this
* subrequest into a 500. */ if (ap_is_recursion_limit_exceeded(r)) {
rnew->status = HTTP_INTERNAL_SERVER_ERROR; return rnew;
}
if ((res = ap_process_request_internal(rnew))) {
rnew->status = res;
}
/* Translate r->filename, if it was canonical, it stays canonical
*/ if (r->canonical_filename == r->filename) {
rnew->canonical_filename = (char*)(1);
}
if (r->uri && *r->uri) { char *udir = ap_make_dirstr_parent(rnew->pool, r->uri);
rnew->uri = ap_make_full_path(rnew->pool, udir,
rnew->filename + fdirlen);
ap_parse_uri(rnew, rnew->uri); /* fill in parsed_uri values */
} else {
ap_parse_uri(rnew, new_file); /* fill in parsed_uri values */
rnew->uri = apr_pstrdup(rnew->pool, "");
}
} else { /* XXX: @@@: What should be done with the parsed_uri values? *Wewouldbebetteroffstrippingdowntothe'common'elements *ofthepath,thenreassemblingtheURIasbestaswecan.
*/
ap_parse_uri(rnew, new_file); /* fill in parsed_uri values */ /* *XXX:thisshouldbesetproperlylikeitisinthesame-dircase *butit'sactuallysometimestoimpossibletodoit...becausethe *filemaynothaveauriassociatedwithit-djg
*/
rnew->uri = apr_pstrdup(rnew->pool, "");
}
/* We cannot return NULL without violating the API. So just turn this
* subrequest into a 500. */ if (ap_is_recursion_limit_exceeded(r)) {
rnew->status = HTTP_INTERNAL_SERVER_ERROR; return rnew;
}
if ((res = ap_process_request_internal(rnew))) {
rnew->status = res;
}
return rnew;
}
AP_DECLARE(int) ap_run_sub_req(request_rec *r)
{ int retval = DECLINED; /* Run the quick handler if the subrequest is not a dirent or file *subrequest
*/ if (!(r->filename && r->finfo.filetype != APR_NOFILE)) {
retval = ap_run_quick_handler(r, 0);
} if (retval != OK) {
retval = ap_invoke_handler(r); if (retval == DONE) {
retval = OK;
}
}
ap_finalize_sub_req_protocol(r); return retval;
}
AP_DECLARE(void) ap_destroy_sub_req(request_rec *r)
{ /* Reclaim the space */
apr_pool_destroy(r->pool);
}
/* *Isittheinitialmainrequest,whichweonlyget*once*perHTTPrequest?
*/
AP_DECLARE(int) ap_is_initial_req(request_rec *r)
{ return (r->main == NULL) /* otherwise, this is a sub-request */
&& (r->prev == NULL); /* otherwise, this is an internal redirect */
}
Messung V0.5 in Prozent
¤ 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.0.123Bemerkung:
(vorverarbeitet am 2026-09-27)
¤
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.