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 * http://www.apache.org/licenses/LICENSE-2.0
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.
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maedermodule AP_MODULE_DECLARE_DATA netware_module;
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 */
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maederstatic void *create_netware_dir_config(apr_pool_t *p, char *dir)
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder netware_dir_config *new = (netware_dir_config*) apr_palloc(p, sizeof(netware_dir_config));
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 apr_table_set(new->file_type_handlers, "NLM", "OS");
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maederstatic void *merge_netware_dir_configs(apr_pool_t *p, void *basev, void *addv)
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));
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 Maederstatic const char *set_extension_map(cmd_parms *cmd, netware_dir_config *m,
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder for (i=0; i<len; i++) {
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder apr_table_set(m->file_type_handlers, ext, CGIhdlr);
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder apr_table_set(m->file_handler_mode, ext, "y");
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maederstatic apr_status_t ap_cgi_build_command(const char **cmd, const char ***argv,
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder d = (netware_dir_config *)ap_get_module_config(r->per_dir_config,
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.
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 if (r->args && r->args[0] && !ap_strchr_c(r->args, '=')) {
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder /* truncate any arguments from the cmd */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder for (ptr = cmd_only; *ptr && (*ptr != ' '); ptr++);
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 /* If there isn't an extension then give it an empty string */
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder /* eliminate the '.' if there is one */
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 "Could not find a command associated with the %s extension", ext);
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 /* Run in its own address space if specified */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder if(apr_table_get(d->file_handler_mode, ext))
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder /* Tokenize the full command string into its arguments */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder apr_tokenize_to_argv(*cmd, (char***)argv, p);
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder /* The first argument should be the executible */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder *cmd = ap_server_root_relative(p, *argv[0]);
return APR_SUCCESS;
return OK;
{ NULL }