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