842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes * Unless required by applicable law or agreed to in writing, software
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes * distributed under the License is distributed on an "AS IS" BASIS,
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes * See the License for the specific language governing permissions and
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes * limitations under the License.
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes * Security options etc.
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes * Module derived from code originally written by Rob McCool
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholestypedef struct {
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes/* things in the 'order' array */
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholestypedef struct {
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholesmodule AP_MODULE_DECLARE_DATA access_compat_module;
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholesstatic void *create_access_compat_dir_config(apr_pool_t *p, char *dummy)
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes (access_compat_dir_conf *)apr_pcalloc(p, sizeof(access_compat_dir_conf));
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes for (i = 0; i < METHODS; ++i) {
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes conf->allows = apr_array_make(p, 1, sizeof(allowdeny));
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes conf->denys = apr_array_make(p, 1, sizeof(allowdeny));
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes conf->satisfy = apr_palloc(p, sizeof(*conf->satisfy) * METHODS);
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes for (i = 0; i < METHODS; ++i) {
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes return (void *)conf;
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholesstatic const char *order(cmd_parms *cmd, void *dv, const char *arg)
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes access_compat_dir_conf *d = (access_compat_dir_conf *) dv;
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes return "unknown order";
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes for (i = 0; i < METHODS; ++i)
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholesstatic const char *satisfy(cmd_parms *cmd, void *dv, const char *arg)
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes access_compat_dir_conf *d = (access_compat_dir_conf *) dv;
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes return "Satisfy either 'any' or 'all'.";
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes for (i = 0; i < METHODS; ++i) {
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholesstatic const char *allow_cmd(cmd_parms *cmd, void *dv, const char *from,
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes const char *where_c)
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes access_compat_dir_conf *d = (access_compat_dir_conf *) dv;
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes return "allow and deny must be followed by 'from'";
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes a = (allowdeny *) apr_array_push(cmd->info ? d->allows : d->denys);
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes *s++ = '\0';
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes rv = apr_ipsubnet_create(&a->x.ip, where, s, cmd->pool);
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes /* looked nothing like an IP address */
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes return "An IP address was expected";
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes else if (!APR_STATUS_IS_EINVAL(rv = apr_ipsubnet_create(&a->x.ip, where,
a1ad96ae397dcfc3d5599181ccc29381c7674cc6jkaluza return "No comments are allowed here";
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes else { /* no slash, didn't look like an IP address => must be a host */
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes "'allow,deny', 'deny,allow', or 'mutual-failure'"),
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes AP_INIT_ITERATE2("allow", allow_cmd, &its_an_allow, OR_LIMIT,
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes "'from' followed by hostnames or IP-address wildcards"),
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes AP_INIT_ITERATE2("deny", allow_cmd, NULL, OR_LIMIT,
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes "'from' followed by hostnames or IP-address wildcards"),
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes AP_INIT_TAKE1("Satisfy", satisfy, NULL, OR_AUTHCFG,
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes "access policy if both allow and require used ('all' or 'any')"),
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholesstatic int in_domain(const char *domain, const char *what)
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes /* Make sure we matched an *entire* subdomain --- if the user
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes * said 'allow from good.com', we don't want people from nogood.com
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes * to be able to get in.
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes return (domain[0] == '.' || what[wl - dl - 1] == '.');
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholesstatic int find_allowdeny(request_rec *r, apr_array_header_t *a, int method)
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes for (i = 0; i < a->nelts; ++i) {
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes if (apr_table_get(r->subprocess_env, ap[i].x.from)) {
a221184be5b40f8349982d94cda02b98068ce0d8minfrin if (apr_ipsubnet_test(ap[i].x.ip, r->useragent_addr)) {
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes if ((gothost == 2) && in_domain(ap[i].x.from, remotehost)) {
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes /* do nothing? */
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholesstatic int access_compat_ap_satisfies(request_rec *r)
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes access_compat_dir_conf *conf = (access_compat_dir_conf *)
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes ap_get_module_config(r->per_dir_config, &access_compat_module);
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes access_compat_dir_conf *a = (access_compat_dir_conf *)
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes ap_get_module_config(r->per_dir_config, &access_compat_module);
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01797)
6eebc35261655d22ef6798bc1a46cf620a09ad49trawick "client denied by server configuration: %s%s",
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes APR_REGISTER_OPTIONAL_FN(access_compat_ap_satisfies);
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes /* This can be access checker since we don't require r->user to be set. */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_hook_check_access(check_dir_access, NULL, NULL, APR_HOOK_MIDDLE,
bbb1d2f82de322f7ce7746301a5f6cb3ce625663bnicholes create_access_compat_dir_config, /* dir config creater */