mod_access.c revision 928f342270fd8ca02a36f484072d35063121171f
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd/* ====================================================================
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * The Apache Software License, Version 1.1
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * reserved.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * Redistribution and use in source and binary forms, with or without
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * modification, are permitted provided that the following conditions
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * are met:
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * 1. Redistributions of source code must retain the above copyright
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * notice, this list of conditions and the following disclaimer.
2e545ce2450a9953665f701bb05350f0d3f26275nd * 2. Redistributions in binary form must reproduce the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer in
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * the documentation and/or other materials provided with the
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * distribution.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * 3. The end-user documentation included with the redistribution,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if any, must include the following acknowledgment:
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * "This product includes software developed by the
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * Apache Software Foundation (http://www.apache.org/)."
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * Alternately, this acknowledgment may appear in the software itself,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if and wherever such third-party acknowledgments normally appear.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * 4. The names "Apache" and "Apache Software Foundation" must
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * not be used to endorse or promote products derived from this
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * software without prior written permission. For written
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * permission, please contact apache@apache.org.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * 5. Products derived from this software may not be called "Apache",
bf7fcf0c216a914407c0877aa37894fd9aecc219nilgun * nor may "Apache" appear in their name, without prior written
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * permission of the Apache Software Foundation.
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * SUCH DAMAGE.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * ====================================================================
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * This software consists of voluntary contributions made by many
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * individuals on behalf of the Apache Software Foundation. For more
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * information on the Apache Software Foundation, please see
2893256d86dd891d5859ef01dec4d85bf6488b69nd * Portions of this software are based upon public domain software
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * originally written at the National Center for Supercomputing Applications,
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * University of Illinois, Urbana-Champaign.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * Security options etc.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * Module derived from code originally written by Rob McCool
5383fa753e1bcd3a04ec34ba9810d671302380f2colmtypedef struct {
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd unsigned long net;
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd unsigned long mask;
2893256d86dd891d5859ef01dec4d85bf6488b69nd/* things in the 'order' array */
1cc20a8827ff6056399d64e3106b44d31e8e0e53ndtypedef struct {
1cc20a8827ff6056399d64e3106b44d31e8e0e53ndstatic void *create_access_dir_config(apr_pool_t *p, char *dummy)
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd (access_dir_conf *) apr_pcalloc(p, sizeof(access_dir_conf));
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd for (i = 0; i < METHODS; ++i)
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd return (void *) conf;
1cc20a8827ff6056399d64e3106b44d31e8e0e53ndstatic const char *order(cmd_parms *cmd, void *dv, const char *arg)
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd return "unknown order";
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd for (i = 0; i < METHODS; ++i)
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd d->order[i] = o;
1cc20a8827ff6056399d64e3106b44d31e8e0e53ndstatic const char *allow_cmd(cmd_parms *cmd, void *dv, const char *from,
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd const char *where_c)
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd return "allow and deny must be followed by 'from'";
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd a = (allowdeny *) apr_array_push(cmd->info ? d->allows : d->denys);
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd unsigned long mask;
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd /* trample on where, we won't be using it any more */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd *s++ = '\0';
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd || (a->x.ip.net = apr_inet_addr(where)) == APR_INADDR_NONE) {
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd return "syntax error in network portion of network/netmask";
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd /* is_ip just tests if it matches [\d.]+ */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd if (!is_ip(s)) {
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd return "syntax error in mask portion of network/netmask";
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd /* is it in /a.b.c.d form? */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd return "syntax error in mask portion of network/netmask";
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd /* assume it's in /nnn form */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd return "invalid mask in network/netmask";
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd a->x.ip.net = (a->x.ip.net & mask); /* pjr - This fixes PR 4770 */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd /* legacy syntax for ip addrs: a.b.c. ==> a.b.c.0/24 for example */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd /* parse components */
829881b33014c4321c1e9ea5ec84826b177fe871humbedooh while (*s) {
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd return "invalid ip address";
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd while (apr_isdigit(*t)) {
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd if (*t == '.') {
bf7fcf0c216a914407c0877aa37894fd9aecc219nilgun else if (*t) {
727872d18412fc021f03969b8641810d8896820bhumbedooh return "invalid ip address";
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh return "invalid ip address, only 4 octets allowed";
0d0ba3a410038e179b695446bb149cce6264e0abnd return "each octet must be between 0 and 255 inclusive";
static char its_an_allow;
{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;