mod_access.c revision b132bb4b4e3de68fc3a26ce452bee9274094492f
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/* ====================================================================
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * The Apache Software License, Version 1.1
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * reserved.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Redistribution and use in source and binary forms, with or without
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * modification, are permitted provided that the following conditions
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * are met:
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * 1. Redistributions of source code must retain the above copyright
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * notice, this list of conditions and the following disclaimer.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * 2. Redistributions in binary form must reproduce the above copyright
27e52281f1522522b170cafc76b08b58aa70ccaand * notice, this list of conditions and the following disclaimer in
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * the documentation and/or other materials provided with the
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * distribution.
4b5981e276e93df97c34e4da05ca5cf8bbd937dand * 3. The end-user documentation included with the redistribution,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * if any, must include the following acknowledgment:
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * "This product includes software developed by the
e609c337f729875bc20e01096c7e610f45356f54nilgun * Apache Software Foundation (http://www.apache.org/)."
e609c337f729875bc20e01096c7e610f45356f54nilgun * Alternately, this acknowledgment may appear in the software itself,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * if and wherever such third-party acknowledgments normally appear.
9bcfc3697a91b5215893a7d0206865b13fc72148nd * 4. The names "Apache" and "Apache Software Foundation" must
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * not be used to endorse or promote products derived from this
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * software without prior written permission. For written
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * permission, please contact apache@apache.org.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * 5. Products derived from this software may not be called "Apache",
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * nor may "Apache" appear in their name, without prior written
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * permission of the Apache Software Foundation.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * SUCH DAMAGE.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * ====================================================================
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * This software consists of voluntary contributions made by many
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * individuals on behalf of the Apache Software Foundation. For more
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * information on the Apache Software Foundation, please see
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Portions of this software are based upon public domain software
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * originally written at the National Center for Supercomputing Applications,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * University of Illinois, Urbana-Champaign.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Security options etc.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Module derived from code originally written by Rob McCool
a78048ccbdb6256da15e6b0e7e95355e480c2301ndtypedef struct {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/* things in the 'order' array */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndtypedef struct {
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic void *create_access_dir_config(apr_pool_t *p, char *dummy)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (access_dir_conf *) apr_pcalloc(p, sizeof(access_dir_conf));
a78048ccbdb6256da15e6b0e7e95355e480c2301nd for (i = 0; i < METHODS; ++i)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return (void *) conf;
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic const char *order(cmd_parms *cmd, void *dv, const char *arg)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return "unknown order";
a78048ccbdb6256da15e6b0e7e95355e480c2301nd for (i = 0; i < METHODS; ++i)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd d->order[i] = o;
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic const char *allow_cmd(cmd_parms *cmd, void *dv, const char *from,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const char *where_c)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return "allow and deny must be followed by 'from'";
a78048ccbdb6256da15e6b0e7e95355e480c2301nd a = (allowdeny *) apr_array_push(cmd->info ? d->allows : d->denys);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *s++ = '\0';
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /* looked nothing like an IP address */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return "An IP address was expected";
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else if (!APR_STATUS_IS_EINVAL(rv = apr_ipsubnet_create(&a->x.ip, where, NULL, cmd->pool))) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else { /* no slash, didn't look like an IP address => must be a host */
{NULL}
int gothost = 0;
for (i = 0; i < a->nelts; ++i) {
case T_ENV:
case T_ALL:
case T_IP:
case T_HOST:
if (!gothost) {
int remotehost_is_ip;
case T_FAIL:
access_dir_conf *a =
(access_dir_conf *)
r->filename);
return ret;