mod_netware.c revision 2fe2d6ca1223e3ea902ea3f042a2b8c94ad01816
6903N/A/* Copyright 2002-2004 The Apache Software Foundation
6903N/A *
6903N/A * Licensed under the Apache License, Version 2.0 (the "License");
6903N/A * you may not use this file except in compliance with the License.
6903N/A * You may obtain a copy of the License at
6903N/A *
4416N/A * http://www.apache.org/licenses/LICENSE-2.0
4416N/A *
4416N/A * Unless required by applicable law or agreed to in writing, software
4416N/A * distributed under the License is distributed on an "AS IS" BASIS,
4416N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4416N/A * See the License for the specific language governing permissions and
4416N/A * limitations under the License.
4416N/A */
4416N/A
4416N/A#include "apr_strings.h"
4416N/A#include "apr_portable.h"
4416N/A#include "apr_buckets.h"
4416N/A#include "ap_config.h"
4416N/A#include "httpd.h"
4416N/A#include "http_config.h"
4416N/A#include "http_core.h"
4416N/A#include "http_protocol.h"
4416N/A#include "http_request.h"
4416N/A#include "http_log.h"
4416N/A#include "util_script.h"
4416N/A#include "mod_core.h"
4416N/A#include "apr_optional.h"
4416N/A#include "apr_lib.h"
4416N/A#include "mod_cgi.h"
4416N/A
4416N/A#ifdef NETWARE
4416N/A
4416N/A
4416N/Amodule AP_MODULE_DECLARE_DATA netware_module;
4416N/A
4416N/Atypedef struct {
4416N/A apr_table_t *file_type_handlers; /* CGI map from file types to CGI modules */
4416N/A apr_table_t *file_handler_mode; /* CGI module mode (spawn in same address space or not) */
4416N/A apr_table_t *extra_env_vars; /* Environment variables to be added to the CGI environment */
4416N/A} netware_dir_config;
4416N/A
4416N/A
4416N/Astatic void *create_netware_dir_config(apr_pool_t *p, char *dir)
4416N/A{
4416N/A netware_dir_config *new = (netware_dir_config*) apr_palloc(p, sizeof(netware_dir_config));
4416N/A
4416N/A new->file_type_handlers = apr_table_make(p, 10);
4416N/A new->file_handler_mode = apr_table_make(p, 10);
4416N/A new->extra_env_vars = apr_table_make(p, 10);
4416N/A
4416N/A apr_table_set(new->file_type_handlers, "NLM", "OS");
4416N/A
4416N/A return new;
4416N/A}
4416N/A
4416N/Astatic void *merge_netware_dir_configs(apr_pool_t *p, void *basev, void *addv)
4416N/A{
4416N/A netware_dir_config *base = (netware_dir_config *) basev;
4416N/A netware_dir_config *add = (netware_dir_config *) addv;
4416N/A netware_dir_config *new = (netware_dir_config *) apr_palloc(p, sizeof(netware_dir_config));
4416N/A
4416N/A new->file_type_handlers = apr_table_overlay(p, add->file_type_handlers, base->file_type_handlers);
4416N/A new->file_handler_mode = apr_table_overlay(p, add->file_handler_mode, base->file_handler_mode);
4416N/A new->extra_env_vars = apr_table_overlay(p, add->extra_env_vars, base->extra_env_vars);
4416N/A
4416N/A return new;
4416N/A}
4416N/A
4416N/Astatic const char *set_extension_map(cmd_parms *cmd, netware_dir_config *m,
4416N/A char *CGIhdlr, char *ext, char *detach)
4416N/A{
4416N/A int i, len;
4416N/A
4416N/A if (*ext == '.')
4416N/A ++ext;
4416N/A
4416N/A if (CGIhdlr != NULL) {
4416N/A len = strlen(CGIhdlr);
4416N/A for (i=0; i<len; i++) {
4416N/A if (CGIhdlr[i] == '\\') {
4416N/A CGIhdlr[i] = '/';
4416N/A }
4416N/A }
4416N/A }
4416N/A
4416N/A apr_table_set(m->file_type_handlers, ext, CGIhdlr);
4416N/A if (detach) {
4416N/A apr_table_set(m->file_handler_mode, ext, "y");
4416N/A }
4416N/A
4416N/A return NULL;
4416N/A}
4416N/A
4416N/Astatic apr_status_t ap_cgi_build_command(const char **cmd, const char ***argv,
4416N/A request_rec *r, apr_pool_t *p,
4416N/A cgi_exec_info_t *e_info)
4416N/A{
4416N/A char *ext = NULL;
4416N/A char *cmd_only, *ptr;
4416N/A const char *new_cmd;
4416N/A netware_dir_config *d;
4416N/A apr_file_t *fh;
4416N/A const char *args = "";
4416N/A
4416N/A d = (netware_dir_config *)ap_get_module_config(r->per_dir_config,
4416N/A &netware_module);
4416N/A
4416N/A if (e_info->process_cgi) {
4416N/A /* Handle the complete file name, we DON'T want to follow suexec, since
4416N/A * an unrooted command is as predictable as shooting craps in Win32.
4416N/A *
4416N/A * Notice that unlike most mime extension parsing, we have to use the
4416N/A * win32 parsing here, therefore the final extension is the only one
4416N/A * we will consider
4416N/A */
4416N/A *cmd = r->filename;
4416N/A if (r->args && r->args[0] && !ap_strchr_c(r->args, '=')) {
4416N/A args = r->args;
4416N/A }
4416N/A }
4416N/A
4416N/A cmd_only = apr_pstrdup(p, *cmd);
4416N/A e_info->cmd_type = APR_PROGRAM;
4416N/A
4416N/A /* truncate any arguments from the cmd */
4416N/A for (ptr = cmd_only; *ptr && (*ptr != ' '); ptr++);
4416N/A *ptr = '\0';
4416N/A
4416N/A /* Figure out what the extension is so that we can matche it. */
4416N/A ext = strrchr(apr_filepath_name_get(cmd_only), '.');
4416N/A
4416N/A /* If there isn't an extension then give it an empty string */
4416N/A if (!ext) {
4416N/A ext = "";
4416N/A }
4416N/A
4416N/A /* eliminate the '.' if there is one */
4416N/A if (*ext == '.')
4416N/A ++ext;
4416N/A
4416N/A /* check if we have a registered command for the extension*/
4416N/A new_cmd = apr_table_get(d->file_type_handlers, ext);
4416N/A if (new_cmd == NULL) {
4416N/A ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
4416N/A "Could not find a command associated with the %s extension", ext);
4416N/A return APR_EBADF;
4416N/A }
4416N/A if (stricmp(new_cmd, "OS")) {
4416N/A /* If we have a registered command then add the file that was passed in as a
4416N/A parameter to the registered command. */
4416N/A *cmd = apr_pstrcat (p, new_cmd, " ", cmd_only, NULL);
4416N/A
4416N/A /* Run in its own address space if specified */
4416N/A if(apr_table_get(d->file_handler_mode, ext))
4416N/A e_info->addrspace = 1;
4416N/A }
4416N/A
4416N/A /* Tokenize the full command string into its arguments */
4416N/A apr_tokenize_to_argv(*cmd, (char***)argv, p);
4416N/A e_info->detached = 1;
4416N/A
4416N/A /* The first argument should be the executible */
4416N/A *cmd = ap_server_root_relative(p, *argv[0]);
4416N/A
4416N/A return APR_SUCCESS;
4416N/A}
4416N/A
4416N/Astatic void register_hooks(apr_pool_t *p)
4416N/A{
4416N/A APR_REGISTER_OPTIONAL_FN(ap_cgi_build_command);
4416N/A}
4416N/A
4416N/Astatic const command_rec netware_cmds[] = {
4416N/AAP_INIT_TAKE23("CGIMapExtension", set_extension_map, NULL, OR_FILEINFO,
4416N/A "Full path to the CGI NLM module followed by a file extension. If the "
4416N/A "first parameter is set to \"OS\" then the following file extension is "
4416N/A "treated as NLM. The optional parameter \"detach\" can be specified if "
4416N/A "the NLM should be launched in its own address space."),
4416N/A{ NULL }
4416N/A};
4416N/A
4416N/Amodule AP_MODULE_DECLARE_DATA netware_module = {
4416N/A STANDARD20_MODULE_STUFF,
4416N/A create_netware_dir_config, /* create per-dir config */
4416N/A merge_netware_dir_configs, /* merge per-dir config */
4416N/A NULL, /* server config */
4416N/A NULL, /* merge server config */
4416N/A netware_cmds, /* command apr_table_t */
4416N/A register_hooks /* register hooks */
4416N/A};
4416N/A
4416N/A#endif
4416N/A