/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef WIN32
#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 "mod_cgi.h"
#include "apr_lib.h"
#include "ap_regkey.h"
/*
* CGI Script stuff for Win32...
*/
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;
}
/* XXX: prep_string should translate the string into unicode,
* such that it is compatible with whatever codepage the client
* will read characters 80-ff. For the moment, use the unicode
* values 0080-00ff. This isn't trivial, since the code page
* varies between msdos and Windows applications.
* For subsystem 2 [GUI] the default is the system Ansi CP.
* For subsystem 3 [CLI] the default is the system OEM CP.
*/
{
char *ch2;
if (!ch) {
return;
}
while (*ch) {
if (*(ch++) & 0x80) {
++widen;
}
}
if (!widen) {
return;
}
while (*ch) {
if (*ch & 0x80) {
/* sign extension won't hurt us here */
}
else {
}
}
*(ch2++) = '\0';
}
/* Somewhat more exciting ... figure out where the registry has stashed the
* ExecCGI or Open command - it may be nested one level deep (or more???)
*/
const char* ext,
int strict)
{
char *type_name;
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 */
if (rv != APR_SUCCESS) {
return NULL;
}
/* Retrieve the name of the script filetype extension */
/* Open the key associated with the script filetype extension */
APR_READ, p);
}
/* Open the key for the script command path by:
*
*
* and if the strict arg is false, then continue trying:
*
*/
if (name_key) {
== APR_SUCCESS) {
}
}
== APR_SUCCESS) {
}
}
== APR_SUCCESS) {
}
}
== APR_SUCCESS) {
}
}
if (name_key) {
}
return NULL;
}
return buffer;
}
{
const char **arg;
int prgtaken = 0;
int argtaken = 0;
int inquo;
int sl;
while (*ch) {
/* Skip on through Deep Space */
if (apr_isspace(*ch)) {
++ch; continue;
}
/* One Arg */
argtaken = 1;
for (;;) {
if (!*w) {
break;
}
ap_unescape_url(w);
prep_string((const char**)&w, p);
*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);
prep_string((const char**)&w, p);
*arg = ap_escape_shell_cmd(p, w);
}
}
return args;
}
request_rec *r, apr_pool_t *p,
{
win32_dir_conf *d;
int i;
&win32_module);
/* We have to consider that the client gets any QUERY_ARGS
* without any charset interpretation, use prep_string to
* create a string of the literal QUERY_ARGS bytes.
*/
}
}
/* 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.
* Let apr_proc_create do all of the .bat/.cmd dirty work.
*/
interpreter = "";
}
if (!interpreter && ext
&& (d->script_interpreter_source
/* Check the registry */
strict);
}
else {
strict ? "No ExecCGI verb found for files of type '%s'."
: "No ExecCGI or Open verb found for files of type '%s'.",
ext);
}
}
if (!interpreter) {
apr_size_t 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 open cgi file %s for testing", *cmd);
return rv;
}
"Failed to read cgi file %s for testing", *cmd);
return rv;
}
/* Some twisted character [no pun intended] at MS decided that a
* zero width joiner as the lead wide character would be ideal for
* describing Unicode text files. This was further convoluted to
* another MSism that the same character mapped into utf-8, EF BB BF
* would signify utf-8 text files.
*
* Since MS configuration files are all protecting utf-8 encoded
* Unicode path, file and resource names, we already have the correct
* WinNT encoding. But at least eat the stupid three bytes up front.
*
* ### A more thorough check would also allow UNICODE text in buf, and
* convert it to UTF-8 for invoking unicode scripts. Those are few
* and far between, so leave that code an enterprising soul with a need.
*/
}
/* Script or executable, that is the question...
* we check here also for '! so that .vbs scripts can work as CGI.
*/
/* Assuming file is a script since it starts with a shebang */
for (i = 2; i < bytes; i++) {
buffer[i] = '\0';
break;
}
}
if (i < bytes) {
while (apr_isspace(*interpreter)) {
++interpreter;
}
}
}
}
else if (bytes >= sizeof(IMAGE_DOS_HEADER)) {
/* Not a script, is it an executable? */
/* 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 "
"\"#!\" or \"'!\" first line", *cmd);
return APR_EBADF;
}
/* XXX: Must fix r->subprocess_env to follow utf-8 conventions from
* the client's octets so that win32 apr_proc_create is happy.
* The -best- way is to determine if the .exe is unicode aware
* (using 0x0080-0x00ff) or is linked as a command or windows
* application (following the OEM or Ansi code page in effect.)
*/
}
}
return APR_SUCCESS;
}
{
}
"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 /* defined WIN32 */