/* ==================================================================== * Copyright (c) 1999 Vincent Partington. 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 * the documentation and/or other materials provided with the * distribution. * * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY VINCENT PARTINGTON ``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 VINCENT PARTINGTON 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. * ==================================================================== */ #include "httpd.h" #include "http_core.h" #include "http_config.h" #include "http_log.h" #include /* for libwrap */ #define RQ_DAEMON_NAME "httpd" int allow_severity = LOG_INFO; int deny_severity = LOG_WARNING; module hosts_access_module; struct hosts_access_config { int enabled; }; static void *hosts_access_create_config(pool *p, server_rec * s) { struct hosts_access_config *hac; hac = (struct hosts_access_config *) ap_pcalloc(p, sizeof(struct hosts_access_config)); hac->enabled = 0; /* default is Off */ return hac; } static const char *hosts_access_enable(cmd_parms *cmd, void *dummy, char *value) { struct hosts_access_config *hac; hac = (struct hosts_access_config *) ap_get_module_config(cmd->server->module_config, &hosts_access_module); hac->enabled = (strcasecmp(value, "on") == 0); return NULL; } static int hosts_access_check_access(request_rec *ap_req) { struct hosts_access_config *hac; struct request_info ha_req; char *s; hac = (struct hosts_access_config *) ap_get_module_config(ap_req->server->module_config, &hosts_access_module); if(hac->enabled) { request_init(&ha_req, RQ_DAEMON, RQ_DAEMON_NAME, RQ_CLIENT_SIN, &ap_req->connection->remote_addr, RQ_SERVER_SIN, &ap_req->connection->local_addr, NULL); s = (char *) ap_get_remote_logname(ap_req); if(s != NULL && s != '\0') { request_set(&ha_req, RQ_USER, s, 0); } sock_methods(&ha_req); if(!hosts_access(&ha_req)) { ap_log_rerror(APLOG_MARK, LOG_ERR|APLOG_NOERRNO, ap_req, "connection refused from %s to %s", eval_client(&ha_req), eval_server(&ha_req)); return HTTP_FORBIDDEN; } } return DECLINED; } static const command_rec hosts_access_commands[] = { {"HostsAccess", hosts_access_enable, NULL, OR_LIMIT, TAKE1, "On to enable hosts.allow and hosts.deny checking, Off to disable this" }, {NULL} }; module hosts_access_module = { STANDARD_MODULE_STUFF, NULL, NULL, NULL, hosts_access_create_config, NULL, hosts_access_commands, NULL, NULL, NULL, NULL, hosts_access_check_access, NULL, NULL, NULL, NULL, NULL, NULL, NULL };