static apr_status_t ap_cgi_build_command(const char **cmd, const char ***argv,
request_rec *r, apr_pool_t *p,
- int replace_cmd, apr_cmdtype_e *type)
+ int process_cgi, apr_cmdtype_e *type)
{
const char *ext = NULL;
const char *interpreter = NULL;
win32_dir_conf *d;
apr_file_t *fh;
- const char *args = r->args;
+ const char *args = "";
d = (win32_dir_conf *)ap_get_module_config(r->per_dir_config,
&win32_module);
- /* Handle the complete file name, we DON'T want to follow suexec, since
- * an unrooted command is as predictable as shooting craps in Win32.
- *
- * Notice that unlike most mime extension parsing, we have to use the
- * win32 parsing here, therefore the final extension is the only one
- * we will consider
- */
- ext = strrchr(apr_filename_of_pathname(r->filename), '.');
+ if (process_cgi) {
+ /* Handle the complete file name, we DON'T want to follow suexec, since
+ * an unrooted command is as predictable as shooting craps in Win32.
+ *
+ * Notice that unlike most mime extension parsing, we have to use the
+ * win32 parsing here, therefore the final extension is the only one
+ * we will consider
+ */
+ *cmd = r->filename;
+ if (r->args && r->args[0] && !ap_strchr_c(r->args, '=')) {
+ args = r->args;
+ }
+ }
+ ext = strrchr(apr_filename_of_pathname(*cmd), '.');
/* If the file has an extension and it is not .com and not .exe and
* we've been instructed to search the registry, then do so.
== INTERPRETER_SOURCE_REGISTRY_STRICT);
interpreter = get_interpreter_from_win32_registry(r->pool, ext,
strict);
- if (interpreter) {
+ if (interpreter && *type != APR_SHELLCMD) {
*type = APR_PROGRAM_PATH;
}
else {
/* Need to peek into the file figure out what it really is...
* ### aught to go back and build a cache for this one of these days.
*/
- if (((rv = apr_file_open(&fh, r->filename, APR_READ | APR_BUFFERED,
+ if (((rv = apr_file_open(&fh, *cmd, APR_READ | APR_BUFFERED,
APR_OS_DEFAULT, r->pool)) != APR_SUCCESS)
|| ((rv = apr_file_read(fh, buffer, &bytes)) != APR_SUCCESS)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
- "Failed to read cgi file %s for testing",
- r->filename);
+ "Failed to read cgi file %s for testing", *cmd);
return rv;
}
apr_file_close(fh);
while (isspace(*interpreter)) {
++interpreter;
}
- *type = APR_PROGRAM_PATH;
+ if (*type != APR_SHELLCMD) {
+ *type = APR_PROGRAM_PATH;
+ }
}
}
else {
if (!interpreter) {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
"%s is not executable; ensure interpreted scripts have "
- "\"#!\" first line",
- r->filename);
+ "\"#!\" first line", *cmd);
return APR_EBADF;
}
- if (!args || ap_strchr_c(args, '=')) {
- args = "";
- }
-
- *argv = (const char **)(split_argv(p, interpreter, r->filename,
+ *argv = (const char **)(split_argv(p, interpreter, *cmd,
args)->elts);
*cmd = (*argv)[0];
return APR_SUCCESS;