mod_netware.c revision 1079536268898f733a5f646c3c9a1e040e0146a8
6320N/A/* ====================================================================
6320N/A * The Apache Software License, Version 1.1
6320N/A *
6320N/A * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
6320N/A * reserved.
6320N/A *
6320N/A * Redistribution and use in source and binary forms, with or without
6320N/A * modification, are permitted provided that the following conditions
6320N/A * are met:
6320N/A *
6320N/A * 1. Redistributions of source code must retain the above copyright
6320N/A * notice, this list of conditions and the following disclaimer.
6320N/A *
6320N/A * 2. Redistributions in binary form must reproduce the above copyright
6320N/A * notice, this list of conditions and the following disclaimer in
6320N/A * the documentation and/or other materials provided with the
6320N/A * distribution.
6320N/A *
6320N/A * 3. The end-user documentation included with the redistribution,
6320N/A * if any, must include the following acknowledgment:
6320N/A * "This product includes software developed by the
6320N/A * Apache Software Foundation (http://www.apache.org/)."
6320N/A * Alternately, this acknowledgment may appear in the software itself,
6320N/A * if and wherever such third-party acknowledgments normally appear.
6320N/A *
6320N/A * 4. The names "Apache" and "Apache Software Foundation" must
6320N/A * not be used to endorse or promote products derived from this
6320N/A * software without prior written permission. For written
6320N/A * permission, please contact apache@apache.org.
6320N/A *
6320N/A * 5. Products derived from this software may not be called "Apache",
6320N/A * nor may "Apache" appear in their name, without prior written
6320N/A * permission of the Apache Software Foundation.
6320N/A *
6320N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
6320N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6320N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6320N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
6320N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6320N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6320N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
6320N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
6320N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6320N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
6320N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6320N/A * SUCH DAMAGE.
6320N/A * ====================================================================
6320N/A *
6320N/A * This software consists of voluntary contributions made by many
6320N/A * individuals on behalf of the Apache Software Foundation. For more
6320N/A * information on the Apache Software Foundation, please see
6320N/A * <http://www.apache.org/>.
6320N/A *
6320N/A * Portions of this software are based upon public domain software
6320N/A * originally written at the National Center for Supercomputing Applications,
6320N/A * University of Illinois, Urbana-Champaign.
6320N/A */
6320N/A
6320N/A
6320N/A#include "apr_strings.h"
6320N/A#include "apr_portable.h"
6320N/A#include "apr_buckets.h"
6320N/A#include "ap_config.h"
6320N/A#include "httpd.h"
6320N/A#include "http_config.h"
6320N/A#include "http_core.h"
6320N/A#include "http_protocol.h"
6320N/A#include "http_request.h"
6320N/A#include "http_log.h"
6320N/A#include "util_script.h"
6320N/A#include "mod_core.h"
6320N/A#include "apr_optional.h"
6320N/A#include "apr_lib.h"
6320N/A#include "mod_cgi.h"
6320N/A
6320N/A#ifdef NETWARE
6320N/A
6320N/A
6320N/Amodule AP_MODULE_DECLARE_DATA netware_module;
6320N/A
6320N/Atypedef struct {
6320N/A apr_table_t *file_type_handlers; /* CGI map from file types to CGI modules */
6320N/A apr_table_t *extra_env_vars; /* Environment variables to be added to the CGI environment */
6320N/A} netware_dir_config;
6320N/A
6320N/A
6320N/Astatic void *create_netware_dir_config(apr_pool_t *p, char *dir)
6320N/A{
6320N/A netware_dir_config *new = (netware_dir_config*) apr_palloc(p, sizeof(netware_dir_config));
6320N/A
6320N/A new->file_type_handlers = apr_table_make(p, 10);
6320N/A new->extra_env_vars = apr_table_make(p, 10);
6320N/A
6320N/A return new;
6320N/A}
6320N/A
6320N/Astatic void *merge_netware_dir_configs(apr_pool_t *p, void *basev, void *addv)
6320N/A{
6320N/A netware_dir_config *base = (netware_dir_config *) basev;
6320N/A netware_dir_config *add = (netware_dir_config *) addv;
6320N/A netware_dir_config *new = (netware_dir_config *) apr_palloc(p, sizeof(netware_dir_config));
6320N/A
6320N/A new->file_type_handlers = apr_table_overlay(p, add->file_type_handlers, base->file_type_handlers);
6320N/A new->extra_env_vars = apr_table_overlay(p, add->extra_env_vars, base->extra_env_vars);
6320N/A
6320N/A return new;
6320N/A}
6320N/A
6320N/Astatic const char *set_extension_map(cmd_parms *cmd, netware_dir_config *m, char *CGIhdlr, char *ext)
6320N/A{
6320N/A if (*ext == '.')
6320N/A ++ext;
6320N/A apr_table_set(m->file_type_handlers, ext, CGIhdlr);
6320N/A return NULL;
6320N/A}
6320N/A
6320N/Astatic apr_status_t ap_cgi_build_command(const char **cmd, const char ***argv,
6320N/A request_rec *r, apr_pool_t *p,
6320N/A cgi_exec_info_t *e_info)
6320N/A{
6320N/A const char *ext = NULL;
6320N/A const char *interpreter = NULL;
6320N/A netware_dir_config *d;
6320N/A apr_file_t *fh;
6320N/A const char *args = "";
6320N/A
6320N/A d = (netware_dir_config *)ap_get_module_config(r->per_dir_config,
6320N/A &netware_module);
6320N/A
6320N/A if (e_info->process_cgi) {
6320N/A /* Handle the complete file name, we DON'T want to follow suexec, since
6320N/A * an unrooted command is as predictable as shooting craps in Win32.
6320N/A *
6320N/A * Notice that unlike most mime extension parsing, we have to use the
6320N/A * win32 parsing here, therefore the final extension is the only one
6320N/A * we will consider
6320N/A */
6320N/A *cmd = r->filename;
6320N/A if (r->args && r->args[0] && !ap_strchr_c(r->args, '=')) {
6320N/A args = r->args;
6320N/A }
6320N/A }
6320N/A ext = strrchr(apr_filename_of_pathname(*cmd), '.');
6320N/A
6320N/A if (*ext == '.')
6320N/A ++ext;
6320N/A
6320N/A /* If it is an NLM then just execute it. */
6320N/A if (stricmp(ext, "nlm")) {
6320N/A *cmd = apr_table_get(d->file_type_handlers, ext);
6320N/A if (*cmd == NULL) {
6320N/A ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
6320N/A "Could not find a command associated with the %s extension", ext);
6320N/A return APR_EBADF;
6320N/A }
6320N/A
6320N/A }
6320N/A
6320N/A apr_tokenize_to_argv(r->filename, (char***)argv, p);
6320N/A e_info->cmd_type = APR_PROGRAM;
6320N/A
6320N/A return APR_SUCCESS;
6320N/A}
6320N/A
6320N/Astatic void register_hooks(apr_pool_t *p)
6320N/A{
6320N/A APR_REGISTER_OPTIONAL_FN(ap_cgi_build_command);
6320N/A}
6320N/A
6320N/Astatic const command_rec netware_cmds[] = {
6320N/AAP_INIT_ITERATE2("CGIMapExtension", set_extension_map, NULL, OR_FILEINFO,
6320N/A "full path to the CGI NLM module followed by one or more file extensions"),
6320N/A{ NULL }
6320N/A};
6320N/A
6320N/Amodule AP_MODULE_DECLARE_DATA netware_module = {
6320N/A STANDARD20_MODULE_STUFF,
6320N/A create_netware_dir_config, /* create per-dir config */
6320N/A merge_netware_dir_configs, /* merge per-dir config */
6320N/A NULL, /* server config */
6320N/A NULL, /* merge server config */
6320N/A netware_cmds, /* command apr_table_t */
6320N/A register_hooks /* register hooks */
6320N/A};
6320N/A
6320N/A#endif
6320N/A