Apache HTTPD
mod_allowmethods.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "httpd.h"
18#include "http_core.h"
19#include "http_config.h"
20#include "http_protocol.h"
21#include "http_request.h"
22#include "http_log.h"
23#include "apr_strings.h"
24
46typedef struct am_conf_t {
48 apr_int64_t allowed;
50
51module AP_MODULE_DECLARE_DATA allowmethods_module;
52
54{
55 int method = r->method_number;
56 am_conf_t *conf;
57
59 &allowmethods_module);
60 if (!conf || conf->allowed == 0) {
61 return DECLINED;
62 }
63
64 r->allowed = conf->allowed;
65
66 if (conf->allowed & (AP_METHOD_BIT << method)) {
67 return DECLINED;
68 }
69
71 "client method denied by server configuration: '%s' to %s%s",
72 r->method,
73 r->filename ? "" : "uri ",
74 r->filename ? r->filename : r->uri);
75
77}
78
79static void *am_create_conf(apr_pool_t *p, char *dummy)
80{
81 am_conf_t *conf = apr_pcalloc(p, sizeof(am_conf_t));
82
83 conf->allowed = 0;
84 conf->allowed_set = 0;
85 return conf;
86}
87
88static void *am_merge_conf(apr_pool_t *pool, void *a, void *b)
89{
91 am_conf_t *add = (am_conf_t *)b;
92 am_conf_t *conf = apr_palloc(pool, sizeof(am_conf_t));
93
94 if (add->allowed_set) {
95 conf->allowed = add->allowed;
96 conf->allowed_set = add->allowed_set;
97 }
98 else {
99 conf->allowed = base->allowed;
100 conf->allowed_set = base->allowed_set;
101 }
102
103 return conf;
104}
105
106static const char *am_allowmethods(cmd_parms *cmd, void *d, int argc,
107 char *const argv[])
108{
109 int i;
110 am_conf_t *conf = (am_conf_t *)d;
111
112 if (argc == 0) {
113 return "AllowMethods: No method or 'reset' keyword given";
114 }
115 if (argc == 1) {
116 if (strcasecmp("reset", argv[0]) == 0) {
117 conf->allowed = 0;
118 conf->allowed_set = 1;
119 return NULL;
120 }
121 }
122
123 for (i = 0; i < argc; i++) {
124 int m;
125
127 if (m == M_INVALID) {
128 return apr_pstrcat(cmd->pool, "AllowMethods: Invalid Method '",
129 argv[i], "'", NULL);
130 }
131
132 conf->allowed |= (AP_METHOD_BIT << m);
133 }
134 conf->allowed_set = 1;
135 return NULL;
136}
137
142
143static const command_rec am_cmds[] = {
144 AP_INIT_TAKE_ARGV("AllowMethods", am_allowmethods, NULL,
146 "only allow specific methods"),
147 {NULL}
148};
149
150AP_DECLARE_MODULE(allowmethods) = {
154 NULL,
155 NULL,
156 am_cmds,
158};
apr_size_t const unsigned char unsigned int unsigned int d
Definition apr_siphash.h:72
APR Strings library.
#define ap_get_module_config(v, m)
#define AP_INIT_TAKE_ARGV(directive, func, mconfig, where, help)
#define AP_DECLARE_MODULE(foo)
ap_conf_vector_t * base
request_rec * r
#define DECLINED
Definition httpd.h:457
#define APLOGNO(n)
Definition http_log.h:117
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_ERR
Definition http_log.h:67
#define APLOG_MARK
Definition http_log.h:283
int ap_method_number_of(const char *method)
void ap_hook_access_checker(ap_HOOK_access_checker_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:91
void * dummy
Definition http_vhost.h:62
apr_bucket apr_bucket_brigade * a
#define APR_HOOK_REALLY_FIRST
Definition apr_hooks.h:299
#define ACCESS_CONF
#define HTTP_METHOD_NOT_ALLOWED
Definition httpd.h:513
#define AP_METHOD_BIT
Definition httpd.h:629
#define M_INVALID
Definition httpd.h:618
#define STANDARD20_MODULE_STUFF
const char int apr_pool_t * pool
Definition apr_cstr.h:84
int strcasecmp(const char *a, const char *b)
apr_pool_t int argc
Definition apr_getopt.h:104
apr_uint32_t apr_pool_t apr_uint32_t apr_pollset_method_e method
Definition apr_poll.h:195
apr_pool_t * b
Definition apr_pools.h:529
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
const void * m
apr_cmdtype_e cmd
Apache Configuration.
CORE HTTP Daemon.
Apache Logging library.
HTTP protocol handling.
Apache Request library.
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
static void am_register_hooks(apr_pool_t *p)
static const command_rec am_cmds[]
static int am_check_access(request_rec *r)
static void * am_create_conf(apr_pool_t *p, char *dummy)
static void * am_merge_conf(apr_pool_t *pool, void *a, void *b)
static const char * am_allowmethods(cmd_parms *cmd, void *d, int argc, char *const argv[])
const char * argv[3]
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
apr_int64_t allowed
A structure that represents the current request.
Definition httpd.h:845
char * uri
Definition httpd.h:1016
int method_number
Definition httpd.h:898
char * filename
Definition httpd.h:1018
apr_int64_t allowed
Definition httpd.h:922
struct ap_conf_vector_t * per_dir_config
Definition httpd.h:1047
const char * method
Definition httpd.h:900