home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / LINUX / LINUXISO.S97 / comprimid / apache / mod / mod_block.c.txt < prev    next >
Encoding:
Text File  |  1997-07-19  |  5.3 KB  |  157 lines

  1.  
  2.  
  3.  
  4. /* ====================================================================
  5.  * Copyright (c) 1996 The Apache Group.  All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer. 
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. All advertising materials mentioning features or use of this
  20.  *    software must display the following acknowledgment:
  21.  *    "This product includes software developed by the Apache Group
  22.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  23.  *
  24.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  25.  *    endorse or promote products derived from this software without
  26.  *    prior written permission.
  27.  *
  28.  * 5. Redistributions of any form whatsoever must retain the following
  29.  *    acknowledgment:
  30.  *    "This product includes software developed by the Apache Group
  31.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  32.  *
  33.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  34.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  35.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  36.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  37.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  39.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  40.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  41.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  42.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  44.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  45.  * ====================================================================
  46.  *
  47.  * This software consists of voluntary contributions made by many
  48.  * individuals on behalf of the Apache Group and was originally based
  49.  * on public domain software written at the National Center for
  50.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  51.  * For more information on the Apache Group and the Apache HTTP server
  52.  * project, please see <http://www.apache.org/>.
  53.  *
  54.  */
  55.  
  56. /* mod_block.c - by Alexei Kosut <akosut@organic.com> June, 1996
  57.  *
  58.  * This module allows you to block access to your site that was
  59.  * referred to from a certain URL. This isn't a 100%-foolproof
  60.  * way of preventing access to your site, but if someone has a link
  61.  * to a page or image of yours, that you don't like, it's a pretty
  62.  * good way of blocking access from that location.
  63.  *
  64.  * Example:
  65.  * BlockReferer www.organic.com
  66.  * BlockReferer netscape.com/comprod/sales/index.html
  67.  */
  68.  
  69.  
  70. #include "httpd.h"
  71. #include "http_config.h"
  72.  
  73. module block_module;
  74.  
  75. typedef struct {
  76.     table *block_referer_list;
  77. } block_state;
  78.  
  79. void *make_block_state (pool *p, server_rec *s)
  80. {
  81.     block_state *cls =
  82.       (block_state *)palloc (p, sizeof (block_state));
  83.  
  84.     cls->block_referer_list = make_table(p, 1);
  85.     return (void *)cls;
  86. }
  87.  
  88. void *merge_block_state (pool *p, void *basev, void *overridesv)
  89. {
  90.    block_state *a = (block_state *)pcalloc (p, sizeof (block_state));
  91.    block_state *base = (block_state *)basev,
  92.      *overrides = (block_state *)overridesv;
  93.  
  94.    a->block_referer_list = overlay_tables (p, overrides->block_referer_list,
  95.                       base->block_referer_list);
  96.  
  97.    return a;
  98. }
  99.  
  100. char *add_referer_block (cmd_parms *parms, void *dummy, char *arg)
  101. {
  102.     block_state *cls = get_module_config (parms->server->module_config,
  103.                           &block_module);
  104.  
  105.     table_set(cls->block_referer_list, arg, arg);
  106.     
  107.     return NULL;
  108. }
  109.  
  110. command_rec block_cmds[] = {
  111. { "BlockReferer", add_referer_block, NULL, RSRC_CONF, ITERATE,
  112.     "referer hostnames to block" },
  113. { NULL }
  114. };
  115.  
  116. int proc_block_trans(request_rec *r)
  117. {
  118.     block_state *cls = get_module_config (r->server->module_config,
  119.                       &block_module);
  120.   
  121.     char *referer = table_get(r->headers_in, "Referer");
  122.     array_header *list_arr = table_elts(cls->block_referer_list);
  123.     table_entry *list = (table_entry *)list_arr->elts;
  124.     int i;
  125.  
  126.     if (!referer || !list)
  127.         return DECLINED;    
  128.  
  129.     for (i = 0; i < list_arr->nelts; ++i) {
  130.         char *str = list[i].key;
  131.  
  132.     if (str && strstr(referer, str))
  133.       return FORBIDDEN;
  134.     }
  135.  
  136.     return DECLINED;
  137. }
  138.  
  139.  
  140. module block_module = {
  141.    STANDARD_MODULE_STUFF,
  142.    NULL,            /* initializer */
  143.    NULL,            /* create per-dir config */
  144.    NULL,            /* merge per-dir config */
  145.    make_block_state,        /* server config */
  146.    merge_block_state,               /* merge server config */
  147.    block_cmds,            /* command table */
  148.    NULL,            /* handlers */
  149.    NULL,            /* filename translation */
  150.    NULL,            /* check_user_id */
  151.    NULL,            /* check auth */
  152.    proc_block_trans,        /* check access */
  153.    NULL,            /* type_checker */
  154.    NULL,            /* fixups */
  155.    NULL                /* logger */
  156. };
  157.