mod_authz_host.c revision f6098228fada9d4d6dcdc0cd321f4f5904040d1e
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Security options etc.
*
* Module derived from code originally written by Rob McCool
*
*/
#include "apr_strings.h"
#include "apr_network_io.h"
#include "apr_md5.h"
#include "apr_hash.h"
#define APR_WANT_STRFUNC
#define APR_WANT_BYTEFUNC
#include "apr_want.h"
#include "ap_config.h"
#include "ap_provider.h"
#include "httpd.h"
#include "http_core.h"
#include "http_config.h"
#include "http_log.h"
#include "http_protocol.h"
#include "http_request.h"
#include "mod_auth.h"
#endif
/*
* To save memory if the same subnets are used in hundres of vhosts, we store
* each subnet only once and use this temporary hash to find it again.
*/
static apr_hash_t *parsed_subnets;
static apr_ipsubnet_t *localhost_v4;
#if APR_HAVE_IPV6
static apr_ipsubnet_t *localhost_v6;
#endif
{
return 0;
}
/* Make sure we matched an *entire* subdomain --- if the user
* to be able to get in.
*/
return 1; /* matched whole thing */
}
else {
}
}
else {
return 0;
}
}
const char *require_line,
const void **parsed_require_line)
{
const char *t, *w;
int count = 0;
apr_ipsubnet_t **ip;
/* The 'ip' provider will allow the configuration to specify a list of
ip addresses to check rather than a single address. This is different
from the previous host based syntax. */
t = require_line;
while ((w = ap_getword_conf(ptemp, &t)) && w[0])
count++;
if (count == 0)
return "'require ip' requires an argument";
t = require_line;
while ((w = ap_getword_conf(ptemp, &t)) && w[0]) {
char *mask;
if (parsed_subnets &&
{
/* we already have parsed this subnet */
ip++;
continue;
}
*mask++ = '\0';
if(APR_STATUS_IS_EINVAL(rv)) {
/* looked nothing like an IP address */
return apr_psprintf(p, "ip address '%s' appears to be invalid", w);
}
else if (rv != APR_SUCCESS) {
return apr_psprintf(p, "ip address '%s' appears to be invalid: %pm",
w, &rv);
}
if (parsed_subnets)
ip++;
}
return NULL;
}
const char *require_line,
const void *parsed_require_line)
{
/* apr_ipsubnet_test should accept const but doesn't */
while (*ip) {
return AUTHZ_GRANTED;
ip++;
}
/* authz_core will log the require line and the result at DEBUG */
return AUTHZ_DENIED;
}
const char *require_line,
const void *parsed_require_line)
{
const char *t, *w;
const char *remotehost = NULL;
int remotehost_is_ip;
r->per_dir_config,
"access check of '%s' to %s failed, reason: unable to get the "
}
else {
const char *require;
if (err) {
"authz_host authorize: require host: Can't "
"evaluate require expression: %s", err);
return AUTHZ_DENIED;
}
/* The 'host' provider will allow the configuration to specify a list of
host names to check rather than a single name. This is different
from the previous host based syntax. */
t = require;
while ((w = ap_getword_conf(r->pool, &t)) && w[0]) {
if (in_domain(w, remotehost)) {
return AUTHZ_GRANTED;
}
}
}
/* authz_core will log the require line and the result at DEBUG */
return AUTHZ_DENIED;
}
const char *require_line,
const void *parsed_require_line)
{
r->useragent_addr)
#if APR_HAVE_IPV6
#endif
)
{
return AUTHZ_GRANTED;
}
return AUTHZ_DENIED;
}
const void **parsed_require_line)
{
if (expr_err)
"Cannot parse expression in require line: ",
return NULL;
}
static const authz_provider authz_ip_provider =
{
};
static const authz_provider authz_host_provider =
{
};
static const authz_provider authz_local_provider =
{
NULL,
};
{
/* we only use this hash in the parse config phase, ptemp is enough */
#if APR_HAVE_IPV6
#endif
return OK;
}
{
/* make sure we don't use this during .htaccess parsing */
return OK;
}
static void register_hooks(apr_pool_t *p)
{
}
{
NULL, /* dir config creater */
NULL, /* dir merger --- default is to override */
NULL, /* server config */
NULL, /* merge server config */
NULL,
register_hooks /* register hooks */
};