util_script.c revision 9fba5e90c5fd6e43467a72469cfe51891247757c
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd/* ====================================================================
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar * Redistribution and use in source and binary forms, with or without
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * modification, are permitted provided that the following conditions
acc36ab93565d2880447d535da6ca6e5feac7a70nd * are met:
031b91a62d25106ae69d4693475c79618dd5e884fielding * 1. Redistributions of source code must retain the above copyright
031b91a62d25106ae69d4693475c79618dd5e884fielding * notice, this list of conditions and the following disclaimer.
031b91a62d25106ae69d4693475c79618dd5e884fielding * 2. Redistributions in binary form must reproduce the above copyright
031b91a62d25106ae69d4693475c79618dd5e884fielding * notice, this list of conditions and the following disclaimer in
acc36ab93565d2880447d535da6ca6e5feac7a70nd * the documentation and/or other materials provided with the
acc36ab93565d2880447d535da6ca6e5feac7a70nd * distribution.
acc36ab93565d2880447d535da6ca6e5feac7a70nd * 3. All advertising materials mentioning features or use of this
acc36ab93565d2880447d535da6ca6e5feac7a70nd * software must display the following acknowledgment:
acc36ab93565d2880447d535da6ca6e5feac7a70nd * "This product includes software developed by the Apache Group
acc36ab93565d2880447d535da6ca6e5feac7a70nd * for use in the Apache HTTP server project (http://www.apache.org/)."
acc36ab93565d2880447d535da6ca6e5feac7a70nd * 4. The names "Apache Server" and "Apache Group" must not be used to
acc36ab93565d2880447d535da6ca6e5feac7a70nd * endorse or promote products derived from this software without
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * prior written permission. For written permission, please contact
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * apache@apache.org.
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * 5. Products derived from this software may not be called "Apache"
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * nor may "Apache" appear in their names without prior written
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * permission of the Apache Group.
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * 6. Redistributions of any form whatsoever must retain the following
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * acknowledgment:
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * "This product includes software developed by the Apache Group
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * for use in the Apache HTTP server project (http://www.apache.org/)."
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
7eaa41bc322620d14365712c9fc8438f7a330d8dnd * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * OF THE POSSIBILITY OF SUCH DAMAGE.
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * ====================================================================
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * This software consists of voluntary contributions made by many
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * individuals on behalf of the Apache Group and was originally based
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak * on public domain software written at the National Center for
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * Supercomputing Applications, University of Illinois, Urbana-Champaign.
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * For more information on the Apache Group and the Apache HTTP server
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * project, please see <http://www.apache.org/>.
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * Various utility functions which are common to a whole lot of
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * script-type extensions mechanisms, and might as well be gathered
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * in one place (if only to avoid creating inter-module dependancies
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * where there don't have to be).
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd#define MALFORMED_MESSAGE "malformed header from script. Bad header="
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd/* If a request includes query info in the URL (stuff after "?"), and
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * the query info does not contain "=" (indicative of a FORM submission),
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * then this routine is called to create the argument list to be passed
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * to the CGI script. When suexec is enabled, the suexec path, user, and
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * group are the first three arguments to be passed; if not, all three
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * must be NULL. The query info is split into separate arguments, where
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * "+" is the separator between keyword arguments.
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * XXXX: note that the WIN32 code uses one of the suexec strings
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * to pass an interpreter name. Remember this if changing the way they
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd * are handled in create_argv.
d78d735dbf7c5ce5ae545eecd8ee2c052224db77ndstatic char **create_argv(ap_context_t *p, char *path, char *user, char *group,
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd /* count the number of keywords */
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd numwords = APACHE_ARG_MAX - 5; /* Truncate args to prevent overrun */
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd av = (char **) ap_palloc(p, (numwords + 5) * sizeof(char *));
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd#endif /* defined(OS2) || defined(WIN32) */
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd while (*++cp) {
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);