/* 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.
*/
/* Open the key associated with the script filetype extension */
rv = ap_regkey_open(&type_key, AP_REGKEY_CLASSES_ROOT, ext, APR_READ, p);
if (rv != APR_SUCCESS) { return NULL;
}
/* Retrieve the name of the script filetype extension */
rv = ap_regkey_value_get(&type_name, type_key, "", p);
if (rv == APR_SUCCESS && type_name[0]) { /* Open the key associated with the script filetype extension */
rv = ap_regkey_open(&name_key, AP_REGKEY_CLASSES_ROOT, type_name,
APR_READ, p);
}
/* Open the key for the script command path by: * *1)the'named'filetypekeyforExecCGI/Command *2)theextension'stypekeyforExecCGI/Command * *andifthestrictargisfalse,thencontinuetrying: * *3)the'named'filetypekeyforOpen/Command *4)theextension'stypekeyforOpen/Command
*/
d = (win32_dir_conf *)ap_get_module_config(r->per_dir_config,
&win32_module);
if (e_info->cmd_type) { /* We have to consider that the client gets any QUERY_ARGS *withoutanycharsetinterpretation,useprep_stringto *createastringoftheliteralQUERY_ARGSbytes.
*/
*cmd = r->filename; if (r->args && r->args[0] && !ap_strchr_c(r->args, '=')) {
args = r->args;
}
} /* Handle the complete file name, we DON'T want to follow suexec, since *anunrootedcommandisaspredictableasshootingcrapsinWin32. *Noticethatunlikemostmimeextensionparsing,wehavetousethe *win32parsinghere,thereforethefinalextensionistheonlyone *wewillconsider.
*/
ext = strrchr(apr_filepath_name_get(*cmd), '.');
/* If the file has an extension and it is not .com and not .exe and *we'vebeeninstructedtosearchtheregistry,thendoso. *Letapr_proc_createdoallofthe.bat/.cmddirtywork.
*/ if (ext && (!strcasecmp(ext,".exe") || !strcasecmp(ext,".com")
|| !strcasecmp(ext,".bat") || !strcasecmp(ext,".cmd"))) {
interpreter = "";
} if (!interpreter && ext
&& (d->script_interpreter_source
== INTERPRETER_SOURCE_REGISTRY
|| d->script_interpreter_source
== INTERPRETER_SOURCE_REGISTRY_STRICT)) { /* Check the registry */ int strict = (d->script_interpreter_source
== INTERPRETER_SOURCE_REGISTRY_STRICT);
interpreter = get_interpreter_from_win32_registry(r->pool, ext,
strict); if (interpreter && e_info->cmd_type != APR_SHELLCMD) {
e_info->cmd_type = APR_PROGRAM_PATH;
} else {
ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
strict ? APLOGNO(03180) "No ExecCGI verb found for files of type '%s'."
: APLOGNO(03181) "No ExecCGI or Open verb found for files of type '%s'.",
ext);
}
} if (!interpreter) {
apr_status_t rv; char buffer[1024];
apr_size_t bytes = sizeof(buffer);
apr_size_t i;
/* Need to peek into the file figure out what it really is... *###aughttogobackandbuildacacheforthisoneofthesedays.
*/ if ((rv = apr_file_open(&fh, *cmd, APR_READ | APR_BUFFERED,
APR_OS_DEFAULT, r->pool)) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02100) "Failed to open cgi file %s for testing", *cmd); return rv;
} if ((rv = apr_file_read(fh, buffer, &bytes)) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02101) "Failed to read cgi file %s for testing", *cmd); return rv;
}
apr_file_close(fh);
/* Some twisted character [no pun intended] at MS decided that a *zerowidthjoinerastheleadwidecharacterwouldbeidealfor *describingUnicodetextfiles.Thiswasfurtherconvolutedto *anotherMSismthatthesamecharactermappedintoutf-8,EFBBBF *wouldsignifyutf-8textfiles. * *SinceMSconfigurationfilesareallprotectingutf-8encoded *Unicodepath,fileandresourcenames,wealreadyhavethecorrect *WinNTencoding.Butatleasteatthestupidthreebytesupfront. * *###AmorethoroughcheckwouldalsoallowUNICODEtextinbuf,and *convertittoUTF-8forinvokingunicodescripts.Thosearefew *andfarbetween,soleavethatcodeanenterprisingsoulwithaneed.
*/ if ((bytes >= 3) && memcmp(buffer, "\xEF\xBB\xBF", 3) == 0) {
memmove(buffer, buffer + 3, bytes -= 3);
}
/* Script or executable, that is the question... *wecheckherealsofor'!sothat.vbsscriptscanworkasCGI.
*/ if ((bytes >= 2) && ((buffer[0] == '#') || (buffer[0] == '\''))
&& (buffer[1] == '!')) { /* Assuming file is a script since it starts with a shebang */ for (i = 2; i < bytes; i++) { if ((buffer[i] == '\r') || (buffer[i] == '\n')) {
buffer[i] = '\0'; break;
}
} if (i < bytes) {
interpreter = buffer + 2; while (apr_isspace(*interpreter)) {
++interpreter;
} if (e_info->cmd_type != APR_SHELLCMD) {
e_info->cmd_type = APR_PROGRAM_PATH;
}
}
} elseif (bytes >= sizeof(IMAGE_DOS_HEADER)) { /* Not a script, is it an executable? */
IMAGE_DOS_HEADER *hdr = (IMAGE_DOS_HEADER*)buffer; if (hdr->e_magic == IMAGE_DOS_SIGNATURE) { if (hdr->e_lfarlc < 0x40) { /* Ought to invoke this 16 bit exe by a stub, (cmd /c?) */
interpreter = "";
} else {
interpreter = "";
}
}
}
} if (!interpreter) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02102) "%s is not executable; ensure interpreted scripts have " "\"#!\" or \"'!\" first line", *cmd); return APR_EBADF;
}
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.