mod_allowmethods.c revision 135c1278adef96d36fd421c536b1acc54a341cfb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * contributor license agreements. See the NOTICE file distributed with
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * this work for additional information regarding copyright ownership.
b99dbaab171d91e1b664397cc40e039d0c087c65fielding * The ASF licenses this file to You under the Apache License, Version 2.0
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * (the "License"); you may not use this file except in compliance with
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the License. You may obtain a copy of the License at
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Unless required by applicable law or agreed to in writing, software
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * distributed under the License is distributed on an "AS IS" BASIS,
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * See the License for the specific language governing permissions and
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * limitations under the License.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * This module makes it easy to restrict what HTTP methods can be ran against
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * a server.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * It provides one comand:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * AllowMethods
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * This command takes a list of HTTP methods to allow.
64185f9824e42f21ca7b9ae6c004484215c031a7rbb * The most common configuration should be like this:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * <Directory />
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * AllowMethods GET HEAD OPTIONS
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * </Directory>
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * <Directory /special/cgi-bin>
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * AllowMethods GET HEAD OPTIONS POST
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * </Directory>
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Non-matching methods will be returned a status 405 (method not allowed)
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * To allow all methods, and effectively turn off mod_allowmethods, use:
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * AllowMethods reset
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffieldingtypedef struct am_conf_t {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding conf = (am_conf_t *) ap_get_module_config(r->per_dir_config,
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein "client method denied by server configuration: '%s' to %s%s",
cccd31fa4a72fe23cc3249c06db181b274a55a69gsteinstatic void *am_create_conf(apr_pool_t * p, char *dummy)
cccd31fa4a72fe23cc3249c06db181b274a55a69gsteinstatic void* am_merge_conf(apr_pool_t* pool, void* a, void* b) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding am_conf_t* conf = apr_palloc(pool, sizeof(am_conf_t));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding conf->allowed = add->allowed ? add->allowed : base->allowed;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *am_allowmethods(cmd_parms *cmd, void *d, int argc, char *const argv[])
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < argc; i++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return apr_pstrcat(cmd->pool, "AllowMethods: Invalid Method '", argv[i], "'", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_hook_access_checker(am_check_access, NULL, NULL, APR_HOOK_REALLY_FIRST);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE_ARGV("AllowMethods", am_allowmethods, NULL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "only allow specific methods"),