util_script.c revision f15953964058dc2a5c775df882c73f1c9256d08c
967e5f3c25249c779575864692935627004d3f9eChristian Maeder/* ====================================================================
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * Redistribution and use in source and binary forms, with or without
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * modification, are permitted provided that the following conditions
62599a910de0701b0f9461e534a43d5900131c55Christian Maeder * 1. Redistributions of source code must retain the above copyright
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * notice, this list of conditions and the following disclaimer.
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * 2. Redistributions in binary form must reproduce the above copyright
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * notice, this list of conditions and the following disclaimer in
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * the documentation and/or other materials provided with the
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * distribution.
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * 3. All advertising materials mentioning features or use of this
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * software must display the following acknowledgment:
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * "This product includes software developed by the Apache Group
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * for use in the Apache HTTP server project (http://www.apache.org/)."
62599a910de0701b0f9461e534a43d5900131c55Christian Maeder * 4. The names "Apache Server" and "Apache Group" must not be used to
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * endorse or promote products derived from this software without
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * prior written permission. For written permission, please contact
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * apache@apache.org.
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * 5. Products derived from this software may not be called "Apache"
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * nor may "Apache" appear in their names without prior written
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * permission of the Apache Group.
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * 6. Redistributions of any form whatsoever must retain the following
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * acknowledgment:
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * "This product includes software developed by the Apache Group
62599a910de0701b0f9461e534a43d5900131c55Christian Maeder * for use in the Apache HTTP server project (http://www.apache.org/)."
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
62599a910de0701b0f9461e534a43d5900131c55Christian Maeder * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * OF THE POSSIBILITY OF SUCH DAMAGE.
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * ====================================================================
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * This software consists of voluntary contributions made by many
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * individuals on behalf of the Apache Group and was originally based
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * on public domain software written at the National Center for
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * Supercomputing Applications, University of Illinois, Urbana-Champaign.
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * For more information on the Apache Group and the Apache HTTP server
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * project, please see <http://www.apache.org/>.
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder#include "http_request.h" /* for sub_req_lookup_uri() */
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder#include "util_date.h" /* For parseHTTPdate() */
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * Various utility functions which are common to a whole lot of
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * script-type extensions mechanisms, and might as well be gathered
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * in one place (if only to avoid creating inter-module dependancies
62599a910de0701b0f9461e534a43d5900131c55Christian Maeder * where there don't have to be).
967e5f3c25249c779575864692935627004d3f9eChristian Maeder#define MALFORMED_MESSAGE "malformed header from script. Bad header="
967e5f3c25249c779575864692935627004d3f9eChristian Maeder/* If a request includes query info in the URL (stuff after "?"), and
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * the query info does not contain "=" (indicative of a FORM submission),
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * then this routine is called to create the argument list to be passed
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * to the CGI script. When suexec is enabled, the suexec path, user, and
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * group are the first three arguments to be passed; if not, all three
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * must be NULL. The query info is split into separate arguments, where
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * "+" is the separator between keyword arguments.
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * XXXX: note that the WIN32 code uses one of the suexec strings
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * to pass an interpreter name. Remember this if changing the way they
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * are handled in create_argv.
967e5f3c25249c779575864692935627004d3f9eChristian Maederstatic char **create_argv(ap_context_t *p, char *path, char *user, char *group,
int x, numwords;
char **av;
int idx = 0;
++numwords;
if (path) {
if (user) {
if (group) {
ap_unescape_url(w);
return av;
while (*++cp) {
return res;
char *tz;
char *whack;
++whack;
return env;
ap_table_t *e;
const char *rem_logname;
char *env_path;
#ifdef WIN32
char *env_temp;
const char *host;
#ifndef SECURITY_HOLE_PASS_AUTHORIZATION
#ifdef WIN32
if (host) {
if (r->user) {
if (r->ap_auth_type) {
if (rem_logname) {
if (r->prev) {
lu = 0;
lu++;
return lu;
#ifdef WIN32
NULL);
#ifdef WIN32
int (*getsfunc) (char *, int, void *),
void *getsfunc_data)
char x[MAX_STRING_LEN];
if (buffer) {
return HTTP_INTERNAL_SERVER_ERROR;
p = strlen(w);
return cond_status;
#ifdef CHARSET_EBCDIC
char *cp;
++maybeEBCDIC;
++maybeASCII;
if (!buffer) {
return HTTP_INTERNAL_SERVER_ERROR;
while (*l && ap_isspace(*l)) {
char *tmp;
char *buffer)
char *buffer)
else if (!size) {
char **av;
ap_unescape_url(w);
return av;
int pid = 0;
#ifdef OS2
int is_script = 0;
int cmdlen;
int env_len, e;
if (!program) {
r->filename);
return (pid);
if (is_script) {
*args_end = 0;
/* +4 = 1 space between progname and args, 2 for double null at end, 2 for possible quote on first arg */
while (*cmdline_pos) {
cmdline_pos++;
char *arg;
if (args) {
*args = 0;
args++;
for (e=0; env[e]; e++) {
rc = DosExecPgm(error_object, sizeof(error_object), EXEC_ASYNC, cmdline, env_block, &rescodes, cmdline);
if (rc) {
char *s = NULL;
char *quoted_filename;
char *pCommand;
int iEnvBlockLen;
if (!shellcmd) {
r->filename);
return (pid);
int iStringSize = 0;
for (x=0; arguments[x]; x++) {
while (env[i]) {
while (env[i]) {
return (pid);
if (pos) {
return (pid);
return (pid);
return (pid);
return (pid);
if (shellcmd) {
env);
if (shellcmd) {
env);
return (pid);