mod_access.c revision e68becff3c3ddc18723c9799b8cc2e6e9c3dbd66
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/*
* Security options etc.
*
* Module derived from code originally written by Rob McCool
*
*/
#include "apr_network_io.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_core.h"
#include "http_config.h"
#include "http_log.h"
#include "http_request.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif
enum allowdeny_type {
T_IP,
};
typedef struct {
int limited;
union {
char *from;
struct {
unsigned long net;
unsigned long mask;
} ip;
} x;
enum allowdeny_type type;
} allowdeny;
/* things in the 'order' array */
#define DENY_THEN_ALLOW 0
#define ALLOW_THEN_DENY 1
#define MUTUAL_FAILURE 2
typedef struct {
{
int i;
for (i = 0; i < METHODS; ++i)
return (void *) conf;
}
{
int i, o;
o = ALLOW_THEN_DENY;
o = DENY_THEN_ALLOW;
o = MUTUAL_FAILURE;
else
return "unknown order";
for (i = 0; i < METHODS; ++i)
d->order[i] = o;
return NULL;
}
{
host++;
return (*host == '\0');
}
{
allowdeny *a;
char *s;
return "allow and deny must be followed by 'from'";
a->x.from += 4;
}
}
unsigned long mask;
/* trample on where, we won't be using it any more */
*s++ = '\0';
}
/* is_ip just tests if it matches [\d.]+ */
if (!is_ip(s)) {
}
/* is it in /a.b.c.d form? */
if (strchr(s, '.')) {
mask = ap_inet_addr(s);
if (mask == INADDR_NONE) {
}
}
else {
/* assume it's in /nnn form */
}
}
}
int shift;
char *t;
int octet;
/* parse components */
s = where;
shift = 24;
while (*s) {
t = s;
if (!ap_isdigit(*t)) {
return "invalid ip address";
}
while (ap_isdigit(*t)) {
++t;
}
if (*t == '.') {
*t++ = 0;
}
else if (*t) {
return "invalid ip address";
}
if (shift < 0) {
return "invalid ip address, only 4 octets allowed";
}
return "each octet must be between 0 and 255 inclusive";
}
s = t;
shift -= 8;
}
}
else {
}
return NULL;
}
static char its_an_allow;
static const command_rec access_cmds[] =
{
"'allow,deny', 'deny,allow', or 'mutual-failure'"},
"'from' followed by hostnames or IP-address wildcards"},
"'from' followed by hostnames or IP-address wildcards"},
{NULL}
};
{
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;
}
{
int i;
int gothost = 0;
const char *remotehost = NULL;
for (i = 0; i < a->nelts; ++i) {
continue;
case T_ENV:
return 1;
}
break;
case T_ALL:
return 1;
case T_IP:
return 1;
}
break;
case T_HOST:
if (!gothost) {
gothost = 1;
else
gothost = 2;
}
return 1;
break;
case T_FAIL:
/* do nothing? */
break;
}
}
return 0;
}
static int check_dir_access(request_rec *r)
{
int method = r->method_number;
access_dir_conf *a =
(access_dir_conf *)
}
}
else {
else
}
"client denied by server configuration: %s",
r->filename);
}
return ret;
}
static void register_hooks(void)
{
}
{
create_access_dir_config, /* dir config creater */
NULL, /* dir merger --- default is to override */
NULL, /* server config */
NULL, /* merge server config */
NULL, /* handlers */
register_hooks /* register hooks */
};