mod_cgid.c revision c6a9d49433c9ba5b18b26c3d764f1bbcb9746090
2N/A/* ==================================================================== 2N/A * The Apache Software License, Version 1.1 2N/A * Copyright (c) 2000-2001 The Apache Software Foundation. All rights 2N/A * Redistribution and use in source and binary forms, with or without 2N/A * modification, are permitted provided that the following conditions 2N/A * 1. Redistributions of source code must retain the above copyright 2N/A * notice, this list of conditions and the following disclaimer. 2N/A * 2. Redistributions in binary form must reproduce the above copyright 2N/A * notice, this list of conditions and the following disclaimer in 2N/A * the documentation and/or other materials provided with the 2N/A * 3. The end-user documentation included with the redistribution, 2N/A * if any, must include the following acknowledgment: 2N/A * "This product includes software developed by the 2N/A * Alternately, this acknowledgment may appear in the software itself, 2N/A * if and wherever such third-party acknowledgments normally appear. 2N/A * 4. The names "Apache" and "Apache Software Foundation" must 2N/A * not be used to endorse or promote products derived from this 2N/A * software without prior written permission. For written 2N/A * permission, please contact apache@apache.org. 2N/A * 5. Products derived from this software may not be called "Apache", 12N/A * nor may "Apache" appear in their name, without prior written 12N/A * permission of the Apache Software Foundation. 2N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 2N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 26N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 38N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26N/A * ==================================================================== 26N/A * This software consists of voluntary contributions made by many 26N/A * individuals on behalf of the Apache Software Foundation. For more 26N/A * information on the Apache Software Foundation, please see 26N/A * Portions of this software are based upon public domain software 26N/A * originally written at the National Center for Supercomputing Applications, 26N/A * University of Illinois, Urbana-Champaign. 26N/A * http_script: keeps all script-related ramblings together. 26N/A * Compliant to cgi/1.1 spec 26N/A * Adapted by rst from original NCSA code by Rob McCool 26N/A * Apache adds some new env vars; REDIRECT_URL and REDIRECT_QUERY_STRING for 26N/A * custom error responses, and DOCUMENT_ROOT because we found it useful. 26N/A * It also adds SERVER_ADMIN - useful for scripts to know who to mail when 46N/A/* ### should be tossed in favor of APR */ 46N/A/* KLUDGE --- for back-combatibility, we don't have to check Execcgid 26N/A * in ScriptAliased directories, which means we need to know if this 46N/A * request came through ScriptAlias or not... so the Alias module 46N/A * leaves a note for us. 46N/A/* Configuration stuff */ 2N/A/* DEFAULT_CGID_LISTENBACKLOG controls the max depth on the unix socket's 38N/A * pending connection queue. If a bunch of cgi requests arrive at about 2N/A * in the queue while the cgid process slowly forks off a child to process 32N/A * each connection on the unix socket. If the queue is too short, the 32N/A * httpd process will get ECONNREFUSED when trying to connect. 38N/A/* If a request includes query info in the URL (stuff after "?"), and 38N/A * the query info does not contain "=" (indicative of a FORM submission), 38N/A * then this routine is called to create the argument list to be passed 38N/A * to the CGI script. When suexec is enabled, the suexec path, user, and 38N/A * group are the first three arguments to be passed; if not, all three 38N/A * must be NULL. The query info is split into separate arguments, where 38N/A * "+" is the separator between keyword arguments. 38N/A * XXXX: note that the WIN32 code uses one of the suexec strings 26N/A * to pass an interpreter name. Remember this if changing the way they 26N/A * are handled in create_argv. 32N/A /* count the number of keywords */ /* don't do anything; server is stopping or restarting */ /* it would be better to restart just the cgid child * process but for now we'll gracefully restart the entire * server by sending AP_SIG_GRACEFUL to ourself, the httpd /* we get here when pcgi is cleaned up; pcgi gets cleaned * up when pconf gets cleaned up for (i = 0; i < j; i++) {
/* add 1, so that if i == 0, we still malloc something. */ /* For right now, just make the notes table. At some point we will need * to actually fill this out, but for now we just don't want suexec to for (i =0;
env[i]; i++) {
/* Write the request type (SSI "exec cmd" or cgi). */ "write to cgi daemon process");
/* Write the number of entries in the environment. */ if (
write(
fd, &i,
sizeof(
int)) < 0) {
"write to cgi daemon process");
for (i = 0;
env[i]; i++) {
/* Write the length of the concatenated env string. */ "write to cgi daemon process");
/* Write the concatted env string. */ "write to cgi daemon process");
/* Write module_index id value. */ "write to cgi daemon process");
"Couldn't unlink unix domain socket %s",
/* just a warning; don't bail out */ "Couldn't create unix domain socket");
omask =
umask(00
77);
/* so that only Apache can use socket */ umask(
omask);
/* can't fail, so can't clobber errno */ "Couldn't bind unix domain socket %s",
"Couldn't listen on unix domain socket");
"Couldn't change owner of unix domain socket %s",
const char *
const *
argv;
"Error accepting on cgid socket");
/* XXX apr_procattr_child_*_set() is creating an unnecessary * pipe between this process and the child being created... * It is cleaned up with the temporary pool for this request. /* Something bad happened, tell the world. */ "couldn't set child process attributes: %s", r->
filename);
/* We want to close sd2 for the new CGI process too. * If it is left open it'll make ap_pass_brigade() block * waiting for EOF if CGI forked something running long. * close(sd2) here should be okay, as CGI channel * is already dup()ed by apr_procattr_child_{in,out}_set() (
const char *
const *)
env,
/* Bad things happened. Everyone should have cleaned up. */ "couldn't create child process: %d: %s",
rc, r->
filename);
"Couldn't spawn cgid daemon process");
/* XXX should we return a failure here ? */ /* Required by mod_include filter. This is how mod_cgid registers * with mod_include to provide processing of the exec directive. "the name of a log for script debugging info"),
"the maximum length (in bytes) of the script debug log"),
"the maximum size (in bytes) to record of a POST request"),
"the name of the socket to use for communication with " /* XXX Very expensive mainline case! Open, then getfileinfo! */ /* XXX Very expensive mainline case! Open, then getfileinfo! */ /* Soak up script output */ /**************************************************************** * Actual cgid handling... /* 99 out of 100 cgid scripts, this is all they support */ "Options ExecCGI is off in this directory");
"attempt to include NPH CGI script");
"script not found or unable to stat");
"attempt to invoke directory as script");
"AcceptPathInfo off disallows user's path");
if (!ap_suexec_enabled) { if (!ap_can_exec(&r->finfo)) return log_scripterror(r, conf, HTTP_FORBIDDEN, 0, "file permissions deny server execution"); "unable to create socket to cgi daemon");
"unable to connect to cgi daemon");
/* We are putting the tempsock variable into a file so that we can use * a pipe bucket to send the data to the client. /* Transfer any put/post args, CERN style... * Note that we already ignore SIGPIPE in the core server. /* silly script stopped reading, soak up remaining message */ /* we're done writing, or maybe we didn't write at all; * force EOF on child's stdin so that the cgi detects end (or /* Handle script return... */ /* Soak up all the script output */ /* This redirect needs to be a GET no matter what the original /* We already read the message body (if any), so don't allow * the redirected request to think it has one. We can ignore * Transfer-Encoding, since we used REQUEST_CHUNKED_ERROR. /* XX Note that if a script wants to produce its own Redirect * body, it now has to explicitly *say* "Status: 302" return OK;
/* NOT r->status, even if it has changed. */ /*============================================================================ *============================================================================ * This is the beginning of the cgi filter code moved from mod_include. This * is the code required to handle the "exec" SSI directive. *============================================================================ *============================================================================*/ /* No hardwired path info or query allowed */ /* Script gets parameters of the *document*, for back compatibility */ /* Force sub_req to be treated as a CGI request, even if ordinary * typing rules would have called it something else. /* XXX: if most of this stuff is going to get copied anyway, * it'd be more efficient to pstrcat it into a single pool buffer * and a single pool bucket */ sizeof(
"<A HREF=\"") -
1);
/* This is the special environment used for running the "exec cmd=" * variety of SSI directives. "unable to create socket to cgi daemon");
"unable to connect to cgi daemon");
/* We are putting the tempsock variable into a file so that we can use * a pipe bucket to send the data to the client. /* Soak up all the script output */ /* This redirect needs to be a GET no matter what the original /* We already read the message body (if any), so don't allow * the redirected request to think it has one. We can ignore * Transfer-Encoding, since we used REQUEST_CHUNKED_ERROR. /* XX Note that if a script wants to produce its own Redirect * body, it now has to explicitly *say* "Status: 302" "exec used but not allowed in %s", r->
filename);
"execution failure for parameter \"%s\" " /* just in case some stooge changed directories */ "unknown parameter \"%s\" to tag exec in %s",
tag,
file);
/*============================================================================ *============================================================================ * This is the end of the cgi filter code moved from mod_include. *============================================================================ *============================================================================*/ NULL,
/* dir config creater */ NULL,
/* dir merger --- default is to override */