mod_win32.c revision fb4d6124f12703dd1eed48e27dd712f046fea222
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_buckets.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_request.h"
#include "http_log.h"
#include "util_script.h"
#include "mod_core.h"
#include "apr_optional.h"
#include "apr_lib.h"
#ifdef WIN32
/*
* CGI Script stuff for Win32...
*/
typedef enum { INTERPRETER_SOURCE_UNSET, INTERPRETER_SOURCE_REGISTRY_STRICT,
char **interpreter,
char **arguments);
typedef struct {
/* Where to find interpreter to run scripts */
{
return conf;
}
{
return new;
}
char *arg)
{
}
}
}
else {
"\" must be \"registry\", \"registry-strict\" or "
"\"script\"", NULL);
}
return NULL;
}
/* Pretty unexciting ... yank a registry value, and explode any envvars
* that the system has configured (e.g. %SystemRoot%/someapp.exe)
*
* XXX: Need Unicode versions for i18n
*/
char* relativepath,
char **value)
{
if (result != ERROR_SUCCESS) {
return APR_FROM_OS_ERROR(result);
}
/* Read to NULL buffer to determine value size */
if (result == ERROR_SUCCESS) {
}
else {
/* Read value based on size query above */
}
}
/* TODO: This might look fine, but we need to provide some warning
* somewhere that some environment variables may -not- be translated,
* seeing as we may have chopped the environment table down somewhat.
*/
if (size) {
}
}
return APR_FROM_OS_ERROR(result);
}
/* Somewhat more exciting ... figure out where the registry has stashed the
* ExecCGI or Open command - it may be nested one level deep (or more???)
*/
static char* get_interpreter_from_win32_registry(apr_pool_t *p,
const char* ext,
int strict)
{
char execcgi_path[] = "SHELL\\EXECCGI\\COMMAND";
char execopen_path[] = "SHELL\\OPEN\\COMMAND";
int size;
int result;
char *buffer;
if (!ext) {
return NULL;
}
/*
* Future optimization:
* When the registry is successfully searched, store the strings for
* interpreter and arguments in an ext hash to speed up subsequent look-ups
*/
/* Open the key associated with the script filetype extension */
&hkeyType);
if (result != ERROR_SUCCESS) {
return NULL;
}
/* Retrieve the name of the script filetype extension */
/* Open the key associated with the script filetype extension */
if (result == ERROR_SUCCESS) {
}
}
/* Open the key for the script command path by:
*
*
* and if the strict arg is false, then continue trying:
*
*/
if (cmdOfName) {
execcgi_path, &buffer);
}
execcgi_path, &buffer);
}
execopen_path, &buffer);
}
execopen_path, &buffer);
}
if (cmdOfName) {
}
return NULL;
}
return buffer;
}
{
const char **arg;
int prgtaken = 0;
int argtaken = 0;
int inquo;
int sl;
while (*ch) {
/* Skip on through Deep Space */
++ch; continue;
}
/* One Arg */
argtaken = 1;
for (;;) {
if (!*w) {
break;
}
ap_unescape_url(w);
*arg = ap_escape_shell_cmd(p, w);
}
ch += 2;
continue;
}
/* Todo: Make short name!!! */
prgtaken = 1;
if (*ch == '%') {
*repl++ = '\\';
}
}
else {
}
ch += 2;
continue;
}
prgtaken = 1;
*repl++ = '\\';
}
}
else {
}
ch += 4;
continue;
}
*arg = d;
inquo = 0;
while (*ch) {
++ch; break;
}
/* Get 'em backslashes */
*d++ = *ch++;
}
if (sl & 1) {
/* last unmatched '\' + '"' sequence is a '"' */
if (*ch == '\"') {
*(d - 1) = *ch++;
}
continue;
}
if (*ch == '\"') {
/* '""' sequence within quotes is a '"' */
*d++ = *ch++; continue;
}
/* Flip quote state */
++ch; break;
}
/* All other '"'s are Munched */
continue;
}
/* Anything else is, well, something else */
*d++ = *ch++;
}
/* Term that arg, already pushed on args */
*d++ = '\0';
}
if (!prgtaken) {
}
if (!argtaken) {
for (;;) {
if (!*w) {
break;
}
ap_unescape_url(w);
*arg = ap_escape_shell_cmd(p, w);
}
}
return args;
}
request_rec *r, apr_pool_t *p,
{
const char *interpreter = NULL;
win32_dir_conf *d;
apr_file_t *fh;
&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
*/
/* 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 = "";
}
if (!interpreter && ext
&& (d->script_interpreter_source
/* Check the registry */
int strict = (d->script_interpreter_source
strict);
if (!interpreter) {
strict ? "No ExecCGI verb found for files of type '%s'."
: "No ExecCGI or Open verb found for files of type '%s'.",
ext);
}
}
if (!interpreter) {
char buffer[1024];
int i;
/* 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.
*/
"Failed to read cgi file %s for testing",
r->filename);
return rv;
}
/* Script or executable, that is the question... */
/* Assuming file is a script since it starts with a shebang */
for (i = 2; i < sizeof(buffer); i++) {
buffer[i] = '\0';
break;
}
}
if (i < sizeof(buffer)) {
while (isspace(*interpreter)) {
++interpreter;
}
}
}
else {
/* Not a script, is it an executable? */
if ((bytes >= sizeof(IMAGE_DOS_HEADER))
/* Ought to invoke this 16 bit exe by a stub, (cmd /c?) */
interpreter = "";
}
else {
interpreter = "";
}
}
}
}
if (!interpreter) {
"%s is not executable; ensure interpreted scripts have "
"\"#!\" first line",
r->filename);
return APR_EBADF;
}
args = "";
}
return APR_SUCCESS;
}
request_rec *r, apr_pool_t *p,
static void register_hooks(apr_pool_t *p)
{
}
static const command_rec win32_cmds[] = {
"Where to find interpreter to run Win32 scripts "
"(Registry or script shebang line)"),
{ NULL }
};
create_win32_dir_config, /* create per-dir config */
merge_win32_dir_configs, /* merge per-dir config */
NULL, /* server config */
NULL, /* merge server config */
win32_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};
#endif